7.1
general documentation
fvm_writer_helper.h
Go to the documentation of this file.
1 #ifndef __FVM_WRITER_HELPER_H__
2 #define __FVM_WRITER_HELPER_H__
3 
4 /*============================================================================
5  * Helper types and functions for mesh and field writers
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 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 #include "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------
33  * Local headers
34  *----------------------------------------------------------------------------*/
35 
36 #include "cs_block_dist.h"
37 #include "cs_part_to_block.h"
38 #include "fvm_defs.h"
39 #include "fvm_nodal.h"
40 #include "fvm_writer.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*=============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*============================================================================
51  * Type definitions
52  *============================================================================*/
53 
54 /*----------------------------------------------------------------------------
55  * FVM nodal to writer section translation list
56  *----------------------------------------------------------------------------*/
57 
58 typedef struct _fvm_writer_section_t {
59 
60  struct _fvm_writer_section_t *next; /* Pointer to next element
61  in list (NULL at end) */
62 
63  const fvm_nodal_section_t *section; /* Corresponding section in mesh */
64 
65  cs_gnum_t extra_vertex_base; /* Start global number of added
66  vertices (for tesselation) */
67 
68  cs_lnum_t num_shift; /* Element number shift when no
69  parent lists are used */
70  fvm_element_t type; /* Corresponding element type (may
71  differ from section->type when
72  using tesselations) */
73 
74  bool continues_previous; /* Indicates if the corresponding FVM
75  nodal section should be appended
76  to the previous one on output */
77 
79 
80 /*----------------------------------------------------------------------------
81  * FVM nodal to writer field output helper
82  *----------------------------------------------------------------------------*/
83 
84 /*
85  Pointer to structure keeping track of the status of a writer's field
86  output state. The structure itself is private, and is defined in fvm_writer.c
87 */
88 
89 typedef struct _fvm_writer_field_helper_t fvm_writer_field_helper_t;
90 
91 /*----------------------------------------------------------------------------
92  * Function pointer for output of field values by a writer helper
93  *
94  * parameters:
95  * context <-> pointer to writer and field context
96  * datatype <-- output datatype
97  * dimension <-- output field dimension
98  * component_id <-- output component id (if non-interleaved)
99  * block_start <-- start global number of element for current block
100  * block_end <-- past-the-end global number of element for current block
101  * buffer <-> associated output buffer
102  *----------------------------------------------------------------------------*/
103 
104 typedef void
105 (fvm_writer_field_output_t) (void *context,
106  cs_datatype_t datatype,
107  int dimension,
108  int component_id,
109  cs_gnum_t block_start,
110  cs_gnum_t block_end,
111  void *buffer);
112 
113 /*=============================================================================
114  * Semi-private function prototypes
115  *============================================================================*/
116 
117 /*----------------------------------------------------------------------------
118  * Build list of sections to output
119  *
120  * Depending on whether multiple sections of a given element type
121  * are allowed or not, sections may be ordered in different ways.
122  * Discarded element types are not added to the list.
123  *
124  * parameters:
125  * mesh <-- pointer to nodal mesh structure
126  * min_export_dim <-- minimum dimension of sections to export
127  * max_export_dim <-- maximum dimension of sections to export
128  * boundary_flag <-- -1 if ignored, otherwise only sections
129  * with -1 or matching boundary flag
130  * group_by_type <-- if true, group sections of same type
131  * group_all <-- if true, all sections continue previous ones
132  * discard_polygons <-- ignore polygonal sections
133  * discard_polyhedra <-- ignore polyhedral sections
134  * divide_polygons <-- tesselate polygonal sections
135  * divide_polyhedra <-- tesselate polyhedral sections
136  *
137  * returns:
138  * array of section translations (must be freed by caller),
139  * or NULL if section list is completely empty
140  *----------------------------------------------------------------------------*/
141 
143 fvm_writer_export_list(const fvm_nodal_t *mesh,
144  int min_export_dim,
145  int max_export_dim,
146  int boundary_flag,
147  bool group_by_type,
148  bool group_all,
149  bool discard_polygons,
150  bool discard_polyhedra,
151  bool divide_polygons,
152  bool divide_polyhedra);
153 
154 /*----------------------------------------------------------------------------
155  * Count number of extra vertices when tesselations are present
156  *
157  * parameters:
158  * mesh <-- pointer to nodal mesh structure
159  * divide_polyhedra <-- true if polyhedra are tesselated
160  * n_extra_vertices_g --> global number of extra vertices (optional)
161  * n_extra_vertices --> local number of extra vertices (optional)
162  *----------------------------------------------------------------------------*/
163 
164 void
165 fvm_writer_count_extra_vertices(const fvm_nodal_t *mesh,
166  bool divide_polyhedra,
167  cs_gnum_t *n_extra_vertices_g,
168  cs_lnum_t *n_extra_vertices);
169 
170 #if defined(HAVE_MPI)
171 
172 /*----------------------------------------------------------------------------
173  * Build block info and part to block distribution helper for vertices.
174  *
175  * parameters:
176  * min_rank_step <-- minimum step between output ranks
177  * min_block_size <-- minimum block buffer size
178  * n_g_add_vertices <-- global number of vertices due to tesselated polyhedra
179  * n_add_vertices <-- local number of vertices due to tesselated polyhedra
180  * mesh <-- pointer to nodal mesh structure
181  * bi --> block information structure
182  * d --> part to block distributor
183  * comm <-- associated communicator
184  *----------------------------------------------------------------------------*/
185 
186 void
187 fvm_writer_vertex_part_to_block_create(int min_rank_step,
188  cs_lnum_t min_block_size,
189  cs_gnum_t n_g_add_vertices,
190  cs_lnum_t n_add_vertices,
191  const fvm_nodal_t *mesh,
193  cs_part_to_block_t **d,
194  MPI_Comm comm);
195 
196 #endif /* defined(HAVE_MPI) */
197 
198 /*----------------------------------------------------------------------------
199  * Return extra vertex coordinates when tesselations are present
200  *
201  * parameters:
202  * mesh <-- pointer to nodal mesh structure
203  * n_extra_vertices <-- number of extra vertices
204  *
205  * returns:
206  * array containing all extra vertex coordinates
207  *----------------------------------------------------------------------------*/
208 
209 cs_coord_t *
210 fvm_writer_extra_vertex_coords(const fvm_nodal_t *mesh,
211  cs_lnum_t n_extra_vertices);
212 
213 /*----------------------------------------------------------------------------
214  * Create field writer helper structure.
215  *
216  * Local values are initialized, ang lobal values are set to zero
217  * (they may be initialized by calling fvm_writer_field_helper_init_g()).
218  *
219  * parameters:
220  * mesh <-- pointer to nodal mesh structure
221  * section_list <-- point to export section list helper structure
222  * field_dim <-- indicates output field dimension
223  * interlace <-- indicates if output is interlaced
224  * location <-- indicates if field is cell or node based
225  * datatype <-- datatype of destination buffers
226  *
227  * returns:
228  * pointer to allocated and initialized field writer helper
229  *----------------------------------------------------------------------------*/
230 
232 fvm_writer_field_helper_create(const fvm_nodal_t *mesh,
233  const fvm_writer_section_t *section_list,
234  int field_dim,
235  cs_interlace_t interlace,
236  cs_datatype_t datatype,
237  fvm_writer_var_loc_t location);
238 
239 /*----------------------------------------------------------------------------
240  * Destroy FVM field writer helper.
241  *
242  * parameters: * helper <-> pointer to pointer to structure that should be destroyed
243  *----------------------------------------------------------------------------*/
244 
245 void
247 
248 #if defined(HAVE_MPI)
249 
250 /*----------------------------------------------------------------------------
251  * Set MPI info for an fvm_writer_field_helper structure.
252  *
253  * parameters:
254  * helper <-> pointer to structure that should be initialized
255  * min_rank_step <-- minimum step between output ranks
256  * min_block_size <-- minimum block buffer size
257  * comm <-- associated MPI communicator
258  *
259  * returns:
260  * pointer to allocated and initialized field writer helper
261  *----------------------------------------------------------------------------*/
262 
263 void
264 fvm_writer_field_helper_init_g(fvm_writer_field_helper_t *helper,
265  int min_rank_step,
266  int min_block_size,
267  MPI_Comm comm);
268 
269 #endif /* defined(HAVE_MPI) */
270 
271 /*----------------------------------------------------------------------------
272  * Return sizes associated with a writer field helper.
273  *
274  * parameters:
275  * helper <-- pointer to helper structure
276  * input_size --> Total field locations in input (or NULL)
277  * output_size --> Total field locations in output (or NULL)
278  * min_output_buffer_size --> Minimum required buffer size (or NULL)
279  *----------------------------------------------------------------------------*/
280 
281 void
283  size_t *input_size,
284  size_t *output_size,
285  size_t *min_output_buffer_size);
286 
287 /*----------------------------------------------------------------------------
288  * Return the output dimension associated with a writer field helper.
289  *
290  * parameters:
291  * helper <-- pointer to helper structure
292  *
293  * returns:
294  * field dimension associated with helper
295  *----------------------------------------------------------------------------*/
296 
297 int
299 
300 /*----------------------------------------------------------------------------
301  * Return the output datatype associated with a writer field helper.
302  *
303  * parameters:
304  * helper <-- pointer to helper structure
305  *
306  * returns:
307  * output datatype associated with helper
308  *----------------------------------------------------------------------------*/
309 
312 
313 /*----------------------------------------------------------------------------
314  * Partially distribute field values to a local output buffer.
315  *
316  * parameters:
317  * helper <-> pointer to helper structure
318  * export_section <-- pointer to section helper structure
319  * src_dim <-- dimension of source data
320  * src_dim_shift <-- source data dimension shift (start index)
321  * src_interlace <-- indicates if field in memory is interlaced
322  * n_parent_lists <-- indicates if field values are to be obtained
323  * directly through the local entity index (when 0) or
324  * through the parent entity numbers (when 1 or more)
325  * parent_num_shift <-- parent list to common number index shifts;
326  * size: n_parent_lists
327  * datatype <-- indicates the data type of (source) field values
328  * field_values <-- array of associated field value arrays
329  * datatype <-- input data type
330  * field_values <-- pointer to input array
331  * output_buffer <-- pointer to output buffer
332  * (working array only for ranks > 0)
333  * output_buffer_size <-- size of output buffer (in datatype units)
334  * output_size --> size of output upon return (in datatype units)
335  *
336  * returns:
337  * 0 if values were distributed to the output buffer, 1 if the end of the
338  * section has already been reached and no values were left to distribute.
339  *----------------------------------------------------------------------------*/
340 
341 int
343  const fvm_writer_section_t *export_section,
344  int src_dim,
345  int src_dim_shift,
346  cs_interlace_t src_interlace,
347  int n_parent_lists,
348  const cs_lnum_t parent_num_shift[],
349  cs_datatype_t datatype,
350  const void *const field_values[],
351  void *output_buffer,
352  size_t output_buffer_size,
353  size_t *output_size);
354 
355 /*----------------------------------------------------------------------------
356  * Partially distribute per node field values to a local output buffer.
357  *
358  * parameters:
359  * helper <-> pointer to helper structure
360  * mesh <-- pointer to associated mesh
361  * src_dim <-- dimension of source data
362  * src_dim_shift <-- source data dimension shift (start index)
363  * src_interlace <-- indicates if field in memory is interlaced
364  * n_parent_lists <-- indicates if field values are to be obtained
365  * directly through the local entity index (when 0) or
366  * through the parent entity numbers (when 1 or more)
367  * parent_num_shift <-- parent list to common number index shifts;
368  * size: n_parent_lists
369  * datatype <-- indicates the data type of (source) field values
370  * field_values <-- array of associated field value arrays
371  * datatype <-- input data type
372  * field_values <-- pointer to input array
373  * output_buffer <-- pointer to output buffer
374  * (working array only for ranks > 0)
375  * output_buffer_size <-- size of output buffer (in datatype units)
376  * output_size --> size of output upon return (in datatype units)
377  *
378  * returns:
379  * 0 if values were distributed to the output buffer, 1 if the end of the
380  * section has already been reached and no values were left to distribute.
381  *----------------------------------------------------------------------------*/
382 
383 int
385  const fvm_nodal_t *mesh,
386  int src_dim,
387  int src_dim_shift,
388  cs_interlace_t src_interlace,
389  int n_parent_lists,
390  const cs_lnum_t parent_num_shift[],
391  cs_datatype_t datatype,
392  const void *const field_values[],
393  void *output_buffer,
394  size_t output_buffer_size,
395  size_t *output_size);
396 
397 /*----------------------------------------------------------------------------
398  * Output per element field values, using writer-specific function
399  * and context structure pointers.
400  *
401  * Note that if the output data is not interleaved, for multidimensional data,
402  * the output function is called once per component, using the same buffer.
403  * This is a good fit for most options, but if a format requires writing
404  * additional buffering may be required in the context.
405  *
406  * parameters:
407  * helper <-> pointer to helper structure
408  * context <-> pointer to writer context
409  * export_section <-- pointer to section helper structure
410  * src_dim <-- dimension of source data
411  * src_interlace <-- indicates if field in memory is interlaced
412  * comp_order <-- field component reordering array, or NULL
413  * n_parent_lists <-- indicates if field values are to be obtained
414  * directly through the local entity index (when 0) or
415  * through the parent entity numbers (when 1 or more)
416  * parent_num_shift <-- parent list to common number index shifts;
417  * size: n_parent_lists
418  * datatype <-- indicates the data type of (source) field values
419  * field_values <-- array of associated field value arrays
420  * output_func <-- pointer to output function
421  *
422  * returns:
423  * pointer to next section helper structure in list
424  *----------------------------------------------------------------------------*/
425 
426 const fvm_writer_section_t *
428  void *context,
429  const fvm_writer_section_t *export_section,
430  int src_dim,
431  cs_interlace_t src_interlace,
432  const int *comp_order,
433  int n_parent_lists,
434  const cs_lnum_t parent_num_shift[],
435  cs_datatype_t datatype,
436  const void *const field_values[],
437  fvm_writer_field_output_t *output_func);
438 
439 /*----------------------------------------------------------------------------
440  * Output per node field values, using writer-specific function
441  * and context structure pointers.
442  *
443  * Note that if the output data is not interleaved, for multidimensional data,
444  * the output function is called once per component, using the same buffer.
445  * This is a good fit for most options, but if a format requires writing
446  * additional buffering may be required in the context.
447  *
448  * parameters:
449  * helper <-> pointer to helper structure
450  * context <-> pointer to writer context
451  * mesh <-- pointer to nodal mesh
452  * divide_polyhedra <-- tesselate polyhedral sections
453  * src_dim <-- dimension of source data
454  * src_dim_shift <-- source data dimension shift (start index)
455  * src_interlace <-- indicates if field in memory is interlaced
456  * n_parent_lists <-- indicates if field values are to be obtained
457  * directly through the local entity index (when 0) or
458  * through the parent entity numbers (when 1 or more)
459  * parent_num_shift <-- parent list to common number index shifts;
460  * size: n_parent_lists
461  * datatype <-- indicates the data type of (source) field values
462  * field_values <-- array of associated field value arrays
463  * datatype <-- input data type
464  * field_values <-- pointer to input array
465  * output_func <-- pointer to output function
466  *----------------------------------------------------------------------------*/
467 
468 void
470  void *context,
471  const fvm_nodal_t *mesh,
472  int src_dim,
473  cs_interlace_t src_interlace,
474  const int *comp_order,
475  int n_parent_lists,
476  const cs_lnum_t parent_num_shift[],
477  cs_datatype_t datatype,
478  const void *const field_values[],
479  fvm_writer_field_output_t *output_func);
480 
481 /*----------------------------------------------------------------------------
482  * Set string representing a field component's name based on its id.
483  *
484  * parameters:
485  * s --> destination string
486  * s_size <-- maximum string size
487  * lowercase <-- true if lowercase is required
488  * dimension <-- field dimension
489  * component_id <-- field component id
490  *----------------------------------------------------------------------------*/
491 
492 void
494  size_t s_size,
495  bool lowercase,
496  int dimension,
497  int component_id);
498 
499 /*----------------------------------------------------------------------------*/
500 
502 
503 #endif /* __FVM_WRITER_HELPER_H__ */
struct _fvm_writer_section_t * next
Definition: fvm_writer_helper.h:60
const fvm_nodal_section_t * section
Definition: fvm_writer_helper.h:63
cs_datatype_t
Definition: cs_defs.h:275
void fvm_writer_field_helper_destroy(fvm_writer_field_helper_t **helper)
int fvm_writer_field_helper_step_el(fvm_writer_field_helper_t *helper, const fvm_writer_section_t *export_section, int src_dim, int src_dim_shift, cs_interlace_t src_interlace, int n_parent_lists, const cs_lnum_t parent_num_shift[], cs_datatype_t datatype, const void *const field_values[], void *output_buffer, size_t output_buffer_size, size_t *output_size)
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:301
Definition: fvm_nodal_priv.h:58
void fvm_writer_field_helper_output_n(fvm_writer_field_helper_t *helper, void *context, const fvm_nodal_t *mesh, int src_dim, cs_interlace_t src_interlace, const int *comp_order, int n_parent_lists, const cs_lnum_t parent_num_shift[], cs_datatype_t datatype, const void *const field_values[], fvm_writer_field_output_t *output_func)
fvm_writer_var_loc_t
Definition: fvm_writer.h:69
cs_coord_t * fvm_writer_extra_vertex_coords(const fvm_nodal_t *mesh, cs_lnum_t n_extra_vertices)
Definition: cs_block_dist.h:50
cs_interlace_t
Definition: cs_defs.h:482
cs_lnum_t num_shift
Definition: fvm_writer_helper.h:68
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
struct _cs_part_to_block_t cs_part_to_block_t
Definition: cs_part_to_block.h:57
int fvm_writer_field_helper_step_nl(fvm_writer_field_helper_t *helper, const fvm_nodal_t *mesh, int src_dim, int src_dim_shift, cs_interlace_t src_interlace, int n_parent_lists, const cs_lnum_t parent_num_shift[], cs_datatype_t datatype, const void *const field_values[], void *output_buffer, size_t output_buffer_size, size_t *output_size)
double cs_coord_t
Definition: cs_defs.h:320
void() fvm_writer_field_output_t(void *context, cs_datatype_t datatype, int dimension, int component_id, cs_gnum_t block_start, cs_gnum_t block_end, void *buffer)
Definition: fvm_writer_helper.h:105
fvm_element_t
Definition: fvm_defs.h:48
void fvm_writer_field_helper_get_size(const fvm_writer_field_helper_t *helper, size_t *input_size, size_t *output_size, size_t *min_output_buffer_size)
struct _fvm_writer_field_helper_t fvm_writer_field_helper_t
Definition: fvm_writer_helper.h:89
void fvm_writer_count_extra_vertices(const fvm_nodal_t *mesh, bool divide_polyhedra, cs_gnum_t *n_extra_vertices_g, cs_lnum_t *n_extra_vertices)
const fvm_writer_section_t * fvm_writer_field_helper_output_e(fvm_writer_field_helper_t *helper, void *context, const fvm_writer_section_t *export_section, int src_dim, cs_interlace_t src_interlace, const int *comp_order, int n_parent_lists, const cs_lnum_t parent_num_shift[], cs_datatype_t datatype, const void *const field_values[], fvm_writer_field_output_t *output_func)
fvm_writer_section_t * fvm_writer_export_list(const fvm_nodal_t *mesh, int min_export_dim, int max_export_dim, int boundary_flag, bool group_by_type, bool group_all, bool discard_polygons, bool discard_polyhedra, bool divide_polygons, bool divide_polyhedra)
void fvm_writer_field_component_name(char *s, size_t s_size, bool lowercase, int dimension, int component_id)
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
#define END_C_DECLS
Definition: cs_defs.h:511
Definition: fvm_writer_helper.h:58
fvm_writer_field_helper_t * fvm_writer_field_helper_create(const fvm_nodal_t *mesh, const fvm_writer_section_t *section_list, int field_dim, cs_interlace_t interlace, cs_datatype_t datatype, fvm_writer_var_loc_t location)
fvm_element_t type
Definition: fvm_writer_helper.h:70
cs_gnum_t extra_vertex_base
Definition: fvm_writer_helper.h:65
bool continues_previous
Definition: fvm_writer_helper.h:74
int fvm_writer_field_helper_field_dim(const fvm_writer_field_helper_t *helper)
Definition: mesh.f90:26
cs_datatype_t fvm_writer_field_helper_datatype(const fvm_writer_field_helper_t *helper)