commit 5db76da4ea9d5580842ec9d4cd407176dc915c50
parent 90236fe178b26bed1724c30166e0fd1d5ecdabf4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 4 Nov 2021 16:43:05 +0100
Add <get|set> <temperature_range|max_branchings> functions
Diffstat:
11 files changed, 134 insertions(+), 45 deletions(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -362,7 +362,7 @@ typedef void
struct sdis_ambient_radiative_temperature {
double temperature; /* In Kelvin */
- double reference; /* Used to linearise the radiative transfert */
+ double reference; /* Used to linearise the radiative transfer */
};
#define SDIS_AMBIENT_RADIATIVE_TEMPERATURE_NULL__ {-1, -1}
static const struct sdis_ambient_radiative_temperature
@@ -382,8 +382,9 @@ struct sdis_scene_create_args {
size_t nvertices; /* #vertices */
double fp_to_meter; /* Scale factor used to convert 1.0 in 1 meter */
struct sdis_ambient_radiative_temperature trad; /* Ambient radiative temp */
- double tmin; /* Min temperature */
- double tmax; /* Max temperature used to linearize the radiative temperature */
+
+ /* Min/max temperature used to linearise the radiative temperature */
+ double t_range[2];
/* Maximum number of heat path branchings. Actually the Picard order
* used to estimate the radiative temperature is max_branchings+1 */
@@ -399,8 +400,7 @@ struct sdis_scene_create_args {
0, /* #vertices */ \
1.0, /* #Floating point to meter scale factor */ \
SDIS_AMBIENT_RADIATIVE_TEMPERATURE_NULL__,/* Ambient radiative temperature */\
- 0.0, /* Minimum temperature */ \
- -1.0, /* Maximum temperature */ \
+ {0.0, -1.0}, /* Temperature range */ \
0 /* Maximum branchings */ \
}
static const struct sdis_scene_create_args SDIS_SCENE_CREATE_ARGS_DEFAULT =
@@ -854,18 +854,34 @@ sdis_scene_set_ambient_radiative_temperature
(struct sdis_scene* scn,
const struct sdis_ambient_radiative_temperature* trad);
-/* Get scene's maximum temperature */
+/* Get scene's minimum/maximum temperature */
+SDIS_API res_T
+sdis_scene_get_temperature_range
+ (const struct sdis_scene* scn,
+ double t_range[2]);
+
+/* Set scene's minimum/maximum temperature. Must be correctly defined if there
+ * is any radiative transfer in the scene */
+SDIS_API res_T
+sdis_scene_set_temperature_range
+ (struct sdis_scene* scn,
+ const double t_range[2]);
+
+/* Get the maximum number of branchings for the sampled paths. */
SDIS_API res_T
-sdis_scene_get_maximum_temperature
+sdis_scene_get_max_branchings
(const struct sdis_scene* scn,
- double* tmax);
+ size_t* max_branchings);
-/* Set scene's maximum temperature. Must be correctly defined if there is any
- * radiative transfert in the scene. */
+/* Set the maximum number of branchings for the sampled paths. A value greater
+ * than zero enables the estimation of T4 radiative transfer by using the
+ * Picard's algorithm. In others words, 'max_branchings+1' is the order of the
+ * Picard's recursion: at order one (i.e. max_branchings==0), the radiative
+ * transfer is linearised */
SDIS_API res_T
-sdis_scene_set_maximum_temperature
+sdis_scene_set_max_branchings
(struct sdis_scene* scn,
- const double tmax);
+ const size_t max_branchings);
/* Search the point onto the scene geometry that is the closest of `pos'. The
* `radius' parameter controls the maximum search distance around `pos'. The
diff --git a/src/sdis_heat_path_boundary_Xd_solid_fluid_picardN.h b/src/sdis_heat_path_boundary_Xd_solid_fluid_picardN.h
@@ -76,13 +76,16 @@ XD(sample_path)
res_T res = RES_OK;
ASSERT(rwalk_from && rng && T);
+ /* Clean-up the output variable */
*T = XD(TEMPERATURE_NULL);
+ /* Init the random walk */
rwalk.vtx = rwalk_from->vtx;
rwalk.mdm = rwalk_from->mdm;
rwalk.hit = rwalk_from->hit;
rwalk.hit_side = rwalk_from->hit_side;
+ /* Start the registration of a new heat path */
if(ctx->heat_path) {
struct sdis_heat_vertex heat_vtx = SDIS_HEAT_VERTEX_NULL;
@@ -97,10 +100,18 @@ XD(sample_path)
if(res != RES_OK) goto error;
}
+ /* Sample the path */
res = XD(compute_temperature)(scn, ctx, &rwalk, rng, T);
if(res != RES_OK) goto error;
+ /* Check the returned temperature */
ASSERT(T->done);
+ if(T->value < scn->tmin || scn->tmax < T->value) {
+ log_err(scn->dev, "%s: invalid temperature range `[%g, %g]K` regarding the "
+ "retrieved temperature %gK.\n", FUNC_NAME, scn->tmin, scn->tmax, T->value);
+ res = RES_BAD_OP_IRRECOVERABLE;
+ goto error;
+ }
exit:
return res;
diff --git a/src/sdis_scene.c b/src/sdis_scene.c
@@ -221,18 +221,44 @@ sdis_scene_set_ambient_radiative_temperature
}
res_T
-sdis_scene_get_maximum_temperature(const struct sdis_scene* scn, double* tmax)
+sdis_scene_get_temperature_range
+ (const struct sdis_scene* scn,
+ double t_range[2])
+{
+ if(!scn || !t_range) return RES_BAD_ARG;
+ t_range[0] = scn->tmin;
+ t_range[1] = scn->tmax;
+ return RES_OK;
+}
+
+res_T
+sdis_scene_set_temperature_range
+ (struct sdis_scene* scn,
+ const double t_range[2])
{
- if(!scn || !tmax) return RES_BAD_ARG;
- *tmax = scn->tmax;
+ if(!scn || !t_range) return RES_BAD_ARG;
+ scn->tmin = t_range[0];
+ scn->tmax = t_range[1];
return RES_OK;
}
res_T
-sdis_scene_set_maximum_temperature(struct sdis_scene* scn, const double tmax)
+sdis_scene_get_max_branchings
+ (const struct sdis_scene* scn,
+ size_t* max_branchings)
{
- if(!scn || tmax < 0) return RES_BAD_ARG;
- scn->tmax = tmax;
+ if(!scn || !max_branchings) return RES_BAD_ARG;
+ *max_branchings = scn->max_branchings;
+ return RES_OK;
+}
+
+res_T
+sdis_scene_set_max_branchings
+ (struct sdis_scene* scn,
+ const size_t max_branchings)
+{
+ if(!scn) return RES_BAD_ARG;
+ scn->max_branchings = max_branchings;
return RES_OK;
}
diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h
@@ -913,8 +913,8 @@ XD(scene_create)
scn->dev = dev;
scn->fp_to_meter = args->fp_to_meter;
scn->trad = args->trad;
- scn->tmin = args->tmin;
- scn->tmax = args->tmax;
+ scn->tmin = args->t_range[0];
+ scn->tmax = args->t_range[1];
scn->outer_enclosure_id = UINT_MAX;
scn->max_branchings = args->max_branchings;
darray_interf_init(dev->allocator, &scn->interfaces);
diff --git a/src/test_sdis_conducto_radiative.c b/src/test_sdis_conducto_radiative.c
@@ -306,6 +306,7 @@ main(int argc, char** argv)
const double T0 = 300; /* Fixed temperature on the left side of the system */
const double T1 = 310; /* Fixed temperature on the right side of the system */
const double thickness = 2.0; /* Thickness of the solid along X */
+ double t_range[2];
double Ts0, Ts1, hr, tmp;
struct interfac* p_intface;
(void)argc, (void)argv;
@@ -414,7 +415,8 @@ main(int argc, char** argv)
scn_args.get_position = get_position;
scn_args.nprimitives = ntriangles;
scn_args.nvertices = nvertices;
- scn_args.tmax = MMAX(T0, T1);
+ scn_args.t_range[0] = MMIN(T0, T1);
+ scn_args.t_range[1] = MMAX(T0, T1);
scn_args.context = &geom;
OK(sdis_scene_create(dev, &scn_args, &scn));
@@ -492,7 +494,9 @@ main(int argc, char** argv)
/* Check same green used at a different temperature */
p_intface->temperature = T1b = T1 + ((double)isimul + 1) * 10;
- OK(sdis_scene_set_maximum_temperature(scn, MMAX(T0, T1b)));
+ t_range[0] = MMIN(T0, T1b);
+ t_range[1] = MMAX(T0, T1b);
+ OK(sdis_scene_set_temperature_range(scn, t_range));
OK(sdis_solve_probe(scn, &solve_args, &estimator));
OK(sdis_estimator_get_realisation_count(estimator, &nreals));
diff --git a/src/test_sdis_conducto_radiative_2d.c b/src/test_sdis_conducto_radiative_2d.c
@@ -408,7 +408,8 @@ main(int argc, char** argv)
scn_args.nprimitives = nsegments;
scn_args.nvertices = nvertices;
scn_args.context = &geom;
- scn_args.tmax = MMAX(T0, T1);
+ scn_args.t_range[0] = MMIN(T0, T1);
+ scn_args.t_range[1] = MMAX(T0, T1);
OK(sdis_scene_2d_create(dev, &scn_args, &scn));
hr = 4*BOLTZMANN_CONSTANT * Tref*Tref*Tref * emissivity;
diff --git a/src/test_sdis_picard1.c b/src/test_sdis_picard1.c
@@ -37,7 +37,7 @@
* o--- X +------+----------+------+ (1.1,1)
* | |##########| |
* | |##########| |
- * 300K | E=1 |##########| E=1 | 350K
+ * 280K | E=1 |##########| E=1 | 350K
* | |##########| |
* | |##########| |
* (-1,-1) +------+----------+------+
@@ -512,7 +512,8 @@ create_scene_3d
scn_args.get_position = get_position_3d;
scn_args.nprimitives = nprimitives_3d;
scn_args.nvertices = nvertices_3d;
- scn_args.tmax = 350;
+ scn_args.t_range[0] = 280;
+ scn_args.t_range[1] = 350;
scn_args.context = &geom;
OK(sdis_scene_create(dev, &scn_args, scn));
}
@@ -554,7 +555,8 @@ create_scene_2d
scn_args.get_position = get_position_2d;
scn_args.nprimitives = nprimitives_2d;
scn_args.nvertices = nvertices_2d;
- scn_args.tmax = 350;
+ scn_args.t_range[0] = 280;
+ scn_args.t_range[1] = 350;
scn_args.context = &geom;
OK(sdis_scene_2d_create(dev, &scn_args, scn));
}
@@ -672,6 +674,21 @@ main(int argc, char** argv)
test_picard1(scn_3d, &ref);
printf("\n");
+#if 0
+ /* Test picardN */
+ printf("Test Picard1 using T4 as a reference\n");
+ ref.T = 320.37126474482994;
+ ref.T1 = 312.12650299072266;
+ ref.T2 = 328.61602649893723;
+ pinterf_props[SOLID_FLUID_mX]->Tref = 300;
+ pinterf_props[SOLID_FLUID_pX]->Tref = 300;
+ pinterf_props[BOUNDARY_mX]->Tref = 280;
+ pinterf_props[BOUNDARY_pX]->Tref = 350;
+ test_picard1(scn_2d, &ref);
+ test_picard1(scn_3d, &ref);
+ printf("\n");
+#endif
+
/* Add volumic power */
psolid_props->volumic_power = 1000;
diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c
@@ -261,8 +261,9 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
struct sdis_ambient_radiative_temperature trad =
SDIS_AMBIENT_RADIATIVE_TEMPERATURE_NULL;
double lower[2], upper[2];
+ double t_range[2];
double u0, u1, u2, pos[2], pos1[2];
- double dst, fp, t;
+ double dst, fp;
struct context ctx;
struct senc2d_scene* scn2d;
struct senc3d_scene* scn3d;
@@ -369,19 +370,24 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
CHK(trad.temperature == 100);
CHK(trad.reference == 110);
- BA(sdis_scene_get_maximum_temperature(NULL, NULL));
- BA(sdis_scene_get_maximum_temperature(scn, NULL));
- BA(sdis_scene_get_maximum_temperature(NULL, &t));
- OK(sdis_scene_get_maximum_temperature(scn, &t));
- CHK(t == SDIS_SCENE_CREATE_ARGS_DEFAULT.tmax);
-
- t = -1;
- BA(sdis_scene_set_maximum_temperature(NULL, t));
- BA(sdis_scene_set_maximum_temperature(scn, t));
- t = 100;
- OK(sdis_scene_set_maximum_temperature(scn, t));
- OK(sdis_scene_get_maximum_temperature(scn, &t));
- CHK(t == 100);
+ BA(sdis_scene_get_temperature_range(NULL, NULL));
+ BA(sdis_scene_get_temperature_range(scn, NULL));
+ BA(sdis_scene_get_temperature_range(NULL, t_range));
+ OK(sdis_scene_get_temperature_range(scn, t_range));
+ CHK(t_range[0] == SDIS_SCENE_CREATE_ARGS_DEFAULT.t_range[0]);
+ CHK(t_range[1] == SDIS_SCENE_CREATE_ARGS_DEFAULT.t_range[1]);
+
+ t_range[0] = 1;
+ t_range[1] = 100;
+
+ BA(sdis_scene_set_temperature_range(NULL, t_range));
+ BA(sdis_scene_set_temperature_range(scn, NULL));
+ OK(sdis_scene_set_temperature_range(scn, t_range));
+ t_range[0] = -1;
+ t_range[1] = -1;
+ OK(sdis_scene_get_temperature_range(scn, t_range));
+ CHK(t_range[0] == 1);
+ CHK(t_range[1] == 100);
BA(sdis_scene_get_boundary_position(NULL, 1, &u0, pos));
BA(sdis_scene_get_boundary_position(scn, 4, &u0, pos));
diff --git a/src/test_sdis_solve_boundary_flux.c b/src/test_sdis_solve_boundary_flux.c
@@ -347,7 +347,8 @@ main(int argc, char** argv)
scn_args.nvertices = box_nvertices;
scn_args.trad.temperature = Trad;
scn_args.trad.reference = Trad;
- scn_args.tmax = MMAX(MMAX(Tf, Trad), Tb);
+ scn_args.t_range[0] = MMIN(MMIN(Tf, Trad), Tb);
+ scn_args.t_range[1] = MMAX(MMAX(Tf, Trad), Tb);
scn_args.context = box_interfaces;
OK(sdis_scene_create(dev, &scn_args, &box_scn));
@@ -359,7 +360,8 @@ main(int argc, char** argv)
scn_args.nvertices = square_nvertices;
scn_args.trad.temperature = Trad;
scn_args.trad.reference = Trad;
- scn_args.tmax = MMAX(MMAX(Tf, Trad), Tb);
+ scn_args.t_range[0] = MMIN(MMIN(Tf, Trad), Tb);
+ scn_args.t_range[1] = MMAX(MMAX(Tf, Trad), Tb);
scn_args.context = square_interfaces;
OK(sdis_scene_2d_create(dev, &scn_args, &square_scn));
diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c
@@ -634,7 +634,8 @@ main(int argc, char** argv)
scn_args.nvertices = npos;
scn_args.trad.temperature = 300;
scn_args.trad.reference = 300;
- scn_args.tmax = 350;
+ scn_args.t_range[0] = 300;
+ scn_args.t_range[1] = 350;
scn_args.context = &geom;
OK(sdis_scene_create(dev, &scn_args, &scn));
diff --git a/src/test_sdis_solve_probe.c b/src/test_sdis_solve_probe.c
@@ -286,6 +286,7 @@ main(int argc, char** argv)
struct ssp_rng* rng_state = NULL;
enum sdis_estimator_type type;
FILE* stream = NULL;
+ double t_range[2];
double ref;
const size_t N = 1000;
const size_t N_dump = 10;
@@ -551,8 +552,10 @@ main(int argc, char** argv)
/* Green and ambient radiative temperature */
solve_args.nrealisations = N;
trad.temperature = trad.reference = 300;
+ t_range[0] = 300;
+ t_range[1] = 300;
OK(sdis_scene_set_ambient_radiative_temperature(scn, &trad));
- OK(sdis_scene_set_maximum_temperature(scn, 300));
+ OK(sdis_scene_set_temperature_range(scn, t_range));
interface_param->epsilon = 1;
interface_param->reference_temperature = 300;
@@ -569,8 +572,10 @@ main(int argc, char** argv)
/* Check same green used at different ambient radiative temperature */
trad.temperature = 600;
+ t_range[0] = 300;
+ t_range[1] = 600;
OK(sdis_scene_set_ambient_radiative_temperature(scn, &trad));
- OK(sdis_scene_set_maximum_temperature(scn, 600));
+ OK(sdis_scene_set_temperature_range(scn, t_range));
OK(sdis_solve_probe(scn, &solve_args, &estimator));
OK(sdis_green_function_solve(green, &estimator2));