commit 24e085623af95c4b400e079aa343819ce1ca7dd3
parent 9eb47751af26807b5e8f8229f0dcced88e0ee992
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 28 Oct 2015 18:40:45 +0100
Update the schiff options
The sphere distribution is now fully defined by the -s option.
Diffstat:
3 files changed, 53 insertions(+), 36 deletions(-)
diff --git a/src/schiff_args.c b/src/schiff_args.c
@@ -58,27 +58,27 @@ print_help(const char* binary)
"the relative refractive index, and \"Ne\" the refractive index of the medium.\n"
"With no FILE, read optical properties from standard input.\n\n");
printf(
-" -d DIRS number of sampled directions for each geometry. Default is %u.\n",
+" -d DIRS number of sampled directions for each geometry. Default is %u.\n",
SCHIFF_ARGS_NULL.ndirs);
printf(
-" -g GOEMS number of sampled geometries. This is actually the number of\n"
-" realisations. Default is %u.\n",
+" -g GOEMS number of sampled geometries. This is actually the number of\n"
+" realisations. Default is %u.\n",
SCHIFF_ARGS_NULL.ngeoms);
printf(
-" -s STEPS number of points used to discretised the spherical mesh along 2PI.\n"
-" Default is %u.\n",
- SCHIFF_ARGS_NULL.nthetas);
+" -o OUTPUT write results to OUTPUT. If not defined, write results to\n"
+" stdout.\n");
printf(
-" -o OUTPUT write results to OUTPUT. If not defined, write results to stdout.\n");
+" -s [R[:S[:N]] the micro organisms are spherical meshes discretised in N\n"
+" points along 2PI. Their radius is distributed with respect to a\n"
+" lognormal distribution:\n"
+" 1/(ln(S)*x*sqrt(2PI)) * exp(-(ln(x)-ln(R))^2 / (2*ln(S)^2))\n"
+" Default is %g:%g:%u.\n",
+ SCHIFF_DISTRIBUTION_SPHERE_DEFAULT.radius,
+ SCHIFF_DISTRIBUTION_SPHERE_DEFAULT.sigma,
+ SCHIFF_DISTRIBUTION_SPHERE_DEFAULT.nthetas);
printf(
-" -r RADIUS mean radius of the lognormal distribution. Default is %g.\n",
- SCHIFF_ARGS_NULL.radius);
- printf(
-" -s SIGMA sigma argument of the lognormal distribution. Default is %g.\n",
- SCHIFF_ARGS_NULL.sigma);
- printf(
-" -w A[:B]... list of wavelengths to integrate in meter. At least one\n"
-" wavelength must be provided.\n");
+" -w A[:B]... list of wavelengths to integrate in meter. At least one\n"
+" wavelength must be provided.\n");
}
static int
@@ -99,12 +99,13 @@ schiff_args_init
char** argv)
{
size_t len;
+ double list[3];
int opt;
res_T res = RES_OK;
ASSERT(argc && argv && args);
*args = SCHIFF_ARGS_NULL;
- while((opt = getopt(argc, argv, "d:g:hn:o:r:s:w:")) != -1) {
+ while((opt = getopt(argc, argv, "d:g:ho:s:w:")) != -1) {
res_T res = RES_OK;
switch(opt) {
case 'd': res = cstr_to_uint(optarg, &args->ndirs); break;
@@ -113,15 +114,19 @@ schiff_args_init
print_help(argv[0]);
schiff_args_release(args);
return RES_OK;
- case 'n': res = cstr_to_uint(optarg, &args->nthetas); break;
case 'o': args->output_filename = optarg; break;
- case 'r':
- res = cstr_to_double(optarg, &args->radius);
- if(res == RES_OK && args->radius < 0.0) res = RES_BAD_ARG;
- break;
case 's':
- res = cstr_to_double(optarg, &args->sigma);
- if(res == RES_OK && args->sigma < 0.0) res = RES_BAD_ARG;
+ res = cstr_to_list_double(optarg, list, &len, 3);
+ if(res == RES_OK) {
+ args->distribution.sphere = SCHIFF_DISTRIBUTION_SPHERE_DEFAULT;
+ if(len > 0) args->distribution.sphere.radius = list[0];
+ if(len > 1) args->distribution.sphere.sigma = list[1];
+ if(len > 2) {
+ args->distribution.sphere.nthetas = (unsigned)list[2];
+ if((double)args->distribution.sphere.nthetas != list[2])
+ res = RES_BAD_ARG;
+ }
+ }
break;
case 'w':
sa_clear(args->wavelengths);
diff --git a/src/schiff_args.h b/src/schiff_args.h
@@ -31,26 +31,37 @@
#include <rsys/rsys.h>
+struct schiff_distribution_sphere {
+ double radius;
+ double sigma;
+ unsigned nthetas;
+};
+#define SCHIFF_DISTRIBUTION_SPHERE_DEFAULT__ {1.0, 1.0, 64}
+static const struct schiff_distribution_sphere
+SCHIFF_DISTRIBUTION_SPHERE_DEFAULT = SCHIFF_DISTRIBUTION_SPHERE_DEFAULT__;
+
+union schiff_distribution {
+ struct schiff_distribution_sphere sphere;
+};
+
+#define SCHIFF_DISTRIBUTION_DEFAULT__ {SCHIFF_DISTRIBUTION_SPHERE_DEFAULT__}
+
struct schiff_args {
const char* output_filename;
struct schiff_optical_properties* properties;
double* wavelengths;
- double radius;
- double sigma;
+ union schiff_distribution distribution;
unsigned ngeoms;
unsigned ndirs;
- unsigned nthetas;
};
static const struct schiff_args SCHIFF_ARGS_NULL = {
NULL, /* Output filename */
NULL, /* List of optical properties */
NULL, /* List of wavelength to integrate */
- 1.0, /* Mean radius */
- 1.0, /* Sigma */
+ SCHIFF_DISTRIBUTION_DEFAULT__,
1000, /* # Sampled geometries */
100, /* # Sampled directions per gemetry */
- 64 /* # Discret points along 2PI */
};
extern LOCAL_SYM res_T
diff --git a/src/schiff_sphere.c b/src/schiff_sphere.c
@@ -49,8 +49,8 @@ struct sphere {
struct schiff_sphere_geometry_distribution_context {
struct schiff_mesh* mesh; /* Triangular mesh of an unit sphere */
struct schiff_optical_properties* properties; /* Per wavelength properties */
- double mean_radius; /* Mean radius of the log normal sphere distribution */
- double sigma; /* Sigma argument of the log normal sphere distribution */
+ double log_mean_radius; /* Log of the mean sphere radius */
+ double log_sigma; /* Log of the sigma argument of the lognormal distribution*/
};
/*******************************************************************************
@@ -133,7 +133,7 @@ schiff_sphere_sample_geometry
sphere.mesh = ctx->mesh;
sphere.radius = (float)ssp_ran_lognormal
- (rng, log(ctx->mean_radius), log(ctx->sigma));
+ (rng, ctx->log_mean_radius, ctx->log_sigma);
attrib.usage = S3D_POSITION;
attrib.type = S3D_FLOAT3;
@@ -179,11 +179,12 @@ schiff_run_sphere(const struct schiff_args* args)
}
/* Generate the spherical mesh */
- res = schiff_mesh_init_sphere(&mem_default_allocator, &mesh, args->nthetas);
+ res = schiff_mesh_init_sphere
+ (&mem_default_allocator, &mesh, args->distribution.sphere.nthetas);
if(res != RES_OK) {
fprintf(stderr,
"Couldn't create the sphere mesh discretised in %u steps along 2PI\n",
- args->nthetas);
+ args->distribution.sphere.nthetas);
goto error;
}
@@ -203,8 +204,8 @@ schiff_run_sphere(const struct schiff_args* args)
/* Setup the geometry distribution context */
ctx.mesh = &mesh;
ctx.properties = args->properties;
- ctx.mean_radius = args->radius;
- ctx.sigma = args->sigma;
+ ctx.log_mean_radius = log(args->distribution.sphere.radius);
+ ctx.log_sigma = log(args->distribution.sphere.sigma);
/* Setup the geometry distribution */
distrib.sample = schiff_sphere_sample_geometry;