solstice-solver

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

commit 2888a852fbdc55ed2adc14db6f783d7d72d34def
parent dfa6e3b4d14f1d966d77df7c900e376f1cbd1792
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 15 Sep 2016 15:20:11 +0200

Add a new test solver #4

Parabol with a receiver at the focal.
This one is currently failing, mainly due to impacts accounted for twice.

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/test_ssol_solver4.c | 166+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -151,6 +151,7 @@ if(NOT NO_TEST) new_test(test_ssol_solver1) new_test(test_ssol_solver2) new_test(test_ssol_solver3) + new_test(test_ssol_solver4) new_test(test_ssol_sun) endif(NOT NO_TEST) diff --git a/src/test_ssol_solver4.c b/src/test_ssol_solver4.c @@ -0,0 +1,166 @@ +/* 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, square_walls_ntris, get_ids, + square_walls_nverts, attribs, 1, (void*) &square_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_PARABOL; + 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_instance_set_receiver(heliostat, "heliostat", NULL), 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, 1), 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; +}