commit 938eb33caf2407a06b3ea78f20001b3e1176e0f7
parent 52a837058feb2802e8adcd86a50d0a3ce81a701d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 26 Mar 2024 09:05:19 +0100
Relaxing constraints on the initial time of a medium
It had to be positive and less than infinity. Now it can be negative and
fixed at +/- infinity. So we can now define a medium that is always or
never in its initial state, which can be useful in certain cases.
For example, if we want to simulate a conducting medium whose
temperature is unknown even in its initial state, with a spatio-temporal
dirichlet condition, i.e. a surrounding interface whose temperature is
known at any point and at any time. In this particular case, we'd like
to ensure that conduction always reaches the limits and never its
initial state, which is in fact unknown. Hence an initial time fixed at
-infinity.
Diffstat:
3 files changed, 41 insertions(+), 36 deletions(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -247,8 +247,9 @@ struct sdis_solid_shader {
* This getter is always called at time >= t0 (see below). */
sdis_medium_getter_T temperature;
- /* The time until the initial condition is maintained for this solid;
- * can neither be negative nor infinity, default is 0. */
+ /* The time until the initial condition is maintained for this solid.
+ * Can be negative or set to +/- infinity to simulate a system that is always
+ * in the initial state or never reaches it, respectively. */
double t0;
};
#define SDIS_SOLID_SHADER_NULL__ {NULL, NULL, NULL, NULL, NULL, NULL, 0}
@@ -265,8 +266,10 @@ struct sdis_fluid_shader {
* unknown for the submitted random walk vertex.
* This getter is always called at time >= t0 (see below). */
sdis_medium_getter_T temperature;
- /* The time until the initial condition is maintained for this fluid;
- * can neither be negative nor infinity, default is 0. */
+
+ /* The time until the initial condition is maintained for this fluid.
+ * Can be negative or set to +/- infinity to simulate a system that is always
+ * in the initial state or never reaches it, respectively. */
double t0;
};
#define SDIS_FLUID_SHADER_NULL__ {NULL, NULL, NULL, 0}
diff --git a/src/sdis_medium.c b/src/sdis_medium.c
@@ -23,26 +23,30 @@
/*******************************************************************************
* Helper functions
******************************************************************************/
-static int
+static res_T
check_fluid_shader(const struct sdis_fluid_shader* shader)
{
- ASSERT(shader);
- return shader->calorific_capacity
- && shader->volumic_mass
- && shader->temperature
- && 0 <= shader->t0 && shader->t0 < INF;
+ if(!shader
+ || !shader->calorific_capacity
+ || !shader->volumic_mass
+ || !shader->temperature)
+ return RES_BAD_ARG;
+
+ return RES_OK;
}
-static int
+static res_T
check_solid_shader(const struct sdis_solid_shader* shader)
{
- ASSERT(shader);
- return shader->calorific_capacity
- && shader->thermal_conductivity
- && shader->volumic_mass
- && shader->delta
- && shader->temperature
- && 0 <= shader->t0 && shader->t0 < INF;
+ if(!shader
+ || !shader->calorific_capacity
+ || !shader->thermal_conductivity
+ || !shader->volumic_mass
+ || !shader->delta
+ || !shader->temperature)
+ return RES_BAD_ARG;
+
+ return RES_OK;
}
static res_T
@@ -108,14 +112,11 @@ sdis_fluid_create
struct sdis_medium* medium = NULL;
res_T res = RES_OK;
- if(!dev || !shader || !out_medium) {
- res = RES_BAD_ARG;
- goto error;
- }
+ if(!dev || !out_medium) { res = RES_BAD_ARG; goto error; }
- if(!check_fluid_shader(shader)) {
+ res = check_fluid_shader(shader);
+ if(res != RES_OK) {
log_err(dev, "%s: invalid fluid shader.\n", FUNC_NAME);
- res = RES_BAD_ARG;
goto error;
}
@@ -162,14 +163,11 @@ sdis_solid_create
struct sdis_medium* medium = NULL;
res_T res = RES_OK;
- if(!dev || !shader || !out_medium) {
- res = RES_BAD_ARG;
- goto error;
- }
+ if(!dev || !out_medium) { res = RES_BAD_ARG; goto error; }
- if(!check_solid_shader(shader)) {
+ res = check_solid_shader(shader);
+ if(res != RES_OK) {
log_err(dev, "%s: invalid solid shader.\n", FUNC_NAME);
- res = RES_BAD_ARG;
goto error;
}
diff --git a/src/test_sdis_medium.c b/src/test_sdis_medium.c
@@ -63,10 +63,12 @@ main(int argc, char** argv)
BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));
fluid_shader.temperature = DUMMY_FLUID_SHADER.temperature;
- fluid_shader.t0 = -1;
- BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));
+ fluid_shader.t0 = -INF;
+ OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));
+ OK(sdis_medium_ref_put(fluid));
fluid_shader.t0 = INF;
- BA(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));
+ OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));
+ OK(sdis_medium_ref_put(fluid));
fluid_shader.t0 = DUMMY_FLUID_SHADER.t0;
BA(sdis_fluid_create(dev, &SDIS_FLUID_SHADER_NULL, NULL, &fluid));
@@ -106,10 +108,12 @@ main(int argc, char** argv)
BA(sdis_solid_create(dev, &solid_shader, NULL, &solid));
solid_shader.temperature = DUMMY_SOLID_SHADER.temperature;
- solid_shader.t0 = -1;
- BA(sdis_solid_create(dev, &solid_shader, NULL, &solid));
+ solid_shader.t0 = -INF;
+ OK(sdis_solid_create(dev, &solid_shader, NULL, &solid));
+ OK(sdis_medium_ref_put(solid));
solid_shader.t0 = INF;
- BA(sdis_solid_create(dev, &solid_shader, NULL, &solid));
+ OK(sdis_solid_create(dev, &solid_shader, NULL, &solid));
+ OK(sdis_medium_ref_put(solid));
solid_shader.t0 = DUMMY_SOLID_SHADER.t0;
OK(sdis_fluid_create(dev, &fluid_shader, NULL, &fluid));