commit 899f050c0b136920dcceaf7d28096f5d6c7e3cc6
parent c11d20bc054256c49ac9318d223929a93d897fdd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 12 Feb 2025 15:34:39 +0100
planets: update -r option synthax
It is now defined as a list of sub-options that define both the volume
mesh and the number of realisations to be used to estimate the volumic
radiative budget of each tetrahedron.
Diffstat:
5 files changed, 130 insertions(+), 27 deletions(-)
diff --git a/Makefile b/Makefile
@@ -487,6 +487,7 @@ libhtrdr-planets.o: $(PLANETS_OBJ)
src/planets/htrdr_planets_args.h: config.mk src/planets/htrdr_planets_args.h.in
sed -e 's/@HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD@/$(HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD)/g' \
-e 's/@HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT@/$(HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT)/g' \
+ -e 's/@HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT@/$(HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT)/g' \
$@.in > $@
$(PLANETS_DEP):
@@ -576,6 +577,7 @@ doc/htrdr-planets.1: doc/htrdr-planets.1.in
-e 's/@HTRDR_ARGS_DEFAULT_IMG_SPP@/$(HTRDR_ARGS_DEFAULT_IMG_SPP)/g' \
-e 's/@HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD@/$(HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD)/g' \
-e 's/@HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT@/$(HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT)/g' \
+ -e 's/@HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT@/$(HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT)/g' \
$@.in > $@
clean_man:
diff --git a/config.mk b/config.mk
@@ -21,8 +21,8 @@ PLANETS = ENABLE
LIB_TYPE = SHARED
#LIB_TYPE = STATIC
-#BUILD_TYPE = RELEASE
-BUILD_TYPE = DEBUG
+BUILD_TYPE = RELEASE
+#BUILD_TYPE = DEBUG
# MPI pkg-config file
MPI_PC = ompi
@@ -63,6 +63,7 @@ HTRDR_COMBUSTION_ARGS_DEFAULT_WAVELENGTH = 532
# Planets
HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD = 1
HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT = 512
+HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT = 1000
################################################################################
# Tools
diff --git a/doc/htrdr-planets.1.in b/doc/htrdr-planets.1.in
@@ -41,7 +41,7 @@
.Op Fl i Ar image_opt Ns Op : Ns Ar image_opt No ...
.Op Fl O Ar accel_struct_storage
.Op Fl o Ar output
-.Op Fl r Ar volrad_budget_mesh
+.Op Fl r Ar volrad_budget_opt Ns Op : Ns Ar volrad_budget_opt No ...
.Op Fl S Ar source_opt Ns Op : Ns Ar source_opt No ...
.Op Fl s Ar spectral_opt Ns Op : Ns Ar spectral_opt No ...
.Op Fl T Ar optical_thickness
@@ -135,7 +135,7 @@ necessary.
.Pp
The aerosol options are as follows:
.Bl -tag -width Ds
-.It Cm mesh= Ns Ar volumetric_mesh
+.It Cm mesh= Ns Ar volume_mesh
Aerosol tetrahedral mesh saved in
.Xr smsh 5
format.
@@ -329,21 +329,27 @@ stopped, thus avoiding the use of incorrect acceleration structures.
.It Fl o Ar output
Output file.
If not defined, data is written to standard output.
-.It Fl r Ar volrad_budget_mesh
-Tetrahedral mesh in
-.Xr smsh 5
-format on which the volumic radiative budget is estimated per
-tetrahedron
-.Po see
-.Sx OUTPUT DATA
-section
-.Pc .
-The calculation is no longer an image rendering:
+.It Fl r Ar volrad_budget_opt Ns Op : Ns Ar volrad_budget_opt No ...
+Define the calculation of the volumic radiative budget.
+Calculation is no longer a rendering:
neither a camera
.Pq option Fl C
nor an image
.Pq option Fl i
is required.
+.Pp
+The volume radiative budget options are as follows:
+.Bl -tag -width Ds
+.It Cm mesh= Ns Ar volume_mesh
+Tetrahedral mesh in
+.Xr smsh 5
+format on which the volumic radiative budget is estimated per
+tetrahedron.
+.It Cm spt= Ns Ar samples_per_tetrahedron
+Number of samples to estimate the volumic radiative budget of each
+tetrahedron.
+Default is @HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT@.
+.El
.It Fl S Ar source_opt Ns Op : Ns Ar source_opt No ...
Define the external source.
.Pp
@@ -442,8 +448,7 @@ verbose.
The output of
.Nm
depends on the type of calculation invoked.
-This section describes the nature and layout of output data, depending
-on the type of calculation.
+This section describes the nature and layout of these output data.
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Ss XYZ image
For an image rendering in the visible part of the spectrum
@@ -500,14 +505,14 @@ there are tetrahedra in the volume mesh as an argument to the
.Fl r
option.
The lines follow the order of the input meshes.
-For each line, the first 2 values correspond to the estimated volumic
-radiative budget of the corresponding tetrahedron (in W/m^3) and its
+For each line, the first 2 values correspond to the expected value of
+the volumic radiative budget of the tetrahedron (in W/m^3) and its
standard error.
The remaining 3 values are the sum of the Monte Carlo weights, the sum
of the Monte Carlo weights squared, and the total number of Monte Carlo
weights used to calculate the preceding quantities.
-Their purpose is to help calculate the estimate and standard error of
-the volumic radiative budget for a set of tetrahedra.
+Their purpose is to help calculate the expected value and standard error
+of the volumic radiative budget for a set of tetrahedra.
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.\" Returned status
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
diff --git a/src/planets/htrdr_planets_args.c b/src/planets/htrdr_planets_args.c
@@ -102,6 +102,21 @@ check_spectral_args(const struct htrdr_planets_spectral_args* args)
return RES_OK;
}
+
+static INLINE res_T
+check_volrad_budget_args(const struct htrdr_planets_volrad_budget_args* args)
+{
+ if(!args) return RES_BAD_ARG;
+
+ /* Filename could not be NULL */
+ if(!args->mesh) return RES_BAD_ARG;
+
+ /* Samples per tetrahedron could not be zero */
+ if(!args->spt) return RES_BAD_ARG;
+
+ return RES_OK;
+}
+
static void
usage(void)
{
@@ -507,6 +522,70 @@ error:
goto exit;
}
+static res_T
+parse_volrad_budget_parameters(const char* str, void* ptr)
+{
+ enum { MESH, SPT } iparam;
+ char buf[BUFSIZ];
+ struct htrdr_planets_args* args = ptr;
+ char* key;
+ char* val;
+ char* tk_ctx;
+ res_T res = RES_OK;
+ ASSERT(str && ptr);
+
+ if(strlen(str) >= sizeof(buf) -1/*NULL char*/) {
+ fprintf(stderr,
+ "Could not duplicate the parameters "
+ "of the volumic radiative budget calculation `%s'\n",
+ str);
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ strncpy(buf, str, sizeof(buf));
+
+ key = strtok_r(buf, "=", &tk_ctx);
+ val = strtok_r(NULL, "", &tk_ctx);
+
+ if(!strcmp(key, "mesh")) iparam = MESH;
+ else if(!strcmp(key, "spt")) iparam = SPT;
+ else {
+ fprintf(stderr, "Invalid volumic radiative budget parameter `%s'\n", key);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if(!val) {
+ fprintf(stderr,
+ "Invalid null value for the volumic radiative budget parameter `%s'.\n",
+ key);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ switch(iparam) {
+ case MESH:
+ if(args->volrad_budget.mesh) mem_rm(args->volrad_budget.mesh);
+ if(!(args->volrad_budget.mesh = str_dup(val))) res = RES_MEM_ERR;
+ break;
+ case SPT: /* Sample Per Tetrahedron */
+ res = cstr_to_uint(val, &args->volrad_budget.spt);
+ break;
+ default: FATAL("Unreachable code\n"); break;
+ }
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Unable to parse the volumic radiative budget parameter `%s' -- %s\n",
+ str, res_to_cstr(res));
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
/*******************************************************************************
* Local functions
******************************************************************************/
@@ -564,7 +643,7 @@ htrdr_planets_args_init(struct htrdr_planets_args* args, int argc, char** argv)
case 'O': args->octrees_storage = optarg; break;
case 'o': args->output = optarg; break;
case 'r':
- args->volrad_budget_mesh = optarg;
+ res = cstr_parse_list(optarg, ':', parse_volrad_budget_parameters, args);
args->output_type = HTRDR_PLANETS_ARGS_OUTPUT_VOLUMIC_RADIATIVE_BUDGET;
break;
case 'S':
@@ -697,7 +776,7 @@ htrdr_planets_args_check(const struct htrdr_planets_args* args)
}
}
- if(args->output_type != HTRDR_PLANETS_ARGS_OUTPUT_IMAGE) {
+ if(args->output_type == HTRDR_PLANETS_ARGS_OUTPUT_IMAGE) {
res = htrdr_args_camera_perspective_check(&args->cam_persp);
if(res != RES_OK) return res;
@@ -705,6 +784,11 @@ htrdr_planets_args_check(const struct htrdr_planets_args* args)
if(res != RES_OK) return res;
}
+ if(args->output_type == HTRDR_PLANETS_ARGS_OUTPUT_VOLUMIC_RADIATIVE_BUDGET) {
+ res = check_volrad_budget_args(&args->volrad_budget);
+ if(res != RES_OK) return res;
+ }
+
/* Check miscalleneous parameters */
if(args->nthreads == 0
|| (unsigned)args->output_type >= HTRDR_PLANETS_ARGS_OUTPUT_TYPES_COUNT__)
diff --git a/src/planets/htrdr_planets_args.h.in b/src/planets/htrdr_planets_args.h.in
@@ -71,6 +71,17 @@ struct htrdr_planets_ground_args {
static const struct htrdr_planets_ground_args HTRDR_PLANETS_GROUND_ARGS_NULL =
HTRDR_PLANETS_GROUND_ARGS_NULL__;
+struct htrdr_planets_volrad_budget_args {
+ char* mesh; /* The Star-Mesh geometry */
+ unsigned spt; /* Number of MC realisations per tetrahedron */
+};
+#define HTRDR_PLANETS_VOLRAD_BUDGET_ARGS_NULL__ { \
+ NULL, @HTRDR_PLANETS_ARGS_DEFAULT_VOLRAD_BUDGET_SPT@ \
+}
+static const struct htrdr_planets_volrad_budget_args
+HTRDR_PLANETS_VOLRAD_BUDGET_ARGS_NULL =
+ HTRDR_PLANETS_VOLRAD_BUDGET_ARGS_NULL__;
+
struct htrdr_planets_args {
/* System data */
struct rnatm_gas_args gas;
@@ -82,10 +93,6 @@ struct htrdr_planets_args {
* at runtime and kept in memory */
char* octrees_storage;
- /* Input volume mesh in smsh(5) format, on which the volumic radiative budget
- * per-tetrahedron is estimated */
- char* volrad_budget_mesh;
-
unsigned octree_definition_hint; /* Hint on octree definition */
double optical_thickness; /* Threshold used during octree building */
@@ -96,6 +103,9 @@ struct htrdr_planets_args {
struct htrdr_args_camera_perspective cam_persp; /* Perspective camera */
+ /* Input parameters for volumic radiative budget calculation */
+ struct htrdr_planets_volrad_budget_args volrad_budget;
+
/* Miscellaneous arguments */
unsigned nthreads; /* Hint on the nimber of threads to use */
enum htrdr_planets_args_output_type output_type;
@@ -111,7 +121,6 @@ struct htrdr_planets_args {
HTRDR_PLANETS_GROUND_ARGS_NULL__, /* Ground */ \
\
NULL, /* File where to dump octrees */ \
- NULL, /* Volumic mesh for volumic radiative budget estimations */ \
\
@HTRDR_PLANETS_ARGS_DEFAULT_GRID_DEFINITION_HINT@, /* octree definition */ \
@HTRDR_PLANETS_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD@, \
@@ -123,6 +132,8 @@ struct htrdr_planets_args {
\
HTRDR_ARGS_CAMERA_PERSPECTIVE_DEFAULT__, /* Perspective camera */ \
\
+ HTRDR_PLANETS_VOLRAD_BUDGET_ARGS_NULL__, /* Volumic radiative budget */ \
+ \
UINT_MAX, /* Number of threads */ \
HTRDR_PLANETS_ARGS_OUTPUT_IMAGE, \
0, /* Force output overwrite */ \