star-schiff

Library for estimating radiative properties
git clone git://git.meso-star.com/star-schiff.git
Log | Files | Refs | README | LICENSE

commit 525cbe51e6ffca609d823e51aeaabfa9061962d8
parent feb29598bd7077192484e7e4da76955c16e59f06
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 29 Feb 2016 14:18:10 +0100

First draft of a new test on cylindrical geometries

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/test_sschiff_estimator_rhodo.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -107,6 +107,7 @@ if(NOT NO_TEST) new_test(test_sschiff_device) new_test(test_sschiff_estimator_sphere) new_test(test_sschiff_estimator_cylinder) + new_test(test_sschiff_estimator_rhodo) rcmake_copy_runtime_libraries(test_sschiff_device) endif() diff --git a/src/test_sschiff_estimator_rhodo.c b/src/test_sschiff_estimator_rhodo.c @@ -0,0 +1,139 @@ +/* Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com) + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#include "sschiff.h" +#include "test_sschiff_utils.h" + +#include <rsys/stretchy_array.h> + +#include <star/s3d.h> +#include <star/ssp.h> + +struct sampler_context { + struct geometry geometry; + double aspect_ratio; + double mean_radius; + double sigma; +}; + +static void +get_material_property + (void* mtl, + const double wavelength, + struct sschiff_material_properties* props) +{ + (void)mtl; +#if 0 + props->medium_refractive_index = 1.34177984360538; + props->relative_imaginary_refractive_index = 2.20382600910679e-03; + props->relative_real_refractive_index = 1.38912721283454; +#else + props->medium_refractive_index = 1.331073; + props->relative_imaginary_refractive_index = 8.53534081490802e-04; + props->relative_real_refractive_index = 1.39071033668243; +#endif +} + +static res_T +sample_cylinder + (struct ssp_rng* rng, struct s3d_shape* shape, void* sampler_context) +{ + struct sampler_context* sampler_ctx = sampler_context; + struct cylinder cylinder; + double sample; + (void)rng, (void)sampler_context; + + sample = ssp_ran_lognormal(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma)); + cylinder.geometry = &sampler_ctx->geometry; + cylinder.radius = (float)(sample / pow(3.0 / (2.0*sampler_ctx->aspect_ratio), 1.0/3.0)); + cylinder.height = (float)(2.f * cylinder.radius / sampler_ctx->aspect_ratio); + + return cylinder_setup_s3d_shape(&cylinder, shape); +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sampler_context sampler_ctx; + struct sschiff_device* dev; + struct sschiff_geometry_distribution distrib = SSCHIFF_NULL_GEOMETRY_DISTRIBUTION; + struct sschiff_estimator* estimator; + struct sschiff_cross_section cross_section; + struct ssp_rng* rng; + const double wavelength = 0.6; /* In micron */ + const size_t nscatt_angles = 1000; + const size_t ngeoms = 10000; + const size_t ndirs = 10; + (void)argc, (void)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, 1, 1, NULL, &dev), RES_OK); + + geometry_init_cylinder(&sampler_ctx.geometry, 64); + + sampler_ctx.aspect_ratio = 0.263; + sampler_ctx.mean_radius = 0.983; + sampler_ctx.sigma = 1.1374; + + distrib.caracteristic_length = 0.382; + distrib.material.get_property = get_material_property; + distrib.material.material = &sampler_ctx; + distrib.sample = sample_cylinder; + distrib.context = &sampler_ctx; + + CHECK(sschiff_integrate(dev, rng, &distrib, &wavelength, 1, + sschiff_uniform_scattering_angles, nscatt_angles, ngeoms, ndirs, + &estimator), RES_OK); + + CHECK(sschiff_estimator_get_wavelength_cross_section + (estimator, wavelength, &cross_section), RES_OK); + + printf("Wavelength = %g micron\n", wavelength); + printf(" Extinction ~ %9.3g +/- %9.3g\n", + cross_section.extinction.E, cross_section.extinction.SE); + printf(" Absorption ~ %9.3g +/- %9.3g\n", + cross_section.absorption.E, cross_section.absorption.SE); + printf(" Scattering ~ %9.3g +/- %9.3g\n", + cross_section.scattering.E, cross_section.scattering.SE); + printf(" Proj area ~ %9.3g +/- %9.3g\n", + cross_section.average_projected_area.E, + cross_section.average_projected_area.SE); + + CHECK(sschiff_estimator_ref_put(estimator), RES_OK); + CHECK(sschiff_device_ref_put(dev), RES_OK); + CHECK(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); + return 0; +}