stardis-solver

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

commit 15801166fc6a68cb84aee94130414ac0b9d804e6
parent 6b4e40829ff8bad5fd8a1c85e191c37cd931dc90
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 19 Dec 2017 11:11:03 +0100

Test the scene API

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/sdis_scene.c | 14++++++++------
Asrc/test_sdis_scene.c | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sdis_utils.h | 41+++++++++++++++++++++++++++++++++++++++++
4 files changed, 170 insertions(+), 6 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -105,6 +105,7 @@ if(NOT NO_TEST) new_test(test_sdis_device) new_test(test_sdis_interface) new_test(test_sdis_medium) + new_test(test_sdis_scene) endif() ################################################################################ diff --git a/src/sdis_scene.c b/src/sdis_scene.c @@ -23,7 +23,7 @@ #include <limits.h> -/* Context used to wrap the user geometry to Star-3D */ +/* Context used to wrap the user geometry to Star-3D. */ struct geometry_context { void (*indices)(const size_t itri, size_t ids[3], void*); void (*position)(const size_t ivert, double pos[3], void*); @@ -87,8 +87,9 @@ clear_interfaces(struct sdis_scene* scn) size_t i; ASSERT(scn); FOR_EACH(i, 0, darray_interface_size_get(&scn->interfaces)) { - if(!darray_interface_cdata_get(&scn->interfaces)[i]) continue; - SDIS(interface_ref_put(darray_interface_data_get(&scn->interfaces)[i])); + if(darray_interface_cdata_get(&scn->interfaces)[i]) { + SDIS(interface_ref_put(darray_interface_data_get(&scn->interfaces)[i])); + } } darray_interface_clear(&scn->interfaces); darray_interface_clear(&scn->prim_interfaces); @@ -200,6 +201,7 @@ scene_release(ref_T * ref) clear_interfaces(scn); darray_interface_release(&scn->interfaces); darray_interface_release(&scn->prim_interfaces); + if(scn->s3d_view) S3D(scene_view_ref_put(scn->s3d_view)); MEM_RM(dev->allocator, scn); SDIS(device_ref_put(dev)); } @@ -221,7 +223,7 @@ sdis_scene_create struct sdis_scene* scn = NULL; res_T res = RES_OK; - if(!dev || !out_scn || !scn || !ntris || !indices || !interface || nverts + if(!dev || !out_scn || !ntris || !indices || !interface || !nverts || !position || ntris > UINT_MAX || nverts > UINT_MAX) { res = RES_BAD_ARG; goto error; @@ -265,7 +267,7 @@ error: res_T sdis_scene_ref_get(struct sdis_scene* scn) { - if(scn) return RES_BAD_ARG; + if(!scn) return RES_BAD_ARG; ref_get(&scn->ref); return RES_OK; } @@ -273,7 +275,7 @@ sdis_scene_ref_get(struct sdis_scene* scn) res_T sdis_scene_ref_put(struct sdis_scene* scn) { - if(scn) return RES_BAD_ARG; + if(!scn) return RES_BAD_ARG; ref_put(&scn->ref, scene_release); return RES_OK; } diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c @@ -0,0 +1,120 @@ +/* Copyright (C) |Meso|Star> 2016-2017 (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" + +struct context { + const double* positions; + const size_t* indices; + struct sdis_interface* interface; +}; + +static INLINE void +get_indices(const size_t itri, size_t ids[3], void* context) +{ + struct context* ctx = context; + CHK(ctx != NULL); + CHK(itri < box_ntriangles); + ids[0] = ctx->indices[itri*3+0]; + ids[1] = ctx->indices[itri*3+1]; + ids[2] = ctx->indices[itri*3+2]; +} + +static INLINE void +get_position(const size_t ivert, double pos[3], void* context) +{ + struct context* ctx = context; + CHK(ctx != NULL); + CHK(ivert < box_nvertices); + pos[0] = ctx->positions[ivert*3+0]; + pos[1] = ctx->positions[ivert*3+1]; + pos[2] = ctx->positions[ivert*3+2]; +} + +static INLINE void +get_interface(const size_t itri, struct sdis_interface** bound, void* context) +{ + struct context* ctx = context; + CHK(ctx != NULL); + CHK(itri < box_ntriangles); + CHK(bound != NULL); + *bound = ctx->interface; +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sdis_device* dev = NULL; + struct sdis_medium* solid = NULL; + struct sdis_medium* fluid = NULL; + struct sdis_interface* interface = NULL; + struct sdis_scene* scn = 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; + size_t ntris, npos; + (void)argc, (void)argv; + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + CHK(sdis_device_create(NULL, &allocator, 1, 0, &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); + CHK(sdis_interface_create + (dev, solid, fluid, &interface_shader, NULL, &interface) == RES_OK); + + ctx.positions = box_vertices; + ctx.indices = box_indices; + ctx.interface = interface; + ntris = box_ntriangles; + npos = box_nvertices; + + #define CREATE sdis_scene_create + #define IDS get_indices + #define POS get_position + #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); + + 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); + + #undef CREATE + #undef IDS + #undef POS + #undef ITFACE + + CHK(sdis_device_ref_put(dev) == RES_OK); + CHK(sdis_interface_ref_put(interface) == RES_OK); + CHK(sdis_medium_ref_put(solid) == RES_OK); + CHK(sdis_medium_ref_put(fluid) == 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 @@ -19,6 +19,44 @@ #include <rsys/mem_allocator.h> #include <stdio.h> +/******************************************************************************* + * Geometry + ******************************************************************************/ +static const double box_vertices[8/*#vertices*/*3/*#coords per vertex*/] = { + 0.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 1.0, 1.0, 0.0, + 0.0, 0.0, 1.0, + 1.0, 0.0, 1.0, + 0.0, 1.0, 1.0, + 1.0, 1.0, 1.0 +}; +static const size_t box_nvertices = sizeof(box_vertices) / sizeof(double[3]); + +/* The following array lists the indices toward the 3D vertices of each + * triangle. + * ,6---,7 ,6----7 + * ,' | ,'/| ,' | \ | + * 2----3' / | 2', | \ | + * |', | / ,5 | ',4---,5 + * | ',|/,' | ,' | ,' + * 0----1' 0----1' + * Front, right Back, left and + * and Top faces bottom faces */ +static const size_t box_indices[12/*#triangles*/*3/*#indices per triangle*/] = { + 0, 2, 1, 1, 2, 3, /* Front face */ + 0, 4, 2, 2, 4, 6, /* Left face*/ + 4, 5, 6, 6, 5, 7, /* Back face */ + 3, 7, 1, 1, 7, 5, /* Right face */ + 2, 6, 3, 3, 6, 7, /* Top face */ + 0, 1, 4, 4, 1, 5 /* Bottom face */ +}; +static const size_t box_ntriangles = sizeof(box_indices) / sizeof(size_t[3]); + +/******************************************************************************* + * Medium & interface + ******************************************************************************/ static INLINE void dummy_medium_getter (struct sdis_device* dev, @@ -63,6 +101,9 @@ static const struct sdis_interface_shader DUMMY_INTERFACE_SHADER = { dummy_interface_getter }; +/******************************************************************************* + * Miscellaneous + ******************************************************************************/ static INLINE void check_memory_allocator(struct mem_allocator* allocator) {