9.2
general documentation
cs_stl.h
Go to the documentation of this file.
1#ifndef CS_STL_H
2#define CS_STL_H
3
4/*============================================================================
5 * STL reader and writer.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35#include "fvm/fvm_nodal.h"
36#include "fvm/fvm_writer.h"
37
38/*=============================================================================
39 * Macro definitions
40 *============================================================================*/
41
42/*============================================================================
43 * Type definitions
44 *============================================================================*/
45
46/*----------------------------------------------------------------------------
47 * Structure defining an STL mesh
48 *----------------------------------------------------------------------------*/
49
50typedef struct {
51
52 char name[20];
54 char header[80];
69 int n_seeds;
75 bool is_porous;
78 fvm_nodal_t *ext_mesh;
81
82/*----------------------------------------------------------------------------
83 * Structure containing the number of STL meshes and their associated pointers
84 *----------------------------------------------------------------------------*/
85
86typedef struct {
87
96
97/*=============================================================================
98 * Static global variables
99 *============================================================================*/
100
102
103/*=============================================================================
104 * Public function prototypes
105 *============================================================================*/
106
107/*-----------------------------------------------------------------------------
108 * Add a new STL mesh structure.
109 *
110 * parameters:
111 * path <-- path of the STL mesh
112 *
113 * returns:
114 * pointer to the new STL mesh structure
115 *----------------------------------------------------------------------------*/
116
118cs_stl_mesh_add(const char *path);
119
120/*----------------------------------------------------------------------------
121 * Return a pointer to a STL mesh based on its name if present.
122 *
123 * parameters:
124 * name <-- name of the STL mesh
125 *
126 * returns:
127 * pointer to the STL mesh structure, or NULL
128 *----------------------------------------------------------------------------*/
129
131cs_stl_mesh_get_by_name(const char *name);
132
133/*----------------------------------------------------------------------------
134 * Free all allocated STL mesh structures
135 *----------------------------------------------------------------------------*/
136
137void
139
140/*----------------------------------------------------------------------------
141 * Read a binary STL file and store its content in a STL mesh structure.
142 *
143 * parameters:
144 * stl_mesh <-- pointer to the associated STL mesh structure
145 * path <-- path to the STL file
146 *----------------------------------------------------------------------------*/
147
148void
150 const char *path);
151
152/*----------------------------------------------------------------------------
153 * Apply a transformation matrix to a STL mesh structure.
154 *
155 * parameters:
156 * stl_mesh <-- pointer to the associated STL mesh structure
157 * matrix <-- transformation matrix
158 *----------------------------------------------------------------------------*/
159
160void
162 double matrix[3][4]);
163
164/*----------------------------------------------------------------------------
165 * Apply a transformation matrix to a STL mesh structure, but use
166 * the initial coordinates as inputs
167 *
168 * parameters:
169 * stl_mesh <-- pointer to the associated STL mesh structure
170 * matrix <-- transformation matrix
171 *----------------------------------------------------------------------------*/
172
173void
175 double matrix[3][4]);
176
177/*----------------------------------------------------------------------------
178 * Apply a translation to a STL mesh structure.
179 *
180 * parameters:
181 * stl_mesh <-- pointer to the associated STL mesh structure
182 * vector <-- translation vector
183 *----------------------------------------------------------------------------*/
184
185void
187 double vector[3]);
188
189/*----------------------------------------------------------------------------
190 * Apply a rotation to a STL mesh structure.
191 *
192 * parameters:
193 * stl_mesh <-- pointer to the associated STL mesh structure
194 * tehta <-- rotation angle
195 * axis <-- rotation axis
196 * center <-- rotation center
197 *----------------------------------------------------------------------------*/
198
199void
201 double theta,
202 double axis[3],
203 double center[3]);
204
205/*----------------------------------------------------------------------------
206 * Apply a scaling to a STL mesh structure.
207 *
208 * parameters:
209 * stl_mesh <-- pointer to the associated STL mesh structure
210 * scale <-- scale factor
211 *----------------------------------------------------------------------------*/
212
213void
215 double scale);
216
217/*----------------------------------------------------------------------------
218 * Set the points outside he STL geometry. Those points will be used as seed
219 * to propagate porosity values outside the STL geometry.
220 *
221 * parameters:
222 * stl_mesh <-- pointer to the associated STL mesh structure
223 * n_points <-- number of points
224 * coords <-- coordinates (x1,y1,z1,...,xn,yn,zn)
225 * (size : 3*n_point)
226 *----------------------------------------------------------------------------*/
227
228void
230 int n_points,
231 cs_real_t *coords);
232
233/*----------------------------------------------------------------------------*/
237/*----------------------------------------------------------------------------*/
238
239int
241
242/*----------------------------------------------------------------------------
243 * Create a new writer that will contains the STL mesh added by the user
244 * The writer_id is stored in the cs_glob_stl_meshes structure.
245 *
246 * case_name associated case name
247 * dir_name associated directory name
248 * fmt_name associated format name
249 * fmt_opts associated format options string
250 * time_dep FVM_WRITER_FIXED_MESH if mesh definitions
251 * are fixed, FVM_WRITER_TRANSIENT_COORDS if
252 * coordinates change, FVM_WRITER_TRANSIENT_CONNECT if
253 * connectivity changes
254 * output_at_start force output at calculation start if true
255 * output_at_end force output at calculation end if true
256 * frequency_n default output frequency in time-steps, or < 0
257 * frequency_t default output frequency in secon
258 *----------------------------------------------------------------------------*/
259
260void
261cs_stl_post_init_writer(const char *case_name,
262 const char *dir_name,
263 const char *fmt_name,
264 const char *fmt_opts,
265 fvm_writer_time_dep_t time_dep,
266 bool output_at_start,
267 bool output_at_end,
268 int frequency_n,
269 double frequency_t);
270
271/*----------------------------------------------------------------------------
272 * Associate a STL mesh to the default writer
273 *
274 * stl_mesh <-- pointer to the associated STL mesh structure
275 *----------------------------------------------------------------------------*/
276
277void
279
280/*----------------------------------------------------------------------------
281 * Write a binary STL file according to a given STL mesh structure.
282 *
283 * parameters:
284 * stl_mesh <-- pointer to the associated STL mesh structure
285 * path <-- path to the STL file
286 *----------------------------------------------------------------------------*/
287
288void
290 const char *path);
291
292/*----------------------------------------------------------------------------
293 * Compute intersection between a STL mesh and the main mesh.
294 *
295 * parameters:
296 * stl_mesh <-- pointer to the associated STL mesh structure
297 * n_input <-- number of cells on which intersection is done
298 * input_index <-- index of input cells (size: n_input)
299 * n_selected_cells --> number of intersecting cells
300 * selected_cells --> index of output cells (size: n_output)
301 * tria_in_cell_idx --> start index of triangle intersecting each cell
302 * (size: n_output)
303 * tria_in_cell_lst --> list of triangles in intersecting cells
304 * max_size --> maximum size of tria_in_cell_lst array
305 *----------------------------------------------------------------------------*/
306
307void
309 cs_lnum_t n_input,
310 cs_lnum_t *input_idx,
311 cs_lnum_t *n_selected_cells,
312 cs_lnum_t *selected_cells,
313 cs_lnum_t *tria_in_cell_idx,
314 cs_lnum_t **tria_in_cell_lst,
315 cs_lnum_t *max_size);
316
317/*----------------------------------------------------------------------------
318 * Refine the mesh following a given STL mesh
319 *
320 * parameters:
321 * stl_mesh <-- pointer to the associated STL mesh structure
322 * n_ref <-- level of refinement
323 * n_add_layer <-- additional layers between two refinement stage
324 *----------------------------------------------------------------------------*/
325
326void
328 int n_ref,
329 int n_add_layer);
330
331/*----------------------------------------------------------------------------
332 * Compute porosity field according to a given STL mesh
333 *
334 * parameters:
335 * stl_mesh <-- pointer to the associated STL mesh structure
336 * n_ref_point <-- number of prescribed points outside the STL
337 * ref_coords <-- coordinates of the reference points :
338 * x1,y1,z1,...,xn,yn,zn (size : 3*n_ref_point)
339 * porosity --> interpolated porosity field
340 * indic --> indicator of the STL location (NULL if not needed)
341 *----------------------------------------------------------------------------*/
342
343void
345 cs_real_t *porosity,
346 int *indic);
347
348/*----------------------------------------------------------------------------*/
349
350#endif /* CS_STL_H */
cs_lnum_t cs_lnum_3_t[3]
Definition: cs_defs.h:343
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
void cs_stl_mesh_destroy_all(void)
Free all allocated STL mesh structures.
Definition: cs_stl.cpp:1205
void cs_stl_mesh_rotate(cs_stl_mesh_t *stl_mesh, double theta, double axis[3], double center[3])
Apply a rotation to a STL mesh structure.
Definition: cs_stl.cpp:1932
void cs_stl_set_porosity_seed(cs_stl_mesh_t *stl_mesh, int n_points, cs_real_t *coords)
Set the points outside he STL geometry. Those points will be used as.
Definition: cs_stl.cpp:1978
cs_stl_mesh_t * cs_stl_mesh_add(const char *path)
Add a new STL mesh structure.
Definition: cs_stl.cpp:1129
void cs_stl_post_add_mesh(cs_stl_mesh_t *stl_mesh)
Associate a STL mesh to the default writer.
Definition: cs_stl.cpp:2056
cs_stl_mesh_t * cs_stl_mesh_get_by_name(const char *name)
Return a pointer to a STL mesh based on its name if present.
Definition: cs_stl.cpp:1184
void cs_stl_file_read(cs_stl_mesh_t *stl_mesh, const char *path)
Read a binary STL file and store its content in a STL mesh structure.
Definition: cs_stl.cpp:1242
void cs_stl_file_write(cs_stl_mesh_t *stl_mesh, const char *path)
Write a binary STL file according to a given STL mesh structure.
Definition: cs_stl.cpp:2086
void cs_stl_refine(cs_stl_mesh_t *stl_mesh, int n_ref, int n_add_layer)
Refine the mesh following a given STL mesh.
Definition: cs_stl.cpp:2391
void cs_stl_mesh_transform(cs_stl_mesh_t *stl_mesh, double matrix[3][4])
Apply a transformation matrix to a STL mesh structure.
Definition: cs_stl.cpp:1836
void cs_stl_mesh_transform_from_init(cs_stl_mesh_t *stl_mesh, double matrix[3][4])
Apply a transformation matrix to a STL mesh structure, but use.
Definition: cs_stl.cpp:1872
int cs_stl_post_get_writer_id(void)
Return writer_id used for stl meshes. 0 means unused.
Definition: cs_stl.cpp:1996
void cs_stl_intersection(cs_stl_mesh_t *stl_mesh, cs_lnum_t n_input, cs_lnum_t *input_idx, cs_lnum_t *n_selected_cells, cs_lnum_t *selected_cells, cs_lnum_t *tria_in_cell_idx, cs_lnum_t **tria_in_cell_lst, cs_lnum_t *max_size)
Compute intersection between a STL mesh and the main mesh.
Definition: cs_stl.cpp:2186
void cs_stl_mesh_translate(cs_stl_mesh_t *stl_mesh, double vector[3])
Apply a translation to a STL mesh structure.
Definition: cs_stl.cpp:1905
void cs_stl_mesh_scale(cs_stl_mesh_t *stl_mesh, double scale)
Apply a scaling to a STL mesh structure.
Definition: cs_stl.cpp:1954
void cs_stl_post_init_writer(const char *case_name, const char *dir_name, const char *fmt_name, const char *fmt_opts, fvm_writer_time_dep_t time_dep, bool output_at_start, bool output_at_end, int frequency_n, double frequency_t)
Create a new writer that will contains the STL mesh added by the user.
Definition: cs_stl.cpp:2013
cs_stl_mesh_info_t * cs_glob_stl_meshes
void cs_stl_compute_porosity(cs_stl_mesh_t *stl_mesh, cs_real_t *porosity, int *indic)
Compute porosity field according to a given STL mesh.
Definition: cs_stl.cpp:2539
fvm_writer_time_dep_t
Definition: fvm_writer.h:57
Definition: cs_stl.h:86
cs_stl_mesh_t ** mesh_list
Definition: cs_stl.h:88
int writer_id
Definition: cs_stl.h:93
cs_lnum_t n_meshes
Definition: cs_stl.h:91
Definition: cs_stl.h:50
cs_real_3_t * coords_ini
Definition: cs_stl.h:66
cs_lnum_t n_faces
Definition: cs_stl.h:56
cs_real_3_t * coords
Definition: cs_stl.h:61
bool is_porous
Definition: cs_stl.h:75
int n_seeds
Definition: cs_stl.h:69
cs_real_t * seed_coords
Definition: cs_stl.h:72
cs_lnum_t n_points
Definition: cs_stl.h:58
cs_lnum_3_t * tria_vtx_ids
Definition: cs_stl.h:64
fvm_nodal_t * ext_mesh
Definition: cs_stl.h:78