commit fe5afc09c9736c1d061036f975d1e6909f8c3697
parent a210ec6076c05324755f5492ebbdd5b3367d2c49
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 25 Apr 2021 18:44:55 +0200
Parse the parmeters of the step geometry
Diffstat:
| M | src/sgs.c | | | 2 | ++ |
| M | src/sgs_args.c | | | 115 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- |
2 files changed, 103 insertions(+), 14 deletions(-)
diff --git a/src/sgs.c b/src/sgs.c
@@ -143,6 +143,8 @@ sgs_run(struct sgs* sgs)
if(sgs->dump_geometry) {
res = sgs_geometry_dump_vtk(sgs->geom, stdout);
if(res != RES_OK) goto error;
+ } else {
+ /* TODO Monte Carlo computation */
}
exit:
diff --git a/src/sgs_args.c b/src/sgs_args.c
@@ -46,42 +46,70 @@ print_help(void)
" low=x,y,z\n"
" define the lower bound of the box\n"
" (default: %g,%g,%g).\n",
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[0],
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[1],
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[2]);
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[0],
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[1],
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[2]);
printf(
" upp=x,y,z\n"
" define the upper bound of the box\n"
" (default: %g,%g,%g).\n",
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[0],
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[1],
- SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[2]);
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[0],
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[1],
+ SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[2]);
printf(
" -d dump geometry following the VTK file format.\n");
printf(
" -h display this help and exit.\n");
printf(
+" -p <step-params:...>\n"
+" define an axis aligned box whose +Z face is replaced\n"
+" by a step along the X axis. Available step parameters\n"
+" are:\n");
+ printf(
+" low=x,y,z\n"
+" define the lower bound (default: %g,%g,%g).\n",
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.lower[0],
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.lower[1],
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.lower[2]);
+ printf(
+" upp=x,y\n"
+" define the upper bound in the XY plane\n"
+" (default: %g,%g).\n",
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.upper[0],
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.upper[1]);
+ printf(
+" heights=h0,h1\n"
+" define the heights of the first and second\n"
+" levels of the step (default: %g,%g).\n",
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.heights[0],
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.heights[1]);
+ printf(
+" step=x\n"
+" coordinates of the step along the X axis\n"
+" (default: %g).\n",
+ SGS_GEOMETRY_STEP_ARGS_DEFAULT.step);
+ printf(
" -s <slope-params:...>\n"
" define an axis aligned box whose +Z face is tilted\n"
" along the X axis. Available slope parameters are:\n");
printf(
" low=x,y,z\n"
" define the lower bound (default: %g,%g,%g).\n",
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[0],
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[1],
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[2]);
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[0],
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[1],
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[2]);
printf(
" upp=x,y\n"
" define the upper bound in the XY plane\n"
" (default: %g,%g).\n",
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[0],
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[1]);
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[0],
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[1]);
printf(
" heights=h0,h1\n"
" define the start and end heights of the slope\n"
" (default: %g,%g).\n",
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[0],
- SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[1]);
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[0],
+ SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[1]);
printf(
" -t nthreads hint on the number of threads to use. By default use\n"
" as many threads as CPU cores.\n");
@@ -192,6 +220,59 @@ error:
goto exit;
}
+static res_T
+parse_step_parameters(const char* str, void* ptr)
+{
+ char buf[128];
+ struct sgs_geometry_step_args* step = ptr;
+ char* key;
+ char* val;
+ char* ctx;
+ size_t len;
+ res_T res = RES_OK;
+ ASSERT(ptr && str);
+
+ if(strlen(str) >= sizeof(buf) -1/*NULL char*/) {
+ fprintf(stderr, SGS_LOG_ERROR_PREFIX
+ "Could not duplicate the step option string `%s'.\n", str);
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ strncpy(buf, str, sizeof(buf));
+
+ key = strtok_r(buf, "=", &ctx);
+ val = strtok_r(NULL, "", &ctx);
+
+ if(!strcmp(key, "low")) {
+ res = cstr_to_list_double(val, ',', step->lower, &len, 3);
+ if(res == RES_OK && len != 3) res = RES_BAD_ARG;
+ } else if(!strcmp(key, "upp")) {
+ res = cstr_to_list_double(val, ',', step->upper, &len, 2);
+ if(res == RES_OK && len != 2) res = RES_BAD_ARG;
+ } else if(!strcmp(key, "heights")) {
+ res = cstr_to_list_double(val, ',', step->heights, &len, 2);
+ if(res == RES_OK && len != 2) res = RES_BAD_ARG;
+ } else if(!strcmp(key, "step")) {
+ res = cstr_to_double(val, &step->step);
+ } else {
+ fprintf(stderr, SGS_LOG_ERROR_PREFIX
+ "Invalid step parameter `%s'.\n", key);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ if(res != RES_OK) {
+ fprintf(stderr, SGS_LOG_ERROR_PREFIX
+ "Error parsing the value of the `%s' step parameter: %s -- %s.\n",
+ key, val, res_to_cstr(res));
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
/*******************************************************************************
* sgs_args API
******************************************************************************/
@@ -204,7 +285,7 @@ sgs_args_init(struct sgs_args* args, int argc, char** argv)
*args = SGS_ARGS_DEFAULT;
- while((opt = getopt(argc, argv, "b:dhs:t:v")) != -1) {
+ while((opt = getopt(argc, argv, "b:dhp:s:t:v")) != -1) {
switch(opt) {
case 'b':
args->geom.type = SGS_GEOMETRY_BOX;
@@ -218,6 +299,12 @@ sgs_args_init(struct sgs_args* args, int argc, char** argv)
sgs_args_release(args);
args->quit = 1;
break;
+ case 'p':
+ args->geom.type = SGS_GEOMETRY_STEP;
+ args->geom.args.step = SGS_GEOMETRY_STEP_ARGS_DEFAULT;
+ res = cstr_parse_list
+ (optarg, ':', parse_step_parameters, &args->geom.args.step);
+ break;
case 's':
args->geom.type = SGS_GEOMETRY_SLOPE;
args->geom.args.slope = SGS_GEOMETRY_SLOPE_ARGS_DEFAULT;