stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit 4deec0f8b7f90f56449345f21f27c9c6ca7cf844
parent bbc1fb6f9310b11d6055ddf07b24979fb7a66b8d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 21 Feb 2018 20:47:01 +0100

Draft of an unfinished test of the sdis_solve_camera function

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/test_sdis_solve_camera.c | 250+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sdis_solve_probe.c | 12++++++------
3 files changed, 257 insertions(+), 6 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -131,6 +131,7 @@ if(NOT NO_TEST) new_test(test_sdis_solve_probe2_2d) new_test(test_sdis_solve_probe3_2d) new_test(test_sdis_conducto_radiative_2d) + new_test(test_sdis_solve_camera) target_link_libraries(test_sdis_solve_probe3 Star3DUT) if(CMAKE_COMPILER_IS_GNUCC) diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c @@ -0,0 +1,250 @@ +/* Copyright (C) |Meso|Star> 2016-2018 (contact@meso-star.com) + * + * 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 "sdis.h" +#include "test_sdis_utils.h" + +#include <rsys/math.h> + +#define UNKOWN_TEMPERATURE -1 + +/******************************************************************************* + * Fluid medium + ******************************************************************************/ +struct fluid { + double temperature; +}; + +static double +fluid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct fluid*)sdis_data_cget(data))->temperature; +} + +/******************************************************************************* + * Solid medium + ******************************************************************************/ +struct solid { + double cp; + double lambda; + double rho; + double delta; + double temperature; +}; + +static double +solid_get_calorific_capacity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->cp; +} + +static double +solid_get_thermal_conductivity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->lambda; +} + +static double +solid_get_volumic_mass + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->rho; +} + +static double +solid_get_delta + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->delta; +} + +static double +solid_get_delta_boundary + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->delta * 2.1; +} + +static double +solid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + CHK(data != NULL && vtx != NULL); + return ((const struct solid*)sdis_data_cget(data))->temperature; +} + +/******************************************************************************* + * Interface + ******************************************************************************/ +struct interf { + double hc; + double epsilon; + double specular_fraction; + double temperature; +}; + +static double +interface_get_convection_coef + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + CHK(data != NULL && frag != NULL); + return ((const struct interf*)sdis_data_cget(data))->hc; +} + +static double +interface_get_emissivity + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + CHK(data != NULL && frag != NULL); + return ((const struct interf*)sdis_data_cget(data))->epsilon; +} + +static double +interface_get_specular_fraction + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + CHK(data != NULL && frag != NULL); + return ((const struct interf*)sdis_data_cget(data))->specular_fraction; +} + +static double +interface_get_temperature + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + CHK(data != NULL && frag != NULL); + return ((const struct interf*)sdis_data_cget(data))->temperature; +} + +/******************************************************************************* + * Test + ******************************************************************************/ +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sdis_data* data = NULL; + struct sdis_device* dev = NULL; + struct sdis_medium* solid = NULL; + struct sdis_medium* fluid0 = NULL; + struct sdis_medium* fluid1 = NULL; + struct sdis_interface* interf0 = NULL; + struct sdis_interface* interf1 = NULL; + struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; + struct sdis_fluid_shader fluid_shader = DUMMY_FLUID_SHADER; + struct sdis_interface_shader interface_shader = DUMMY_INTERFACE_SHADER; + struct fluid* fluid_param; + struct solid* solid_param; + struct interf* interface_param; + (void)argc, (void)argv; + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + CHK(sdis_device_create + (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev) == RES_OK); + + /* Create the fluid0 */ + CHK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + fluid_param = sdis_data_get(data); + fluid_param->temperature = 300; + fluid_shader.temperature = fluid_get_temperature; + CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid0) == RES_OK); + CHK(sdis_data_ref_put(data) == RES_OK); + + /* Create the fluid1 */ + CHK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + fluid_param = sdis_data_get(data); + fluid_param->temperature = UNKOWN_TEMPERATURE; + fluid_shader.temperature = fluid_get_temperature; + CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1) == RES_OK); + CHK(sdis_data_ref_put(data) == RES_OK); + + /* Create the solid medium */ + CHK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + solid_param = sdis_data_get(data); + solid_param->cp = 1.0; + solid_param->lambda = 0.1; + solid_param->rho = 1.0; + solid_param->delta = 1.0/20.0; + solid_param->temperature = UNKOWN_TEMPERATURE; + solid_shader.calorific_capacity = solid_get_calorific_capacity; + solid_shader.calorific_capacity = solid_get_calorific_capacity; + solid_shader.thermal_conductivity = solid_get_thermal_conductivity; + solid_shader.volumic_mass = solid_get_volumic_mass; + solid_shader.delta_solid = solid_get_delta; + solid_shader.delta_boundary = solid_get_delta_boundary; + solid_shader.temperature = solid_get_temperature; + CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); + CHK(sdis_data_ref_put(data) == RES_OK); + + /* Create the fluid0/solid interface */ + CHK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data) == RES_OK); + interface_param = sdis_data_get(data); + interface_param->hc = 1; + interface_param->epsilon = 0; + interface_param->specular_fraction = 0; + interface_param->temperature = UNKOWN_TEMPERATURE; + interface_shader.convection_coef = interface_get_convection_coef; + interface_shader.temperature = interface_get_temperature; + interface_shader.emissivity = interface_get_emissivity; + interface_shader.specular_fraction = interface_get_specular_fraction; + CHK(sdis_interface_create + (dev, solid, fluid0, &interface_shader, data, &interf0) == RES_OK); + CHK(sdis_data_ref_put(data) == RES_OK); + + /* Create the fluid1/solid interface */ + CHK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data) == RES_OK); + interface_param = sdis_data_get(data); + interface_param->hc = 0; + interface_param->epsilon = 1; + interface_param->specular_fraction = 1; + interface_param->temperature = UNKOWN_TEMPERATURE; + interface_shader.convection_coef = interface_get_convection_coef; + interface_shader.temperature = interface_get_temperature; + interface_shader.emissivity = interface_get_emissivity; + interface_shader.specular_fraction = interface_get_specular_fraction; + CHK(sdis_interface_create + (dev, fluid1, solid, &interface_shader, data, &interf1) == RES_OK); + CHK(sdis_data_ref_put(data) == RES_OK); + + /* TODO setup the geometry */ + + /* Release the media */ + CHK(sdis_medium_ref_put(solid) == RES_OK); + CHK(sdis_medium_ref_put(fluid0) == RES_OK); + CHK(sdis_medium_ref_put(fluid1) == RES_OK); + + /* Release memory */ + CHK(sdis_interface_ref_put(interf0) == RES_OK); + CHK(sdis_interface_ref_put(interf1) == RES_OK); + CHK(sdis_device_ref_put(dev) == RES_OK); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_sdis_solve_probe.c b/src/test_sdis_solve_probe.c @@ -146,8 +146,8 @@ solid_get_temperature ******************************************************************************/ struct interf { double hc; - double rho_s; - double rho_d; + double epsilon; + double specular_fraction; }; static double @@ -163,7 +163,7 @@ interface_get_emissivity (const struct sdis_interface_fragment* frag, struct sdis_data* data) { CHK(data != NULL && frag != NULL); - return ((const struct interf*)sdis_data_cget(data))->rho_s; + return ((const struct interf*)sdis_data_cget(data))->epsilon; } static double @@ -171,7 +171,7 @@ interface_get_specular_fraction (const struct sdis_interface_fragment* frag, struct sdis_data* data) { CHK(data != NULL && frag != NULL); - return ((const struct interf*)sdis_data_cget(data))->rho_d; + return ((const struct interf*)sdis_data_cget(data))->specular_fraction; } /******************************************************************************* @@ -240,8 +240,8 @@ main(int argc, char** argv) ALIGNOF(struct interf), NULL, &data) == RES_OK); interface_param = sdis_data_get(data); interface_param->hc = 0.5; - interface_param->rho_s = 0; - interface_param->rho_d = 0; + interface_param->epsilon = 0; + interface_param->specular_fraction = 0; interface_shader.convection_coef = interface_get_convection_coef; interface_shader.temperature = NULL; interface_shader.emissivity = interface_get_emissivity;