stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit bf832062f9fcbdf6633d22db5c43b36a46066535
parent 6c0d2815606738aded434ba06c7787a8899862e0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 18 Apr 2024 11:46:03 +0200

Added support for diffuse radiance from an external source

This diffuse radiance is supported both for a spherical source with
constant parameters (SPHERICAL_SOURCE keyword) and for a programmable
source (SPHERICAL_SOURCE_PROG keyword). In the former case, we simply
evaluate a new argument defining this diffuse radiance, while in the
latter, a new function is dynamically loaded from the program describing
the source.

The manual page for the stardis-input file format is updated
accordingly.

Diffstat:
Mdoc/stardis-input.5.in | 5+++--
Msrc/stardis-extern-source.c | 29+++++++++++++++++++++++++++--
Msrc/stardis-extern-source.h | 11+++++++++--
Msrc/stardis-parsing.c | 12+++++++++++-
Msrc/stardis-prog-properties.h.in | 11+++++++++++
5 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/doc/stardis-input.5.in b/doc/stardis-input.5.in @@ -12,7 +12,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with this program. If not, see <http://www.gnu.org/licenses/>. -.Dd April 13, 2024 +.Dd April 18, 2024 .Dt STARDIS-INPUT 5 .Os .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -263,7 +263,7 @@ that changes at .\" External source .It Ao Va ext-source Ac Ta ::= Ta Ao Va ext-source-const Ac | Ao Va ext-source-prog Ac .It Ao Va ext-source-const Ac Ta ::= Ta Li SPHERICAL_SOURCE Ao Va radius Ac Ao Va position Ac \e -.It Ta Ta Ao Va power Ac +.It Ta Ta Ao Va power Ac Ao Va diffuse-radiance Ac .It Ao Va ext-source-prog Ac Ta ::= Ta Li SPHERICAL_SOURCE_PROG Ao Va radius Ac \e .It Ta Ta Ao Va prog-name Ac Op Li PROG_PARAMS Op Ao Va args Ac .It \ Ta Ta @@ -273,6 +273,7 @@ that changes at .It Ao Va outside-temp Ac Ta ::= Ta Vt real No # Temperature > 0 [K] .It Ao Va flux Ac Ta ::= Ta Vt real No # [W/m^2] .It Ao Va power Ac Ta ::= Ta Vt real No # [W] +.It Ao Va diffuse-radiance Ac Ta ::= Ta Vt real No # [W/m^2/sr] .It Ao Va position Ac Ta ::= Ta Vt real real real .It Ao Va radius Ac Ta ::= Ta Vt real .El diff --git a/src/stardis-extern-source.c b/src/stardis-extern-source.c @@ -46,6 +46,19 @@ sphere_get_power(const double time, struct sdis_data* data) return src->power; /* [W] */ } +static double +sphere_get_diffuse_radiance + (const double time, + const double dir[3], + struct sdis_data* data) +{ + const struct spherical_source* src = NULL; + (void)time, (void)dir; + + src = *((const struct spherical_source* const*)sdis_data_cget(data)); + return src->diffuse_radiance; /* [W/m^2/sr] */ +} + static res_T create_solver_source_sphere (struct extern_source* src, @@ -66,6 +79,7 @@ create_solver_source_sphere /* Create the spherical source */ args.position = sphere_get_position; args.power = sphere_get_power; + args.diffuse_radiance = sphere_get_diffuse_radiance; args.data = data; args.radius = src->data.sphere.radius; res = sdis_spherical_source_create(stardis->dev, &args, &src->sdis_src); @@ -87,7 +101,6 @@ sphere_prog_get_position(const double time, double pos[3], struct sdis_data* dat { const struct spherical_source_prog* src = NULL; ASSERT(pos); - (void)time; src = *((const struct spherical_source_prog* const*)sdis_data_cget(data)); src->position(time, pos, src->data);; @@ -97,12 +110,23 @@ static double sphere_prog_get_power(const double time, struct sdis_data* data) { const struct spherical_source_prog* src = NULL; - (void)time; src = *((const struct spherical_source_prog* const*)sdis_data_cget(data)); return src->power(time, src->data); } +static double +sphere_prog_get_diffuse_radiance + (const double time, + const double dir[3], + struct sdis_data* data) +{ + const struct spherical_source_prog* src = NULL; + + src = *((const struct spherical_source_prog* const*)sdis_data_cget(data)); + return src->diffuse_radiance(time, dir, src->data); +} + static res_T create_solver_source_sphere_prog (struct extern_source* src, @@ -123,6 +147,7 @@ create_solver_source_sphere_prog /* Create the spherical source */ args.position = sphere_prog_get_position; args.power = sphere_prog_get_power; + args.diffuse_radiance = sphere_prog_get_diffuse_radiance; args.data = data; args.radius = src->data.sphere_prog.radius; res = sdis_spherical_source_create(stardis->dev, &args, &src->sdis_src); diff --git a/src/stardis-extern-source.h b/src/stardis-extern-source.h @@ -32,8 +32,9 @@ struct spherical_source { double position[3]; double radius; double power; /* [W] */ + double diffuse_radiance; /* [W/m^2/sr] */ }; -#define SPHERICAL_SOURCE_NULL__ {{0,0,0}, -1, 0} +#define SPHERICAL_SOURCE_NULL__ {{0,0,0}, -1, 0, 0} static const struct spherical_source SPHERICAL_SOURCE_NULL = SPHERICAL_SOURCE_NULL__; @@ -70,9 +71,15 @@ struct spherical_source_prog { (*power) (const double time, void* data); + + double + (*diffuse_radiance) + (const double time, + const double dir[3], + void* data); }; #define SPHERICAL_SOURCE_PROG_NULL__ \ - {{0}, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL} + {{0}, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL} static const struct spherical_source_prog SPHERICAL_SOURCE_PROG_NULL= SPHERICAL_SOURCE_PROG_NULL__; diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -2197,7 +2197,16 @@ process_spherical_source if(res == RES_OK && src->power < 0) res = RES_BAD_ARG; if(res != RES_OK) { logger_print(stardis->logger, LOG_ERROR, - "Invalid sphercial source power: %s\n", arg); + "Invalid spherical source power: %s\n", arg); + goto error; + } + + CHK_ARG(idx, "diffuse radiance"); + res = cstr_to_double(arg, &src->diffuse_radiance); + if(res == RES_OK && src->diffuse_radiance < 0) res = RES_BAD_ARG; + if(res != RES_OK) { + logger_print(stardis->logger, LOG_ERROR, + "Invalid diffuse radiance for the spherical source: %s\n", arg); goto error; } @@ -2261,6 +2270,7 @@ process_spherical_source_prog(struct stardis* stardis, wordexp_t* pwordexp) ERR(get_prog_common(lib_name, stardis, &src->program, &src->create, &src->release)); GET_LIB_SYMBOL(src, position, stardis_spherical_source_position); GET_LIB_SYMBOL(src, power, stardis_spherical_source_power); + GET_LIB_SYMBOL(src, diffuse_radiance, stardis_spherical_source_diffuse_radiance); ctx.name = "External spherical source"; src->data = src->create(&ctx, src->program->prog_data, src->argc, src->argv); diff --git a/src/stardis-prog-properties.h.in b/src/stardis-prog-properties.h.in @@ -631,6 +631,17 @@ stardis_spherical_source_power (const double time, void* data); +/* Describes the diffuse part of the source's radiance, i.e. the radiance + * emitted by the source and scattered at least once in the environment. This + * parameter is actually used to approximate a semi-transparent medium. Its + * value can be 0, meaning that the source has not been scattered by the + * environment, or, to put it another way, that the source is in a vacuum. */ +STARDIS_API double /* [W/m^2/sr] */ +stardis_spherical_source_diffuse_radiance + (const double time, + const double dir[3], + void* data); + /******************************************************************************/ /* Additional mandatory functions for a programmed radiative environment */ /******************************************************************************/