commit 3a203068e4d644fa863cb5015ce96186055ce734
parent 5cce8be4d28d17445e9835d5e8a62bde7d7d002c
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 27 Jan 2025 15:27:53 +0100
Create stardis description for mode 0 buildings
Diffstat:
3 files changed, 176 insertions(+), 4 deletions(-)
diff --git a/src/cg_city.c b/src/cg_city.c
@@ -449,7 +449,14 @@ create_city
fprintf(city->set_vars,
"#!/bin/sh\n"
"\n"
+ GENERIC_WALL_VARS
+ GENERIC_FLOOR_VARS
+ GENERIC_ROOF_VARS
GENERIC_GROUND_VARS
+ GENERIC_CAVITY_VARS
+ GENERIC_SFC_VARS
+ GENERIC_B_WALL_VARS
+ GENERIC_B_ROOF_VARS
GENERIC_B_GROUND_VARS
);
diff --git a/src/cg_construction_mode_0.c b/src/cg_construction_mode_0.c
@@ -26,6 +26,7 @@
#include "cg_construction_mode_0.h"
#include "cg_construction_mode.h"
#include "cg_vertex_denoiser.h"
+#include "cg_stardis_model.h"
#include <rsys/rsys.h>
#include <rsys/str.h>
@@ -537,7 +538,7 @@ build_cad_cmode_0
logger_print(logger, LOG_OUTPUT,
"Building '%s' construction mode 0, dataset '%s', %g m tall.\n",
- name, str_cget(&building->dataset_name), building->total_height);
+ name, str_cget(&building->dataset_name), building->total_height);
if(height <= 0 || data->wall_thickness <= 0 || data->floor_thickness <= 0) {
res = RES_BAD_ARG;
@@ -746,16 +747,39 @@ export_stl_cmode_0
int initialized = 0;
struct mem_allocator* allocator = NULL;
struct city* city;
+ struct building* building;
struct vertex_denoiser* denoiser;
+ FILE* model = NULL;
+ FILE* vars = NULL;
+ fpos_t model_pos, vars_pos;
+ long model_count = 0;
+ const char* n;
+ static int fst = 1;
if(!cad) {
res = RES_BAD_ARG;
goto error;
}
- city = data_cad->building->city;
+ building = data_cad->building;
+ city = building->city;
allocator = city->allocator;
denoiser = city->denoiser;
+ model = city->stardis_model;
+ vars = city->set_vars;
+
+ if(!fst) fprintf(model, "\n");
+ fst = 0;
+ fprintf(model,
+ "# Building '%s' construction mode 0, dataset '%s', %g m tall\n",
+ str_cget(&building->name), str_cget(&building->dataset_name),
+ building->total_height);
+ fgetpos(model, &model_pos);
+ fprintf(vars,
+ "\n# Building '%s' construction mode 0, dataset '%s', %g m tall\n",
+ str_cget(&building->name), str_cget(&building->dataset_name),
+ building->total_height);
+ fgetpos(vars, &vars_pos);
/* wall export */
if(darray_geometries_size_get(&data_cad->adj_walls) == 0) {
@@ -808,34 +832,53 @@ export_stl_cmode_0
binary));
}
+ STARDIS_SOLID(wall);
+
/* floor export */
ERR(stl_export_denoised_geometry(denoiser, data_cad->floor,
Scad_force_normals_outward, binary));
+ STARDIS_SOLID(floor);
+
/* roof export */
ERR(stl_export_denoised_geometry(denoiser, data_cad->roof,
Scad_force_normals_outward, binary));
+ STARDIS_SOLID(roof);
+
/* cavity export */
ERR(stl_export_denoised_geometry(denoiser, data_cad->cavity,
Scad_force_normals_outward, binary));
+ STARDIS_FLUID(cavity);
+
/* connection export */
for(i = 0; i < data_cad->n_connection; i++) {
- ERR(stl_export_denoised_geometry(denoiser, data_cad->connection[i],
+ struct scad_geometry* c = data_cad->connection[i];
+ ERR(stl_export_denoised_geometry(denoiser, c,
Scad_keep_normals_unchanged, binary));
+
+ ERR(scad_geometry_get_name(c, &n));
+ STARDIS_SFC_2(SFC, n);
}
/* boundary export */
ERR(stl_export_denoised_geometry(denoiser, data_cad->boundary_wall,
Scad_keep_normals_unchanged, binary));
+ STARDIS_H_BOUND(boundary_wall);
+
ERR(stl_export_denoised_geometry(denoiser, data_cad->boundary_roof,
Scad_keep_normals_unchanged, binary));
+ STARDIS_H_BOUND(boundary_roof);
+
/* ground/building connection export*/
ERR(stl_export_denoised_geometry(denoiser, data_cad->ground_connection,
Scad_keep_normals_unchanged, binary));
+ /* No need to describe solid-solid connections until there is a contact
+ * resistance */
+
exit:
if(initialized) {
darray_double_release(&trg);
@@ -848,6 +891,19 @@ error:
"Internal error '"__FILE__"': creating STL for building '%s'.\n",
str_cget(&data_cad->building->name));
}
+ /* Reset stardis model file */
+ if(model) {
+ long l;
+ fsetpos(model, &model_pos);
+ for(l = 0; l < model_count; l += 40)
+ fprintf(model, " \n");
+ fprintf(model, "# Building '%s' construction cancelled\n",
+ str_cget(&building->name));
+ }
+ if(vars) {
+ fprintf(vars, "# Building '%s' construction cancelled\n",
+ str_cget(&building->name));
+ }
goto exit;
}
diff --git a/src/cg_stardis_model.h b/src/cg_stardis_model.h
@@ -22,6 +22,27 @@
#include <rsys/rsys.h>
+/* Utility macros for stardis model output */
+#define STARDIS_FLUID_2(Group, Name) { \
+ model_count += fprintf(model, \
+ "FLUID %s " \
+ "$%s_RHO $%s_CP $%s_TINIT $%s_T_IMPOSED " \
+ "FRONT %s.stl\n", \
+ Name, Name, Name, Name, Name, Name); \
+ fprintf(vars, \
+ "export %s_RHO=$" #Group "_RHO\n" \
+ "export %s_CP=$" #Group "_CP\n" \
+ "export %s_TINIT=$" #Group "_TINIT\n" \
+ "export %s_T_IMPOSED=$" #Group "_T_IMPOSED\n", \
+ Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_FLUID(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_FLUID_2(Field, n___); \
+} (void)0
+
#define STARDIS_SOLID_2_model(Group, Name) { \
model_count += fprintf(model, \
"SOLID %s " \
@@ -130,7 +151,35 @@
#define STARDIS_H_BOUND(Field) { \
const char* n___; \
ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
- STARDIS_T_BOUND_2(Field, n___); \
+ STARDIS_H_BOUND_2(Field, n___); \
+} (void)0
+
+#define STARDIS_SFC_2_model(Group, Name) { \
+ model_count += fprintf(model, \
+ "SOLID_FLUID_CONNECTION %s " \
+ "$%s_TREF $%s_EMISSIVITY $%s_SPEC_FRACTION $%s_H " \
+ "%s.stl\n", \
+ Name, Name, Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_SFC_2_vars(Group, Name) { \
+ fprintf(vars, \
+ "export %s_TREF=$" #Group "_TREF\n" \
+ "export %s_EMISSIVITY=$" #Group "_EMISSIVITY\n" \
+ "export %s_SPEC_FRACTION=$" #Group "_SPEC_FRACTION\n" \
+ "export %s_H=$" #Group "_H\n", \
+ Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_SFC_2(Group, Name) { \
+ STARDIS_SFC_2_model(Group, Name); \
+ STARDIS_SFC_2_vars(Group, Name); \
+} (void)0
+
+#define STARDIS_SFC(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_SFC_2(Field, n___); \
} (void)0
#define GENERIC_GROUND_VARS \
@@ -153,4 +202,64 @@
"export ground_B_bottom_T=286\n" \
"export ground_B_lateral_F=0\n"
+#define GENERIC_WALL_VARS \
+ "# Generic WALL properties.\n" \
+ "export wall_LAMBDA=0.4\n" \
+ "export wall_RHO=650\n" \
+ "export wall_CP=1000\n" \
+ "export wall_DELTA=AUTO\n" \
+ "export wall_TINIT=273\n" \
+ "export wall_T_IMPOSED=UNKNOWN\n" \
+ "export wall_POWER=0\n"
+
+#define GENERIC_FLOOR_VARS \
+ "# Generic FLOOR properties.\n" \
+ "export floor_LAMBDA=1.5\n" \
+ "export floor_RHO=2300\n" \
+ "export floor_CP=2500\n" \
+ "export floor_DELTA=AUTO\n" \
+ "export floor_TINIT=273\n" \
+ "export floor_T_IMPOSED=UNKNOWN\n" \
+ "export floor_POWER=0\n"
+
+#define GENERIC_ROOF_VARS \
+ "# Generic ROOF properties.\n" \
+ "export roof_LAMBDA=1.5\n" \
+ "export roof_RHO=2300\n" \
+ "export roof_CP=2500\n" \
+ "export roof_DELTA=AUTO\n" \
+ "export roof_TINIT=273\n" \
+ "export roof_T_IMPOSED=UNKNOWN\n" \
+ "export roof_POWER=0\n"
+
+#define GENERIC_CAVITY_VARS \
+ "# Generic FLUID CAVITY properties.\n" \
+ "export cavity_RHO=1.25\n" \
+ "export cavity_CP=1000\n" \
+ "export cavity_TINIT=273\n" \
+ "export cavity_T_IMPOSED=UNKNOWN\n"
+
+#define GENERIC_SFC_VARS \
+ "# Generic SOLID-FLUID CONNECTION properties.\n" \
+ "export SFC_TREF=293\n" \
+ "export SFC_EMISSIVITY=0.9\n" \
+ "export SFC_SPEC_FRACTION=0\n" \
+ "export SFC_H=5\n"
+
+#define GENERIC_B_WALL_VARS \
+ "# Generic WALL BOUNDARY properties.\n" \
+ "export boundary_wall_TREF=273\n" \
+ "export boundary_wall_EMISSIVITY=0.9\n" \
+ "export boundary_wall_SPEC_FRACTION=0\n" \
+ "export boundary_wall_H=10\n" \
+ "export boundary_wall_TEXT=273\n" \
+
+#define GENERIC_B_ROOF_VARS \
+ "# Generic ROOF BOUNDARY properties.\n" \
+ "export boundary_roof_TREF=273\n" \
+ "export boundary_roof_EMISSIVITY=0.9\n" \
+ "export boundary_roof_SPEC_FRACTION=0\n" \
+ "export boundary_roof_H=10\n" \
+ "export boundary_roof_TEXT=273\n"
+
#endif /* STARDIS_MODEL_H */