stardis-app.h (7730B)
1 /* Copyright (C) 2018-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifndef STARDIS_APP_H 17 #define STARDIS_APP_H 18 19 #include "stardis-args.h" 20 #include "stardis-description.h" 21 #include "stardis-extern-source.h" 22 #include "stardis-radiative-env.h" 23 24 #include <star/sg3d.h> 25 26 #include <rsys/rsys.h> 27 #include <rsys/double2.h> 28 #include <rsys/double3.h> 29 #include <rsys/dynamic_array_size_t.h> 30 #include <rsys/dynamic_array_uint.h> 31 #include <rsys/dynamic_array.h> 32 #include <rsys/str.h> 33 34 #include <sdis.h> 35 36 #ifdef STARDIS_ENABLE_MPI 37 #include <mpi.h> 38 #endif 39 40 /* Forward declarations */ 41 struct logger; 42 struct mem_allocator; 43 struct sdis_medium; 44 45 struct args; 46 struct solid; 47 struct fluid; 48 49 /* Utility macros */ 50 #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 51 52 #define VFATAL(Fmt, Args) \ 53 { \ 54 fprintf(stderr, Fmt COMMA_##Args LIST_##Args); \ 55 ASSERT(0); \ 56 abort(); \ 57 } (void)0 58 59 60 #define DELTA_AUTO INF /* Placeholder until actual value is substituted */ 61 #define UNKNOWN_MEDIUM_TEMPERATURE SDIS_TEMPERATURE_NONE 62 63 enum properties_conflict_t { 64 NO_PROPERTY_CONFLICT, 65 BOUND_H_FOR_FLUID_BETWEEN_2_DEFS, 66 BOUND_H_FOR_FLUID_BETWEEN_2_UNDEFS, 67 BOUND_H_FOR_FLUID_ENCLOSING_SOLID, 68 BOUND_H_FOR_SOLID_BETWEEN_2_DEFS, 69 BOUND_H_FOR_SOLID_BETWEEN_2_UNDEFS, 70 BOUND_H_FOR_SOLID_ENCLOSING_FLUID, 71 BOUND_HF_FOR_SOLID_BETWEEN_2_DEFS, 72 BOUND_HF_FOR_SOLID_BETWEEN_2_UNDEFS, 73 BOUND_HF_FOR_SOLID_ENCLOSING_FLUID, 74 BOUND_T_FOR_SOLID_BETWEEN_2_DEFS, 75 BOUND_T_FOR_SOLID_BETWEEN_2_UNDEFS, 76 BOUND_T_FOR_SOLID_ENCLOSING_FLUID, 77 BOUND_F_FOR_SOLID_BETWEEN_2_DEFS, 78 BOUND_F_FOR_SOLID_BETWEEN_2_UNDEFS, 79 BOUND_F_FOR_SOLID_ENCLOSING_FLUID, 80 SFCONNECT_BETWEEN_2_SOLIDS, 81 SFCONNECT_BETWEEN_2_FLUIDS, 82 SFCONNECT_USED_AS_BOUNDARY, 83 SFCONNECT_BETWEEN_2_UNDEFS, 84 NO_CONNECTION_BETWEEN_2_FLUIDS, 85 NO_CONNECTION_BETWEEN_SOLID_AND_FLUID, 86 NO_BOUND_BETWEEN_FLUID_AND_UNDEF, 87 NO_BOUND_BETWEEN_SOLID_AND_UNDEF, 88 TRG_WITH_NO_PROPERTY, 89 PROPERTIES_CONFLICT_COUNT__ 90 }; 91 92 #define DARRAY_NAME interface_ptrs 93 #define DARRAY_DATA struct sdis_interface* 94 #include <rsys/dynamic_array.h> 95 96 struct dummies { 97 struct sdis_medium* dummy_fluid; 98 unsigned dummy_fluid_id; 99 struct fluid* stardis_fluid; 100 struct sdis_medium* dummy_solid; 101 unsigned dummy_solid_id; 102 struct solid* stardis_solid; 103 }; 104 #define DUMMIES_NULL__ {\ 105 NULL, UINT_MAX, NULL, NULL, UINT_MAX, NULL\ 106 } 107 static const struct dummies DUMMIES_NULL; 108 109 static FINLINE void 110 init_media_ptr 111 (struct mem_allocator* alloc, 112 struct sdis_medium** data) 113 { 114 ASSERT(data); (void)alloc; 115 *data = NULL; 116 } 117 118 #define DARRAY_NAME media_ptr 119 #define DARRAY_DATA struct sdis_medium* 120 #define DARRAY_FUNCTOR_INIT init_media_ptr 121 #include <rsys/dynamic_array.h> 122 123 struct geometry { 124 struct sg3d_geometry* sg3d; 125 struct darray_interface_ptrs interf_bytrg; 126 struct darray_interface_ptrs interfaces; 127 }; 128 129 void 130 release_geometry 131 (struct geometry* geom); 132 133 res_T 134 init_geometry 135 (struct logger* logger, 136 struct mem_allocator* allocator, 137 const int verbose, 138 struct geometry* geom); 139 140 /******************************************************************************/ 141 enum stardis_output_fmt { 142 STARDIS_RENDERING_OUTPUT_FILE_FMT_VTK, 143 STARDIS_RENDERING_OUTPUT_FILE_FMT_HT 144 }; 145 146 struct camera { 147 double pos[3]; 148 double tgt[3]; 149 double up[3]; 150 enum stardis_output_fmt fmt; 151 double fov; 152 double time_range[2]; 153 unsigned spp; 154 unsigned img_width, img_height; 155 int auto_look_at; 156 struct str file_name; 157 }; 158 159 void 160 init_camera 161 (struct mem_allocator* alloc, struct camera* cam); 162 163 /******************************************************************************/ 164 void 165 release_camera(struct camera* cam); 166 167 void 168 log_err_fn(const char* msg, void* ctx); 169 170 void 171 log_warn_fn(const char* msg, void* ctx); 172 173 void 174 log_prt_fn(const char* msg, void* ctx); 175 176 struct counts { 177 unsigned smed_count, fmed_count, tbound_count, hbound_count, 178 fbound_count, sfconnect_count, ssconnect_count; 179 }; 180 #define COUNTS_NULL__ {\ 181 0, 0, 0, 0, 0, 0, 0\ 182 } 183 184 /* Type to store the primitives of a compute region */ 185 #define DARRAY_NAME sides 186 #define DARRAY_DATA enum sdis_side 187 #include <rsys/dynamic_array.h> 188 189 #define DARRAY_NAME descriptions 190 #define DARRAY_DATA struct description 191 #define DARRAY_FUNCTOR_INIT init_description 192 #include <rsys/dynamic_array.h> 193 194 struct compute_surface { 195 struct darray_size_t primitives; 196 struct darray_sides sides; 197 struct darray_uint err_triangles; 198 double area; /* in m2, regardless of scale factor */ 199 }; 200 201 struct stardis { 202 struct dummies dummies; /* dummy meterials for boundaries' outside */ 203 struct geometry geometry; 204 struct sdis_scene* sdis_scn; /* The solver scene */ 205 struct darray_descriptions descriptions; /* Materials and boundaries */ 206 struct darray_media_ptr media; 207 struct senc3d_scene* senc3d_scn; 208 struct counts counts; 209 210 double probe[3]; /* x,y,z of probe when mode is PROBE_COMPUTE */ 211 double time_range[2]; /* compute time */ 212 struct camera camera; /* camera when mode is IR_COMPUTE */ 213 struct str solve_name; /* medium name when mode is MEDIUM_COMPUTE, 214 boundary file name when [FLUX_]BOUNDARY_COMPUTE 215 map file name when MAP_COMPUTE */ 216 struct compute_surface compute_surface; /* 2D compute region when mode is 217 [FLUX_]BOUNDARY_COMPUTE 218 or MAP_COMPUTE */ 219 220 /* Min/Max temperatures used to linearize radiative transfer */ 221 double t_range[2]; /* [K] */ 222 223 struct str dump_model_filename; 224 struct str paths_filename; 225 struct str bin_green_filename; 226 struct str end_paths_filename; 227 struct str rndgen_state_in_filename; 228 struct str rndgen_state_out_filename; 229 struct str chunks_prefix; 230 struct mem_allocator* allocator; 231 struct logger* logger; 232 struct sdis_device* dev; 233 struct radiative_env radenv; 234 int radenv_def; 235 size_t samples; 236 double scale_factor; 237 double initial_time; /* [s] */ 238 int mode; 239 unsigned nthreads; 240 unsigned picard_order; 241 unsigned next_medium_id; 242 unsigned undefined_medium_behind_boundary_id; 243 enum sdis_diffusion_algorithm diff_algo; 244 int dump_paths; 245 int verbose; 246 int geometry_initialized; 247 int mpi_initialized; 248 int mpi_rank; 249 250 struct darray_probe_boundary probe_boundary_list; 251 struct extern_source extsrc; 252 int disable_intrad; /* Disable internal radiative exchanges */ 253 }; 254 255 unsigned 256 allocate_stardis_medium_id 257 (struct stardis* stardis); 258 259 #ifdef STARDIS_ENABLE_MPI 260 extern LOCAL_SYM res_T 261 init_mpi 262 (int* pargc, 263 char** pargv[], 264 void (*prt_err_fn)(const char* msg, void* ctx), 265 void (*prt_warn_fn)(const char* msg, void* ctx)); 266 267 extern LOCAL_SYM void 268 finalize_mpi(void); 269 #endif 270 271 res_T 272 stardis_init 273 (const struct args* args, 274 struct logger* logger, 275 struct mem_allocator* allocator, 276 struct stardis* stardis); 277 278 void 279 stardis_release 280 (struct stardis* stardis); 281 282 res_T 283 init_enclosures 284 (struct stardis* stardis); 285 286 res_T 287 validate_properties 288 (const unsigned itri, 289 const unsigned properties[SG3D_PROP_TYPES_COUNT__], 290 void* context, 291 int* properties_conflict_status); 292 293 #endif /*STARDIS-APP_H*/