star-uvm

Spatial structuring of unstructured volumetric meshes
git clone git://git.meso-star.fr/star-uvm.git
Log | Files | Refs | README | LICENSE

commit 6150aac6e30cd6d456cb5ee8bd8f6b7b2cd0ca64
parent 660741337dce874990e602570dda88832537bbcb
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 24 Sep 2020 16:35:40 +0200

Test the suvm_tetrahedral_mesh_create function

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/suvm_device.c | 2+-
Msrc/suvm_volume.c | 4++--
Asrc/test_suvm_volume.c | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -88,6 +88,7 @@ if(NOT NO_TEST) endfunction() new_test(test_suvm_device) + new_test(test_suvm_volume) endif() ################################################################################ diff --git a/src/suvm_device.c b/src/suvm_device.c @@ -44,7 +44,7 @@ device_release(ref_T* ref) struct suvm_device* dev; ASSERT(ref); dev = CONTAINER_OF(ref, struct suvm_device, ref); - rtcReleaseDevice(dev->rtc); + if(dev->rtc) rtcReleaseDevice(dev->rtc); MEM_RM(dev->allocator, dev); } diff --git a/src/suvm_volume.c b/src/suvm_volume.c @@ -351,8 +351,8 @@ build_bvh(struct suvm_volume* vol) prim->lower_y = (float)low[1]; prim->lower_z = (float)low[2]; prim->upper_x = (float)upp[0]; - prim->upper_x = (float)upp[1]; - prim->upper_x = (float)upp[2]; + prim->upper_y = (float)upp[1]; + prim->upper_z = (float)upp[2]; prim->geomID = 0; prim->primID = (unsigned int)iprim; } diff --git a/src/test_suvm_volume.c b/src/test_suvm_volume.c @@ -0,0 +1,130 @@ +/* Copyright (C) 2020 |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 "suvm.h" +#include "test_suvm_utils.h" + +static const double box_vertices[9/*#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, + 0.5, 0.5, 0.5 +}; +static const size_t box_nverts = sizeof(box_vertices) / sizeof(double[3]); + +/* The following array lists the indices toward the 3D vertices of each + * boundary triangle. The index 8 references the vertex at the center of the + * box. + * ,2---,3 ,2----3 + * ,' | ,'/| ,'/| \ | Y + * 6----7' / | 6' / | \ | | + * |', | / ,1 | / ,0---,1 o--X + * | ',|/,' |/,' | ,' / + * 4----5' 4----5' Z */ +static const size_t box_indices[12/*#tetras*/*4/*#indices per tetra*/] = { + 0, 1, 2, 8, 1, 3, 2, 8, /* -Z */ + 0, 2, 4, 8, 2, 6, 4, 8, /* -X */ + 4, 6, 5, 8, 6, 7, 5, 8, /* +Z */ + 3, 5, 7, 8, 5, 3, 1, 8, /* +X */ + 2, 7, 6, 8, 7, 2, 3, 8, /* +Y */ + 0, 5, 1, 8, 5, 0, 4, 8 /* -Y */ +}; +static const size_t box_ntetras = sizeof(box_indices) / sizeof(size_t[4]); + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +get_indices(const size_t itetra, size_t ids[4], void* ctx) +{ + (void)ctx; + CHK(itetra < box_ntetras); + CHK(ids != NULL); + ids[0] = box_indices[itetra*4+0]; + ids[1] = box_indices[itetra*4+1]; + ids[2] = box_indices[itetra*4+2]; + ids[3] = box_indices[itetra*4+3]; +} + +static void +get_position(const size_t ivert, double pos[3], void* ctx) +{ + (void)ctx; + CHK(ivert < box_nverts); + CHK(pos != NULL); + pos[0] = box_vertices[ivert*3+0]; + pos[1] = box_vertices[ivert*3+1]; + pos[2] = box_vertices[ivert*3+2]; +} + +/******************************************************************************* + * Main function + ******************************************************************************/ +int +main(int argc, char** argv) +{ + struct suvm_tetrahedral_mesh_args args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL; + struct suvm_device* dev = NULL; + struct suvm_volume* vol = NULL; + (void)argc, (void)argv; + + CHK(suvm_device_create(NULL, &mem_default_allocator, 1, &dev) == RES_OK); + + args.ntetrahedras = box_ntetras; + args.nvertices = box_nverts; + args.get_indices = get_indices; + args.get_position = get_position; + args.tetrahedra_data = SUVM_DATA_NULL; + args.vertex_data = SUVM_DATA_NULL; + args.context = NULL; + + CHK(suvm_tetrahedral_mesh_create(NULL, &args, &vol) == RES_BAD_ARG); + CHK(suvm_tetrahedral_mesh_create(dev, NULL, &vol) == RES_BAD_ARG); + CHK(suvm_tetrahedral_mesh_create(dev, &args, NULL) == RES_BAD_ARG); + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK); + + CHK(suvm_volume_ref_get(NULL) == RES_BAD_ARG); + CHK(suvm_volume_ref_get(vol) == RES_OK); + CHK(suvm_volume_ref_put(NULL) == RES_BAD_ARG); + CHK(suvm_volume_ref_put(vol) == RES_OK); + CHK(suvm_volume_ref_put(vol) == RES_OK); + + args.ntetrahedras = 0; + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_BAD_ARG); + args.ntetrahedras = box_ntetras; + args.nvertices = 0; + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_BAD_ARG); + args.nvertices = box_nverts; + args.get_indices = NULL; + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_BAD_ARG); + args.get_indices = get_indices; + args.get_position = NULL; + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_BAD_ARG); + args.get_position = get_position;; + CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK); + + CHK(suvm_volume_ref_put(vol) == RES_OK); + CHK(suvm_device_ref_put(dev) == RES_OK); + + check_memory_allocator(&mem_default_allocator); + CHK(mem_allocated_size() == 0); + return 0; +} +