commit 069779bdcec8d9f59b8225db3e7a26ca20c6b0e4
parent e677c1b08e99c43e03170ec4a59ccf95464eeb02
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 8 Dec 2020 08:58:58 +0100
Use Star-UVM to structure the volumetric mesh
Diffstat:
5 files changed, 133 insertions(+), 9 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -50,7 +50,8 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(ATRSTM_FILES_SRC
atrstm.c
- atrstm_log.c)
+ atrstm_log.c
+ atrstm_setup_uvm.c)
set(ATRSTM_FILES_INC
atrstm_c.h
atrstm_log.h)
diff --git a/src/atrstm.c b/src/atrstm.c
@@ -20,7 +20,6 @@
#include <astoria/atrtp.h>
#include <rsys/mem_allocator.h>
-#include <star/sth.h>
#include <star/suvm.h>
#include <omp.h>
@@ -52,8 +51,8 @@ release_atrstm(ref_T* ref)
struct atrstm* atrstm;
ASSERT(ref);
atrstm = CONTAINER_OF(ref, struct atrstm, ref);
- if(atrstm->sth) STH(ref_put(atrstm->sth));
if(atrstm->atrtp) ATRTP(ref_put(atrstm->atrtp));
+ if(atrstm->suvm) SUVM(device_ref_put(atrstm->suvm));
if(atrstm->logger == &atrstm->logger__) logger_release(&atrstm->logger__);
str_release(&atrstm->name);
MEM_RM(atrstm->allocator, atrstm);
@@ -123,11 +122,13 @@ atrstm_create
goto error;
}
- /* Load the volumetric mesh */
- res = sth_create
- (atrstm->logger, atrstm->allocator, atrstm->verbose, &atrstm->sth);
+ res = suvm_device_create
+ (atrstm->logger, atrstm->allocator, atrstm->verbose, &atrstm->suvm);
if(res != RES_OK) goto error;
- res = sth_load(atrstm->sth, args->sth_filename);
+
+ /* Structure the volumetric mesh */
+ res = setup_unstructured_volumetric_mesh
+ (atrstm, args->precompute_normals, args->sth_filename, &atrstm->volume);
if(res != RES_OK) goto error;
/* Load the thermodynamic properties of the volumetric mesh */
diff --git a/src/atrstm.h b/src/atrstm.h
@@ -54,6 +54,7 @@ struct atrstm_args {
double wlen_range[2]; /* Spectral range to handle In nm */
unsigned grid_max_definition[3]; /* Maximum definition of the grid */
double optical_thickness; /* Threshold used during octree building */
+ int precompute_normals; /* Pre-compute the Tetrahedron normals */
unsigned nthreads; /* Hint on the number of threads to use */
int verbose; /* Verbosity level */
};
@@ -68,6 +69,7 @@ struct atrstm_args {
{DBL_MAX,-DBL_MAX}, /* Spectral integration range */ \
{UINT_MAX, UINT_MAX, UINT_MAX}, /* Acceleration grid max definition */ \
1, /* Optical thickness */ \
+ 1, /* Precompute tetrahedron normals */ \
(unsigned)~0, /* #threads */ \
0 /* Verbosity level */ \
}
diff --git a/src/atrstm_c.h b/src/atrstm_c.h
@@ -23,11 +23,14 @@
/* Forward declaration of external data types */
struct atrtp;
struct mem_allocator;
-struct sth;
+struct suvm;
struct atrstm {
struct atrtp* atrtp; /* Handle toward the Astoria Thermodynamic properties */
- struct sth* sth; /* Handle toward Star-TetraHedra */
+
+ /* Unstructured volumetric mesh */
+ struct suvm_device* suvm;
+ struct suvm_volume* volume;
unsigned nthreads; /* #nthreads */
@@ -40,4 +43,11 @@ struct atrstm {
ref_T ref;
};
+extern LOCAL_SYM res_T
+setup_unstructured_volumetric_mesh
+ (struct atrstm* atrstm,
+ const int precompute_normals,
+ const char* sth_filename,
+ struct suvm_volume** out_volume);
+
#endif /* ATRSTM_C_H */
diff --git a/src/atrstm_setup_uvm.c b/src/atrstm_setup_uvm.c
@@ -0,0 +1,110 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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 "atrstm_c.h"
+#include "atrstm_log.h"
+
+#include <star/sth.h>
+#include <star/suvm.h>
+
+#include <rsys/clock_time.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static INLINE void
+tetrahedron_get_indices(const size_t itetra, size_t ids[4], void* ctx)
+{
+ const struct sth_desc* sth_desc = ctx;
+ const uint64_t* indices = NULL;
+ ASSERT(ctx && ids && itetra < sth_desc->ntetrahedra);
+ indices = sth_desc_get_tetrahedron_indices(sth_desc, itetra);
+ ids[0] = (size_t)indices[0];
+ ids[1] = (size_t)indices[1];
+ ids[2] = (size_t)indices[2];
+ ids[3] = (size_t)indices[3];
+}
+
+static INLINE void
+vertex_get_position(const size_t ivert, double pos[3], void* ctx)
+{
+ struct sth_desc* sth_desc = ctx;
+ const double* position = NULL;
+ ASSERT(ctx && pos && ivert < sth_desc->nvertices);
+ position = sth_desc_get_vertex_position(sth_desc, ivert);
+ pos[0] = position[0];
+ pos[1] = position[1];
+ pos[2] = position[2];
+}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
+res_T
+setup_unstructured_volumetric_mesh
+ (struct atrstm* atrstm,
+ const int precompute_normals,
+ const char* sth_filename,
+ struct suvm_volume** out_volume)
+{
+ struct suvm_tetrahedral_mesh_args mesh_args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL;
+ struct sth_desc sth_desc = STH_DESC_NULL;
+ struct sth* sth = NULL;
+ struct suvm_volume* volume = NULL;
+ struct time t0, t1;
+ char buf[128];
+ res_T res = RES_OK;
+ ASSERT(atrstm && sth_filename && out_volume);
+
+ log_info(atrstm, "Loading and structuring the volumetric mesh '%s'\n",
+ sth_filename);
+
+ /* Load the volumetric mesh */
+ res = sth_create(atrstm->logger, atrstm->allocator, atrstm->verbose, &sth);
+ if(res != RES_OK) goto error;
+ res = sth_load(sth, sth_filename);
+ if(res != RES_OK) goto error;
+ res = sth_get_desc(sth, &sth_desc);
+ if(res != RES_OK) goto error;
+
+ /* Partition the unstructured volumetric mesh */
+ mesh_args.ntetrahedra = sth_desc.ntetrahedra;
+ mesh_args.nvertices = sth_desc.nvertices;
+ mesh_args.get_indices = tetrahedron_get_indices;
+ mesh_args.get_position = vertex_get_position;
+ mesh_args.tetrahedron_data = SUVM_DATA_NULL; /* Tetra data are not in SUVM */
+ mesh_args.vertex_data = SUVM_DATA_NULL; /* Vertex data are not in SUVM */
+ mesh_args.precompute_normals = precompute_normals;
+ mesh_args.context = &sth_desc;
+ res = suvm_tetrahedral_mesh_create(atrstm->suvm, &mesh_args, &volume);
+ if(res != RES_OK) goto error;
+
+ /* Report time */
+ time_sub(&t0, time_current(&t1), &t0);
+ time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf));
+ log_info(atrstm, "Setup volumetric mesh in %s\n", buf);
+
+exit:
+ *out_volume = NULL;
+ if(sth) STH(ref_put(sth));
+ return res;
+error:
+ if(volume) {
+ SUVM(volume_ref_put(volume));
+ volume = NULL;
+ }
+ goto exit;
+}
+