commit e22e0f6696d2bc93656b223dea6f0c646a4bb568
parent 46285200a49daf56c2bb1dc33600034ab15aee0c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 28 Apr 2020 12:05:49 +0200
Merge branch 'release_0.4'
Diffstat:
12 files changed, 589 insertions(+), 448 deletions(-)
diff --git a/README.md b/README.md
@@ -32,12 +32,26 @@ package as well as all the aforementioned Star-Schiff prerequisites. Then
generate the project from the `cmake/CMakeLists.txt` file by appending to the
`CMAKE_PREFIX_PATH` variable the install directories of its dependencies.
-## License
-
-Star-Schiff is developed by [|Meso|Star>](http://www.meso-star.com) for the
-[National Center for Scientific Research](http://www.cnrs.fr/index.php) (CNRS).
-It is a free software copyright (C) CNRS 2015-2016 released under the
-[OSI](http://opensource.org)-approved GPL v3+ license. You are welcome to
-redistribute it under certain conditions; refer to the COPYING file for
-details.
+## Release notes
+
+### Version 0.4
+
+- Update the `struct sschiff_geometry_distribution` data structure. The
+ `sample` function now only samples the particle geometry. Its volume scaling
+ is sampled through the new `sample_volume_scaling` function. This scaling
+ factor is now sampled at the same frequency than the particle orientation,
+ i.e. several times per sampled particle geometry.
+- Relax constraints on the minimum number of scattering angles. It is now set
+ to 2 rather than 3, i.e. the scattering can be purely forward or backward.
+- Overall update of the project dependencies. Most notably, the update of the
+ Star-3D library drastically improves the performances of sampling particles
+ with the same shape.
+- Add an option to avoid the analytic computations of wide angles.
+
+## Copying
+
+Copyright (C) 2020 |Meso|Star> (contact@meso-star.com). Copyright (C) 2015, 2016
+CNRS. Star-Schiff is free software released under the GPL v3+ license: GNU GPL
+version 3 or later. You are welcome to redistribute it under certain
+conditions; refer to the COPYING file for details.
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Copyright (C) 2015-2016 CNRS
+# Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+# Copyright (C) 2015, 2016 CNRS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,10 +24,10 @@ option(NO_TEST "Disable the test" OFF)
################################################################################
# Check dependencies
################################################################################
-find_package(RCMake 0.2.3 REQUIRED)
-find_package(RSys 0.3 REQUIRED)
-find_package(StarSP 0.3 REQUIRED)
-find_package(Star3D 0.3 REQUIRED)
+find_package(RCMake 0.4 REQUIRED)
+find_package(RSys 0.8 REQUIRED)
+find_package(StarSP 0.8 REQUIRED)
+find_package(Star3D 0.7 REQUIRED)
find_package(OpenMP 1.2 REQUIRED)
find_package(PkgConfig REQUIRED)
@@ -53,13 +54,14 @@ include_directories(
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
include(rcmake)
include(rcmake_runtime)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
################################################################################
# Configure and define targets
################################################################################
set(VERSION_MAJOR 0)
-set(VERSION_MINOR 3)
-set(VERSION_PATCH 1)
+set(VERSION_MINOR 4)
+set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(SSCHIFF_FILES_SRC
diff --git a/src/sschiff.h b/src/sschiff.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -69,16 +70,21 @@ static const struct sschiff_material SSCHIFF_NULL_MATERIAL = { NULL, NULL };
struct sschiff_geometry_distribution {
struct sschiff_material material; /* Material of the geometry distribution */
double characteristic_length;
- res_T (*sample) /* Sample a geometry i.e. a shape and its material */
+ res_T (*sample) /* Sample a geometry i.e. a shape */
(struct ssp_rng* rng,
- struct s3d_shape* shape, /* Sampled shape */
+ void** shape, /* Returned client side data of the sampled shape */
+ struct s3d_shape* s3d_shape, /* Star-3D shape where geometry are stored */
+ void* context);
+ res_T (*sample_volume_scaling) /* Can be NULL <=> No volume scaling */
+ (struct ssp_rng* rng,
+ void* shape, /* Client side shape into which a volume scaling is sampled */
double* scale_factor, /* Scale factor to apply to the shape volume */
void* context);
void* context;
};
static const struct sschiff_geometry_distribution
-SSCHIFF_NULL_GEOMETRY_DISTRIBUTION = { {NULL, NULL}, -1.0, NULL, NULL };
+SSCHIFF_NULL_GEOMETRY_DISTRIBUTION = { {NULL, NULL}, -1.0, NULL, NULL, NULL };
/* State of the Monte Carlo estimation */
struct sschiff_state {
@@ -94,7 +100,7 @@ struct sschiff_cross_section {
struct sschiff_state average_projected_area;
};
-/* Type of the function use to distribute the scattering angles in [0, PI].
+/* Type of the function used to distribute the scattering angles in [0, PI].
* nangles is assumed to be greater than or equal to 2 and the angles is
* ensured to have `nangles' entries. */
typedef void (*sschiff_scattering_angles_distribution_T)
@@ -149,6 +155,7 @@ sschiff_integrate
const size_t scattering_angles_count, /* # scattering angles. Must be >= 3 */
const size_t sampled_geometries_count, /* # geometries to sample */
const size_t sampled_directions_count, /* # directions to sample per geometry */
+ const int discard_wide_angles, /* Avoid analytic model for wide angles */
struct sschiff_estimator** estimator);
SSCHIFF_API res_T
diff --git a/src/sschiff_device.c b/src/sschiff_device.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/sschiff_device.h b/src/sschiff_device.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/sschiff_estimator.c b/src/sschiff_estimator.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -79,6 +80,8 @@ struct integrator_context {
/* Geometry of the micro particle */
struct s3d_shape* shape;
struct s3d_scene* scene;
+ struct s3d_scene_view* view;
+ void* shape_data; /* Client side data of the shape */
struct ssp_rng* rng; /* Random Number Generator */
size_t nwavelengths; /* #wavelengths */
@@ -116,6 +119,7 @@ struct sschiff_estimator {
size_t nrealisations; /* # realisation used by MC estimations */
int no_phase_function; /* Set to 1 when no phase function is computed */
+ int discard_large_angles; /* Avoid analytic model for wide angles */
struct sschiff_device* dev;
ref_T ref;
@@ -245,7 +249,7 @@ self_hit
static res_T
compute_path_length
(struct sschiff_device* dev,
- struct s3d_scene* scn,
+ struct s3d_scene_view* view,
const struct s3d_hit* first_hit,
const float ray_org[3],
const float ray_dir[3],
@@ -256,7 +260,7 @@ compute_path_length
struct s3d_hit hit_from, hit;
double len = 0;
float dst;
- ASSERT(scn && first_hit && ray_org && ray_dir && !S3D_HIT_NONE(first_hit));
+ ASSERT(view && first_hit && ray_org && ray_dir && !S3D_HIT_NONE(first_hit));
ASSERT(scale > 0);
(void)dev;
@@ -266,7 +270,7 @@ compute_path_length
do {
do {
range[0] = nextafterf(range[0], range[1]);
- S3D(scene_trace_ray(scn, ray_org, ray_dir, range, NULL, &hit));
+ S3D(scene_view_trace_ray(view, ray_org, ray_dir, range, NULL, &hit));
} while(hit.distance < range[0] || self_hit(&hit_from, &hit, 1.e-6f));
if(S3D_HIT_NONE(&hit))
@@ -278,7 +282,7 @@ compute_path_length
do {
range[0] = nextafterf(range[0], range[1]);
- S3D(scene_trace_ray(scn, ray_org, ray_dir, range, NULL, &hit));
+ S3D(scene_view_trace_ray(view, ray_org, ray_dir, range, NULL, &hit));
} while(hit.distance < range[0] || self_hit(&hit_from, &hit, 1.e-6f));
range[0] = hit.distance;
@@ -437,12 +441,12 @@ accum_monte_carlo_weight
f3_mulf(y, axis_y, (float)sample[1]);
f3_add(ray_org[0], f3_add(ray_org[0], x, y), org);
- S3D(scene_trace_ray(ctx->scene, ray_org[0], axis_z, range, NULL, &hit));
+ S3D(scene_view_trace_ray(ctx->view, ray_org[0], axis_z, range, NULL, &hit));
/* NULL cross section and differential cross section weight */
if(S3D_HIT_NONE(&hit))
break;
- res = compute_path_length(dev, ctx->scene, &hit, ray_org[0], axis_z,
+ res = compute_path_length(dev, ctx->view, &hit, ray_org[0], axis_z,
dist_scaling, &path_length[0]);
if(res != RES_OK) { /* Handle numerical/geometry issues */
++nfailures;
@@ -462,11 +466,11 @@ accum_monte_carlo_weight
f3_mulf(y, axis_y, (float)sample[1]);
f3_add(ray_org[1], f3_add(ray_org[1], x, y), org);
- S3D(scene_trace_ray(ctx->scene, ray_org[1], axis_z, range, NULL, &hit));
+ S3D(scene_view_trace_ray(ctx->view, ray_org[1], axis_z, range, NULL, &hit));
if(S3D_HIT_NONE(&hit)) /* NULL differential cross section weight */
break;
- res = compute_path_length(dev, ctx->scene, &hit, ray_org[1], axis_z,
+ res = compute_path_length(dev, ctx->view, &hit, ray_org[1], axis_z,
dist_scaling, &path_length[1]);
if(res != RES_OK) { /* Handle numerical/geometry issues */
++nfailures;
@@ -495,8 +499,7 @@ radiative_properties
(struct sschiff_device* dev,
const int istep,
const size_t ndirs,
- const double area_scaling, /* Scale factor to apply to the areas */
- const double dist_scaling, /* Scale factor to apply to the distances */
+ struct sschiff_geometry_distribution* distrib,
struct integrator_context* ctx)
{
float lower[3], upper[3];
@@ -506,10 +509,10 @@ radiative_properties
size_t iwlen;
int i;
res_T res = RES_OK;
- ASSERT(dev && ndirs && ctx && area_scaling > 0 && dist_scaling > 0);
+ ASSERT(dev && ndirs && distrib && ctx);
(void)istep;
- S3D(scene_get_aabb(ctx->scene, lower, upper));
+ S3D(scene_view_get_aabb(ctx->view, lower, upper));
/* AABB vertex layout
* 6-------7
@@ -547,12 +550,36 @@ radiative_properties
}
FOR_EACH(idir, 0, ndirs) {
- float dir[4];
+ float dir[3];
float basis[9];
float transform[12];
float pt[8][3];
+ double volume_scaling = 1.0;
+ double area_scaling = 1.0;
+ double dist_scaling = 1.0;
+
+ /* Sample a volume scaling factor if necessary */
+ if(distrib->sample_volume_scaling) {
+ res = distrib->sample_volume_scaling
+ (ctx->rng, ctx->shape_data, &volume_scaling, distrib->context);
+ if(res != RES_OK) {
+ log_error(dev, "Error in sampling a volume scaling.\n");
+ goto error;
+ }
+ if(volume_scaling <= 0) {
+ log_error(dev, "Invalid volume scale factor `%g'.\n", volume_scaling);
+ res = RES_BAD_ARG;
+ goto error;
+ }
- ssp_ran_sphere_uniform(ctx->rng, dir);
+ /* Define the scale factor to apply the the area and the distance from the
+ * scale factor of the volume */
+ area_scaling = pow(volume_scaling, 2.0/3.0);
+ dist_scaling = pow(volume_scaling, 1.0/3.0);
+ }
+
+ /* Sample an orientation */
+ ssp_ran_sphere_uniform_float(ctx->rng, dir, NULL);
/* Build the transformation matrix from world to footprint space. Use the
* AABB centroid as the origin of the footprint space. */
@@ -789,7 +816,54 @@ compute_differential_cross_section_cumulative_term
}
static res_T
-compute_phase_function
+compute_small_scattering_angles_properties
+ (struct sschiff_device* dev,
+ struct solver_context* ctx,
+ const size_t iwlen,
+ const size_t nangles,
+ struct sschiff_estimator* estimator)
+{
+ double rcp_scattering_cross_section;
+ double rcp_sqr_scattering_cross_section;
+ struct sschiff_state scattering_cross_section;
+ size_t ilimit_angle;
+ size_t iangle;
+ ASSERT(dev && estimator && iwlen < sa_size(estimator->wavelengths) && ctx);
+ (void)ctx, (void)dev, (void)nangles;
+
+ /* Fetch the limit angle and precompute some values */
+ ilimit_angle = estimator->limit_angles[iwlen]-1;
+
+ get_mc_value
+ (&estimator->accums[iwlen].scattering_cross_section,
+ estimator->nrealisations,
+ &scattering_cross_section);
+
+ /* Compute the [cumulative] phase function for small angles */
+ rcp_scattering_cross_section = 1.0/scattering_cross_section.E;
+ rcp_sqr_scattering_cross_section =
+ rcp_scattering_cross_section * rcp_scattering_cross_section;
+
+ FOR_EACH(iangle, 0, ilimit_angle+1) {
+ struct mc_data mc_data;
+
+ mc_data = estimator->accums[iwlen].differential_cross_section[iangle];
+ mc_data.weight *= rcp_scattering_cross_section;
+ mc_data.sqr_weight *= rcp_sqr_scattering_cross_section;
+ get_mc_value(&mc_data, estimator->nrealisations,
+ &estimator->phase_functions[iwlen].values[iangle]);
+
+ mc_data = estimator->accums[iwlen].differential_cross_section_cumulative[iangle];
+ mc_data.weight *= rcp_scattering_cross_section;
+ mc_data.sqr_weight *= rcp_sqr_scattering_cross_section;
+ get_mc_value(&mc_data, estimator->nrealisations,
+ &estimator->phase_functions[iwlen].cumulative[iangle]);
+ }
+ return RES_OK;
+}
+
+static res_T
+compute_large_scattering_angles_properties
(struct sschiff_device* dev,
struct solver_context* ctx,
const size_t iwlen,
@@ -803,7 +877,6 @@ compute_phase_function
double coef_limit;
double n, r; /* Connector values */
double rcp_scattering_cross_section;
- double rcp_sqr_scattering_cross_section;
struct sschiff_state scattering_cross_section;
struct sschiff_state limit_differential_cross_section;
struct sschiff_state limit_differential_cross_section_cumulative;
@@ -850,14 +923,16 @@ compute_phase_function
"angles. The phase function is thus not computed.\n"
"Wavelength = %g micron\n",
estimator->wavelengths[iwlen]);
-
goto error;
}
if(n < 2 || n > 4) {
log_warning(estimator->dev,
"The wide scattering angles phase function model parameter `n' is not in\n"
-"[2, 4]. One might increase the number of realisations.\n"
+"[2, 4]. One might increase the number of realisations and/or adjust the\n"
+"characteristic length of the particles (that sets the limit between small\n"
+"and large scattering angles) and/or increase the number of scattering\n"
+"angles computed.\n"
" wavelength = %g micron\n"
" n = %g\n"
" scattering cross section = %g +/- %g\n"
@@ -906,31 +981,8 @@ compute_phase_function
limit_differential_cross_section_cumulative.E + 2*PI*r*(coef-coef_limit);
}
- /* Check the post condition of the cumulative differential cross section */
- /*ASSERT(eq_eps
- (estimator->accums[iwlen].differential_cross_section_cumulative[nangles-1].weight,
- scattering_cross_section.E, 1.e-3));*/
-
- /* Compute the [cumulative] phase function for small angles */
- rcp_scattering_cross_section = 1.0/scattering_cross_section.E;
- rcp_sqr_scattering_cross_section =
- rcp_scattering_cross_section * rcp_scattering_cross_section;
- FOR_EACH(iangle, 0, ilimit_angle+1) {
- struct mc_data mc_data;
-
- mc_data = estimator->accums[iwlen].differential_cross_section[iangle];
- mc_data.weight *= rcp_scattering_cross_section;
- mc_data.sqr_weight *= rcp_sqr_scattering_cross_section;
- get_mc_value(&mc_data, estimator->nrealisations,
- &estimator->phase_functions[iwlen].values[iangle]);
-
- mc_data = estimator->accums[iwlen].differential_cross_section_cumulative[iangle];
- mc_data.weight *= rcp_scattering_cross_section;
- mc_data.sqr_weight *= rcp_sqr_scattering_cross_section;
- get_mc_value(&mc_data, estimator->nrealisations,
- &estimator->phase_functions[iwlen].cumulative[iangle]);
- }
/* Compute the [cumulative] phase function for wide angles */
+ rcp_scattering_cross_section = 1.0/scattering_cross_section.E;
FOR_EACH(iangle, ilimit_angle + 1, nangles) {
estimator->phase_functions[iwlen].values[iangle].E =
estimator->accums[iwlen].differential_cross_section[iangle].weight
@@ -951,7 +1003,7 @@ compute_phase_function
exit:
return res;
error:
- FOR_EACH(iangle, 0, nangles) {
+ FOR_EACH(iangle, ilimit_angle+1, nangles) {
estimator->phase_functions[iwlen].values[iangle].E = -1;
estimator->phase_functions[iwlen].values[iangle].V = -1;
estimator->phase_functions[iwlen].values[iangle].SE = -1;
@@ -962,6 +1014,31 @@ error:
goto exit;
}
+static res_T
+compute_scattering_angles_properties
+ (struct sschiff_device* dev,
+ struct solver_context* ctx,
+ const size_t iwlen,
+ const size_t nangles,
+ struct sschiff_estimator* estimator)
+{
+ res_T res = RES_OK;
+
+ res = compute_small_scattering_angles_properties
+ (dev, ctx, iwlen, nangles, estimator);
+ if(res != RES_OK) goto error;
+
+ if(!estimator->discard_large_angles) {
+ res = compute_large_scattering_angles_properties
+ (dev, ctx, iwlen, nangles, estimator);
+ if(res != RES_OK) goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
static res_T
inverse_cumulative_phase_function
@@ -990,6 +1067,12 @@ inverse_cumulative_phase_function
iangle = (size_t)(found - cumulative_small_angles);
upper = cumulative_small_angles[iangle];
lower = cumulative_small_angles[iangle-1];
+
+ /* Use the cumulative bounds to linearly interpolate the angles */
+ u = (cumulative - lower) / (upper - lower);
+ *theta = u*estimator->angles[iangle] + (1.0 - u)*estimator->angles[iangle-1];
+ } else if(estimator->discard_large_angles) {
+ *theta = -1;
} else {
/* Look for the cumulative in the wide angles cumulative */
struct sschiff_state cumul;
@@ -1016,12 +1099,11 @@ inverse_cumulative_phase_function
} else {
lower = estimator->phase_functions[iwlen].cumulative[iangle-1].E;
}
+ /* Use the cumulative bounds to linearly interpolate the angles */
+ u = (cumulative - lower) / (upper - lower);
+ *theta = u*estimator->angles[iangle] + (1.0 - u)*estimator->angles[iangle-1];
}
- /* Use the cumulative bounds to linearly interpolate the angles */
- u = (cumulative - lower) / (upper - lower);
- *theta = u*estimator->angles[iangle] + (1.0 - u)*estimator->angles[iangle-1];
-
return RES_OK;
}
@@ -1029,7 +1111,8 @@ static char
check_distribution(struct sschiff_geometry_distribution* distrib)
{
ASSERT(distrib);
- return distrib->sample != NULL && distrib->characteristic_length > 0;
+ return distrib->sample != NULL
+ && distrib->characteristic_length > 0;
}
static void
@@ -1042,6 +1125,7 @@ integrator_context_release(struct integrator_context* ctx)
if(ctx->estimator) SSCHIFF(estimator_ref_put(ctx->estimator));
if(ctx->shape) S3D(shape_ref_put(ctx->shape));
if(ctx->scene) S3D(scene_ref_put(ctx->scene));
+ if(ctx->view) S3D(scene_view_ref_put(ctx->view));
#define RELEASE(Data) if(Data) sa_release(Data)
if(ctx->accums) {
@@ -1072,7 +1156,7 @@ integrator_context_init
{
size_t iwlen;
res_T res = RES_OK;
- ASSERT(ctx && s3d && rng && nwavelengths && nangles >= 3);
+ ASSERT(ctx && s3d && rng && nwavelengths && nangles >= 2);
memset(ctx, 0, sizeof(struct integrator_context));
@@ -1163,37 +1247,34 @@ static res_T
begin_realisation
(struct sschiff_device* dev,
struct sschiff_geometry_distribution* distrib,
- double* volume_scaling,
struct integrator_context* ctx)
{
+ struct s3d_accel_struct_conf accel_struct_conf = S3D_ACCEL_STRUCT_CONF_DEFAULT;
res_T res = RES_OK;
- ASSERT(dev && distrib && volume_scaling && ctx);
+ ASSERT(dev && distrib && ctx && !ctx->view);
/* Sample a particle */
res = distrib->sample
- (ctx->rng, ctx->shape, volume_scaling, distrib->context);
+ (ctx->rng, &ctx->shape_data, ctx->shape, distrib->context);
if(res != RES_OK) {
log_error(dev, "Error in sampling a particle.\n");
goto error;
}
- if(*volume_scaling <= 0) {
- log_error(dev, "Invalid volume scale factor `%g'.\n", *volume_scaling);
- res = RES_BAD_ARG;
- goto error;
- }
+
+ accel_struct_conf.quality = S3D_ACCEL_STRUCT_QUALITY_LOW;
+ accel_struct_conf.mask =
+ S3D_ACCEL_STRUCT_FLAG_ROBUST
+ | S3D_ACCEL_STRUCT_FLAG_DYNAMIC;
/* Build the Star-3D representation of the sampled shape */
- S3D(scene_begin_session(ctx->scene, S3D_TRACE));
+ S3D(scene_view_create2(ctx->scene, S3D_TRACE, &accel_struct_conf, &ctx->view));
exit:
return res;
error:
- {
- /* Disable active session if necessary */
- int mask;
- if(S3D(scene_get_session_mask(ctx->scene, &mask)), mask) {
- S3D(scene_end_session(ctx->scene));
- }
+ if(ctx->view) {
+ S3D(scene_view_ref_put(ctx->view));
+ ctx->view = NULL;
}
goto exit;
}
@@ -1201,8 +1282,9 @@ error:
static FINLINE void
end_realisation(struct integrator_context* ctx)
{
- ASSERT(ctx);
- S3D(scene_end_session(ctx->scene));
+ ASSERT(ctx && ctx->view);
+ S3D(scene_view_ref_put(ctx->view));
+ ctx->view = NULL;
}
static void
@@ -1253,6 +1335,7 @@ estimator_create
const size_t nwavelengths,
sschiff_scattering_angles_distribution_T angles_distrib,
const size_t nangles,
+ const int discard_large_angles,
struct sschiff_estimator** out_estimator)
{
struct sschiff_estimator* estimator = NULL;
@@ -1273,6 +1356,7 @@ estimator_create
ref_init(&estimator->ref);
SSCHIFF(device_ref_get(dev));
estimator->dev = dev;
+ estimator->discard_large_angles = discard_large_angles;
#define RESIZE(Array, Count, ErrMsg) { \
if(!sa_add(Array, Count)) { \
@@ -1363,11 +1447,11 @@ estimator_create
res = RES_BAD_ARG;
goto error;
}
- if(eq_eps(*angle, PI, 1.e-6)) {
+ /* if(eq_eps(*angle, PI, 1.e-6)) {
log_error(dev, "Invalid limit scattering angle `%g'.\n", *angle);
res = RES_BAD_ARG;
goto error;
- }
+ }*/
/* Define the index of the first "wide scattering angle" */
estimator->limit_angles[i] = (size_t)(angle - estimator->angles);
ASSERT(estimator->limit_angles[i] < nangles);
@@ -1438,6 +1522,7 @@ sschiff_integrate
const size_t nangles,
const size_t ngeoms,
const size_t ndirs,
+ const int discard_large_angles,
struct sschiff_estimator** out_estimator)
{
struct integrator_context* ctxs = NULL;
@@ -1451,14 +1536,14 @@ sschiff_integrate
ATOMIC res = (ATOMIC)RES_OK;
if(!dev || !rng || !distrib || !wavelengths || !nwavelengths
- || !angles_distrib || nangles < 3 || !ngeoms || !ndirs || !out_estimator
+ || !angles_distrib || nangles < 2 || !ngeoms || !ndirs || !out_estimator
|| !check_distribution(distrib)) {
return RES_BAD_ARG;
}
/* Create the Schiff estimator */
res = estimator_create(dev, distrib, wavelengths, nwavelengths,
- angles_distrib, nangles, &estimator);
+ angles_distrib, nangles, discard_large_angles, &estimator);
if(res != RES_OK) goto error;
estimator->nrealisations = ngeoms;
@@ -1519,28 +1604,19 @@ sschiff_integrate
#pragma omp parallel for schedule(static)
for(igeom=0; igeom < (int)ngeoms; ++igeom) {
const int ithread = omp_get_thread_num();
- double volume_scaling;
- double area_scaling;
- double dist_scaling;
ATOMIC res_local = RES_OK;
if(ATOMIC_GET(&res) != RES_OK) continue;
/* Setup the data for the current realisation */
- res_local = begin_realisation(dev, distrib, &volume_scaling, ctxs+ithread);
+ res_local = begin_realisation(dev, distrib, ctxs+ithread);
if(res_local != RES_OK) {
ATOMIC_CAS(&res, res_local, RES_OK);
continue;
}
- /* Define the scale factor to apply the the area and the distance from the
- * scale factor of the volume */
- area_scaling = pow(volume_scaling, 2.0/3.0);
- dist_scaling = pow(volume_scaling, 1.0/3.0);
-
/* Schiff Estimation */
- res_local = radiative_properties
- (dev, igeom, ndirs, area_scaling, dist_scaling, ctxs+ithread);
+ res_local = radiative_properties(dev, igeom, ndirs, distrib, ctxs+ithread);
if(res_local != RES_OK) ATOMIC_CAS(&res, res_local, RES_OK);
end_realisation(ctxs + ithread);
@@ -1549,7 +1625,6 @@ sschiff_integrate
/* Merge the per thread integration results */
FOR_EACH(i, 0, dev->nthreads) {
- size_t iwlen;
FOR_EACH(iwlen, 0, nwavelengths) {
size_t iangle;
#define MC_ACCUM(Data) { \
@@ -1580,7 +1655,7 @@ sschiff_integrate
const int ithread = omp_get_thread_num();
if(estimator->limit_angles[iwlen] == INVALID_LIMIT_ANGLE) continue;
/* Do not handle phase function errors */
- compute_phase_function
+ compute_scattering_angles_properties
(dev, &solver_ctxs[ithread], (size_t)iwlen, nangles, estimator);
}
diff --git a/src/sschiff_scattering_angles_distributions.c b/src/sschiff_scattering_angles_distributions.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/test_sschiff_device.c b/src/test_sschiff_device.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -42,58 +43,58 @@ main(int argc, char** argv)
(void)argc, (void)argv;
- CHECK(sschiff_device_create(NULL, NULL, N, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_create(NULL, NULL, N, 0, NULL, &dev), RES_OK);
+ CHK(sschiff_device_create(NULL, NULL, N, 0, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_create(NULL, NULL, N, 0, NULL, &dev) == RES_OK);
- CHECK(sschiff_device_ref_get(NULL), RES_BAD_ARG);
- CHECK(sschiff_device_ref_get(dev), RES_OK);
- CHECK(sschiff_device_ref_put(NULL), RES_BAD_ARG);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
+ CHK(sschiff_device_ref_get(NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_ref_get(dev) == RES_OK);
+ CHK(sschiff_device_ref_put(NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
- CHECK(sschiff_device_create(NULL, &allocator, N, 1, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_create(NULL, &allocator, N, 1, NULL, &dev), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
- CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
+ CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
+ CHK(sschiff_device_create(NULL, &allocator, N, 1, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_create(NULL, &allocator, N, 1, NULL, &dev) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
+ CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
- CHECK(logger_init(&allocator, &logger), RES_OK);
+ CHK(logger_init(&allocator, &logger) == RES_OK);
logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
- CHECK(sschiff_device_create(&logger, NULL, N, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_create(&logger, NULL, N, 0, NULL, &dev), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
+ CHK(sschiff_device_create(&logger, NULL, N, 0, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_create(&logger, NULL, N, 0, NULL, &dev) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
- CHECK(sschiff_device_create(&logger, &allocator, N, 1, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_create(&logger, &allocator, N, 1, NULL, &dev), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
+ CHK(sschiff_device_create(&logger, &allocator, N, 1, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_create(&logger, &allocator, N, 1, NULL, &dev) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
- CHECK(s3d_device_create(NULL, NULL, 0, &s3d), RES_OK);
- CHECK(sschiff_device_create(NULL, NULL, N, 0, s3d, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_create(NULL, NULL, N, 0, s3d, &dev), RES_OK);
+ CHK(s3d_device_create(NULL, NULL, 0, &s3d) == RES_OK);
+ CHK(sschiff_device_create(NULL, NULL, N, 0, s3d, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_create(NULL, NULL, N, 0, s3d, &dev) == RES_OK);
- CHECK(s3d_device_ref_put(s3d), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
+ CHK(s3d_device_ref_put(s3d) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
- CHECK(sschiff_device_create(NULL, NULL, 0, 0, NULL, &dev), RES_BAD_ARG);
- CHECK(sschiff_device_create(NULL, NULL, 1, 0, NULL, &dev), RES_OK);
+ CHK(sschiff_device_create(NULL, NULL, 0, 0, NULL, &dev) == RES_BAD_ARG);
+ CHK(sschiff_device_create(NULL, NULL, 1, 0, NULL, &dev) == RES_OK);
- CHECK(sschiff_device_get_threads_count(NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_get_threads_count(dev, NULL), RES_BAD_ARG);
- CHECK(sschiff_device_get_threads_count(NULL, &nthreads), RES_BAD_ARG);
- CHECK(sschiff_device_get_threads_count(dev, &nthreads), RES_OK);
- CHECK(nthreads, 1);
+ CHK(sschiff_device_get_threads_count(NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_get_threads_count(dev, NULL) == RES_BAD_ARG);
+ CHK(sschiff_device_get_threads_count(NULL, &nthreads) == RES_BAD_ARG);
+ CHK(sschiff_device_get_threads_count(dev, &nthreads) == RES_OK);
+ CHK(nthreads == 1);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
logger_release(&logger);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}
diff --git a/src/test_sschiff_estimator_cylinder.c b/src/test_sschiff_estimator_cylinder.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -48,7 +49,7 @@ get_material_property
struct sschiff_material_properties* props)
{
(void)mtl;
- CHECK(eq_eps(wavelength, 0.6, 1.e-6), 1);
+ CHK(eq_eps(wavelength, 0.6, 1.e-6) == 1);
props->medium_refractive_index = 4.0/3.0;
props->relative_imaginary_refractive_index = 4.e-3;
props->relative_real_refractive_index = 1.01;
@@ -57,20 +58,35 @@ get_material_property
static res_T
sample_cylinder
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
+ void* sampler_context)
+{
+ struct sampler_context* sampler_ctx = sampler_context;
+ ASSERT(sampler_context && shape_data);
+ (void)rng;
+ *shape_data = (void*)((intptr_t)0xDECAFBAD);
+ return s3d_mesh_copy(sampler_ctx->shape, shape);
+}
+
+static res_T
+sample_volume_scaling
+ (struct ssp_rng* rng,
+ void* shape,
double* volume_scaling,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
- double sphere_volume;
double sample;
-
- NCHECK(volume_scaling, NULL);
+ double sphere_volume;
+ ASSERT(sampler_context);
+
+ CHK(shape == (void*)((intptr_t)0xDECAFBAD));
sample = ssp_ran_lognormal(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
sphere_volume = 4.0*PI*sample*sample*sample / 3.0;
*volume_scaling = sphere_volume / sampler_ctx->cylinder_volume;
- return s3d_mesh_copy(sampler_ctx->shape, shape);
+ return RES_OK;
}
static INLINE void
@@ -420,12 +436,12 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(s3d_device_create(NULL, &allocator, 0, &s3d), RES_OK);
- CHECK(s3d_shape_create_mesh(s3d, &shape), RES_OK);
+ CHK(s3d_device_create(NULL, &allocator, 0, &s3d) == RES_OK);
+ CHK(s3d_shape_create_mesh(s3d, &shape) == RES_OK);
- CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(sschiff_device_create
- (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, s3d, &dev), RES_OK);
+ CHK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng) == RES_OK);
+ CHK(sschiff_device_create
+ (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, s3d, &dev) == RES_OK);
geometry_init_cylinder(&geometry, 64);
cylinder.geometry = &geometry;
@@ -450,18 +466,19 @@ main(int argc, char** argv)
distrib.material.get_property = get_material_property;
distrib.material.material = &sampler_ctx;
distrib.sample = sample_cylinder;
+ distrib.sample_volume_scaling = sample_volume_scaling;
distrib.context = &sampler_ctx;
time_current(&t0);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
- sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs,
- &estimator), RES_OK);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
+ sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs, 0,
+ &estimator) == RES_OK);
time_current(&t1);
time_sub(&t0, &t1, &t0);
time_dump(&t0, TIME_MIN|TIME_SEC|TIME_MSEC, NULL, buf, sizeof(buf));
- CHECK(sschiff_estimator_get_cross_section
- (estimator, 0, &cross_section), RES_OK);
+ CHK(sschiff_estimator_get_cross_section
+ (estimator, 0, &cross_section) == RES_OK);
printf("%u - x = %g - Wavelength = %g micron - %s\n",
(unsigned)i, x[i], wavelength, buf);
@@ -473,7 +490,7 @@ main(int argc, char** argv)
printf(" Extinction ~ %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
results[i].extinction_E, results[i].extinction_SE,
val->E, val->SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
val = &cross_section.absorption;
result.E = results[i].absorption_E;
@@ -482,7 +499,7 @@ main(int argc, char** argv)
printf(" Absorption ~ %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
results[i].absorption_E, results[i].absorption_SE,
val->E, val->SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
val = &cross_section.scattering;
result.E = results[i].scattering_E;
@@ -491,7 +508,7 @@ main(int argc, char** argv)
printf(" Scattering ~ %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
results[i].scattering_E, results[i].scattering_SE,
val->E, val->SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
val = &cross_section.average_projected_area;
result.E = results[i].avg_proj_area_E;
@@ -500,21 +517,21 @@ main(int argc, char** argv)
printf(" Proj Area ~ %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
results[i].avg_proj_area_E, results[i].avg_proj_area_SE,
val->E, val->SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
- CHECK(sschiff_estimator_ref_put(estimator), RES_OK);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
}
- CHECK(sschiff_device_ref_put(dev), RES_OK);
- CHECK(ssp_rng_ref_put(rng), RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
+ CHK(ssp_rng_ref_put(rng) == RES_OK);
- CHECK(s3d_device_ref_put(s3d), RES_OK);
- CHECK(s3d_shape_ref_put(shape), RES_OK);
+ CHK(s3d_device_ref_put(s3d) == RES_OK);
+ CHK(s3d_shape_ref_put(shape) == RES_OK);
geometry_release(&geometry);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}
diff --git a/src/test_sschiff_estimator_rhodo.c b/src/test_sschiff_estimator_rhodo.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -2552,20 +2553,34 @@ get_material_property
static res_T
sample_cylinder
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
+ void* sampler_context)
+{
+ struct sampler_context* sampler_ctx = sampler_context;
+ CHK(sampler_context && shape_data);
+ (void)rng;
+ *shape_data = NULL;
+ return s3d_mesh_copy(sampler_ctx->shape, shape);
+}
+
+static res_T
+sample_volume_scaling
+ (struct ssp_rng* rng,
+ void* shape,
double* volume_scaling,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
double sphere_volume;
double sample;
-
- NCHECK(volume_scaling, NULL);
+ CHK(volume_scaling != NULL);
+ CHK(shape == NULL);
sample = ssp_ran_lognormal(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
sphere_volume = 4.0*PI*sample*sample*sample / 3.0;
*volume_scaling = sphere_volume / sampler_ctx->cylinder_volume;
- return s3d_mesh_copy(sampler_ctx->shape, shape);
+ return RES_OK;
}
struct cross_section_result {
@@ -2612,11 +2627,11 @@ main(int argc, char** argv)
(void)argc, (void)argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(s3d_device_create(NULL, &allocator, 0, &s3d), RES_OK);
- CHECK(s3d_shape_create_mesh(s3d, &shape), RES_OK);
- CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(sschiff_device_create
- (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, NULL, &dev), RES_OK);
+ CHK(s3d_device_create(NULL, &allocator, 0, &s3d) == RES_OK);
+ CHK(s3d_shape_create_mesh(s3d, &shape) == RES_OK);
+ CHK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng) == RES_OK);
+ CHK(sschiff_device_create
+ (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, NULL, &dev) == RES_OK);
geometry_init_cylinder(&geometry, 64);
cylinder.geometry = &geometry;
@@ -2641,14 +2656,15 @@ main(int argc, char** argv)
distrib.material.get_property = get_material_property;
distrib.material.material = &sampler_ctx;
distrib.sample = sample_cylinder;
+ distrib.sample_volume_scaling = sample_volume_scaling;
distrib.context = &sampler_ctx;
- CHECK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
- sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs,
- &estimator), RES_OK);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
+ sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs, 0,
+ &estimator) == RES_OK);
- CHECK(sschiff_estimator_get_cross_section
- (estimator, 0, &cross_section), RES_OK);
+ CHK(sschiff_estimator_get_cross_section
+ (estimator, 0, &cross_section) == RES_OK);
printf("Wavelength = %g micron\n", wavelength);
@@ -2658,7 +2674,7 @@ main(int argc, char** argv)
compute_estimation_intersection(interval, 4, &result, val);
printf(" Extinction = %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
result.E, result.SE, val->E, val->SE, interval[1]-interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
result.E = cross_section_result.absorption_E;
result.SE = cross_section_result.absorption_SE;
@@ -2666,7 +2682,7 @@ main(int argc, char** argv)
compute_estimation_intersection(interval, 4, &result, val);
printf(" Absorption = %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
result.E, result.SE, val->E, val->SE, interval[1]-interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
result.E = cross_section_result.scattering_E;
result.SE = cross_section_result.scattering_SE;
@@ -2674,58 +2690,58 @@ main(int argc, char** argv)
compute_estimation_intersection(interval, 4, &result, val);
printf(" Scattering = %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
result.E, result.SE, val->E, val->SE, interval[1]-interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
printf(" Proj area ~ %9.3g +/- %9.3g\n",
cross_section.average_projected_area.E,
cross_section.average_projected_area.SE);
- CHECK(sschiff_estimator_get_scattering_angles(estimator, &angles, &count), RES_OK);
- CHECK(count, nscatt_angles);
+ CHK(sschiff_estimator_get_scattering_angles(estimator, &angles, &count) == RES_OK);
+ CHK(count == nscatt_angles);
#define LIMIT_ANGLE sschiff_estimator_get_limit_scattering_angle_index
- CHECK(LIMIT_ANGLE(NULL, 1, NULL), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(estimator, 1, NULL), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(estimator, 0, NULL), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(NULL, 1, &ilimit_angle), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(estimator, 1, &ilimit_angle), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(NULL, 0, &ilimit_angle), RES_BAD_ARG);
- CHECK(LIMIT_ANGLE(estimator, 0, &ilimit_angle), RES_OK);
+ CHK(LIMIT_ANGLE(NULL, 1, NULL) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(estimator, 1, NULL) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(estimator, 0, NULL) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(NULL, 1, &ilimit_angle) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(estimator, 1, &ilimit_angle) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(NULL, 0, &ilimit_angle) == RES_BAD_ARG);
+ CHK(LIMIT_ANGLE(estimator, 0, &ilimit_angle) == RES_OK);
#undef LIMIT_ANGLE
- CHECK(ilimit_angle < count, 1);
+ CHK(ilimit_angle < count);
printf(" Limit angle = %g radians; ", angles[ilimit_angle]);
#define GET_N sschiff_estimator_get_wide_scattering_angle_model_parameter
- CHECK(GET_N(NULL, 1, NULL), RES_BAD_ARG);
- CHECK(GET_N(estimator, 1, NULL), RES_BAD_ARG);
- CHECK(GET_N(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(GET_N(estimator, 0, NULL), RES_BAD_ARG);
- CHECK(GET_N(NULL, 1, &n), RES_BAD_ARG);
- CHECK(GET_N(estimator, 1, &n), RES_BAD_ARG);
- CHECK(GET_N(NULL, 0, &n), RES_BAD_ARG);
- CHECK(GET_N(estimator, 0, &n), RES_OK);
+ CHK(GET_N(NULL, 1, NULL) == RES_BAD_ARG);
+ CHK(GET_N(estimator, 1, NULL) == RES_BAD_ARG);
+ CHK(GET_N(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(GET_N(estimator, 0, NULL) == RES_BAD_ARG);
+ CHK(GET_N(NULL, 1, &n) == RES_BAD_ARG);
+ CHK(GET_N(estimator, 1, &n) == RES_BAD_ARG);
+ CHK(GET_N(NULL, 0, &n) == RES_BAD_ARG);
+ CHK(GET_N(estimator, 0, &n) == RES_OK);
#undef GET_N
printf("n = %g\n", n);
#define DIFF_XSECTION sschiff_estimator_get_differential_cross_section
i = ilimit_angle;
- CHECK(DIFF_XSECTION(NULL, 1, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 1, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 0, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 0, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 1, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 1, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 0, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 0, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 1, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 1, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 0, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 0, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 1, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 1, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(NULL, 0, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION(estimator, 0, i, &result), RES_OK);
+ CHK(DIFF_XSECTION(NULL, 1, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 1, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 0, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 0, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 1, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 1, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 0, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 0, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 1, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 1, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 0, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 0, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 1, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 1, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(NULL, 0, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION(estimator, 0, i, &result) == RES_OK);
#undef DIFF_XSECTION
result2.E = 7.89191057312786e-2;
@@ -2733,26 +2749,26 @@ main(int argc, char** argv)
compute_estimation_intersection(interval, 4, &result2, &result);
printf(" Ws = %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
result2.E, result2.SE, result.E, result.SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
#define DIFF_XSECTION_CUMUL \
sschiff_estimator_get_differential_cross_section_cumulative
- CHECK(DIFF_XSECTION_CUMUL(NULL, 1, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 1, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 0, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 0, nscatt_angles, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 1, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 1, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 0, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 0, i, NULL), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 1, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 1, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 0, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 0, nscatt_angles, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 1, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 1, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(NULL, 0, i, &result), RES_BAD_ARG);
- CHECK(DIFF_XSECTION_CUMUL(estimator, 0, i, &result), RES_OK);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 1, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 1, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 0, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 0, nscatt_angles, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 1, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 1, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 0, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 0, i, NULL) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 1, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 1, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 0, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 0, nscatt_angles, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 1, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 1, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(NULL, 0, i, &result) == RES_BAD_ARG);
+ CHK(DIFF_XSECTION_CUMUL(estimator, 0, i, &result) == RES_OK);
#undef DIFF_XSECTION_CUMUL
result2.E = 2.57417550513944;
@@ -2760,17 +2776,17 @@ main(int argc, char** argv)
compute_estimation_intersection(interval, 4, &result2, &result);
printf(" Wc = %9.3g +/- %9.3g ~ %9.3g +/- %9.3g (%9.3g)\n",
result2.E, result2.SE, result.E, result.SE, interval[1] - interval[0]);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
#define PHASE_FUNCTION sschiff_estimator_get_phase_function
- CHECK(PHASE_FUNCTION(NULL, 1, NULL), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(estimator, 1, NULL), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(estimator, 0, NULL), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(NULL, 1, &func), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(estimator, 1, &func), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(NULL, 0, &func), RES_BAD_ARG);
- CHECK(PHASE_FUNCTION(estimator, 0, &func), RES_OK);
+ CHK(PHASE_FUNCTION(NULL, 1, NULL) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(estimator, 1, NULL) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(estimator, 0, NULL) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(NULL, 1, &func) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(estimator, 1, &func) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(NULL, 0, &func) == RES_BAD_ARG);
+ CHK(PHASE_FUNCTION(estimator, 0, &func) == RES_OK);
#undef PHASE_FUNCTION
printf("\n# Phase function\n");
@@ -2786,19 +2802,19 @@ main(int argc, char** argv)
* is not sufficiently well estimated due to a limited number of
* realisations. */
if(i <= ilimit_angle) {
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
}
}
#define CUMULATIVE sschiff_estimator_get_phase_function_cumulative
- CHECK(CUMULATIVE(NULL, 1, NULL), RES_BAD_ARG);
- CHECK(CUMULATIVE(estimator, 1, NULL), RES_BAD_ARG);
- CHECK(CUMULATIVE(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(CUMULATIVE(estimator, 0, NULL), RES_BAD_ARG);
- CHECK(CUMULATIVE(NULL, 1, &cumul), RES_BAD_ARG);
- CHECK(CUMULATIVE(estimator, 1, &cumul), RES_BAD_ARG);
- CHECK(CUMULATIVE(NULL, 0, &cumul), RES_BAD_ARG);
- CHECK(CUMULATIVE(estimator, 0, &cumul), RES_OK);
+ CHK(CUMULATIVE(NULL, 1, NULL) == RES_BAD_ARG);
+ CHK(CUMULATIVE(estimator, 1, NULL) == RES_BAD_ARG);
+ CHK(CUMULATIVE(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(CUMULATIVE(estimator, 0, NULL) == RES_BAD_ARG);
+ CHK(CUMULATIVE(NULL, 1, &cumul) == RES_BAD_ARG);
+ CHK(CUMULATIVE(estimator, 1, &cumul) == RES_BAD_ARG);
+ CHK(CUMULATIVE(NULL, 0, &cumul) == RES_BAD_ARG);
+ CHK(CUMULATIVE(estimator, 0, &cumul) == RES_OK);
#undef CUMULATIVE
printf("\n# Cumulative phase function\n");
@@ -2814,31 +2830,31 @@ main(int argc, char** argv)
* is not sufficiently well estimated due to a limited number of
* realisations. */
if(i <= ilimit_angle) {
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
}
}
- NCHECK(sa_add(thetas, 2000), NULL);
+ CHK(sa_add(thetas, 2000) != NULL);
#define INV_CUMULATIVE sschiff_estimator_inverse_cumulative_phase_function
- CHECK(INV_CUMULATIVE(NULL, 1, NULL, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 1, NULL, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 0, NULL, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 0, NULL, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 1, thetas, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 1, thetas, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 0, thetas, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 0, thetas, 0), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 1, NULL, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 1, NULL, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 0, NULL, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 0, NULL, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 1, thetas, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 1, thetas, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(NULL, 0, thetas, 2), RES_BAD_ARG);
- CHECK(INV_CUMULATIVE(estimator, 0, thetas, 2), RES_OK);
- CHECK(eq_eps(thetas[0], 0, 1.e-6), 1);
- CHECK(eq_eps(thetas[1], PI, 1.e-6), 1);
- CHECK(INV_CUMULATIVE(estimator, 0, thetas, sa_size(thetas)), RES_OK);
+ CHK(INV_CUMULATIVE(NULL, 1, NULL, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 1, NULL, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 0, NULL, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 0, NULL, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 1, thetas, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 1, thetas, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 0, thetas, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 0, thetas, 0) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 1, NULL, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 1, NULL, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 0, NULL, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 0, NULL, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 1, thetas, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 1, thetas, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(NULL, 0, thetas, 2) == RES_BAD_ARG);
+ CHK(INV_CUMULATIVE(estimator, 0, thetas, 2) == RES_OK);
+ CHK(eq_eps(thetas[0], 0, 1.e-6) == 1);
+ CHK(eq_eps(thetas[1], PI, 1.e-6) == 1);
+ CHK(INV_CUMULATIVE(estimator, 0, thetas, sa_size(thetas)) == RES_OK);
#undef INV_CUMULATIVE
printf("\n# Inverse cumulative phase function\n");
@@ -2847,20 +2863,20 @@ main(int argc, char** argv)
error = fabs(thetas[i] - inverse_cumulative[i]) / inverse_cumulative[i];
printf("CDF^-1(%9.3g) = %9.3g ~ %9.3g; err = %.3f%%\n",
(double)i*(1.0/1999.0), thetas[i], inverse_cumulative[i], error*100);
- CHECK(interval[0] <= interval[1], 1);
+ CHK(interval[0] <= interval[1]);
}
sa_release(thetas);
- CHECK(sschiff_estimator_ref_put(estimator), RES_OK);
- CHECK(sschiff_device_ref_put(dev), RES_OK);
- CHECK(ssp_rng_ref_put(rng), RES_OK);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
+ CHK(ssp_rng_ref_put(rng) == RES_OK);
- CHECK(s3d_device_ref_put(s3d), RES_OK);
- CHECK(s3d_shape_ref_put(shape), RES_OK);
+ CHK(s3d_device_ref_put(s3d) == RES_OK);
+ CHK(s3d_shape_ref_put(shape) == RES_OK);
geometry_release(&geometry);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}
diff --git a/src/test_sschiff_estimator_sphere.c b/src/test_sschiff_estimator_sphere.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -48,9 +49,9 @@ get_material_property
{
struct sampler_context* ctx = mtl;
- NCHECK(mtl, NULL);
- NCHECK(properties, NULL);
- CHECK(eq_eps(ctx->wavelength, wavelength, 1.e-8), 1);
+ CHK(mtl != NULL);
+ CHK(properties != NULL);
+ CHK(eq_eps(ctx->wavelength, wavelength, 1.e-8) == 1);
properties->medium_refractive_index = ctx->medium_refractive_index;
properties->relative_real_refractive_index =
@@ -62,20 +63,19 @@ get_material_property
static res_T
sample_sphere
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
- double* volume_scaling,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
struct sphere sphere;
-
- NCHECK(rng, NULL);
- NCHECK(volume_scaling, NULL);
+ CHK(rng && shape_data);
sphere.geometry = &sampler_ctx->geometry;
sphere.radius = (float)ssp_ran_lognormal
(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
- *volume_scaling = 1.0;
+
+ *shape_data = NULL;
return sphere_setup_s3d_shape(&sphere, shape);
}
@@ -100,9 +100,9 @@ check_schiff_estimation
const size_t ndirs = 100;
const double wavelength = sampler_ctx->wavelength;
- NCHECK(sampler_ctx, NULL);
- NCHECK(results, NULL);
- NCHECK(results, 0);
+ CHK(sampler_ctx != NULL);
+ CHK(results != NULL);
+ CHK(results != 0);
distrib.material.get_property = get_material_property;
distrib.material.material = sampler_ctx;
@@ -123,37 +123,38 @@ check_schiff_estimation
distrib.characteristic_length = sampler_ctx->mean_radius * 2.0;
time_current(&t0);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
- sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs, &estimator), RES_OK);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1,
+ sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs, 0, &estimator)
+ == RES_OK);
time_current(&t1);
time_sub(&t0, &t1, &t0);
time_dump(&t0, TIME_MIN|TIME_SEC|TIME_MSEC, NULL, buf, sizeof(buf));
printf("%d - mean radius: %5.2f micron - %s: \n", (int)i, results[i].mean_radius, buf);
- CHECK(sschiff_estimator_get_cross_sections(estimator, &cross_section), RES_OK);
+ CHK(sschiff_estimator_get_cross_sections(estimator, &cross_section) == RES_OK);
val = &cross_section.extinction;
dst = val->E - results[i].extinction_cross_section;
printf(" Extinction cross section = %7.2f ~ %12.7f +/- %12.7f (%6.2f)\n",
results[i].extinction_cross_section, val->E, val->SE, dst / val->SE);
- CHECK(eq_eps(val->E, results[i].extinction_cross_section, 4*val->SE), 1);
+ CHK(eq_eps(val->E, results[i].extinction_cross_section, 4*val->SE) == 1);
val = &cross_section.absorption;
dst = val->E - results[i].absorption_cross_section;
printf(" Absorption cross section = %7.2f ~ %12.7f +/- %12.7f (%6.2f)\n",
results[i].absorption_cross_section, val->E, val->SE, dst / val->SE);
- CHECK(eq_eps(val->E, results[i].absorption_cross_section, 4*val->SE), 1);
+ CHK(eq_eps(val->E, results[i].absorption_cross_section, 4*val->SE) == 1);
val = &cross_section.scattering;
dst = val->E - results[i].scattering_cross_section;
printf(" Scattering cross section = %7.2f ~ %12.7f +/- %12.7f (%6.2f)\n",
results[i].scattering_cross_section, val->E, val->SE, dst / val->SE);
- CHECK(eq_eps(val->E, results[i].scattering_cross_section, 4*val->SE), 1);
+ CHK(eq_eps(val->E, results[i].scattering_cross_section, 4*val->SE) == 1);
val = &cross_section.average_projected_area;
printf(" Averavege projected area = %12.7g +/- %12.7g\n", val->E, val->SE);
- CHECK(sschiff_estimator_ref_put(estimator), RES_OK);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
}
}
@@ -199,9 +200,9 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(sschiff_device_create
- (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, NULL, &dev), RES_OK);
+ CHK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng) == RES_OK);
+ CHK(sschiff_device_create
+ (NULL, &allocator, SSCHIFF_NTHREADS_DEFAULT, 1, NULL, &dev) == RES_OK);
geometry_init_sphere(&sampler_ctx.geometry, 64);
@@ -218,128 +219,132 @@ main(int argc, char** argv)
distrib.sample = sample_sphere;
distrib.context = &sampler_ctx;
- CHECK(sschiff_integrate(NULL, NULL, NULL, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, NULL, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, NULL, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, NULL, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, NULL, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, NULL, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, NULL, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(NULL, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, &estimator), RES_BAD_ARG);
-
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 1,
- sschiff_uniform_scattering_angles, 1, 1, 1, &estimator), RES_BAD_ARG);
- CHECK(sschiff_integrate(dev, rng, &distrib, &wlen, 1,
- sschiff_uniform_scattering_angles, 10, 1000, 1, &estimator), RES_OK);
-
- CHECK(sschiff_estimator_get_wavelengths(NULL, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_wavelengths(estimator, NULL, NULL), RES_OK);/*Useless*/
- CHECK(sschiff_estimator_get_wavelengths(NULL, NULL, &count), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_wavelengths(estimator, NULL, &count), RES_OK);
- CHECK(count, 1);
- CHECK(sschiff_estimator_get_wavelengths(NULL, &dbls, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_wavelengths(estimator, &dbls, NULL), RES_OK);
- CHECK(dbls[0], wlen);
- CHECK(sschiff_estimator_get_wavelengths(NULL, &dbls, &count), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_wavelengths(estimator, &dbls, &count), RES_OK);
- CHECK(dbls[0], wlen);
- CHECK(count, 1);
-
- CHECK(sschiff_estimator_get_scattering_angles(NULL, NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_scattering_angles(estimator, NULL, NULL), RES_OK); /* Useless */
- CHECK(sschiff_estimator_get_scattering_angles(NULL, NULL, &count), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_scattering_angles(estimator, NULL, &count), RES_OK);
- CHECK(count, 10);
- CHECK(sschiff_estimator_get_scattering_angles(NULL, &dbls, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_scattering_angles(estimator, &dbls, NULL), RES_OK); /* Useless */
+ CHK(sschiff_integrate(NULL, NULL, NULL, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, NULL, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, NULL, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, NULL, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 0, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, NULL, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, NULL, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, NULL, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, NULL, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, NULL, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(NULL, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 1, NULL, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 1,
+ sschiff_uniform_scattering_angles, 1, 1, 1, 0, &estimator) == RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 1,
+ sschiff_uniform_scattering_angles, 10, 1000, 1, 0, &estimator) == RES_OK);
+
+ CHK(sschiff_estimator_get_wavelengths(NULL, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_wavelengths(estimator, NULL, NULL) == RES_OK);/*Useless*/
+ CHK(sschiff_estimator_get_wavelengths(NULL, NULL, &count) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_wavelengths(estimator, NULL, &count) == RES_OK);
+ CHK(count == 1);
+ CHK(sschiff_estimator_get_wavelengths(NULL, &dbls, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_wavelengths(estimator, &dbls, NULL) == RES_OK);
+ CHK(dbls[0] == wlen);
+ CHK(sschiff_estimator_get_wavelengths(NULL, &dbls, &count) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_wavelengths(estimator, &dbls, &count) == RES_OK);
+ CHK(dbls[0] == wlen);
+ CHK(count == 1);
+
+ CHK(sschiff_estimator_get_scattering_angles(NULL, NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_scattering_angles(estimator, NULL, NULL) == RES_OK); /* Useless */
+ CHK(sschiff_estimator_get_scattering_angles(NULL, NULL, &count) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_scattering_angles(estimator, NULL, &count) == RES_OK);
+ CHK(count == 10);
+ CHK(sschiff_estimator_get_scattering_angles(NULL, &dbls, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_scattering_angles(estimator, &dbls, NULL) == RES_OK); /* Useless */
FOR_EACH(i, 0, count)
- CHECK(eq_eps(dbls[i], (double)i*PI/((double)count-1), 1.e-6), 1);
- CHECK(sschiff_estimator_get_scattering_angles(NULL, &dbls, &count), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_scattering_angles(estimator, &dbls, &count), RES_OK);
+ CHK(eq_eps(dbls[i], (double)i*PI/((double)count-1), 1.e-6) == 1);
+ CHK(sschiff_estimator_get_scattering_angles(NULL, &dbls, &count) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_scattering_angles(estimator, &dbls, &count) == RES_OK);
FOR_EACH(i, 0, count)
- CHECK(eq_eps(dbls[i], (double)i*PI/((double)count-1), 1.e-6), 1);
- CHECK(count, 10);
-
- CHECK(sschiff_estimator_get_realisations_count(NULL, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_realisations_count(estimator, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_realisations_count(NULL, &count), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_realisations_count(estimator, &count), RES_OK);
- CHECK(count, 1000);
-
- CHECK(sschiff_estimator_get_cross_section(NULL, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(estimator, 1, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(NULL, 1, &cross_section), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(estimator, 1, &cross_section), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(estimator, 0, NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(NULL, 0, &cross_section), RES_BAD_ARG);
- CHECK(sschiff_estimator_get_cross_section(estimator, 0, &cross_section), RES_OK);
-
- CHECK(sschiff_estimator_ref_get(NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_ref_get(estimator), RES_OK);
- CHECK(sschiff_estimator_ref_put(NULL), RES_BAD_ARG);
- CHECK(sschiff_estimator_ref_put(estimator), RES_OK);
- CHECK(sschiff_estimator_ref_put(estimator), RES_OK);
+ CHK(eq_eps(dbls[i], (double)i*PI/((double)count-1), 1.e-6) == 1);
+ CHK(count == 10);
+
+ CHK(sschiff_estimator_get_realisations_count(NULL, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_realisations_count(estimator, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_realisations_count(NULL, &count) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_realisations_count(estimator, &count) == RES_OK);
+ CHK(count == 1000);
+
+ CHK(sschiff_estimator_get_cross_section(NULL, 1, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(estimator, 1, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(NULL, 1, &cross_section) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(estimator, 1, &cross_section) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(estimator, 0, NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(NULL, 0, &cross_section) == RES_BAD_ARG);
+ CHK(sschiff_estimator_get_cross_section(estimator, 0, &cross_section) == RES_OK);
+
+ CHK(sschiff_estimator_ref_get(NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_ref_get(estimator) == RES_OK);
+ CHK(sschiff_estimator_ref_put(NULL) == RES_BAD_ARG);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
wlens[0] = 0.2, wlens[1] = 0.6, wlens[2] = 0.4;
- CHECK(sschiff_integrate(dev, rng, &distrib, wlens, 3,
- sschiff_uniform_scattering_angles, 10, 1000, 1, &estimator), RES_BAD_ARG);
+ CHK(sschiff_integrate(dev, rng, &distrib, wlens, 3,
+ sschiff_uniform_scattering_angles, 10, 1000, 1, 0, &estimator) == RES_BAD_ARG);
+
+ CHK(sschiff_integrate(dev, rng, &distrib, &wlen, 1,
+ sschiff_uniform_scattering_angles, 2, 1, 1, 1, &estimator) == RES_OK);
+ CHK(sschiff_estimator_ref_put(estimator) == RES_OK);
sampler_ctx.relative_real_refractive_index = 1.1;
check_schiff_estimation(dev, rng, &sampler_ctx, results_n_r_1_1,
@@ -350,13 +355,13 @@ main(int argc, char** argv)
check_schiff_estimation(dev, rng, &sampler_ctx, results_n_r_1_01,
sizeof(results_n_r_1_01)/sizeof(struct result));
- CHECK(sschiff_device_ref_put(dev), RES_OK);
- CHECK(ssp_rng_ref_put(rng), RES_OK);
+ CHK(sschiff_device_ref_put(dev) == RES_OK);
+ CHK(ssp_rng_ref_put(rng) == RES_OK);
geometry_release(&sampler_ctx.geometry);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}
diff --git a/src/test_sschiff_utils.h b/src/test_sschiff_utils.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2015-2016 CNRS
+/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2015, 2016 CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -42,8 +43,8 @@ geometry_init_sphere(struct geometry* sphere, const unsigned ntheta)
double* sin_phi = NULL;
unsigned itheta, iphi;
- NCHECK(sphere, NULL);
- NCHECK(ntheta, 0);
+ CHK(sphere != NULL);
+ CHK(ntheta != 0);
sphere->vertices = NULL;
sphere->indices = NULL;
@@ -116,8 +117,8 @@ geometry_init_cylinder(struct geometry* geometry, const unsigned nsteps)
const double step = 2*PI / (double)nsteps;
unsigned istep;
- NCHECK(geometry, NULL);
- NCHECK(nsteps, 0);
+ CHK(geometry != NULL);
+ CHK(nsteps != 0);
geometry->vertices = NULL;
geometry->indices = NULL;
@@ -172,7 +173,7 @@ geometry_init_cylinder(struct geometry* geometry, const unsigned nsteps)
static INLINE void
geometry_release(struct geometry* geometry)
{
- NCHECK(geometry, NULL);
+ CHK(geometry != NULL);
sa_release(geometry->vertices);
sa_release(geometry->indices);
geometry->vertices = NULL;
@@ -183,11 +184,11 @@ static INLINE void
geometry_dump(struct geometry* geom, FILE* file)
{
size_t i;
- NCHECK(geom, NULL);
- NCHECK(file, NULL);
+ CHK(geom != NULL);
+ CHK(file != NULL);
- CHECK(sa_size(geom->vertices)%3, 0); /* Ensure 3D position */
- CHECK(sa_size(geom->indices)%3, 0); /* Ensure triangular primitives */
+ CHK(sa_size(geom->vertices)%3 == 0); /* Ensure 3D position */
+ CHK(sa_size(geom->indices)%3 == 0); /* Ensure triangular primitives */
FOR_EACH(i, 0, sa_size(geom->vertices)/3) {
fprintf(file, "v %f %f %f\n",
@@ -218,8 +219,8 @@ cylinder_get_indices(const unsigned itri, unsigned ids[3], void* ctx)
struct cylinder* cylinder = ctx;
const size_t i = itri * 3;
- CHECK(sa_size(cylinder->geometry->indices) % 3, 0);
- CHECK(itri < sa_size(cylinder->geometry->indices) / 3, 1);
+ CHK(sa_size(cylinder->geometry->indices) % 3 == 0);
+ CHK(itri < sa_size(cylinder->geometry->indices) / 3);
ids[0] = cylinder->geometry->indices[i + 0];
ids[1] = cylinder->geometry->indices[i + 1];
ids[2] = cylinder->geometry->indices[i + 2];
@@ -231,8 +232,8 @@ cylinder_get_position(const unsigned ivert, float vertex[3], void* ctx)
struct cylinder* cylinder = ctx;
const size_t i = ivert * 3;
- CHECK(sa_size(cylinder->geometry->vertices) % 3, 0);
- CHECK(ivert < sa_size(cylinder->geometry->vertices) / 3, 1);
+ CHK(sa_size(cylinder->geometry->vertices) % 3 == 0);
+ CHK(ivert < sa_size(cylinder->geometry->vertices) / 3);
vertex[0] = cylinder->geometry->vertices[i + 0] * cylinder->radius;
vertex[1] = cylinder->geometry->vertices[i + 1] * cylinder->radius;
vertex[2] = cylinder->geometry->vertices[i + 2] * cylinder->height;
@@ -244,8 +245,8 @@ cylinder_setup_s3d_shape(struct cylinder* cylinder, struct s3d_shape* shape)
struct s3d_vertex_data attrib;
size_t nverts, nprims;
- NCHECK(cylinder, NULL);
- NCHECK(shape, NULL);
+ CHK(cylinder != NULL);
+ CHK(shape != NULL);
attrib.usage = S3D_POSITION;
attrib.type = S3D_FLOAT3;
@@ -272,8 +273,8 @@ sphere_get_indices(const unsigned itri, unsigned ids[3], void* ctx)
struct sphere* sphere = ctx;
const size_t i = itri * 3;
- CHECK(sa_size(sphere->geometry->indices) % 3, 0);
- CHECK(itri < sa_size(sphere->geometry->indices) / 3, 1);
+ CHK(sa_size(sphere->geometry->indices) % 3 == 0);
+ CHK(itri < sa_size(sphere->geometry->indices) / 3);
ids[0] = sphere->geometry->indices[i + 0];
ids[1] = sphere->geometry->indices[i + 1];
ids[2] = sphere->geometry->indices[i + 2];
@@ -285,8 +286,8 @@ sphere_get_position(const unsigned ivert, float vertex[3], void* ctx)
struct sphere* sphere = ctx;
const size_t i = ivert * 3;
- CHECK(sa_size(sphere->geometry->vertices) % 3, 0);
- CHECK(ivert < sa_size(sphere->geometry->vertices) / 3, 1);
+ CHK(sa_size(sphere->geometry->vertices) % 3 == 0);
+ CHK(ivert < sa_size(sphere->geometry->vertices) / 3);
vertex[0] = sphere->geometry->vertices[i + 0] * sphere->radius;
vertex[1] = sphere->geometry->vertices[i + 1] * sphere->radius;
vertex[2] = sphere->geometry->vertices[i + 2] * sphere->radius;
@@ -298,8 +299,8 @@ sphere_setup_s3d_shape(struct sphere* sphere, struct s3d_shape* shape)
struct s3d_vertex_data attrib;
size_t nverts, nprims;
- NCHECK(sphere, NULL);
- NCHECK(shape, NULL);
+ CHK(sphere != NULL);
+ CHK(shape != NULL);
attrib.usage = S3D_POSITION;
attrib.type = S3D_FLOAT3;
@@ -323,7 +324,7 @@ compute_estimation_intersection
const struct sschiff_state* state1)
{
double interval0[2], interval1[2];
- CHECK(scale > 0, 1);
+ CHK(scale > 0);
interval0[0] = state0->E - scale*state0->SE;
interval0[1] = state0->E + scale*state0->SE;
interval1[0] = state1->E - scale*state1->SE;