commit 5cce8be4d28d17445e9835d5e8a62bde7d7d002c
parent 90decfc5cd6fa3564dd8432b1baf7b18d406ae29
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 27 Jan 2025 14:45:34 +0100
Create stardis description for the ground
Diffstat:
4 files changed, 189 insertions(+), 0 deletions(-)
diff --git a/src/cg_city.c b/src/cg_city.c
@@ -30,6 +30,7 @@
#include "cg_args.h"
#include "cg_city_parsing_schemas.h"
#include "cg_vertex_denoiser.h"
+#include "cg_stardis_model.h"
#include <rsys/rsys.h>
#include <rsys/logger.h>
@@ -445,6 +446,12 @@ create_city
res = RES_IO_ERR;
goto error;
}
+ fprintf(city->set_vars,
+ "#!/bin/sh\n"
+ "\n"
+ GENERIC_GROUND_VARS
+ GENERIC_B_GROUND_VARS
+ );
ground_init(allocator, &city->ground);
ERR(vertex_denoiser_create(allocator, pow(10, -(CLIPPER_PRECISON+2)),
diff --git a/src/cg_ground.c b/src/cg_ground.c
@@ -22,6 +22,7 @@
#include "cg_building.h"
#include "cg_city.h"
#include "cg_vertex_denoiser.h"
+#include "cg_stardis_model.h"
#include <rsys/rsys.h>
#include <rsys/dynamic_array_double.h>
@@ -90,6 +91,7 @@ ground_build_cad
if (N[0] == 0 && N[1] == 0 && N[2] == -1) {
ERR(scad_geometry_rename(surface, "ground_B_bottom"));
+ ground->bottom = surface;
GPUSH(surface);
}
else if (N[0] == 0 && N[1] == 0 && N[2] == 1) {
@@ -104,6 +106,7 @@ ground_build_cad
GPUSH(tmp);
} else {
ERR(scad_geometry_rename(surface, "ground_B_top"));
+ ground->top = surface;
GPUSH(surface);
}
}
@@ -152,18 +155,29 @@ ground_export_stl
const char* name;
struct str filename;
int binary;
+ FILE* model = NULL;
+ FILE* vars = NULL;
+ const char* n;
size_t i = 0;
+ long model_count = 0;
ASSERT(city);
+ (void)model_count; /* To allow STARDIS_SOLID_ use */
ground = &city->ground;
binary = city->binary_export;
denoiser = city->denoiser;
allocator = city->allocator;
darray_double_init(allocator, &trg);
str_init(allocator, &filename);
+ model = city->stardis_model;
+ vars = city->set_vars;
+
+ fprintf(model, "\n# GROUND\n");
+ fprintf(vars, "\n# GROUND\n");
for(i = 0; i < darray_geometries_size_get(&ground->boundaries); i++) {
struct scad_geometry* b = darray_geometries_data_get(&ground->boundaries)[i];
+ ERR(scad_geometry_get_name(b, &n));
/* Boundary files */
darray_double_clear(&trg);
ERR(scad_stl_get_data(b, &trg));
@@ -177,6 +191,15 @@ ground_export_stl
ERR(denoise_array(denoiser, &trg));
ERR(scad_stl_data_write(&trg, str_cget(&filename),
Scad_keep_normals_unchanged, binary));
+ if(b == ground->bottom) {
+ STARDIS_T_BOUND_2_model(ground_B_bottom, n);
+ } else {
+ if(b == ground->top) {
+ STARDIS_H_BOUND_2_model(ground_B_top, n);
+ }else {
+ STARDIS_F_BOUND_2(ground_B_lateral, n);
+ }
+ }
/* Also collect boundaries triangles into ground body */
ERR(darray_double_merge(&ground->ground_building_connections, &trg));
}
@@ -184,6 +207,8 @@ ground_export_stl
ERR(scad_stl_data_write(&ground->ground_building_connections, "ground_body.stl",
Scad_force_normals_outward, binary));
+ STARDIS_SOLID_2(ground_body, "ground_body");
+
exit:
darray_double_release(&trg);
str_release(&filename);
diff --git a/src/cg_ground.h b/src/cg_ground.h
@@ -38,6 +38,7 @@ struct ground {
struct darray_double ground_building_connections; /* Connection of unremoved buildings */
struct darray_double ground_patches; /* patches for removed buildings */
struct scad_geometry* top; /* Uncounted ptr to top boundary */
+ struct scad_geometry* bottom; /* Uncounted ptr to bottom boundary */
};
res_T
diff --git a/src/cg_stardis_model.h b/src/cg_stardis_model.h
@@ -0,0 +1,156 @@
+/* Copyright (C) 2022 Université de Pau et des Pays de l'Adour UPPA
+ * Copyright (C) 2022 CNRS
+ * Copyright (C) 2022 Sorbonne Université
+ * Copyright (C) 2022 Université Paul Sabatier
+ * Copyright (C) 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 STARDIS_MODEL_H
+#define STARDIS_MODEL_H
+
+#include <rsys/rsys.h>
+
+#define STARDIS_SOLID_2_model(Group, Name) { \
+ model_count += fprintf(model, \
+ "SOLID %s " \
+ "$%s_LAMBDA $%s_RHO $%s_CP $%s_DELTA " \
+ "$%s_TINIT $%s_T_IMPOSED $%s_POWER " \
+ "FRONT %s.stl\n", \
+ Name, Name, Name, Name, Name, Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_SOLID_2_vars(Group, Name) { \
+ fprintf(vars, \
+ "export %s_LAMBDA=$" #Group "_LAMBDA\n" \
+ "export %s_RHO=$" #Group "_RHO\n" \
+ "export %s_CP=$" #Group "_CP\n" \
+ "export %s_DELTA=$" #Group "_DELTA\n" \
+ "export %s_TINIT=$" #Group "_TINIT\n" \
+ "export %s_T_IMPOSED=$" #Group "_T_IMPOSED\n" \
+ "export %s_POWER=$" #Group "_POWER\n", \
+ Name, Name, Name, Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_SOLID_2(Group, Name) { \
+ STARDIS_SOLID_2_model(Group, Name); \
+ STARDIS_SOLID_2_vars(Group, Name); \
+} (void)0
+
+#define STARDIS_SOLID(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_SOLID_2(Field, n___); \
+} (void)0
+
+#define STARDIS_F_BOUND_2_model(Group, Name) { \
+ model_count += fprintf(model, \
+ "F_BOUNDARY_FOR_SOLID %s " \
+ "$%s_F " \
+ "%s.stl\n", \
+ Name, Name, Name); \
+} (void)0
+
+#define STARDIS_F_BOUND_2_vars(Group, Name) { \
+ fprintf(vars, \
+ "export %s_F=$" #Group "_F\n", \
+ Name); \
+} (void)0
+
+#define STARDIS_F_BOUND_2(Group, Name) { \
+ STARDIS_F_BOUND_2_model(Group, Name); \
+ STARDIS_F_BOUND_2_vars(Group, Name); \
+} (void)0
+
+#define STARDIS_F_BOUND(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_F_BOUND_2(Field, n___); \
+} (void)0
+
+#define STARDIS_T_BOUND_2_model(Group, Name) { \
+ model_count += fprintf(model, \
+ "T_BOUNDARY_FOR_SOLID %s " \
+ "$%s_T " \
+ "%s.stl\n", \
+ Name, Name, Name); \
+} (void)0
+
+#define STARDIS_T_BOUND_2_vars(Group, Name) { \
+ fprintf(vars, \
+ "export %s_T=$" #Group "_T\n", \
+ Name); \
+} (void)0
+
+#define STARDIS_T_BOUND_2(Group, Name) { \
+ STARDIS_T_BOUND_2_model(Group, Name); \
+ STARDIS_T_BOUND_2_vars(Group, Name); \
+} (void)0
+
+#define STARDIS_T_BOUND(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_T_BOUND_2(Field, n___); \
+} (void)0
+
+#define STARDIS_H_BOUND_2_model(Group, Name) { \
+ model_count += fprintf(model, \
+ "H_BOUNDARY_FOR_SOLID %s " \
+ "$%s_TREF $%s_EMISSIVITY $%s_SPEC_FRACTION $%s_H $%s_TEXT " \
+ "%s.stl\n", \
+ Name, Name, Name, Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_H_BOUND_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" \
+ "export %s_TEXT=$" #Group "_TEXT\n", \
+ Name, Name, Name, Name, Name); \
+} (void)0
+
+#define STARDIS_H_BOUND_2(Group, Name) { \
+ STARDIS_H_BOUND_2_model(Group, Name); \
+ STARDIS_H_BOUND_2_vars(Group, Name); \
+} (void)0
+
+#define STARDIS_H_BOUND(Field) { \
+ const char* n___; \
+ ERR(scad_geometry_get_name(data_cad->Field, &n___)); \
+ STARDIS_T_BOUND_2(Field, n___); \
+} (void)0
+
+#define GENERIC_GROUND_VARS \
+ "# GROUND properties.\n" \
+ "export ground_body_LAMBDA=2\n" \
+ "export ground_body_RHO=2000\n" \
+ "export ground_body_CP=1000\n" \
+ "export ground_body_DELTA=AUTO\n" \
+ "export ground_body_TINIT=273\n" \
+ "export ground_body_T_IMPOSED=UNKNOWN\n" \
+ "export ground_body_POWER=0\n"
+
+#define GENERIC_B_GROUND_VARS \
+ "# GROUND BOUNDARIES properties.\n" \
+ "export ground_B_top_TREF=273\n" \
+ "export ground_B_top_EMISSIVITY=0.9\n" \
+ "export ground_B_top_SPEC_FRACTION=0\n" \
+ "export ground_B_top_H=10\n" \
+ "export ground_B_top_TEXT=273\n" \
+ "export ground_B_bottom_T=286\n" \
+ "export ground_B_lateral_F=0\n"
+
+#endif /* STARDIS_MODEL_H */