commit 9cb975b5a5a042d780bb7e43ac450111d966ce0c
parent 06b699912d3e2147e996c18d1c91e082ff0ba5c5
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 13 Sep 2019 12:44:13 +0200
Add compute-flux-on-a-surface feature
Diffstat:
4 files changed, 95 insertions(+), 26 deletions(-)
diff --git a/src/stardis-compute.c b/src/stardis-compute.c
@@ -593,7 +593,7 @@ compute_boundary
/* FIXME: MOVE TO BOUNDARY SETTING */
ASSERT(sa_size(stardis->boundary.primitives)
== sa_size(stardis->boundary.sides));
- if (sa_size(stardis->boundary.sides) == 0) {
+ if (sa_size(stardis->boundary.primitives) == 0) {
fprintf(stderr, "Cannot solve boundary %s (empty geometry)\n",
stardis->solve_name);
}
@@ -605,7 +605,7 @@ compute_boundary
stardis->N,
stardis->boundary.primitives,
stardis->boundary.sides,
- sa_size(stardis->boundary.sides),
+ sa_size(stardis->boundary.primitives),
stardis->scale_factor,
stardis->radiative_temp[0],
stardis->radiative_temp[1],
@@ -620,7 +620,7 @@ compute_boundary
stardis->N,
stardis->boundary.primitives,
stardis->boundary.sides,
- sa_size(stardis->boundary.sides),
+ sa_size(stardis->boundary.primitives),
time,
stardis->scale_factor,
stardis->radiative_temp[0],
@@ -640,6 +640,48 @@ error:
}
static res_T
+compute_flux_boundary
+ (struct sdis_scene* scn,
+ const struct counts* counts,
+ struct stardis* stardis,
+ const int mode)
+{
+ res_T res = RES_OK;
+ double time[2], pos[3];
+ struct sdis_green_function* green = NULL;
+ struct sdis_estimator* estimator = NULL;
+
+ ASSERT(scn && counts && stardis && (mode & FLUX_BOUNDARY_COMPUTE));
+
+ /* FIXME: MOVE TO BOUNDARY SETTING */
+ if (sa_size(stardis->boundary.primitives) == 0) {
+ fprintf(stderr, "Cannot solve boundary %s (empty geometry)\n",
+ stardis->solve_name);
+ }
+
+ d3_set(pos, stardis->probe);
+ d2_splat(time, stardis->probe[3]);
+ res = sdis_solve_boundary_flux(scn,
+ stardis->N,
+ stardis->boundary.primitives,
+ sa_size(stardis->boundary.primitives),
+ time,
+ stardis->scale_factor,
+ stardis->radiative_temp[0],
+ stardis->radiative_temp[1],
+ &estimator);
+ if (res != RES_OK) goto error;
+ res = print_single_MC_result(mode, estimator, stardis);
+ if (res != RES_OK) goto error;
+end:
+ if (estimator) SDIS(estimator_ref_put(estimator));
+ if (green) SDIS(green_function_ref_put(green));
+ return res;
+error:
+ goto end;
+}
+
+static res_T
compute_map
(struct sdis_scene* scn,
struct stardis* stardis,
@@ -658,7 +700,7 @@ compute_map
/* FIXME: MOVE TO BOUNDARY SETTING */
ASSERT(sa_size(stardis->boundary.primitives)
== sa_size(stardis->boundary.sides));
- if (sa_size(stardis->boundary.sides) == 0) {
+ if (sa_size(stardis->boundary.primitives) == 0) {
fprintf(stderr, "Cannot solve boundary %s (empty geometry)\n",
stardis->solve_name);
}
@@ -666,9 +708,9 @@ compute_map
d3_set(pos, stardis->probe);
d2_splat(time, stardis->probe[3]);
- sa_add(estimators, sa_size(stardis->boundary.sides));
+ sa_add(estimators, sa_size(stardis->boundary.primitives));
- FOR_EACH(p, 0, sa_size(stardis->boundary.sides)) {
+ FOR_EACH(p, 0, sa_size(stardis->boundary.primitives)) {
res = sdis_solve_boundary(scn,
stardis->N,
stardis->boundary.primitives + p,
@@ -686,7 +728,7 @@ compute_map
end:
if (estimators) {
- FOR_EACH(p, 0, sa_size(stardis->boundary.sides)) {
+ FOR_EACH(p, 0, sa_size(stardis->boundary.primitives)) {
SDIS(estimator_ref_put(estimators[p]));
}
sa_release(estimators);
@@ -808,6 +850,8 @@ stardis_compute
res = compute_medium(scn, media, stardis, mode);
else if (mode & BOUNDARY_COMPUTE)
res = compute_boundary(scn, &counts, stardis, mode);
+ else if (mode & FLUX_BOUNDARY_COMPUTE)
+ res = compute_flux_boundary(scn, &counts, stardis, mode);
else if (mode & MAP_COMPUTE)
res = compute_map(scn, stardis, mode);
else FATAL("Unknown mode.\n");
diff --git a/src/stardis-output.c b/src/stardis-output.c
@@ -662,13 +662,13 @@ print_single_MC_result
struct stardis* stardis)
{
res_T res = RES_OK;
- struct sdis_mc temperature;
+ struct sdis_mc result;
size_t nfailures;
ASSERT(estimator && stardis);
/* Fetch the estimation data */
- res = sdis_estimator_get_temperature(estimator, &temperature);
+ res = sdis_estimator_get_temperature(estimator, &result);
if (res != RES_OK) goto error;
res = sdis_estimator_get_failure_count(estimator, &nfailures);
if (res != RES_OK) goto error;
@@ -679,20 +679,26 @@ print_single_MC_result
case PROBE_COMPUTE_ON_INTERFACE:
printf("Temperature at [%g, %g, %g], t=%g = %g +/- %g\n",
SPLIT4(stardis->probe),
- temperature.E, /* Expected value */
- temperature.SE); /* Standard error */
+ result.E, /* Expected value */
+ result.SE); /* Standard error */
break;
case MEDIUM_COMPUTE:
printf("Temperature in medium %s at t=%g = %g +/- %g\n",
stardis->solve_name, stardis->probe[3],
- temperature.E, /* Expected value */
- temperature.SE); /* Standard error */
+ result.E, /* Expected value */
+ result.SE); /* Standard error */
break;
case BOUNDARY_COMPUTE:
printf("Temperature at boundary %s at t=%g = %g +/- %g\n",
stardis->solve_name, stardis->probe[3],
- temperature.E, /* Expected value */
- temperature.SE); /* Standard error */
+ result.E, /* Expected value */
+ result.SE); /* Standard error */
+ break;
+ case FLUX_BOUNDARY_COMPUTE:
+ printf("Flux at boundary %s at t=%g = %g +/- %g\n",
+ stardis->solve_name, stardis->probe[3],
+ result.E, /* Expected value */
+ result.SE); /* Standard error */
break;
default: FATAL("Invalid mode.");
}
diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c
@@ -159,27 +159,34 @@ print_help
printf(" boundary conditions.\n");
printf("\nExclusive arguments\n");
printf("-------------------\n");
- printf("\n -p X:Y:Z:TIME:\n");
+ printf("\n -p X,Y,Z:TIME:\n");
printf(" Compute the temperature at the given probe.\n");
printf(" The probe must be in a medium.\n");
printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
- printf("\n -P X:Y:Z:TIME:\n");
+ printf("\n -P X,Y,Z:TIME:\n");
printf(" Compute the temperature at the given probe on an interface.\n");
printf(" The probe must be in a medium and is moved to the closest interface.\n");
printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
printf("\n -m MEDIUM_NAME,TIME:\n");
printf(" Compute the mean temperature in a given medium at a given time.\n");
printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
- printf("\n -s SURFACE.vtk,TIME:\n");
+ printf("\n -s SURFACE.stl,TIME:\n");
printf(" Compute the mean temperature on a given 2D shape at a given time.\n");
printf(" Mean temperature is computed on the front sides of the primitives\n");
- printf(" listed in SURFACE.vtk. These primitives are not added to the geometry,\n");
+ printf(" listed in SURFACE.stl. These primitives are not added to the geometry,\n");
printf(" but must be already known. The shape doesn't need to be connex.\n");
printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
- printf("\n -S SURFACE.vtk,TIME:\n");
+ printf("\n -S SURFACE.stl,TIME:\n");
printf(" Compute by-primitives mean temperature on a given 2D shape at a given time.\n");
printf(" Mean temperature is computed on the front sides of the primitives\n");
- printf(" listed in SURFACE.vtk. These primitives are not added to the geometry,\n");
+ printf(" listed in SURFACE.stl. These primitives are not added to the geometry,\n");
+ printf(" but must be already known. The shape doesn't need to be connex.\n");
+ printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
+ printf("\n -F SURFACE.stl,TIME:\n");
+ printf(" Compute the mean flux on a given 2D shape at a given time.\n");
+ printf(" Mean flux is computed on the primitives listed in SURFACE.stl and is\n");
+ printf(" accounted positive, at the primitive scale, when going from the front\n");
+ printf(" side to the back side. These primitives are not added to the geometry,\n");
printf(" but must be already known. The shape doesn't need to be connex.\n");
printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n");
printf("\n -R t=TIME:spp=SPP:fov=FOV:up=XUP,YUP,ZUP:pos=X,Y,Z:tgt=XT,YT,ZT:img=WxH:\n");
@@ -236,7 +243,7 @@ parse_args
}
opterr = 0; /* No default error messages */
- while ((opt = getopt(argc, argv, "hvgn:t:B:M:m:p:P:dD:s:S:f:r:R:")) != -1) {
+ while ((opt = getopt(argc, argv, "hvgn:t:B:M:m:p:P:dD:s:S:F:f:r:R:")) != -1) {
switch (opt) {
case '?': /* Unreconised option */
res = RES_BAD_ARG;
@@ -326,7 +333,8 @@ parse_args
break;
case 's':
- case 'S': {
+ case 'S':
+ case 'F': {
int err = 0;
char *ptr;
if (args->mode & EXCLUSIVE_MODES) {
@@ -335,7 +343,17 @@ parse_args
(char)opt, mode_option(args->mode));
goto error;
}
- args->mode |= (opt == 's' ? BOUNDARY_COMPUTE : MAP_COMPUTE);
+ switch (opt) {
+ case 's':
+ args->mode |= BOUNDARY_COMPUTE;
+ break;
+ case 'S':
+ args->mode |= MAP_COMPUTE;
+ break;
+ case 'F':
+ args->mode |= FLUX_BOUNDARY_COMPUTE;
+ break;
+ }
ptr = strrchr(optarg, ',');
/* Single ',' allowed */
if (!ptr || ptr != strchr(optarg, ','))
diff --git a/src/stardis-parsing.h b/src/stardis-parsing.h
@@ -20,15 +20,16 @@ enum stardis_mode {
MAP_COMPUTE = BIT(5),
DUMP_VTK = BIT(6),
GREEN_MODE = BIT(7),
+ FLUX_BOUNDARY_COMPUTE = BIT(8),
GREEN_COMPATIBLE_MODES = PROBE_COMPUTE | PROBE_COMPUTE_ON_INTERFACE | MEDIUM_COMPUTE
| BOUNDARY_COMPUTE,
- COMPUTE_MODES = GREEN_COMPATIBLE_MODES | IR_COMPUTE | MAP_COMPUTE,
+ COMPUTE_MODES = GREEN_COMPATIBLE_MODES | IR_COMPUTE | MAP_COMPUTE | FLUX_BOUNDARY_COMPUTE,
NON_COMPUTE_MODES = UNDEF_MODE | DUMP_VTK | GREEN_MODE,
- EXCLUSIVE_MODES = COMPUTE_MODES | DUMP_VTK
+ EXCLUSIVE_MODES = COMPUTE_MODES | DUMP_VTK | FLUX_BOUNDARY_COMPUTE
};
STATIC_ASSERT(GREEN_COMPATIBLE_MODES == (COMPUTE_MODES & GREEN_COMPATIBLE_MODES),