commit b975623d49983fc9553a5bda14165ce00c191f86
parent 4589213aee5e26a4e928dbfba1f2b82322443320
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 9 Mar 2022 16:07:23 +0100
Use new stardis-green.h header file
This file is installed along with the stardis app and contains the description of the various types involved in reading and writing binary Green files
Diffstat:
6 files changed, 180 insertions(+), 512 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -56,6 +56,7 @@ configure_file(${GREEN_SOURCE_DIR}/green-version.h.in
###############################################################################
find_package(RCMake 0.4 REQUIRED)
find_package(RSys 0.9 REQUIRED)
+find_package(Stardis 0.8 REQUIRED)
find_package(OpenMP 2.0 REQUIRED)
if(MSVC)
find_package(MuslGetopt REQUIRED)
diff --git a/src/green-compute.c b/src/green-compute.c
@@ -90,12 +90,12 @@ check_green_table_variables_use
ASSERT(green);
ASSERT(!green->references_checked); /* Fix double call in caller */
- FOR_EACH(i, 0, green->counts.ok_count) {
+ FOR_EACH(i, 0, green->header.ok_count) {
const struct sample* sample = green->samples + i;
- unsigned id = sample->header.end_id;
- /* Ambient ID is desc_count */
- ASSERT(id <= green->counts.desc_count);
- ASSERT(id == green->counts.desc_count
+ unsigned id = sample->header.sample_end_description_id;
+ /* Ambient ID is description_count */
+ ASSERT(id <= green->header.description_count);
+ ASSERT(id == green->header.description_count
|| DESC_HOLDS_T(green->descriptions[id].type));
if(sample->header.at_initial)
green->table[id].initial_T_weight++;
@@ -105,14 +105,14 @@ check_green_table_variables_use
FOR_EACH(j, 0, sample->header.pw_count) {
const double w = sample->pw_weights[j];
id = sample->pw_ids[j];
- ASSERT(id < green->counts.desc_count);
+ ASSERT(id < green->header.description_count);
ASSERT(DESC_IS_MEDIUM(green->descriptions[id].type));
green->table[id].other_weight += w;
}
FOR_EACH(j, 0, sample->header.fx_count) {
const double w = sample->fx_weights[j];
id = sample->fx_ids[j];
- ASSERT(id < green->counts.desc_count);
+ ASSERT(id < green->header.description_count);
ASSERT(DESC_IS_F(green->descriptions[id].type));
green->table[id].other_weight += w;
}
@@ -140,9 +140,9 @@ check_green_table_variables_use
&(green->table[Elt].Field ## _name), &vd___)); \
} (void)0
-#define MK_VAR(Str) \
+#define MK_VAR(Str, Desc) \
for(;;) { \
- size_t n = (size_t)snprintf(buf, bufsz, (Str), str_cget(name));\
+ size_t n = (size_t)snprintf(buf, bufsz, (Str), (Desc).name);\
if(n < bufsz) break; \
buf = MEM_REALLOC(green->allocator, buf, n + 1); \
bufsz = n + 1; \
@@ -159,24 +159,22 @@ build_green_table
ASSERT(green);
- green->table = MEM_CALLOC(green->allocator, 1 + green->counts.desc_count,
+ green->table = MEM_CALLOC(green->allocator, 1+green->header.description_count,
sizeof(*green->table));
buf = MEM_ALLOC(green->allocator, bufsz);
if(!green->table || ! buf) {
res = RES_MEM_ERR;
goto error;
}
- FOR_EACH(i, 0, 1 + green->counts.desc_count)
+ FOR_EACH(i, 0, 1 + green->header.description_count)
init_table_elt(green->allocator, green->table + i);
check_green_table_variables_use(green);
- FOR_EACH(i, 0, green->counts.desc_count) {
- struct description* desc = green->descriptions + i;
- struct str* name;
- ERR(get_description_name(desc, &name));
+ FOR_EACH(i, 0, green->header.description_count) {
+ struct green_description* desc = green->descriptions + i;
if(DESC_IS_T(desc->type)) {
- MK_VAR("%s.T");
+ MK_VAR("%s.T", desc->d.t_boundary);
ERR(str_set(&green->table[i].imposed_T_name, buf));
ASSERT(desc->d.t_boundary.imposed_temperature >= 0);
green->table[i].imposed_T_value = desc->d.t_boundary.imposed_temperature;
@@ -184,7 +182,7 @@ build_green_table
INSERT(i, imposed_T);
}
else if(DESC_IS_H(desc->type)) {
- MK_VAR("%s.T");
+ MK_VAR("%s.T", desc->d.h_boundary);
ERR(str_set(&green->table[i].imposed_T_name, buf));
ASSERT(desc->d.h_boundary.imposed_temperature >= 0);
green->table[i].imposed_T_value = desc->d.h_boundary.imposed_temperature;
@@ -192,49 +190,48 @@ build_green_table
INSERT(i, imposed_T);
}
else if(DESC_IS_F(desc->type)) {
- MK_VAR("%s.F");
+ MK_VAR("%s.F", desc->d.f_boundary);
ERR(str_set(&green->table[i].other_name, buf));
green->table[i].other_value = desc->d.f_boundary.imposed_flux;
green->table[i].other_defined = 1;
INSERT(i, other);
}
- else if(DESC_IS_MEDIUM(desc->type)) {
- if(desc->type == DESC_MAT_SOLID) {
- MK_VAR("%s.T");
- ERR(str_set(&green->table[i].imposed_T_name, buf));
- green->table[i].imposed_T_value = desc->d.solid.imposed_temperature;
- green->table[i].imposed_T_defined = 1;
- if(green->table[i].imposed_T_value < 0)
- green->table[i].imposed_T_unknown = 1;
- INSERT(i, imposed_T);
- MK_VAR("%s.Tinit");
- ERR(str_set(&green->table[i].initial_T_name, buf));
- green->table[i].initial_T_value = desc->d.solid.tinit;
- green->table[i].initial_T_defined = 1;
- if(green->table[i].initial_T_value < 0)
- green->table[i].initial_T_unknown = 1;
- INSERT(i, initial_T);
- MK_VAR("%s.VP");
- ERR(str_set(&green->table[i].other_name, buf));
- green->table[i].other_value = desc->d.solid.vpower;
- green->table[i].other_defined = 1;
- INSERT(i, other);
- } else {
- MK_VAR("%s.T");
- ERR(str_set(&green->table[i].imposed_T_name, buf));
- green->table[i].imposed_T_value = desc->d.fluid.imposed_temperature;
- green->table[i].imposed_T_defined = 1;
- if(green->table[i].imposed_T_value < 0)
- green->table[i].imposed_T_unknown = 1;
- INSERT(i, imposed_T);
- MK_VAR("%s.Tinit");
- ERR(str_set(&green->table[i].initial_T_name, buf));
- green->table[i].initial_T_value = desc->d.fluid.tinit;
- green->table[i].initial_T_defined = 1;
- if(green->table[i].initial_T_value < 0)
- green->table[i].initial_T_unknown = 1;
- INSERT(i, initial_T);
- }
+ else if(desc->type == GREEN_MAT_SOLID) {
+ MK_VAR("%s.T", desc->d.solid);
+ ERR(str_set(&green->table[i].imposed_T_name, buf));
+ green->table[i].imposed_T_value = desc->d.solid.imposed_temperature;
+ green->table[i].imposed_T_defined = 1;
+ if(green->table[i].imposed_T_value < 0)
+ green->table[i].imposed_T_unknown = 1;
+ INSERT(i, imposed_T);
+ MK_VAR("%s.Tinit", desc->d.solid);
+ ERR(str_set(&green->table[i].initial_T_name, buf));
+ green->table[i].initial_T_value = desc->d.solid.initial_temperature;
+ green->table[i].initial_T_defined = 1;
+ if(green->table[i].initial_T_value < 0)
+ green->table[i].initial_T_unknown = 1;
+ INSERT(i, initial_T);
+ MK_VAR("%s.VP", desc->d.solid);
+ ERR(str_set(&green->table[i].other_name, buf));
+ green->table[i].other_value = desc->d.solid.volumic_power;
+ green->table[i].other_defined = 1;
+ INSERT(i, other);
+ }
+ else if(desc->type == GREEN_MAT_FLUID) {
+ MK_VAR("%s.T", desc->d.fluid);
+ ERR(str_set(&green->table[i].imposed_T_name, buf));
+ green->table[i].imposed_T_value = desc->d.fluid.imposed_temperature;
+ green->table[i].imposed_T_defined = 1;
+ if(green->table[i].imposed_T_value < 0)
+ green->table[i].imposed_T_unknown = 1;
+ INSERT(i, imposed_T);
+ MK_VAR("%s.Tinit", desc->d.fluid);
+ ERR(str_set(&green->table[i].initial_T_name, buf));
+ green->table[i].initial_T_value = desc->d.fluid.initial_temperature;
+ green->table[i].initial_T_defined = 1;
+ if(green->table[i].initial_T_value < 0)
+ green->table[i].initial_T_unknown = 1;
+ INSERT(i, initial_T);
}
else if(DESC_IS_CONNECTION(desc->type)) {
/* No variables here */
@@ -245,10 +242,11 @@ build_green_table
goto error;
}
}
- /* Ambient ID is desc_count */
- ambient_id = green->counts.desc_count;
+ /* Ambient ID is description_count */
+ ambient_id = green->header.description_count;
ERR(str_set(&green->table[ambient_id].imposed_T_name, "AMBIENT"));
- green->table[ambient_id].imposed_T_value = green->ambient_temp;
+ green->table[ambient_id].imposed_T_value
+ = green->header.ambient_radiative_temperature;
green->table[ambient_id].imposed_T_defined = 1;
INSERT(ambient_id, imposed_T);
@@ -267,7 +265,7 @@ applied_settings_set_defaults
struct applied_settings_elt* settings)
{
unsigned i;
- FOR_EACH(i, 0, 1 + green->counts.desc_count) {
+ FOR_EACH(i, 0, 1 + green->header.description_count) {
settings[i].imposed_T_value = green->table[i].imposed_T_value;
settings[i].initial_T_value = green->table[i].initial_T_value;
settings[i].other_value = green->table[i].other_value;
@@ -287,11 +285,11 @@ green_compute_1
ASSERT(green && E && STD);
- FOR_EACH(i, 0, green->counts.ok_count) {
+ FOR_EACH(i, 0, green->header.ok_count) {
const struct sample* sample = green->samples + i;
- unsigned id = sample->header.end_id;
- ASSERT(id <= green->counts.desc_count); /* Ambient ID is desc_count */
- ASSERT(id == green->counts.desc_count
+ unsigned id = sample->header.sample_end_description_id;
+ ASSERT(id <= green->header.description_count); /* Ambient ID is description_count */
+ ASSERT(id == green->header.description_count
|| DESC_IS_T(green->descriptions[id].type)
|| DESC_IS_H(green->descriptions[id].type)
|| DESC_IS_MEDIUM(green->descriptions[id].type));
@@ -308,7 +306,7 @@ green_compute_1
FOR_EACH(j, 0, sample->header.pw_count) {
const double w = sample->pw_weights[j];
id = sample->pw_ids[j];
- ASSERT(id < green->counts.desc_count);
+ ASSERT(id < green->header.description_count);
ASSERT(DESC_IS_MEDIUM(green->descriptions[id].type));
ASSERT(green->table[id].other_defined && !green->table[id].other_unknown);
Ti += w * settings[id].other_value;
@@ -316,7 +314,7 @@ green_compute_1
FOR_EACH(j, 0, sample->header.fx_count) {
const double w = sample->fx_weights[j];
id = sample->fx_ids[j];
- ASSERT(id < green->counts.desc_count);
+ ASSERT(id < green->header.description_count);
ASSERT(DESC_IS_F(green->descriptions[id].type));
ASSERT(green->table[id].other_defined && !green->table[id].other_unknown);
Ti += w * settings[id].other_value;
@@ -324,9 +322,9 @@ green_compute_1
T += Ti;
T2 += Ti * Ti;
}
- *E = T / (double)green->counts.ok_count;
- V = T2 / (double)green->counts.ok_count - *E * *E;
- *STD = (V > 0) ? sqrt(V / (double)green->counts.ok_count) : 0;
+ *E = T / (double)green->header.ok_count;
+ V = T2 / (double)green->header.ok_count - *E * *E;
+ *STD = (V > 0) ? sqrt(V / (double)green->header.ok_count) : 0;
}
static int
@@ -562,8 +560,8 @@ green_compute
if(res != RES_OK) continue;
if(settings[t] == NULL) {
- /* desc_count + 1 for AMBIENT */
- settings[t] = MEM_CALLOC(green->allocator, 1 + green->counts.desc_count,
+ /* description_count + 1 for AMBIENT */
+ settings[t] = MEM_CALLOC(green->allocator, 1 + green->header.description_count,
sizeof(**settings));
if(settings[t] == NULL) {
res = RES_MEM_ERR;
diff --git a/src/green-description.h b/src/green-description.h
@@ -1,129 +0,0 @@
-/* Copyright (C) 2020, 2021 |Meso|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 GREEN_DESCRIPTION_H
-#define GREEN_DESCRIPTION_H
-
-#include <rsys/str.h>
-
-/* Different types of descriptions */
-enum description_type {
- DESC_MAT_SOLID,
- DESC_MAT_FLUID,
- DESC_BOUND_H_FOR_FLUID,
- DESC_BOUND_H_FOR_SOLID,
- DESC_BOUND_T_FOR_FLUID,
- DESC_BOUND_T_FOR_SOLID,
- DESC_BOUND_F_FOR_SOLID,
- DESC_SOLID_FLUID_CONNECT,
- DESCRIPTION_TYPE_COUNT__,
- DESC_OUTSIDE
-};
-
-#define DESC_IS_H(D) \
- ((D) == DESC_BOUND_H_FOR_SOLID || (D) == DESC_BOUND_H_FOR_FLUID)
-#define DESC_IS_T(D) \
- ((D) == DESC_BOUND_T_FOR_SOLID || (D) == DESC_BOUND_T_FOR_FLUID)
-
-struct mat_fluid {
- struct str name;
- unsigned fluid_id;
- double rho;
- double cp;
- double tinit;
- double imposed_temperature;
-};
-
-struct mat_solid {
- struct str name;
- unsigned solid_id;
- double lambda;
- double rho;
- double cp;
- double delta;
- double tinit;
- double imposed_temperature;
- double vpower;
-};
-
-struct h_boundary {
- struct str name;
- unsigned mat_id;
- double emissivity;
- double specular_fraction;
- double hc;
- double imposed_temperature;
-};
-
-struct t_boundary {
- struct str name;
- unsigned mat_id;
- double emissivity;
- double specular_fraction;
- double hc;
- double imposed_temperature;
-};
-
-struct f_boundary {
- struct str name;
- unsigned mat_id;
- double imposed_flux;
-};
-
-struct solid_fluid_connect {
- struct str name;
- double emissivity;
- double specular_fraction;
- double hc;
-};
-
-struct description {
- enum description_type type;
- union {
- struct mat_fluid fluid;
- struct mat_solid solid;
- struct t_boundary t_boundary;
- struct f_boundary f_boundary;
- struct h_boundary h_boundary;
- struct solid_fluid_connect sf_connect;
- } d;
-};
-
-static INLINE const struct str*
-get_description_name
- (const struct description* desc)
-{
- ASSERT(desc);
- switch (desc->type) {
- case DESC_MAT_SOLID:
- return &desc->d.solid.name;
- case DESC_MAT_FLUID:
- return &desc->d.fluid.name;
- case DESC_BOUND_T_FOR_SOLID:
- case DESC_BOUND_T_FOR_FLUID:
- return &desc->d.t_boundary.name;
- case DESC_BOUND_H_FOR_SOLID:
- case DESC_BOUND_H_FOR_FLUID:
- return &desc->d.h_boundary.name;
- case DESC_BOUND_F_FOR_SOLID:
- return &desc->d.f_boundary.name;
- case DESC_SOLID_FLUID_CONNECT:
- return &desc->d.sf_connect.name;
- default:
- FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n");
- }
-}
-
-#endif /* GREEN_DESCRIPTION_H */
diff --git a/src/green-input.c b/src/green-input.c
@@ -63,92 +63,58 @@ read_green_function
{
res_T res = RES_OK;
unsigned i;
- char* pool_ptr;
- const char expected_green_string[] = "GREEN_BIN_FILE:";
- const unsigned expected_file_fmt_version = 4;
- char green_string[sizeof(expected_green_string)];
- unsigned file_fmt_version;
ASSERT(green && stream);
+
+ /* Read header */
+ FR(&green->header, 1);
+
/* Check Green string and file format version */
- FR(green_string, sizeof(green_string));
- if(strncmp(expected_green_string, green_string, sizeof(expected_green_string)))
- {
+ if(strcmp(green->header.green_string, BIN_FILE_IDENT_STRING)) {
logger_print(green->logger, LOG_ERROR,
"File is not a binary Green file.\n");
res = RES_BAD_ARG;
goto error;
}
- FR(&file_fmt_version, 1);
- if(expected_file_fmt_version != file_fmt_version) {
+ if(green->header.file_format_version != GREEN_FILE_FORMAT_VERSION) {
logger_print(green->logger, LOG_ERROR,
"Incompatible file format version (%u VS expected %u).\n",
- file_fmt_version, expected_file_fmt_version);
+ green->header.file_format_version, GREEN_FILE_FORMAT_VERSION);
res = RES_BAD_ARG;
goto error;
}
- /* Read counts */
- FR(&green->counts, 1);
- if(green->counts.desc_count !=
- (green->counts.smed_count + green->counts.fmed_count
- + green->counts.tbound_count + green->counts.hbound_count
- + green->counts.fbound_count + green->counts.sfconnect_count
- + green->counts.ssconnect_count))
+ /* Check counts */
+ if(green->header.description_count !=
+ (green->header.solid_count + green->header.fluid_count
+ + green->header.tbound_count + green->header.hbound_count
+ + green->header.fbound_count + green->header.sfconnect_count
+ + green->header.ssconnect_count))
{
logger_print(green->logger, LOG_ERROR,
"Inconsistant description counts (%u).\n",
- green->counts.desc_count);
+ green->header.description_count);
res = RES_BAD_ARG;
goto error;
}
/* Read descriptions*/
- green->descriptions = MEM_CALLOC(green->allocator, green->counts.desc_count,
- sizeof(*green->descriptions));
+ green->descriptions = MEM_CALLOC(green->allocator,
+ green->header.description_count, sizeof(*green->descriptions));
if(!green->descriptions) {
res = RES_MEM_ERR;
goto error;
}
- FR(green->descriptions, green->counts.desc_count);
-
- /* Read names */
- green->names_pool = pool_ptr = MEM_CALLOC(green->allocator,
- green->counts.name_pool_sz, sizeof(*green->names_pool));
- if(!green->names_pool) {
- res = RES_MEM_ERR;
- goto error;
- }
- FR(green->names_pool, green->counts.name_pool_sz);
- FOR_EACH(i, 0, green->counts.desc_count) {
- struct description* desc = green->descriptions + i;
- struct str* name;
- const size_t len = strlen(pool_ptr);
- res = get_description_name(desc, &name);
- if(res != RES_OK) {
- logger_print(green->logger, LOG_ERROR, "Invalid description type.\n");
- goto error;
- }
- name->cstr = pool_ptr;
- pool_ptr += len + 1;
- }
- ASSERT(pool_ptr == green->names_pool + green->counts.name_pool_sz);
-
- /* Read radiative temperatures */
- FR(&green->ambient_temp, 1);
- FR(&green->ref_temp, 1);
-
- /* Read time range */
- FR(&green->time_range, 2);
+ FR(green->descriptions, green->header.description_count);
/* Read samples*/
- green->samples = MEM_CALLOC(green->allocator, green->counts.ok_count,
+ green->samples = MEM_CALLOC(green->allocator, green->header.ok_count,
sizeof(*green->samples));
if(!green->samples) {
res = RES_MEM_ERR;
goto error;
}
- FOR_EACH(i, 0, green->counts.ok_count) {
+ FOR_EACH(i, 0, green->header.ok_count) {
ERR(read_sample(green->samples + i, green->allocator, green, stream));
}
diff --git a/src/green-output.c b/src/green-output.c
@@ -171,7 +171,7 @@ dump_green_info
"= value</b></u> in the tables below.</p>");
fst = 1;
- FOR_EACH(i, 0, green->counts.desc_count + 1) {
+ FOR_EACH(i, 0, green->header.description_count + 1) {
struct table_elt* elt = green->table + i;
if(elt->imposed_T_defined && elt->imposed_T_weight > 0) {
if(!fst) fprintf(stream, ", ");
@@ -201,7 +201,7 @@ dump_green_info
"below.</p>\n");
fst = 1;
- FOR_EACH(i, 0, green->counts.desc_count + 1) {
+ FOR_EACH(i, 0, green->header.description_count + 1) {
struct table_elt* elt = green->table + i;
if(elt->imposed_T_defined
&& !elt->imposed_T_unknown && elt->imposed_T_weight == 0) {
@@ -235,7 +235,7 @@ dump_green_info
"</p>\n");
fst = 1;
- FOR_EACH(i, 0, green->counts.desc_count + 1) {
+ FOR_EACH(i, 0, green->header.description_count + 1) {
struct table_elt* elt = green->table + i;
if(elt->imposed_T_unknown) {
if(!fst) fprintf(stream, ", ");
@@ -257,18 +257,18 @@ dump_green_info
fprintf(stream, "<h2>Formula of the Monte-Carlo estimate</h2>\n");
- if(green->time_range[0] == green->time_range[1])
+ if(green->header.time_range[0] == green->header.time_range[1])
fprintf(stream, "<p>The Monte-Carlo estimate of the Green function of the "
"system at t=%g is as follows:</p>\n",
- green->time_range[0]);
+ green->header.time_range[0]);
else
fprintf(stream, "<p>The Monte-Carlo estimate of the Green function of the "
"system with t in [%g %g] is as follows:</p>\n",
- SPLIT2(green->time_range));
+ SPLIT2(green->header.time_range));
/* Print result */
fst = 1;
- FOR_EACH(i, 0, 1 + green->counts.desc_count) {
+ FOR_EACH(i, 0, 1 + green->header.description_count) {
if(green->table[i].imposed_T_weight > 0) {
double k;
CHK(green->table[i].imposed_T_defined
@@ -277,7 +277,7 @@ dump_green_info
else fprintf(stream, " + ");
fst = 0;
k = (double)green->table[i].imposed_T_weight
- / (double)green->counts.ok_count;
+ / (double)green->header.ok_count;
t += k * green->table[i].imposed_T_value;
fprintf(stream, "%g * <b>%s</b>",
k, str_cget(&green->table[i].imposed_T_name));
@@ -290,19 +290,19 @@ dump_green_info
else fprintf(stream, " + ");
fst = 0;
k = (double)green->table[i].initial_T_weight
- / (double)green->counts.ok_count;
+ / (double)green->header.ok_count;
t += k * green->table[i].initial_T_value;
fprintf(stream, "%g * <b>%s</b>",
k, str_cget(&green->table[i].initial_T_name));
}
}
ASSERT(!fst);
- FOR_EACH(i, 0, green->counts.desc_count) {
+ FOR_EACH(i, 0, green->header.description_count) {
if(green->table[i].other_weight) {
double k;
CHK(green->table[i].other_defined);
k = (double)green->table[i].other_weight
- / (double)green->counts.ok_count;
+ / (double)green->header.ok_count;
t += k * green->table[i].other_value;
fprintf(stream, " + %g * <b>%s</b>",
k, str_cget(&green->table[i].other_name));
@@ -326,32 +326,32 @@ dump_green_info
fprintf(stream, " <th>Failures</th>\n");
fprintf(stream, "</tr>\n");
fprintf(stream, "<tr>\n");
- CELL(u, green->counts.smed_count);
- CELL(u, green->counts.fmed_count);
- CELL(u, green->counts.tbound_count);
- CELL(u, green->counts.hbound_count);
- CELL(u, green->counts.fbound_count);
- CELL(u, green->counts.sfconnect_count);
- CELL(u, green->counts.ssconnect_count);
- CELL(lu, (long unsigned)green->counts.ok_count);
- CELL(lu, (long unsigned)green->counts.failed_count);
+ CELL(u, green->header.solid_count);
+ CELL(u, green->header.fluid_count);
+ CELL(u, green->header.tbound_count);
+ CELL(u, green->header.hbound_count);
+ CELL(u, green->header.fbound_count);
+ CELL(u, green->header.sfconnect_count);
+ CELL(u, green->header.ssconnect_count);
+ CELL(lu, (long unsigned)green->header.ok_count);
+ CELL(lu, (long unsigned)green->header.failed_count);
fprintf(stream, "</tr>\n");
fprintf(stream, "</table>\n");
/* Solids table */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct mat_solid* sl;
- if(desc->type != DESC_MAT_SOLID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_solid* sl;
+ if(desc->type != GREEN_MAT_SOLID) continue;
if(!local_count) {
fprintf(stream, "<h2>Solids</h2>\n");
fprintf(stream, "<table>\n");
fprintf(stream, "<tr>\n");
fprintf(stream, " <th>Name</th>\n");
- fprintf(stream, " <th>Lambda</th>\n");
- fprintf(stream, " <th>Rho</th>\n");
- fprintf(stream, " <th>Cp</th>\n");
+ fprintf(stream, " <th>Conductivity</th>\n");
+ fprintf(stream, " <th>Volumic mass</th>\n");
+ fprintf(stream, " <th>Calorific capacity</th>\n");
fprintf(stream, " <th>Volumic Power</th>\n");
fprintf(stream, " <th>Imposed temperature</th>\n");
fprintf(stream, " <th>Initial temperature</th>\n");
@@ -359,10 +359,10 @@ dump_green_info
}
sl = &desc->d.solid;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&sl->name));
- CELL(g, sl->lambda);
- CELL(g, sl->rho);
- CELL(g, sl->cp);
+ CELL(s, sl->name);
+ CELL(g, sl->conductivity);
+ CELL(g, sl->volumic_mass);
+ CELL(g, sl->calorific_capacity);
VAR_CELL(i, other);
VAR_CELL(i, imposed_T);
VAR_CELL(i, initial_T);
@@ -373,26 +373,26 @@ dump_green_info
/* Fluids table */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct mat_fluid* fl;
- if(desc->type != DESC_MAT_FLUID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_fluid* fl;
+ if(desc->type != GREEN_MAT_FLUID) continue;
if(!local_count) {
fprintf(stream, "<h2>Fluids</h2>\n");
fprintf(stream, "<table>\n");
fprintf(stream, "<tr>\n");
fprintf(stream, " <th>Name</th>\n");
- fprintf(stream, " <th>Rho</th>\n");
- fprintf(stream, " <th>Cp</th>\n");
+ fprintf(stream, " <th>Volumic mass</th>\n");
+ fprintf(stream, " <th>Calorific capacity</th>\n");
fprintf(stream, " <th>Imposed temperature</th>\n");
fprintf(stream, " <th>Initial temperature</th>\n");
fprintf(stream, "</tr>\n");
}
fl = &desc->d.fluid;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&fl->name));
- CELL(g, fl->rho);
- CELL(g, fl->cp);
+ CELL(s, fl->name);
+ CELL(g, fl->volumic_mass);
+ CELL(g, fl->calorific_capacity);
VAR_CELL(i, imposed_T);
VAR_CELL(i, initial_T);
fprintf(stream, "</tr>\n");
@@ -402,10 +402,10 @@ dump_green_info
/* T boundaries tables */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct t_boundary* bd;
- if(desc->type != DESC_BOUND_T_FOR_SOLID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_t_boundary* bd;
+ if(desc->type != GREEN_BOUND_T_FOR_SOLID) continue;
if(!local_count) {
fprintf(stream, "<h2>T boundaries for solids</h2>\n");
fprintf(stream, "<table>\n");
@@ -416,7 +416,7 @@ dump_green_info
}
bd = &desc->d.t_boundary;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&bd->name));
+ CELL(s, bd->name);
ASSERT(green->table[i].imposed_T_defined);
VAR_CELL(i, imposed_T);
fprintf(stream, "</tr>\n");
@@ -426,10 +426,10 @@ dump_green_info
/* H boundaries tables */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct h_boundary* bd;
- if(desc->type != DESC_BOUND_H_FOR_SOLID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_h_boundary* bd;
+ if(desc->type != GREEN_BOUND_H_FOR_SOLID) continue;
if(!local_count) {
fprintf(stream, "<h2>H boundaries for solids</h2>\n");
fprintf(stream, "<table>\n");
@@ -437,16 +437,16 @@ dump_green_info
fprintf(stream, " <th>Name</th>\n");
fprintf(stream, " <th>Emissivity</th>\n");
fprintf(stream, " <th>Specular Fraction</th>\n");
- fprintf(stream, " <th>Hc</th>\n");
+ fprintf(stream, " <th>Convection coefficient</th>\n");
fprintf(stream, " <th>Temperature</th>\n");
fprintf(stream, "</tr>\n");
}
bd = &desc->d.h_boundary;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&bd->name));
+ CELL(s, bd->name);
CELL(g, bd->emissivity);
CELL(g, bd->specular_fraction);
- CELL(g, bd->hc);
+ CELL(g, bd->convection_coefficient);
ASSERT(green->table[i].imposed_T_defined);
VAR_CELL(i, imposed_T);
fprintf(stream, "</tr>\n");
@@ -455,10 +455,10 @@ dump_green_info
if(local_count) fprintf(stream, "</table>\n");
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct h_boundary* bd;
- if(desc->type != DESC_BOUND_H_FOR_FLUID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_h_boundary* bd;
+ if(desc->type != GREEN_BOUND_H_FOR_FLUID) continue;
if(!local_count) {
fprintf(stream, "<h2>H boundaries for fluids</h2>\n");
fprintf(stream, "<table>\n");
@@ -466,16 +466,16 @@ dump_green_info
fprintf(stream, " <th>Name</th>\n");
fprintf(stream, " <th>Emissivity</th>\n");
fprintf(stream, " <th>Specular Fraction</th>\n");
- fprintf(stream, " <th>Hc</th>\n");
+ fprintf(stream, " <th>Convection coefficient</th>\n");
fprintf(stream, " <th>Temperature</th>\n");
fprintf(stream, "</tr>\n");
}
bd = &desc->d.h_boundary;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&bd->name));
+ CELL(s, bd->name);
CELL(g, bd->emissivity);
CELL(g, bd->specular_fraction);
- CELL(g, bd->hc);
+ CELL(g, bd->convection_coefficient);
ASSERT(green->table[i].imposed_T_defined);
VAR_CELL(i, imposed_T);
fprintf(stream, "</tr>\n");
@@ -485,10 +485,10 @@ dump_green_info
/* F boundaries table */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct f_boundary* bd;
- if(desc->type != DESC_BOUND_F_FOR_SOLID) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_f_boundary* bd;
+ if(desc->type != GREEN_BOUND_F_FOR_SOLID) continue;
if(!local_count) {
fprintf(stream, "<h2>F boundaries for solids</h2>\n");
fprintf(stream, "<table>\n");
@@ -499,7 +499,7 @@ dump_green_info
}
bd = &desc->d.f_boundary;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&bd->name));
+ CELL(s, bd->name);
ASSERT(green->table[i].other_defined);
VAR_CELL(i, other);
fprintf(stream, "</tr>\n");
@@ -509,10 +509,10 @@ dump_green_info
/* S-F connection table */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct solid_fluid_connect* sf;
- if(desc->type != DESC_SOLID_FLUID_CONNECT) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_solid_fluid_connect* sf;
+ if(desc->type != GREEN_SOLID_FLUID_CONNECT) continue;
if(!local_count) {
fprintf(stream, "<h2>Solid-Fluid connections</h2>\n");
fprintf(stream, "<table>\n");
@@ -520,15 +520,15 @@ dump_green_info
fprintf(stream, " <th>Name</th>\n");
fprintf(stream, " <th>Emissivity</th>\n");
fprintf(stream, " <th>Specular Fraction</th>\n");
- fprintf(stream, " <th>Hc</th>\n");
+ fprintf(stream, " <th>Convection coefficient</th>\n");
fprintf(stream, "</tr>\n");
}
sf = &desc->d.sf_connect;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&sf->name));
+ CELL(s, sf->name);
CELL(g, sf->emissivity);
CELL(g, sf->specular_fraction);
- CELL(g, sf->hc);
+ CELL(g, sf->convection_coefficient);
fprintf(stream, "</tr>\n");
local_count++;
}
@@ -536,10 +536,10 @@ dump_green_info
/* S-S connection table */
local_count = 0;
- FOR_EACH(i, 0, green->counts.desc_count) {
- const struct description* desc = green->descriptions + i;
- const struct solid_solid_connect* ss;
- if(desc->type != DESC_SOLID_SOLID_CONNECT) continue;
+ FOR_EACH(i, 0, green->header.description_count) {
+ const struct green_description* desc = green->descriptions + i;
+ const struct green_solid_solid_connect* ss;
+ if(desc->type != GREEN_SOLID_SOLID_CONNECT) continue;
if(!local_count) {
fprintf(stream, "<h2>Solid-Solid connections</h2>\n");
fprintf(stream, "<table>\n");
@@ -550,8 +550,8 @@ dump_green_info
}
ss = &desc->d.ss_connect;
fprintf(stream, "<tr>\n");
- CELL(s, str_cget(&ss->name));
- CELL(g, ss->tcr);
+ CELL(s, ss->name);
+ CELL(g, ss->thermal_contact_resistance);
fprintf(stream, "</tr>\n");
local_count++;
}
@@ -566,12 +566,12 @@ dump_green_info
fprintf(stream, "</tr>\n");
fprintf(stream, "<tr>\n");
CELL(s, "Ambient");
- ASSERT(green->table[green->counts.desc_count].imposed_T_defined);
- VAR_CELL(green->counts.desc_count, imposed_T);
+ ASSERT(green->table[green->header.description_count].imposed_T_defined);
+ VAR_CELL(green->header.description_count, imposed_T);
fprintf(stream, "</tr>\n");
fprintf(stream, "<tr>\n");
CELL(s, "Linearization");
- CELL(g, green->ref_temp);
+ CELL(g, green->header.ambient_radiative_temperature_reference);
fprintf(stream, "</tr>\n");
fprintf(stream, "</table>\n");
diff --git a/src/green-types.h b/src/green-types.h
@@ -22,6 +22,7 @@
#include <rsys/dynamic_array.h>
#include <rsys/dynamic_array_char.h>
#include <rsys/dynamic_array_str.h>
+#include <stardis-green.h>
#include <string.h>
#include <omp.h>
@@ -77,33 +78,6 @@ log_prt(const char* msg, void* ctx)
}
/*
- * Counts read from the binary file
- */
-struct bfile_green_counts {
- unsigned desc_count, smed_count, fmed_count, tbound_count, hbound_count,
- fbound_count, sfconnect_count, ssconnect_count, name_pool_sz;
- size_t ok_count, failed_count;
-};
-
-static INLINE void
-init_green_counts
- (struct bfile_green_counts* counts)
-{
- ASSERT(counts);
- counts->desc_count = 0;
- counts->smed_count = 0;
- counts->fmed_count = 0;
- counts->tbound_count = 0;
- counts->hbound_count = 0;
- counts->fbound_count = 0;
- counts->sfconnect_count = 0;
- counts->ssconnect_count = 0;
- counts->name_pool_sz = 0;
- counts->ok_count = 0;
- counts->failed_count = 0;
-}
-
-/*
* A type for green mode
*/
enum green_mode {
@@ -121,14 +95,8 @@ enum green_mode {
/*
* The type to store a green sample
*/
-struct sample_header {
- unsigned end_id;
- unsigned pw_count, fx_count;
- char at_initial;
-};
-
struct sample {
- struct sample_header header;
+ struct green_sample_header header;
unsigned* pw_ids;
double* pw_weights;
unsigned* fx_ids;
@@ -263,11 +231,8 @@ struct result {
struct green {
struct mem_allocator* allocator;
struct logger* logger;
- struct bfile_green_counts counts;
- char* names_pool;
- struct description* descriptions;
- double ambient_temp, ref_temp;
- double time_range[2];
+ struct green_file_header header;
+ struct green_description* descriptions;
struct table_elt* table;
struct sample* samples;
int references_checked, unused_variables, unknown_variables;
@@ -287,13 +252,9 @@ green_init
ASSERT(alloc && green);
green->allocator = alloc;
green->logger = logger;
- green->names_pool = NULL;
green->descriptions = NULL;
green->table = NULL;
green->samples = NULL;
- init_green_counts(&green->counts);
- green->ambient_temp = 0;
- green->ref_temp = 0;
green->references_checked = 0;
green->unused_variables = 0;
green->unknown_variables = 0;
@@ -310,15 +271,14 @@ green_release
unsigned i;
ASSERT(green);
- MEM_RM(green->allocator, green->names_pool);
MEM_RM(green->allocator, green->descriptions);
if(green->samples) { /* On error, samples could be not yet allocated */
- FOR_EACH(i, 0, green->counts.ok_count)
+ FOR_EACH(i, 0, green->header.ok_count)
release_sample(green->allocator, green->samples + i);
MEM_RM(green->allocator, green->samples);
}
if(green->table) { /* On error, table could be not yet allocated */
- FOR_EACH(i, 0, 1 + green->counts.desc_count)
+ FOR_EACH(i, 0, 1 + green->header.description_count)
if(&green->table[i]) release_table_elt(&green->table[i]);
MEM_RM(green->allocator, green->table);
}
@@ -338,149 +298,21 @@ green_read_settings
(struct green* green,
const char* in_name);
-/*
- * Different types of descriptions read from the binary file
- */
-enum description_type {
- DESC_MAT_SOLID,
- DESC_MAT_FLUID,
- DESC_BOUND_H_FOR_FLUID,
- DESC_BOUND_H_FOR_SOLID,
- DESC_BOUND_T_FOR_SOLID,
- DESC_BOUND_F_FOR_SOLID,
- DESC_SOLID_FLUID_CONNECT,
- DESC_SOLID_SOLID_CONNECT,
- DESCRIPTION_TYPE_COUNT__,
- DESC_OUTSIDE
-};
-
#define DESC_IS_MEDIUM(D) \
- ((D) == DESC_MAT_SOLID || (D) == DESC_MAT_FLUID)
+ ((D) == GREEN_MAT_SOLID || (D) == GREEN_MAT_FLUID)
#define DESC_IS_H(D) \
- ((D) == DESC_BOUND_H_FOR_SOLID || (D) == DESC_BOUND_H_FOR_FLUID)
+ ((D) == GREEN_BOUND_H_FOR_SOLID || (D) == GREEN_BOUND_H_FOR_FLUID)
#define DESC_IS_T(D) \
- ((D) == DESC_BOUND_T_FOR_SOLID)
+ ((D) == GREEN_BOUND_T_FOR_SOLID)
#define DESC_IS_F(D) \
- ((D) == DESC_BOUND_F_FOR_SOLID)
+ ((D) == GREEN_BOUND_F_FOR_SOLID)
#define DESC_IS_SF(D) \
- ((D) == DESC_SOLID_FLUID_CONNECT)
+ ((D) == GREEN_SOLID_FLUID_CONNECT)
#define DESC_IS_SS(D) \
- ((D) == DESC_SOLID_SOLID_CONNECT)
+ ((D) == GREEN_SOLID_SOLID_CONNECT)
#define DESC_IS_CONNECTION(D) \
(DESC_IS_SS(D) || DESC_IS_SF(D))
#define DESC_HOLDS_T(D) \
(DESC_IS_MEDIUM(D) || DESC_IS_H(D) || DESC_IS_T(D))
-struct mat_fluid {
- struct str name;
- double rho; /* Volumic mass */
- double cp; /* Calorific capacity */
- double tinit;
- double imposed_temperature;
- double t0; /* End time of tinit */
- int is_outside; /* the fluid is used for a boundary */
- int is_green; /* green computation nothing to do with fluid itself) */
- unsigned desc_id; /* id of the boundary; meaningful if is_outside */
- unsigned fluid_id;
-};
-
-struct mat_solid {
- struct str name;
- double lambda; /* Conductivity */
- double rho; /* Volumic mass */
- double cp; /* Calorific capacity */
- double delta; /* Numerical parameter */
- double tinit; /* Initial temperature */
- double imposed_temperature; /* allow to impose a T; -1 if unset */
- double vpower;
- double t0; /* End time of tinit */
- int is_outside; /* the fluid is used for a boundary */
- int is_green; /* green computation nothing to do with fluid itself) */
- unsigned desc_id; /* id of the boundary; meaningful if is_outside */
- unsigned solid_id;
-};
-
-struct h_boundary {
- struct str name;
- double emissivity;
- double specular_fraction;
- double hc;
- double imposed_temperature;
- unsigned mat_id;
-};
-
-struct t_boundary {
- struct str name;
- double imposed_temperature;
- unsigned mat_id;
-};
-
-struct f_boundary {
- struct str name;
- double imposed_flux;
- unsigned mat_id;
-};
-
-struct solid_fluid_connect {
- struct str name;
- double emissivity;
- double specular_fraction;
- double hc;
- unsigned connection_id;
-};
-
-struct solid_solid_connect {
- struct str name;
- double tcr;
- unsigned connection_id;
-};
-
-struct description {
- enum description_type type;
- union {
- struct mat_fluid fluid;
- struct mat_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 INLINE res_T
-get_description_name
- (struct description* desc,
- struct str** name)
-{
- ASSERT(desc && name);
- switch (desc->type) {
- case DESC_MAT_SOLID:
- *name = &desc->d.solid.name;
- break;
- case DESC_MAT_FLUID:
- *name = &desc->d.fluid.name;
- break;
- case DESC_BOUND_T_FOR_SOLID:
- *name = &desc->d.t_boundary.name;
- break;
- case DESC_BOUND_H_FOR_SOLID:
- case DESC_BOUND_H_FOR_FLUID:
- *name = &desc->d.h_boundary.name;
- break;
- case DESC_BOUND_F_FOR_SOLID:
- *name = &desc->d.f_boundary.name;
- break;
- case DESC_SOLID_FLUID_CONNECT:
- *name = &desc->d.sf_connect.name;
- break;
- case DESC_SOLID_SOLID_CONNECT:
- *name = &desc->d.ss_connect.name;
- break;
- default:
- return RES_BAD_ARG;
- }
- return RES_OK;
-}
-
#endif /* GREEN_TYPES_H */