solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 8b0fe9974f30c26caa8deecb12412e80f13d7ce7
parent 0fe127c2d514c6290dbf363d0989324eb455ba8b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 21 Sep 2016 16:11:04 +0200

Add test solver #5 to check parabolic cylinders

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/test_ssol_geometries.h | 18+++++++++++++++++-
Asrc/test_ssol_solver5.c | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 183 insertions(+), 1 deletion(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -157,6 +157,7 @@ if(NOT NO_TEST) new_test(test_ssol_solver2) new_test(test_ssol_solver3) new_test(test_ssol_solver4) + new_test(test_ssol_solver5) new_test(test_ssol_sun) endif(NOT NO_TEST) diff --git a/src/test_ssol_geometries.h b/src/test_ssol_geometries.h @@ -22,7 +22,7 @@ struct desc { }; /******************************************************************************* - * Plane + * Square plane ******************************************************************************/ static const float square_walls [] = { -1.f, -1.f, 0.f, @@ -38,6 +38,22 @@ const unsigned square_walls_ntris = sizeof(square_walls_ids) / sizeof(unsigned[3 static const struct desc square_walls_desc = { square_walls, square_walls_ids }; /******************************************************************************* +* Rectangle plane +******************************************************************************/ +static const float rect_walls [] = { + -10.f, -1.f, 0.f, + 10.f, -1.f, 0.f, + 10.f, 1.f, 0.f, + -10.f, 1.f, 0.f +}; +const unsigned rect_walls_nverts = sizeof(rect_walls) / sizeof(float[3]); + +const unsigned rect_walls_ids [] = { 0, 2, 1, 2, 0, 3 }; +const unsigned rect_walls_ntris = sizeof(rect_walls_ids) / sizeof(unsigned[3]); + +static const struct desc rect_walls_desc = { rect_walls, rect_walls_ids }; + +/******************************************************************************* * Box ******************************************************************************/ static const float box_walls [] = { diff --git a/src/test_ssol_solver5.c b/src/test_ssol_solver5.c @@ -0,0 +1,165 @@ +/* Copyright (C) CNRS 2016 +* +* 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 +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "ssol.h" +#include "test_ssol_utils.h" +#include "test_ssol_geometries.h" +#include "test_ssol_materials.h" +#include "test_ssol_postprocess.h" + +#include "ssol_solver_c.h" + +#include <rsys/logger.h> +#include <rsys/double33.h> + +#include <star/s3d.h> +#include <star/ssp.h> + +/******************************************************************************* +* Test main program +******************************************************************************/ +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + struct ssp_rng* rng; + struct ssol_scene* scene; + struct ssol_shape* square; + struct ssol_vertex_data attribs[1]; + struct ssol_shape* quad_square; + struct ssol_carving carving; + struct ssol_quadric quadric; + struct ssol_punched_surface punched; + struct ssol_material* m_mtl; + struct ssol_material* v_mtl; + struct ssol_mirror_shader shader; + struct ssol_object* m_object; + struct ssol_object* t_object; + struct ssol_instance* heliostat; + struct ssol_instance* target; + struct ssol_sun* sun; + struct ssol_spectrum* spectrum; + double dir[3]; + double frequencies[3] = { 1, 2, 3 }; + double intensities[3] = { 1, 0.8, 1 }; + double transform[12]; /* 3x4 column major matrix */ + double polygon[] = { -10.0, -10.0, -10.0, 10.0, 10.0, 10.0, 10.0, -10.0 }; + const size_t npolygon_verts = sizeof(polygon) / sizeof(double[2]); + FILE* tmp; + double m, std; + + (void) argc, (void) argv; +#define FOCAL 10 + d33_splat(transform, 0); + d3_splat(transform + 9, 0); + d33_rotation_pitch(transform, PI); /* flip faces: invert normal */ + transform[11] = FOCAL; /* +FOCAL offset along Z axis */ + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(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(ssol_device_create + (&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + + CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK); + CHECK(ssol_spectrum_create(dev, &spectrum), RES_OK); + CHECK(ssol_spectrum_setup(spectrum, frequencies, intensities, 3), RES_OK); + CHECK(ssol_sun_create_directional(dev, &sun), RES_OK); + CHECK(ssol_sun_set_direction(sun, d3(dir, 0, 0, -1)), RES_OK); + CHECK(ssol_sun_set_spectrum(sun, spectrum), RES_OK); + CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); + CHECK(ssol_scene_create(dev, &scene), RES_OK); + CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); + + /* create scene content */ + + CHECK(ssol_shape_create_mesh(dev, &square), RES_OK); + attribs[0].usage = SSOL_POSITION; + attribs[0].get = get_position; + CHECK(ssol_mesh_setup(square, rect_walls_ntris, get_ids, + rect_walls_nverts, attribs, 1, (void*) &rect_walls_desc), RES_OK); + + CHECK(ssol_shape_create_punched_surface(dev, &quad_square), RES_OK); + carving.get = get_polygon_vertices; + carving.operation = SSOL_AND; + carving.nb_vertices = npolygon_verts; + carving.context = &polygon; + quadric.type = SSOL_QUADRIC_PARABOLIC_CYLINDER; + quadric.data.parabol.focal = FOCAL; + punched.nb_carvings = 1; + punched.quadric = &quadric; + punched.carvings = &carving; + CHECK(ssol_punched_surface_setup(quad_square, &punched), RES_OK); + + CHECK(ssol_material_create_mirror(dev, &m_mtl), RES_OK); + shader.normal = get_shader_normal; + shader.reflectivity = get_shader_reflectivity; + shader.roughness = get_shader_roughness; + CHECK(ssol_mirror_set_shader(m_mtl, &shader), RES_OK); + CHECK(ssol_material_create_virtual(dev, &v_mtl), RES_OK); + + CHECK(ssol_object_create(dev, quad_square, m_mtl, m_mtl, &m_object), RES_OK); + CHECK(ssol_object_instantiate(m_object, &heliostat), RES_OK); + CHECK(ssol_scene_attach_instance(scene, heliostat), RES_OK); + + CHECK(ssol_object_create(dev, square, v_mtl, v_mtl, &t_object), RES_OK); + CHECK(ssol_object_instantiate(t_object, &target), RES_OK); + CHECK(ssol_instance_set_transform(target, transform), RES_OK); + CHECK(ssol_instance_set_receiver(target, "cible", NULL), RES_OK); + CHECK(ssol_instance_set_target_mask(target, 0x1, 0), RES_OK); + CHECK(ssol_instance_dont_sample(target, 1), RES_OK); + CHECK(ssol_scene_attach_instance(scene, target), RES_OK); + + CHECK(ssol_solve(scene, rng, 20, stdout), RES_OK); + + tmp = tmpfile(); +#define N 10000 + CHECK(ssol_solve(scene, rng, N, tmp), RES_OK); + CHECK(pp_sum(tmp, "cible", &m, &std), RES_OK); + logger_print(&logger, LOG_OUTPUT, "\nP = %g +/- %g\n", m, std); +#define DNI_cos (1000 * cos(0)) + CHECK(eq_eps(m, 400 * DNI_cos, 20), 1); + CHECK(eq_eps(std, 0, 0.1), 1); + + /* free data */ + + CHECK(ssol_instance_ref_put(heliostat), RES_OK); + CHECK(ssol_instance_ref_put(target), RES_OK); + CHECK(ssol_object_ref_put(m_object), RES_OK); + CHECK(ssol_object_ref_put(t_object), RES_OK); + CHECK(ssol_shape_ref_put(square), RES_OK); + CHECK(ssol_shape_ref_put(quad_square), RES_OK); + CHECK(ssol_material_ref_put(m_mtl), RES_OK); + CHECK(ssol_material_ref_put(v_mtl), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + CHECK(ssol_scene_ref_put(scene), RES_OK); + CHECK(ssp_rng_ref_put(rng), RES_OK); + CHECK(ssol_spectrum_ref_put(spectrum), RES_OK); + CHECK(ssol_sun_ref_put(sun), RES_OK); + + logger_release(&logger); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + + return 0; +}