stardis-solver

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

commit f0d639b37faf5a5a6233112126e99945dfc0bf46
parent c8aed87e4ffb0880b2b07520563d6c4ee353c65e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 16 Jan 2019 15:01:52 +0100

Merge branch 'release_0.6'

Diffstat:
MREADME.md | 23++++++++++++++++++++---
Mcmake/CMakeLists.txt | 13++++++++-----
Msrc/sdis.h | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/sdis_accum_buffer.c | 2+-
Msrc/sdis_camera.c | 2+-
Msrc/sdis_camera.h | 2+-
Msrc/sdis_data.c | 2+-
Msrc/sdis_device.c | 2+-
Msrc/sdis_device_c.h | 2+-
Msrc/sdis_estimator.c | 59++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/sdis_estimator_c.h | 13++++++++++++-
Msrc/sdis_interface.c | 16+++++++++-------
Msrc/sdis_interface_c.h | 2+-
Msrc/sdis_medium.c | 8+++++---
Msrc/sdis_medium_c.h | 24+++++++++++++++++++++++-
Msrc/sdis_scene.c | 7+++----
Msrc/sdis_scene_Xd.h | 59+++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/sdis_scene_c.h | 24+++++++++++++++++++++++-
Msrc/sdis_solve.c | 297+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Msrc/sdis_solve_Xd.h | 899++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/test_sdis_accum_buffer.c | 49++++++++++++++++++++++++-------------------------
Msrc/test_sdis_camera.c | 87+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_conducto_radiative.c | 72++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/test_sdis_conducto_radiative_2d.c | 73+++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/test_sdis_convection.c | 79+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/test_sdis_convection_non_uniform.c | 80++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/test_sdis_data.c | 62+++++++++++++++++++++++++++++---------------------------------
Msrc/test_sdis_device.c | 45++++++++++++++++++++++-----------------------
Msrc/test_sdis_flux.c | 79+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_interface.c | 126+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_medium.c | 92+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/test_sdis_scene.c | 136++++++++++++++++++++++++++++++++++++++++----------------------------------------
Asrc/test_sdis_solve_boundary.c | 408+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_sdis_solve_boundary_flux.c | 454+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sdis_solve_camera.c | 93++++++++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/test_sdis_solve_probe.c | 123+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/test_sdis_solve_probe2.c | 67+++++++++++++++++++++++++++++++++----------------------------------
Msrc/test_sdis_solve_probe2_2d.c | 67+++++++++++++++++++++++++++++++++----------------------------------
Msrc/test_sdis_solve_probe3.c | 79+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_solve_probe3_2d.c | 73++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/test_sdis_solve_probe_2d.c | 63+++++++++++++++++++++++++++++++++++++++------------------------
Dsrc/test_sdis_solve_probe_boundary.c | 305------------------------------------------------------------------------------
Msrc/test_sdis_utils.h | 11++++++++---
Msrc/test_sdis_volumic_power.c | 82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_volumic_power2.c | 126++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_volumic_power2_2d.c | 126++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_volumic_power3_2d.c | 138++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/test_sdis_volumic_power4_2d.c | 92++++++++++++++++++++++++++++++++++++++++----------------------------------------
48 files changed, 3327 insertions(+), 1511 deletions(-)

diff --git a/README.md b/README.md @@ -10,9 +10,11 @@ Stardis relies on the [CMake](http://www.cmake.org) and the It also depends on the [RSys](https://gitlab.com/vaplv/rsys/), [Star-2D](https://gitlab.com/meso-star/star-2d/), -[Star-3D](https://gitlab.com/meso-star/star-3d/) and +[Star-3D](https://gitlab.com/meso-star/star-3d/), +[Star-Enclosures](https://gitlab.com/meso-star/star-enclosures/), +[Star-Enclosures2D](https://gitlab.com/meso-star/star-enclosures-2d/) and [Star-SP](https://gitlab.com/meso-star/star-sp/) libraries as well as on the -[OpenMP](http://www.openmp.org) 1.2 specification to parallelize its +[OpenMP](http://www.openmp.org) 2.0 specification to parallelize its computations. First ensure that CMake and a compiler that implements the OpenMP 1.2 @@ -23,6 +25,21 @@ variable the install directories of its dependencies. ## Release notes +### Version 0.6 + +- Add the `sdis_solve_boundary` function: it computes the average temperature + on a subset of geometric primitives. +- Add flux solvers: the new `sdis_solve_probe_boundary_flux` and + `sdis_solve_boundary_flux` functions estimate the convective and radiative + fluxes at a given surface position or for a sub-set of geometric primitives, + respectively. +- Add support of time integration: almost all solvers can estimate the average + temperature on a given time range. Only the `sdis_solve_camera` function does + not support time integration, yet. +- Add support of an explicit initial time `t0` for the fluid. +- Fix a bug in the estimation of unknown fluid temperatures: the associativity + between the internal Stardis data and the user defined data was wrong. + ### Version 0.5 Add support of fluid enclosure with unknown uniform temperature. @@ -114,7 +131,7 @@ First version and implementation of the Stardis solver API. ## License -Stardis is Copyright (C) 2016-2018 |Meso|Star> (<contact@meso-star.com>). It is +Stardis is Copyright (C) 2016-2019 |Meso|Star> (<contact@meso-star.com>). It is free software released under the GPLv3+ license. You are welcome to redistribute it under certain conditions; refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 |Meso|Star> +# Copyright (C) 2016-2019 |Meso|Star> # # 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 @@ -29,9 +29,9 @@ CMAKE_DEPENDENT_OPTION(ALL_TESTS # Check dependencies ################################################################################ find_package(RCMake 0.4 REQUIRED) -find_package(Star2D 0.1.1 REQUIRED) +find_package(Star2D 0.2 REQUIRED) find_package(Star3D 0.5 REQUIRED) -find_package(StarSP 0.7 REQUIRED) +find_package(StarSP 0.8 REQUIRED) find_package(StarEnc 0.2.0 REQUIRED) find_package(StarEnc2D 0.2.0 REQUIRED) find_package(RSys 0.6.1 REQUIRED) @@ -47,7 +47,7 @@ rcmake_append_runtime_dirs(_runtime_dirs RSys Star3D StarSP StarEnc StarEnc2D) # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 5) +set(VERSION_MINOR 6) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) @@ -91,6 +91,8 @@ if(MSVC) ### disable verbose warnings: # warning C4127: conditional expression is constant set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127") + # warning C4204: nonstandard extension used : non-constant aggregate initializer + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4204") # warning C4938: Floating point reduction variable may cause inconsistent # results under /fp:strict or #pragma fenv_access set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4938") @@ -155,7 +157,8 @@ if(NOT NO_TEST) new_test(test_sdis_solve_probe_2d) new_test(test_sdis_solve_probe2_2d) new_test(test_sdis_solve_probe3_2d) - new_test(test_sdis_solve_probe_boundary) + new_test(test_sdis_solve_boundary) + new_test(test_sdis_solve_boundary_flux) new_test(test_sdis_volumic_power) # Additionnal tests diff --git a/src/sdis.h b/src/sdis.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -41,7 +41,7 @@ * as CPU cores */ #define SDIS_NTHREADS_DEFAULT (~0u) -#define SDIS_VOLUMIC_POWER_NONE DBL_MAX /* <=> No volumic power */ +#define SDIS_VOLUMIC_POWER_NONE 0 /* <=> No volumic power */ #define SDIS_FLUX_NONE DBL_MAX /* <=> No flux */ /* Forward declaration of external opaque data types */ @@ -76,6 +76,12 @@ enum sdis_medium_type { SDIS_MEDIUM_TYPES_COUNT__ }; +enum sdis_estimator_type { + SDIS_TEMPERATURE_ESTIMATOR, + SDIS_FLUX_ESTIMATOR, + SDIS_EST_TYPES_COUNT__ +}; + /* Random walk vertex, i.e. a spatiotemporal position at a given step of the * random walk. */ struct sdis_rwalk_vertex { @@ -146,10 +152,14 @@ struct sdis_solid_shader { sdis_medium_getter_T volumic_power; /* In W.m^-3 */ /* Initial/limit condition. A temperature < 0 means that the temperature is - * unknown for the submitted random walk vertex. */ + * unknown for the submitted random walk vertex. + * This getter is always called at time >= t0 (see below). */ sdis_medium_getter_T temperature; + /* The time until the initial condition is maintained for this solid; + * can neither be negative nor infinity, default is 0. */ + double t0; }; -#define SDIS_SOLID_SHADER_NULL__ {NULL, NULL, NULL, NULL, NULL, NULL} +#define SDIS_SOLID_SHADER_NULL__ {NULL, NULL, NULL, NULL, NULL, NULL, 0} static const struct sdis_solid_shader SDIS_SOLID_SHADER_NULL = SDIS_SOLID_SHADER_NULL__; @@ -160,10 +170,14 @@ struct sdis_fluid_shader { sdis_medium_getter_T volumic_mass; /* In kg.m^-3 */ /* Initial/limit condition. A temperature < 0 means that the temperature is - * unknown for the submitted position and time. */ + * unknown for the submitted random walk vertex. + * This getter is always called at time >= t0 (see below). */ sdis_medium_getter_T temperature; + /* The time until the initial condition is maintained for this fluid; + * can neither be negative nor infinity, default is 0. */ + double t0; }; -#define SDIS_FLUID_SHADER_NULL__ {NULL, NULL, NULL} +#define SDIS_FLUID_SHADER_NULL__ {NULL, NULL, NULL, 0} static const struct sdis_fluid_shader SDIS_FLUID_SHADER_NULL = SDIS_FLUID_SHADER_NULL__; @@ -336,7 +350,7 @@ SDIS_API res_T sdis_accum_buffer_unmap (const struct sdis_accum_buffer* buf); -/* Helper function that matches the `sdis_write_accums_T' functor type. On can +/* Helper function that matches the `sdis_write_accums_T' functor type. One can * send this function directly to the sdis_solve_camera function, to fill the * accum buffer with the estimation of the radiative temperature that reaches * each pixel of an image whose definition matches the definition of the accum @@ -403,7 +417,7 @@ sdis_interface_ref_put /******************************************************************************* * A scene is a collection of primitives. Each primitive is the geometric - * support of the interface between 2 mediums. + * support of the interface between 2 media. ******************************************************************************/ /* Create a 3D scene. The geometry of the scene is defined by an indexed * triangular mesh: each triangle is composed of 3 indices where each index @@ -527,9 +541,14 @@ sdis_estimator_ref_put (struct sdis_estimator* estimator); SDIS_API res_T +sdis_estimator_get_type + (const struct sdis_estimator* estimator, + enum sdis_estimator_type* type); + +SDIS_API res_T sdis_estimator_get_realisation_count (const struct sdis_estimator* estimator, - size_t* nrealisations); + size_t* nrealisations); /* Succesfull ones */ SDIS_API res_T sdis_estimator_get_failure_count @@ -541,6 +560,22 @@ sdis_estimator_get_temperature (const struct sdis_estimator* estimator, struct sdis_mc* temperature); +SDIS_API res_T +sdis_estimator_get_convective_flux + (const struct sdis_estimator* estimator, + struct sdis_mc* flux); + +SDIS_API res_T +sdis_estimator_get_radiative_flux + (const struct sdis_estimator* estimator, + struct sdis_mc* flux); + + +SDIS_API res_T +sdis_estimator_get_total_flux + (const struct sdis_estimator* estimator, + struct sdis_mc* flux); + /******************************************************************************* * Miscellaneous functions ******************************************************************************/ @@ -549,7 +584,7 @@ sdis_solve_probe (struct sdis_scene* scn, const size_t nrealisations, /* #realisations */ const double position[3], /* Probe position */ - const double time, /* Observation time */ + const double time_range[2], /* Observation time */ const double fp_to_meter, /* Scale from floating point units to meters */ const double ambient_radiative_temperature, /* In Kelvin */ const double reference_temperature, /* In Kelvin */ @@ -561,7 +596,7 @@ sdis_solve_probe_boundary const size_t nrealisations, /* #realisations */ const size_t iprim, /* Identifier of the primitive on which the probe lies */ const double uv[2], /* Parametric coordinates of the probe onto the primitve */ - const double time, /* Observation time */ + const double time_range[2], /* Observation time */ const enum sdis_side side, /* Side of iprim on which the probe lies */ const double fp_to_meter, /* Scale from floating point units to meters */ const double ambient_radiative_temperature, /* In Kelvin */ @@ -582,6 +617,44 @@ sdis_solve_camera sdis_write_accums_T writer, void* writer_data); +SDIS_API res_T +sdis_solve_boundary + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const enum sdis_side sides[], /* Per primitive side to consider */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double ambient_radiative_temperature, /* In Kelvin */ + const double reference_temperature, /* In Kelvin */ + struct sdis_estimator** estimator); + +/* Flux solver */ +SDIS_API res_T +sdis_solve_probe_boundary_flux + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t iprim, /* Identifier of the primitive on which the probe lies */ + const double uv[2], /* Parametric coordinates of the probe onto the primitve */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double ambient_radiative_temperature, /* In Kelvin */ + const double reference_temperature, /* In Kelvin */ + struct sdis_estimator** estimator); + +SDIS_API res_T +sdis_solve_boundary_flux + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double ambient_radiative_temperature, /* In Kelvin */ + const double reference_temperature, /* In Kelvin */ + struct sdis_estimator** estimator); + END_DECLS #endif /* SDIS_H */ diff --git a/src/sdis_accum_buffer.c b/src/sdis_accum_buffer.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_camera.c b/src/sdis_camera.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_camera.h b/src/sdis_camera.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_data.c b/src/sdis_data.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_device.c b/src/sdis_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_device_c.h b/src/sdis_device_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_estimator.c b/src/sdis_estimator.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -28,6 +28,8 @@ estimator_release(ref_T* ref) ASSERT(ref); estimator = CONTAINER_OF(ref, struct sdis_estimator, ref); dev = estimator->dev; + ASSERT((estimator->fluxes!=NULL) == (estimator->type==SDIS_FLUX_ESTIMATOR)); + MEM_RM(dev->allocator, estimator->fluxes); MEM_RM(dev->allocator, estimator); SDIS(device_ref_put(dev)); } @@ -52,6 +54,15 @@ sdis_estimator_ref_put(struct sdis_estimator* estimator) } res_T +sdis_estimator_get_type + (const struct sdis_estimator* estimator, enum sdis_estimator_type* type) +{ + if(!estimator || !type) return RES_BAD_ARG; + *type = estimator->type; + return RES_OK; +} + +res_T sdis_estimator_get_realisation_count (const struct sdis_estimator* estimator, size_t* nrealisations) { @@ -78,16 +89,54 @@ sdis_estimator_get_temperature return RES_OK; } +res_T +sdis_estimator_get_convective_flux + (const struct sdis_estimator* estimator, struct sdis_mc* flux) +{ + if(!estimator || !flux ||estimator->type != SDIS_FLUX_ESTIMATOR) + return RES_BAD_ARG; + ASSERT(estimator->fluxes); + *flux = estimator->fluxes[FLUX_CONVECTIVE__]; + return RES_OK; +} + +res_T +sdis_estimator_get_radiative_flux + (const struct sdis_estimator* estimator, struct sdis_mc* flux) +{ + if(!estimator || !flux || estimator->type != SDIS_FLUX_ESTIMATOR) + return RES_BAD_ARG; + ASSERT(estimator->fluxes); + *flux = estimator->fluxes[FLUX_RADIATIVE__]; + return RES_OK; +} + +res_T +sdis_estimator_get_total_flux + (const struct sdis_estimator* estimator, struct sdis_mc* flux) +{ + if(!estimator || !flux || estimator->type != SDIS_FLUX_ESTIMATOR) + return RES_BAD_ARG; + ASSERT(estimator->fluxes); + *flux = estimator->fluxes[FLUX_TOTAL__]; + return RES_OK; +} + /******************************************************************************* * Local functions ******************************************************************************/ res_T -estimator_create(struct sdis_device* dev, struct sdis_estimator** out_estimator) +estimator_create + (struct sdis_device* dev, + const enum sdis_estimator_type type, + struct sdis_estimator** out_estimator) { struct sdis_estimator* estimator = NULL; res_T res = RES_OK; - if(!dev || !out_estimator) { + if(!dev || !out_estimator + || (type != SDIS_TEMPERATURE_ESTIMATOR && type != SDIS_FLUX_ESTIMATOR)) + { res = RES_BAD_ARG; goto error; } @@ -97,9 +146,13 @@ estimator_create(struct sdis_device* dev, struct sdis_estimator** out_estimator) res = RES_MEM_ERR; goto error; } + estimator->type = type; + estimator->fluxes = (type != SDIS_FLUX_ESTIMATOR) ? NULL + : MEM_CALLOC(dev->allocator, FLUX_NAMES_COUNT__, sizeof(struct sdis_mc)); ref_init(&estimator->ref); SDIS(device_ref_get(dev)); estimator->dev = dev; + if(type == SDIS_FLUX_ESTIMATOR && !estimator->fluxes) goto error; exit: if(out_estimator) *out_estimator = estimator; diff --git a/src/sdis_estimator_c.h b/src/sdis_estimator_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -21,12 +21,22 @@ /* Forward declarations */ struct sdis_device; struct sdis_estimator; +enum sdis_estimator_type; + +enum flux_names { + FLUX_CONVECTIVE__, + FLUX_RADIATIVE__, + FLUX_TOTAL__, + FLUX_NAMES_COUNT__ +}; struct sdis_estimator { struct sdis_mc temperature; + struct sdis_mc* fluxes; size_t nrealisations; size_t nfailures; + enum sdis_estimator_type type; ref_T ref; struct sdis_device* dev; }; @@ -37,6 +47,7 @@ struct sdis_estimator { extern LOCAL_SYM res_T estimator_create (struct sdis_device* dev, + const enum sdis_estimator_type type, struct sdis_estimator** estimator); #endif /* SDIS_PROBE_ESTIMATOR_C_H */ diff --git a/src/sdis_interface.c b/src/sdis_interface.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -50,8 +50,9 @@ check_interface_shader && type[1] == SDIS_SOLID && shader->convection_coef) { log_warn(dev, - "%s: a solid/solid interface can't have a convection coefficient. This " - "function of the interface shader should be NULL.\n", caller_name); + "%s: a solid/solid interface can't have a convection coefficient. The " + " shader's pointer function for this attribute should be NULL.\n", + caller_name); } if(shader->convection_coef_upper_bound < 0) { @@ -66,16 +67,17 @@ check_interface_shader case SDIS_SOLID: if(shaders[i]->emissivity || shaders[i]->specular_fraction) { log_warn(dev, - "%s: the interface side toward a solid can't have the emissivity " - "and specular_fraction properties. The shader functions that return " - "these attributes should be NULL.\n", caller_name); + "%s: the interface side toward a solid can neither have the " + "emissivity nor the specular_fraction properties. The shader's " + " pointer functions for these attributes should be NULL.\n", + caller_name); } break; case SDIS_FLUID: if(shaders[i]->flux) { log_warn(dev, "%s: the interface side toward a fluid can't have a flux property. " - "The shader function that returns this attribute should be NULL.\n", + "The shader's pointer function for this attribute should be NULL.\n", caller_name); } break; diff --git a/src/sdis_interface_c.h b/src/sdis_interface_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 diff --git a/src/sdis_medium.c b/src/sdis_medium.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -28,7 +28,8 @@ check_fluid_shader(const struct sdis_fluid_shader* shader) ASSERT(shader); return shader->calorific_capacity && shader->volumic_mass - && shader->temperature; + && shader->temperature + && 0 <= shader->t0 && shader->t0 < INF; } static int @@ -39,7 +40,8 @@ check_solid_shader(const struct sdis_solid_shader* shader) && shader->thermal_conductivity && shader->volumic_mass && shader->delta_solid - && shader->temperature; + && shader->temperature + && 0 <= shader->t0 && shader->t0 < INF; } static res_T diff --git a/src/sdis_medium_c.h b/src/sdis_medium_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -18,6 +18,8 @@ #include "sdis.h" +#include <rsys/math.h> + struct sdis_medium { enum sdis_medium_type type; union { @@ -63,9 +65,19 @@ fluid_get_temperature (const struct sdis_medium* mdm, const struct sdis_rwalk_vertex* vtx) { ASSERT(mdm && mdm->type == SDIS_FLUID); + ASSERT(vtx->time >= mdm->shader.fluid.t0); return mdm->shader.fluid.temperature(vtx, mdm->data); } +static INLINE double + fluid_get_t0 +(const struct sdis_medium* mdm) +{ + ASSERT(mdm && mdm->type == SDIS_FLUID); + ASSERT(0 <= mdm->shader.fluid.t0 && mdm->shader.fluid.t0 < INF); + return mdm->shader.fluid.t0; +} + /******************************************************************************* * Solid local functions ******************************************************************************/ @@ -116,8 +128,18 @@ solid_get_temperature (const struct sdis_medium* mdm, const struct sdis_rwalk_vertex* vtx) { ASSERT(mdm && mdm->type == SDIS_SOLID); + ASSERT(vtx->time >= mdm->shader.solid.t0); return mdm->shader.solid.temperature(vtx, mdm->data); } +static INLINE double + solid_get_t0 +(const struct sdis_medium* mdm) +{ + ASSERT(mdm && mdm->type == SDIS_SOLID); + ASSERT(0 <= mdm->shader.solid.t0 && mdm->shader.solid.t0 < INF); + return mdm->shader.solid.t0; +} + #endif /* SDIS_MEDIUM_C_H */ diff --git a/src/sdis_scene.c b/src/sdis_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -231,8 +231,8 @@ sdis_scene_boundary_project_position /* Retrieve the segment vertices */ S2D(scene_view_get_primitive(scn->s2d_view, (unsigned int)iprim, &prim)); - S2D(primitive_get_attrib(&prim, S2D_POSITION, 0, &a)); d2_set_f2(V[0], a.value); - S2D(primitive_get_attrib(&prim, S2D_POSITION, 1, &a)); d2_set_f2(V[1], a.value); + S2D(segment_get_vertex_attrib(&prim, 0, S2D_POSITION, &a)); d2_set_f2(V[0], a.value); + S2D(segment_get_vertex_attrib(&prim, 1, S2D_POSITION, &a)); d2_set_f2(V[1], a.value); /* Compute the parametric coordinate of the project of `pos' onto the * segment.*/ @@ -296,4 +296,3 @@ scene_get_medium ? scene_get_medium_2d(scn, pos, info, out_medium) : scene_get_medium_3d(scn, pos, info, out_medium); } - diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -564,7 +564,7 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e #if DIM == 2 vdata.type = S2D_FLOAT2; #else - vdata.type = S2D_FLOAT3; + vdata.type = S3D_FLOAT3; #endif vdata.get = XD(enclosure_position); @@ -585,16 +585,14 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e /* Compute the S/V ratio */ #if DIM == 2 - CALL(sXd(scene_view_compute_contour_length)(enc_data->sXd(view), &S)); - CALL(sXd(scene_view_compute_area)(enc_data->sXd(view), &V)); + CALL(s2d_scene_view_compute_contour_length(enc_data->s2d_view, &S)); + CALL(s2d_scene_view_compute_area(enc_data->s2d_view, &V)); #else - CALL(sXd(scene_view_compute_area)(enc_data->sXd(view), &S)); - CALL(sXd(scene_view_compute_volume)(enc_data->sXd(view), &V)); + CALL(s3d_scene_view_compute_area(enc_data->s3d_view, &S)); + CALL(s3d_scene_view_compute_volume(enc_data->s3d_view, &V)); #endif - /* The volume of the enclosure is actually negative since Star-Enc ensures - * that the normal of its primitives point outward the enclosure. Take its - * absolute value in order to ensure a postive value. */ - enc_data->S_over_V = S/absf(V); + enc_data->S_over_V = S / V; + ASSERT(enc_data->S_over_V >= 0); #undef CALL /* Set enclosure hc upper bound regardless of its media being a fluid */ @@ -607,11 +605,11 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e if(res != RES_OK) goto error; FOR_EACH(iprim, 0, nprims) { #if DIM == 2 - SENCXD(enclosure_get_segment_global_id - (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim)); + senc2d_enclosure_get_segment_global_id + (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim); #else - SENCXD(enclosure_get_triangle_global_id - (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim)); + senc_enclosure_get_triangle_global_id + (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim); #endif } @@ -633,8 +631,10 @@ XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(descriptor)* desc) struct sencXd(enclosure)* enc = NULL; unsigned ienc, nencs; unsigned enclosed_medium; + int outer_found = 0; res_T res = RES_OK; ASSERT(scn && desc); + (void)outer_found; SENCXD(descriptor_get_enclosure_count(desc, &nencs)); FOR_EACH(ienc, 0, nencs) { @@ -648,9 +648,39 @@ XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(descriptor)* desc) SENCXD(descriptor_get_enclosure(desc, ienc, &enc)); SENCXD(enclosure_get_header(enc, &header)); + if(header.is_infinite) { + ASSERT(!outer_found); + outer_found = 1; + scn->outer_enclosure_id = ienc; + } + /* As paths don't go in infinite enclosures we can accept models are broken * there. But nowhere else. */ if(header.enclosed_media_count != 1 && !header.is_infinite) { +#ifndef NDEBUG + /* Dump the problematic enclosure. */ + unsigned i; + FOR_EACH(i, 0, header.vertices_count) { + double tmp[3]; + SENCXD(enclosure_get_vertex(enc, i, tmp)); + printf("v %g %g %g\n", SPLIT3(tmp)); + } +#if DIM == 2 + FOR_EACH(i, 0, header.segment_count) { + unsigned indices[2]; + SENCXD(enclosure_get_segment(enc, i, indices)); + printf("f %lu %lu\n", (unsigned long)(1 + indices[0]), + (unsigned long)(1 + indices[1])); + } +#else + FOR_EACH(i, 0, header.triangle_count) { + unsigned indices[3]; + SENCXD(enclosure_get_triangle(enc, i, indices)); + printf("f %lu %lu %lu\n", (unsigned long) (1 + indices[0]), + (unsigned long) (1 + indices[1]), (unsigned long) (1 + indices[2])); + } +#endif +#endif res = RES_BAD_ARG; goto error; } @@ -711,6 +741,7 @@ XD(scene_create) SDIS(device_ref_get(dev)); scn->dev = dev; scn->ambient_radiative_temperature = -1; + scn->outer_enclosure_id = UINT_MAX; darray_interf_init(dev->allocator, &scn->interfaces); darray_medium_init(dev->allocator, &scn->media); darray_prim_prop_init(dev->allocator, &scn->prim_props); diff --git a/src/sdis_scene_c.h b/src/sdis_scene_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -132,6 +132,15 @@ enclosure_copy_and_release(struct enclosure* dst, struct enclosure* src) return RES_OK; } +static INLINE unsigned +enclosure_local2global_prim_id + (const struct enclosure* enc, + const size_t local_prim_id) +{ + ASSERT(enc && local_prim_id < darray_uint_size_get(&enc->local2global)); + return darray_uint_cdata_get(&enc->local2global)[local_prim_id]; +} + /* Declare the array of interfaces */ #define DARRAY_NAME interf #define DARRAY_DATA struct sdis_interface* @@ -175,6 +184,7 @@ struct sdis_scene { struct htable_d tmp_hc_ub; /* Map an enclosure id to its hc upper bound */ struct htable_enclosure enclosures; /* Map an enclosure id to its data */ + unsigned outer_enclosure_id; double ambient_radiative_temperature; /* In Kelvin */ @@ -213,6 +223,18 @@ scene_get_enclosure_ids encs[1] = darray_prim_prop_cdata_get(&scn->prim_props)[iprim].back_enclosure; } +static INLINE int +scene_is_outside + (const struct sdis_scene* scn, + const enum sdis_side side, + const unsigned iprim) +{ + unsigned encs[2]; + ASSERT(scn && scn->outer_enclosure_id != UINT_MAX); + scene_get_enclosure_ids(scn, iprim, encs); + return (encs[side] == scn->outer_enclosure_id); +} + static INLINE const struct enclosure* scene_get_enclosure(struct sdis_scene* scn, const unsigned ienc) { diff --git a/src/sdis_solve.c b/src/sdis_solve.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -17,6 +17,7 @@ #include "sdis_camera.h" #include "sdis_device_c.h" #include "sdis_estimator_c.h" +#include "sdis_interface_c.h" #include "sdis_solve_Xd.h" /* Generate the 2D solver */ @@ -64,7 +65,7 @@ solve_pixel size_t N = 0; /* #realisations that do not fail */ size_t irealisation; res_T res = RES_OK; - ASSERT(scn && mdm && rng && cam && ipix && nrealisations); + ASSERT(scn && mdm && rng && cam && ipix && nrealisations && Tref >= 0); ASSERT(pix_sz && pix_sz[0] > 0 && pix_sz[1] > 0); FOR_EACH(irealisation, 0, nrealisations) { @@ -125,7 +126,7 @@ solve_tile size_t mcode; /* Morton code of the tile pixel */ size_t npixels; res_T res = RES_OK; - ASSERT(scn && rng && mdm && cam && spp && origin && accums); + ASSERT(scn && rng && mdm && cam && spp && origin && accums && Tref >= 0); ASSERT(size &&size[0] && size[1]); ASSERT(pix_sz && pix_sz[0] > 0 && pix_sz[1] > 0); @@ -165,7 +166,7 @@ sdis_solve_probe (struct sdis_scene* scn, const size_t nrealisations, const double position[3], - const double time, + const double time_range[2], const double fp_to_meter,/* Scale factor from floating point unit to meter */ const double Tarad, /* Ambient radiative temperature */ const double Tref, /* Reference temperature */ @@ -184,7 +185,9 @@ sdis_solve_probe ATOMIC res = RES_OK; if(!scn || !nrealisations || nrealisations > INT64_MAX || !position - || time < 0 || fp_to_meter <= 0 || Tref < 0 || !out_estimator) { + || !time_range || time_range[0] < 0 || time_range[1] < time_range[0] + || (time_range[1] > DBL_MAX && time_range[0] != time_range[1]) + || fp_to_meter <= 0 || Tref < 0 || !out_estimator) { res = RES_BAD_ARG; goto error; } @@ -207,7 +210,7 @@ sdis_solve_probe } /* Create the estimator */ - res = estimator_create(scn->dev, &estimator); + res = estimator_create(scn->dev, SDIS_TEMPERATURE_ESTIMATOR, &estimator); if(res != RES_OK) goto error; /* Retrieve the medium in which the submitted position lies */ @@ -227,10 +230,10 @@ sdis_solve_probe if(scene_is_2d(scn)) { res_local = probe_realisation_2d - (scn, rng, medium, position, time, fp_to_meter, Tarad, Tref, &w); + (scn, rng, medium, position, time_range, fp_to_meter, Tarad, Tref, &w); } else { res_local = probe_realisation_3d - (scn, rng, medium, position, time, fp_to_meter, Tarad, Tref, &w); + (scn, rng, medium, position, time_range, fp_to_meter, Tarad, Tref, &w); } if(res_local != RES_OK) { if(res_local != RES_BAD_OP) { @@ -243,14 +246,9 @@ sdis_solve_probe ++N; } } + if(res != RES_OK) goto error; - estimator->nrealisations = N; - estimator->nfailures = nrealisations - N; - estimator->temperature.E = weight / (double)N; - estimator->temperature.V = - sqr_weight / (double)N - - estimator->temperature.E * estimator->temperature.E; - estimator->temperature.SE = sqrt(estimator->temperature.V / (double)N); + setup_estimator(estimator, nrealisations, N, weight, sqr_weight); exit: if(rngs) { @@ -276,7 +274,7 @@ sdis_solve_probe_boundary const size_t nrealisations, /* #realisations */ const size_t iprim, /* Identifier of the primitive on which the probe lies */ const double uv[2], /* Parametric coordinates of the probe onto the primitve */ - const double time, /* Observation time */ + const double time_range[2], /* Observation time */ const enum sdis_side side, /* Side of iprim on which the probe lies */ const double fp_to_meter, /* Scale from floating point units to meters */ const double Tarad, /* In Kelvin */ @@ -294,7 +292,9 @@ sdis_solve_probe_boundary size_t i; ATOMIC res = RES_OK; - if(!scn || !nrealisations || nrealisations > INT64_MAX || !uv || time < 0 + if(!scn || !nrealisations || nrealisations > INT64_MAX || !uv + || !time_range || time_range[0] < 0 || time_range[1] < time_range[0] + || (time_range[1] > DBL_MAX && time_range[0] != time_range[1]) || fp_to_meter <= 0 || Tref < 0 || (side != SDIS_FRONT && side != SDIS_BACK) || !out_estimator) { res = RES_BAD_ARG; @@ -304,10 +304,10 @@ sdis_solve_probe_boundary /* Check the primitive identifier */ if(iprim >= scene_get_primitives_count(scn)) { log_err(scn->dev, -"%s: invalid primitive identifier `%lu'. It must be less than %lu.\n", +"%s: invalid primitive identifier `%lu'. It must be in the [0 %lu] range.\n", FUNC_NAME, (unsigned long)iprim, - (unsigned long)scene_get_primitives_count(scn)); + (unsigned long)scene_get_primitives_count(scn)-1); res = RES_BAD_ARG; goto error; } @@ -354,7 +354,7 @@ sdis_solve_probe_boundary } /* Create the estimator */ - res = estimator_create(scn->dev, &estimator); + res = estimator_create(scn->dev, SDIS_TEMPERATURE_ESTIMATOR, &estimator); if(res != RES_OK) goto error; /* Here we go! Launch the Monte Carlo estimation */ @@ -366,14 +366,14 @@ sdis_solve_probe_boundary const int ithread = omp_get_thread_num(); struct ssp_rng* rng = rngs[ithread]; - if(ATOMIC_GET(&res) != RES_OK) continue; /* An error occured */ + if(ATOMIC_GET(&res) != RES_OK) continue; /* An error occurred */ if(scene_is_2d(scn)) { res_local = boundary_realisation_2d - (scn, rng, iprim, uv, time, side, fp_to_meter, Tarad, Tref, &w); + (scn, rng, iprim, uv, time_range, side, fp_to_meter, Tarad, Tref, &w); } else { res_local = boundary_realisation_3d - (scn, rng, iprim, uv, time, side, fp_to_meter, Tarad, Tref, &w); + (scn, rng, iprim, uv, time_range, side, fp_to_meter, Tarad, Tref, &w); } if(res_local != RES_OK) { if(res_local != RES_BAD_OP) { @@ -386,14 +386,9 @@ sdis_solve_probe_boundary ++N; } } + if(res != RES_OK) goto error; - estimator->nrealisations = N; - estimator->nfailures = nrealisations - N; - estimator->temperature.E = weight / (double)N; - estimator->temperature.V = - sqr_weight / (double)N - - estimator->temperature.E * estimator->temperature.E; - estimator->temperature.SE = sqrt(estimator->temperature.V / (double)N); + setup_estimator(estimator, nrealisations, N, weight, sqr_weight); exit: if(rngs) { @@ -551,3 +546,245 @@ error: goto exit; } +res_T +sdis_solve_boundary + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const enum sdis_side sides[], /* Per primitive side to consider */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double Tarad, /* In Kelvin */ + const double Tref, /* In Kelvin */ + struct sdis_estimator** out_estimator) +{ + res_T res = RES_OK; + if(!scn) return RES_BAD_ARG; + if(scene_is_2d(scn)) { + res = solve_boundary_2d(scn, nrealisations, primitives, sides, nprimitives, + time_range, fp_to_meter, Tarad, Tref, out_estimator); + } else { + res = solve_boundary_3d(scn, nrealisations, primitives, sides, nprimitives, + time_range, fp_to_meter, Tarad, Tref, out_estimator); + } + return res; +} + +res_T +sdis_solve_probe_boundary_flux + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t iprim, /* Identifier of the primitive on which the probe lies */ + const double uv[2], /* Parametric coordinates of the probe onto the primitve */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double Tarad, /* In Kelvin */ + const double Tref, /* In Kelvin */ + struct sdis_estimator** out_estimator) +{ + struct sdis_estimator* estimator = NULL; + struct ssp_rng_proxy* rng_proxy = NULL; + struct ssp_rng** rngs = NULL; + const struct sdis_interface* interf; + const struct sdis_medium *fmd, *bmd; + enum sdis_side solid_side, fluid_side; + struct sdis_interface_fragment frag; + double weight_t = 0, sqr_weight_t = 0; + double weight_fc = 0, sqr_weight_fc = 0; + double weight_fr = 0, sqr_weight_fr = 0; + double weight_f= 0, sqr_weight_f = 0; + const int64_t rcount = (int64_t)nrealisations; + int64_t irealisation = 0; + size_t N = 0; /* #realisations that do not fail */ + size_t i; + ATOMIC res = RES_OK; + + if(!scn || !nrealisations || nrealisations > INT64_MAX || !uv + || !time_range || time_range[0] < 0 || time_range[1] < time_range[0] + || (time_range[1] > DBL_MAX && time_range[0] != time_range[1]) + || fp_to_meter <= 0 || Tref < 0 + || !out_estimator) { + res = RES_BAD_ARG; + goto error; + } + + /* Check the primitive identifier */ + if(iprim >= scene_get_primitives_count(scn)) { + log_err(scn->dev, + "%s: invalid primitive identifier `%lu'. It must be in the [0 %lu] range.\n", + FUNC_NAME, + (unsigned long)iprim, + (unsigned long)scene_get_primitives_count(scn)-1); + res = RES_BAD_ARG; + goto error; + } + + /* Check parametric coordinates */ + if(scene_is_2d(scn)) { + const double v = CLAMP(1.0 - uv[0], 0, 1); + if(uv[0] < 0 || uv[0] > 1 || !eq_eps(uv[0] + v, 1, 1.e-6)) { + log_err(scn->dev, + "%s: invalid parametric coordinates %g.\n" + "u + (1-u) must be equal to 1 with u [0, 1].\n", + FUNC_NAME, uv[0]); + res = RES_BAD_ARG; + goto error; + } + } else { + const double w = CLAMP(1 - uv[0] - uv[1], 0, 1); + if(uv[0] < 0 || uv[1] < 0 || uv[0] > 1 || uv[1] > 1 + || !eq_eps(w + uv[0] + uv[1], 1, 1.e-6)) { + log_err(scn->dev, + "%s: invalid parametric coordinates [%g, %g].\n" + "u + v + (1-u-v) must be equal to 1 with u and v in [0, 1].\n", + FUNC_NAME, uv[0], uv[1]); + res = RES_BAD_ARG; + goto error; + } + } + /* Check medium is fluid on one side and solid on the other */ + interf = scene_get_interface(scn, (unsigned)iprim); + fmd = interface_get_medium(interf, SDIS_FRONT); + bmd = interface_get_medium(interf, SDIS_BACK); + if(!fmd || !bmd + || (!(fmd->type == SDIS_FLUID && bmd->type == SDIS_SOLID) + && !(fmd->type == SDIS_SOLID && bmd->type == SDIS_FLUID))) + { + res = RES_BAD_ARG; + goto error; + } + solid_side = (fmd->type == SDIS_SOLID) ? SDIS_FRONT : SDIS_BACK; + fluid_side = (fmd->type == SDIS_FLUID) ? SDIS_FRONT : SDIS_BACK; + + /* Create the proxy RNG */ + res = ssp_rng_proxy_create(scn->dev->allocator, &ssp_rng_mt19937_64, + scn->dev->nthreads, &rng_proxy); + if(res != RES_OK) goto error; + + /* Create the per thread RNG */ + rngs = MEM_CALLOC + (scn->dev->allocator, scn->dev->nthreads, sizeof(struct ssp_rng*)); + if(!rngs) { + res = RES_MEM_ERR; + goto error; + } + FOR_EACH(i, 0, scn->dev->nthreads) { + res = ssp_rng_proxy_create_rng(rng_proxy, i, rngs + i); + if(res != RES_OK) goto error; + } + + /* Prebuild the interface fragment */ + if(scene_is_2d(scn)) { + res = interface_prebuild_fragment_2d(&frag, scn, (unsigned)iprim, + uv, fluid_side); + } else { + res = interface_prebuild_fragment_3d(&frag, scn, (unsigned)iprim, + uv, fluid_side); + } + + /* Create the estimator */ + res = estimator_create(scn->dev, SDIS_FLUX_ESTIMATOR, &estimator); + if(res != RES_OK) goto error; + + /* Here we go! Launch the Monte Carlo estimation */ + omp_set_num_threads((int)scn->dev->nthreads); + #pragma omp parallel for schedule(static) reduction(+:weight_t,sqr_weight_t,\ + weight_fc,sqr_weight_fc,weight_fr,sqr_weight_fr,weight_f,sqr_weight_f,N) + for(irealisation = 0; irealisation < rcount; ++irealisation) { + res_T res_local; + double T_brf[3] = { 0, 0, 0 }; + const int ithread = omp_get_thread_num(); + struct ssp_rng* rng = rngs[ithread]; + double time, epsilon, hc, hr; + + if(ATOMIC_GET(&res) != RES_OK) continue; /* An error occurred */ + + /* Sample a time */ + time = sample_time(time_range, rng); + + /* Compute hr and hc */ + frag.time = time; + epsilon = interface_side_get_emissivity(interf, &frag); + hc = interface_get_convection_coef(interf, &frag); + hr = 4.0 * BOLTZMANN_CONSTANT * Tref * Tref * Tref * epsilon; + + /* Fluid, Radiative and Solid temperatures */ + if(scene_is_2d(scn)) { + res_local = probe_flux_realisation_2d(scn, rng, iprim, uv, time, + solid_side, fp_to_meter, Tarad, Tref, hr>0, hc>0, T_brf); + } else { + res_local = probe_flux_realisation_3d(scn, rng, iprim, uv, time, + solid_side, fp_to_meter, Tarad, Tref, hr>0, hc>0, T_brf); + } + if(res_local != RES_OK) { + if(res_local != RES_BAD_OP) { + ATOMIC_SET(&res, res_local); + continue; + } + } else { + const double Tboundary = T_brf[0]; + const double Tradiative = T_brf[1]; + const double Tfluid = T_brf[2]; + const double w_conv = hc * (Tboundary - Tfluid); + const double w_rad = hr * (Tboundary - Tradiative); + const double w_total = w_conv + w_rad; + weight_t += Tboundary; + sqr_weight_t += Tboundary * Tboundary; + weight_fc += w_conv; + sqr_weight_fc += w_conv * w_conv; + weight_fr += w_rad; + sqr_weight_fr += w_rad * w_rad; + weight_f += w_total; + sqr_weight_f += w_total * w_total; + ++N; + } + } + if(res != RES_OK) goto error; + + setup_estimator(estimator, nrealisations, N, weight_t, sqr_weight_t); + setup_estimator_flux(estimator, FLUX_CONVECTIVE__, weight_fc, sqr_weight_fc); + setup_estimator_flux(estimator, FLUX_RADIATIVE__, weight_fr, sqr_weight_fr); + setup_estimator_flux(estimator, FLUX_TOTAL__, weight_f, sqr_weight_f); + +exit: + if(rngs) { + FOR_EACH(i, 0, scn->dev->nthreads) { + if(rngs[i]) SSP(rng_ref_put(rngs[i])); + } + MEM_RM(scn->dev->allocator, rngs); + } + if(rng_proxy) SSP(rng_proxy_ref_put(rng_proxy)); + if(out_estimator) *out_estimator = estimator; + return (res_T)res; +error: + if(estimator) { + SDIS(estimator_ref_put(estimator)); + estimator = NULL; + } + goto exit; +} + +res_T +sdis_solve_boundary_flux + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double Tarad, /* In Kelvin */ + const double Tref, /* In Kelvin */ + struct sdis_estimator** out_estimator) +{ + res_T res = RES_OK; + if(!scn) return RES_BAD_ARG; + if(scene_is_2d(scn)) { + res = solve_boundary_flux_2d(scn, nrealisations, primitives, nprimitives, + time_range, fp_to_meter, Tarad, Tref, out_estimator); + } else { + res = solve_boundary_flux_3d(scn, nrealisations, primitives, nprimitives, + time_range, fp_to_meter, Tarad, Tref, out_estimator); + } + return res; +} diff --git a/src/sdis_solve_Xd.h b/src/sdis_solve_Xd.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -27,6 +27,7 @@ #include <rsys/stretchy_array.h> #include <star/ssp.h> +#include <omp.h> /* Define a new result code from RES_BAD_OP saying that the bad operation is * definitive, i.e. in the current state, the realisation will inevitably fail. @@ -80,6 +81,55 @@ reflect_3d(float res[3], const float V[3], const float N[3]) return res; } +static INLINE void +setup_estimator + (struct sdis_estimator* estimator, + const size_t nrealisations, + const size_t nsuccesses, + const double accum_weights, + const double accum_sqr_weights) +{ + ASSERT(estimator && nrealisations && nsuccesses); + estimator->nrealisations = nsuccesses; + estimator->nfailures = nrealisations - nsuccesses; + estimator->temperature.E = accum_weights / (double)nsuccesses; + estimator->temperature.V = + accum_sqr_weights / (double)nsuccesses + - estimator->temperature.E * estimator->temperature.E; + estimator->temperature.V = MMAX(estimator->temperature.V, 0); + estimator->temperature.SE = + sqrt(estimator->temperature.V / (double)nsuccesses); +} + +static INLINE void +setup_estimator_flux + (struct sdis_estimator* estimator, + const enum flux_names name, + const double accum_weights, + const double accum_sqr_weights) +{ + ASSERT(estimator && (unsigned)name < FLUX_NAMES_COUNT__ && estimator->fluxes); + ASSERT(estimator->nrealisations); + estimator->fluxes[name].E = accum_weights / (double)estimator->nrealisations; + estimator->fluxes[name].V = + accum_sqr_weights / (double)estimator->nrealisations + - estimator->fluxes[name].E * estimator->fluxes[name].E; + estimator->fluxes[name].V = MMAX(estimator->fluxes[name].V, 0); + estimator->fluxes[name].SE = + sqrt(estimator->fluxes[name].V / (double)estimator->nrealisations); +} + +static INLINE double +sample_time + (const double time_range[2], + struct ssp_rng* rng) +{ + ASSERT(time_range && time_range[0] >= 0 && time_range[1] >= time_range[0]); + ASSERT(rng); + if(time_range[0] == time_range[1]) return time_range[0]; + return ssp_rng_uniform_double(rng, time_range[0], time_range[1]); +} + #endif /* SDIS_SOLVE_XD_H */ #else @@ -106,7 +156,13 @@ reflect_3d(float res[3], const float V[3], const float N[3]) #define SXD_HIT_NULL__ CONCAT(CONCAT(S, DIM), D_HIT_NULL__) #define SXD_POSITION CONCAT(CONCAT(S, DIM), D_POSITION) #define SXD_GEOMETRY_NORMAL CONCAT(CONCAT(S, DIM), D_GEOMETRY_NORMAL) +#define SXD_GEOMETRY_NORMAL CONCAT(CONCAT(S, DIM), D_GEOMETRY_NORMAL) +#define SXD_VERTEX_DATA_NULL CONCAT(CONCAT(S, DIM), D_VERTEX_DATA_NULL) #define SXD CONCAT(CONCAT(S, DIM), D) +#define SXD_FLOAT2 CONCAT(CONCAT(S, DIM), D_FLOAT2) +#define SXD_FLOAT3 CONCAT(CONCAT(S, DIM), D_FLOAT3) +#define SXD_SAMPLE CONCAT(CONCAT(S, DIM), D_SAMPLE) +#define sXd_dev CONCAT(CONCAT(s, DIM), d) /* Vector macros generic to SDIS_SOLVE_DIMENSION */ #define dX(Func) CONCAT(CONCAT(CONCAT(d, DIM), _), Func) @@ -128,6 +184,14 @@ static const struct XD(rwalk) XD(RWALK_NULL) = { SDIS_RWALK_VERTEX_NULL__, NULL, SXD_HIT_NULL__, SDIS_SIDE_NULL__ }; +struct XD(boundary_context) { + struct sXd(scene_view)* view; + const size_t* primitives; +}; +static const struct XD(boundary_context) XD(BOUNDARY_CONTEXT_NULL) = { + NULL, NULL +}; + struct XD(temperature) { res_T (*func)/* Next function to invoke in order to compute the temperature */ (struct sdis_scene* scn, @@ -180,6 +244,38 @@ XD(radiative_temperature) /******************************************************************************* * Helper functions ******************************************************************************/ +static INLINE void +XD(boundary_get_indices)(const unsigned iprim, unsigned ids[DIM], void* context) +{ + unsigned i; + (void)context; + ASSERT(ids); + FOR_EACH(i, 0, DIM) ids[i] = iprim*DIM + i; +} + +static INLINE void +XD(boundary_get_position)(const unsigned ivert, float pos[DIM], void* context) +{ + struct XD(boundary_context)* ctx = context; + struct sXd(primitive) prim; + struct sXd(attrib) attr; + const unsigned iprim_id = ivert / DIM; + const unsigned iprim_vert = ivert % DIM; + unsigned iprim; + ASSERT(pos && context); + + iprim = (unsigned)ctx->primitives[iprim_id]; + SXD(scene_view_get_primitive(ctx->view, iprim, &prim)); +#if DIM == 2 + s2d_segment_get_vertex_attrib(&prim, iprim_vert, S2D_POSITION, &attr); + ASSERT(attr.type == S2D_FLOAT2); +#else + s3d_triangle_get_vertex_attrib(&prim, iprim_vert, S3D_POSITION, &attr); + ASSERT(attr.type == S3D_FLOAT3); +#endif + fX(set)(pos, attr.value); +} + static FINLINE void XD(move_pos)(double pos[DIM], const float dir[DIM], const float delta) { @@ -340,7 +436,7 @@ XD(trace_radiative_path) log_err(scn->dev, "%s: invalid overall emissivity `%g' at position `%g %g %g'.\n", FUNC_NAME, epsilon, SPLIT3(rwalk->vtx.P)); - res = RES_BAD_ARG; + res = RES_BAD_OP; goto error; } @@ -363,10 +459,19 @@ XD(trace_radiative_path) } if(chk_mdm != rwalk->mdm) { - log_err(scn->dev, "%s: inconsistent medium definition at `%g %g %g'.\n", - FUNC_NAME, SPLIT3(rwalk->vtx.P)); - res = RES_BAD_OP; - goto error; + /* To ease the setting of models, the external enclosure is allowed to be + * incoherent regarding media. + * Here a radiative path is allowed to join 2 different fluids. */ + const int outside = scene_is_outside + (scn, rwalk->hit_side, rwalk->hit.prim.prim_id); + if(outside && chk_mdm->type == SDIS_FLUID) { + rwalk->mdm = chk_mdm; + } else { + log_err(scn->dev, "%s: inconsistent medium definition at `%g %g %g'.\n", + FUNC_NAME, SPLIT3(rwalk->vtx.P)); + res = RES_BAD_OP; + goto error; + } } alpha = interface_side_get_specular_fraction(interf, &frag); r = ssp_rng_canonical(rng); @@ -440,8 +545,6 @@ XD(fluid_temperature) double rho; /* Volumic mass */ double hc; /* Convection coef */ double cp; /* Calorific capacity */ - double mu; - double tau; double tmp; double r; #if DIM == 2 @@ -500,18 +603,21 @@ XD(fluid_temperature) /* Fetch the enclosure data */ enc = scene_get_enclosure(scn, enc_id); if(!enc) { + /* The possibility for a fluid enclosure to be unregistred is that it is + * the external enclosure. In this situation unknown temperature is + * forbidden. */ log_err(scn->dev, -"%s: invalid enclosure. The position %g %g %g may lie in the surrounding fluid.\n", - FUNC_NAME, SPLIT3(rwalk->vtx.P)); - return RES_BAD_OP; +"%s: invalid enclosure. The surrounding fluid has an unset temperature.\n", + FUNC_NAME); + return RES_BAD_ARG; } - /* The hc upper bound can be 0 is h is uniformly 0. In that case the result + /* The hc upper bound can be 0 if h is uniformly 0. In that case the result * is the initial condition. */ if(enc->hc_upper_bound == 0) { /* Cannot be in the fluid without starting there. */ ASSERT(SXD_HIT_NONE(&rwalk->hit)); - rwalk->vtx.time = 0; + rwalk->vtx.time = fluid_get_t0(rwalk->mdm); tmp = fluid_get_temperature(rwalk->mdm, &rwalk->vtx); if(tmp >= 0) { T->value += tmp; @@ -521,8 +627,8 @@ XD(fluid_temperature) /* At t=0, the initial condition should have been reached. */ log_err(scn->dev, -"%s: undefined initial condition. " -"Time is 0 but the temperature remains unknown.\n", + "%s: undefined initial condition. " + "Time is 0 but the temperature remains unknown.\n", FUNC_NAME); return RES_BAD_OP; } @@ -532,6 +638,7 @@ XD(fluid_temperature) /* Sample time until init condition is reached or a true convection occurs. */ for(;;) { + struct sXd(primitive) prim; /* Setup the fragment of the interface. */ XD(setup_interface_fragment)(&frag, &rwalk->vtx, &rwalk->hit, rwalk->hit_side); @@ -554,46 +661,50 @@ XD(fluid_temperature) rho = fluid_get_volumic_mass(rwalk->mdm, &rwalk->vtx); /* Sample the time using the upper bound. */ - mu = enc->hc_upper_bound / (rho * cp) * enc->S_over_V; - tau = ssp_ran_exp(rng, mu); - rwalk->vtx.time = MMAX(rwalk->vtx.time - tau, 0); - - /* Check the initial condition. */ - tmp = fluid_get_temperature(rwalk->mdm, &rwalk->vtx); - if(tmp >= 0) { - T->value += tmp; - T->done = 1; - return RES_OK; - } - - if(rwalk->vtx.time <= 0) { - /* The initial condition should have been reached. */ - log_err(scn->dev, -"%s: undefined initial condition. " -"Time is 0 but the temperature remains unknown.\n", - FUNC_NAME); - return RES_BAD_OP; + if(rwalk->vtx.time != INF) { + double mu, tau, t0; + mu = enc->hc_upper_bound / (rho * cp) * enc->S_over_V; + tau = ssp_ran_exp(rng, mu); + t0 = fluid_get_t0(rwalk->mdm); + rwalk->vtx.time = MMAX(rwalk->vtx.time - tau, t0); + if(rwalk->vtx.time == t0) { + /* Check the initial condition. */ + tmp = fluid_get_temperature(rwalk->mdm, &rwalk->vtx); + if(tmp >= 0) { + T->value += tmp; + T->done = 1; + return RES_OK; + } + /* The initial condition should have been reached. */ + log_err(scn->dev, + "%s: undefined initial condition. " + "Time is %g but the temperature remains unknown.\n", + FUNC_NAME, t0); + return RES_BAD_OP; + } } /* Uniformly sample the enclosure. */ #if DIM == 2 SXD(scene_view_sample - (enc->sXd(view), - ssp_rng_canonical_float(rng), - ssp_rng_canonical_float(rng), - &rwalk->hit.prim, - &rwalk->hit.u)); + (enc->sXd(view), + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, &rwalk->hit.u)); st = rwalk->hit.u; #else SXD(scene_view_sample - (enc->sXd(view), - ssp_rng_canonical_float(rng), - ssp_rng_canonical_float(rng), - ssp_rng_canonical_float(rng), - &rwalk->hit.prim, - rwalk->hit.uv)); + (enc->sXd(view), + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, rwalk->hit.uv)); f2_set(st, rwalk->hit.uv); #endif + /* Map the sampled primitive id from the enclosure space to the scene + * space. Note that the overall scene has only one shape. As a consequence + * neither the geom_id nor the inst_id needs to be updated */ + rwalk->hit.prim.prim_id = enclosure_local2global_prim_id(enc, prim.prim_id); SXD(primitive_get_attrib(&rwalk->hit.prim, SXD_POSITION, st, &attr_P)); SXD(primitive_get_attrib(&rwalk->hit.prim, SXD_GEOMETRY_NORMAL, st, &attr_N)); @@ -602,6 +713,13 @@ XD(fluid_temperature) /* Fetch the interface of the sampled point. */ interf = scene_get_interface(scn, rwalk->hit.prim.prim_id); + if(rwalk->mdm == interf->medium_front) { + rwalk->hit_side = SDIS_FRONT; + } else if(rwalk->mdm == interf->medium_back) { + rwalk->hit_side = SDIS_BACK; + } else { + FATAL("Unexpected fluid interface.\n"); + } /* Renew r for next loop. */ r = ssp_rng_canonical_float(rng); @@ -1059,7 +1177,7 @@ XD(boundary_temperature) return RES_OK; } - /* Check if the boundary flux is known. Note that actually, only solid media + /* Check if the boundary flux is known. Note that currently, only solid media * can have a flux as limit condition */ mdm = interface_get_medium(interf, frag.side); if(sdis_medium_get_type(mdm) == SDIS_SOLID ) { @@ -1084,6 +1202,20 @@ XD(boundary_temperature) return RES_OK; } +#ifdef COMPILER_CL +#pragma warning(push) +#pragma warning(disable : 4701) +/* potentially uninitialized local variable 'info' used + * + * For warning numbers in the range 4700-4999, which are the ones associated + * with code generation, the state of the warning in effect when the compiler + * encounters the open curly brace of a function will be in effect for the rest + * of the function. Using the warning pragma in the function to change the + * state of a warning that has a number larger than 4699 will only take effect + * after the end of the function. The following example shows the correct + * placement of warning pragmas to disable a code-generation warning message, + * and then to restore it. */ +#endif res_T XD(solid_temperature) (struct sdis_scene* scn, @@ -1116,7 +1248,6 @@ XD(solid_temperature) double lambda; /* Thermal conductivity */ double rho; /* Volumic mass */ double cp; /* Calorific capacity */ - double tau, mu; double tmp; double power; float delta, delta_solid; /* Random walk numerical parameter */ @@ -1205,7 +1336,7 @@ XD(solid_temperature) tmp += (power*delta_s_in_meter*delta_s_in_meter)/(6*lambda) * tmp1; #endif - } else if (h == delta_solid) { + } else if(h == delta_solid) { tmp += -(delta_s_in_meter*delta_s_in_meter*power)/(2.0*DIM*lambda); } T->value += tmp; @@ -1213,25 +1344,27 @@ XD(solid_temperature) } /* Sample the time */ - mu = (2*DIM*lambda) / (rho*cp*delta*fp_to_meter*delta*fp_to_meter); - tau = ssp_ran_exp(rng, mu); - rwalk->vtx.time = MMAX(rwalk->vtx.time - tau, 0); - - /* Check the initial condition */ - tmp = solid_get_temperature(mdm, &rwalk->vtx); - if(tmp >= 0) { - T->value += tmp; - T->done = 1; - return RES_OK; - } - - /* The initial condition should be reached */ - if(rwalk->vtx.time <=0) { - log_err(scn->dev, - "%s: undefined initial condition. " - "The time is null but the temperature remains unknown.\n", - FUNC_NAME); - return RES_BAD_OP; + if(rwalk->vtx.time != INF) { + double tau, mu, t0; + mu = (2*DIM*lambda) / (rho*cp*delta*fp_to_meter*delta*fp_to_meter); + tau = ssp_ran_exp(rng, mu); + t0 = solid_get_t0(rwalk->mdm); + rwalk->vtx.time = MMAX(rwalk->vtx.time - tau, t0); + if(rwalk->vtx.time == t0) { + /* Check the initial condition */ + tmp = solid_get_temperature(mdm, &rwalk->vtx); + if(tmp >= 0) { + T->value += tmp; + T->done = 1; + return RES_OK; + } + /* The initial condition should have been reached */ + log_err(scn->dev, + "%s: undefined initial condition. " + "The time is %f but the temperature remains unknown.\n", + FUNC_NAME, t0); + return RES_BAD_OP; + } } /* Define if the random walk hits something along dir0 */ @@ -1291,6 +1424,9 @@ XD(solid_temperature) rwalk->mdm = NULL; /* The random walk is at an interface between 2 media */ return RES_OK; } +#ifdef COMPILER_CL +#pragma warning(pop) +#endif static res_T XD(compute_temperature) @@ -1352,7 +1488,7 @@ XD(probe_realisation) struct ssp_rng* rng, const struct sdis_medium* medium, const double position[], - const double time, + const double time_range[2], const double fp_to_meter,/* Scale factor from floating point unit to meter */ const double ambient_radiative_temperature, const double reference_temperature, @@ -1361,17 +1497,46 @@ XD(probe_realisation) struct rwalk_context ctx; struct XD(rwalk) rwalk = XD(RWALK_NULL); struct XD(temperature) T = XD(TEMPERATURE_NULL); + double (*get_initial_temperature) + (const struct sdis_medium* mdm, const struct sdis_rwalk_vertex* vtx); + double t0; res_T res = RES_OK; - ASSERT(medium && position && fp_to_meter > 0 && weight && time >= 0); + ASSERT(medium && position && fp_to_meter > 0 && weight); switch(medium->type) { - case SDIS_FLUID: T.func = XD(fluid_temperature); break; - case SDIS_SOLID: T.func = XD(solid_temperature); break; + case SDIS_FLUID: + T.func = XD(fluid_temperature); + get_initial_temperature = fluid_get_temperature; + t0 = fluid_get_t0(medium); + break; + case SDIS_SOLID: + T.func = XD(solid_temperature); + get_initial_temperature = solid_get_temperature; + t0 = solid_get_t0(medium); + break; default: FATAL("Unreachable code\n"); break; } dX(set)(rwalk.vtx.P, position); - rwalk.vtx.time = time; + /* Sample a time */ + rwalk.vtx.time = sample_time(time_range, rng); + if(t0 >= rwalk.vtx.time) { + double tmp; + /* Check the initial condition. */ + rwalk.vtx.time = t0; + tmp = get_initial_temperature(medium, &rwalk.vtx); + if(tmp >= 0) { + *weight = tmp; + return RES_OK; + } + /* The initial condition should have been reached */ + log_err(scn->dev, + "%s: undefined initial condition. " + "The time is %f but the temperature remains unknown.\n", + FUNC_NAME, t0); + return RES_BAD_OP; + } + rwalk.hit = SXD_HIT_NULL; rwalk.mdm = medium; @@ -1393,8 +1558,8 @@ XD(boundary_realisation) (struct sdis_scene* scn, struct ssp_rng* rng, const size_t iprim, - const double uv[DIM], - const double time, + const double uv[2], + const double time_range[2], const enum sdis_side side, const double fp_to_meter, const double Tarad, @@ -1411,13 +1576,14 @@ XD(boundary_realisation) float st[2]; #endif res_T res = RES_OK; - ASSERT(uv && fp_to_meter > 0 && weight && time >= 0); + ASSERT(uv && fp_to_meter > 0 && weight && Tref >= 0 + && time_range && time_range[0] >= 0 && time_range[1] >= time_range[0]); T.func = XD(boundary_temperature); - rwalk.hit_side = side; rwalk.hit.distance = 0; - rwalk.vtx.time = time; + /* Sample a time */ + rwalk.vtx.time = sample_time(time_range, rng); rwalk.mdm = NULL; /* The random walk is at an interface between 2 media */ #if SDIS_SOLVE_DIMENSION == 2 @@ -1454,6 +1620,180 @@ XD(boundary_realisation) return RES_OK; } +static res_T +XD(probe_flux_realisation) + (struct sdis_scene* scn, + struct ssp_rng* rng, + const size_t iprim, + const double uv[DIM], + const double time, + const enum sdis_side solid_side, + const double fp_to_meter, + const double Tarad, + const double Tref, + const char compute_radiative, + const char compute_convective, + double weight[3]) +{ + struct rwalk_context ctx; + struct XD(rwalk) rwalk; + struct XD(temperature) T; + struct sXd(attrib) attr; + struct sXd(primitive) prim; +#if SDIS_SOLVE_DIMENSION == 2 + float st; +#else + float st[2]; +#endif + double P[SDIS_SOLVE_DIMENSION]; + float N[SDIS_SOLVE_DIMENSION]; + const double Tr3 = Tref * Tref * Tref; + const enum sdis_side fluid_side = + (solid_side == SDIS_FRONT) ? SDIS_BACK : SDIS_FRONT; + res_T res = RES_OK; + ASSERT(uv && fp_to_meter > 0 && weight && time >= 0 && Tref >= 0); + +#if SDIS_SOLVE_DIMENSION == 2 + #define SET_PARAM(Dest, Src) (Dest).u = (Src); + st = (float)uv[0]; +#else + #define SET_PARAM(Dest, Src) f2_set((Dest).uv, (Src)); + f2_set_d2(st, uv); +#endif + + /* Fetch the primitive */ + SXD(scene_view_get_primitive(scn->sXd(view), (unsigned int)iprim, &prim)); + + /* Retrieve the world space position of the probe onto the primitive */ + SXD(primitive_get_attrib(&prim, SXD_POSITION, st, &attr)); + dX_set_fX(P, attr.value); + + /* Retrieve the primitive normal */ + SXD(primitive_get_attrib(&prim, SXD_GEOMETRY_NORMAL, st, &attr)); + fX(set)(N, attr.value); + + #define RESET_WALK(Side, Mdm) \ + rwalk = XD(RWALK_NULL); \ + rwalk.hit_side = (Side); \ + rwalk.hit.distance = 0; \ + rwalk.vtx.time = time; \ + rwalk.mdm = (Mdm); \ + SET_PARAM(rwalk.hit, st); \ + ctx.Tarad = Tarad; \ + ctx.Tref3 = Tr3; \ + rwalk.hit.prim = prim; \ + dX(set)(rwalk.vtx.P, P); \ + fX(set)(rwalk.hit.normal, N); \ + T = XD(TEMPERATURE_NULL); + + /* Compute boundary temperature */ + RESET_WALK(solid_side, NULL); + T.func = XD(boundary_temperature); + res = XD(compute_temperature)(scn, fp_to_meter, &ctx, &rwalk, rng, &T); + if(res != RES_OK) return res; + weight[0] = T.value; + + /* Compute radiative temperature */ + if(compute_radiative) { + RESET_WALK(fluid_side, NULL); + T.func = XD(radiative_temperature); + res = XD(compute_temperature)(scn, fp_to_meter, &ctx, &rwalk, rng, &T); + if(res != RES_OK) return res; + weight[1] = T.value; + } + + /* Compute fluid temperature */ + if(compute_convective) { + const struct sdis_interface* interf = + scene_get_interface(scn, (unsigned)iprim); + const struct sdis_medium* mdm = interface_get_medium(interf, fluid_side); + + RESET_WALK(fluid_side, mdm); + T.func = XD(fluid_temperature); + res = XD(compute_temperature)(scn, fp_to_meter, &ctx, &rwalk, rng, &T); + if(res != RES_OK) return res; + weight[2] = T.value; + } + + #undef SET_PARAM + #undef RESET_WALK + + return RES_OK; +} + +static INLINE res_T +XD(interface_prebuild_fragment) + (struct sdis_interface_fragment* frag, + const struct sdis_scene* scn, + const unsigned iprim, + const double* uv, + const enum sdis_side fluid_side) +{ struct sXd(attrib) attr; + struct sXd(primitive) prim; + struct sXd(hit) hit; + struct sdis_rwalk_vertex vtx; +#if SDIS_SOLVE_DIMENSION == 2 + float st; +#else + float st[2]; +#endif + res_T res = RES_OK; + + ASSERT(frag && scn && uv); + ASSERT(fluid_side == SDIS_FRONT || fluid_side == SDIS_BACK); + + *frag = SDIS_INTERFACE_FRAGMENT_NULL; + +#if SDIS_SOLVE_DIMENSION == 2 +#define SET_PARAM(Dest, Src) (Dest).u = (Src); + st = (float)uv[0]; +#else +#define SET_PARAM(Dest, Src) f2_set((Dest).uv, (Src)); + f2_set_d2(st, uv); +#endif + res = sXd(scene_view_get_primitive(scn->sXd(view), iprim, &prim)); + if(res != RES_OK) return res; + res = sXd(primitive_get_attrib(&prim, SXD_POSITION, st, &attr)); + if(res != RES_OK) return res; + dX_set_fX(vtx.P, attr.value); + res = sXd(primitive_get_attrib(&prim, SXD_GEOMETRY_NORMAL, st, &attr)); + if(res != RES_OK) return res; + fX(set)(hit.normal, attr.value); + + hit.distance = 0; + hit.prim = prim; + vtx.time = NaN; + SET_PARAM(hit, st); + #undef SET_PARAM + XD(setup_interface_fragment)(frag, &vtx, &hit, fluid_side); + + return res; +} + +static res_T +XD(interface_get_hc_epsilon) + (double *hc, + double* epsilon, + const struct sdis_scene* scn, + const unsigned iprim, + const double* uv, + const double time, + const enum sdis_side fluid_side) +{ + struct sdis_interface_fragment frag; + const struct sdis_interface* interf; + res_T res = RES_OK; + + res = XD(interface_prebuild_fragment)(&frag, scn, iprim, uv, fluid_side); + frag.time = time; + interf = scene_get_interface(scn, iprim); + ASSERT(interf); + *epsilon = interface_side_get_emissivity(interf, &frag); + *hc = interface_get_convection_coef(interf, &frag); + + return res; +} + #if SDIS_SOLVE_DIMENSION == 3 static res_T XD(ray_realisation) @@ -1473,7 +1813,8 @@ XD(ray_realisation) struct XD(temperature) T = XD(TEMPERATURE_NULL); float dir[3]; res_T res = RES_OK; - ASSERT(scn && position && direction && time>=0 && fp_to_meter>0 && weight); + ASSERT(scn && position && direction && time>=0 && fp_to_meter>0 && weight + && Tref >= 0); ASSERT(medium && medium->type == SDIS_FLUID); dX(set)(rwalk.vtx.P, position); @@ -1504,14 +1845,416 @@ error: } #endif /* SDIS_SOLVE_DIMENSION == 3 */ +static res_T +XD(solve_boundary) + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const enum sdis_side sides[], /* Per primitive side to consider */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double Tarad, /* In Kelvin */ + const double Tref, /* In Kelvin */ + struct sdis_estimator** out_estimator) +{ + struct XD(boundary_context) ctx = XD(BOUNDARY_CONTEXT_NULL); + struct sXd(vertex_data) vdata = SXD_VERTEX_DATA_NULL; + struct sXd(scene)* scene = NULL; + struct sXd(shape)* shape = NULL; + struct sXd(scene_view)* view = NULL; + struct sdis_estimator* estimator = NULL; + struct ssp_rng_proxy* rng_proxy = NULL; + struct ssp_rng** rngs = NULL; + size_t i; + size_t N = 0; /* #realisations that do not fail */ + size_t view_nprims; + double weight=0, sqr_weight=0; + int64_t irealisation; + ATOMIC res = RES_OK; + + if(!scn || !nrealisations || nrealisations > INT64_MAX || !primitives + || !time_range || time_range[0] < 0 || time_range[1] < time_range[0] + || (time_range[1] > DBL_MAX && time_range[0] != time_range[1]) + || !sides || !nprimitives || fp_to_meter < 0 || Tref < 0 + || !out_estimator) { + res = RES_BAD_ARG; + goto error; + } + + SXD(scene_view_primitives_count(scn->sXd(view), &view_nprims)); + FOR_EACH(i, 0, nprimitives) { + if(primitives[i] >= view_nprims) { + log_err(scn->dev, + "%s: invalid primitive identifier `%lu'. It must be in the [0 %lu] range.\n", + FUNC_NAME, + (unsigned long)primitives[i], + (unsigned long)scene_get_primitives_count(scn)-1); + res = RES_BAD_ARG; + goto error; + } + } + + /* Create the Star-XD shape of the boundary */ +#if DIM == 2 + res = s2d_shape_create_line_segments(scn->dev->sXd_dev, &shape); +#else + res = s3d_shape_create_mesh(scn->dev->sXd_dev, &shape); +#endif + if(res != RES_OK) goto error; + + /* Initialise the boundary shape with the triangles/segments of the + * submitted primitives */ + ctx.primitives = primitives; + ctx.view = scn->sXd(view); + vdata.usage = SXD_POSITION; + vdata.get = XD(boundary_get_position); +#if DIM == 2 + vdata.type = S2D_FLOAT2; + res = s2d_line_segments_setup_indexed_vertices(shape, (unsigned)nprimitives, + boundary_get_indices_2d, (unsigned)(nprimitives*2), &vdata, 1, &ctx); +#else /* DIM == 3 */ + vdata.type = S3D_FLOAT3; + res = s3d_mesh_setup_indexed_vertices(shape, (unsigned)nprimitives, + boundary_get_indices_3d, (unsigned)(nprimitives*3), &vdata, 1, &ctx); +#endif + if(res != RES_OK) goto error; + + /* Create and setup the boundary Star-XD scene */ + res = sXd(scene_create)(scn->dev->sXd_dev, &scene); + if(res != RES_OK) goto error; + res = sXd(scene_attach_shape)(scene, shape); + if(res != RES_OK) goto error; + res = sXd(scene_view_create)(scene, SXD_SAMPLE, &view); + if(res != RES_OK) goto error; + + /* Create the proxy RNG */ + res = ssp_rng_proxy_create(scn->dev->allocator, &ssp_rng_mt19937_64, + scn->dev->nthreads, &rng_proxy); + if(res != RES_OK) goto error; + + /* Create the per thread RNG */ + rngs = MEM_CALLOC(scn->dev->allocator, scn->dev->nthreads, sizeof(*rngs)); + if(!rngs) { res = RES_MEM_ERR; goto error; } + FOR_EACH(i, 0, scn->dev->nthreads) { + res = ssp_rng_proxy_create_rng(rng_proxy, i, rngs+i); + if(res != RES_OK) goto error; + } + + /* Create the estimator */ + res = estimator_create(scn->dev, SDIS_TEMPERATURE_ESTIMATOR, &estimator); + if(res != RES_OK) goto error; + + omp_set_num_threads((int)scn->dev->nthreads); + #pragma omp parallel for schedule(static) reduction(+:weight,sqr_weight,N) + for(irealisation=0; irealisation<(int64_t)nrealisations; ++irealisation) { + const int ithread = omp_get_thread_num(); + struct sXd(primitive) prim; + struct ssp_rng* rng = rngs[ithread]; + enum sdis_side side; + size_t iprim; + double w = NaN; + double uv[DIM-1]; + float st[DIM-1]; + res_T res_local = RES_OK; + + if(ATOMIC_GET(&res) != RES_OK) continue; /* An error occurred */ + + /* Sample a position onto the boundary */ +#if DIM == 2 + res_local = s2d_scene_view_sample + (view, + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, st); + uv[0] = (double)st[0]; +#else + res_local = s3d_scene_view_sample + (view, + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, st); + d2_set_f2(uv, st); +#endif + if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; } + + /* Map from boundary scene to sdis scene */ + ASSERT(prim.prim_id < nprimitives); + iprim = primitives[prim.prim_id]; + side = sides[prim.prim_id]; + + /* Invoke the boundary realisation */ + res_local = XD(boundary_realisation) + (scn, rng, iprim, uv, time_range, side, fp_to_meter, Tarad, Tref, &w); + + /* Update the MC accumulators */ + if(res_local == RES_OK) { + weight += w; + sqr_weight += w*w; + ++N; + } else if(res_local != RES_BAD_OP) { + ATOMIC_SET(&res, res_local); + continue; + } + } + + setup_estimator(estimator, nrealisations, N, weight, sqr_weight); + +exit: + if(scene) SXD(scene_ref_put(scene)); + if(shape) SXD(shape_ref_put(shape)); + if(view) SXD(scene_view_ref_put(view)); + if(rng_proxy) SSP(rng_proxy_ref_put(rng_proxy)); + if(out_estimator) *out_estimator = estimator; + if(rngs) { + FOR_EACH(i, 0, scn->dev->nthreads) {if(rngs[i]) SSP(rng_ref_put(rngs[i]));} + MEM_RM(scn->dev->allocator, rngs); + } + return (res_T)res; +error: + if(estimator) { + SDIS(estimator_ref_put(estimator)); + estimator = NULL; + } + goto exit; +} + +static res_T +XD(solve_boundary_flux) + (struct sdis_scene* scn, + const size_t nrealisations, /* #realisations */ + const size_t primitives[], /* List of boundary primitives to handle */ + const size_t nprimitives, /* #primitives */ + const double time_range[2], /* Observation time */ + const double fp_to_meter, /* Scale from floating point units to meters */ + const double Tarad, /* In Kelvin */ + const double Tref, /* In Kelvin */ + struct sdis_estimator** out_estimator) +{ + struct XD(boundary_context) ctx = XD(BOUNDARY_CONTEXT_NULL); + struct sXd(vertex_data) vdata = SXD_VERTEX_DATA_NULL; + struct sXd(scene)* scene = NULL; + struct sXd(shape)* shape = NULL; + struct sXd(scene_view)* view = NULL; + struct sdis_estimator* estimator = NULL; + struct ssp_rng_proxy* rng_proxy = NULL; + struct ssp_rng** rngs = NULL; + double weight_t = 0, sqr_weight_t = 0; + double weight_fc = 0, sqr_weight_fc = 0; + double weight_fr = 0, sqr_weight_fr = 0; + double weight_f = 0, sqr_weight_f = 0; + size_t i; + size_t N = 0; /* #realisations that do not fail */ + size_t view_nprims; + int64_t irealisation; + ATOMIC res = RES_OK; + + if(!scn || !nrealisations || nrealisations > INT64_MAX || !primitives + || !time_range || time_range[0] < 0 || time_range[1] < time_range[0] + || (time_range[1] > DBL_MAX && time_range[0] != time_range[1]) + || !nprimitives || fp_to_meter < 0 || Tref < 0 + || !out_estimator) { + res = RES_BAD_ARG; + goto error; + } + + SXD(scene_view_primitives_count(scn->sXd(view), &view_nprims)); + FOR_EACH(i, 0, nprimitives) { + if(primitives[i] >= view_nprims) { + log_err(scn->dev, + "%s: invalid primitive identifier `%lu'. It must be in the [0 %lu] range.\n", + FUNC_NAME, + (unsigned long)primitives[i], + (unsigned long)scene_get_primitives_count(scn)-1); + res = RES_BAD_ARG; + goto error; + } + } + + /* Create the Star-XD shape of the boundary */ +#if DIM == 2 + res = s2d_shape_create_line_segments(scn->dev->s2d, &shape); +#else + res = s3d_shape_create_mesh(scn->dev->s3d, &shape); +#endif + if(res != RES_OK) goto error; + + /* Initialise the boundary shape with the triangles/segments of the + * submitted primitives */ + ctx.primitives = primitives; + ctx.view = scn->sXd(view); + vdata.get = XD(boundary_get_position); +#if DIM == 2 + vdata.usage = S2D_POSITION; + vdata.type = S2D_FLOAT2; + res = s2d_line_segments_setup_indexed_vertices(shape, (unsigned)nprimitives, + boundary_get_indices_2d, (unsigned)(nprimitives*2), &vdata, 1, &ctx); +#else /* DIM == 3 */ + vdata.usage = S3D_POSITION; + vdata.type = S3D_FLOAT3; + res = s3d_mesh_setup_indexed_vertices(shape, (unsigned)nprimitives, + boundary_get_indices_3d, (unsigned)(nprimitives*3), &vdata, 1, &ctx); +#endif + if(res != RES_OK) goto error; + + /* Create and setup the boundary Star-XD scene */ + res = sXd(scene_create)(scn->dev->sXd_dev, &scene); + if(res != RES_OK) goto error; + res = sXd(scene_attach_shape)(scene, shape); + if(res != RES_OK) goto error; + res = sXd(scene_view_create)(scene, SXD_SAMPLE, &view); + if(res != RES_OK) goto error; + + /* Create the proxy RNG */ + res = ssp_rng_proxy_create(scn->dev->allocator, &ssp_rng_mt19937_64, + scn->dev->nthreads, &rng_proxy); + if(res != RES_OK) goto error; + + /* Create the per thread RNG */ + rngs = MEM_CALLOC(scn->dev->allocator, scn->dev->nthreads, sizeof(*rngs)); + if(!rngs) { res = RES_MEM_ERR; goto error; } + FOR_EACH(i, 0, scn->dev->nthreads) { + res = ssp_rng_proxy_create_rng(rng_proxy, i, rngs + i); + if(res != RES_OK) goto error; + } + + /* Create the estimator */ + res = estimator_create(scn->dev, SDIS_FLUX_ESTIMATOR, &estimator); + if(res != RES_OK) goto error; + + omp_set_num_threads((int)scn->dev->nthreads); + #pragma omp parallel for schedule(static) reduction(+:weight_t,sqr_weight_t,\ + weight_fc,sqr_weight_fc,weight_fr,sqr_weight_fr,weight_f,sqr_weight_f,N) + for(irealisation = 0; irealisation < (int64_t)nrealisations; ++irealisation) { + const int ithread = omp_get_thread_num(); + struct sXd(primitive) prim; + struct ssp_rng* rng = rngs[ithread]; + const struct sdis_interface* interf; + const struct sdis_medium *fmd, *bmd; + enum sdis_side solid_side, fluid_side; + double T_brf[3] = { 0, 0, 0 }; + double epsilon, hc, hr; + size_t iprim; + double uv[DIM - 1]; + float st[DIM - 1]; + double time; + res_T res_local = RES_OK; + + if(ATOMIC_GET(&res) != RES_OK) continue; /* An error occurred */ + + /* Sample a time */ + time = sample_time(time_range, rng); + + /* Sample a position onto the boundary */ +#if DIM == 2 + res_local = s2d_scene_view_sample + (view, + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, st); + uv[0] = (double)st[0]; +#else + res_local = s3d_scene_view_sample + (view, + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + ssp_rng_canonical_float(rng), + &prim, st); + d2_set_f2(uv, st); +#endif + if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; } + + /* Map from boundary scene to sdis scene */ + ASSERT(prim.prim_id < nprimitives); + iprim = primitives[prim.prim_id]; + + interf = scene_get_interface(scn, (unsigned)iprim); + fmd = interface_get_medium(interf, SDIS_FRONT); + bmd = interface_get_medium(interf, SDIS_BACK); + if(!fmd || !bmd + || (!(fmd->type == SDIS_FLUID && bmd->type == SDIS_SOLID) + && !(fmd->type == SDIS_SOLID && bmd->type == SDIS_FLUID))) + { + ATOMIC_SET(&res, RES_BAD_ARG); + continue; + } + solid_side = (fmd->type == SDIS_SOLID) ? SDIS_FRONT : SDIS_BACK; + fluid_side = (fmd->type == SDIS_FLUID) ? SDIS_FRONT : SDIS_BACK; + + res_local = XD(interface_get_hc_epsilon)(&hc, &epsilon, scn, + (unsigned)iprim, uv, time, fluid_side); + if(res_local != RES_OK) { + ATOMIC_SET(&res, res_local); + continue; + } + hr = 4.0 * BOLTZMANN_CONSTANT * Tref * Tref * Tref * epsilon; + + /* Fluid, Radiative and Solid temperatures */ + res_local = XD(probe_flux_realisation)(scn, rng, iprim, uv, time, + solid_side, fp_to_meter, Tarad, Tref, hr > 0, hc > 0, T_brf); + if(res_local != RES_OK) { + if(res_local != RES_BAD_OP) { + ATOMIC_SET(&res, res_local); + continue; + } + } else { + const double Tboundary = T_brf[0]; + const double Tradiative = T_brf[1]; + const double Tfluid = T_brf[2]; + const double w_conv = hc * (Tboundary - Tfluid); + const double w_rad = hr * (Tboundary - Tradiative); + const double w_total = w_conv + w_rad; + weight_t += Tboundary; + sqr_weight_t += Tboundary * Tboundary; + weight_fc += w_conv; + sqr_weight_fc += w_conv * w_conv; + weight_fr += w_rad; + sqr_weight_fr += w_rad * w_rad; + weight_f += w_total; + sqr_weight_f += w_total * w_total; + ++N; + } + } + if(res != RES_OK) goto error; + + setup_estimator(estimator, nrealisations, N, weight_t, sqr_weight_t); + setup_estimator_flux(estimator, FLUX_CONVECTIVE__, weight_fc, sqr_weight_fc); + setup_estimator_flux(estimator, FLUX_RADIATIVE__, weight_fr, sqr_weight_fr); + setup_estimator_flux(estimator, FLUX_TOTAL__, weight_f, sqr_weight_f); + +exit: + if(scene) SXD(scene_ref_put(scene)); + if(shape) SXD(shape_ref_put(shape)); + if(view) SXD(scene_view_ref_put(view)); + if(rng_proxy) SSP(rng_proxy_ref_put(rng_proxy)); + if(out_estimator) *out_estimator = estimator; + if(rngs) { + FOR_EACH(i, 0, scn->dev->nthreads) { if(rngs[i]) SSP(rng_ref_put(rngs[i])); } + MEM_RM(scn->dev->allocator, rngs); + } + return (res_T)res; +error: + if(estimator) { + SDIS(estimator_ref_put(estimator)); + estimator = NULL; + } + goto exit; +} + #undef SDIS_SOLVE_DIMENSION #undef DIM #undef sXd +#undef sXd_dev #undef SXD_HIT_NONE #undef SXD_HIT_NULL #undef SXD_HIT_NULL__ #undef SXD_POSITION #undef SXD_GEOMETRY_NORMAL +#undef SXD_VERTEX_DATA_NULL +#undef SXD_FLOAT2 +#undef SXD_FLOAT3 +#undef SXD_SAMPLE #undef SXD #undef dX #undef fX diff --git a/src/test_sdis_accum_buffer.c b/src/test_sdis_accum_buffer.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -27,34 +27,33 @@ main(int argc, char** argv) struct sdis_accum* accums_tmp = NULL; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); - CHK(sdis_accum_buffer_create(NULL, 4 ,4, &buf) == RES_BAD_ARG); - CHK(sdis_accum_buffer_create(dev, 0 ,4, &buf) == RES_BAD_ARG); - CHK(sdis_accum_buffer_create(dev, 4 ,0, &buf) == RES_BAD_ARG); - CHK(sdis_accum_buffer_create(dev, 4 ,0, NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_create(dev, 4 ,4, &buf) == RES_OK); + BA(sdis_accum_buffer_create(NULL, 4 ,4, &buf)); + BA(sdis_accum_buffer_create(dev, 0 ,4, &buf)); + BA(sdis_accum_buffer_create(dev, 4 ,0, &buf)); + BA(sdis_accum_buffer_create(dev, 4 ,0, NULL)); + OK(sdis_accum_buffer_create(dev, 4 ,4, &buf)); - CHK(sdis_accum_buffer_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_ref_get(buf) == RES_OK); - CHK(sdis_accum_buffer_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_ref_put(buf) == RES_OK); - CHK(sdis_accum_buffer_ref_put(buf) == RES_OK); + BA(sdis_accum_buffer_ref_get(NULL)); + OK(sdis_accum_buffer_ref_get(buf)); + BA(sdis_accum_buffer_ref_put(NULL)); + OK(sdis_accum_buffer_ref_put(buf)); + OK(sdis_accum_buffer_ref_put(buf)); - CHK(sdis_accum_buffer_create(dev, 16, 8, &buf) == RES_OK); + OK(sdis_accum_buffer_create(dev, 16, 8, &buf)); - CHK(sdis_accum_buffer_get_layout(NULL, &layout) == RES_BAD_ARG); - CHK(sdis_accum_buffer_get_layout(buf, NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_get_layout(buf, &layout) == RES_OK); + BA(sdis_accum_buffer_get_layout(NULL, &layout)); + BA(sdis_accum_buffer_get_layout(buf, NULL)); + OK(sdis_accum_buffer_get_layout(buf, &layout)); CHK(layout.width == 16); CHK(layout.height == 8); - CHK(sdis_accum_buffer_map(NULL, &accums) == RES_BAD_ARG); - CHK(sdis_accum_buffer_map(buf, NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_map(buf, &accums) == RES_OK); + BA(sdis_accum_buffer_map(NULL, &accums)); + BA(sdis_accum_buffer_map(buf, NULL)); + OK(sdis_accum_buffer_map(buf, &accums)); /* Check the accessibility to the mapped data */ accums_tmp = MEM_CALLOC @@ -64,11 +63,11 @@ main(int argc, char** argv) layout.width*layout.height*sizeof(struct sdis_accum)); MEM_RM(&allocator, accums_tmp); - CHK(sdis_accum_buffer_unmap(NULL) == RES_BAD_ARG); - CHK(sdis_accum_buffer_unmap(buf) == RES_OK); + BA(sdis_accum_buffer_unmap(NULL)); + OK(sdis_accum_buffer_unmap(buf)); - CHK(sdis_accum_buffer_ref_put(buf) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_accum_buffer_ref_put(buf)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_camera.c b/src/test_sdis_camera.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -29,62 +29,61 @@ main(int argc, char** argv) double up[3] = {0}; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); - CHK(sdis_camera_create(NULL, NULL) == RES_BAD_ARG); - CHK(sdis_camera_create(dev, NULL) == RES_BAD_ARG); - CHK(sdis_camera_create(NULL, &cam) == RES_BAD_ARG); - CHK(sdis_camera_create(dev, &cam) == RES_OK); + BA(sdis_camera_create(NULL, NULL)); + BA(sdis_camera_create(dev, NULL)); + BA(sdis_camera_create(NULL, &cam)); + OK(sdis_camera_create(dev, &cam)); - CHK(sdis_camera_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_camera_ref_get(cam) == RES_OK); - CHK(sdis_camera_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_camera_ref_put(cam) == RES_OK); - CHK(sdis_camera_ref_put(cam) == RES_OK); + BA(sdis_camera_ref_get(NULL)); + OK(sdis_camera_ref_get(cam)); + BA(sdis_camera_ref_put(NULL)); + OK(sdis_camera_ref_put(cam)); + OK(sdis_camera_ref_put(cam)); - CHK(sdis_camera_create(dev, &cam) == RES_OK); - CHK(sdis_camera_set_proj_ratio(NULL, 0) == RES_BAD_ARG); - CHK(sdis_camera_set_proj_ratio(cam, 0) == RES_BAD_ARG); - CHK(sdis_camera_set_proj_ratio(NULL, 4.0/3.0) == RES_BAD_ARG); - CHK(sdis_camera_set_proj_ratio(cam, 4.0/3.0) == RES_OK); - CHK(sdis_camera_set_proj_ratio(cam, -4.0/3.0) == RES_BAD_ARG); + OK(sdis_camera_create(dev, &cam)); + BA(sdis_camera_set_proj_ratio(NULL, 0)); + BA(sdis_camera_set_proj_ratio(cam, 0)); + BA(sdis_camera_set_proj_ratio(NULL, 4.0 / 3.0)); + OK(sdis_camera_set_proj_ratio(cam, 4.0/3.0)); + BA(sdis_camera_set_proj_ratio(cam, -4.0/3.0)); - CHK(sdis_camera_set_fov(NULL, 0) == RES_BAD_ARG); - CHK(sdis_camera_set_fov(cam, 0) == RES_BAD_ARG); - CHK(sdis_camera_set_fov(NULL, PI/4.0) == RES_BAD_ARG); - CHK(sdis_camera_set_fov(cam, PI/4.0) == RES_OK); - CHK(sdis_camera_set_fov(cam, -PI/4.0) == RES_BAD_ARG); + BA(sdis_camera_set_fov(NULL, 0)); + BA(sdis_camera_set_fov(cam, 0)); + BA(sdis_camera_set_fov(NULL, PI/4.0)); + OK(sdis_camera_set_fov(cam, PI/4.0)); + BA(sdis_camera_set_fov(cam, -PI/4.0)); pos[0] = 0, pos[1] = 0, pos[2] = 0; tgt[0] = 0, tgt[1] = 0, tgt[2] = -1; up[0] = 0, up[1] = 1, up[2] = 0; - CHK(sdis_camera_look_at(NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, pos, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, pos, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, NULL, tgt, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, NULL, tgt, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, pos, tgt, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, pos, tgt, NULL) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, NULL, NULL, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, NULL, NULL, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, pos, NULL, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, pos, NULL, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, NULL, tgt, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, NULL, tgt, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(NULL, pos, tgt, up) == RES_BAD_ARG); - CHK(sdis_camera_look_at(cam, pos, tgt, up) == RES_OK); + BA(sdis_camera_look_at(NULL, NULL, NULL, NULL)); + BA(sdis_camera_look_at(cam, NULL, NULL, NULL)); + BA(sdis_camera_look_at(NULL, pos, NULL, NULL)); + BA(sdis_camera_look_at(cam, pos, NULL, NULL)); + BA(sdis_camera_look_at(NULL, NULL, tgt, NULL)); + BA(sdis_camera_look_at(cam, NULL, tgt, NULL)); + BA(sdis_camera_look_at(NULL, pos, tgt, NULL)); + BA(sdis_camera_look_at(cam, pos, tgt, NULL)); + BA(sdis_camera_look_at(NULL, NULL, NULL, up)); + BA(sdis_camera_look_at(cam, NULL, NULL, up)); + BA(sdis_camera_look_at(NULL, pos, NULL, up)); + BA(sdis_camera_look_at(cam, pos, NULL, up)); + BA(sdis_camera_look_at(NULL, NULL, tgt, up)); + BA(sdis_camera_look_at(cam, NULL, tgt, up)); + BA(sdis_camera_look_at(NULL, pos, tgt, up)); + OK(sdis_camera_look_at(cam, pos, tgt, up)); tgt[0] = 0, tgt[1] = 0, tgt[2] = 0; - CHK(sdis_camera_look_at(cam, pos, tgt, up) == RES_BAD_ARG); + BA(sdis_camera_look_at(cam, pos, tgt, up)); tgt[0] = 0, tgt[1] = 0, tgt[2] = -1; up[0] = 0, up[1] = 0, up[2] = 0; - CHK(sdis_camera_look_at(cam, pos, tgt, up) == RES_BAD_ARG); + BA(sdis_camera_look_at(cam, pos, tgt, up)); - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(sdis_camera_ref_put(cam) == RES_OK); + OK(sdis_device_ref_put(dev)); + OK(sdis_camera_ref_put(cam)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_conducto_radiative.c b/src/test_sdis_conducto_radiative.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -241,12 +241,12 @@ create_interface } shader.convection_coef_upper_bound = MMAX(0, interf->convection_coef); - CHK(sdis_data_create(dev, sizeof(struct interfac), ALIGNOF(struct interfac), - NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interfac), ALIGNOF(struct interfac), + NULL, &data)); *((struct interfac*)sdis_data_get(data)) = *interf; - CHK(sdis_interface_create(dev, front, back, &shader, data, out_interf) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, front, back, &shader, data, out_interf)); + OK(sdis_data_ref_put(data)); } /******************************************************************************* @@ -280,37 +280,36 @@ main(int argc, char** argv) double Ts0, Ts1, hr, tmp; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ - CHK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), - NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), + NULL, &data)); ((struct solid*)sdis_data_get(data))->lambda = lambda; 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.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); /* Create the surrounding solid medium */ - CHK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), - NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), + NULL, &data)); ((struct solid*)sdis_data_get(data))->lambda = 0; 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.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Create the interface that forces to keep in conduction */ interf.temperature = UNKNOWN_TEMPERATURE; @@ -373,8 +372,8 @@ main(int argc, char** argv) geom.positions = vertices; geom.indices = indices; geom.interfaces = prim_interfaces; - CHK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, nvertices, - get_position, &geom, &scn) == RES_OK); + OK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, nvertices, + get_position, &geom, &scn)); hr = 4.0 * BOLTZMANN_CONSTANT * Tref*Tref*Tref * emissivity; tmp = lambda/(2*lambda + thickness*hr) * (T1 - T0); @@ -382,11 +381,12 @@ main(int argc, char** argv) Ts1 = T1 - tmp; /* Run the simulations */ - CHK(ssp_rng_create(&allocator, &ssp_rng_kiss, &rng) == RES_OK); + OK(ssp_rng_create(&allocator, &ssp_rng_kiss, &rng)); FOR_EACH(isimul, 0, nsimuls) { struct sdis_mc T = SDIS_MC_NULL; struct sdis_estimator* estimator; double pos[3]; + double time_range[2] = { INF, INF }; double ref, u; size_t nreals = 0; size_t nfails = 0; @@ -396,10 +396,10 @@ main(int argc, char** argv) pos[1] = ssp_rng_uniform_double(rng, -0.9, 0.9); pos[2] = ssp_rng_uniform_double(rng, -0.9, 0.9); - CHK(sdis_solve_probe(scn, N, pos, INF, 1, -1, Tref, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + OK(sdis_solve_probe(scn, N, pos, time_range, 1, -1, Tref, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); u = (pos[0] + 1) / thickness; ref = u * Ts1 + (1-u) * Ts0; @@ -411,21 +411,21 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, 2*T.SE) == 1); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); } /* Release memory */ - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[0]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[1]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[2]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[3]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[4]) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(ssp_rng_ref_put(rng) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_interface_ref_put(interfaces[0])); + OK(sdis_interface_ref_put(interfaces[1])); + OK(sdis_interface_ref_put(interfaces[2])); + OK(sdis_interface_ref_put(interfaces[3])); + OK(sdis_interface_ref_put(interfaces[4])); + OK(sdis_medium_ref_put(fluid)); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(solid2)); + OK(sdis_device_ref_put(dev)); + OK(ssp_rng_ref_put(rng)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_conducto_radiative_2d.c b/src/test_sdis_conducto_radiative_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -257,12 +257,12 @@ create_interface } shader.convection_coef_upper_bound = MMAX(0, interf->convection_coef); - CHK(sdis_data_create(dev, sizeof(struct interfac), ALIGNOF(struct interfac), - NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interfac), ALIGNOF(struct interfac), + NULL, &data)); *((struct interfac*)sdis_data_get(data)) = *interf; - CHK(sdis_interface_create(dev, front, back, &shader, data, out_interf) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, front, back, &shader, data, out_interf)); + OK(sdis_data_ref_put(data)); } /******************************************************************************* @@ -291,40 +291,40 @@ main(int argc, char** argv) const double lambda = 0.1; /* Conductivity of the solid */ const double Tref = 300; /* Reference temperature */ const double T0 = 300; /* Fixed temperature on the left side of the system */ - const double T1 = 310; /* Fixed temperature on the right side of the system */ + const double T1 = 310; /* Fixed temperature on the right side of the system */ const double thickness = 2.0; /* Thickness of the solid along X */ double Ts0, Ts1, hr, tmp; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); ((struct solid*)sdis_data_get(data))->lambda = lambda; 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.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); /* Create the surrounding solid medium */ - CHK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), - NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), + NULL, &data)); ((struct solid*)sdis_data_get(data))->lambda = 0; solid_shader.calorific_capacity = solid_get_thermal_conductivity; solid_shader.thermal_conductivity = solid_get_thermal_conductivity; solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Create the interface that forces to keep in conduction */ interf = INTERFACE_NULL; @@ -378,8 +378,8 @@ main(int argc, char** argv) geom.positions = vertices; geom.indices = indices; geom.interfaces = prim_interfaces; - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, nvertices, - get_position, &geom, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, nvertices, + get_position, &geom, &scn)); hr = 4*BOLTZMANN_CONSTANT * Tref*Tref*Tref * emissivity; tmp = lambda/(2*lambda + thickness*hr) * (T1 - T0); @@ -387,11 +387,12 @@ main(int argc, char** argv) Ts1 = T1 - tmp; /* Run the simulations */ - CHK(ssp_rng_create(&allocator, &ssp_rng_kiss, &rng) == RES_OK); + OK(ssp_rng_create(&allocator, &ssp_rng_kiss, &rng)); FOR_EACH(isimul, 0, nsimuls) { struct sdis_mc T = SDIS_MC_NULL; struct sdis_estimator* estimator; double pos[2]; + double time_range[2] = { INF, INF }; double ref, u; size_t nreals = 0; size_t nfails = 0; @@ -400,10 +401,10 @@ main(int argc, char** argv) pos[0] = ssp_rng_uniform_double(rng, -0.9, 0.9); pos[1] = ssp_rng_uniform_double(rng, -0.9, 0.9); - CHK(sdis_solve_probe(scn, 10000, pos, INF, 1, -1, Tref, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + OK(sdis_solve_probe(scn, 10000, pos, time_range, 1, -1, Tref, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); u = (pos[0] + 1) / thickness; ref = u * Ts1 + (1-u) * Ts0; @@ -415,21 +416,21 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, 3*T.SE) == 1); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); } /* Release memory */ - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[0]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[1]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[2]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[3]) == RES_OK); - CHK(sdis_interface_ref_put(interfaces[4]) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); - CHK(ssp_rng_ref_put(rng) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_interface_ref_put(interfaces[0])); + OK(sdis_interface_ref_put(interfaces[1])); + OK(sdis_interface_ref_put(interfaces[2])); + OK(sdis_interface_ref_put(interfaces[3])); + OK(sdis_interface_ref_put(interfaces[4])); + OK(sdis_medium_ref_put(fluid)); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(solid2)); + OK(ssp_rng_ref_put(rng)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_convection.c b/src/test_sdis_convection.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -146,13 +146,13 @@ create_interface struct sdis_interface* interf; struct interf* interf_props; - CHK(sdis_data_create - (dev, sizeof(struct interf), ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct interf), ALIGNOF(struct interf), NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = temperature; - CHK(sdis_interface_create - (dev, front, back, interf_shader, data, &interf) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, front, back, interf_shader, data, &interf)); + OK(sdis_data_ref_put(data)); return interf; } @@ -190,18 +190,17 @@ main(int argc, char** argv) int i; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); /* Create the fluid medium */ fluid_shader.temperature = fluid_get_temperature; fluid_shader.calorific_capacity = fluid_get_calorific_capacity; fluid_shader.volumic_mass = fluid_get_volumic_mass; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid_medium */ - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; @@ -219,8 +218,8 @@ main(int argc, char** argv) interf_T5 = create_interface(dev, fluid, solid, &interf_shader, T5); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Map the interfaces to their box triangles */ box_interfaces[0] = box_interfaces[1] = interf_T5; /* Front */ @@ -237,22 +236,22 @@ main(int argc, char** argv) square_interfaces[3] = interf_T1; /* Right */ /* Create the box scene */ - CHK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, box_get_interface, box_nvertices, box_get_position, box_interfaces, - &box_scn) == RES_OK); + &box_scn)); /* Create the square scene */ - CHK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, square_get_interface, square_nvertices, square_get_position, - square_interfaces, &square_scn) == RES_OK); + square_interfaces, &square_scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_T0) == RES_OK); - CHK(sdis_interface_ref_put(interf_T1) == RES_OK); - CHK(sdis_interface_ref_put(interf_T2) == RES_OK); - CHK(sdis_interface_ref_put(interf_T3) == RES_OK); - CHK(sdis_interface_ref_put(interf_T4) == RES_OK); - CHK(sdis_interface_ref_put(interf_T5) == RES_OK); + OK(sdis_interface_ref_put(interf_T0)); + OK(sdis_interface_ref_put(interf_T1)); + OK(sdis_interface_ref_put(interf_T2)); + OK(sdis_interface_ref_put(interf_T3)); + OK(sdis_interface_ref_put(interf_T4)); + OK(sdis_interface_ref_put(interf_T5)); d3_splat(pos, 0.25); @@ -261,16 +260,18 @@ main(int argc, char** argv) Tinf = (H*(T0 + T1 + T2 + T3 + T4 + T5)) / (6 * H); printf("Temperature of the box at (%g %g %g)\n", SPLIT3(pos)); FOR_EACH(i, 0, 5) { - double time = i ? (double) i / nu : INF; + double time = i ? (double)i / nu : INF; + double time_range[2]; + time_range[0] = time_range[1] = time; ref = Tf_0 * exp(-nu * time) + Tinf * (1 - exp(-nu * time)); /* Solve in 3D */ - CHK(sdis_solve_probe(box_scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(box_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); CHK(nfails + nreals == N); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf(" t=%g : %g ~ %g +/- %g\n", time, ref, T.E, T.SE); if(nfails) printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); @@ -282,25 +283,27 @@ main(int argc, char** argv) Tinf = (H * (T0 + T1 + T2 + T3)) / (4 * H); printf("Temperature of the square at (%g %g)\n", SPLIT2(pos)); FOR_EACH(i, 0, 5) { - double time = i ? (double) i / nu : INF; + double time = i ? (double)i / nu : INF; + double time_range[2]; + time_range[0] = time_range[1] = time; ref = Tf_0 * exp(-nu * time) + Tinf * (1 - exp(-nu * time)); /* Solve in 2D */ - CHK(sdis_solve_probe(square_scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(square_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); CHK(nfails + nreals == N); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf(" t=%g : %g ~ %g +/- %g\n", time, ref, T.E, T.SE); if(nfails) printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); CHK(eq_eps(T.E, ref, T.SE * 3)); } - CHK(sdis_scene_ref_put(box_scn) == RES_OK); - CHK(sdis_scene_ref_put(square_scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_convection_non_uniform.c b/src/test_sdis_convection_non_uniform.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -155,14 +155,13 @@ create_interface struct sdis_interface* interf; struct interf* interf_props; - CHK(sdis_data_create - (dev, sizeof(struct interf), ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = temperature; interf_props->hc = hc; - CHK(sdis_interface_create - (dev, front, back, interf_shader, data, &interf) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, front, back, interf_shader, data, &interf)); + OK(sdis_data_ref_put(data)); return interf; } @@ -200,18 +199,17 @@ main(int argc, char** argv) int i; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); /* Create the fluid medium */ fluid_shader.temperature = fluid_get_temperature; fluid_shader.calorific_capacity = fluid_get_calorific_capacity; fluid_shader.volumic_mass = fluid_get_volumic_mass; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid_medium */ - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; @@ -234,8 +232,8 @@ main(int argc, char** argv) interf_T5 = create_interface(dev, fluid, solid, &interf_shader, T5, HC5); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Map the interfaces to their box triangles */ box_interfaces[0] = box_interfaces[1] = interf_T5; /* Front */ @@ -252,22 +250,22 @@ main(int argc, char** argv) square_interfaces[3] = interf_T1; /* Right */ /* Create the box scene */ - CHK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, box_get_interface, box_nvertices, box_get_position, box_interfaces, - &box_scn) == RES_OK); + &box_scn)); /* Create the square scene */ - CHK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, square_get_interface, square_nvertices, square_get_position, - square_interfaces, &square_scn) == RES_OK); + square_interfaces, &square_scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_T0) == RES_OK); - CHK(sdis_interface_ref_put(interf_T1) == RES_OK); - CHK(sdis_interface_ref_put(interf_T2) == RES_OK); - CHK(sdis_interface_ref_put(interf_T3) == RES_OK); - CHK(sdis_interface_ref_put(interf_T4) == RES_OK); - CHK(sdis_interface_ref_put(interf_T5) == RES_OK); + OK(sdis_interface_ref_put(interf_T0)); + OK(sdis_interface_ref_put(interf_T1)); + OK(sdis_interface_ref_put(interf_T2)); + OK(sdis_interface_ref_put(interf_T3)); + OK(sdis_interface_ref_put(interf_T4)); + OK(sdis_interface_ref_put(interf_T5)); d3_splat(pos, 0.25); @@ -277,16 +275,18 @@ main(int argc, char** argv) / (HC0 + HC1 + HC2 + HC3 + HC4 + HC5); printf("Temperature of the box at (%g %g %g)\n", SPLIT3(pos)); FOR_EACH(i, 0, 5) { - double time = i ? (double) i / nu : INF; + double time = i ? (double)i / nu : INF; + double time_range[2]; + time_range[0] = time_range[1] = time; ref = Tf_0 * exp(-nu * time) + Tinf * (1 - exp(-nu * time)); /* Solve in 3D */ - CHK(sdis_solve_probe(box_scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(box_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); CHK(nfails + nreals == N); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf(" t=%g : %g ~ %g +/- %g\n", time, ref, T.E, T.SE); if(nfails) printf("#failures = %lu/%lu\n", (unsigned long)nfails,(unsigned long)N); @@ -298,24 +298,26 @@ main(int argc, char** argv) Tinf = (HC0 * T0 + HC1 * T1 + HC2 * T2 + HC3 * T3) / (HC0 + HC1 + HC2 + HC3); printf("Temperature of the square at (%g %g)\n", SPLIT2(pos)); FOR_EACH(i, 0, 5) { - double time = i ? (double) i / nu : INF; + double time = i ? (double)i / nu : INF; + double time_range[2]; + time_range[0] = time_range[1] = time; ref = Tf_0 * exp(-nu * time) + Tinf * (1 - exp(-nu * time)); - CHK(sdis_solve_probe(square_scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(square_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); CHK(nfails + nreals == N); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf(" t=%g : %g ~ %g +/- %g\n", time, ref, T.E, T.SE); - if (nfails) + if(nfails) printf("#failures = %lu/%lu\n", (unsigned long)nfails,(unsigned long)N); CHK(eq_eps(T.E, ref, T.SE * 3)); } - CHK(sdis_scene_ref_put(box_scn) == RES_OK); - CHK(sdis_scene_ref_put(square_scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_data.c b/src/test_sdis_data.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -29,7 +29,7 @@ param_release(void* mem) { struct param* param = mem; CHK(param != NULL); - if(param->name) CHK(sdis_data_ref_put(param->name) == RES_OK); + if(param->name) OK(sdis_data_ref_put(param->name)); } int @@ -42,43 +42,39 @@ main(int argc, char** argv) struct param* param = NULL; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); + BA(sdis_data_create(NULL, 0, 0, NULL, NULL)); + BA(sdis_data_create(dev, 0, 0, NULL, NULL)); + BA(sdis_data_create(NULL, 8, 0, NULL, NULL)); + BA(sdis_data_create(dev, 8, 0, NULL, NULL)); + BA(sdis_data_create(NULL, 0, 8, NULL, NULL)); + BA(sdis_data_create(dev, 0, 8, NULL, NULL)); + BA(sdis_data_create(NULL, 8, 8, NULL, NULL)); + BA(sdis_data_create(dev, 8, 8, NULL, NULL)); - CHK(sdis_data_create(NULL, 0, 0, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 0, 0, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 8, 0, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 8, 0, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 0, 8, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 0, 8, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 8, 8, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 8, 8, NULL, NULL) == RES_BAD_ARG); - - CHK(sdis_data_create(NULL, 0, 0, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 0, 0, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 8, 0, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 8, 0, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 0, 8, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 0, 8, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(NULL, 8, 8, NULL, &data) == RES_BAD_ARG); - CHK(sdis_data_create(dev, 8, 8, NULL, &data) == RES_OK); + BA(sdis_data_create(NULL, 0, 0, NULL, &data)); + BA(sdis_data_create(dev, 0, 0, NULL, &data)); + BA(sdis_data_create(NULL, 8, 0, NULL, &data)); + BA(sdis_data_create(dev, 8, 0, NULL, &data)); + BA(sdis_data_create(NULL, 0, 8, NULL, &data)); + BA(sdis_data_create(dev, 0, 8, NULL, &data)); + BA(sdis_data_create(NULL, 8, 8, NULL, &data)); + OK(sdis_data_create(dev, 8, 8, NULL, &data)); CHK(sdis_data_get(data) != NULL); CHK(sdis_data_cget(data) == sdis_data_get(data)); CHK(IS_ALIGNED(sdis_data_get(data), 8)); - CHK(sdis_data_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_data_ref_get(data) == RES_OK); - CHK(sdis_data_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_data_ref_put(data) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + BA(sdis_data_ref_get(NULL)); + OK(sdis_data_ref_get(data)); + BA(sdis_data_ref_put(NULL)); + OK(sdis_data_ref_put(data)); + OK(sdis_data_ref_put(data)); - CHK(sdis_data_create - (dev, sizeof(struct param), 64, param_release, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct param), 64, param_release, &data)); param = sdis_data_get(data); - CHK(sdis_data_create - (dev, strlen(str)+1, ALIGNOF(char), NULL, &param->name) == RES_OK); + OK(sdis_data_create(dev, strlen(str)+1, ALIGNOF(char), NULL, &param->name)); strcpy(sdis_data_get(param->name), str); param->d = 3.14159; param->i = 314159; @@ -88,9 +84,9 @@ main(int argc, char** argv) CHK(param->d == 3.14159); CHK(param->i == 314159); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_ref_put(data)); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_device_ref_put(dev)); mem_shutdown_proxy_allocator(&allocator); CHK(mem_allocated_size() == 0); return 0; diff --git a/src/test_sdis_device.c b/src/test_sdis_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -34,39 +34,38 @@ main(int argc, char** argv) struct sdis_device* dev; (void)argc, (void)argv; - CHK(sdis_device_create(NULL, NULL, 0, 0, NULL) == RES_BAD_ARG); - CHK(sdis_device_create(NULL, NULL, 0, 0, &dev) == RES_BAD_ARG); - CHK(sdis_device_create(NULL, NULL, 1, 0, &dev) == RES_OK); - CHK(sdis_device_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_device_ref_get(dev) == RES_OK); - CHK(sdis_device_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + BA(sdis_device_create(NULL, NULL, 0, 0, NULL)); + BA(sdis_device_create(NULL, NULL, 0, 0, &dev)); + OK(sdis_device_create(NULL, NULL, 1, 0, &dev)); + BA(sdis_device_ref_get(NULL)); + OK(sdis_device_ref_get(dev)); + BA(sdis_device_ref_put(NULL)); + OK(sdis_device_ref_put(dev)); + OK(sdis_device_ref_put(dev)); - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); - CHK(sdis_device_create(NULL, &allocator, 1, 0, NULL) == RES_BAD_ARG); - CHK(sdis_device_create(NULL, &allocator, 1, 0, &dev) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + BA(sdis_device_create(NULL, &allocator, 1, 0, NULL)); + OK(sdis_device_create(NULL, &allocator, 1, 0, &dev)); + OK(sdis_device_ref_put(dev)); CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); - CHK(logger_init(&allocator, &logger) == RES_OK); + OK(logger_init(&allocator, &logger)); 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); - CHK(sdis_device_create(&logger, NULL, 1, 0, NULL) == RES_BAD_ARG); - CHK(sdis_device_create(&logger, NULL, 1, 0, &dev) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + BA(sdis_device_create(&logger, NULL, 1, 0, NULL)); + OK(sdis_device_create(&logger, NULL, 1, 0, &dev)); + OK(sdis_device_ref_put(dev)); - CHK(sdis_device_create(&logger, &allocator, 1, 0, NULL) == RES_BAD_ARG); - CHK(sdis_device_create(&logger, &allocator, 1, 0, &dev) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + BA(sdis_device_create(&logger, &allocator, 1, 0, NULL)); + OK(sdis_device_create(&logger, &allocator, 1, 0, &dev)); + OK(sdis_device_ref_put(dev)); - CHK(sdis_device_create - (&logger, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_device_create(&logger, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); + OK(sdis_device_ref_put(dev)); logger_release(&logger); check_memory_allocator(&allocator); diff --git a/src/test_sdis_flux.c b/src/test_sdis_flux.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -147,17 +147,17 @@ main(int argc, char** argv) struct sdis_interface* square_interfaces[4/*#segments*/]; struct interf* interf_props = NULL; double pos[3]; + double time_range[2] = { INF, INF }; double ref; size_t nreals; size_t nfails; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); /* Create the dummy fluid medium */ - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid_medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -165,42 +165,41 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = solid_get_temperature; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Setup the interface shader */ interf_shader.front.temperature = interface_get_temperature; interf_shader.front.flux = interface_get_flux; /* Create the adiabatic interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = UNKNOWN_TEMPERATURE; interf_props->phi = 0; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_adiabatic)); + OK(sdis_data_ref_put(data)); /* Create the T0 interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = T0; interf_props->phi = 0; /* Unused */ - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_T0) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, fluid, &interf_shader, data, &interf_T0)); + OK(sdis_data_ref_put(data)); /* Create the PHI interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = UNKNOWN_TEMPERATURE; interf_props->phi = PHI; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_phi) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_phi)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Map the interfaces to their box triangles */ box_interfaces[0] = box_interfaces[1] = interf_adiabatic; /* Front */ @@ -217,29 +216,29 @@ main(int argc, char** argv) square_interfaces[3] = interf_T0; /* Right */ /* Create the box scene */ - CHK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, box_get_interface, box_nvertices, box_get_position, box_interfaces, - &box_scn) == RES_OK); + &box_scn)); /* Create the square scene */ - CHK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, square_get_interface, square_nvertices, square_get_position, - square_interfaces, &square_scn) == RES_OK); + square_interfaces, &square_scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_T0) == RES_OK); - CHK(sdis_interface_ref_put(interf_phi) == RES_OK); + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_T0)); + OK(sdis_interface_ref_put(interf_phi)); d3_splat(pos, 0.25); ref = T0 + (1 - pos[0]) * PHI/LAMBDA; /* Solve in 3D */ - CHK(sdis_solve_probe(box_scn, N, pos, INF, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_solve_probe(box_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf("Temperature of the box at (%g %g %g) = %g ~ %g +/- %g\n", SPLIT3(pos), ref, T.E, T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); @@ -248,11 +247,11 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, T.SE*3)); /* Solve in 2D */ - CHK(sdis_solve_probe(square_scn, N, pos, INF, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_solve_probe(square_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf("Temperature of the square at (%g %g) = %g ~ %g +/- %g\n", SPLIT2(pos), ref, T.E, T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); @@ -260,9 +259,9 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, T.SE*3)); - CHK(sdis_scene_ref_put(box_scn) == RES_OK); - CHK(sdis_scene_ref_put(square_scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_interface.c b/src/test_sdis_interface.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -29,91 +29,89 @@ main(int argc, char** argv) struct sdis_interface_shader shader = DUMMY_INTERFACE_SHADER; (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); - - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); shader = SDIS_INTERFACE_SHADER_NULL; #define CREATE sdis_interface_create - CHK(CREATE(NULL, NULL, NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, solid, NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, fluid, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, fluid, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, fluid, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, solid, fluid, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, NULL, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, NULL, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, NULL, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, solid, NULL, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, fluid, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, fluid, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, fluid, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, solid, fluid, &shader, NULL, NULL) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, NULL, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, NULL, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, NULL, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, solid, NULL, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, fluid, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, fluid, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, fluid, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, solid, fluid, NULL, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, NULL, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, NULL, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, NULL, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, solid, NULL, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, NULL, fluid, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, NULL, fluid, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(NULL, solid, fluid, &shader, NULL, &interf) == RES_BAD_ARG); - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_OK); + BA(CREATE(NULL, NULL, NULL, NULL, NULL, NULL)); + BA(CREATE(dev, NULL, NULL, NULL, NULL, NULL)); + BA(CREATE(NULL, solid, NULL, NULL, NULL, NULL)); + BA(CREATE(dev, solid, NULL, NULL, NULL, NULL)); + BA(CREATE(NULL, NULL, fluid, NULL, NULL, NULL)); + BA(CREATE(dev, NULL, fluid, NULL, NULL, NULL)); + BA(CREATE(NULL, solid, fluid, NULL, NULL, NULL)); + BA(CREATE(dev, solid, fluid, NULL, NULL, NULL)); + BA(CREATE(NULL, NULL, NULL, &shader, NULL, NULL)); + BA(CREATE(dev, NULL, NULL, &shader, NULL, NULL)); + BA(CREATE(NULL, solid, NULL, &shader, NULL, NULL)); + BA(CREATE(dev, solid, NULL, &shader, NULL, NULL)); + BA(CREATE(NULL, NULL, fluid, &shader, NULL, NULL)); + BA(CREATE(dev, NULL, fluid, &shader, NULL, NULL)); + BA(CREATE(NULL, solid, fluid, &shader, NULL, NULL)); + BA(CREATE(dev, solid, fluid, &shader, NULL, NULL)); + BA(CREATE(NULL, NULL, NULL, NULL, NULL, &interf)); + BA(CREATE(dev, NULL, NULL, NULL, NULL, &interf)); + BA(CREATE(NULL, solid, NULL, NULL, NULL, &interf)); + BA(CREATE(dev, solid, NULL, NULL, NULL, &interf)); + BA(CREATE(NULL, NULL, fluid, NULL, NULL, &interf)); + BA(CREATE(dev, NULL, fluid, NULL, NULL, &interf)); + BA(CREATE(NULL, solid, fluid, NULL, NULL, &interf)); + BA(CREATE(dev, solid, fluid, NULL, NULL, &interf)); + BA(CREATE(NULL, NULL, NULL, &shader, NULL, &interf)); + BA(CREATE(dev, NULL, NULL, &shader, NULL, &interf)); + BA(CREATE(NULL, solid, NULL, &shader, NULL, &interf)); + BA(CREATE(dev, solid, NULL, &shader, NULL, &interf)); + BA(CREATE(NULL, NULL, fluid, &shader, NULL, &interf)); + BA(CREATE(dev, NULL, fluid, &shader, NULL, &interf)); + BA(CREATE(NULL, solid, fluid, &shader, NULL, &interf)); + OK(CREATE(dev, solid, fluid, &shader, NULL, &interf)); - CHK(sdis_interface_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_interface_ref_get(interf) == RES_OK); - CHK(sdis_interface_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_interface_ref_put(interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + BA(sdis_interface_ref_get(NULL)); + OK(sdis_interface_ref_get(interf)); + BA(sdis_interface_ref_put(NULL)); + OK(sdis_interface_ref_put(interf)); + OK(sdis_interface_ref_put(interf)); - CHK(CREATE(dev, solid, solid, &shader, NULL, &interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, solid, &shader, NULL, &interf)); + OK(sdis_interface_ref_put(interf)); shader = SDIS_INTERFACE_SHADER_NULL; - CHK(CREATE(dev, solid, solid, &shader, NULL, &interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, solid, &shader, NULL, &interf)); + OK(sdis_interface_ref_put(interf)); shader.front.temperature = dummy_interface_getter; - CHK(CREATE(dev, solid, solid, &shader, NULL, &interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, solid, &shader, NULL, &interf)); + OK(sdis_interface_ref_put(interf)); shader.back.emissivity = dummy_interface_getter; - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, fluid, &shader, NULL, &interf)); + OK(sdis_interface_ref_put(interf)); shader.back.specular_fraction = dummy_interface_getter; - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, fluid, &shader, NULL, &interf)); + OK(sdis_interface_ref_put(interf)); shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; shader.front.emissivity = dummy_interface_getter; - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_OK); /* Warning */ - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, fluid, &shader, NULL, &interf)); /* Warning */ + OK(sdis_interface_ref_put(interf)); shader.front.emissivity = NULL; shader.front.specular_fraction = dummy_interface_getter; - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_OK); /* Warning */ - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(CREATE(dev, solid, fluid, &shader, NULL, &interf)); /* Warning */ + OK(sdis_interface_ref_put(interf)); shader.front.specular_fraction = NULL; shader.convection_coef_upper_bound = -1; - CHK(CREATE(dev, solid, solid, &shader, NULL, &interf) == RES_OK); /* Warning */ - CHK(sdis_interface_ref_put(interf) == RES_OK); - CHK(CREATE(dev, solid, fluid, &shader, NULL, &interf) == RES_BAD_ARG); + OK(CREATE(dev, solid, solid, &shader, NULL, &interf)); /* Warning */ + OK(sdis_interface_ref_put(interf)); + BA(CREATE(dev, solid, fluid, &shader, NULL, &interf)); shader.convection_coef_upper_bound = 0; #undef CREATE - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); - CHK(sdis_medium_ref_put(solid) == RES_OK); + OK(sdis_device_ref_put(dev)); + OK(sdis_medium_ref_put(fluid)); + OK(sdis_medium_ref_put(solid)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_medium.c b/src/test_sdis_medium.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -16,6 +16,8 @@ #include "sdis.h" #include "test_sdis_utils.h" +#include <rsys/math.h> + int main(int argc, char** argv) { @@ -28,78 +30,88 @@ main(int argc, char** argv) struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; (void)argc, (void)argv; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create - (NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); - CHK(sdis_fluid_create(NULL, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_fluid_create(dev, NULL, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_fluid_create(NULL, &fluid_shader, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, NULL) == RES_BAD_ARG); - CHK(sdis_fluid_create(NULL, NULL, NULL, &fluid) == RES_BAD_ARG); - CHK(sdis_fluid_create(dev, NULL, NULL, &fluid) == RES_BAD_ARG); - CHK(sdis_fluid_create(NULL, &fluid_shader, NULL, &fluid) == RES_BAD_ARG); - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + BA(sdis_fluid_create(NULL, NULL, NULL, NULL)); + BA(sdis_fluid_create(dev, NULL, NULL, NULL)); + BA(sdis_fluid_create(NULL, &fluid_shader, NULL, NULL)); + BA(sdis_fluid_create(dev, &fluid_shader, NULL, NULL)); + BA(sdis_fluid_create(NULL, NULL, NULL, &fluid)); + BA(sdis_fluid_create(dev, NULL, NULL, &fluid)); + BA(sdis_fluid_create(NULL, &fluid_shader, NULL, &fluid)); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); CHK(sdis_medium_get_type(fluid) == SDIS_FLUID); CHK(sdis_medium_get_data(fluid) == NULL); - CHK(sdis_medium_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_medium_ref_get(fluid) == RES_OK); - CHK(sdis_medium_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_medium_ref_put(fluid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + BA(sdis_medium_ref_get(NULL)); + OK(sdis_medium_ref_get(fluid)); + BA(sdis_medium_ref_put(NULL)); + OK(sdis_medium_ref_put(fluid)); + OK(sdis_medium_ref_put(fluid)); fluid_shader.calorific_capacity = NULL; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_BAD_ARG); + BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); fluid_shader.calorific_capacity = DUMMY_FLUID_SHADER.calorific_capacity; fluid_shader.volumic_mass = NULL; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_BAD_ARG); + BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); fluid_shader.volumic_mass = DUMMY_FLUID_SHADER.volumic_mass; fluid_shader.temperature = NULL; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_BAD_ARG); + BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); fluid_shader.temperature = DUMMY_FLUID_SHADER.temperature; - CHK(sdis_fluid_create - (dev, &SDIS_FLUID_SHADER_NULL, NULL, &fluid) == RES_BAD_ARG); - - CHK(sdis_data_create(dev, 4, 16, NULL, &data) == RES_OK); - CHK(sdis_solid_create(NULL, NULL, data, NULL) == RES_BAD_ARG); - CHK(sdis_solid_create(dev, NULL, data, NULL) == RES_BAD_ARG); - CHK(sdis_solid_create(NULL, &solid_shader, data, NULL) == RES_BAD_ARG); - CHK(sdis_solid_create(dev, &solid_shader, data, NULL) == RES_BAD_ARG); - CHK(sdis_solid_create(NULL, NULL, data, &solid) == RES_BAD_ARG); - CHK(sdis_solid_create(dev, NULL, data, &solid) == RES_BAD_ARG); - CHK(sdis_solid_create(NULL, &solid_shader, data, &solid) == RES_BAD_ARG); - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); + fluid_shader.t0 = -1; + BA(sdis_fluid_create(dev, &fluid_shader, NULL, &solid)); + fluid_shader.t0 = INF; + BA(sdis_fluid_create(dev, &fluid_shader, NULL, &solid)); + fluid_shader.t0 = DUMMY_FLUID_SHADER.t0; + + BA(sdis_fluid_create(dev, &SDIS_FLUID_SHADER_NULL, NULL, &fluid)); + + OK(sdis_data_create(dev, 4, 16, NULL, &data)); + BA(sdis_solid_create(NULL, NULL, data, NULL)); + BA(sdis_solid_create(dev, NULL, data, NULL)); + BA(sdis_solid_create(NULL, &solid_shader, data, NULL)); + BA(sdis_solid_create(dev, &solid_shader, data, NULL)); + BA(sdis_solid_create(NULL, NULL, data, &solid)); + BA(sdis_solid_create(dev, NULL, data, &solid)); + BA(sdis_solid_create(NULL, &solid_shader, data, &solid)); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); CHK(sdis_medium_get_type(solid) == SDIS_SOLID); CHK(sdis_medium_get_data(solid) == data); - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_data_ref_put(data)); solid_shader.calorific_capacity = NULL; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_BAD_ARG); + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); solid_shader.calorific_capacity = DUMMY_SOLID_SHADER.calorific_capacity; solid_shader.thermal_conductivity = NULL; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_BAD_ARG); + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); solid_shader.thermal_conductivity = DUMMY_SOLID_SHADER.thermal_conductivity; solid_shader.volumic_mass = NULL; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_BAD_ARG); + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); solid_shader.volumic_mass = DUMMY_SOLID_SHADER.volumic_mass; solid_shader.delta_solid = NULL; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_BAD_ARG); + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); solid_shader.delta_solid = DUMMY_SOLID_SHADER.delta_solid; solid_shader.temperature = NULL; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_BAD_ARG); + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); solid_shader.temperature = DUMMY_SOLID_SHADER.temperature; - CHK(sdis_device_ref_put(dev) == RES_OK); + solid_shader.t0 = -1; + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); + solid_shader.t0 = INF; + BA(sdis_solid_create(dev, &solid_shader, NULL, &solid)); + solid_shader.t0 = DUMMY_SOLID_SHADER.t0; + + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -105,23 +105,23 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf) #define POS get_position_3d #define IFA get_interface - CHK(CREATE(NULL, 0, NULL, NULL, 0, NULL, &ctx, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, 0, IDS, IFA, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, ntris, NULL, IFA, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, ntris, IDS, NULL, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, ntris, IDS, IFA, 0, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, ntris, IDS, IFA, npos, NULL, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, ntris, IDS, IFA, npos, POS, &ctx, &scn) == RES_OK); + BA(CREATE(NULL, 0, NULL, NULL, 0, NULL, &ctx, NULL)); + BA(CREATE(dev, 0, IDS, IFA, npos, POS, &ctx, &scn)); + BA(CREATE(dev, ntris, NULL, IFA, npos, POS, &ctx, &scn)); + BA(CREATE(dev, ntris, IDS, NULL, npos, POS, &ctx, &scn)); + BA(CREATE(dev, ntris, IDS, IFA, 0, POS, &ctx, &scn)); + BA(CREATE(dev, ntris, IDS, IFA, npos, NULL, &ctx, &scn)); + OK(CREATE(dev, ntris, IDS, IFA, npos, POS, &ctx, &scn)); #undef CREATE #undef IDS #undef POS #undef IFA - CHK(sdis_scene_get_aabb(NULL, lower, upper) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, NULL, upper) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, lower, NULL) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, lower, upper) == RES_OK); + BA(sdis_scene_get_aabb(NULL, lower, upper)); + BA(sdis_scene_get_aabb(scn, NULL, upper)); + BA(sdis_scene_get_aabb(scn, lower, NULL)); + OK(sdis_scene_get_aabb(scn, lower, upper)); CHK(eq_eps(lower[0], 0, 1.e-6)); CHK(eq_eps(lower[1], 0, 1.e-6)); CHK(eq_eps(lower[2], 0, 1.e-6)); @@ -132,17 +132,17 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf) uv0[0] = 0.3; uv0[1] = 0.3; - CHK(sdis_scene_get_boundary_position(NULL, 6, uv0, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 12, uv0, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 6, NULL, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 6, uv0, NULL) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 6, uv0, pos) == RES_OK); + BA(sdis_scene_get_boundary_position(NULL, 6, uv0, pos)); + BA(sdis_scene_get_boundary_position(scn, 12, uv0, pos)); + BA(sdis_scene_get_boundary_position(scn, 6, NULL, pos)); + BA(sdis_scene_get_boundary_position(scn, 6, uv0, NULL)); + OK(sdis_scene_get_boundary_position(scn, 6, uv0, pos) ); - CHK(sdis_scene_boundary_project_position(NULL, 6, pos, uv1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 12, pos, uv1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 6, NULL, uv1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 6, pos, NULL) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 6, pos, uv1) == RES_OK); + BA(sdis_scene_boundary_project_position(NULL, 6, pos, uv1)); + BA(sdis_scene_boundary_project_position(scn, 12, pos, uv1)); + BA(sdis_scene_boundary_project_position(scn, 6, NULL, uv1)); + BA(sdis_scene_boundary_project_position(scn, 6, pos, NULL)); + OK(sdis_scene_boundary_project_position(scn, 6, pos, uv1)); CHK(d2_eq_eps(uv0, uv1, 1.e-6)); @@ -150,23 +150,23 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf) uv0[0] = rand_canonic(); uv0[1] = rand_canonic() * (1 - uv0[0]); - CHK(sdis_scene_get_boundary_position(scn, 4, uv0, pos) == RES_OK); - CHK(sdis_scene_boundary_project_position(scn, 4, pos, uv1) == RES_OK); + OK(sdis_scene_get_boundary_position(scn, 4, uv0, pos)); + OK(sdis_scene_boundary_project_position(scn, 4, pos, uv1)); CHK(d2_eq_eps(uv0, uv1, 1.e-6)); } pos[0] = 10; pos[1] = 0.1; pos[2] = 0.5; - CHK(sdis_scene_boundary_project_position(scn, 6, pos, uv1) == RES_OK); - CHK(sdis_scene_get_boundary_position(scn, 6, uv1, pos1) == RES_OK); + OK(sdis_scene_boundary_project_position(scn, 6, pos, uv1)); + OK(sdis_scene_get_boundary_position(scn, 6, uv1, pos1)); CHK(!d3_eq_eps(pos1, pos, 1.e-6)); - CHK(sdis_scene_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_scene_ref_get(scn) == RES_OK); - CHK(sdis_scene_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_scene_ref_put(scn) == RES_OK); + BA(sdis_scene_ref_get(NULL)); + OK(sdis_scene_ref_get(scn)); + BA(sdis_scene_ref_put(NULL)); + OK(sdis_scene_ref_put(scn)); + OK(sdis_scene_ref_put(scn)); } static void @@ -190,23 +190,23 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf) #define POS get_position_2d #define IFA get_interface - CHK(CREATE(NULL, 0, NULL, NULL, 0, NULL, &ctx, NULL) == RES_BAD_ARG); - CHK(CREATE(dev, 0, IDS, IFA, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, nsegs, NULL, IFA, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, nsegs, IDS, NULL, npos, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, nsegs, IDS, IFA, 0, POS, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, nsegs, IDS, IFA, npos, NULL, &ctx, &scn) == RES_BAD_ARG); - CHK(CREATE(dev, nsegs, IDS, IFA, npos, POS, &ctx, &scn) == RES_OK); + BA(CREATE(NULL, 0, NULL, NULL, 0, NULL, &ctx, NULL)); + BA(CREATE(dev, 0, IDS, IFA, npos, POS, &ctx, &scn)); + BA(CREATE(dev, nsegs, NULL, IFA, npos, POS, &ctx, &scn)); + BA(CREATE(dev, nsegs, IDS, NULL, npos, POS, &ctx, &scn)); + BA(CREATE(dev, nsegs, IDS, IFA, 0, POS, &ctx, &scn)); + BA(CREATE(dev, nsegs, IDS, IFA, npos, NULL, &ctx, &scn)); + OK(CREATE(dev, nsegs, IDS, IFA, npos, POS, &ctx, &scn)); #undef CREATE #undef IDS #undef POS #undef IFA - CHK(sdis_scene_get_aabb(NULL, lower, upper) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, NULL, upper) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, lower, NULL) == RES_BAD_ARG); - CHK(sdis_scene_get_aabb(scn, lower, upper) == RES_OK); + BA(sdis_scene_get_aabb(NULL, lower, upper)); + BA(sdis_scene_get_aabb(scn, NULL, upper)); + BA(sdis_scene_get_aabb(scn, lower, NULL)); + OK(sdis_scene_get_aabb(scn, lower, upper)); CHK(eq_eps(lower[0], 0, 1.e-6)); CHK(eq_eps(lower[1], 0, 1.e-6)); CHK(eq_eps(upper[0], 1, 1.e-6)); @@ -214,41 +214,41 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf) u0 = 0.5; - CHK(sdis_scene_get_boundary_position(NULL, 1, &u0, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 4, &u0, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 1, NULL, pos) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 1, &u0, NULL) == RES_BAD_ARG); - CHK(sdis_scene_get_boundary_position(scn, 1, &u0, pos) == RES_OK); + BA(sdis_scene_get_boundary_position(NULL, 1, &u0, pos)); + BA(sdis_scene_get_boundary_position(scn, 4, &u0, pos)); + BA(sdis_scene_get_boundary_position(scn, 1, NULL, pos)); + BA(sdis_scene_get_boundary_position(scn, 1, &u0, NULL)); + OK(sdis_scene_get_boundary_position(scn, 1, &u0, pos)); - CHK(sdis_scene_boundary_project_position(NULL, 1, pos, &u1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 4, pos, &u1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 1, NULL, &u1) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 1, pos, NULL) == RES_BAD_ARG); - CHK(sdis_scene_boundary_project_position(scn, 1, pos, &u1) == RES_OK); + BA(sdis_scene_boundary_project_position(NULL, 1, pos, &u1)); + BA(sdis_scene_boundary_project_position(scn, 4, pos, &u1)); + BA(sdis_scene_boundary_project_position(scn, 1, NULL, &u1)); + BA(sdis_scene_boundary_project_position(scn, 1, pos, NULL)); + OK(sdis_scene_boundary_project_position(scn, 1, pos, &u1)); CHK(eq_eps(u0, u1, 1.e-6)); FOR_EACH(i, 0, 64) { u0 = rand_canonic(); - CHK(sdis_scene_get_boundary_position(scn, 2, &u0, pos) == RES_OK); - CHK(sdis_scene_boundary_project_position(scn, 2, pos, &u1) == RES_OK); + OK(sdis_scene_get_boundary_position(scn, 2, &u0, pos)); + OK(sdis_scene_boundary_project_position(scn, 2, pos, &u1)); CHK(eq_eps(u0, u1, 1.e-6)); } d2(pos, 5, 0.5); - CHK(sdis_scene_boundary_project_position(scn, 3, pos, &u0) == RES_OK); + OK(sdis_scene_boundary_project_position(scn, 3, pos, &u0)); CHK(eq_eps(u0, 0.5, 1.e-6)); d2(pos, 1, 2); - CHK(sdis_scene_boundary_project_position(scn, 3, pos, &u0) == RES_OK); + OK(sdis_scene_boundary_project_position(scn, 3, pos, &u0)); CHK(eq_eps(u0, 0, 1.e-6)); d2(pos, 1, -1); - CHK(sdis_scene_boundary_project_position(scn, 3, pos, &u0) == RES_OK); + OK(sdis_scene_boundary_project_position(scn, 3, pos, &u0)); CHK(eq_eps(u0, 1, 1.e-6)); - CHK(sdis_scene_ref_put(scn) == RES_OK); + OK(sdis_scene_ref_put(scn)); } int @@ -266,22 +266,22 @@ main(int argc, char** argv) interface_shader.convection_coef = DUMMY_INTERFACE_SHADER.convection_coef; - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(sdis_device_create(NULL, &allocator, 1, 0, &dev) == RES_OK); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, 1, 0, &dev)); - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &interf) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &interf)); - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); test_scene_3d(dev, interf); test_scene_2d(dev, interf); - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(sdis_device_ref_put(dev)); + OK(sdis_interface_ref_put(interf)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_boundary.c b/src/test_sdis_solve_boundary.c @@ -0,0 +1,408 @@ +/* Copyright (C) 2016-2019 |Meso|Star> (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> + +/* + * The scene is composed of a solid cube/square whose temperature is unknown. + * The convection coefficient with the surrounding fluid is null exepted for + * the +X face whose value is 'H'. The Temperature of the -X face is fixed to + * Tb. This test computes the temperature on the +X face and check that it is + * equal to: + * + * T = (H*Tf + LAMBDA/A * Tb) / (H+LAMBDA/A) + * + * with Tf the temperature of the surrounding fluid, lambda the conductivity of + * the cube and A the size of the cube/square, i.e. 1. + * + * 3D 2D + * + * ///// (1,1,1) ///// (1,1) + * +-------+ +-------+ + * /' /| _\ | | _\ + * +-------+ | / / Tf Tb | / / Tf + * Tb +.....|.+ \__/ | | \__/ + * |, |/ +-------+ + * +-------+ (0,0) ///// + * (0,0,0) ///// + */ + +#define UNKNOWN_TEMPERATURE -1 +#define N 10000 /* #realisations */ + +#define Tf 310.0 +#define Tb 300.0 +#define H 0.5 +#define LAMBDA 0.1 + +/******************************************************************************* + * Media + ******************************************************************************/ +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; +} + + +static double +solid_get_calorific_capacity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void)data; + CHK(vtx != NULL); + return 2.0; +} + +static double +solid_get_thermal_conductivity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void)data; + CHK(vtx != NULL); + return LAMBDA; +} + +static double +solid_get_volumic_mass + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void)data; + CHK(vtx != NULL); + return 25.0; +} + +static double +solid_get_delta + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void)data; + CHK(vtx != NULL); + return 1.0/20.0; +} + +static double +solid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void)data; + CHK(vtx != NULL); + return UNKNOWN_TEMPERATURE; +} + +/******************************************************************************* + * Interfaces + ******************************************************************************/ +struct interf { + double temperature; + double hc; +}; + +static double +interface_get_temperature + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interf* interf = sdis_data_cget(data); + CHK(frag && data); + return interf->temperature; +} + +static double +interface_get_convection_coef + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interf* interf = sdis_data_cget(data); + CHK(frag && data); + return interf->hc; +} + +/******************************************************************************* + * Helper function + ******************************************************************************/ +static void +check_estimator + (const struct sdis_estimator* estimator, + const size_t nrealisations, /* #realisations */ + const double ref) +{ + struct sdis_mc T = SDIS_MC_NULL; + size_t nreals; + size_t nfails; + CHK(estimator && nrealisations); + + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + printf("%g ~ %g +/- %g\n", ref, T.E, T.SE); + printf("#failures = %lu/%lu\n", + (unsigned long)nfails, (unsigned long)nrealisations); + CHK(nfails + nreals == nrealisations); + CHK(nfails < N/1000); + CHK(eq_eps(T.E, ref, 3*T.SE)); +} + +/******************************************************************************* + * Test + ******************************************************************************/ +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sdis_data* data = NULL; + struct sdis_device* dev = NULL; + struct sdis_medium* fluid = NULL; + struct sdis_medium* solid = NULL; + struct sdis_interface* interf_adiabatic = NULL; + struct sdis_interface* interf_Tb = NULL; + struct sdis_interface* interf_H = NULL; + struct sdis_scene* box_scn = NULL; + struct sdis_scene* square_scn = NULL; + struct sdis_estimator* estimator = NULL; + struct sdis_fluid_shader fluid_shader = DUMMY_FLUID_SHADER; + struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; + struct sdis_interface_shader interf_shader = SDIS_INTERFACE_SHADER_NULL; + struct sdis_interface* box_interfaces[12 /*#triangles*/]; + struct sdis_interface* square_interfaces[4/*#segments*/]; + struct interf* interf_props = NULL; + struct fluid* fluid_param; + double uv[2]; + double pos[3]; + double time_range[2] = { INF, INF }; + double tr[2]; + double ref; + size_t prims[4]; + enum sdis_side sides[4]; + size_t iprim; + (void)argc, (void)argv; + + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); + + /* Create the fluid medium */ + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); + fluid_param = sdis_data_get(data); + fluid_param->temperature = Tf; + fluid_shader.temperature = fluid_get_temperature; + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid)); + OK(sdis_data_ref_put(data)); + + /* Create the solid_medium */ + 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.temperature = solid_get_temperature; + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); + + /* Setup the interface shader */ + interf_shader.convection_coef = interface_get_convection_coef; + interf_shader.front.temperature = interface_get_temperature; + interf_shader.front.emissivity = NULL; + interf_shader.front.specular_fraction = NULL; + interf_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; + + /* Create the adiabatic interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = 0; + interf_props->temperature = UNKNOWN_TEMPERATURE; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_adiabatic)); + OK(sdis_data_ref_put(data)); + + /* Create the Tb interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = 0; + interf_props->temperature = Tb; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_Tb)); + OK(sdis_data_ref_put(data)); + + /* Create the H interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = H; + interf_props->temperature = UNKNOWN_TEMPERATURE; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_H)); + OK(sdis_data_ref_put(data)); + + /* Release the media */ + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); + + /* Map the interfaces to their box triangles */ + box_interfaces[0] = box_interfaces[1] = interf_adiabatic; /* Front */ + box_interfaces[2] = box_interfaces[3] = interf_Tb; /* Left */ + box_interfaces[4] = box_interfaces[5] = interf_adiabatic; /* Back */ + box_interfaces[6] = box_interfaces[7] = interf_H; /* Right */ + box_interfaces[8] = box_interfaces[9] = interf_adiabatic; /* Top */ + box_interfaces[10]= box_interfaces[11]= interf_adiabatic; /* Bottom */ + + /* Map the interfaces to their square segments */ + square_interfaces[0] = interf_adiabatic; /* Bottom */ + square_interfaces[1] = interf_Tb; /* Lef */ + square_interfaces[2] = interf_adiabatic; /* Top */ + square_interfaces[3] = interf_H; /* Right */ + + /* Create the box scene */ + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + box_get_interface, box_nvertices, box_get_position, box_interfaces, + &box_scn)); + + /* Create the square scene */ + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + square_get_interface, square_nvertices, square_get_position, + square_interfaces, &square_scn)); + + /* Release the interfaces */ + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_Tb)); + OK(sdis_interface_ref_put(interf_H)); + + ref = (H*Tf + LAMBDA * Tb) / (H + LAMBDA); + + #define SOLVE sdis_solve_probe_boundary + #define F SDIS_FRONT + uv[0] = 0.3; + uv[1] = 0.3; + iprim = 6; + + BA(SOLVE(NULL, N, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, 0, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, 12, uv, time_range, F, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, iprim, NULL, time_range, F, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, iprim, uv, NULL, F, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, iprim, uv, time_range, -1, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, iprim, uv, time_range, F, 1.0, 0, 0, NULL)); + tr[0] = tr[1] = -1; + BA(SOLVE(box_scn, N, iprim, uv, tr, F, 1.0, 0, 0, NULL)); + tr[0] = 1; + BA(SOLVE(box_scn, N, iprim, uv, tr, F, 1.0, 0, 0, NULL)); + tr[1] = 0; + BA(SOLVE(box_scn, N, iprim, uv, tr, F, 1.0, 0, 0, NULL)); + + OK(SOLVE(box_scn, N, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + OK(sdis_scene_get_boundary_position(box_scn, iprim, uv, pos)); + printf("Boundary temperature of the box at (%g %g %g) = ", SPLIT3(pos)); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + + /* The external fluid cannot have an unknown temperature */ + fluid_param->temperature = UNKNOWN_TEMPERATURE; + BA(SOLVE(box_scn, N, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + fluid_param->temperature = Tf; + + uv[0] = 0.5; + iprim = 3; + BA(SOLVE(square_scn, N, 4, uv, time_range, F, 1.0, 0, 0, &estimator)); + OK(SOLVE(square_scn, N, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + OK(sdis_scene_get_boundary_position(square_scn, iprim, uv, pos)); + printf("Boundary temperature of the square at (%g %g) = ", SPLIT2(pos)); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + + /* The external fluid cannot have an unknown temperature */ + fluid_param->temperature = UNKNOWN_TEMPERATURE; + BA(SOLVE(square_scn, N, iprim, uv, time_range, F, 1.0, 0, 0, &estimator)); + fluid_param->temperature = Tf; + #undef F + #undef SOLVE + + sides[0] = SDIS_FRONT; + sides[1] = SDIS_FRONT; + sides[2] = SDIS_FRONT; + sides[3] = SDIS_FRONT; + + #define SOLVE sdis_solve_boundary + prims[0] = 6; + prims[1] = 7; + BA(SOLVE(NULL, N, prims, sides, 2, time_range, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, 0, prims, sides, 2, time_range, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, NULL, sides, 2, time_range, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, prims, NULL, 2, time_range, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, prims, sides, 0, time_range, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, prims, sides, 2, NULL, 1.0, 0, 0, &estimator)); + BA(SOLVE(box_scn, N, prims, sides, 2, time_range, 1.0, 0, 0, NULL)); + tr[0] = tr[1] = -1; + BA(SOLVE(box_scn, N, prims, sides, 2, tr, 1.0, 0, 0, NULL)); + tr[0] = 1; + BA(SOLVE(box_scn, N, prims, sides, 2, tr, 1.0, 0, 0, NULL)); + tr[1] = 0; + BA(SOLVE(box_scn, N, prims, sides, 2, tr, 1.0, 0, 0, NULL)); + + /* Average temperature on the right side of the box */ + OK(SOLVE(box_scn, N, prims, sides, 2, time_range, 1.0, 0, 0, &estimator)); + printf("Average temperature of the right side of the box = "); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + + /* Average temperature on the right side of the square */ + prims[0] = 3; + sides[0] = SDIS_FRONT; + OK(SOLVE(square_scn, N, prims, sides, 1, time_range, 1.0, 0, 0, &estimator)); + printf("Average temperature of the right side of the square = "); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + + /* Check out of bound prims */ + prims[0] = 12; + BA(SOLVE(box_scn, N, prims, sides, 2, time_range, 1.0, 0, 0, &estimator)); + prims[0] = 4; + BA(SOLVE(square_scn, N, prims, sides, 1, time_range, 1.0, 0, 0, &estimator)); + + /* Average temperature on the left+right sides of the box */ + prims[0] = 2; + prims[1] = 3; + prims[2] = 6; + prims[3] = 7; + + ref = (ref + Tb) / 2; + + OK(SOLVE(box_scn, N, prims, sides, 4, time_range, 1.0, 0, 0, &estimator)); + printf("Average temperature of the left+right sides of the box = "); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + + /* Average temperature on the left+right sides of the square */ + prims[0] = 1; + prims[1] = 3; + OK(SOLVE(square_scn, N, prims, sides, 2, time_range, 1.0, 0, 0, &estimator)); + printf("Average temperature of the left+right sides of the square = "); + check_estimator(estimator, N, ref); + OK(sdis_estimator_ref_put(estimator)); + #undef SOLVE + + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} + diff --git a/src/test_sdis_solve_boundary_flux.c b/src/test_sdis_solve_boundary_flux.c @@ -0,0 +1,454 @@ +/* Copyright (C) 2016-2019 |Meso|Star> (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> + + /* + * The scene is composed of a solid cube/square whose temperature is unknown. + * The convection coefficient with the surrounding fluid is null excepted for + * the X faces whose value is 'H'. The Temperature T of the -X face is fixed + * to Tb. The ambiant radiative temperature is 0 excepted for the X faces + * whose value is 'Trad'. + * This test computes temperature and fluxes on the X faces and check that + * they are equal to: + * + * T(+X) = (H*Tf + Hrad*Trad + LAMBDA/A * Tb) / (H+Hrad+LAMBDA/A) + * with Hrad = 4 * BOLTZMANN_CONSTANT * Tref^3 * epsilon + * T(-X) = Tb + * + * CF = H * (T - Tf) + * RF = Hrad * (T - Trad) + * TF = CF + RF + * + * with Tf the temperature of the surrounding fluid, lambda the conductivity of + * the cube and A the size of the cube/square, i.e. 1. + * + * 3D + * + * ///////(1,1,1) + * +-------+ + * /' /| _\ <----- + * -----> _\ +-------+ | / / H,Tf <----- Trad + * Trad -----> H,Tf / / Tb +.....|.+ \__/ <----- + * -----> \__/ |, |/ + * +-------+ + * (0,0,0)/////// + * + * + * 2D + * + * ///////(1,1) + * +-------+ + * -----> _\ | | _\ <----- + * Trad -----> H,Tf / / Tb | / / H,Tf <----- Trad + * -----> \__/ | | \__/ <----- + * +-------+ + * (0,0)/////// + */ + +#define UNKNOWN_TEMPERATURE -1 +#define N 10000 /* #realisations */ + +#define Tf 300.0 +#define Tb 0.0 +#define H 0.5 +#define Trad 300.0 +#define LAMBDA 0.1 +#define EPSILON 1.0 + +#define Tref 300.0 +#define Hrad (4 * BOLTZMANN_CONSTANT * Tref * Tref * Tref * EPSILON) + +/******************************************************************************* + * Media + ******************************************************************************/ +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; +} + + +static double +solid_get_calorific_capacity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void) data; + CHK(vtx != NULL); + return 2.0; +} + +static double +solid_get_thermal_conductivity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void) data; + CHK(vtx != NULL); + return LAMBDA; +} + +static double +solid_get_volumic_mass + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void) data; + CHK(vtx != NULL); + return 25.0; +} + +static double +solid_get_delta + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void) data; + CHK(vtx != NULL); + return 1.0 / 20.0; +} + +static double +solid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + (void) data; + CHK(vtx != NULL); + return UNKNOWN_TEMPERATURE; +} + +/******************************************************************************* + * Interfaces + ******************************************************************************/ +struct interf { + double temperature; + double emissivity; + double hc; +}; + +static double +interface_get_temperature + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interf* interf = sdis_data_cget(data); + CHK(frag && data); + return interf->temperature; +} + +static double +interface_get_emissivity + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interf* interf = sdis_data_cget(data); + CHK(frag && data); + return interf->emissivity; +} + +static double +interface_get_convection_coef + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interf* interf = sdis_data_cget(data); + CHK(frag && data); + return interf->hc; +} + +/******************************************************************************* + * Helper function + ******************************************************************************/ +static void +check_estimator + (const struct sdis_estimator* estimator, + const size_t nrealisations, /* #realisations */ + const double T, + const double CF, + const double RF, + const double TF) +{ + struct sdis_mc V = SDIS_MC_NULL; + enum sdis_estimator_type type; + size_t nreals; + size_t nfails; + CHK(estimator && nrealisations); + + OK(sdis_estimator_get_temperature(estimator, &V)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + printf("T = %g ~ %g +/- %g\n", T, V.E, V.SE); + CHK(eq_eps(V.E, T, 3 * (V.SE ? V.SE : FLT_EPSILON))); + OK(sdis_estimator_get_type(estimator, &type)); + if(type == SDIS_FLUX_ESTIMATOR) { + OK(sdis_estimator_get_convective_flux(estimator, &V)); + printf("Convective flux = %g ~ %g +/- %g\n", CF, V.E, V.SE); + CHK(eq_eps(V.E, CF, 3 * (V.SE ? V.SE : FLT_EPSILON))); + OK(sdis_estimator_get_radiative_flux(estimator, &V)); + printf("Radiative flux = %g ~ %g +/- %g\n", RF, V.E, V.SE); + CHK(eq_eps(V.E, RF, 3 * (V.SE ? V.SE : FLT_EPSILON))); + OK(sdis_estimator_get_total_flux(estimator, &V)); + printf("Total flux = %g ~ %g +/- %g\n", TF, V.E, V.SE); + CHK(eq_eps(V.E, TF, 3 * (V.SE ? V.SE : FLT_EPSILON))); + } + printf("#failures = %lu/%lu\n", + (unsigned long) nfails, (unsigned long) nrealisations); + CHK(nfails + nreals == nrealisations); + CHK(nfails < N / 1000); +} + +/******************************************************************************* + * Test + ******************************************************************************/ +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sdis_data* data = NULL; + struct sdis_device* dev = NULL; + struct sdis_medium* fluid = NULL; + struct sdis_medium* solid = NULL; + struct sdis_interface* interf_adiabatic = NULL; + struct sdis_interface* interf_Tb = NULL; + struct sdis_interface* interf_H = NULL; + struct sdis_scene* box_scn = NULL; + struct sdis_scene* square_scn = NULL; + struct sdis_estimator* estimator = NULL; + struct sdis_fluid_shader fluid_shader = DUMMY_FLUID_SHADER; + struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; + struct sdis_interface_shader interf_shader = SDIS_INTERFACE_SHADER_NULL; + struct sdis_interface* box_interfaces[12 /*#triangles*/]; + struct sdis_interface* square_interfaces[4/*#segments*/]; + struct interf* interf_props = NULL; + struct fluid* fluid_param; + enum sdis_estimator_type type; + double uv[2]; + double pos[3]; + double time_range[2] = { INF, INF }; + double tr[2]; + double analyticT, analyticCF, analyticRF, analyticTF; + size_t prims[2]; + size_t iprim; + (void)argc, (void)argv; + + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); + + /* Create the fluid medium */ + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); + fluid_param = sdis_data_get(data); + fluid_param->temperature = Tf; + fluid_shader.temperature = fluid_get_temperature; + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid)); + OK(sdis_data_ref_put(data)); + + /* Create the solid_medium */ + 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.temperature = solid_get_temperature; + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); + + /* Setup the interface shader */ + interf_shader.convection_coef = interface_get_convection_coef; + interf_shader.front.temperature = interface_get_temperature; + interf_shader.front.specular_fraction = NULL; + interf_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; + + /* Create the adiabatic interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = 0; + interf_props->temperature = UNKNOWN_TEMPERATURE; + interf_props->emissivity = 0; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_adiabatic)); + OK(sdis_data_ref_put(data)); + + /* Create the Tb interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = H; + interf_props->temperature = Tb; + interf_props->emissivity = EPSILON; + interf_shader.back.emissivity = interface_get_emissivity; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_Tb)); + interf_shader.back.emissivity = NULL; + OK(sdis_data_ref_put(data)); + + /* Create the H interface */ + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); + interf_props = sdis_data_get(data); + interf_props->hc = H; + interf_props->temperature = UNKNOWN_TEMPERATURE; + interf_props->emissivity = EPSILON; + interf_shader.back.emissivity = interface_get_emissivity; + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_H)); + interf_shader.back.emissivity = NULL; + OK(sdis_data_ref_put(data)); + + /* Release the media */ + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); + + /* Map the interfaces to their box triangles */ + box_interfaces[0] = box_interfaces[1] = interf_adiabatic; /* Front */ + box_interfaces[2] = box_interfaces[3] = interf_Tb; /* Left */ + box_interfaces[4] = box_interfaces[5] = interf_adiabatic; /* Back */ + box_interfaces[6] = box_interfaces[7] = interf_H; /* Right */ + box_interfaces[8] = box_interfaces[9] = interf_adiabatic; /* Top */ + box_interfaces[10] = box_interfaces[11] = interf_adiabatic; /* Bottom */ + + /* Map the interfaces to their square segments */ + square_interfaces[0] = interf_adiabatic; /* Bottom */ + square_interfaces[1] = interf_Tb; /* Lef */ + square_interfaces[2] = interf_adiabatic; /* Top */ + square_interfaces[3] = interf_H; /* Right */ + + /* Create the box scene */ + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + box_get_interface, box_nvertices, box_get_position, box_interfaces, + &box_scn)); + + /* Create the square scene */ + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + square_get_interface, square_nvertices, square_get_position, + square_interfaces, &square_scn)); + + /* Release the interfaces */ + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_Tb)); + OK(sdis_interface_ref_put(interf_H)); + + analyticT = (H*Tf + Hrad*Trad + LAMBDA * Tb) / (H + Hrad + LAMBDA); + analyticCF = H * (analyticT - Tf); + analyticRF = Hrad * (analyticT - Trad); + analyticTF = analyticCF + analyticRF; + + #define SOLVE sdis_solve_probe_boundary_flux + uv[0] = 0.3; + uv[1] = 0.3; + iprim = 6; + + BA(SOLVE(NULL, N, iprim, uv, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, 0, iprim, uv, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, 12, uv, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, iprim, NULL, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, iprim, uv, NULL, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, iprim, uv, time_range, 1.0, Trad, Tref, NULL)); + tr[0] = tr[1] = -1; + BA(SOLVE(box_scn, N, iprim, uv, tr, 1.0, Trad, Tref, &estimator)); + tr[0] = 1; + BA(SOLVE(box_scn, N, iprim, uv, tr, 1.0, Trad, Tref, &estimator)); + tr[1] = 0; + BA(SOLVE(box_scn, N, iprim, uv, tr, 1.0, Trad, Tref, &estimator)); + tr[1] = INF; + BA(SOLVE(box_scn, N, iprim, uv, tr, 1.0, Trad, Tref, &estimator)); + + OK(SOLVE(box_scn, N, iprim, uv, time_range, 1.0, Trad, Tref, &estimator)); + OK(sdis_estimator_get_type(estimator, &type)); + CHK(type == SDIS_FLUX_ESTIMATOR); + + OK(sdis_scene_get_boundary_position(box_scn, iprim, uv, pos)); + printf("Boundary values of the box at (%g %g %g) = ", SPLIT3(pos)); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + + uv[0] = 0.5; + iprim = 3; + BA(SOLVE(square_scn, N, 4, uv, time_range, 1.0, Trad, Tref, &estimator)); + OK(SOLVE(square_scn, N, iprim, uv, time_range, 1.0, Trad, Tref, &estimator)); + OK(sdis_scene_get_boundary_position(square_scn, iprim, uv, pos)); + printf("Boundary values of the square at (%g %g) = ", SPLIT2(pos)); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + + #undef F + #undef SOLVE + + #define SOLVE sdis_solve_boundary_flux + prims[0] = 6; + prims[1] = 7; + BA(SOLVE(NULL, N, prims, 2, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, 0, prims, 2, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, NULL, 2, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, prims, 0, time_range, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, prims, 2, NULL, 1.0, Trad, Tref, &estimator)); + BA(SOLVE(box_scn, N, prims, 2, time_range, 1.0, Trad, Tref, NULL)); + tr[0] = tr[1] = -1; + BA(SOLVE(box_scn, N, prims, 2, tr, 1.0, Trad, Tref, NULL)); + tr[0] = 1; + BA(SOLVE(box_scn, N, prims, 2, tr, 1.0, Trad, Tref, NULL)); + tr[1] = 0; + BA(SOLVE(box_scn, N, prims, 2, tr, 1.0, Trad, Tref, NULL)); + + /* Average temperature on the right side of the box */ + OK(SOLVE(box_scn, N, prims, 2, time_range, 1.0, Trad, Tref, &estimator)); + printf("Average values of the right side of the box = "); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + + /* Average temperature on the right side of the square */ + prims[0] = 3; + OK(SOLVE(square_scn, N, prims, 1, time_range, 1.0, Trad, Tref, &estimator)); + printf("Average values of the right side of the square = "); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + + /* Check out of bound prims */ + prims[0] = 12; + BA(SOLVE(box_scn, N, prims, 2, time_range, 1.0, Trad, Tref, &estimator)); + prims[0] = 4; + BA(SOLVE(square_scn, N, prims, 1, time_range, 1.0, Trad, Tref, &estimator)); + + /* Average temperature on the left side of the box */ + prims[0] = 2; + prims[1] = 3; + + analyticT = Tb; + analyticCF = H * (analyticT - Tf); + analyticRF = Hrad * (analyticT - Trad); + analyticTF = analyticCF + analyticRF; + + OK(SOLVE(box_scn, N, prims, 2, time_range, 1.0, Trad, Tref, &estimator)); + printf("Average values of the left side of the box = "); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + + /* Average temperature on the left/right side of the square */ + prims[0] = 1; + OK(SOLVE(square_scn, N, prims, 1, time_range, 1.0, Trad, Tref, &estimator)); + printf("Average values of the left side of the square = "); + check_estimator(estimator, N, analyticT, analyticCF, analyticRF, analyticTF); + OK(sdis_estimator_ref_put(estimator)); + #undef SOLVE + + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} + diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -289,8 +289,8 @@ create_solid CHK(solid != NULL); /* Copy the solid parameters into the Stardis memory space */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); memcpy(solid_param, param, sizeof(struct solid)); @@ -303,11 +303,11 @@ create_solid solid_shader.temperature = solid_get_temperature; /* Create the solid medium */ - CHK(sdis_solid_create(dev, &solid_shader, data, solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, solid)); /* Release the ownership onto the Stardis memory space storing the solid * parameters */ - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_ref_put(data)); } static void @@ -324,8 +324,8 @@ create_fluid CHK(fluid != NULL); /* Copy the fluid parameters into the Stardis memory space */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); memcpy(fluid_param, param, sizeof(struct fluid)); @@ -335,11 +335,11 @@ create_fluid fluid_shader.temperature = fluid_get_temperature; /* Create the fluid medium */ - CHK(sdis_fluid_create(dev, &fluid_shader, data, fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, fluid)); /* Release the ownership onto the Stardis memory space storing the fluid * parameters */ - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_ref_put(data)); } static void @@ -360,8 +360,8 @@ create_interface CHK(interf != NULL); /* Copy the interface parameters into the Stardis memory space */ - CHK(sdis_data_create - (dev, sizeof(struct interf), ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct interf), ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); memcpy(interface_param, param, sizeof(struct interf)); @@ -378,12 +378,12 @@ create_interface interface_shader.back.specular_fraction = interface_get_specular_fraction; } /* Create the interface */ - CHK(sdis_interface_create - (dev, mdm_front, mdm_back, &interface_shader, data, interf) == RES_OK); + OK(sdis_interface_create + (dev, mdm_front, mdm_back, &interface_shader, data, interf)); /* Release the ownership onto the Stardis memory space storing the interface * parameters */ - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_ref_put(data)); } static void @@ -445,12 +445,12 @@ dump_image(const struct sdis_accum_buffer* buf) size_t i, ix, iy; CHK(buf != NULL); - CHK(sdis_accum_buffer_get_layout(buf, &layout) == RES_OK); + OK(sdis_accum_buffer_get_layout(buf, &layout)); temps = mem_alloc(layout.width*layout.height*sizeof(double)); CHK(temps != NULL); - CHK(sdis_accum_buffer_map(buf, &accums) == RES_OK); + OK(sdis_accum_buffer_map(buf, &accums)); /* Check the results validity */ FOR_EACH(i, 0, layout.height * layout.width) { @@ -478,9 +478,8 @@ dump_image(const struct sdis_accum_buffer* buf) } /* Allocate the image memory space */ - CHK(image_init(NULL, &img) == RES_OK); - CHK(image_setup(&img, IMG_WIDTH, IMG_HEIGHT, IMG_WIDTH*3, IMAGE_RGB8, NULL) - == RES_OK); + OK(image_init(NULL, &img)); + OK(image_setup(&img, IMG_WIDTH, IMG_HEIGHT, IMG_WIDTH*3, IMAGE_RGB8, NULL)); FOR_EACH(iy, 0, layout.height) { const double* src_row = temps + iy*layout.width; @@ -495,7 +494,7 @@ dump_image(const struct sdis_accum_buffer* buf) pixels[2] = T; } } - CHK(image_write_ppm_stream(&img, 0/*binary?*/, stdout) == RES_OK); + OK(image_write_ppm_stream(&img, 0/*binary?*/, stdout)); image_release(&img); mem_rm(temps); } @@ -528,9 +527,8 @@ main(int argc, char** argv) double up[3]; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid0 */ fluid_param.temperature = 350; @@ -567,43 +565,42 @@ main(int argc, char** argv) create_interface(dev, fluid1, solid, &interface_param, &interf1); /* Release the ownership onto 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); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid0)); + OK(sdis_medium_ref_put(fluid1)); /* Setup the cube geometry */ - CHK(s3dut_create_cuboid(&allocator, 2, 2, 2, &msh) == RES_OK); - CHK(s3dut_mesh_get_data(msh, &msh_data) == RES_OK); + OK(s3dut_create_cuboid(&allocator, 2, 2, 2, &msh)); + OK(s3dut_mesh_get_data(msh, &msh_data)); geometry_add_shape(&geom, msh_data.positions, msh_data.nvertices, msh_data.indices, msh_data.nprimitives, NULL, interf1); - CHK(s3dut_mesh_ref_put(msh) == RES_OK); + OK(s3dut_mesh_ref_put(msh)); /* Setup the sphere geometry */ - CHK(s3dut_create_sphere(&allocator, 0.5, 32, 16, &msh) == RES_OK); - CHK(s3dut_mesh_get_data(msh, &msh_data) == RES_OK); + OK(s3dut_create_sphere(&allocator, 0.5, 32, 16, &msh)); + OK(s3dut_mesh_get_data(msh, &msh_data)); geometry_add_shape(&geom, msh_data.positions, msh_data.nvertices, msh_data.indices, msh_data.nprimitives, NULL, interf0); - CHK(s3dut_mesh_ref_put(msh) == RES_OK); + OK(s3dut_mesh_ref_put(msh)); /* Setup the scene */ ntris = sa_size(geom.indices) / 3; /* #primitives */ npos = sa_size(geom.positions) / 3; /* #positions */ - CHK(sdis_scene_create(dev, ntris, geometry_get_indices, + OK(sdis_scene_create(dev, ntris, geometry_get_indices, geometry_get_interface, npos, geometry_get_position, - &geom, &scn) == RES_OK); + &geom, &scn)); /* Setup the camera */ d3(pos, 3, 3, 3); d3(tgt, 0, 0, 0); d3(up, 0, 0, 1); - CHK(sdis_camera_create(dev, &cam) == RES_OK); - CHK(sdis_camera_set_proj_ratio - (cam, (double)IMG_WIDTH/(double)IMG_HEIGHT) == RES_OK); - CHK(sdis_camera_set_fov(cam, MDEG2RAD(70)) == RES_OK); - CHK(sdis_camera_look_at(cam, pos, tgt, up) == RES_OK); + OK(sdis_camera_create(dev, &cam)); + OK(sdis_camera_set_proj_ratio(cam, (double)IMG_WIDTH/(double)IMG_HEIGHT)); + OK(sdis_camera_set_fov(cam, MDEG2RAD(70))); + OK(sdis_camera_look_at(cam, pos, tgt, up)); /* Create the accum buffer */ - CHK(sdis_accum_buffer_create(dev, IMG_WIDTH, IMG_HEIGHT, &buf) == RES_OK); + OK(sdis_accum_buffer_create(dev, IMG_WIDTH, IMG_HEIGHT, &buf)); #if 0 dump_mesh(stdout, geom.positions, npos, geom.indices, ntris); @@ -611,19 +608,19 @@ main(int argc, char** argv) #endif /* Launch the simulation */ - CHK(sdis_solve_camera(scn, cam, INF, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, SPP, - sdis_accum_buffer_write, buf) == RES_OK); + OK(sdis_solve_camera(scn, cam, INF, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, SPP, + sdis_accum_buffer_write, buf)); /* Write the image */ dump_image(buf); /* Release memory */ - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_camera_ref_put(cam) == RES_OK); - CHK(sdis_interface_ref_put(interf0) == RES_OK); - CHK(sdis_interface_ref_put(interf1) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); - CHK(sdis_accum_buffer_ref_put(buf) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_camera_ref_put(cam)); + OK(sdis_interface_ref_put(interf0)); + OK(sdis_interface_ref_put(interf1)); + OK(sdis_device_ref_put(dev)); + OK(sdis_accum_buffer_ref_put(buf)); geometry_release(&geom); check_memory_allocator(&allocator); diff --git a/src/test_sdis_solve_probe.c b/src/test_sdis_solve_probe.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -174,6 +174,7 @@ main(int argc, char** argv) { struct mem_allocator allocator; struct sdis_mc T = SDIS_MC_NULL; + struct sdis_mc F = SDIS_MC_NULL; struct sdis_device* dev = NULL; struct sdis_medium* solid = NULL; struct sdis_medium* fluid = NULL; @@ -188,30 +189,30 @@ main(int argc, char** argv) struct fluid* fluid_param; struct solid* solid_param; struct interf* interface_param; + enum sdis_estimator_type type; double pos[3]; - double time; + double time_range[2]; double ref; const size_t N = 1000; size_t nreals; size_t nfails; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = 300; fluid_shader.temperature = fluid_get_temperature; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid)); + OK(sdis_data_ref_put(data)); /* Create the solid medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 1.0; solid_param->lambda = 0.1; @@ -223,12 +224,12 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; 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); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); /* Create the solid/fluid interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->hc = 0.5; interface_param->epsilon = 0; @@ -238,47 +239,65 @@ main(int argc, char** argv) interface_shader.back.temperature = NULL; interface_shader.back.emissivity = interface_get_emissivity; interface_shader.back.specular_fraction = interface_get_specular_fraction; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &interf) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &interf)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Create the scene */ ctx.positions = box_vertices; ctx.indices = box_indices; ctx.interf = interf; - CHK(sdis_scene_create(dev, box_ntriangles, get_indices, get_interface, - box_nvertices, get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_create(dev, box_ntriangles, get_indices, get_interface, + box_nvertices, get_position, &ctx, &scn)); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(sdis_interface_ref_put(interf)); /* Test the solver */ pos[0] = 0.5; pos[1] = 0.5; pos[2] = 0.5; - time = INF; - CHK(sdis_solve_probe(NULL, N, pos, time, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, 0, pos, time, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, N, NULL, time, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, N, pos, time, 0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, N, pos, time, 0, 0, -1, &estimator) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, N, pos, time, 1.0, 0, 0, NULL) == RES_BAD_ARG); - CHK(sdis_solve_probe(scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - - CHK(sdis_estimator_get_realisation_count(estimator, NULL) == RES_BAD_ARG); - CHK(sdis_estimator_get_realisation_count(NULL, &nreals) == RES_BAD_ARG); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - - CHK(sdis_estimator_get_failure_count(estimator, NULL) == RES_BAD_ARG); - CHK(sdis_estimator_get_failure_count(NULL, &nfails) == RES_BAD_ARG); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - - CHK(sdis_estimator_get_temperature(estimator, NULL) == RES_BAD_ARG); - CHK(sdis_estimator_get_temperature(NULL, &T) == RES_BAD_ARG); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + time_range[0] = time_range[1] = INF; + BA(sdis_solve_probe(NULL, N, pos, time_range, 1.0, 0, 0, &estimator)); + BA(sdis_solve_probe(scn, 0, pos, time_range, 1.0, 0, 0, &estimator)); + BA(sdis_solve_probe(scn, N, NULL, time_range, 1.0, 0, 0, &estimator)); + BA(sdis_solve_probe(scn, N, pos, time_range, 0, 0, 0, &estimator)); + BA(sdis_solve_probe(scn, N, pos, time_range, 0, 0, -1, &estimator)); + BA(sdis_solve_probe(scn, N, pos, time_range, 1.0, 0, 0, NULL)); + OK(sdis_solve_probe(scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + + BA(sdis_estimator_get_type(estimator, NULL)); + BA(sdis_estimator_get_type(NULL, &type)); + OK(sdis_estimator_get_type(estimator, &type)); + CHK(type == SDIS_TEMPERATURE_ESTIMATOR); + + /* Fluxes aren't available after sdis_solve_probe */ + BA(sdis_estimator_get_convective_flux(estimator, NULL)); + BA(sdis_estimator_get_convective_flux(NULL, &F)); + BA(sdis_estimator_get_convective_flux(estimator, &F)); + + BA(sdis_estimator_get_radiative_flux(estimator, NULL)); + BA(sdis_estimator_get_radiative_flux(NULL, &F)); + BA(sdis_estimator_get_radiative_flux(estimator, &F)); + + BA(sdis_estimator_get_total_flux(estimator, NULL)); + BA(sdis_estimator_get_total_flux(NULL, &F)); + BA(sdis_estimator_get_total_flux(estimator, &F)); + + BA(sdis_estimator_get_realisation_count(estimator, NULL)); + BA(sdis_estimator_get_realisation_count(NULL, &nreals)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + + BA(sdis_estimator_get_failure_count(estimator, NULL)); + BA(sdis_estimator_get_failure_count(NULL, &nfails)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + + BA(sdis_estimator_get_temperature(estimator, NULL)); + BA(sdis_estimator_get_temperature(NULL, &T)); + OK(sdis_estimator_get_temperature(estimator, &T)); ref = 300; printf("Temperature at (%g, %g, %g) = %g ~ %g +/- %g\n", @@ -289,14 +308,18 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, T.SE)); - CHK(sdis_estimator_ref_get(NULL) == RES_BAD_ARG); - CHK(sdis_estimator_ref_get(estimator) == RES_OK); - CHK(sdis_estimator_ref_put(NULL) == RES_BAD_ARG); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + BA(sdis_estimator_ref_get(NULL)); + OK(sdis_estimator_ref_get(estimator)); + BA(sdis_estimator_ref_put(NULL)); + OK(sdis_estimator_ref_put(estimator)); + OK(sdis_estimator_ref_put(estimator)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + /* The external fluid cannot have an unknown temperature */ + fluid_param->temperature = -1; + BA(sdis_solve_probe(scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe2.c b/src/test_sdis_solve_probe2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -162,20 +162,19 @@ main(int argc, char** argv) struct context ctx; struct interf* interface_param = NULL; double pos[3]; - double time; + double time_range[2] = { INF, INF }; double ref; const size_t N = 10000; size_t nreals; size_t nfails; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -183,37 +182,37 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Create the fluid/solid interface with no limit conidition */ interface_shader.convection_coef = null_interface_value; interface_shader.front = SDIS_INTERFACE_SIDE_SHADER_NULL; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &Tnone) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &Tnone)); /* Create the fluid/solid interface with a fixed temperature of 300K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 300; interface_shader.front.temperature = interface_get_temperature; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T300) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T300)); + OK(sdis_data_ref_put(data)); /* Create the fluid/solid interface with a fixed temperature of 350K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 350; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T350) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T350)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Setup the per primitive scene interfaces */ CHK(sizeof(interfaces)/sizeof(struct sdis_interface*) == box_ntriangles); @@ -228,23 +227,23 @@ main(int argc, char** argv) ctx.positions = box_vertices; ctx.indices = box_indices; ctx.interfaces = interfaces; - CHK(sdis_scene_create(dev, box_ntriangles, get_indices, get_interface, - box_nvertices, get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_create(dev, box_ntriangles, get_indices, get_interface, + box_nvertices, get_position, &ctx, &scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(Tnone) == RES_OK); - CHK(sdis_interface_ref_put(T300) == RES_OK); - CHK(sdis_interface_ref_put(T350) == RES_OK); + OK(sdis_interface_ref_put(Tnone)); + OK(sdis_interface_ref_put(T300)); + OK(sdis_interface_ref_put(T350)); /* Launch the solver */ pos[0] = 0.5; pos[1] = 0.5; pos[2] = 0.5; - time = INF; - CHK(sdis_solve_probe( scn, N, pos, time, 1.0, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + time_range[0] = time_range[1] = INF; + OK(sdis_solve_probe( scn, N, pos, time_range, 1.0, -1, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); /* Print the estimation results */ ref = 350 * pos[2] + (1-pos[2]) * 300; @@ -258,9 +257,9 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, 3*T.SE)); /* Release data */ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe2_2d.c b/src/test_sdis_solve_probe2_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -159,20 +159,19 @@ main(int argc, char** argv) struct context ctx; struct interf* interface_param = NULL; double pos[2]; - double time; + double time_range[2]; double ref; const size_t N = 10000; size_t nreals; size_t nfails; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -180,14 +179,14 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Create the fluid/solid interface with no limit conidition */ interface_shader.convection_coef = null_interface_value; interface_shader.front = SDIS_INTERFACE_SIDE_SHADER_NULL; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &Tnone) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &Tnone)); interface_shader.convection_coef = null_interface_value; interface_shader.front = SDIS_INTERFACE_SIDE_SHADER_NULL; @@ -195,26 +194,26 @@ main(int argc, char** argv) interface_shader.front.temperature = interface_get_temperature; /* Create the fluid/solid interface with a fixed temperature of 300K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 300; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T300) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T300)); + OK(sdis_data_ref_put(data)); /* Create the fluid/solid interface with a fixed temperature of 350K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 350; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T350) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T350)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Setup the per primitive scene interfaces */ CHK(sizeof(interfaces)/sizeof(struct sdis_interface*) == square_nsegments); @@ -227,22 +226,22 @@ main(int argc, char** argv) ctx.positions = square_vertices; ctx.indices = square_indices; ctx.interfaces = interfaces; - CHK(sdis_scene_2d_create(dev, square_nsegments, get_indices, get_interface, - square_nvertices, get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, square_nsegments, get_indices, get_interface, + square_nvertices, get_position, &ctx, &scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(Tnone) == RES_OK); - CHK(sdis_interface_ref_put(T300) == RES_OK); - CHK(sdis_interface_ref_put(T350) == RES_OK); + OK(sdis_interface_ref_put(Tnone)); + OK(sdis_interface_ref_put(T300)); + OK(sdis_interface_ref_put(T350)); /* Launch the solver */ pos[0] = 0.5; pos[1] = 0.5; - time = INF; - CHK(sdis_solve_probe( scn, N, pos, time, 1.0, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + time_range[0] = time_range[1] = INF; + OK(sdis_solve_probe( scn, N, pos, time_range, 1.0, -1, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); /* Print the estimation results */ ref = 350 * pos[0] + (1-pos[0]) * 300; @@ -256,9 +255,9 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, T.SE*2)); /* Release data */ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe3.c b/src/test_sdis_solve_probe3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -186,7 +186,7 @@ main(int argc, char** argv) struct context ctx = CONTEXT_NULL; struct interf* interface_param = NULL; double pos[3]; - double time; + double time_range[2]; double ref; const size_t N = 10000; size_t ntris; @@ -196,13 +196,12 @@ main(int argc, char** argv) size_t i; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -210,42 +209,42 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Create the fluid/solid interface with no limit conidition */ interface_shader.convection_coef = null_interface_value; interface_shader.front = SDIS_INTERFACE_SIDE_SHADER_NULL; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &Tnone) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &Tnone)); /* Create the fluid/solid interface with a fixed temperature of 300K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 300; interface_shader.front.temperature = interface_get_temperature; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T300) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T300)); + OK(sdis_data_ref_put(data)); /* Create the fluid/solid interface with a fixed temperature of 350K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 350; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T350) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T350)); + OK(sdis_data_ref_put(data)); /* Create the solid/solid interface */ interface_shader = SDIS_INTERFACE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, solid, &interface_shader, NULL, &solid_solid) == RES_OK); + OK(sdis_interface_create + (dev, solid, solid, &interface_shader, NULL, &solid_solid)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Register the box geometry */ FOR_EACH(i, 0, box_nvertices) { @@ -260,8 +259,8 @@ main(int argc, char** argv) } /* Setup a sphere at the center of the box */ - CHK(s3dut_create_sphere(&allocator, 0.25, 64, 32, &msh) == RES_OK); - CHK(s3dut_mesh_get_data(msh, &msh_data) == RES_OK); + OK(s3dut_create_sphere(&allocator, 0.25, 64, 32, &msh)); + OK(s3dut_mesh_get_data(msh, &msh_data)); FOR_EACH(i, 0, msh_data.nvertices) { sa_push(ctx.positions, msh_data.positions[i*3+0] + 0.5); sa_push(ctx.positions, msh_data.positions[i*3+1] + 0.5); @@ -272,7 +271,7 @@ main(int argc, char** argv) sa_push(ctx.indices, msh_data.indices[i*3+1] + box_nvertices); sa_push(ctx.indices, msh_data.indices[i*3+2] + box_nvertices); } - CHK(s3dut_mesh_ref_put(msh) == RES_OK); + OK(s3dut_mesh_ref_put(msh)); /* Create the scene */ ctx.solid_fluid_Tnone = Tnone; @@ -281,14 +280,14 @@ main(int argc, char** argv) ctx.solid_solid = solid_solid; nverts = sa_size(ctx.positions) / 3; ntris = sa_size(ctx.indices) / 3; - CHK(sdis_scene_create(dev, ntris, get_indices, get_interface, nverts, - get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_create(dev, ntris, get_indices, get_interface, nverts, + get_position, &ctx, &scn)); /* Release the scene data */ - CHK(sdis_interface_ref_put(Tnone) == RES_OK); - CHK(sdis_interface_ref_put(T300) == RES_OK); - CHK(sdis_interface_ref_put(T350) == RES_OK); - CHK(sdis_interface_ref_put(solid_solid) == RES_OK); + OK(sdis_interface_ref_put(Tnone)); + OK(sdis_interface_ref_put(T300)); + OK(sdis_interface_ref_put(T350)); + OK(sdis_interface_ref_put(solid_solid)); sa_release(ctx.positions); sa_release(ctx.indices); @@ -296,11 +295,11 @@ main(int argc, char** argv) pos[0] = 0.5; pos[1] = 0.5; pos[2] = 0.5; - time = INF; - CHK(sdis_solve_probe( scn, N, pos, time, 1.0, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + time_range[0] = time_range[1] = INF; + OK(sdis_solve_probe( scn, N, pos, time_range, 1.0, -1, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); /* Print the estimation results */ ref = 350 * pos[2] + (1-pos[2]) * 300; @@ -314,9 +313,9 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, 2*T.SE)); /* Release data */ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe3_2d.c b/src/test_sdis_solve_probe3_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -181,7 +181,7 @@ main(int argc, char** argv) struct context ctx = CONTEXT_NULL; struct interf* interface_param = NULL; double pos[2]; - double time; + double time_range[2]; double ref; const size_t N = 10000; size_t nsegs; @@ -191,13 +191,12 @@ main(int argc, char** argv) size_t i; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Create the solid medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -205,45 +204,45 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = temperature_unknown; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Create the fluid/solid interface with no limit conidition */ interface_shader = SDIS_INTERFACE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &Tnone) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &Tnone)); /* Create the fluid/solid interface with a fixed temperature of 300K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 300; interface_shader.convection_coef = null_interface_value; interface_shader.front.temperature = interface_get_temperature; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T300) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T300)); + OK(sdis_data_ref_put(data)); /* Create the fluid/solid interface with a fixed temperature of 350K */ - CHK(sdis_data_create(dev, sizeof(struct interf), - ALIGNOF(struct interf), NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), + ALIGNOF(struct interf), NULL, &data)); interface_param = sdis_data_get(data); interface_param->temperature = 350; interface_shader.convection_coef = null_interface_value; interface_shader.front.temperature = interface_get_temperature; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, data, &T350) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, data, &T350)); + OK(sdis_data_ref_put(data)); /* Create the solid/solid interface */ interface_shader = SDIS_INTERFACE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, solid, &interface_shader, NULL, &solid_solid) == RES_OK); + OK(sdis_interface_create + (dev, solid, solid, &interface_shader, NULL, &solid_solid)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Register the square geometry */ FOR_EACH(i, 0, square_nvertices) { @@ -275,25 +274,25 @@ main(int argc, char** argv) ctx.solid_solid = solid_solid; nverts = sa_size(ctx.positions) / 2; nsegs = sa_size(ctx.indices) / 2; - CHK(sdis_scene_2d_create(dev, nsegs, get_indices, get_interface, nverts, - get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegs, get_indices, get_interface, nverts, + get_position, &ctx, &scn)); /* Release the scene data */ - CHK(sdis_interface_ref_put(Tnone) == RES_OK); - CHK(sdis_interface_ref_put(T300) == RES_OK); - CHK(sdis_interface_ref_put(T350) == RES_OK); - CHK(sdis_interface_ref_put(solid_solid) == RES_OK); + OK(sdis_interface_ref_put(Tnone)); + OK(sdis_interface_ref_put(T300)); + OK(sdis_interface_ref_put(T350)); + OK(sdis_interface_ref_put(solid_solid)); sa_release(ctx.positions); sa_release(ctx.indices); /* Launch the solver */ pos[0] = 0.5; pos[1] = 0.5; - time = INF; - CHK(sdis_solve_probe( scn, N, pos, time, 1.0, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + time_range[0] = time_range[1] = INF; + OK(sdis_solve_probe( scn, N, pos, time_range, 1.0, -1, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); /* Print the estimation results */ ref = 350 * pos[0] + (1-pos[0]) * 300; @@ -307,9 +306,9 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, 3*T.SE)); /* Release data */ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe_2d.c b/src/test_sdis_solve_probe_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -67,12 +67,16 @@ get_interface(const size_t iseg, struct sdis_interface** bound, void* context) /******************************************************************************* * Media & interface ******************************************************************************/ +struct fluid { + double temperature; +}; + static double fluid_get_temperature (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - (void)vtx, (void)data; - return 300.0; + CHK(data != NULL && vtx != NULL); + return ((const struct fluid*)sdis_data_cget(data))->temperature; } static double @@ -136,26 +140,32 @@ main(int argc, char** argv) struct sdis_medium* fluid = NULL; struct sdis_interface* interf = NULL; struct sdis_scene* scn = NULL; + struct sdis_data* data = NULL; struct sdis_estimator* estimator = NULL; struct sdis_fluid_shader fluid_shader = DUMMY_FLUID_SHADER; struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; struct sdis_interface_shader interface_shader = DUMMY_INTERFACE_SHADER; struct context ctx; + struct fluid* fluid_param; double pos[2]; - double time; + double time_range[2] = { INF, INF }; double ref; const size_t N = 1000; size_t nreals; size_t nfails; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); + fluid_param = sdis_data_get(data); + fluid_param->temperature = 300; fluid_shader.temperature = fluid_get_temperature; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid)); + OK(sdis_data_ref_put(data)); /* Create the solid medium */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -163,37 +173,37 @@ main(int argc, char** argv) solid_shader.volumic_mass = solid_get_volumic_mass; solid_shader.delta_solid = solid_get_delta; solid_shader.temperature = solid_get_temperature; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, NULL, &solid)); /* Create the solid/fluid interface */ interface_shader.convection_coef = interface_get_convection_coef; interface_shader.front = SDIS_INTERFACE_SIDE_SHADER_NULL; interface_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - CHK(sdis_interface_create - (dev, solid, fluid, &interface_shader, NULL, &interf) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &interf)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid)); /* Create the scene */ ctx.positions = square_vertices; ctx.indices = square_indices; ctx.interf = interf; - CHK(sdis_scene_2d_create(dev, square_nsegments, get_indices, get_interface, - square_nvertices, get_position, &ctx, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, square_nsegments, get_indices, get_interface, + square_nvertices, get_position, &ctx, &scn)); - CHK(sdis_interface_ref_put(interf) == RES_OK); + OK(sdis_interface_ref_put(interf)); /* Test the solver */ pos[0] = 0.5; pos[1] = 0.5; - time = INF; - CHK(sdis_solve_probe(scn, N, pos, time, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + time_range[0] = time_range[1] = INF; + OK(sdis_solve_probe(scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); ref = 300; printf("Temperature at (%g, %g) = %g ~ %g +/- %g\n", @@ -204,10 +214,15 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, T.SE)); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); + + /* The external fluid cannot have an unknown temperature */ + fluid_param->temperature = -1; + + BA(sdis_solve_probe(scn, N, pos, time_range, 1.0, 0, 0, &estimator)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_solve_probe_boundary.c b/src/test_sdis_solve_probe_boundary.c @@ -1,305 +0,0 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (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> - -/* - * The scene is composed of a solid cube/square whose temperature is unknown. - * The convection coefficient with the surrounding fluid is null exepted for - * the +X face whose value is 'H'. The Temperature of the -X face is fixed to - * Tb. This test computes the temperature on the +X face and check that it is - * equal to: - * - * T = (H*Tf + LAMBDA/A * Tb) / (H+LAMBDA/A) - * - * with Tf the temperature of the surrounding fluid, lambda the conductivity of - * the cube and A the size of the cube/square, i.e. 1. - * - * 3D 2D - * - * ///// (1,1,1) ///// (1,1) - * +-------+ +-------+ - * /' /| _\ | | _\ - * +-------+ | / / Tf Tb | / / Tf - * Tb +.....|.+ \__/ | | \__/ - * |, |/ +-------+ - * +-------+ (0,0) ///// - * (0,0,0) ///// - */ - -#define UNKNOWN_TEMPERATURE -1 -#define N 10000 /* #realisations */ - -#define Tf 310 -#define Tb 300 -#define H 0.5 -#define LAMBDA 0.1 - -/******************************************************************************* - * Media - ******************************************************************************/ -static double -fluid_get_temperature - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return Tf; -} - -static double -solid_get_calorific_capacity - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return 2.0; -} - -static double -solid_get_thermal_conductivity - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return LAMBDA; -} - -static double -solid_get_volumic_mass - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return 25.0; -} - -static double -solid_get_delta - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return 1.0/20.0; -} - -static double -solid_get_temperature - (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) -{ - (void)data; - CHK(vtx != NULL); - return UNKNOWN_TEMPERATURE; -} - -/******************************************************************************* - * Interfaces - ******************************************************************************/ -struct interf { - double temperature; - double hc; -}; - -static double -interface_get_temperature - (const struct sdis_interface_fragment* frag, struct sdis_data* data) -{ - const struct interf* interf = sdis_data_cget(data); - CHK(frag && data); - return interf->temperature; -} - -static double -interface_get_convection_coef - (const struct sdis_interface_fragment* frag, struct sdis_data* data) -{ - const struct interf* interf = sdis_data_cget(data); - CHK(frag && data); - return interf->hc; -} - -/******************************************************************************* - * Test - ******************************************************************************/ -int -main(int argc, char** argv) -{ - struct mem_allocator allocator; - struct sdis_mc T = SDIS_MC_NULL; - struct sdis_data* data = NULL; - struct sdis_device* dev = NULL; - struct sdis_medium* fluid = NULL; - struct sdis_medium* solid = NULL; - struct sdis_interface* interf_adiabatic = NULL; - struct sdis_interface* interf_Tb = NULL; - struct sdis_interface* interf_H = NULL; - struct sdis_scene* box_scn = NULL; - struct sdis_scene* square_scn = NULL; - struct sdis_estimator* estimator = NULL; - struct sdis_fluid_shader fluid_shader = DUMMY_FLUID_SHADER; - struct sdis_solid_shader solid_shader = DUMMY_SOLID_SHADER; - struct sdis_interface_shader interf_shader = SDIS_INTERFACE_SHADER_NULL; - struct sdis_interface* box_interfaces[12 /*#triangles*/]; - struct sdis_interface* square_interfaces[4/*#segments*/]; - struct interf* interf_props = NULL; - double uv[2]; - double pos[3]; - double ref; - size_t iprim; - size_t nreals; - size_t nfails; - (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 fluid medium */ - fluid_shader.temperature = fluid_get_temperature; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); - - /* Create the solid_medium */ - 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.temperature = solid_get_temperature; - CHK(sdis_solid_create(dev, &solid_shader, NULL, &solid) == RES_OK); - - /* Setup the interface shader */ - interf_shader.convection_coef = interface_get_convection_coef; - interf_shader.front.temperature = interface_get_temperature; - interf_shader.front.emissivity = NULL; - interf_shader.front.specular_fraction = NULL; - interf_shader.back = SDIS_INTERFACE_SIDE_SHADER_NULL; - - /* Create the adiabatic interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); - interf_props = sdis_data_get(data); - interf_props->hc = 0; - interf_props->temperature = UNKNOWN_TEMPERATURE; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); - - /* Create the Tb interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); - interf_props = sdis_data_get(data); - interf_props->hc = 0; - interf_props->temperature = Tb; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_Tb) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); - - /* Create the H interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); - interf_props = sdis_data_get(data); - interf_props->hc = H; - interf_props->temperature = UNKNOWN_TEMPERATURE; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_H) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); - - /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); - - /* Map the interfaces to their box triangles */ - box_interfaces[0] = box_interfaces[1] = interf_adiabatic; /* Front */ - box_interfaces[2] = box_interfaces[3] = interf_Tb; /* Left */ - box_interfaces[4] = box_interfaces[5] = interf_adiabatic; /* Back */ - box_interfaces[6] = box_interfaces[7] = interf_H; /* Right */ - box_interfaces[8] = box_interfaces[9] = interf_adiabatic; /* Top */ - box_interfaces[10]= box_interfaces[11]= interf_adiabatic; /* Bottom */ - - /* Map the interfaces to their square segments */ - square_interfaces[0] = interf_adiabatic; /* Bottom */ - square_interfaces[1] = interf_Tb; /* Lef */ - square_interfaces[2] = interf_adiabatic; /* Top */ - square_interfaces[3] = interf_H; /* Right */ - - /* Create the box scene */ - CHK(sdis_scene_create(dev, box_ntriangles, box_get_indices, - box_get_interface, box_nvertices, box_get_position, box_interfaces, - &box_scn) == RES_OK); - - /* Create the square scene */ - CHK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, - square_get_interface, square_nvertices, square_get_position, - square_interfaces, &square_scn) == RES_OK); - - /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_Tb) == RES_OK); - CHK(sdis_interface_ref_put(interf_H) == RES_OK); - - uv[0] = 0.3; - uv[1] = 0.3; - iprim = 6; - - #define SOLVE sdis_solve_probe_boundary - #define F SDIS_FRONT - CHK(SOLVE(NULL, N, iprim, uv, INF, F, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, 0, iprim, uv, INF, F, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, 12, uv, INF, F, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, iprim, NULL, INF, F, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, iprim, uv, -1, F, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, iprim, uv, INF, -1, 1.0, 0, 0, &estimator) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, iprim, uv, INF, F, 1.0, 0, 0, NULL) == RES_BAD_ARG); - CHK(SOLVE(box_scn, N, iprim, uv, INF, F, 1.0, 0, 0, &estimator) == RES_OK); - - ref = (H*Tf + LAMBDA * Tb) / (H + LAMBDA); - - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_get_boundary_position(box_scn, iprim, uv, pos) == RES_OK); - printf("Boundary temperature of the box at (%g %g %g) = %g ~ %g +/- %g\n", - SPLIT3(pos), ref, T.E, T.SE); - printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); - CHK(nfails + nreals == N); - CHK(nfails < N/1000); - CHK(eq_eps(T.E, ref, 3*T.SE)); - - uv[0] = 0.5; - iprim = 3; - CHK(SOLVE(square_scn, N, iprim, uv, INF, F, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); - CHK(sdis_scene_get_boundary_position(square_scn, iprim, uv, pos) == RES_OK); - printf("Boundary temperature of the square at (%g %g) = %g ~ %g +/- %g\n", - SPLIT2(pos), ref, T.E, T.SE); - printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); - CHK(nfails + nreals == N); - CHK(nfails < N/1000); - CHK(eq_eps(T.E, ref, 3*T.SE)); - #undef SOLVE - - CHK(sdis_scene_ref_put(box_scn) == RES_OK); - CHK(sdis_scene_ref_put(square_scn) == 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_utils.h b/src/test_sdis_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -23,6 +23,9 @@ #define BOLTZMANN_CONSTANT 5.6696e-8 /* W/m^2/K^4 */ +#define OK(Cond) CHK((Cond) == RES_OK) +#define BA(Cond) CHK((Cond) == RES_BAD_ARG) + /******************************************************************************* * Box geometry ******************************************************************************/ @@ -165,13 +168,15 @@ static const struct sdis_solid_shader DUMMY_SOLID_SHADER = { dummy_medium_getter, dummy_medium_getter, dummy_medium_getter, - dummy_medium_getter + dummy_medium_getter, + 0 }; static const struct sdis_fluid_shader DUMMY_FLUID_SHADER = { dummy_medium_getter, dummy_medium_getter, - dummy_medium_getter + dummy_medium_getter, + 0 }; diff --git a/src/test_sdis_volumic_power.c b/src/test_sdis_volumic_power.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -170,18 +170,18 @@ main(int argc, char** argv) struct interf* interf_props = NULL; struct solid* solid_props = NULL; double pos[3]; + double time_range[2] = { INF, INF }; double x; double ref; size_t nreals; size_t nfails; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); fluid_shader.temperature = fluid_get_temperature; - CHK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid)); /* Setup the solid shader */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -192,48 +192,48 @@ main(int argc, char** argv) solid_shader.volumic_power = solid_get_volumic_power; /* Create the solid medium */ - CHK(sdis_data_create(dev, sizeof(struct solid), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct solid), 16, NULL, &data)); solid_props = sdis_data_get(data); solid_props->lambda = LAMBDA; solid_props->cp = 2; solid_props->rho = 25; solid_props->delta = DELTA; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); - CHK(sdis_data_create(dev, sizeof(struct solid), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct solid), 16, NULL, &data)); solid_props = sdis_data_get(data); solid_props->lambda = 0; solid_props->cp = 0; solid_props->rho = 0; solid_props->delta = DELTA/4; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; interf_shader.front.temperature = interface_get_temperature; /* Create the adiabatic interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = UNKNOWN_TEMPERATURE; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_adiabatic)); + OK(sdis_data_ref_put(data)); /* Create the T0 interface */ - CHK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data) == RES_OK); + OK(sdis_data_create(dev, sizeof(struct interf), 16, NULL, &data)); interf_props = sdis_data_get(data); interf_props->temperature = T0; - CHK(sdis_interface_create - (dev, solid, fluid, &interf_shader, data, &interf_T0) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create + (dev, solid, fluid, &interf_shader, data, &interf_T0)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); - CHK(sdis_medium_ref_put(fluid) == RES_OK); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(solid2)); + OK(sdis_medium_ref_put(fluid)); /* Map the interfaces to their box triangles */ box_interfaces[0] = box_interfaces[1] = interf_adiabatic; /* Front */ @@ -250,30 +250,30 @@ main(int argc, char** argv) square_interfaces[3] = interf_T0; /* Right */ /* Create the box scene */ - CHK(sdis_scene_create(dev, box_ntriangles, box_get_indices, + OK(sdis_scene_create(dev, box_ntriangles, box_get_indices, box_get_interface, box_nvertices, box_get_position, box_interfaces, - &box_scn) == RES_OK); + &box_scn)); /* Create the square scene */ - CHK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, + OK(sdis_scene_2d_create(dev, square_nsegments, square_get_indices, square_get_interface, square_nvertices, square_get_position, - square_interfaces, &square_scn) == RES_OK); + square_interfaces, &square_scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_T0) == RES_OK); + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_T0)); d3_splat(pos, 0.25); x = pos[0] - 0.5; ref = P0 / (2*LAMBDA) * (1.0/4.0 - x*x) + T0; /* Solve in 3D */ - CHK(sdis_solve_probe(box_scn, N, pos, INF, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(box_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); CHK(nfails + nreals == N); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf("Temperature of the box at (%g %g %g) = %g ~ %g +/- %g\n", SPLIT3(pos), ref, T.E, T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); @@ -282,11 +282,11 @@ main(int argc, char** argv) CHK(eq_eps(T.E, ref, 3*T.SE)); /* Solve in 2D */ - CHK(sdis_solve_probe(square_scn, N, pos, INF, 1.0, 0, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_solve_probe(square_scn, N, pos, time_range, 1.0, 0, 0, &estimator)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_ref_put(estimator)); printf("Temperature of the square at (%g %g) = %g ~ %g +/- %g\n", SPLIT2(pos), ref, T.E, T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); @@ -294,9 +294,9 @@ main(int argc, char** argv) CHK(nfails < N/1000); CHK(eq_eps(T.E, ref, 3*T.SE)); - CHK(sdis_scene_ref_put(box_scn) == RES_OK); - CHK(sdis_scene_ref_put(square_scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(box_scn)); + OK(sdis_scene_ref_put(square_scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_volumic_power2.c b/src/test_sdis_volumic_power2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -233,6 +233,7 @@ check(struct sdis_scene* scn, const struct reference refs[], const size_t nrefs) size_t nreals; size_t nfails; double pos[3] = {0,0}; + double time_range[2] = { INF, INF }; size_t i; FOR_EACH(i, 0, nrefs) { @@ -241,17 +242,17 @@ check(struct sdis_scene* scn, const struct reference refs[], const size_t nrefs) pos[1] = refs[i].pos[1]; pos[2] = refs[i].pos[2]; - CHK(sdis_solve_probe(scn, N, pos, INF, 1.f, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(scn, N, pos, time_range, 1.f, -1, 0, &estimator)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); Tc = T.E - 273.15; /* Convert in Celcius */ printf("Temperature at (%g %g %g) = %g ~ %g +/- %g [%g, %g]\n", SPLIT3(pos), refs[i].temperature_2d, Tc, T.SE, Tc-3*T.SE, Tc+3*T.SE); printf("#realisations: %lu; #failures: %lu\n", (unsigned long)nreals, (unsigned long)nfails); /*CHK(eq_eps(Tc, refs[i].temperature, T.SE*3));*/ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); } } @@ -298,9 +299,8 @@ main(int argc, char** argv) }; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Setup the fluid shader */ fluid_shader.temperature = fluid_get_temperature; @@ -308,20 +308,20 @@ main(int argc, char** argv) fluid_shader.volumic_mass = dummy_medium_getter; /* Create the fluid1 medium */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = 373.15; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1) ); + OK(sdis_data_ref_put(data)); /* Create the fluid2 medium */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = 273.15; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2)); + OK(sdis_data_ref_put(data)); /* Setup the solid shader */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -332,8 +332,8 @@ main(int argc, char** argv) solid_shader.volumic_power = solid_get_volumic_power; /* Create the solid1 medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) ); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -341,12 +341,12 @@ main(int argc, char** argv) solid_param->delta = DELTA; solid_param->P = SDIS_VOLUMIC_POWER_NONE; solid_param->T = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid1)); + OK(sdis_data_ref_put(data)); /* Create the solid2 medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -354,52 +354,52 @@ main(int argc, char** argv) solid_param->delta = DELTA_PSQUARE; solid_param->P = Pw; solid_param->T = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Create the solid1/solid2 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); - CHK(sdis_interface_create(dev, solid2, solid1, &SDIS_INTERFACE_SHADER_NULL, - NULL, &interf_solid1_solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); + OK(sdis_interface_create(dev, solid2, solid1, &SDIS_INTERFACE_SHADER_NULL, + NULL, &interf_solid1_solid2)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; /* Create the adiabatic interfaces */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 0; - CHK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, - &interf_solid1_adiabatic) == RES_OK); - CHK(sdis_interface_create(dev, solid2, fluid1, &interf_shader, data, - &interf_solid2_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, + &interf_solid1_adiabatic)); + OK(sdis_interface_create(dev, solid2, fluid1, &interf_shader, data, + &interf_solid2_adiabatic)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.front.temperature = interface_get_temperature; /* Create the solid1/fluid1 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 5; interf_param->temperature = NONE; - CHK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, - &interf_solid1_fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, + &interf_solid1_fluid1)); + OK(sdis_data_ref_put(data)); /* Create the solid1/fluid2 interace */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 10; interf_param->temperature = NONE; - CHK(sdis_interface_create(dev, solid1, fluid2, &interf_shader, data, - &interf_solid1_fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid2, &interf_shader, data, + &interf_solid1_fluid2)); + OK(sdis_data_ref_put(data)); /* Map the interfaces to their faces */ interfaces[0] = interf_solid1_adiabatic; @@ -422,8 +422,8 @@ main(int argc, char** argv) interfaces[17] = interf_solid2_adiabatic; /* Create the scene */ - CHK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); #if 0 dump_mesh(stdout, vertices, nvertices, indices, ntriangles); @@ -434,31 +434,31 @@ main(int argc, char** argv) check(scn, refs1, sizeof(refs1)/sizeof(struct reference)); /* Update the scene */ - CHK(sdis_scene_ref_put(scn) == RES_OK); + OK(sdis_scene_ref_put(scn)); data = sdis_medium_get_data(solid1); solid_param = sdis_data_get(data); solid_param->lambda = 0.1; - CHK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_create(dev, ntriangles, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); printf("\n>>> Check 2\n"); check(scn, refs2, sizeof(refs2)/sizeof(struct reference)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_solid1_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid2_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_fluid1) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_fluid2) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_solid2) == RES_OK); + OK(sdis_interface_ref_put(interf_solid1_adiabatic)); + OK(sdis_interface_ref_put(interf_solid2_adiabatic)); + OK(sdis_interface_ref_put(interf_solid1_fluid1)); + OK(sdis_interface_ref_put(interf_solid1_fluid2)); + OK(sdis_interface_ref_put(interf_solid1_solid2)); /* Release the media */ - CHK(sdis_medium_ref_put(fluid1) == RES_OK); - CHK(sdis_medium_ref_put(fluid2) == RES_OK); - CHK(sdis_medium_ref_put(solid1) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); + OK(sdis_medium_ref_put(fluid1)); + OK(sdis_medium_ref_put(fluid2)); + OK(sdis_medium_ref_put(solid1)); + OK(sdis_medium_ref_put(solid2)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_volumic_power2_2d.c b/src/test_sdis_volumic_power2_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -253,6 +253,7 @@ check(struct sdis_scene* scn, const struct reference refs[], const size_t nrefs) size_t nreals; size_t nfails; double pos[2] = {0,0}; + double time_range[2] = { INF, INF }; size_t i; FOR_EACH(i, 0, nrefs) { @@ -260,17 +261,17 @@ check(struct sdis_scene* scn, const struct reference refs[], const size_t nrefs) pos[0] = refs[i].pos[0]; pos[1] = refs[i].pos[1]; - CHK(sdis_solve_probe(scn, N, pos, INF, 1.f, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(scn, N, pos, time_range, 1.f, -1, 0, &estimator)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); Tc = T.E - 273.15; /* Convert in Celcius */ printf("Temperature at (%g %g) = %g ~ %g +/- %g [%g, %g]\n", SPLIT2(pos), refs[i].temperature, Tc, T.SE, Tc-3*T.SE, Tc+3*T.SE); printf("#realisations: %lu; #failures: %lu\n", (unsigned long)nreals, (unsigned long)nfails); /*CHK(eq_eps(Tc, refs[i].temperature, T.SE*3));*/ - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); } } @@ -329,9 +330,8 @@ main(int argc, char** argv) }; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Setup the fluid shader */ fluid_shader.temperature = fluid_get_temperature; @@ -339,20 +339,20 @@ main(int argc, char** argv) fluid_shader.volumic_mass = dummy_medium_getter; /* Create the fluid1 medium */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = 373.15; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1)); + OK(sdis_data_ref_put(data)); /* Create the fluid2 medium */ - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = 273.15; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2)); + OK(sdis_data_ref_put(data)); /* Setup the solid shader */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -363,8 +363,8 @@ main(int argc, char** argv) solid_shader.volumic_power = solid_get_volumic_power; /* Create the solid1 medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -372,12 +372,12 @@ main(int argc, char** argv) solid_param->delta = DELTA; solid_param->P = SDIS_VOLUMIC_POWER_NONE; solid_param->T = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid1)); + OK(sdis_data_ref_put(data)); /* Create the solid2 medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -385,50 +385,50 @@ main(int argc, char** argv) solid_param->delta = DELTA; solid_param->P = Pw; solid_param->T = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Create the solid1/solid2 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); - CHK(sdis_interface_create(dev, solid2, solid1, &SDIS_INTERFACE_SHADER_NULL, - NULL, &interf_solid1_solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); + OK(sdis_interface_create(dev, solid2, solid1, &SDIS_INTERFACE_SHADER_NULL, + NULL, &interf_solid1_solid2)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; /* Create the adiabatic interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 0; - CHK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, - &interf_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, + &interf_adiabatic)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.front.temperature = interface_get_temperature; /* Create the solid1/fluid1 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 5; interf_param->temperature = Tboundary1; - CHK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, - &interf_solid1_fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid1, &interf_shader, data, + &interf_solid1_fluid1)); + OK(sdis_data_ref_put(data)); /* Create the solid1/fluid2 interace */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 10; interf_param->temperature = Tboundary2; - CHK(sdis_interface_create(dev, solid1, fluid2, &interf_shader, data, - &interf_solid1_fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid2, &interf_shader, data, + &interf_solid1_fluid2)); + OK(sdis_data_ref_put(data)); /* Map the interfaces to their square segments */ @@ -442,25 +442,25 @@ main(int argc, char** argv) interfaces[7] = interf_solid1_solid2; /* Create the scene */ - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); printf(">>> Check 1\n"); check(scn, refs1, sizeof(refs1)/sizeof(struct reference)); /* Update the scene */ - CHK(sdis_scene_ref_put(scn) == RES_OK); + OK(sdis_scene_ref_put(scn)); data = sdis_medium_get_data(solid1); solid_param = sdis_data_get(data); solid_param->lambda = 0.1; - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, + nvertices, get_position, interfaces, &scn) ); printf("\n>>> Check 2\n"); check(scn, refs2, sizeof(refs2)/sizeof(struct reference)); /* Update the scene */ - CHK(sdis_scene_ref_put(scn) == RES_OK); + OK(sdis_scene_ref_put(scn)); data = sdis_medium_get_data(solid1); solid_param = sdis_data_get(data); solid_param->lambda = 1; @@ -468,8 +468,8 @@ main(int argc, char** argv) solid_param = sdis_data_get(data); solid_param->lambda = 10; solid_param->P = SDIS_VOLUMIC_POWER_NONE; - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); printf("\n>>> Check 3\n"); check(scn, refs3, sizeof(refs3)/sizeof(struct reference)); @@ -480,19 +480,19 @@ main(int argc, char** argv) #endif /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_fluid1) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_fluid2) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_solid2) == RES_OK); + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_solid1_fluid1)); + OK(sdis_interface_ref_put(interf_solid1_fluid2)); + OK(sdis_interface_ref_put(interf_solid1_solid2)); /* Release the media */ - CHK(sdis_medium_ref_put(fluid1) == RES_OK); - CHK(sdis_medium_ref_put(fluid2) == RES_OK); - CHK(sdis_medium_ref_put(solid1) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); + OK(sdis_medium_ref_put(fluid1)); + OK(sdis_medium_ref_put(fluid2)); + OK(sdis_medium_ref_put(solid1)); + OK(sdis_medium_ref_put(solid2)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_volumic_power3_2d.c b/src/test_sdis_volumic_power3_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -263,26 +263,26 @@ main(int argc, char** argv) struct sdis_interface* interfaces[10/*#segment*/]; struct sdis_mc T = SDIS_MC_NULL; double Tref; + double time_range[2] = { INF, INF }; double pos[2]; size_t nfails; size_t nreals; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = fluid_get_temperature; fluid_shader.calorific_capacity = dummy_medium_getter; fluid_shader.volumic_mass = dummy_medium_getter; - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature_upper = T1; fluid_param->temperature_lower = T2; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid)); + OK(sdis_data_ref_put(data)); /* Setup the solid shader */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -293,8 +293,8 @@ main(int argc, char** argv) solid_shader.volumic_power = solid_get_volumic_power; /* Create the medium of the upper slab */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -302,12 +302,12 @@ main(int argc, char** argv) solid_param->delta = DELTA1; solid_param->volumic_power = SDIS_VOLUMIC_POWER_NONE; solid_param->temperature = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid1)); + OK(sdis_data_ref_put(data)); /* Create the medium of the lower slab */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -315,12 +315,12 @@ main(int argc, char** argv) solid_param->delta = DELTA2; solid_param->volumic_power = SDIS_VOLUMIC_POWER_NONE; solid_param->temperature = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid2)); + OK(sdis_data_ref_put(data)); /* Create the medium of the middle slab */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -328,72 +328,72 @@ main(int argc, char** argv) solid_param->delta = DELTA; solid_param->volumic_power = Pw; solid_param->temperature = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); interf_shader.front.temperature = interface_get_temperature; /* Create the solid/solid1 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->temperature = Tsolid_solid1; - CHK(sdis_interface_create(dev, solid, solid1, &interf_shader, - data, &interf_solid_solid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, solid1, &interf_shader, + data, &interf_solid_solid1)); + OK(sdis_data_ref_put(data)); /* Create the solid/solid2 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->temperature = Tsolid_solid2; - CHK(sdis_interface_create(dev, solid, solid2, &interf_shader, - data, &interf_solid_solid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, solid2, &interf_shader, + data, &interf_solid_solid2)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; interf_shader.front.temperature = interface_get_temperature; /* Create the adiabatic interfaces */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 0; interf_param->temperature = -1; - CHK(sdis_interface_create(dev, solid, fluid, &interf_shader, data, - &interf_solid_adiabatic) == RES_OK); - CHK(sdis_interface_create(dev, solid1, fluid, &interf_shader, data, - &interf_solid1_adiabatic) == RES_OK); - CHK(sdis_interface_create(dev, solid2, fluid, &interf_shader, data, - &interf_solid2_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, fluid, &interf_shader, data, + &interf_solid_adiabatic)); + OK(sdis_interface_create(dev, solid1, fluid, &interf_shader, data, + &interf_solid1_adiabatic)); + OK(sdis_interface_create(dev, solid2, fluid, &interf_shader, data, + &interf_solid2_adiabatic) ); + OK(sdis_data_ref_put(data)); /* Create the solid1 fluid interace */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = H1; interf_param->temperature = Tsolid1_fluid; - CHK(sdis_interface_create(dev, solid1, fluid, &interf_shader, data, - &interf_solid1_fluid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid1, fluid, &interf_shader, data, + &interf_solid1_fluid)); + OK(sdis_data_ref_put(data)); /* Create the solid2 fluid interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = H2; interf_param->temperature = Tsolid2_fluid; - CHK(sdis_interface_create(dev, solid2, fluid, &interf_shader, data, - &interf_solid2_fluid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid2, fluid, &interf_shader, data, + &interf_solid2_fluid)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(fluid) == RES_OK); - CHK(sdis_medium_ref_put(solid) == RES_OK); - CHK(sdis_medium_ref_put(solid1) == RES_OK); - CHK(sdis_medium_ref_put(solid2) == RES_OK); + OK(sdis_medium_ref_put(fluid)); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(solid1)); + OK(sdis_medium_ref_put(solid2)); /* Map the interfaces to their square segments */ interfaces[0] = interf_solid2_adiabatic; @@ -413,17 +413,17 @@ main(int argc, char** argv) #endif /* Create the scene */ - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_solid_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid2_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid_solid1) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid_solid2) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid1_fluid) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid2_fluid) == RES_OK); + OK(sdis_interface_ref_put(interf_solid_adiabatic)); + OK(sdis_interface_ref_put(interf_solid1_adiabatic)); + OK(sdis_interface_ref_put(interf_solid2_adiabatic)); + OK(sdis_interface_ref_put(interf_solid_solid1)); + OK(sdis_interface_ref_put(interf_solid_solid2)); + OK(sdis_interface_ref_put(interf_solid1_fluid)); + OK(sdis_interface_ref_put(interf_solid2_fluid)); pos[0] = 0; pos[1] = PROBE_POS; @@ -441,21 +441,21 @@ main(int argc, char** argv) FATAL("Unreachable code.\n"); } - CHK(sdis_solve_probe(scn, N, pos, INF, 1.f, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); + OK(sdis_solve_probe(scn, N, pos, time_range, 1.f, -1, 0, &estimator)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); printf("Temperature at (%g %g) = %g ~ %g +/- %g [%g, %g]\n", SPLIT2(pos), Tref, T.E, T.SE, T.E-3*T.SE, T.E+3*T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); CHK(nfails + nreals == N); CHK(nfails < N/1000); CHK(eq_eps(T.E, Tref, T.SE*3)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sdis_volumic_power4_2d.c b/src/test_sdis_volumic_power4_2d.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2016-2019 |Meso|Star> (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 @@ -221,33 +221,33 @@ main(int argc, char** argv) struct sdis_mc T = SDIS_MC_NULL; size_t nreals, nfails; double pos[2]; + double time_range[2] = { INF, INF }; double Tref; double a, b, x; double L; (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); + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 1, &dev)); /* Create the fluid medium */ fluid_shader.temperature = fluid_get_temperature; fluid_shader.calorific_capacity = dummy_medium_getter; fluid_shader.volumic_mass = dummy_medium_getter; - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = Tf1; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid1)); + OK(sdis_data_ref_put(data)); - CHK(sdis_data_create - (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); fluid_param = sdis_data_get(data); fluid_param->temperature = Tf2; - CHK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_fluid_create(dev, &fluid_shader, data, &fluid2)); + OK(sdis_data_ref_put(data)); /* Setup the solid shader */ solid_shader.calorific_capacity = solid_get_calorific_capacity; @@ -258,8 +258,8 @@ main(int argc, char** argv) solid_shader.volumic_power = solid_get_volumic_power; /* Create the solid medium */ - CHK(sdis_data_create - (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data) == RES_OK); + OK(sdis_data_create + (dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); solid_param = sdis_data_get(data); solid_param->cp = 500000; solid_param->rho = 1000; @@ -267,47 +267,47 @@ main(int argc, char** argv) solid_param->delta = DELTA; solid_param->volumic_power = Power; solid_param->temperature = -1; - CHK(sdis_solid_create(dev, &solid_shader, data, &solid) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_solid_create(dev, &solid_shader, data, &solid)); + OK(sdis_data_ref_put(data)); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; interf_shader.front.temperature = interface_get_temperature; /* Create the adiabatic interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = 0; interf_param->temperature = -1; - CHK(sdis_interface_create(dev, solid, fluid1, &interf_shader, data, - &interf_adiabatic) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, fluid1, &interf_shader, data, + &interf_adiabatic)); + OK(sdis_data_ref_put(data)); /* Create the solid fluid1 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = H1; interf_param->temperature = -1; - CHK(sdis_interface_create(dev, solid, fluid1, &interf_shader, data, - &interf_solid_fluid1) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, fluid1, &interf_shader, data, + &interf_solid_fluid1)); + OK(sdis_data_ref_put(data)); /* Create the solid fluid2 interface */ - CHK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), - NULL, &data) == RES_OK); + OK(sdis_data_create (dev, sizeof(struct interf), ALIGNOF(struct interf), + NULL, &data)); interf_param = sdis_data_get(data); interf_param->h = H2; interf_param->temperature = -1; - CHK(sdis_interface_create(dev, solid, fluid2, &interf_shader, data, - &interf_solid_fluid2) == RES_OK); - CHK(sdis_data_ref_put(data) == RES_OK); + OK(sdis_interface_create(dev, solid, fluid2, &interf_shader, data, + &interf_solid_fluid2)); + OK(sdis_data_ref_put(data)); /* Release the media */ - CHK(sdis_medium_ref_put(fluid1) == RES_OK); - CHK(sdis_medium_ref_put(fluid2) == RES_OK); - CHK(sdis_medium_ref_put(solid) == RES_OK); + OK(sdis_medium_ref_put(fluid1)); + OK(sdis_medium_ref_put(fluid2)); + OK(sdis_medium_ref_put(solid)); /* Map the interfaces to their square segments */ interfaces[0] = interf_adiabatic; @@ -321,13 +321,13 @@ main(int argc, char** argv) #endif /* Create the scene */ - CHK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, - nvertices, get_position, interfaces, &scn) == RES_OK); + OK(sdis_scene_2d_create(dev, nsegments, get_indices, get_interface, + nvertices, get_position, interfaces, &scn)); /* Release the interfaces */ - CHK(sdis_interface_ref_put(interf_adiabatic) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid_fluid1) == RES_OK); - CHK(sdis_interface_ref_put(interf_solid_fluid2) == RES_OK); + OK(sdis_interface_ref_put(interf_adiabatic)); + OK(sdis_interface_ref_put(interf_solid_fluid1)); + OK(sdis_interface_ref_put(interf_solid_fluid2)); pos[0] = 0; pos[1] = 0.25; @@ -348,20 +348,20 @@ main(int argc, char** argv) Tref = T2 + (T1-T2)/L * (pos[1] + vertices[3]); #endif - CHK(sdis_solve_probe(scn, N, pos, INF, 1.f, -1, 0, &estimator) == RES_OK); - CHK(sdis_estimator_get_temperature(estimator, &T) == RES_OK); - CHK(sdis_estimator_get_realisation_count(estimator, &nreals) == RES_OK); - CHK(sdis_estimator_get_failure_count(estimator, &nfails) == RES_OK); + OK(sdis_solve_probe(scn, N, pos, time_range, 1.f, -1, 0, &estimator)); + OK(sdis_estimator_get_temperature(estimator, &T)); + OK(sdis_estimator_get_realisation_count(estimator, &nreals)); + OK(sdis_estimator_get_failure_count(estimator, &nfails)); printf("Temperature at (%g %g) = %g ~ %g +/- %g [%g %g]\n", SPLIT2(pos), Tref, T.E, T.SE, T.E-3*T.SE, T.E+3*T.SE); printf("#failures = %lu/%lu\n", (unsigned long)nfails, (unsigned long)N); - CHK(sdis_estimator_ref_put(estimator) == RES_OK); + OK(sdis_estimator_ref_put(estimator)); CHK(nfails + nreals == N); CHK(nfails < N/1000); CHK(eq_eps(T.E, Tref, T.SE*3)); - CHK(sdis_scene_ref_put(scn) == RES_OK); - CHK(sdis_device_ref_put(dev) == RES_OK); + OK(sdis_scene_ref_put(scn)); + OK(sdis_device_ref_put(dev)); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator);