stardis

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

commit 030dbe9af79d9705823389b38c19c44766814716
parent 878a417064db845f31925bf906b3cd1f63bc62c0
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 24 Nov 2021 13:59:45 +0100

Some refactoring

Diffstat:
Msrc/stardis-app.c | 42+++++++++++++++++++++++++-----------------
Msrc/stardis-app.h | 416+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/stardis-compute.c | 26+++++++++++++-------------
Msrc/stardis-fluid.c | 93++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/stardis-fluid.h | 12++++++------
Msrc/stardis-intface.c | 60++++++++++++++++++++++++++++++------------------------------
Msrc/stardis-output.c | 10+++++-----
Msrc/stardis-parsing.c | 304++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/stardis-parsing.h | 11+++++------
Msrc/stardis-solid.c | 115++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/stardis-solid.h | 14+++++++-------
11 files changed, 563 insertions(+), 540 deletions(-)

diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -33,7 +33,6 @@ #include <string.h> static const struct dummies DUMMIES_NULL = DUMMIES_NULL__; - static const struct counts COUNTS_NULL = COUNTS_NULL__; /******************************************************************************* @@ -42,8 +41,7 @@ static const struct counts COUNTS_NULL = COUNTS_NULL__; static res_T read_model (const struct darray_str* model_files, - struct stardis* stardis, - struct dummies* dummies) + struct stardis* stardis) { res_T res = RES_OK; const struct str* files = NULL; @@ -51,7 +49,7 @@ read_model FILE* f = NULL; struct txtrdr* txtrdr = NULL; - ASSERT(model_files && stardis && dummies); + ASSERT(model_files && stardis); files = darray_str_cdata_get(model_files); FOR_EACH(i, 0, darray_str_size_get(model_files)) { const char* name = str_cget(files + i); @@ -69,7 +67,7 @@ read_model ERR(txtrdr_read_line(txtrdr)); line = txtrdr_get_line(txtrdr); if(!line) break; - ERR(process_model_line(name, line, stardis, dummies)); + ERR(process_model_line(name, line, stardis)); } txtrdr_ref_put(txtrdr); txtrdr = NULL; @@ -124,7 +122,7 @@ check_delta_and_create_solid if(stardis->senc3d_scn) { /* Due to previous errors, senc3d_scn can be unavailable */ unsigned e, ecount = 0; - const unsigned desc_id = description->d.solid.desc_id; + const unsigned desc_id = description->d.solid->desc_id; /* The enclosures where created using description ids */ ERR(senc3d_scene_get_enclosure_count_by_medium(stardis->senc3d_scn, @@ -159,31 +157,31 @@ check_delta_and_create_solid logger_print(stardis->logger, LOG_WARNING, "Solid '%s' is used in %u different enclosures that have different " "delta requirements.\n", - str_cget(&description->d.solid.name), ecount); + str_cget(&description->d.solid->name), ecount); /* Delta needs to be substituted with actual value */ - if(description->d.solid.delta == DELTA_AUTO) { - description->d.solid.delta = delta_range[0]; + if(description->d.solid->delta == DELTA_AUTO) { + description->d.solid->delta = delta_range[0]; logger_print(stardis->logger, LOG_OUTPUT, "Auto delta for solid '%s' set to %g\n", - str_cget(&description->d.solid.name), description->d.solid.delta); + str_cget(&description->d.solid->name), description->d.solid->delta); } else { int too_small - = (delta_range[0] > description->d.solid.delta * acceptance_ratio); + = (delta_range[0] > description->d.solid->delta * acceptance_ratio); int too_big - = (delta_range[0] * acceptance_ratio < description->d.solid.delta); + = (delta_range[0] * acceptance_ratio < description->d.solid->delta); /* Check if user delta is OK */ if(too_small || too_big) { logger_print(stardis->logger, LOG_WARNING, "User delta for solid '%s' seems too %s: %g; " "auto delta would have set it to %g.\n", - str_cget(&description->d.solid.name), (too_big ? "big" : "small"), - description->d.solid.delta, delta_range[0]); + str_cget(&description->d.solid->name), (too_big ? "big" : "small"), + description->d.solid->delta, delta_range[0]); } } } } } - ERR(create_solver_solid(stardis, &description->d.solid)); + ERR(create_solver_solid(stardis, description->d.solid)); end: if(enc) SENC3D(enclosure_ref_put(enc)); @@ -205,7 +203,6 @@ stardis_init { res_T tmp_res, res = RES_OK; struct sg3d_sdisXd_scene_create_context create_context; - struct dummies dummies = DUMMIES_NULL; struct htable_intface htable_interfaces; struct str str; unsigned i, vcount, tcount, ocount, count; @@ -215,6 +212,7 @@ stardis_init str_init(allocator, &str); /* Init everithing that cannot fail */ + stardis->dummies = DUMMIES_NULL; stardis->logger = logger; stardis->allocator = allocator; htable_intface_init(stardis->allocator, &htable_interfaces); @@ -280,7 +278,7 @@ stardis_init else if(args->mode & MODE_DUMP_C_CHUNKS) { ERR(str_set(&stardis->chunks_prefix, args->chunks_prefix)); } - ERR(read_model(&args->model_files, stardis, &dummies)); + ERR(read_model(&args->model_files, stardis)); create_context.geometry = stardis->geometry.sg3d; create_context.app_interface_getter = geometry_get_interface; @@ -439,6 +437,10 @@ stardis_release str_release(&stardis->bin_green_filename); str_release(&stardis->end_paths_filename); str_release(&stardis->chunks_prefix); + FOR_EACH(i, 0, darray_descriptions_size_get(&stardis->descriptions)) { + struct description* d = darray_descriptions_data_get(&stardis->descriptions) +i; + release_description(d, stardis->allocator); + } darray_descriptions_release(&stardis->descriptions); release_geometry(&stardis->geometry); darray_size_t_release(&stardis->compute_surface.primitives); @@ -450,6 +452,12 @@ stardis_release } darray_media_ptr_release(&stardis->media); release_camera(&stardis->camera); + if(stardis->dummies.stardis_fluid) { + release_fluid(stardis->dummies.stardis_fluid, stardis->allocator); + } + if(stardis->dummies.stardis_solid) { + release_solid(stardis->dummies.stardis_solid, stardis->allocator); + } } res_T diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -125,12 +125,15 @@ enum description_type { struct dummies { struct sdis_medium* dummy_fluid; unsigned dummy_fluid_id; + struct fluid* stardis_fluid; struct sdis_medium* dummy_solid; unsigned dummy_solid_id; + struct solid* stardis_solid; }; #define DUMMIES_NULL__ {\ - NULL, UINT_MAX, NULL, UINT_MAX\ + NULL, UINT_MAX, NULL, NULL, UINT_MAX, NULL\ } +static const struct dummies DUMMIES_NULL; static FINLINE void init_media_ptr @@ -193,6 +196,29 @@ error: /******************************************************************************/ +struct fluid; +struct solid; +struct t_boundary; +struct f_boundary; +struct h_boundary; +struct solid_fluid_connect; +struct solid_solid_connect; + +struct description { + enum description_type type; + union { + struct fluid* fluid; + struct solid* solid; + struct t_boundary* t_boundary; + struct f_boundary* f_boundary; + struct h_boundary* h_boundary; + struct solid_fluid_connect* sf_connect; + struct solid_solid_connect* ss_connect; + } d; +}; + +/******************************************************************************/ + struct h_boundary { struct str name; double ref_temperature; @@ -201,24 +227,49 @@ struct h_boundary { double hc; double imposed_temperature; unsigned mat_id; + struct fluid* possible_external_fluid; /* if H for solid */ }; -static FINLINE void -init_h(struct mem_allocator* allocator, struct h_boundary* dst) +static FINLINE res_T +init_h + (struct mem_allocator* allocator, + struct h_boundary** dst) { - str_init(allocator, &dst->name); - dst->ref_temperature = 0; - dst->emissivity = 0; - dst->specular_fraction = 0; - dst->hc = 0; - dst->imposed_temperature = -1; - dst->mat_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct h_boundary)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->ref_temperature = 0; + (*dst)->emissivity = 0; + (*dst)->specular_fraction = 0; + (*dst)->hc = 0; + (*dst)->imposed_temperature = -1; + (*dst)->mat_id = UINT_MAX; + (*dst)->possible_external_fluid = NULL; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } static FINLINE void -release_h_boundary(struct h_boundary* bound) +release_h_boundary + (struct h_boundary* bound, + struct mem_allocator* allocator) { + ASSERT(bound && allocator); str_release(&bound->name); + if(bound->possible_external_fluid) { + release_fluid(bound->possible_external_fluid, allocator); + } + MEM_RM(allocator, bound); } static res_T @@ -241,36 +292,44 @@ error: goto end; } -static FINLINE res_T -cp_h_boundary(struct h_boundary* dst, const struct h_boundary* src) -{ - dst->ref_temperature = src->ref_temperature; - dst->emissivity = src->emissivity; - dst->specular_fraction = src->specular_fraction; - dst->hc = src->hc; - dst->imposed_temperature = src->imposed_temperature; - dst->mat_id = src->mat_id; - return str_copy(&dst->name, &src->name); -} - struct t_boundary { struct str name; double imposed_temperature; unsigned mat_id; }; -static FINLINE void -init_t(struct mem_allocator* allocator, struct t_boundary* dst) +static FINLINE res_T +init_t + (struct mem_allocator* allocator, + struct t_boundary** dst) { - str_init(allocator, &dst->name); - dst->imposed_temperature = -1; - dst->mat_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct t_boundary)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->imposed_temperature = -1; + (*dst)->mat_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } static FINLINE void -release_t_boundary(struct t_boundary* bound) +release_t_boundary + (struct t_boundary* bound, + struct mem_allocator* allocator) { + ASSERT(bound && allocator); str_release(&bound->name); + MEM_RM(allocator, bound); } static res_T @@ -291,32 +350,44 @@ error: goto end; } -static FINLINE res_T -cp_t_boundary(struct t_boundary* dst, const struct t_boundary* src) -{ - dst->imposed_temperature = src->imposed_temperature; - dst->mat_id = src->mat_id; - return str_copy(&dst->name, &src->name); -} - struct f_boundary { struct str name; double imposed_flux; unsigned mat_id; }; -static FINLINE void -init_f(struct mem_allocator* allocator, struct f_boundary* dst) +static FINLINE res_T +init_f + (struct mem_allocator* allocator, + struct f_boundary** dst) { - str_init(allocator, &dst->name); - dst->mat_id = UINT_MAX; - dst->imposed_flux = -1; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct f_boundary)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->mat_id = UINT_MAX; + (*dst)->imposed_flux = -1; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } static FINLINE void -release_f_boundary(struct f_boundary* bound) +release_f_boundary + (struct f_boundary* bound, + struct mem_allocator* allocator) { + ASSERT(bound && allocator); str_release(&bound->name); + MEM_RM(allocator, bound); } static res_T @@ -335,14 +406,6 @@ error: goto end; } -static FINLINE res_T -cp_f_boundary(struct f_boundary* dst, const struct f_boundary* src) -{ - dst->imposed_flux = src->imposed_flux; - dst->mat_id = src->mat_id; - return str_copy(&dst->name, &src->name); -} - struct solid_fluid_connect { struct str name; double ref_temperature; @@ -353,20 +416,40 @@ struct solid_fluid_connect { }; static FINLINE void -release_sf_connect(struct solid_fluid_connect* connect) +release_sf_connect + (struct solid_fluid_connect* connect, + struct mem_allocator* allocator) { + ASSERT(connect && allocator); str_release(&connect->name); + MEM_RM(allocator, connect); } -static FINLINE void -init_sf(struct mem_allocator* allocator, struct solid_fluid_connect* dst) +static FINLINE res_T +init_sf + (struct mem_allocator* allocator, + struct solid_fluid_connect** dst) { - str_init(allocator, &dst->name); - dst->ref_temperature = 0; - dst->emissivity = 0; - dst->specular_fraction = 0; - dst->hc = 0; - dst->connection_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct solid_fluid_connect)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->ref_temperature = 0; + (*dst)->emissivity = 0; + (*dst)->specular_fraction = 0; + (*dst)->hc = 0; + (*dst)->connection_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } static res_T @@ -385,25 +468,6 @@ error: goto end; } -static FINLINE res_T -cp_sf_connect - (struct solid_fluid_connect* dst, const struct solid_fluid_connect* src) -{ - dst->ref_temperature = src->ref_temperature; - dst->emissivity = src->emissivity; - dst->specular_fraction = src->specular_fraction; - dst->hc = src->hc; - dst->connection_id = src->connection_id; - return str_copy(&dst->name, &src->name); -} - -static FINLINE res_T -cp_release_sf_connect - (struct solid_fluid_connect* dst, struct solid_fluid_connect* src) -{ - return cp_sf_connect(dst, src); -} - struct solid_solid_connect { struct str name; double tcr; @@ -411,17 +475,37 @@ struct solid_solid_connect { }; static FINLINE void -release_ss_connect(struct solid_solid_connect* connect) +release_ss_connect + (struct solid_solid_connect* connect, + struct mem_allocator* allocator) { + ASSERT(connect && allocator); str_release(&connect->name); + MEM_RM(allocator, connect); } -static FINLINE void -init_ss(struct mem_allocator* allocator, struct solid_solid_connect* dst) +static FINLINE res_T +init_ss + (struct mem_allocator* allocator, + struct solid_solid_connect** dst) { - str_init(allocator, &dst->name); - dst->tcr = 0; - dst->connection_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct solid_solid_connect)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->tcr = 0; + (*dst)->connection_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } static res_T @@ -440,69 +524,45 @@ error: } static FINLINE res_T -cp_ss_connect - (struct solid_solid_connect* dst, const struct solid_solid_connect* src) -{ - dst->connection_id = src->connection_id; - dst->tcr = src->tcr; - return str_copy(&dst->name, &src->name); -} - -static FINLINE res_T -cp_release_ss_connect - (struct solid_solid_connect* dst, struct solid_solid_connect* src) -{ - return cp_ss_connect(dst, src); -} - - -struct description { - enum description_type type; - union { - struct fluid fluid; - struct solid solid; - struct t_boundary t_boundary; - struct f_boundary f_boundary; - struct h_boundary h_boundary; - struct solid_fluid_connect sf_connect; - struct solid_solid_connect ss_connect; - } d; -}; - -static FINLINE res_T -init_description(struct mem_allocator* alloc, struct description* desc) +init_description + (struct mem_allocator* alloc, + struct description* desc) { ASSERT(desc); (void)alloc; desc->type = DESCRIPTION_TYPE_COUNT__; + desc->d.fluid = NULL; return RES_OK; } static FINLINE void -release_description(struct description* desc) +release_description + (struct description* desc, + struct mem_allocator* allocator) { + ASSERT(desc && allocator); switch (desc->type) { case DESC_MAT_SOLID: - release_solid(&desc->d.solid); + release_solid(desc->d.solid, allocator); break; case DESC_MAT_FLUID: - release_fluid(&desc->d.fluid); + release_fluid(desc->d.fluid, allocator); break; case DESC_BOUND_H_FOR_SOLID: case DESC_BOUND_H_FOR_FLUID: - release_h_boundary(&desc->d.h_boundary); + release_h_boundary(desc->d.h_boundary, allocator); break; case DESC_BOUND_T_FOR_SOLID: - release_t_boundary(&desc->d.t_boundary); + release_t_boundary(desc->d.t_boundary, allocator); break; case DESC_BOUND_F_FOR_SOLID: - release_f_boundary(&desc->d.f_boundary); + release_f_boundary(desc->d.f_boundary, allocator); break; case DESC_SOLID_FLUID_CONNECT: - release_sf_connect(&desc->d.sf_connect); + release_sf_connect(desc->d.sf_connect, allocator); break; case DESC_SOLID_SOLID_CONNECT: - release_ss_connect(&desc->d.ss_connect); + release_ss_connect(desc->d.ss_connect, allocator); break; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); @@ -521,26 +581,26 @@ str_print_description ERR(str_printf(str, "Description %u: ", rank)); switch (desc->type) { case DESC_MAT_SOLID: - ERR(str_print_solid(str, &desc->d.solid)); + ERR(str_print_solid(str, desc->d.solid)); break; case DESC_MAT_FLUID: - ERR(str_print_fluid(str, &desc->d.fluid)); + ERR(str_print_fluid(str, desc->d.fluid)); break; case DESC_BOUND_T_FOR_SOLID: - ERR(str_print_t_boundary(str, &desc->d.t_boundary)); + ERR(str_print_t_boundary(str, desc->d.t_boundary)); break; case DESC_BOUND_H_FOR_SOLID: case DESC_BOUND_H_FOR_FLUID: - ERR(str_print_h_boundary(str, &desc->d.h_boundary, desc->type)); + ERR(str_print_h_boundary(str, desc->d.h_boundary, desc->type)); break; case DESC_BOUND_F_FOR_SOLID: - ERR(str_print_f_boundary(str, &desc->d.f_boundary)); + ERR(str_print_f_boundary(str, desc->d.f_boundary)); break; case DESC_SOLID_FLUID_CONNECT: - ERR(str_print_sf_connect(str, &desc->d.sf_connect)); + ERR(str_print_sf_connect(str, desc->d.sf_connect)); break; case DESC_SOLID_SOLID_CONNECT: - ERR(str_print_ss_connect(str, &desc->d.ss_connect)); + ERR(str_print_ss_connect(str, desc->d.ss_connect)); break; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); @@ -558,92 +618,25 @@ get_description_name ASSERT(desc); switch (desc->type) { case DESC_MAT_SOLID: - return &desc->d.solid.name; + return &desc->d.solid->name; case DESC_MAT_FLUID: - return &desc->d.fluid.name; + return &desc->d.fluid->name; case DESC_BOUND_T_FOR_SOLID: - return &desc->d.t_boundary.name; + return &desc->d.t_boundary->name; case DESC_BOUND_H_FOR_SOLID: case DESC_BOUND_H_FOR_FLUID: - return &desc->d.h_boundary.name; + return &desc->d.h_boundary->name; case DESC_BOUND_F_FOR_SOLID: - return &desc->d.f_boundary.name; + return &desc->d.f_boundary->name; case DESC_SOLID_FLUID_CONNECT: - return &desc->d.sf_connect.name; + return &desc->d.sf_connect->name; case DESC_SOLID_SOLID_CONNECT: - return &desc->d.ss_connect.name; + return &desc->d.ss_connect->name; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } } -static FINLINE res_T -cp_description - (struct description* dst, - const struct description* src) -{ - res_T res = RES_OK; - ASSERT(src && dst); - switch (src->type) { - case DESC_MAT_SOLID: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_solid(src->d.solid.name.allocator, &dst->d.solid); - } - ERR(cp_solid(&dst->d.solid, &src->d.solid)); - break; - case DESC_MAT_FLUID: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_fluid(src->d.fluid.name.allocator, &dst->d.fluid); - } - ERR(cp_fluid(&dst->d.fluid, &src->d.fluid)); - break; - case DESC_BOUND_H_FOR_SOLID: - case DESC_BOUND_H_FOR_FLUID: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_h(src->d.h_boundary.name.allocator, &dst->d.h_boundary); - } - ERR(cp_h_boundary(&dst->d.h_boundary, &src->d.h_boundary)); - break; - case DESC_BOUND_T_FOR_SOLID: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_t(src->d.t_boundary.name.allocator, &dst->d.t_boundary); - } - ERR(cp_t_boundary(&dst->d.t_boundary, &src->d.t_boundary)); - break; - case DESC_BOUND_F_FOR_SOLID: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_f(src->d.f_boundary.name.allocator, &dst->d.f_boundary); - } - ERR(cp_f_boundary(&dst->d.f_boundary, &src->d.f_boundary)); - break; - case DESC_SOLID_FLUID_CONNECT: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_sf(src->d.sf_connect.name.allocator, &dst->d.sf_connect); - } - ERR(cp_sf_connect(&dst->d.sf_connect, &src->d.sf_connect)); - break; - case DESC_SOLID_SOLID_CONNECT: - if(dst->type == DESCRIPTION_TYPE_COUNT__) { - dst->type = src->type; - init_ss(src->d.ss_connect.name.allocator, &dst->d.ss_connect); - } - ERR(cp_ss_connect(&dst->d.ss_connect, &src->d.ss_connect)); - break; - default: - FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); - } -end: - return res; -error: - goto end; -} - static FINLINE void description_get_medium_id (const struct description* desc, @@ -652,20 +645,20 @@ description_get_medium_id ASSERT(desc && id); switch (desc->type) { case DESC_MAT_SOLID: - *id = desc->d.solid.solid_id; + *id = desc->d.solid->solid_id; return; case DESC_MAT_FLUID: - *id = desc->d.fluid.fluid_id; + *id = desc->d.fluid->fluid_id; return; case DESC_BOUND_H_FOR_SOLID: case DESC_BOUND_H_FOR_FLUID: - *id = desc->d.h_boundary.mat_id; + *id = desc->d.h_boundary->mat_id; return; case DESC_BOUND_T_FOR_SOLID: - *id = desc->d.t_boundary.mat_id; + *id = desc->d.t_boundary->mat_id; return; case DESC_BOUND_F_FOR_SOLID: - *id = desc->d.f_boundary.mat_id; + *id = desc->d.f_boundary->mat_id; return; case DESC_SOLID_FLUID_CONNECT: /* No medium linked to SF */ case DESC_SOLID_SOLID_CONNECT: /* No medium linked to SS */ @@ -766,8 +759,6 @@ struct counts { #define DARRAY_NAME descriptions #define DARRAY_DATA struct description #define DARRAY_FUNCTOR_INIT init_description -#define DARRAY_FUNCTOR_COPY cp_description -#define DARRAY_FUNCTOR_RELEASE release_description #include <rsys/dynamic_array.h> struct compute_surface { @@ -778,6 +769,7 @@ struct compute_surface { }; struct stardis { + struct dummies dummies; /* dummy meterials for boundaries' outside */ struct geometry geometry; struct sdis_scene* sdis_scn; /* The solver scene */ struct darray_descriptions descriptions; /* Materials and boundaries */ diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -246,10 +246,10 @@ check_probe_conform_to_type "Could not determine the medium probe is in.\n"); } else { if(filter_ctx.desc->type == DESC_MAT_SOLID) { - double delta = filter_ctx.desc->d.solid.delta; + double delta = filter_ctx.desc->d.solid->delta; ASSERT(delta < INF); logger_print(stardis->logger, LOG_OUTPUT, - "Probe was in solid '%s'.\n", str_cget(&filter_ctx.desc->d.solid.name)); + "Probe was in solid '%s'.\n", str_cget(&filter_ctx.desc->d.solid->name)); if(filter_ctx.dist > 2 * delta) { logger_print(stardis->logger, LOG_ERROR, "Probe moved to (%g, %g, %g), primitive %u, uv = (%g, %g).\n", @@ -274,7 +274,7 @@ check_probe_conform_to_type } else { /* TODO: check move length wrt local geometry? */ logger_print(stardis->logger, LOG_OUTPUT, - "Probe was in fluid '%s'.\n", str_cget(&filter_ctx.desc->d.fluid.name)); + "Probe was in fluid '%s'.\n", str_cget(&filter_ctx.desc->d.fluid->name)); logger_print(stardis->logger, LOG_OUTPUT, "Probe distance from closest boundary was %g.\n", filter_ctx.dist); } @@ -329,9 +329,9 @@ check_probe_conform_to_type goto error; } logger_print(stardis->logger, LOG_OUTPUT, - "Probe is in solid '%s'.\n", str_cget(&filter_ctx.desc->d.solid.name)); + "Probe is in solid '%s'.\n", str_cget(&filter_ctx.desc->d.solid->name)); if(filter_ctx.desc->type == DESC_MAT_SOLID) { - double delta = filter_ctx.desc->d.solid.delta; + double delta = filter_ctx.desc->d.solid->delta; if(filter_ctx.dist < 0.25 * delta) { logger_print(stardis->logger, LOG_ERROR, "Probe is %g delta from closest boundary. Use -P instead of -p.\n", @@ -356,7 +356,7 @@ check_probe_conform_to_type logger_print(stardis->logger, LOG_WARNING, "Probe is in fluid '%s': computing fluid temperature, " "not using a specific position.\n", - str_cget(&filter_ctx.desc->d.fluid.name)); + str_cget(&filter_ctx.desc->d.fluid->name)); /* In fluid; TODO: check distance wrt local geometry (use 4V/S?) */ } } @@ -532,7 +532,7 @@ compute_probe_on_interface(struct stardis* stardis, struct time* start) ASSERT(prop[SG3D_INTFACE] < dcount); intface_desc = descriptions + prop[SG3D_INTFACE]; if(intface_desc->type == DESC_SOLID_SOLID_CONNECT) - tcr = intface_desc->d.ss_connect.tcr; + tcr = intface_desc->d.ss_connect->tcr; } if(str_is_empty(&stardis->solve_name)) { @@ -575,10 +575,10 @@ compute_probe_on_interface(struct stardis* stardis, struct time* start) bd = descriptions + prop[SG3D_BACK]; ASSERT(fd->type == DESC_MAT_SOLID || fd->type == DESC_MAT_FLUID); fmat_id = (fd->type == DESC_MAT_SOLID) - ? fd->d.solid.solid_id : fd->d.fluid.fluid_id; + ? fd->d.solid->solid_id : fd->d.fluid->fluid_id; ASSERT(bd->type == DESC_MAT_SOLID || bd->type == DESC_MAT_FLUID); bmat_id = (bd->type == DESC_MAT_SOLID) - ? bd->d.solid.solid_id : bd->d.fluid.fluid_id; + ? bd->d.solid->solid_id : bd->d.fluid->fluid_id; if(med_id != fmat_id && med_id != bmat_id) { /* Not here */ logger_print(stardis->logger, LOG_ERROR, @@ -1243,8 +1243,8 @@ find_medium_by_name struct description* desc = darray_descriptions_data_get(&stardis->descriptions) + i; if(desc->type == DESC_MAT_SOLID) { - if(str_eq(name, &desc->d.solid.name)) { - unsigned id = desc->d.solid.solid_id; + if(str_eq(name, &desc->d.solid->name)) { + unsigned id = desc->d.solid->solid_id; ASSERT(darray_media_ptr_size_get(&stardis->media) > id); medium = darray_media_ptr_data_get(&stardis->media)[id]; if(out_id) *out_id = id; @@ -1252,8 +1252,8 @@ find_medium_by_name } } else if(desc->type == DESC_MAT_FLUID) { - if(str_eq(name, &desc->d.fluid.name)) { - unsigned id = desc->d.fluid.fluid_id; + if(str_eq(name, &desc->d.fluid->name)) { + unsigned id = desc->d.fluid->fluid_id; ASSERT(darray_media_ptr_size_get(&stardis->media) > id); medium = darray_media_ptr_data_get(&stardis->media)[id]; if(out_id) *out_id = id; diff --git a/src/stardis-fluid.c b/src/stardis-fluid.c @@ -19,6 +19,8 @@ #include <sdis.h> +#include <rsys/mem_allocator.h> + #include <limits.h> /******************************************************************************* @@ -30,9 +32,9 @@ fluid_get_calorific_capacity (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct fluid* fluid_props = sdis_data_cget(data); + const struct fluid* const* fluid_props = sdis_data_cget(data); (void)vtx; - return fluid_props->cp; + return (*fluid_props)->cp; } static double @@ -40,9 +42,9 @@ fluid_get_volumic_mass (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct fluid* fluid_props = sdis_data_cget(data); + const struct fluid* const* fluid_props = sdis_data_cget(data); (void)vtx; - return fluid_props->rho; + return (*fluid_props)->rho; } static double @@ -50,21 +52,21 @@ fluid_get_temperature (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct fluid* fluid_props = sdis_data_cget(data); - if(fluid_props->imposed_temperature >= 0) + const struct fluid* const* fluid_props = sdis_data_cget(data); + if((*fluid_props)->imposed_temperature >= 0) /* If there is an imposed temp, it is imposed regardless of time */ - return fluid_props->imposed_temperature; - if(vtx->time <= fluid_props->t0) { + return (*fluid_props)->imposed_temperature; + if(vtx->time <= (*fluid_props)->t0) { /* If time is <= t0: use tinit */ - if(fluid_props->tinit < 0) { - if(str_is_empty(&fluid_props->name)) { + if((*fluid_props)->tinit < 0) { + if(str_is_empty(&(*fluid_props)->name)) { FATAL("fluid_get_temperature: getting undefined Tinit\n"); } else { VFATAL("fluid_get_temperature: getting undefined Tinit (fluid '%s')\n", - ARG1(str_cget(&fluid_props->name))); + ARG1(str_cget(&(*fluid_props)->name))); } } - return fluid_props->tinit; + return (*fluid_props)->tinit; } return -1; /* Unknown temperature */ } @@ -81,18 +83,17 @@ create_solver_fluid res_T res = RES_OK; struct sdis_fluid_shader fluid_shader = SDIS_FLUID_SHADER_NULL; struct sdis_data* data = NULL; - struct fluid* props; + const struct fluid** props; ASSERT(stardis && fluid_props); fluid_shader.calorific_capacity = fluid_get_calorific_capacity; fluid_shader.volumic_mass = fluid_get_volumic_mass; fluid_shader.temperature = fluid_get_temperature; - ERR(sdis_data_create(stardis->dev, sizeof(struct fluid), ALIGNOF(struct fluid), + ERR(sdis_data_create(stardis->dev, sizeof(struct fluid*), ALIGNOF(struct fluid*), NULL, &data)); props = sdis_data_get(data); /* Fetch the allocated memory space */ - init_fluid(stardis->allocator, props); - cp_fluid(props, fluid_props); + *props = fluid_props; if(fluid_props->fluid_id >= darray_media_ptr_size_get(&stardis->media)) { ERR(darray_media_ptr_resize(&stardis->media, fluid_props->fluid_id + 1)); } @@ -107,25 +108,44 @@ error: goto end; } -void -init_fluid(struct mem_allocator* allocator, struct fluid* dst) +res_T +init_fluid(struct mem_allocator* allocator, struct fluid** dst) { - str_init(allocator, &dst->name); - dst->rho = 1; - dst->cp = 1; - dst->tinit = -1; - dst->imposed_temperature = -1; - dst->t0 = 0; - dst->is_outside = 0; - dst->is_green = 0; - dst->desc_id = UINT_MAX; - dst->fluid_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct fluid)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + str_initialized = 1; + (*dst)->rho = 1; + (*dst)->cp = 1; + (*dst)->tinit = -1; + (*dst)->imposed_temperature = -1; + (*dst)->t0 = 0; + (*dst)->is_outside = 0; + (*dst)->is_green = 0; + (*dst)->desc_id = UINT_MAX; + (*dst)->fluid_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } void -release_fluid(struct fluid* fluid) +release_fluid + (struct fluid* fluid, + struct mem_allocator* allocator) { + ASSERT(fluid && allocator); str_release(&fluid->name); + MEM_RM(allocator, fluid); } res_T @@ -147,18 +167,3 @@ end: error: goto end; } - -res_T -cp_fluid(struct fluid* dst, const struct fluid* src) -{ - dst->rho = src->rho; - dst->cp = src->cp; - dst->tinit = src->tinit; - dst->imposed_temperature = src->imposed_temperature; - dst->t0 = src->t0; - dst->is_outside = src->is_outside; - dst->is_green = src->is_green; - dst->desc_id = src->desc_id; - dst->fluid_id = src->fluid_id; - return str_copy(&dst->name, &src->name); -} diff --git a/src/stardis-fluid.h b/src/stardis-fluid.h @@ -22,6 +22,7 @@ #include <rsys/str.h> struct stardis; +struct mem_allocator; /******************************************************************************* * Fluid data @@ -44,16 +45,15 @@ create_solver_fluid (struct stardis* stardis, const struct fluid* fluid_props); -LOCAL_SYM void -init_fluid(struct mem_allocator* allocator, struct fluid* dst); +LOCAL_SYM res_T +init_fluid(struct mem_allocator* allocator, struct fluid** dst); LOCAL_SYM void -release_fluid(struct fluid* fluid); +release_fluid + (struct fluid* desc, + struct mem_allocator* allocator); LOCAL_SYM res_T str_print_fluid(struct str* str, const struct fluid* s); -LOCAL_SYM res_T -cp_fluid(struct fluid* dst, const struct fluid* src); - #endif diff --git a/src/stardis-intface.c b/src/stardis-intface.c @@ -160,14 +160,14 @@ create_intface if(front_defined) { switch (descriptions[fd].type) { case DESC_MAT_SOLID: - id = descriptions[fd].d.solid.solid_id; + id = descriptions[fd].d.solid->solid_id; solid_count++; interface_props->front_medium_id = id; front_med = media[id]; break; case DESC_MAT_FLUID: fluid_count++; - id = descriptions[fd].d.fluid.fluid_id; + id = descriptions[fd].d.fluid->fluid_id; interface_props->front_medium_id = id; front_med = media[id]; fluid_side_shader = &interface_shader.front; @@ -179,14 +179,14 @@ create_intface if(back_defined) { switch (descriptions[bd].type) { case DESC_MAT_SOLID: - id = descriptions[bd].d.solid.solid_id; + id = descriptions[bd].d.solid->solid_id; solid_count++; interface_props->back_medium_id = id; back_med = media[id]; break; case DESC_MAT_FLUID: fluid_count++; - id = descriptions[bd].d.fluid.fluid_id; + id = descriptions[bd].d.fluid->fluid_id; interface_props->back_medium_id = id; back_med = media[id]; /* Can overwrite fluid_side_shader. However it would imply two @@ -232,9 +232,9 @@ create_intface goto error; } type_checked = 1; - ASSERT(connect->d.h_boundary.imposed_temperature >= 0); + ASSERT(connect->d.h_boundary->imposed_temperature >= 0); interface_props->imposed_temperature - = connect->d.h_boundary.imposed_temperature; + = connect->d.h_boundary->imposed_temperature; ASSERT(fluid_side_shader); fluid_side_shader->temperature = interface_get_temperature; /* fall through */ @@ -244,7 +244,7 @@ create_intface { res = RES_BAD_ARG; goto error; } - ext_id = connect->d.h_boundary.mat_id; /* External material id */ + ext_id = connect->d.h_boundary->mat_id; /* External material id */ ASSERT(ext_id < darray_media_ptr_size_get(&stardis->media)); ASSERT(sdis_medium_get_type(media[ext_id]) == (connect->type == DESC_BOUND_H_FOR_SOLID ? SDIS_FLUID : SDIS_SOLID)); @@ -252,17 +252,17 @@ create_intface boundary_count++; if(front_defined) back_med = media[ext_id]; else front_med = media[ext_id]; - interface_shader.convection_coef_upper_bound = connect->d.h_boundary.hc; - interface_props->hc = connect->d.h_boundary.hc; - interface_props->ref_temperature = connect->d.h_boundary.ref_temperature; - interface_props->emissivity = connect->d.h_boundary.emissivity; - interface_props->alpha = connect->d.h_boundary.specular_fraction; - if(connect->d.h_boundary.hc > 0) { + interface_shader.convection_coef_upper_bound = connect->d.h_boundary->hc; + interface_props->hc = connect->d.h_boundary->hc; + interface_props->ref_temperature = connect->d.h_boundary->ref_temperature; + interface_props->emissivity = connect->d.h_boundary->emissivity; + interface_props->alpha = connect->d.h_boundary->specular_fraction; + if(connect->d.h_boundary->hc > 0) { interface_shader.convection_coef = interface_get_convection_coef; } ASSERT(fluid_side_shader); fluid_side_shader->reference_temperature = interface_get_ref_temperature; - if(connect->d.h_boundary.emissivity > 0) { + if(connect->d.h_boundary->emissivity > 0) { fluid_side_shader->emissivity = interface_get_emissivity; fluid_side_shader->specular_fraction = interface_get_alpha; } @@ -272,7 +272,7 @@ create_intface res = RES_BAD_ARG; goto error; } - ext_id = connect->d.t_boundary.mat_id; /* External material id */ + ext_id = connect->d.t_boundary->mat_id; /* External material id */ ASSERT(ext_id < darray_media_ptr_size_get(&stardis->media)); ASSERT(sdis_medium_get_type(media[ext_id]) == SDIS_FLUID); connection_count++; @@ -293,9 +293,9 @@ create_intface fluid_side_shader->reference_temperature = interface_get_ref_temperature; fluid_side_shader->emissivity = interface_get_emissivity; interface_props->emissivity = 1; - ASSERT(connect->d.t_boundary.imposed_temperature >= 0); + ASSERT(connect->d.t_boundary->imposed_temperature >= 0); interface_props->imposed_temperature - = connect->d.t_boundary.imposed_temperature; + = connect->d.t_boundary->imposed_temperature; break; case DESC_BOUND_F_FOR_SOLID: if(sdis_medium_get_type(def_medium) != SDIS_SOLID) { @@ -305,14 +305,14 @@ create_intface connection_count++; boundary_count++; if(front_defined) { - back_med = media[connect->d.f_boundary.mat_id]; + back_med = media[connect->d.f_boundary->mat_id]; interface_shader.front.flux = interface_get_flux; } else { - front_med = media[connect->d.f_boundary.mat_id]; + front_med = media[connect->d.f_boundary->mat_id]; interface_shader.back.flux = interface_get_flux; } - ASSERT(connect->d.f_boundary.imposed_flux != SDIS_FLUX_NONE); - interface_props->imposed_flux = connect->d.f_boundary.imposed_flux; + ASSERT(connect->d.f_boundary->imposed_flux != SDIS_FLUX_NONE); + interface_props->imposed_flux = connect->d.f_boundary->imposed_flux; break; case DESC_SOLID_FLUID_CONNECT: /* Both front and back should be defined */ @@ -323,17 +323,17 @@ create_intface ASSERT(front_defined && back_defined); connection_count++; solid_fluid_connection_count++; - interface_shader.convection_coef_upper_bound = connect->d.sf_connect.hc; - interface_props->hc = connect->d.sf_connect.hc; - interface_props->ref_temperature = connect->d.sf_connect.ref_temperature; - interface_props->emissivity = connect->d.sf_connect.emissivity; - interface_props->alpha = connect->d.sf_connect.specular_fraction; - if(connect->d.sf_connect.hc > 0) { + interface_shader.convection_coef_upper_bound = connect->d.sf_connect->hc; + interface_props->hc = connect->d.sf_connect->hc; + interface_props->ref_temperature = connect->d.sf_connect->ref_temperature; + interface_props->emissivity = connect->d.sf_connect->emissivity; + interface_props->alpha = connect->d.sf_connect->specular_fraction; + if(connect->d.sf_connect->hc > 0) { interface_shader.convection_coef = interface_get_convection_coef; } ASSERT(fluid_side_shader); fluid_side_shader->reference_temperature = interface_get_ref_temperature; - if(connect->d.sf_connect.emissivity > 0) { + if(connect->d.sf_connect->emissivity > 0) { fluid_side_shader->emissivity = interface_get_emissivity; fluid_side_shader->specular_fraction = interface_get_alpha; } @@ -347,8 +347,8 @@ create_intface ASSERT(front_defined && back_defined); connection_count++; solid_solid_connection_count++; - interface_props->tcr = connect->d.ss_connect.tcr; - if(connect->d.ss_connect.tcr > 0) { + interface_props->tcr = connect->d.ss_connect->tcr; + if(connect->d.ss_connect->tcr > 0) { interface_shader.thermal_contact_resistance = interface_get_tcr; } break; diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -932,7 +932,7 @@ dump_green_ascii const struct description* desc = descs + i; const struct solid* sl; if(desc->type != DESC_MAT_SOLID) continue; - sl = &desc->d.solid; + sl = desc->d.solid; fprintf(stream, "%u\t%s\t%g\t%g\t%g\t%g", i, str_cget(&sl->name), sl->lambda, sl->rho, sl->cp, sl->vpower); if(sl->tinit >= 0) { @@ -954,7 +954,7 @@ dump_green_ascii const struct description* desc = descs + i; const struct fluid* fl; if(desc->type != DESC_MAT_FLUID) continue; - fl = &desc->d.fluid; + fl = desc->d.fluid; if(fl->imposed_temperature >= 0) { fprintf(stream, "%u\t%s\t%g\t%g", i, str_cget(&fl->name), fl->rho, fl->cp); @@ -982,7 +982,7 @@ dump_green_ascii FOR_EACH(i, 0, szd) { const struct description* desc = descs + i; const struct t_boundary* bd; - bd = &desc->d.t_boundary; + bd = desc->d.t_boundary; fprintf(stream, "%u\t%s\t%g\n", i, str_cget(&bd->name), bd->imposed_temperature); } @@ -995,7 +995,7 @@ dump_green_ascii const struct h_boundary* bd; if(desc->type != DESC_BOUND_H_FOR_SOLID && desc->type != DESC_BOUND_H_FOR_FLUID) continue; - bd = &desc->d.h_boundary; + bd = desc->d.h_boundary; fprintf(stream, "%u\t%s\t%g\t%g\t%g\t%g\t%g\n", i, str_cget(&bd->name), bd->ref_temperature, bd->emissivity, bd->specular_fraction, bd->hc, bd->imposed_temperature); @@ -1008,7 +1008,7 @@ dump_green_ascii const struct description* desc = descs + i; const struct f_boundary* bd; if(desc->type != DESC_BOUND_F_FOR_SOLID) continue; - bd = &desc->d.f_boundary; + bd = desc->d.f_boundary; fprintf(stream, "%u\t%s\t%g\n", i, str_cget(&bd->name), bd->imposed_flux); } diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -1175,7 +1175,6 @@ find_description_by_name static res_T process_h (struct stardis* stardis, - struct dummies* dummies, const enum description_type type, char** tok_ctx) { @@ -1191,13 +1190,12 @@ process_h sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz+1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_h(stardis->allocator, &desc->d.h_boundary); - + ERR(init_h(stardis->allocator, &desc->d.h_boundary)); desc->type = type; CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "h boundary name"); - ERR(description_set_name(stardis, &desc->d.h_boundary.name, tk)); - if(find_description_by_name(stardis, &desc->d.h_boundary.name, NULL) + ERR(description_set_name(stardis, &desc->d.h_boundary->name, tk)); + if(find_description_by_name(stardis, &desc->d.h_boundary->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1207,31 +1205,31 @@ process_h } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "ref_temperature"); - res = cstr_to_double(tk, &desc->d.h_boundary.ref_temperature); + res = cstr_to_double(tk, &desc->d.h_boundary->ref_temperature); if(res != RES_OK - || desc->d.h_boundary.ref_temperature < 0) + || desc->d.h_boundary->ref_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid reference temperature: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - stardis->t_range[0] = MMIN(stardis->t_range[0], desc->d.h_boundary.ref_temperature); - stardis->t_range[1] = MMAX(stardis->t_range[1], desc->d.h_boundary.ref_temperature); + stardis->t_range[0] = MMIN(stardis->t_range[0], desc->d.h_boundary->ref_temperature); + stardis->t_range[1] = MMAX(stardis->t_range[1], desc->d.h_boundary->ref_temperature); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "emissivity"); - res = cstr_to_double(tk, &desc->d.h_boundary.emissivity); + res = cstr_to_double(tk, &desc->d.h_boundary->emissivity); if(res != RES_OK - || desc->d.h_boundary.emissivity < 0 - || desc->d.h_boundary.emissivity > 1) + || desc->d.h_boundary->emissivity < 0 + || desc->d.h_boundary->emissivity > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid emissivity: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "specular fraction"); - res = cstr_to_double(tk, &desc->d.h_boundary.specular_fraction); + res = cstr_to_double(tk, &desc->d.h_boundary->specular_fraction); if(res != RES_OK - || desc->d.h_boundary.specular_fraction < 0 - || desc->d.h_boundary.specular_fraction > 1) + || desc->d.h_boundary->specular_fraction < 0 + || desc->d.h_boundary->specular_fraction > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid specular fraction: %s\n", tk); @@ -1239,18 +1237,18 @@ process_h goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "hc"); - res = cstr_to_double(tk, &desc->d.h_boundary.hc); + res = cstr_to_double(tk, &desc->d.h_boundary->hc); if(res != RES_OK - || desc->d.h_boundary.hc < 0) + || desc->d.h_boundary->hc < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid hc: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "temperature"); - res = cstr_to_double(tk, &desc->d.h_boundary.imposed_temperature); + res = cstr_to_double(tk, &desc->d.h_boundary->imposed_temperature); if(res != RES_OK - || desc->d.h_boundary.imposed_temperature < 0) + || desc->d.h_boundary->imposed_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; @@ -1258,23 +1256,24 @@ process_h } if(type == DESC_BOUND_H_FOR_FLUID) - desc->d.h_boundary.mat_id = get_dummy_solid_id(stardis, dummies); + ERR(get_dummy_solid_id(stardis, &desc->d.h_boundary->mat_id)); else { - struct fluid fluid_props; - init_fluid(stardis->allocator, &fluid_props); - fluid_props.fluid_id = allocate_stardis_medium_id(stardis); - desc->d.h_boundary.mat_id = fluid_props.fluid_id; + struct fluid* fluid = NULL; + ERR(init_fluid(stardis->allocator, &fluid)); + fluid->fluid_id = allocate_stardis_medium_id(stardis); + desc->d.h_boundary->mat_id = fluid->fluid_id; + desc->d.h_boundary->possible_external_fluid = fluid; ASSERT(sz <= UINT_MAX); - fluid_props.desc_id = (unsigned)sz; - fluid_props.imposed_temperature - = desc->d.h_boundary.imposed_temperature; - fluid_props.is_outside = 1; - fluid_props.is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); - ERR(create_solver_fluid(stardis, &fluid_props)); + fluid->desc_id = (unsigned)sz; + fluid->imposed_temperature + = desc->d.h_boundary->imposed_temperature; + fluid->is_outside = 1; + fluid->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + ERR(create_solver_fluid(stardis, fluid)); logger_print(stardis->logger, LOG_OUTPUT, "External fluid created: T=%g (it is medium %u)\n", - fluid_props.imposed_temperature, - fluid_props.fluid_id); + fluid->imposed_temperature, + fluid->fluid_id); } ASSERT(sz <= UINT_MAX); @@ -1290,7 +1289,6 @@ error: static res_T process_t (struct stardis* stardis, - struct dummies* dummies, char** tok_ctx) { char* tk = NULL; @@ -1305,14 +1303,14 @@ process_t sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_t(stardis->allocator, &desc->d.t_boundary); - + ERR(init_t(stardis->allocator, &desc->d.t_boundary)); desc->type = DESC_BOUND_T_FOR_SOLID; - desc->d.t_boundary.mat_id = get_dummy_fluid_id(stardis, dummies); + + ERR(get_dummy_fluid_id(stardis, &desc->d.t_boundary->mat_id)); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "temperature boundary name"); - ERR(description_set_name(stardis, &desc->d.t_boundary.name, tk)); - if(find_description_by_name(stardis, &desc->d.t_boundary.name, NULL) + ERR(description_set_name(stardis, &desc->d.t_boundary->name, tk)); + if(find_description_by_name(stardis, &desc->d.t_boundary->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1322,9 +1320,9 @@ process_t } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "temperature"); - res = cstr_to_double(tk, &desc->d.t_boundary.imposed_temperature); + res = cstr_to_double(tk, &desc->d.t_boundary->imposed_temperature); if(res != RES_OK - || desc->d.t_boundary.imposed_temperature < 0) + || desc->d.t_boundary->imposed_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; @@ -1344,7 +1342,6 @@ error: static res_T process_flx (struct stardis* stardis, - struct dummies* dummies, char** tok_ctx) { char* tk = NULL; @@ -1359,14 +1356,14 @@ process_flx sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_f(stardis->allocator, &desc->d.f_boundary); - + ERR(init_f(stardis->allocator, &desc->d.f_boundary)); desc->type = DESC_BOUND_F_FOR_SOLID; - desc->d.f_boundary.mat_id = get_dummy_fluid_id(stardis, dummies); + + ERR(get_dummy_fluid_id(stardis, &desc->d.f_boundary->mat_id)); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "flux boundary name"); - ERR(description_set_name(stardis, &desc->d.f_boundary.name, tk)); - if(find_description_by_name(stardis, &desc->d.f_boundary.name, NULL) + ERR(description_set_name(stardis, &desc->d.f_boundary->name, tk)); + if(find_description_by_name(stardis, &desc->d.f_boundary->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1376,9 +1373,9 @@ process_flx } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "flux"); - res = cstr_to_double(tk, &desc->d.f_boundary.imposed_flux); + res = cstr_to_double(tk, &desc->d.f_boundary->imposed_flux); if(res != RES_OK - || desc->d.f_boundary.imposed_flux == SDIS_FLUX_NONE) { + || desc->d.f_boundary->imposed_flux == SDIS_FLUX_NONE) { /* Flux can be < 0 but not undefined */ if(res == RES_OK) res = RES_BAD_ARG; logger_print(stardis->logger, LOG_ERROR, "Invalid flux: %s\n", tk); @@ -1412,17 +1409,17 @@ process_sfc sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_sf(stardis->allocator, &desc->d.sf_connect); + ERR(init_sf(stardis->allocator, &desc->d.sf_connect)); + desc->type = DESC_SOLID_FLUID_CONNECT; /* Use a medium ID even if there is no medium here * As other cases use media IDs as unique IDs for read_sides_and_files calls * we continue the trend to ensure connection ID is OK */ - desc->type = DESC_SOLID_FLUID_CONNECT; - desc->d.sf_connect.connection_id = allocate_stardis_medium_id(stardis); + desc->d.sf_connect->connection_id = allocate_stardis_medium_id(stardis); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "solid fluid connection name"); - ERR(description_set_name(stardis, &desc->d.sf_connect.name, tk)); - if(find_description_by_name(stardis, &desc->d.sf_connect.name, NULL) + ERR(description_set_name(stardis, &desc->d.sf_connect->name, tk)); + if(find_description_by_name(stardis, &desc->d.sf_connect->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1432,31 +1429,31 @@ process_sfc } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "ref_temperature"); - res = cstr_to_double(tk, &desc->d.sf_connect.ref_temperature); + res = cstr_to_double(tk, &desc->d.sf_connect->ref_temperature); if(res != RES_OK - || desc->d.sf_connect.ref_temperature < 0) + || desc->d.sf_connect->ref_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid reference temperature: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - stardis->t_range[0] = MMIN(stardis->t_range[0], desc->d.sf_connect.ref_temperature); - stardis->t_range[1] = MMAX(stardis->t_range[1], desc->d.sf_connect.ref_temperature); + stardis->t_range[0] = MMIN(stardis->t_range[0], desc->d.sf_connect->ref_temperature); + stardis->t_range[1] = MMAX(stardis->t_range[1], desc->d.sf_connect->ref_temperature); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "emissivity"); - res = cstr_to_double(tk, &desc->d.sf_connect.emissivity); + res = cstr_to_double(tk, &desc->d.sf_connect->emissivity); if(res != RES_OK - || desc->d.sf_connect.emissivity < 0 - || desc->d.h_boundary.emissivity > 1) + || desc->d.sf_connect->emissivity < 0 + || desc->d.h_boundary->emissivity > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid emissivity: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "specular fraction"); - res = cstr_to_double(tk, &desc->d.sf_connect.specular_fraction); + res = cstr_to_double(tk, &desc->d.sf_connect->specular_fraction); if(res != RES_OK - || desc->d.sf_connect.specular_fraction < 0 - || desc->d.sf_connect.specular_fraction > 1) + || desc->d.sf_connect->specular_fraction < 0 + || desc->d.sf_connect->specular_fraction > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid specular fraction: %s\n", tk); @@ -1464,9 +1461,9 @@ process_sfc goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "hc"); - res = cstr_to_double(tk, &desc->d.sf_connect.hc); + res = cstr_to_double(tk, &desc->d.sf_connect->hc); if(res != RES_OK - || desc->d.sf_connect.hc < 0) + || desc->d.sf_connect->hc < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid hc: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; @@ -1500,17 +1497,17 @@ process_ssc sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_ss(stardis->allocator, &desc->d.ss_connect); + ERR(init_ss(stardis->allocator, &desc->d.ss_connect)); + desc->type = DESC_SOLID_SOLID_CONNECT; /* Use a medium ID even if there is no medium here * As other cases use media IDs as unique IDs for read_sides_and_files calls * we continue the trend to ensure connection ID is OK */ - desc->type = DESC_SOLID_SOLID_CONNECT; - desc->d.ss_connect.connection_id = allocate_stardis_medium_id(stardis); + desc->d.ss_connect->connection_id = allocate_stardis_medium_id(stardis); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "solid solid connection name"); - ERR(description_set_name(stardis, &desc->d.ss_connect.name, tk)); - if(find_description_by_name(stardis, &desc->d.ss_connect.name, NULL) + ERR(description_set_name(stardis, &desc->d.ss_connect->name, tk)); + if(find_description_by_name(stardis, &desc->d.ss_connect->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1520,19 +1517,19 @@ process_ssc } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "contact resistance"); - res = cstr_to_double(tk, &desc->d.ss_connect.tcr); + res = cstr_to_double(tk, &desc->d.ss_connect->tcr); if(res != RES_OK - || desc->d.ss_connect.tcr < 0) + || desc->d.ss_connect->tcr < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid contact resistance: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - else if(desc->d.ss_connect.tcr == 0) { + else if(desc->d.ss_connect->tcr == 0) { logger_print(stardis->logger, LOG_WARNING, "Solid-solid connection %s: defining a contact resistance to 0 has " - "no effect\n", str_cget(&desc->d.ss_connect.name)); + "no effect\n", str_cget(&desc->d.ss_connect->name)); } ASSERT(sz <= UINT_MAX); @@ -1639,18 +1636,18 @@ process_solid sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_solid(stardis->allocator, &desc->d.solid); - + ERR(init_solid(stardis->allocator, &desc->d.solid)); desc->type = DESC_MAT_SOLID; - desc->d.solid.solid_id = allocate_stardis_medium_id(stardis); - desc->d.solid.is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); - desc->d.solid.is_outside = 0; + + desc->d.solid->solid_id = allocate_stardis_medium_id(stardis); + desc->d.solid->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + desc->d.solid->is_outside = 0; ASSERT(sz <= UINT_MAX); - desc->d.solid.desc_id = (unsigned)sz; + desc->d.solid->desc_id = (unsigned)sz; CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "solid name"); - ERR(description_set_name(stardis, &desc->d.solid.name, tk)); - if(find_description_by_name(stardis, &desc->d.solid.name, NULL) + ERR(description_set_name(stardis, &desc->d.solid->name, tk)); + if(find_description_by_name(stardis, &desc->d.solid->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1660,55 +1657,55 @@ process_solid } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "lambda"); - res = cstr_to_double(tk, &desc->d.solid.lambda); + res = cstr_to_double(tk, &desc->d.solid->lambda); if(res != RES_OK - || desc->d.solid.lambda <= 0) + || desc->d.solid->lambda <= 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid lambda: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "rho"); - res = cstr_to_double(tk, &desc->d.solid.rho); + res = cstr_to_double(tk, &desc->d.solid->rho); if(res != RES_OK - || desc->d.solid.rho <= 0) + || desc->d.solid->rho <= 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid rho: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "cp"); - res = cstr_to_double(tk, &desc->d.solid.cp); + res = cstr_to_double(tk, &desc->d.solid->cp); if(res != RES_OK - || desc->d.solid.cp <= 0) + || desc->d.solid->cp <= 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid cp: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - ERR(read_delta(stardis, &desc->d.solid.delta, tok_ctx)); + ERR(read_delta(stardis, &desc->d.solid->delta, tok_ctx)); CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "Tinit"); - res = cstr_to_double(tk, &desc->d.solid.tinit); + res = cstr_to_double(tk, &desc->d.solid->tinit); if(res != RES_OK - || desc->d.solid.tinit < 0) + || desc->d.solid->tinit < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid Tinit: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - ERR(read_imposed_temperature(stardis, &desc->d.solid.imposed_temperature, + ERR(read_imposed_temperature(stardis, &desc->d.solid->imposed_temperature, tok_ctx)); - if(desc->d.solid.imposed_temperature >= 0 - && desc->d.solid.imposed_temperature != desc->d.solid.tinit) + if(desc->d.solid->imposed_temperature >= 0 + && desc->d.solid->imposed_temperature != desc->d.solid->tinit) { logger_print(stardis->logger, LOG_ERROR, "Imposed temperature, if defined, must match initial temperature " "(initial: %g; imposed: %g)\n", - desc->d.solid.tinit, desc->d.solid.imposed_temperature); res = RES_BAD_ARG; + desc->d.solid->tinit, desc->d.solid->imposed_temperature); res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "volumic power"); - res = cstr_to_double(tk, &desc->d.solid.vpower); + res = cstr_to_double(tk, &desc->d.solid->vpower); if(res != RES_OK) { /* VPower can be < 0 */ logger_print(stardis->logger, LOG_ERROR, "Invalid volumic power: %s\n", tk); @@ -1745,18 +1742,18 @@ process_fluid sz = darray_descriptions_size_get(&stardis->descriptions); ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); desc = darray_descriptions_data_get(&stardis->descriptions) + sz; - init_fluid(stardis->allocator, &desc->d.fluid); - + ERR(init_fluid(stardis->allocator, &desc->d.fluid)); desc->type = DESC_MAT_FLUID; - desc->d.fluid.fluid_id = allocate_stardis_medium_id(stardis); - desc->d.fluid.is_outside = 0; - desc->d.fluid.is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + + desc->d.fluid->fluid_id = allocate_stardis_medium_id(stardis); + desc->d.fluid->is_outside = 0; + desc->d.fluid->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); ASSERT(sz <= UINT_MAX); - desc->d.fluid.desc_id = (unsigned)sz; + desc->d.fluid->desc_id = (unsigned)sz; CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "fluid name"); - ERR(description_set_name(stardis, &desc->d.fluid.name, tk)); - if(find_description_by_name(stardis, &desc->d.fluid.name, NULL) + ERR(description_set_name(stardis, &desc->d.fluid->name, tk)); + if(find_description_by_name(stardis, &desc->d.fluid->name, NULL) != desc) { logger_print(stardis->logger, LOG_ERROR, @@ -1766,46 +1763,46 @@ process_fluid } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "rho"); - res = cstr_to_double(tk, &desc->d.fluid.rho); + res = cstr_to_double(tk, &desc->d.fluid->rho); if(res != RES_OK - || desc->d.fluid.rho <= 0) + || desc->d.fluid->rho <= 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid rho: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "cp"); - res = cstr_to_double(tk, &desc->d.fluid.cp); + res = cstr_to_double(tk, &desc->d.fluid->cp); if(res != RES_OK - || desc->d.fluid.cp <= 0) + || desc->d.fluid->cp <= 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid cp: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "Tinit"); - res = cstr_to_double(tk, &desc->d.fluid.tinit); + res = cstr_to_double(tk, &desc->d.fluid->tinit); if(res != RES_OK - || desc->d.fluid.tinit < 0) + || desc->d.fluid->tinit < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid Tinit: %s\n", tk); if(res == RES_OK) res = RES_BAD_ARG; goto end; } - ERR(read_imposed_temperature(stardis, &desc->d.fluid.imposed_temperature, + ERR(read_imposed_temperature(stardis, &desc->d.fluid->imposed_temperature, tok_ctx)); - if(desc->d.fluid.imposed_temperature >= 0 - && desc->d.fluid.imposed_temperature != desc->d.fluid.tinit) + if(desc->d.fluid->imposed_temperature >= 0 + && desc->d.fluid->imposed_temperature != desc->d.fluid->tinit) { logger_print(stardis->logger, LOG_ERROR, "Imposed temperature, if defined, must match initial temperature " "(initial: %g; imposed: %g)\n", - desc->d.fluid.tinit, desc->d.fluid.imposed_temperature); res = RES_BAD_ARG; + desc->d.fluid->tinit, desc->d.fluid->imposed_temperature); res = RES_BAD_ARG; goto end; } - ERR(create_solver_fluid(stardis, &desc->d.fluid)); + ERR(create_solver_fluid(stardis, desc->d.fluid)); ASSERT(sz <= UINT_MAX); ERR(read_sides_and_files(stardis, 0, (unsigned)sz, tok_ctx)); @@ -1912,8 +1909,7 @@ res_T process_model_line (const char* file_name, char* line, - struct stardis* stardis, - struct dummies* dummies) + struct stardis* stardis) { res_T res = RES_OK; struct str keep; @@ -1926,13 +1922,13 @@ process_model_line CHK_TOK(strtok_r(line, " \t", &tok_ctx), "model line type"); if(0 == strcasecmp(tk, "H_BOUNDARY_FOR_SOLID")) - ERR(process_h(stardis, dummies, DESC_BOUND_H_FOR_SOLID, &tok_ctx)); + ERR(process_h(stardis, DESC_BOUND_H_FOR_SOLID, &tok_ctx)); else if(0 == strcasecmp(tk, "H_BOUNDARY_FOR_FLUID")) - ERR(process_h(stardis, dummies, DESC_BOUND_H_FOR_FLUID, &tok_ctx)); + ERR(process_h(stardis, DESC_BOUND_H_FOR_FLUID, &tok_ctx)); else if(0 == strcasecmp(tk, "T_BOUNDARY_FOR_SOLID")) - ERR(process_t(stardis, dummies, &tok_ctx)); + ERR(process_t(stardis, &tok_ctx)); else if(0 == strcasecmp(tk, "F_BOUNDARY_FOR_SOLID")) - ERR(process_flx(stardis, dummies, &tok_ctx)); + ERR(process_flx(stardis, &tok_ctx)); else if(0 == strcasecmp(tk, "SOLID_FLUID_CONNECTION")) ERR(process_sfc(stardis, &tok_ctx)); else if(0 == strcasecmp(tk, "SOLID_SOLID_CONNECTION")) @@ -1962,46 +1958,68 @@ error: goto end; } -unsigned +res_T get_dummy_solid_id (struct stardis* stardis, - struct dummies* dummies) + unsigned* id) { - struct solid dummy; - if(dummies->dummy_solid) - return dummies->dummy_solid_id; + res_T res = RES_OK; + struct solid* dummy = NULL; + struct dummies* dummies; + ASSERT(stardis && id); + dummies = &stardis->dummies; + if(dummies->dummy_solid) { + *id = dummies->dummy_solid_id; + goto end; + } + ERR(init_solid(stardis->allocator, &dummy)); + dummies->stardis_solid = dummy; dummies->dummy_solid_id = allocate_stardis_medium_id(stardis); - init_solid(stardis->allocator, &dummy); - dummy.solid_id = dummies->dummy_solid_id; - dummy.is_outside = 1; - dummy.is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); - create_solver_solid(stardis, &dummy); + dummy->solid_id = dummies->dummy_solid_id; + dummy->is_outside = 1; + dummy->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + create_solver_solid(stardis, dummy); dummies->dummy_solid = darray_media_ptr_data_get(&stardis->media)[dummies->dummy_solid_id]; logger_print(stardis->logger, LOG_OUTPUT, "Dummy solid created: (it is medium %u)\n", dummies->dummy_solid_id); - return dummies->dummy_solid_id; + *id = dummies->dummy_solid_id; +end: + return res; +error: + goto end; } -unsigned +res_T get_dummy_fluid_id (struct stardis* stardis, - struct dummies* dummies) + unsigned* id) { - struct fluid dummy; - if(dummies->dummy_fluid) - return dummies->dummy_fluid_id; + res_T res = RES_OK; + struct fluid* dummy = NULL; + struct dummies* dummies; + ASSERT(stardis && id); + dummies = &stardis->dummies; + if(dummies->dummy_fluid) { + *id = dummies->dummy_fluid_id; + goto end; + } + ERR(init_fluid(stardis->allocator, &dummy)); + dummies->stardis_fluid = dummy; dummies->dummy_fluid_id = allocate_stardis_medium_id(stardis); - init_fluid(stardis->allocator, &dummy); - dummy.fluid_id = dummies->dummy_fluid_id; - dummy.is_outside = 1; - dummy.is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); - create_solver_fluid(stardis, &dummy); + dummy->fluid_id = dummies->dummy_fluid_id; + dummy->is_outside = 1; + dummy->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + create_solver_fluid(stardis, dummy); dummies->dummy_fluid = darray_media_ptr_data_get(&stardis->media)[dummies->dummy_fluid_id]; logger_print(stardis->logger, LOG_OUTPUT, "Dummy fluid created: (it is medium %u)\n", dummies->dummy_fluid_id); - return dummies->dummy_fluid_id; + *id = dummies->dummy_fluid_id; +end: + return res; +error: + goto end; } diff --git a/src/stardis-parsing.h b/src/stardis-parsing.h @@ -193,17 +193,16 @@ extern LOCAL_SYM res_T process_model_line (const char* file_name, char* line, - struct stardis* stardis, - struct dummies* dummies); + struct stardis* stardis); -extern LOCAL_SYM unsigned +extern LOCAL_SYM res_T get_dummy_solid_id (struct stardis* stardis, - struct dummies* dummies); + unsigned* id); -extern LOCAL_SYM unsigned +extern LOCAL_SYM res_T get_dummy_fluid_id (struct stardis* stardis, - struct dummies* dummies); + unsigned* id); #endif /*ARGS_H*/ diff --git a/src/stardis-solid.c b/src/stardis-solid.c @@ -19,6 +19,8 @@ #include <sdis.h> +#include <rsys/mem_allocator.h> + #include <limits.h> /******************************************************************************* @@ -30,9 +32,9 @@ solid_get_calorific_capacity (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); + const struct solid* const* solid_props = sdis_data_cget(data); (void)vtx; - return solid_props->cp; + return (*solid_props)->cp; } static double @@ -40,9 +42,9 @@ solid_get_thermal_conductivity (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); + const struct solid* const* solid_props = sdis_data_cget(data); (void)vtx; - return solid_props->lambda; + return (*solid_props)->lambda; } static double @@ -50,9 +52,9 @@ solid_get_volumic_mass (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); + const struct solid* const* solid_props = sdis_data_cget(data); (void)vtx; - return solid_props->rho; + return (*solid_props)->rho; } static double @@ -60,9 +62,9 @@ solid_get_delta (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); + const struct solid* const* solid_props = sdis_data_cget(data); (void)vtx; - return solid_props->delta; + return (*solid_props)->delta; } #if Stardis_VERSION_MINOR == 3 @@ -71,8 +73,8 @@ solid_get_delta_boundary (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); - return solid_props->delta; + const struct solid* const* solid_props = sdis_data_cget(data); + return (*solid_props)->delta; } #endif @@ -81,21 +83,21 @@ solid_get_temperature (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); - if(solid_props->imposed_temperature >= 0) + const struct solid* const* solid_props = sdis_data_cget(data); + if((*solid_props)->imposed_temperature >= 0) /* If there is an imposed temp, it is imposed regardless of time */ - return solid_props->imposed_temperature; - if(vtx->time <= solid_props->t0) { + return (*solid_props)->imposed_temperature; + if(vtx->time <= (*solid_props)->t0) { /* If time is <= t0: use tinit */ - if(solid_props->tinit < 0) { - if(str_is_empty(&solid_props->name)) { + if((*solid_props)->tinit < 0) { + if(str_is_empty(&(*solid_props)->name)) { FATAL("solid_get_temperature: getting undefined Tinit\n"); } else { VFATAL("solid_get_temperature: getting undefined Tinit (solid '%s')\n", - ARG1(str_cget(&solid_props->name))); + ARG1(str_cget(&(*solid_props)->name))); } } - return solid_props->tinit; + return (*solid_props)->tinit; } return -1; /* Unknown temperature */ } @@ -105,9 +107,9 @@ solid_get_power (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { - const struct solid* solid_props = sdis_data_cget(data); + const struct solid* const* solid_props = sdis_data_cget(data); (void)vtx; - return solid_props->vpower; + return (*solid_props)->vpower; } /******************************************************************************* @@ -122,7 +124,7 @@ create_solver_solid res_T res = RES_OK; struct sdis_solid_shader solid_shader = SDIS_SOLID_SHADER_NULL; struct sdis_data* data = NULL; - struct solid* props; + const struct solid** props; /* Could be less restrictive if green output included positions/dates */ ASSERT(stardis && solid_props); @@ -138,8 +140,7 @@ create_solver_solid NULL, &data)); props = sdis_data_get(data); /* Fetch the allocated memory space */ - init_solid(stardis->allocator, props); - cp_solid(props, solid_props); + *props = solid_props; if(solid_props->vpower != 0) solid_shader.volumic_power = solid_get_power; if(solid_props->solid_id >= darray_media_ptr_size_get(&stardis->media)) { ERR(darray_media_ptr_resize(&stardis->media, solid_props->solid_id + 1)); @@ -155,28 +156,46 @@ error: goto end; } -void -init_solid(struct mem_allocator* allocator, struct solid* dst) +res_T +init_solid(struct mem_allocator* allocator, struct solid** dst) { - str_init(allocator, &dst->name); - dst->lambda = 1; - dst->rho = 1; - dst->cp = 1; - dst->delta = 1; - dst->tinit = -1; - dst->imposed_temperature = -1; - dst->vpower = 0; - dst->t0 = 0; - dst->is_outside = 0; - dst->is_green = 0; - dst->desc_id = UINT_MAX; - dst->solid_id = UINT_MAX; + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_ALLOC(allocator, sizeof(struct solid)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + (*dst)->lambda = 1; + (*dst)->rho = 1; + (*dst)->cp = 1; + (*dst)->delta = 1; + (*dst)->tinit = -1; + (*dst)->imposed_temperature = -1; + (*dst)->vpower = 0; + (*dst)->t0 = 0; + (*dst)->is_outside = 0; + (*dst)->is_green = 0; + (*dst)->desc_id = UINT_MAX; + (*dst)->solid_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; } void -release_solid(struct solid* solid) +release_solid + (struct solid* solid, + struct mem_allocator* allocator) { + ASSERT(solid && allocator); str_release(&solid->name); + MEM_RM(allocator, solid); } res_T @@ -201,21 +220,3 @@ end: error: goto end; } - -res_T -cp_solid(struct solid* dst, const struct solid* src) -{ - dst->lambda = src->lambda; - dst->rho = src->rho; - dst->cp = src->cp; - dst->delta = src->delta; - dst->tinit = src->tinit; - dst->imposed_temperature = src->imposed_temperature; - dst->vpower = src->vpower; - dst->t0 = src->t0; - dst->is_outside = src->is_outside; - dst->is_green = src->is_green; - dst->desc_id = src->desc_id; - dst->solid_id = src->solid_id; - return str_copy(&dst->name, &src->name); -} diff --git a/src/stardis-solid.h b/src/stardis-solid.h @@ -20,6 +20,7 @@ #include <rsys/str.h> struct stardis; +struct mem_allocator; /******************************************************************************* * Solid data @@ -40,17 +41,16 @@ struct solid { unsigned solid_id; }; -LOCAL_SYM void -init_solid(struct mem_allocator* allocator, struct solid* dst); +LOCAL_SYM res_T +init_solid(struct mem_allocator* allocator, struct solid** dst); LOCAL_SYM void -release_solid(struct solid* solid); - -LOCAL_SYM res_T -str_print_solid(struct str* str, const struct solid* s); +release_solid + (struct solid* desc, + struct mem_allocator* allocator); LOCAL_SYM res_T -cp_solid(struct solid* dst, const struct solid* src); +str_print_solid(struct str* str, const struct solid* solid); LOCAL_SYM res_T create_solver_solid