8.1
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-2023 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 "cs_defs.h"
35 #include "fvm_nodal.h"
36 #include "fvm_writer.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*=============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 /*----------------------------------------------------------------------------
51  * Structure defining an STL mesh
52  *----------------------------------------------------------------------------*/
53 
54 typedef struct {
55 
56  char name[20];
58  char header[80];
68  int n_seeds;
74  bool is_porous;
77  fvm_nodal_t *ext_mesh;
79 } cs_stl_mesh_t ;
80 
81 /*----------------------------------------------------------------------------
82  * Structure containing the number of STL meshes and their associated pointers
83  *----------------------------------------------------------------------------*/
84 
85 typedef struct {
86 
92  int writer_id;
95 
96 /*=============================================================================
97  * Static global variables
98  *============================================================================*/
99 
101 
102 /*=============================================================================
103  * Public function prototypes
104  *============================================================================*/
105 
106 /*-----------------------------------------------------------------------------
107  * Add a new STL mesh structure.
108  *
109  * parameters:
110  * path <-- path of the STL mesh
111  *
112  * returns:
113  * pointer to the new STL mesh structure
114  *----------------------------------------------------------------------------*/
115 
117 cs_stl_mesh_add(const char *path);
118 
119 /*----------------------------------------------------------------------------
120  * Return a pointer to a STL mesh based on its name if present.
121  *
122  * parameters:
123  * name <-- name of the STL mesh
124  *
125  * returns:
126  * pointer to the STL mesh structure, or NULL
127  *----------------------------------------------------------------------------*/
128 
130 cs_stl_mesh_get_by_name(const char *name);
131 
132 /*----------------------------------------------------------------------------
133  * Free all allocated STL mesh structures
134  *----------------------------------------------------------------------------*/
135 
136 void
138 
139 /*----------------------------------------------------------------------------
140  * Read a binary STL file and store its content in a STL mesh structure.
141  *
142  * parameters:
143  * stl_mesh <-- pointer to the associated STL mesh structure
144  * path <-- path to the STL file
145  *----------------------------------------------------------------------------*/
146 
147 void
149  const char *path);
150 
151 /*----------------------------------------------------------------------------
152  * Apply a transformation matrix to a STL mesh structure.
153  *
154  * parameters:
155  * stl_mesh <-- pointer to the associated STL mesh structure
156  * matrix <-- transformation matrix
157  *----------------------------------------------------------------------------*/
158 
159 void
161  double matrix[3][4]);
162 
163 /*----------------------------------------------------------------------------
164  * Apply a transformation matrix to a STL mesh structure, but use
165  * the initial coordinates as inputs
166  *
167  * parameters:
168  * stl_mesh <-- pointer to the associated STL mesh structure
169  * matrix <-- transformation matrix
170  *----------------------------------------------------------------------------*/
171 
172 void
174  double matrix[3][4]);
175 
176 /*----------------------------------------------------------------------------
177  * Apply a translation to a STL mesh structure.
178  *
179  * parameters:
180  * stl_mesh <-- pointer to the associated STL mesh structure
181  * vector <-- translation vector
182  *----------------------------------------------------------------------------*/
183 
184 void
186  double vector[3]);
187 
188 /*----------------------------------------------------------------------------
189  * Apply a rotation to a STL mesh structure.
190  *
191  * parameters:
192  * stl_mesh <-- pointer to the associated STL mesh structure
193  * tehta <-- rotation angle
194  * axis <-- rotation axis
195  * center <-- rotation center
196  *----------------------------------------------------------------------------*/
197 
198 void
200  double theta,
201  double axis[3],
202  double center[3]);
203 
204 /*----------------------------------------------------------------------------
205  * Apply a scaling to a STL mesh structure.
206  *
207  * parameters:
208  * stl_mesh <-- pointer to the associated STL mesh structure
209  * scale <-- scale factor
210  *----------------------------------------------------------------------------*/
211 
212 void
214  double scale);
215 
216 /*----------------------------------------------------------------------------
217  * Set the points outside he STL geometry. Those points will be used as seed
218  * to propagate porosity values outside the STL geometry.
219  *
220  * parameters:
221  * stl_mesh <-- pointer to the associated STL mesh structure
222  * n_points <-- number of points
223  * coords <-- coordinates (x1,y1,z1,...,xn,yn,zn)
224  * (size : 3*n_point)
225  *----------------------------------------------------------------------------*/
226 
227 void
229  int n_points,
230  cs_real_t *coords);
231 
232 /*----------------------------------------------------------------------------*/
236 /*----------------------------------------------------------------------------*/
237 
238 int
240 
241 /*----------------------------------------------------------------------------
242  * Create a new writer that will contains the STL mesh added by the user
243  * The writer_id is stored in the cs_glob_stl_meshes structure.
244  *
245  * case_name associated case name
246  * dir_name associated directory name
247  * fmt_name associated format name
248  * fmt_opts associated format options string
249  * time_dep FVM_WRITER_FIXED_MESH if mesh definitions
250  * are fixed, FVM_WRITER_TRANSIENT_COORDS if
251  * coordinates change, FVM_WRITER_TRANSIENT_CONNECT if
252  * connectivity changes
253  * output_at_start force output at calculation start if true
254  * output_at_end force output at calculation end if true
255  * frequency_n default output frequency in time-steps, or < 0
256  * frequency_t default output frequency in secon
257  *----------------------------------------------------------------------------*/
258 
259 void
260 cs_stl_post_init_writer(const char *case_name,
261  const char *dir_name,
262  const char *fmt_name,
263  const char *fmt_opts,
264  fvm_writer_time_dep_t time_dep,
265  bool output_at_start,
266  bool output_at_end,
267  int frequency_n,
268  double frequency_t);
269 
270 /*----------------------------------------------------------------------------
271  * Associate a STL mesh to the default writer
272  *
273  * stl_mesh <-- pointer to the associated STL mesh structure
274  *----------------------------------------------------------------------------*/
275 
276 void
278 
279 /*----------------------------------------------------------------------------
280  * Write a binary STL file according to a given STL mesh structure.
281  *
282  * parameters:
283  * stl_mesh <-- pointer to the associated STL mesh structure
284  * path <-- path to the STL file
285  *----------------------------------------------------------------------------*/
286 
287 void
289  const char *path);
290 
291 /*----------------------------------------------------------------------------
292  * Compute intersection between a STL mesh and the main mesh.
293  *
294  * parameters:
295  * stl_mesh <-- pointer to the associated STL mesh structure
296  * n_input <-- number of cells on which intersection is done
297  * input_index <-- index of input cells (size: n_input)
298  * n_selected_cells --> number of intersecting cells
299  * selected_cells --> index of output cells (size: n_output)
300  * tria_in_cell_idx --> start index of triangle intersecting each cell
301  * (size: n_output)
302  * tria_in_cell_lst --> list of triangles in intersecting cells
303  * max_size --> maximum size of tria_in_cell_lst array
304  *----------------------------------------------------------------------------*/
305 
306 void
308  cs_lnum_t n_input,
309  cs_lnum_t *input_idx,
310  cs_lnum_t *n_selected_cells,
311  cs_lnum_t *selected_cells,
312  cs_lnum_t *tria_in_cell_idx,
313  cs_lnum_t **tria_in_cell_lst,
314  cs_lnum_t *max_size);
315 
316 /*----------------------------------------------------------------------------
317  * Refine the mesh following a given STL mesh
318  *
319  * parameters:
320  * stl_mesh <-- pointer to the associated STL mesh structure
321  * n_ref <-- level of refinement
322  * n_add_layer <-- additional layers between two refinement stage
323  *----------------------------------------------------------------------------*/
324 
325 void
326 cs_stl_refine(cs_stl_mesh_t *stl_mesh,
327  int n_ref,
328  int n_add_layer);
329 
330 /*----------------------------------------------------------------------------
331  * Compute porosity field according to a given STL mesh
332  *
333  * parameters:
334  * stl_mesh <-- pointer to the associated STL mesh structure
335  * n_ref_point <-- number of prescribed points outside the STL
336  * ref_coords <-- coordinates of the reference points :
337  * x1,y1,z1,...,xn,yn,zn (size : 3*n_ref_point)
338  * porosity --> interpolated porosity field
339  * indic --> indicator of the STL location (NULL if not needed)
340  *----------------------------------------------------------------------------*/
341 
342 void
344  cs_real_t *porosity,
345  int *indic);
346 
347 /*----------------------------------------------------------------------------*/
348 
350 
351 #endif /* __CS_STL_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:514
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:334
#define END_C_DECLS
Definition: cs_defs.h:515
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
void matrix(const int *iconvp, const int *idiffp, const int *ndircp, const int *isym, const cs_real_t *thetap, const int *imucpp, const cs_real_t coefbp[], const cs_real_t cofbfp[], const cs_real_t rovsdt[], const cs_real_t i_massflux[], const cs_real_t b_massflux[], const cs_real_t i_visc[], const cs_real_t b_visc[], const cs_real_t xcpp[], cs_real_t da[], cs_real_t xa[])
void cs_stl_mesh_destroy_all(void)
Free all allocated STL mesh structures.
Definition: cs_stl.c:1124
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.c:1517
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.c:1564
cs_stl_mesh_t * cs_stl_mesh_add(const char *path)
Add a new STL mesh structure.
Definition: cs_stl.c:1050
void cs_stl_post_add_mesh(cs_stl_mesh_t *stl_mesh)
Associate a STL mesh to the default writer.
Definition: cs_stl.c:1642
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.c:1159
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.c:1672
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.c:1971
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.c:1418
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.c:1455
int cs_stl_post_get_writer_id(void)
Return writer_id used for stl meshes. 0 means unused.
Definition: cs_stl.c:1582
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.c:1103
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.c:1772
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.c:1489
void cs_stl_mesh_scale(cs_stl_mesh_t *stl_mesh, double scale)
Apply a scaling to a STL mesh structure.
Definition: cs_stl.c:1539
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.c:1599
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.c:2119
fvm_writer_time_dep_t
Definition: fvm_writer.h:57
double precision, dimension(:,:,:), allocatable theta
Definition: atimbr.f90:123
Definition: cs_stl.h:85
cs_stl_mesh_t ** mesh_list
Definition: cs_stl.h:87
int writer_id
Definition: cs_stl.h:92
cs_lnum_t n_meshes
Definition: cs_stl.h:90
Definition: cs_stl.h:54
cs_real_3_t * coords_ini
Definition: cs_stl.h:65
cs_lnum_t n_faces
Definition: cs_stl.h:60
cs_real_3_t * coords
Definition: cs_stl.h:62
bool is_porous
Definition: cs_stl.h:74
int n_seeds
Definition: cs_stl.h:68
cs_real_t * seed_coords
Definition: cs_stl.h:71
fvm_nodal_t * ext_mesh
Definition: cs_stl.h:77