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