commit 764c44397dd00f5cd3ca941ba2c8341f9f5ba0bf
parent a333d6ab323c63e51a9a6b150d6c7a48e4b19667
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 12 Apr 2024 18:45:28 +0200
Fix compilation due to solver API breaks
The functor returning emissivity and specular fraction now depends on
the radiation source. Although we update the function profiles
accordingly, we don't use this new parameter yet, i.e. emissivity and
specular fraction remain the same regardless of the radiation source.
The way the radiative environment is handled has been completely updated
on the solver side. It is no longer a POD structure. It becomes an
opaque data structure like other physical properties such as interfaces
or media, whose values are controlled by caller-side functors. This
commit adjusts the Stardis code accordingly.
Note that this update also prepares for the radiative environment to be
programmable. And it seems that resolving a green function with any
programmable properties is not currently handled correctly. It is not
supported and no errors are reported. We need to look into this further.
In fact, the whole green function section seems to need to be carefully
reviewed and perhaps rewritten.
Diffstat:
8 files changed, 380 insertions(+), 155 deletions(-)
diff --git a/Makefile b/Makefile
@@ -46,6 +46,7 @@ SRC =\
src/stardis-output.c\
src/stardis-parsing.c\
src/stardis-program.c\
+ src/stardis-radiative-env.c\
src/stardis-sfconnect.c\
src/stardis-sfconnect-prog.c\
src/stardis-ssconnect.c\
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -270,9 +270,8 @@ stardis_init
stardis->nthreads = args->nthreads;
stardis->picard_order = args->picard_order;
stardis->scale_factor = -1; /* invalid value */
- stardis->trad = STARDIS_DEFAULT_TRAD;
- stardis->trad_ref = STARDIS_DEFAULT_TRAD_REFERENCE;
- stardis->trad_def = 0;
+ stardis->radenv = RADIATIVE_ENV_DEFAULT;
+ stardis->radenv_def = 0;
stardis->initial_time = args->initial_time;
stardis->geometry_initialized = 0;
d2(stardis->t_range, INF, -INF);
@@ -507,17 +506,20 @@ stardis_init
struct sdis_scene_create_args scn_args = SDIS_SCENE_CREATE_ARGS_DEFAULT;
ASSERT(darray_interface_ptrs_size_get(&stardis->geometry.interf_bytrg)
== tcount);
+
+ res = radiative_env_create_solver_radiative_env(&stardis->radenv, stardis);
+ if(res != RES_OK) goto error;
+
scn_args.get_indices = sg3d_sdisXd_geometry_get_indices;
scn_args.get_interface = sg3d_sdisXd_geometry_get_interface;
scn_args.get_position = sg3d_sdisXd_geometry_get_position;
scn_args.nprimitives = tcount;
scn_args.nvertices = vcount;
scn_args.fp_to_meter = stardis->scale_factor;
- scn_args.trad.temperature = stardis->trad;
- scn_args.trad.reference = stardis->trad_ref;
scn_args.t_range[0] = stardis->t_range[0];
scn_args.t_range[1] = stardis->t_range[1];
scn_args.source = stardis->extsrc.sdis_src;
+ scn_args.radenv = stardis->radenv.sdis_radenv;
scn_args.context = &create_context;
/* Setting Tmax to 0 is a way of setting the radiative coefficient to 0, and
@@ -566,6 +568,7 @@ stardis_release
str_release(&stardis->chunks_prefix);
extern_source_release(&stardis->extsrc);
+ radiative_env_release(&stardis->radenv);
/* release non-PROGRAM descritions first */
FOR_EACH(i, 0, darray_descriptions_size_get(&stardis->descriptions)) {
diff --git a/src/stardis-app.h b/src/stardis-app.h
@@ -19,6 +19,7 @@
#include "stardis-args.h"
#include "stardis-description.h"
#include "stardis-extern-source.h"
+#include "stardis-radiative-env.h"
#include <star/sg3d.h>
@@ -225,13 +226,13 @@ struct stardis {
struct mem_allocator* allocator;
struct logger* logger;
struct sdis_device* dev;
+ struct radiative_env radenv;
+ int radenv_def;
size_t samples;
double scale_factor;
- double trad, trad_ref;
double t_range[2];
double initial_time; /* [s] */
int mode;
- int trad_def;
unsigned nthreads;
unsigned picard_order;
unsigned next_medium_id;
diff --git a/src/stardis-intface.c b/src/stardis-intface.c
@@ -80,20 +80,22 @@ interface_get_ref_temperature
static double
interface_get_emissivity
(const struct sdis_interface_fragment* frag,
+ const unsigned source_id,
struct sdis_data* data)
{
const struct intface* interface_props = sdis_data_cget(data);
- (void)frag;
+ (void)frag, (void)source_id;
return interface_props->emissivity;
}
static double
interface_get_alpha
(const struct sdis_interface_fragment* frag,
+ const unsigned source_id,
struct sdis_data* data)
{
const struct intface* interface_props = sdis_data_cget(data);
- (void)frag;
+ (void)frag, (void)source_id;
return interface_props->alpha;
}
@@ -167,10 +169,12 @@ intface_prog_get_hc
static double
intface_prog_get_emissivity
(const struct sdis_interface_fragment* frag,
+ const unsigned source_id,
struct sdis_data* data)
{
const struct intface* interface_props = sdis_data_cget(data);
struct stardis_interface_fragment f;
+ (void)source_id;
d3_set(f.P, frag->P);
d3_set(f.Ng, frag->Ng);
d3_set(f.uv, frag->uv);
@@ -183,10 +187,12 @@ intface_prog_get_emissivity
static double
intface_prog_get_alpha
(const struct sdis_interface_fragment* frag,
+ const unsigned source_id,
struct sdis_data* data)
{
const struct intface* interface_props = sdis_data_cget(data);
struct stardis_interface_fragment f;
+ (void)source_id;
d3_set(f.P, frag->P);
d3_set(f.Ng, frag->Ng);
d3_set(f.uv, frag->uv);
diff --git a/src/stardis-output.c b/src/stardis-output.c
@@ -648,82 +648,79 @@ medium_get_t0
}
static res_T
-dump_sample_end
- (struct sdis_green_path* path,
- void* ctx)
+dump_sample_end(struct sdis_green_path* path, void* ctx)
{
- res_T res = RES_OK;
+ /* Stardis */
+ struct sdis_green_path_end end = SDIS_GREEN_PATH_END_NULL;
+ struct sdis_data* data = NULL;
+ enum sdis_medium_type type;
+
+ /* Stream */
struct e_ctx* e_ctx = ctx;
- enum sdis_green_path_end_type end_type;
FILE* stream;
+
+ /* Miscellaneous */
+ const struct description* descs;
+ double* pos;
double elapsed;
size_t sz;
unsigned trad_id;
+ unsigned id;
+ res_T res = RES_OK;
CHK(path && ctx);
stream = e_ctx->stream;
ERR(sdis_green_path_get_elapsed_time(path, &elapsed));
- ERR(sdis_green_path_get_end_type(path, &end_type));
+ ERR(sdis_green_path_get_end(path, &end));
+
sz = darray_descriptions_size_get(e_ctx->desc);
- if(sz > UINT_MAX) goto abort;
+ if(sz > UINT_MAX) { res = RES_BAD_ARG; goto error; }
trad_id = (unsigned)sz;
- if(end_type == SDIS_GREEN_PATH_END_RADIATIVE) {
- /* End, End ID, X, Y, Z, Elapsed time */
- fprintf(stream, "TRAD, %u, 0, 0, 0, %g\n", trad_id, elapsed);
- } else {
- struct sdis_point pt = SDIS_POINT_NULL;
- struct sdis_data* data = NULL;
- enum sdis_medium_type type;
- const struct description* descs;
- double* pos;
- unsigned id;
-
- ERR(sdis_green_path_get_limit_point(path, &pt));
-
- descs = darray_descriptions_cdata_get(e_ctx->desc);
- switch(pt.type) {
- case SDIS_FRAGMENT: {
- struct intface* d__;
- data = sdis_interface_get_data(pt.data.itfrag.intface);
- pos = pt.data.itfrag.fragment.P;
- d__ = sdis_data_get(data);
- id = d__->desc_id;
- CHK(DESC_IS_T(descs+id) || DESC_IS_H(descs+id));
- break;
- }
- case SDIS_VERTEX:
- type = sdis_medium_get_type(pt.data.mdmvert.medium);
- data = sdis_medium_get_data(pt.data.mdmvert.medium);
- pos = pt.data.mdmvert.vertex.P;
- if(pt.data.mdmvert.vertex.P[0] == INF) {
- /* Radiative output (Trad) */
- id = trad_id;
- }
- else if(type == SDIS_FLUID) {
- struct fluid** pfluid = sdis_data_get(data);
- id = (*pfluid)->desc_id;
- } else {
- struct solid** psolid = sdis_data_get(data);
- ASSERT(type == SDIS_SOLID);
- ASSERT(!(*psolid)->is_outside); /* FIXME: what if in external solid? */
- id = (*psolid)->desc_id;
- }
- break;
- default: FATAL("Unreachable code.\n"); break;
+
+ descs = darray_descriptions_cdata_get(e_ctx->desc);
+ switch(end.type) {
+ case SDIS_GREEN_PATH_END_AT_RADIATIVE_ENV:
+ /* End, End ID, X, Y, Z, Elapsed time */
+ fprintf(stream, "TRAD, %u, 0, 0, 0, %g\n", trad_id, elapsed);
+ break;
+ case SDIS_GREEN_PATH_END_AT_INTERFACE: {
+ struct intface* d__;
+ data = sdis_interface_get_data(end.data.itfrag.intface);
+ pos = end.data.itfrag.fragment.P;
+ d__ = sdis_data_get(data);
+ id = d__->desc_id;
+ CHK(DESC_IS_T(descs+id) || DESC_IS_H(descs+id));
+ break;
}
- /* End, End ID, X, Y, Z, Elapsed time */
- fprintf(stream, "%s, %u, %g, %g, %g, %g\n",
- str_cget(get_description_name(descs + id)), id, SPLIT3(pos), elapsed);
+ case SDIS_GREEN_PATH_END_IN_VOLUME:
+ type = sdis_medium_get_type(end.data.mdmvert.medium);
+ data = sdis_medium_get_data(end.data.mdmvert.medium);
+ pos = end.data.mdmvert.vertex.P;
+ if(end.data.mdmvert.vertex.P[0] == INF) {
+ /* Radiative output (Trad) */
+ id = trad_id;
+ }
+ else if(type == SDIS_FLUID) {
+ struct fluid** pfluid = sdis_data_get(data);
+ id = (*pfluid)->desc_id;
+ } else {
+ struct solid** psolid = sdis_data_get(data);
+ ASSERT(type == SDIS_SOLID);
+ ASSERT(!(*psolid)->is_outside); /* FIXME: what if in external solid? */
+ id = (*psolid)->desc_id;
+ }
+ break;
+ default: FATAL("Unreachable code.\n"); break;
}
+ /* End, End ID, X, Y, Z, Elapsed time */
+ fprintf(stream, "%s, %u, %g, %g, %g, %g\n",
+ str_cget(get_description_name(descs + id)), id, SPLIT3(pos), elapsed);
end:
return res;
error:
goto end;
-abort:
- res = RES_BAD_ARG;
- goto error;
}
static res_T
@@ -731,75 +728,75 @@ dump_sample
(struct sdis_green_path* path,
void* ctx)
{
- res_T res = RES_OK;
- struct htable_weigth_iterator it, end;
- struct green_sample_header header;
+ /* Stardis variables */
+ struct sdis_green_path_end path_end = SDIS_GREEN_PATH_END_NULL;
+ struct sdis_data* data = NULL;
+ enum sdis_medium_type type;
+
+ /* Miscellaneous variables */
struct w_ctx* w_ctx = ctx;
- enum sdis_green_path_end_type end_type;
FILE* stream;
+ const struct description* descs;
+ struct htable_weigth_iterator it, end;
+ struct green_sample_header header;
unsigned* ids = NULL;
double* weights = NULL;
+ double t0;
size_t sz, i;
unsigned trad_id;
+ res_T res = RES_OK;
+
CHK(path && ctx);
stream = w_ctx->stream;
- ERR(sdis_green_path_get_end_type(path, &end_type));
+ ERR(sdis_green_path_get_end(path, &path_end));
sz = darray_descriptions_size_get(w_ctx->desc);
- if(sz > UINT_MAX) goto abort;
+ if(sz > UINT_MAX) { res = RES_BAD_ARG; goto error; }
trad_id = (unsigned)sz;
- if(end_type == SDIS_GREEN_PATH_END_RADIATIVE) {
- header.at_initial = 0;
- header.sample_end_description_id = trad_id;
- } else {
- struct sdis_point pt = SDIS_POINT_NULL;
- struct sdis_data* data = NULL;
- enum sdis_medium_type type;
- const struct description* descs;
- double t0;
-
- ERR(sdis_green_path_get_limit_point(path, &pt));
-
- /* For each path, dump:
- * # end_id #power_terms #flux_terms
- * power_id_1 ... power_id_n flux_id_1 ... flux_id_n
- * power_factor_1 ... power_factor_n flux_factor_1 ... flux_factor_n
- */
-
- descs = darray_descriptions_cdata_get(w_ctx->desc);
- switch(pt.type) {
- case SDIS_FRAGMENT: {
- struct intface* d__;
- unsigned desc_id;
- data = sdis_interface_get_data(pt.data.itfrag.intface);
- d__ = sdis_data_get(data);
- desc_id = d__->desc_id;
- CHK(DESC_IS_T(descs+desc_id) || DESC_IS_H(descs+desc_id));
- header.sample_end_description_id = desc_id;
- header.at_initial = 0;
- break;
- }
- case SDIS_VERTEX:
- type = sdis_medium_get_type(pt.data.mdmvert.medium);
- data = sdis_medium_get_data(pt.data.mdmvert.medium);
- t0 = medium_get_t0(pt.data.mdmvert.medium);
- header.at_initial = (pt.data.mdmvert.vertex.time <= t0);
- if(pt.data.mdmvert.vertex.P[0] == INF) {
- /* Radiative output (Trad) */
- header.sample_end_description_id = trad_id;
- }
- else if(type == SDIS_FLUID) {
- struct fluid** pfluid = sdis_data_get(data);
- header.sample_end_description_id = (*pfluid)->desc_id;
- } else {
- struct solid** psolid = sdis_data_get(data);
- ASSERT(type == SDIS_SOLID);
- ASSERT(!(*psolid)->is_outside); /* FIXME: what if in external solid? */
- header.sample_end_description_id = (*psolid)->desc_id;
- }
- break;
- default: FATAL("Unreachable code.\n"); break;
+
+ /* For each path, dump:
+ * # end_id #power_terms #flux_terms
+ * power_id_1 ... power_id_n flux_id_1 ... flux_id_n
+ * power_factor_1 ... power_factor_n flux_factor_1 ... flux_factor_n
+ */
+
+ descs = darray_descriptions_cdata_get(w_ctx->desc);
+ switch(path_end.type) {
+ case SDIS_GREEN_PATH_END_AT_RADIATIVE_ENV:
+ header.at_initial = 0;
+ header.sample_end_description_id = trad_id;
+ break;
+ case SDIS_GREEN_PATH_END_AT_INTERFACE: {
+ struct intface* d__;
+ unsigned desc_id;
+ data = sdis_interface_get_data(path_end.data.itfrag.intface);
+ d__ = sdis_data_get(data);
+ desc_id = d__->desc_id;
+ CHK(DESC_IS_T(descs+desc_id) || DESC_IS_H(descs+desc_id));
+ header.sample_end_description_id = desc_id;
+ header.at_initial = 0;
+ break;
}
+ case SDIS_GREEN_PATH_END_IN_VOLUME:
+ type = sdis_medium_get_type(path_end.data.mdmvert.medium);
+ data = sdis_medium_get_data(path_end.data.mdmvert.medium);
+ t0 = medium_get_t0(path_end.data.mdmvert.medium);
+ header.at_initial = (path_end.data.mdmvert.vertex.time <= t0);
+ if(path_end.data.mdmvert.vertex.P[0] == INF) {
+ /* Radiative output (Trad) */
+ header.sample_end_description_id = trad_id;
+ }
+ else if(type == SDIS_FLUID) {
+ struct fluid** pfluid = sdis_data_get(data);
+ header.sample_end_description_id = (*pfluid)->desc_id;
+ } else {
+ struct solid** psolid = sdis_data_get(data);
+ ASSERT(type == SDIS_SOLID);
+ ASSERT(!(*psolid)->is_outside); /* FIXME: what if in external solid? */
+ header.sample_end_description_id = (*psolid)->desc_id;
+ }
+ break;
+ default: FATAL("Unreachable code.\n"); break;
}
/* Merge power and flux terms */
@@ -808,10 +805,10 @@ dump_sample
ERR(sdis_green_path_for_each_power_term(path, merge_power_terms, w_ctx));
ERR(sdis_green_path_for_each_flux_term(path, merge_flux_terms, w_ctx));
sz = htable_weigth_size_get(&w_ctx->pw);
- if(sz > UINT_MAX) goto abort;
+ if(sz > UINT_MAX) { res = RES_BAD_ARG; goto error; }
header.pw_count = (unsigned)sz;
sz = htable_weigth_size_get(&w_ctx->flux);
- if(sz > UINT_MAX) goto abort;
+ if(sz > UINT_MAX) { res = RES_BAD_ARG; goto error; }
header.fx_count = (unsigned)sz;
/* Write path's header */
@@ -863,9 +860,6 @@ end:
return res;
error:
goto end;
-abort:
- res = RES_BAD_ARG;
- goto error;
}
res_T
@@ -874,15 +868,21 @@ dump_green_bin
const struct stardis* stardis,
FILE* stream)
{
- res_T res = RES_OK;
- size_t sz, i;
- struct w_ctx w_ctx;
- int table_initialized = 0;
/* The following type must be identical to its stardis-green counterpart! */
struct green_file_header header;
+ const struct radiative_env_const* radenv_const = NULL;
+ struct w_ctx w_ctx;
+ size_t sz, i;
+ int table_initialized = 0;
+ res_T res = RES_OK;
ASSERT(green && stardis && stream);
+ /* Stardis can produce the green function on systems
+ * with constant properties only */
+ ASSERT(stardis->radenv.type == RADIATIVE_ENV_CONST);
+ radenv_const = &stardis->radenv.data.cst;
+
/* Init header */
strcpy(header.green_string, BIN_FILE_IDENT_STRING);
header.file_format_version = GREEN_FILE_FORMAT_VERSION;
@@ -903,8 +903,9 @@ dump_green_bin
+ stardis->counts.fbound_count + stardis->counts.sfconnect_count
+ stardis->counts.ssconnect_count));
header.description_count = (unsigned)sz;
- header.ambient_radiative_temperature = stardis->trad;
- header.ambient_radiative_temperature_reference = stardis->trad_ref;
+ header.ambient_radiative_temperature = radenv_const->temperature;
+ header.ambient_radiative_temperature_reference =
+ radenv_const->reference_temperature;
d2_set(header.time_range, stardis->time_range);
/* Write header */
@@ -967,7 +968,7 @@ print_sample
void* ctx)
{
res_T res = RES_OK;
- struct sdis_point pt = SDIS_POINT_NULL;
+ struct sdis_green_path_end path_end = SDIS_GREEN_PATH_END_NULL;
struct sdis_data* data = NULL;
enum sdis_medium_type type;
struct htable_weigth_iterator it, end;
@@ -977,7 +978,7 @@ print_sample
const struct description* descs;
CHK(path && ctx);
- ERR(sdis_green_path_get_limit_point(path, &pt));
+ ERR(sdis_green_path_get_end(path, &path_end));
/* For each path, prints:
* # end #power_terms #flux_terms power_term_1 ... power_term_n flux_term_1 ... flux_term_n
@@ -988,10 +989,10 @@ print_sample
*/
descs = darray_descriptions_cdata_get(w_ctx->desc);
- switch (pt.type) {
- case SDIS_FRAGMENT: {
+ switch (path_end.type) {
+ case SDIS_GREEN_PATH_END_AT_INTERFACE: {
struct intface* d__;
- data = sdis_interface_get_data(pt.data.itfrag.intface);
+ data = sdis_interface_get_data(path_end.data.itfrag.intface);
d__ = sdis_data_get(data);
desc_id = d__->desc_id;
switch (descs[desc_id].type) {
@@ -1009,10 +1010,10 @@ print_sample
}
break;
}
- case SDIS_VERTEX:
- type = sdis_medium_get_type(pt.data.mdmvert.medium);
- data = sdis_medium_get_data(pt.data.mdmvert.medium);
- if(pt.data.mdmvert.vertex.P[0] == INF) {
+ case SDIS_GREEN_PATH_END_IN_VOLUME:
+ type = sdis_medium_get_type(path_end.data.mdmvert.medium);
+ data = sdis_medium_get_data(path_end.data.mdmvert.medium);
+ if(path_end.data.mdmvert.vertex.P[0] == INF) {
/* Radiative output (Trad)*/
size_t sz = darray_descriptions_size_get(w_ctx->desc);
if(sz > UINT_MAX) goto abort;
@@ -1085,6 +1086,7 @@ dump_green_ascii
FILE* stream)
{
res_T res = RES_OK;
+ const struct radiative_env_const* radenv_const = NULL;
unsigned ok_count, failed_count;
size_t sz;
struct w_ctx w_ctx;
@@ -1094,6 +1096,11 @@ dump_green_ascii
ASSERT(green && stardis && stream);
+ /* Stardis can produce the green function on systems
+ * with constant properties only */
+ ASSERT(stardis->radenv.type == RADIATIVE_ENV_CONST);
+ radenv_const = &stardis->radenv.data.cst;
+
ERR(sdis_green_function_get_paths_count(green, &sz));
if(sz > UINT_MAX) goto abort;
ok_count = (unsigned)sz;
@@ -1211,7 +1218,7 @@ dump_green_ascii
fprintf(stream, "# Radiative Temperatures\n");
fprintf(stream, "# ID Trad Trad_Ref\n");
fprintf(stream, "%u\t%g\t%g\n",
- szd, stardis->trad, stardis->trad_ref);
+ szd, radenv_const->temperature, radenv_const->reference_temperature);
fprintf(stream, "# Samples\n");
fprintf(stream,
diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c
@@ -2011,37 +2011,44 @@ process_radiative
(struct stardis* stardis,
wordexp_t* pwordexp)
{
+ double trad = 0;
+ double tref = 0;
char* arg = NULL;
size_t idx = 1;
res_T res = RES_OK;
ASSERT(stardis && pwordexp);
- if(stardis->trad_def) {
+ if(stardis->radenv_def) {
logger_print(stardis->logger, LOG_ERROR,
"TRAD cannot be specified twice\n");
res = RES_BAD_ARG;
goto end;
}
+
+ res = radiative_env_init_const(stardis->allocator, &stardis->radenv);
+ if(res != RES_OK) goto error;
+
CHK_ARG(idx, "Trad");
- res = cstr_to_double(arg, &stardis->trad);
- if(res != RES_OK || SDIS_TEMPERATURE_IS_UNKNOWN(stardis->trad)) {
+ res = cstr_to_double(arg, &trad);
+ if(res != RES_OK || SDIS_TEMPERATURE_IS_UNKNOWN(trad)) {
logger_print(stardis->logger, LOG_ERROR,
"Invalid Trad: %s\n", arg);
if(res == RES_OK) res = RES_BAD_ARG;
goto end;
}
CHK_ARG(idx, "Trad reference");
- res = cstr_to_double(arg, &stardis->trad_ref);
- if(res != RES_OK
- || stardis->trad_ref < 0)
- {
+ res = cstr_to_double(arg, &tref);
+ if(res != RES_OK || tref < 0) {
logger_print(stardis->logger, LOG_ERROR,
"Invalid Trad reference: %s\n", arg);
if(res == RES_OK) res = RES_BAD_ARG;
goto end;
}
- stardis->trad_def = 1;
+
+ stardis->radenv.data.cst.temperature = trad;
+ stardis->radenv.data.cst.reference_temperature = tref;
+ stardis->radenv_def = 1;
end:
return res;
@@ -2435,10 +2442,14 @@ exp_error:
stardis->scale_factor = STARDIS_DEFAULT_SCALE_FACTOR;
logger_print(stardis->logger, LOG_OUTPUT,
"Scaling factor is %g\n", stardis->scale_factor);
- logger_print(stardis->logger, LOG_OUTPUT,
- "Trad is %g, Trad reference is %g\n", stardis->trad, stardis->trad_ref);
- stardis->t_range[0] = MMIN(stardis->t_range[0], stardis->trad_ref);
- stardis->t_range[1] = MMAX(stardis->t_range[1], stardis->trad_ref);
+ if(stardis->radenv.type == RADIATIVE_ENV_CONST) {
+ const double trad = stardis->radenv.data.cst.temperature;
+ const double trad_ref = stardis->radenv.data.cst.reference_temperature;
+ logger_print(stardis->logger, LOG_OUTPUT,
+ "Trad is %g, Trad reference is %g\n", trad, trad_ref);
+ stardis->t_range[0] = MMIN(stardis->t_range[0], trad_ref);
+ stardis->t_range[1] = MMAX(stardis->t_range[1], trad_ref);
+ }
logger_print(stardis->logger, LOG_OUTPUT,
"System T range is [%g %g]\n", SPLIT2(stardis->t_range));
logger_print(stardis->logger, LOG_OUTPUT,
diff --git a/src/stardis-radiative-env.c b/src/stardis-radiative-env.c
@@ -0,0 +1,124 @@
+/* Copyright (C) 2018-2023 |Méso|Star> (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "stardis-app.h"
+#include "stardis-radiative-env.h"
+
+#include <sdis.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static double
+radenv_get_temperature
+ (const struct sdis_radiative_ray* ray,
+ struct sdis_data* data)
+{
+ const struct radiative_env_const* props = sdis_data_cget(data);
+ (void)ray;
+ return props->temperature;
+}
+
+static double
+radenv_get_reference_temperature
+ (const struct sdis_radiative_ray* ray,
+ struct sdis_data* data)
+{
+ const struct radiative_env_const* props = sdis_data_cget(data);
+ (void)ray;
+ return props->reference_temperature;
+}
+
+static res_T
+create_radenv_const
+ (struct radiative_env* radenv,
+ struct stardis* stardis)
+{
+ struct sdis_radiative_env_shader shader = SDIS_RADIATIVE_ENV_SHADER_NULL;
+ struct sdis_data* data = NULL;
+ struct radiative_env_const* props = NULL;
+ res_T res = RES_OK;
+ ASSERT(radenv && stardis);
+
+ res = sdis_data_create(stardis->dev, sizeof(struct radiative_env_const),
+ ALIGNOF(struct radiative_env_const), NULL, &data);
+ if(res != RES_OK) goto error;
+ props = sdis_data_get(data);
+ *props = radenv->data.cst;
+
+ shader.temperature = radenv_get_temperature;
+ shader.reference_temperature = radenv_get_reference_temperature;
+ res = sdis_radiative_env_create
+ (stardis->dev, &shader, data, &radenv->sdis_radenv);
+ if(res != RES_OK) goto error;
+
+exit:
+ if(data) SDIS(data_ref_put(data));
+ if(radenv->sdis_radenv) {
+ SDIS(radiative_env_ref_put(radenv->sdis_radenv));
+ radenv->sdis_radenv = NULL;
+ }
+ return res;
+error:
+ goto exit;
+}
+
+/*******************************************************************************
+ * Local function
+ ******************************************************************************/
+res_T
+radiative_env_init_const
+ (struct mem_allocator* allocator,
+ struct radiative_env* radenv)
+{
+ ASSERT(radenv);
+ (void)allocator;
+ radenv->type = RADIATIVE_ENV_CONST;
+ radenv->data.cst = RADIATIVE_ENV_CONST_DEFAULT;
+ return RES_OK;
+}
+
+void
+radiative_env_release(struct radiative_env* radenv)
+{
+ ASSERT(radenv);
+ if(radenv->sdis_radenv) SDIS(radiative_env_ref_put(radenv->sdis_radenv));
+ radenv->sdis_radenv = NULL;
+}
+
+res_T
+radiative_env_create_solver_radiative_env
+ (struct radiative_env* radenv,
+ struct stardis* stardis)
+{
+ res_T res = RES_OK;
+ ASSERT(radenv && stardis);
+
+ switch(radenv->type) {
+ case RADIATIVE_ENV_CONST:
+ res = create_radenv_const(radenv, stardis);
+ if(res != RES_OK) goto error;
+ break;
+ case RADIATIVE_ENV_PROG:
+ /* TODO */
+ break;
+ default: FATAL("Unreachable code.\n"); break;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
diff --git a/src/stardis-radiative-env.h b/src/stardis-radiative-env.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 2018-2023 |Méso|Star> (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef STARDIS_RADIATIVE_ENV_H
+#define STARDIS_RADIATIVE_ENV_H
+
+#include "stardis-default.h"
+#include <rsys/rsys.h>
+
+/* Forward declaration */
+struct stardis;
+
+enum radiative_env_type {
+ RADIATIVE_ENV_CONST,
+ RADIATIVE_ENV_PROG
+};
+
+struct radiative_env_const {
+ double temperature;
+ double reference_temperature;
+};
+#define RADIATIVE_ENV_CONST_DEFAULT__ { \
+ STARDIS_DEFAULT_TRAD, \
+ STARDIS_DEFAULT_TRAD_REFERENCE \
+}
+static const struct radiative_env_const RADIATIVE_ENV_CONST_DEFAULT =
+ RADIATIVE_ENV_CONST_DEFAULT__;
+
+struct radiative_env_prog { char dummy; }; /* TODO */
+
+struct radiative_env {
+ enum radiative_env_type type;
+ union {
+ struct radiative_env_const cst;
+ struct radiative_env_prog prg;
+ } data;
+ struct sdis_radiative_env* sdis_radenv;
+};
+#define RADIATIVE_ENV_DEFAULT__ { \
+ RADIATIVE_ENV_CONST, \
+ {RADIATIVE_ENV_CONST_DEFAULT__}, \
+ NULL \
+}
+static const struct radiative_env RADIATIVE_ENV_DEFAULT = RADIATIVE_ENV_DEFAULT__;
+
+extern LOCAL_SYM res_T
+radiative_env_init_const
+ (struct mem_allocator* allocator,
+ struct radiative_env* radenv);
+
+extern LOCAL_SYM void
+radiative_env_release
+ (struct radiative_env* radenv);
+
+extern LOCAL_SYM res_T
+radiative_env_create_solver_radiative_env
+ (struct radiative_env* radenv,
+ struct stardis* stardis);
+
+#endif /* STARDIS_RADIATIVE_ENV_H */