commit 4c97784d48b341ca409e1c12892b4b8b742daa5f
parent d3148f07ab4939da6ba21a9bdf43e16b37099dae
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 14 Mar 2016 09:10:29 +0100
Add comments
Diffstat:
3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/schiff_args.c b/src/schiff_args.c
@@ -572,6 +572,8 @@ parse_yaml_cylinder
mask |= HEIGHT;
res = parse_yaml_param_distribution
(filename, doc, val, &geom->data.cylinder.height);
+
+ /* Cylinder aspect ratio */
} else if(!strcmp((char*)key->data.scalar.value, "aspect_ratio")) {
if(mask & ASPECT_RATIO) {
log_err(filename, key, "the aspect_ratio is already defined.\n");
@@ -580,6 +582,8 @@ parse_yaml_cylinder
mask |= ASPECT_RATIO;
res = parse_yaml_double
(filename, val, &geom->data.cylinder.aspect_ratio);
+
+ /* # slices used to discretized the triangular cylinder */
} else if(!strcmp((char*)key->data.scalar.value, "slices")) {
if(mask & SLICES) {
log_err(filename, key,
@@ -588,6 +592,8 @@ parse_yaml_cylinder
}
mask |= SLICES;
res = parse_yaml_uint(filename, val, &geom->data.cylinder.nslices);
+
+ /* Error */
} else {
log_err(filename, key, "unkown cylinder attribute `%s'.\n",
key->data.scalar.value);
@@ -661,6 +667,7 @@ parse_yaml_sphere
val = yaml_document_get_node(doc, node->data.mapping.pairs.start[i].value);
ASSERT(key->type == YAML_SCALAR_NODE);
+ /* Probality to sample this geometry */
if(!strcmp((char*)key->data.scalar.value, "proba")) {
if(mask & PROBA) {
log_err(filename, node, "the sphere proba is already defined.\n");
@@ -668,6 +675,8 @@ parse_yaml_sphere
}
mask |= PROBA;
res = parse_yaml_double(filename, val, geom_proba);
+
+ /* Sphere radius */
} else if(!strcmp((char*)key->data.scalar.value, "radius")) {
if(mask & RADIUS) {
log_err(filename, key, "the sphere radius is already defined.\n");
@@ -676,6 +685,8 @@ parse_yaml_sphere
mask |= RADIUS;
res = parse_yaml_param_distribution
(filename, doc, val, &geom->data.sphere.radius);
+
+ /* # slices used to discretized the triangulare sphere */
} else if(!strcmp((char*)key->data.scalar.value, "slices")) {
if(mask & SLICES) {
log_err(filename, key,
@@ -684,6 +695,8 @@ parse_yaml_sphere
}
mask |= SLICES;
res = parse_yaml_uint(filename, val, &geom->data.sphere.nslices);
+
+ /* Error */
} else {
log_err(filename, key, "unkown sphere attribute `%s'.\n",
key->data.scalar.value);
@@ -758,9 +771,11 @@ parse_yaml
goto error;
}
+ /* Define the number of submitted distributions */
ndistribs = (size_t)
(root->data.sequence.items.top - root->data.sequence.items.start);
+ /* Allocate the list geometry distributions */
if(!sa_add(geoms, ndistribs)) {
log_err(filename, root,
"couldn't allocate up to %lu geometry distributions.\n",
@@ -771,6 +786,7 @@ parse_yaml
FOR_EACH(idistrib, 0, ndistribs)
geoms[idistrib] = SCHIFF_GEOMETRY_NULL;
+ /* Allocate the per geometry distribution proba */
if(!sa_add(probas, ndistribs)) {
log_err(filename, root,
"couldn't allocate the list of geometry distribution probabilities.\n");
@@ -778,6 +794,7 @@ parse_yaml
goto error;
}
+ /* Create the geometry distribution random variate */
res = ssp_ran_discrete_create(&mem_default_allocator, &ran);
if(res != RES_OK) {
log_err(filename, root,
@@ -785,6 +802,7 @@ parse_yaml
goto error;
}
+ /* Parse the geometry distributions */
accum_proba = 0;
FOR_EACH(idistrib, 0, ndistribs) {
yaml_node_t* distrib, *key, *val;
@@ -819,10 +837,12 @@ parse_yaml
accum_proba += probas[idistrib];
}
- FOR_EACH(idistrib, 0, ndistribs) {
+ /* Normalized the geometry distribution probabilities */
+ FOR_EACH(idistrib, 0, ndistribs-1)
probas[idistrib] /= accum_proba;
- }
+ probas[ndistribs-1] = 1.f; /* Handle precision issues */
+ /* Setup the geometry distributions random variate */
res = ssp_ran_discrete_setup(ran, probas, ndistribs);
if(res != RES_OK) {
log_err(filename, root,
diff --git a/src/schiff_args.h b/src/schiff_args.h
@@ -38,13 +38,14 @@ struct schiff_args {
struct schiff_optical_properties* properties; /* List of properties */
double* wavelengths; /* List of wavelengths to integrate */
- double caracteristic_length;
+ double caracteristic_length; /* Caracteristic length of the soft particles */
- /* List of geometry and its associated random variates */
+ /* List of parsed geometry distribution parameters and its associated random
+ * variate */
struct schiff_geometry* geoms;
struct ssp_ran_discrete* ran_geoms;
- unsigned ngeoms_dump; /* # geometries to dump */
+ unsigned ngeoms_dump; /* # sampled geometries to dump */
unsigned nrealisations; /* # realisation */
unsigned ndirs; /* Number of directions to sample per realisation */
unsigned nangles; /* Number of scattering angles */
diff --git a/src/schiff_geometry.c b/src/schiff_geometry.c
@@ -105,6 +105,7 @@ histogram_sample
double v;
ASSERT(entries && nentries && lower < upper && u >= 0 && u < 1.0);
+ /* Search for the first entry that is gequal than the canonical variable u */
find = search_lower_bound(&u, entries, nentries, sizeof(double), cmp_double);
if(!find) /* Handle numerical issue */
@@ -115,7 +116,7 @@ histogram_sample
to = from + step;
/* Linear interpolation */
- v = (u - from) / step;
+ v = CLAMP((u - from) / step, 0.0, 1.0);
if(eq_eps(v, 0, 1.e-6)) {
return from;
} else if(eq_eps(v, 1, 1.e-6)) {