commit 2b9651e9db8a4188fd4d2906ba36e051f51913e6
parent afe99d6c797c24b51ff6e3a1d89e668f4dbfe881
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 9 Mar 2022 17:10:40 +0100
Add a new header file (stardis-green-types.h).
The new file is used to share relevant types with apps wanting to read binary Green files.
Diffstat:
7 files changed, 315 insertions(+), 248 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -17,6 +17,8 @@ cmake_minimum_required(VERSION 3.0)
project(stardis C)
set(SDIS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
+set(SDIS_SGT_DIR ${PROJECT_SOURCE_DIR}/../stardis-green-types)
+
option(ENABLE_MPI
"Enable the support of distributed parallelism \
@@ -70,6 +72,14 @@ configure_file(${SDIS_SOURCE_DIR}/stardis-default.h.in
configure_file(${SDIS_SOURCE_DIR}/stardis-version.h.in
${CMAKE_CURRENT_BINARY_DIR}/stardis-version.h @ONLY)
+set(STARDIS_GREEN_TYPES_VERSION "4")
+
+configure_file(${SDIS_SOURCE_DIR}/stardis-green-types.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/stardis-green-types/stardis-green-types.h @ONLY)
+
+configure_file(${SDIS_SGT_DIR}/stardis-green-types-config-version.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/stardis-green-types/stardis-green-types-config-version.cmake @ONLY)
+
###############################################################################
# Check dependencies
###############################################################################
@@ -99,7 +109,8 @@ include_directories(
${Stardis_INCLUDE_DIR}
${StarSTL_INCLUDE_DIR}
${StarSP_INCLUDE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR})
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/stardis-green-types)
if(MSVC)
include_directories(${MuslGetopt_INCLUDE_DIR})
endif()
@@ -124,6 +135,8 @@ if(NOT STARDIS_DOC STREQUAL "NONE")
add_subdirectory(doc)
endif()
+add_subdirectory(stardis-green-types)
+
###############################################################################
# Configure and define targets
###############################################################################
@@ -144,6 +157,7 @@ set(SDIS_FILES_INC
stardis-compute.h
stardis-default.h.in
stardis-fluid.h
+ stardis-green-types.h.in
stardis-intface.h
stardis-output.h
stardis-parsing.h
@@ -186,5 +200,7 @@ install(TARGETS stardis
RUNTIME DESTINATION bin)
install(FILES ${SDIS_FILES_DOC} DESTINATION share/doc/stardis)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/stardis-version.h
+ DESTINATION include/stardis)
rcmake_copy_runtime_libraries(stardis)
diff --git a/cmake/stardis-green-types/CMakeLists.txt b/cmake/stardis-green-types/CMakeLists.txt
@@ -0,0 +1,53 @@
+# Copyright (C) 2018-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/>.
+
+cmake_minimum_required(VERSION 3.0)
+
+set(STARDIS_SGT_DIR ${PROJECT_SOURCE_DIR}/../stardis-green-types)
+
+################################################################################
+# Copy stardis-green-types CMake files
+################################################################################
+set(SGT_NAMES
+ stardis-green-types-config)
+
+set(SGT_FILES)
+foreach(_name IN LISTS SGT_NAMES)
+ set(_src ${STARDIS_SGT_DIR}/${_name}.cmake)
+ set(_dst ${CMAKE_CURRENT_BINARY_DIR}/${_name}.cmake)
+ add_custom_command(
+ OUTPUT ${_dst}
+ COMMAND ${CMAKE_COMMAND} -E copy ${_src} ${_dst}
+ DEPENDS ${_src}
+ COMMENT "Copy the CMake file ${_src}"
+ VERBATIM)
+ list(APPEND SGT_FILES ${_dst})
+endforeach()
+add_custom_target(sgt-cmake ALL DEPENDS ${SGT_FILES})
+
+################################################################################
+# Install stardis-green-types CMake Files
+################################################################################
+list(APPEND SGT_FILES ${CMAKE_CURRENT_BINARY_DIR}/stardis-green-types-config-version.cmake)
+
+install(FILES ${SGT_FILES}
+ DESTINATION lib/cmake/stardis-green-types)
+
+################################################################################
+# Install stardis-green-types header Files
+################################################################################
+install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/stardis-green-types.h
+ DESTINATION include/stardis/)
diff --git a/doc/stardis-input.5.txt b/doc/stardis-input.5.txt
@@ -208,11 +208,12 @@ one or ore ASCII characters, including numbers and special characters like
spacing* either escaped or not. Names are case-sensitive and two different
description lines, either in the same description file or from different
description files, cannot use the same name. Additionaly, medium and boundary
-names cannot be parsable as a number, nor be one of the few keywords defined
+names cannot be parsable as a number, nor be one of the keywords defined
by the present grammar (AUTO, BACK, BOTH, FLUID, FRONT, F_BOUNDARY_FOR_SOLID,
H_BOUNDARY_FOR_FLUID, H_BOUNDARY_FOR_SOLID, SCALE, SOLID,
SOLID_FLUID_CONNECTION, T_BOUNDARY_FOR_FLUID, T_BOUNDARY_FOR_SOLID, UNKNOWN) or
-their lowercase counterparts.
+their lowercase counterparts. Finally, description names cannot be longer than
+63 characters.
EXAMPLES
--------
diff --git a/doc/stardis-output.5.txt b/doc/stardis-output.5.txt
@@ -228,32 +228,34 @@ follows:
=== BINARY GREEN
-Thereafter is the format of binary Green outputs. This output is produced by
-fwrite calls and does not take care of endianness. Comments include the C type
-of the written data.
+Binary Green outputs are formated according to the various C types from the
+*stardis-green.h* header file. The output begins with a header (of type struct
+green_file_header) that includes counts, followed by descriptions (of type
+struct green_description) and samples. Thereafter is the format of binary
+Green outputs. This output is produced by fwrite calls and does not take care
+of endianness. Comments include the C type of the written data.
[verse]
_______
-<binary-green> ::= "BINGREEN" # char[8]
+<binary-green> ::= "GREEN_BIN_FILE:" # char[16]
+ <file_format_version> # unsigned
#descriptions # unsigned
#solids # unsigned
#fluids # unsigned
- #t-boundaries # unsigned
#h-boundaries # unsigned
- #flux-boundaries # unsigned
+ #t-boundaries # unsigned
+ #f-boundaries # unsigned
#solid-fluid-connections # unsigned
- names-pool-size # size of concatenated description names
- # unsigned
+ #solid-solid-connections # unsigned
#ok-samples # size_t
#failed-samples # size_t
- <descriptions>
- <concatenated-names> # char[names-pool-size]
Trad # double
Trad-reference # double
time-range # double[2]
+ <descriptions>
<samples>
-<descriptions> ::= description # struct description
+<descriptions> ::= description # struct green_description
<descriptions> # #descriptions descriptions
<samples> ::= <sample>
@@ -261,113 +263,11 @@ _______
---------------------
-<sample> ::= <sample-header> # struct path_header
- <ids> # unsigned[header.pcount + header.fcount]
- <weights> # double[header.pcount + header.fcount]
+<sample> ::= <sample-header> # struct green_sample_header
+ <ids> # unsigned[header.pw_count then header.fx_count]
+ <weights> # double[header.pw_count then header.fx_count]
_______
-[literal]
- /* The content of stuct str name members in descriptions is meaningless.
- * The name of the ith description is the ith nul-terminated string in
- * <concatenated-names>.
- * As a convenience, one could use char* baz to store a pointer to the
- * description's name into <concatenated-names>. */
- struct str {
- void* foo;
- size_t bar;
- char* baz;
- char qux[16];
- };
-
- struct mat_fluid {
- struct str name;
- double rho;
- double cp;
- double tinit;
- double imposed_temperature;
- double t0;
- int is_outside;
- int is_green;
- unsigned desc_id;
- unsigned fluid_id;
- };
-
- struct mat_solid {
- struct str name;
- double lambda;
- double rho;
- double cp;
- double delta;
- double tinit;
- double imposed_temperature;
- double vpower;
- double t0;
- int is_outside;
- int is_green;
- unsigned desc_id;
- unsigned solid_id;
- };
-
- struct t_boundary {
- struct str name;
- double imposed_temperature;
- unsigned mat_id;
- };
-
- struct h_boundary {
- struct str name;
- double ref_temperature;
- double emissivity;
- double specular_fraction;
- double hc;
- double imposed_temperature;
- unsigned mat_id;
- };
-
- struct solid_fluid_connect {
- struct str name;
- double ref_temperature;
- double emissivity;
- double specular_fraction;
- double hc;
- unsigned connection_id;
- };
-
- 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,
- DESCRIPTION_TYPE_COUNT__,
- DESC_OUTSIDE
- };
-
- struct f_boundary {
- struct str name;
- double imposed_flux;
- unsigned mat_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;
- } d;
- };
-
- struct path_header {
- unsigned id;
- unsigned pcount, fcount;
- char at_initial;
- };
=== ASCII GREEN
diff --git a/src/stardis-green-types.h.in b/src/stardis-green-types.h.in
@@ -0,0 +1,129 @@
+/* Copyright (C) 2018-2022 |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 SDIS_GREEN_H
+#define SDIS_GREEN_H
+
+/* The number of the file format as presented thereafter */
+#define GREEN_FILE_FORMAT_VERSION @STARDIS_GREEN_TYPES_VERSION@
+
+/* The max length for a description name */
+#define DESC_NAME_MAX_LEN 63
+
+/* The string at the beginning of a binary Green file that identifies it */
+#define BIN_FILE_IDENT_STRING "GREEN_BIN_FILE:"
+
+/* The header of a binary Green file */
+struct green_file_header {
+ char green_string[sizeof(BIN_FILE_IDENT_STRING)];
+ unsigned file_format_version;
+ unsigned description_count;
+ unsigned solid_count;
+ unsigned fluid_count;
+ unsigned hbound_count;
+ unsigned tbound_count;
+ unsigned fbound_count;
+ unsigned sfconnect_count;
+ unsigned ssconnect_count;
+ size_t ok_count;
+ size_t failed_count;
+ double ambient_radiative_temperature;
+ double ambient_radiative_temperature_reference;
+ double time_range[2];
+};
+
+/* Different types of descriptions */
+enum green_description_type {
+ GREEN_MAT_SOLID,
+ GREEN_MAT_FLUID,
+ GREEN_BOUND_H,
+ GREEN_BOUND_T,
+ GREEN_BOUND_F,
+ GREEN_SOLID_FLUID_CONNECT,
+ GREEN_SOLID_SOLID_CONNECT
+};
+
+struct green_solid {
+ char name[DESC_NAME_MAX_LEN+1];
+ double conductivity;
+ double volumic_mass;
+ double calorific_capacity;
+ double volumic_power;
+ double initial_temperature;
+ double imposed_temperature;
+};
+
+struct green_fluid {
+ char name[DESC_NAME_MAX_LEN+1];
+ double volumic_mass;
+ double calorific_capacity;
+ double initial_temperature;
+ double imposed_temperature;
+};
+
+struct green_h_boundary {
+ char name[DESC_NAME_MAX_LEN+1];
+ double reference_temperature;
+ double emissivity;
+ double specular_fraction;
+ double convection_coefficient;
+ double imposed_temperature;
+};
+
+struct green_t_boundary {
+ char name[DESC_NAME_MAX_LEN+1];
+ double imposed_temperature;
+};
+
+struct green_f_boundary {
+ char name[DESC_NAME_MAX_LEN+1];
+ double imposed_flux;
+};
+
+struct green_solid_fluid_connect {
+ char name[DESC_NAME_MAX_LEN+1];
+ double reference_temperature;
+ double emissivity;
+ double specular_fraction;
+ double convection_coefficient;
+};
+
+struct green_solid_solid_connect {
+ char name[DESC_NAME_MAX_LEN+1];
+ double thermal_contact_resistance;
+};
+
+struct green_description {
+ enum green_description_type type;
+ union {
+ struct green_fluid fluid;
+ struct green_solid solid;
+ struct green_t_boundary t_boundary;
+ struct green_f_boundary f_boundary;
+ struct green_h_boundary h_boundary;
+ struct green_solid_fluid_connect sf_connect;
+ struct green_solid_solid_connect ss_connect;
+ } d;
+};
+
+/* The header of a Green sample */
+struct green_sample_header {
+ unsigned pw_count;
+ unsigned fx_count;
+ unsigned sample_end_description_id;
+ int at_initial;
+};
+
+#endif
diff --git a/src/stardis-output.c b/src/stardis-output.c
@@ -20,6 +20,7 @@
#include "stardis-solid.h"
#include "stardis-intface.h"
#include "stardis-app.h"
+#include "stardis-green-types.h"
#include <sdis.h>
@@ -68,23 +69,6 @@ enum enclosure_errors_t {
};
-/******************************************************************************
- * Local Type used to write binary Green the way sgreen expects it
- * (its mainly a matter of record size and layout)
- *****************************************************************************/
-struct green_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 res_T
copy_desc_to_green_desc
(struct green_description* gdesc,
@@ -97,36 +81,64 @@ copy_desc_to_green_desc
sz = darray_descriptions_size_get(descriptions);
CHK(idx < sz);
desc = darray_descriptions_cdata_get(descriptions) + idx;
- gdesc->type = desc->type;
switch(desc->type) {
- case DESC_MAT_FLUID:
- gdesc->d.fluid = *desc->d.fluid;
- CHK(desc->d.fluid->desc_id < sz);
- break;
case DESC_MAT_SOLID:
- gdesc->d.solid = *desc->d.solid;
- CHK(desc->d.solid->desc_id < sz);
+ gdesc->type = GREEN_MAT_SOLID;
+ strcpy(gdesc->d.solid.name, str_cget(&desc->d.solid->name));
+ gdesc->d.solid.conductivity = desc->d.solid->lambda;
+ gdesc->d.solid.volumic_mass = desc->d.solid->rho;
+ gdesc->d.solid.calorific_capacity = desc->d.solid->cp;
+ gdesc->d.solid.volumic_power = desc->d.solid->vpower;
+ gdesc->d.solid.initial_temperature = desc->d.solid->tinit;
+ gdesc->d.solid.imposed_temperature = desc->d.solid->imposed_temperature;
+ break;
+ case DESC_MAT_FLUID:
+ gdesc->type = GREEN_MAT_FLUID;
+ strcpy(gdesc->d.fluid.name, str_cget(&desc->d.fluid->name));
+ gdesc->d.fluid.volumic_mass = desc->d.fluid->rho;
+ gdesc->d.fluid.calorific_capacity = desc->d.fluid->cp;
+ gdesc->d.fluid.initial_temperature = desc->d.fluid->tinit;
+ gdesc->d.fluid.imposed_temperature = desc->d.fluid->imposed_temperature;
break;
case DESC_BOUND_H_FOR_FLUID:
case DESC_BOUND_H_FOR_SOLID:
- gdesc->d.h_boundary = *desc->d.h_boundary;
- CHK(desc->d.h_boundary->mat_id < sz);
+ gdesc->type = GREEN_BOUND_H;
+ strcpy(gdesc->d.h_boundary.name, str_cget(&desc->d.h_boundary->name));
+ gdesc->d.h_boundary.reference_temperature
+ = desc->d.h_boundary->ref_temperature;
+ gdesc->d.h_boundary.emissivity = desc->d.h_boundary->emissivity;
+ gdesc->d.h_boundary.specular_fraction
+ = desc->d.h_boundary->specular_fraction;
+ gdesc->d.h_boundary.convection_coefficient = desc->d.h_boundary->hc;
+ gdesc->d.h_boundary.imposed_temperature
+ = desc->d.h_boundary->imposed_temperature;
break;
case DESC_BOUND_T_FOR_SOLID:
- gdesc->d.t_boundary = *desc->d.t_boundary;
- CHK(desc->d.t_boundary->mat_id < sz);
+ gdesc->type = GREEN_BOUND_T;
+ strcpy(gdesc->d.t_boundary.name, str_cget(&desc->d.t_boundary->name));
+ gdesc->d.t_boundary.imposed_temperature
+ = desc->d.t_boundary->imposed_temperature;
break;
case DESC_BOUND_F_FOR_SOLID:
- gdesc->d.f_boundary = *desc->d.f_boundary;
- CHK(desc->d.f_boundary->mat_id < sz);
+ gdesc->type = GREEN_BOUND_F;
+ strcpy(gdesc->d.f_boundary.name, str_cget(&desc->d.f_boundary->name));
+ gdesc->d.f_boundary.imposed_flux
+ = desc->d.f_boundary->imposed_flux;
break;
case DESC_SOLID_FLUID_CONNECT:
- gdesc->d.sf_connect = *desc->d.sf_connect;
- CHK(desc->d.sf_connect->connection_id < sz);
+ gdesc->type = GREEN_SOLID_FLUID_CONNECT;
+ strcpy(gdesc->d.sf_connect.name, str_cget(&desc->d.sf_connect->name));
+ gdesc->d.sf_connect.reference_temperature
+ = desc->d.sf_connect->ref_temperature;
+ gdesc->d.sf_connect.emissivity = desc->d.sf_connect->emissivity;
+ gdesc->d.sf_connect.specular_fraction
+ = desc->d.sf_connect->specular_fraction;
+ gdesc->d.sf_connect.convection_coefficient = desc->d.sf_connect->hc;
break;
case DESC_SOLID_SOLID_CONNECT:
- gdesc->d.ss_connect = *desc->d.ss_connect;
- CHK(desc->d.ss_connect->connection_id < sz);
+ gdesc->type = GREEN_SOLID_SOLID_CONNECT;
+ strcpy(gdesc->d.ss_connect.name, str_cget(&desc->d.ss_connect->name));
+ gdesc->d.ss_connect.thermal_contact_resistance = desc->d.ss_connect->tcr;
break;
default: return RES_BAD_ARG;
}
@@ -531,12 +543,6 @@ abort:
goto error; \
}
-struct path_header {
- unsigned end_id;
- unsigned pcount, fcount;
- char at_initial;
-};
-
static FINLINE double
medium_get_t0
(struct sdis_medium* medium)
@@ -642,7 +648,7 @@ dump_sample
{
res_T res = RES_OK;
struct htable_weigth_iterator it, end;
- struct path_header header;
+ struct green_sample_header header;
struct w_ctx* w_ctx = ctx;
enum sdis_green_path_end_type end_type;
FILE* stream;
@@ -659,7 +665,7 @@ dump_sample
trad_id = (unsigned)sz;
if(end_type == SDIS_GREEN_PATH_END_RADIATIVE) {
header.at_initial = 0;
- header.end_id = trad_id;
+ header.sample_end_description_id = trad_id;
} else {
struct sdis_point pt = SDIS_POINT_NULL;
struct sdis_data* data = NULL;
@@ -684,7 +690,7 @@ dump_sample
d__ = sdis_data_get(data);
desc_id = d__->desc_id;
CHK(DESC_IS_T(descs[desc_id].type) || DESC_IS_H(descs[desc_id].type));
- header.end_id = desc_id;
+ header.sample_end_description_id = desc_id;
header.at_initial = 0;
break;
}
@@ -695,16 +701,16 @@ dump_sample
header.at_initial = (pt.data.mdmvert.vertex.time <= t0);
if(pt.data.mdmvert.vertex.P[0] == INF) {
/* Radiative output (Trad) */
- header.end_id = trad_id;
+ header.sample_end_description_id = trad_id;
}
else if(type == SDIS_FLUID) {
struct fluid** pfluid = sdis_data_get(data);
- header.end_id = (*pfluid)->desc_id;
+ header.sample_end_description_id = (*pfluid)->desc_id;
} else {
struct solid** psolid = sdis_data_get(data);
ASSERT(type == SDIS_SOLID);
ASSERT(!(*psolid)->is_outside); /* FIXME: what if in external solid? */
- header.end_id = (*psolid)->desc_id;
+ header.sample_end_description_id = (*psolid)->desc_id;
}
break;
default: FATAL("Unreachable code.\n"); break;
@@ -718,16 +724,16 @@ dump_sample
ERR(sdis_green_path_for_each_flux_term(path, merge_flux_terms, w_ctx));
sz = htable_weigth_size_get(&w_ctx->pw);
if(sz > UINT_MAX) goto abort;
- header.pcount = (unsigned)sz;
+ header.pw_count = (unsigned)sz;
sz = htable_weigth_size_get(&w_ctx->flux);
if(sz > UINT_MAX) goto abort;
- header.fcount = (unsigned)sz;
+ header.fx_count = (unsigned)sz;
/* Write path's header */
FW(&header, 1);
/* Allocate buffers */
- sz = header.pcount + header.fcount;
+ sz = header.pw_count + header.fx_count;
ids = MEM_CALLOC(w_ctx->alloc, sz, sizeof(*ids));
weights = MEM_CALLOC(w_ctx->alloc, sz, sizeof(*weights));
if(!ids || !weights) {
@@ -748,7 +754,7 @@ dump_sample
htable_weigth_iterator_next(&it);
i++;
}
- CHK(i == header.pcount);
+ CHK(i == header.pw_count);
htable_weigth_begin(&w_ctx->flux, &it);
htable_weigth_end(&w_ctx->flux, &end);
@@ -761,7 +767,7 @@ dump_sample
htable_weigth_iterator_next(&it);
i++;
}
- CHK(i == header.pcount + header.fcount);
+ CHK(i == header.pw_count + header.fx_count);
FW(ids, sz);
FW(weights, sz);
@@ -784,95 +790,48 @@ dump_green_bin
FILE* stream)
{
res_T res = RES_OK;
- size_t ok_count, failed_count;
- size_t sz;
+ size_t sz, i;
struct w_ctx w_ctx;
int table_initialized = 0;
- unsigned i, szd;
- const struct description* descs;
- unsigned name_pool_sz = 0;
- char* name_pool = NULL;
- char* pool_ptr;
- const char green_string[] = "GREEN_BIN_FILE:";
- const unsigned file_fmt_version = 4;
/* The following type must be identical to its stardis-green counterpart! */
- 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;
- } file_counts;
+ struct green_file_header header;
ASSERT(green && stardis && stream);
- ERR(sdis_green_function_get_paths_count(green, &ok_count));
- ERR(sdis_green_function_get_invalid_paths_count(green, &failed_count));
+ /* Init header */
+ strcpy(header.green_string, BIN_FILE_IDENT_STRING);
+ header.file_format_version = GREEN_FILE_FORMAT_VERSION;
+ header.solid_count = stardis->counts.smed_count;
+ header.fluid_count = stardis->counts.fmed_count;
+ header.tbound_count = stardis->counts.tbound_count;
+ header.hbound_count = stardis->counts.hbound_count;
+ header.fbound_count = stardis->counts.fbound_count;
+ header.sfconnect_count = stardis->counts.sfconnect_count;
+ header.ssconnect_count = stardis->counts.ssconnect_count;
+ ERR(sdis_green_function_get_paths_count(green, &header.ok_count));
+ ERR(sdis_green_function_get_invalid_paths_count(green, &header.failed_count));
sz = darray_descriptions_size_get(&stardis->descriptions);
if(sz > UINT_MAX) goto abort;
- szd = (unsigned)sz;
- ASSERT(szd ==
+ ASSERT(sz ==
(stardis->counts.smed_count + stardis->counts.fmed_count
+ stardis->counts.tbound_count + stardis->counts.hbound_count
+ stardis->counts.fbound_count + stardis->counts.sfconnect_count
+ stardis->counts.ssconnect_count));
- descs = darray_descriptions_cdata_get(&stardis->descriptions);
+ header.description_count = (unsigned)sz;
+ header.ambient_radiative_temperature = stardis->trad;
+ header.ambient_radiative_temperature_reference = stardis->trad_ref;
+ d2_set(header.time_range, stardis->time_range);
- /* Save names that do not fit inplace */
- FOR_EACH(i, 0, szd) {
- const struct description* desc = descs + i;
- const struct str* name = get_description_name(desc);
- const size_t len = str_len(name);
- if(name_pool_sz + len + 1 > UINT_MAX) goto abort;
- name_pool_sz += (unsigned)(len + 1);
- }
- pool_ptr = name_pool = MEM_ALLOC(stardis->allocator, name_pool_sz);
- if(!name_pool) {
- res = RES_MEM_ERR;
- goto error;
- }
- FOR_EACH(i, 0, szd) {
- const struct description* desc = descs + i;
- const struct str* name = get_description_name(desc);
- const size_t len = str_len(name);
- strcpy(pool_ptr, name->cstr);
- pool_ptr += len + 1;
- }
- ASSERT(pool_ptr == name_pool + name_pool_sz);
- /* Write Green string and file format version */
- FW(green_string, sizeof(green_string));
- FW(&file_fmt_version, 1);
-
- /* Write counts */
- file_counts.desc_count = szd;
- file_counts.smed_count = stardis->counts.smed_count;
- file_counts.fmed_count = stardis->counts.fmed_count;
- file_counts.tbound_count = stardis->counts.tbound_count;
- file_counts.hbound_count = stardis->counts.hbound_count;
- file_counts.fbound_count = stardis->counts.fbound_count;
- file_counts.sfconnect_count = stardis->counts.sfconnect_count;
- file_counts.ssconnect_count = stardis->counts.ssconnect_count;
- file_counts.name_pool_sz = name_pool_sz;
- file_counts.ok_count = ok_count;
- file_counts.failed_count = failed_count;
- FW(&file_counts, 1);
+ /* Write header */
+ FW(&header, 1);
/* Write descriptions*/
- for(i = 0; i < szd; i++) {
+ for(i = 0; i < sz; i++) {
struct green_description desc;
ERR(copy_desc_to_green_desc(&desc, &stardis->descriptions, i));
FW(&desc, 1);
}
- /* Write names */
- if(name_pool_sz)
- FW(name_pool, name_pool_sz);
-
- /* Write radiative temperatures */
- FW(&stardis->trad, 1);
- FW(&stardis->trad_ref, 1);
-
- /* Write time range */
- FW(&stardis->time_range, 2);
-
w_ctx.alloc = stardis->allocator;
w_ctx.desc = &stardis->descriptions;
htable_weigth_init(stardis->allocator, &w_ctx.pw);
@@ -884,7 +843,6 @@ dump_green_bin
ERR(sdis_green_function_for_each_path(green, dump_sample, &w_ctx));
end:
- MEM_RM(stardis->allocator, name_pool);
if(table_initialized) htable_weigth_release(&w_ctx.pw);
if(table_initialized) htable_weigth_release(&w_ctx.flux);
return res;
@@ -929,7 +887,7 @@ print_sample
enum sdis_medium_type type;
struct htable_weigth_iterator it, end;
unsigned desc_id;
- size_t pcount, fcount;
+ size_t pw_count, fx_count;
struct w_ctx* w_ctx = ctx;
const struct description* descs;
CHK(path && ctx);
@@ -995,17 +953,17 @@ print_sample
default: FATAL("Unreachable code.\n"); break;
}
- ERR(sdis_green_function_get_power_terms_count(path, &pcount));
+ ERR(sdis_green_function_get_power_terms_count(path, &pw_count));
htable_weigth_clear(&w_ctx->pw);
htable_weigth_clear(&w_ctx->flux);
ERR(sdis_green_path_for_each_power_term(path, merge_power_terms, w_ctx));
ERR(sdis_green_path_for_each_flux_term(path, merge_flux_terms, w_ctx));
- fcount = htable_weigth_size_get(&w_ctx->flux);
+ fx_count = htable_weigth_size_get(&w_ctx->flux);
- if(pcount > ULONG_MAX || fcount > ULONG_MAX) goto abort;
+ if(pw_count > ULONG_MAX || fx_count > ULONG_MAX) goto abort;
fprintf(w_ctx->stream, "\t%lu\t%lu",
- (unsigned long)pcount, (unsigned long)fcount);
+ (unsigned long)pw_count, (unsigned long)fx_count);
htable_weigth_begin(&w_ctx->pw, &it);
htable_weigth_end(&w_ctx->pw, &end);
diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c
@@ -17,12 +17,11 @@
#include "stardis-parsing.h"
#include "stardis-app.h"
#include "stardis-default.h"
-#include "stardis-version.h"
+#include "stardis-green-types.h"
#include <rsys/cstr.h>
#include <rsys/double2.h>
#include <rsys/double3.h>
-#include <sdis_version.h>
#include <rsys/logger.h>
#include <getopt.h>
@@ -261,6 +260,7 @@ description_set_name
"H_BOUNDARY_FOR_FLUID", "H_BOUNDARY_FOR_SOLID", "SCALE", "SOLID",
"SOLID_FLUID_CONNECTION", "SOLID_SOLID_CONNECTION", "TRAD",
"T_BOUNDARY_FOR_SOLID", "UNKNOWN" };
+ const char* reason = NULL;
int i;
ASSERT(name && tk);
@@ -270,21 +270,31 @@ description_set_name
if(RES_OK == cstr_to_double(tk, &foo)) {
/* A number is not a sensible choice for a name! */
res = RES_BAD_ARG;
+ reason = "number";
goto error;
}
FOR_EACH(i, 0, sizeof(keywords) / sizeof(*keywords)) {
if(0 == strcasecmp(tk, keywords[i])) {
/* A keyword is not a sensible choice for a name! */
res = RES_BAD_ARG;
+ reason = "reserved keyword";
goto error;
}
}
+ if(str_len(name) > DESC_NAME_MAX_LEN) {
+ /* Due to Green export limitations, names are limited in length */
+ res = RES_BAD_ARG;
+ reason = "too long";
+ goto error;
+ }
/* Name is OK */
end:
return res;
error:
- logger_print(stardis->logger, LOG_ERROR, "Invalid name: %s\n", tk);
+ ASSERT(reason != NULL);
+ logger_print(stardis->logger, LOG_ERROR, "Invalid name (%s): %s\n",
+ reason, tk);
goto end;
}