My Project
programmer's 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-2019 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  * group_by_type <-- if true, group sections of same type
127  * group_all <-- if true, all sections continue previous ones
128  * min_export_dim <-- minimum dimension of sections to export
129  * discard_polygons <-- ignore polygonal sections
130  * discard_polyhedra <-- ignore polyhedral sections
131  * divide_polygons <-- tesselate polygonal sections
132  * divide_polyhedra <-- tesselate polyhedral sections
133  *
134  * returns:
135  * array of section translations (must be freed by caller),
136  * or NULL if section list is completely empty
137  *----------------------------------------------------------------------------*/
138 
140 fvm_writer_export_list(const fvm_nodal_t *mesh,
141  int min_export_dim,
142  bool group_by_type,
143  bool group_all,
144  bool discard_polygons,
145  bool discard_polyhedra,
146  bool divide_polygons,
147  bool divide_polyhedra);
148 
149 /*----------------------------------------------------------------------------
150  * Count number of extra vertices when tesselations are present
151  *
152  * parameters:
153  * mesh <-- pointer to nodal mesh structure
154  * divide_polyhedra <-- true if polyhedra are tesselated
155  * n_extra_vertices_g --> global number of extra vertices (optional)
156  * n_extra_vertices --> local number of extra vertices (optional)
157  *----------------------------------------------------------------------------*/
158 
159 void
160 fvm_writer_count_extra_vertices(const fvm_nodal_t *mesh,
161  bool divide_polyhedra,
162  cs_gnum_t *n_extra_vertices_g,
163  cs_lnum_t *n_extra_vertices);
164 
165 #if defined(HAVE_MPI)
166 
167 /*----------------------------------------------------------------------------
168  * Build block info and part to block distribution helper for vertices.
169  *
170  * parameters:
171  * min_rank_step <-- minimum step between output ranks
172  * min_block_size <-- minimum block buffer size
173  * n_g_add_vertices <-- global number of vertices due to tesselated polyhedra
174  * n_add_vertices <-- local number of vertices due to tesselated polyhedra
175  * mesh <-- pointer to nodal mesh structure
176  * bi --> block information structure
177  * d --> part to block distributor
178  * comm <-- associated communicator
179  *----------------------------------------------------------------------------*/
180 
181 void
182 fvm_writer_vertex_part_to_block_create(int min_rank_step,
183  cs_lnum_t min_block_size,
184  cs_gnum_t n_g_add_vertices,
185  cs_lnum_t n_add_vertices,
186  const fvm_nodal_t *mesh,
188  cs_part_to_block_t **d,
189  MPI_Comm comm);
190 
191 #endif /* defined(HAVE_MPI) */
192 
193 /*----------------------------------------------------------------------------
194  * Return extra vertex coordinates when tesselations are present
195  *
196  * parameters:
197  * mesh <-- pointer to nodal mesh structure
198  * n_extra_vertices <-- number of extra vertices
199  *
200  * returns:
201  * array containing all extra vertex coordinates
202  *----------------------------------------------------------------------------*/
203 
204 cs_coord_t *
205 fvm_writer_extra_vertex_coords(const fvm_nodal_t *mesh,
206  cs_lnum_t n_extra_vertices);
207 
208 /*----------------------------------------------------------------------------
209  * Create field writer helper structure.
210  *
211  * Local values are initialized, ang lobal values are set to zero
212  * (they may be initialized by calling fvm_writer_field_helper_init_g()).
213  *
214  * parameters:
215  * mesh <-- pointer to nodal mesh structure
216  * section_list <-- point to export section list helper structure
217  * field_dim <-- indicates output field dimension
218  * interlace <-- indicates if output is interlaced
219  * location <-- indicates if field is cell or node based
220  * datatype <-- datatype of destination buffers
221  *
222  * returns:
223  * pointer to allocated and initialized field writer helper
224  *----------------------------------------------------------------------------*/
225 
227 fvm_writer_field_helper_create(const fvm_nodal_t *mesh,
228  const fvm_writer_section_t *section_list,
229  int field_dim,
230  cs_interlace_t interlace,
231  cs_datatype_t datatype,
232  fvm_writer_var_loc_t location);
233 
234 /*----------------------------------------------------------------------------
235  * Destroy FVM field writer helper.
236  *
237  * parameters: * helper <-> pointer to pointer to structure that should be destroyed
238  *----------------------------------------------------------------------------*/
239 
240 void
242 
243 #if defined(HAVE_MPI)
244 
245 /*----------------------------------------------------------------------------
246  * Set MPI info for an fvm_writer_field_helper structure.
247  *
248  * parameters:
249  * helper <-> pointer to structure that should be initialized
250  * min_rank_step <-- minimum step between output ranks
251  * min_block_size <-- minimum block buffer size
252  * comm <-- associated MPI communicator
253  *
254  * returns:
255  * pointer to allocated and initialized field writer helper
256  *----------------------------------------------------------------------------*/
257 
258 void
259 fvm_writer_field_helper_init_g(fvm_writer_field_helper_t *helper,
260  int min_rank_step,
261  int min_block_size,
262  MPI_Comm comm);
263 
264 #endif /* defined(HAVE_MPI) */
265 
266 /*----------------------------------------------------------------------------
267  * Return sizes associated with a writer field helper.
268  *
269  * parameters:
270  * helper <-- pointer to helper structure
271  * input_size --> Total field locations in input (or NULL)
272  * output_size --> Total field locations in output (or NULL)
273  * min_output_buffer_size --> Minimum required buffer size (or NULL)
274  *----------------------------------------------------------------------------*/
275 
276 void
278  size_t *input_size,
279  size_t *output_size,
280  size_t *min_output_buffer_size);
281 
282 /*----------------------------------------------------------------------------
283  * Return the output dimension associated with a writer field helper.
284  *
285  * parameters:
286  * helper <-- pointer to helper structure
287  *
288  * returns:
289  * field dimension associated with helper
290  *----------------------------------------------------------------------------*/
291 
292 int
294 
295 /*----------------------------------------------------------------------------
296  * Return the output datatype associated with a writer field helper.
297  *
298  * parameters:
299  * helper <-- pointer to helper structure
300  *
301  * returns:
302  * output datatype associated with helper
303  *----------------------------------------------------------------------------*/
304 
307 
308 /*----------------------------------------------------------------------------
309  * Partially distribute field values to a local output buffer.
310  *
311  * parameters:
312  * helper <-> pointer to helper structure
313  * export_section <-- pointer to section helper structure
314  * src_dim <-- dimension of source data
315  * src_dim_shift <-- source data dimension shift (start index)
316  * src_interlace <-- indicates if field in memory is interlaced
317  * n_parent_lists <-- indicates if field values are to be obtained
318  * directly through the local entity index (when 0) or
319  * through the parent entity numbers (when 1 or more)
320  * parent_num_shift <-- parent list to common number index shifts;
321  * size: n_parent_lists
322  * datatype <-- indicates the data type of (source) field values
323  * field_values <-- array of associated field value arrays
324  * datatype <-- input data type
325  * field_values <-- pointer to input array
326  * output_buffer <-- pointer to output buffer
327  * (working array only for ranks > 0)
328  * output_buffer_size <-- size of output buffer (in datatype units)
329  * output_size --> size of output upon return (in datatype units)
330  *
331  * returns:
332  * 0 if values were distributed to the output buffer, 1 if the end of the
333  * section has already been reached and no values were left to distribute.
334  *----------------------------------------------------------------------------*/
335 
336 int
338  const fvm_writer_section_t *export_section,
339  int src_dim,
340  int src_dim_shift,
341  cs_interlace_t src_interlace,
342  int n_parent_lists,
343  const cs_lnum_t parent_num_shift[],
344  cs_datatype_t datatype,
345  const void *const field_values[],
346  void *output_buffer,
347  size_t output_buffer_size,
348  size_t *output_size);
349 
350 /*----------------------------------------------------------------------------
351  * Partially distribute per node field values to a local output buffer.
352  *
353  * parameters:
354  * helper <-> pointer to helper structure
355  * mesh <-- pointer to associated mesh
356  * src_dim <-- dimension of source data
357  * src_dim_shift <-- source data dimension shift (start index)
358  * src_interlace <-- indicates if field in memory is interlaced
359  * n_parent_lists <-- indicates if field values are to be obtained
360  * directly through the local entity index (when 0) or
361  * through the parent entity numbers (when 1 or more)
362  * parent_num_shift <-- parent list to common number index shifts;
363  * size: n_parent_lists
364  * datatype <-- indicates the data type of (source) field values
365  * field_values <-- array of associated field value arrays
366  * datatype <-- input data type
367  * field_values <-- pointer to input array
368  * output_buffer <-- pointer to output buffer
369  * (working array only for ranks > 0)
370  * output_buffer_size <-- size of output buffer (in datatype units)
371  * output_size --> size of output upon return (in datatype units)
372  *
373  * returns:
374  * 0 if values were distributed to the output buffer, 1 if the end of the
375  * section has already been reached and no values were left to distribute.
376  *----------------------------------------------------------------------------*/
377 
378 int
380  const fvm_nodal_t *mesh,
381  int src_dim,
382  int src_dim_shift,
383  cs_interlace_t src_interlace,
384  int n_parent_lists,
385  const cs_lnum_t parent_num_shift[],
386  cs_datatype_t datatype,
387  const void *const field_values[],
388  void *output_buffer,
389  size_t output_buffer_size,
390  size_t *output_size);
391 
392 /*----------------------------------------------------------------------------
393  * Output per element field values, using writer-specific function
394  * and context structure pointers.
395  *
396  * Note that if the output data is not interleaved, for multidimensional data,
397  * the output function is called once per component, using the same buffer.
398  * This is a good fit for most options, but if a format requires writing
399  * additional buffering may be required in the context.
400  *
401  * parameters:
402  * helper <-> pointer to helper structure
403  * context <-> pointer to writer context
404  * export_section <-- pointer to section helper structure
405  * src_dim <-- dimension of source data
406  * src_interlace <-- indicates if field in memory is interlaced
407  * comp_order <-- field component reordering array, or NULL
408  * n_parent_lists <-- indicates if field values are to be obtained
409  * directly through the local entity index (when 0) or
410  * through the parent entity numbers (when 1 or more)
411  * parent_num_shift <-- parent list to common number index shifts;
412  * size: n_parent_lists
413  * datatype <-- indicates the data type of (source) field values
414  * field_values <-- array of associated field value arrays
415  * output_func <-- pointer to output function
416  *
417  * returns:
418  * pointer to next section helper structure in list
419  *----------------------------------------------------------------------------*/
420 
421 const fvm_writer_section_t *
423  void *context,
424  const fvm_writer_section_t *export_section,
425  int src_dim,
426  cs_interlace_t src_interlace,
427  const int *comp_order,
428  int n_parent_lists,
429  const cs_lnum_t parent_num_shift[],
430  cs_datatype_t datatype,
431  const void *const field_values[],
432  fvm_writer_field_output_t *output_func);
433 
434 /*----------------------------------------------------------------------------
435  * Output per node field values, using writer-specific function
436  * and context structure pointers.
437  *
438  * Note that if the output data is not interleaved, for multidimensional data,
439  * the output function is called once per component, using the same buffer.
440  * This is a good fit for most options, but if a format requires writing
441  * additional buffering may be required in the context.
442  *
443  * parameters:
444  * helper <-> pointer to helper structure
445  * context <-> pointer to writer context
446  * mesh <-- pointer to nodal mesh
447  * divide_polyhedra <-- tesselate polyhedral sections
448  * src_dim <-- dimension of source data
449  * src_dim_shift <-- source data dimension shift (start index)
450  * src_interlace <-- indicates if field in memory is interlaced
451  * n_parent_lists <-- indicates if field values are to be obtained
452  * directly through the local entity index (when 0) or
453  * through the parent entity numbers (when 1 or more)
454  * parent_num_shift <-- parent list to common number index shifts;
455  * size: n_parent_lists
456  * datatype <-- indicates the data type of (source) field values
457  * field_values <-- array of associated field value arrays
458  * datatype <-- input data type
459  * field_values <-- pointer to input array
460  * output_func <-- pointer to output function
461  *----------------------------------------------------------------------------*/
462 
463 void
465  void *context,
466  const fvm_nodal_t *mesh,
467  int src_dim,
468  cs_interlace_t src_interlace,
469  const int *comp_order,
470  int n_parent_lists,
471  const cs_lnum_t parent_num_shift[],
472  cs_datatype_t datatype,
473  const void *const field_values[],
474  fvm_writer_field_output_t *output_func);
475 
476 /*----------------------------------------------------------------------------
477  * Set string representing a field component's name based on its id.
478  *
479  * parameters:
480  * s --> destination string
481  * s_size <-- maximum string size
482  * lowercase <-- true if lowercase is required
483  * dimension <-- field dimension
484  * component_id <-- field component id
485  *----------------------------------------------------------------------------*/
486 
487 void
489  size_t s_size,
490  bool lowercase,
491  int dimension,
492  int component_id);
493 
494 /*----------------------------------------------------------------------------*/
495 
497 
498 #endif /* __FVM_WRITER_HELPER_H__ */
fvm_writer_var_loc_t
fvm_writer_var_loc_t
Definition: fvm_writer.h:69
cs_defs.h
fvm_writer_field_helper_step_nl
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)
fvm_writer_section_t::next
struct _fvm_writer_section_t * next
Definition: fvm_writer_helper.h:60
fvm_writer_field_helper_field_dim
int fvm_writer_field_helper_field_dim(const fvm_writer_field_helper_t *helper)
fvm_writer_field_output_t
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_writer_section_t::section
const fvm_nodal_section_t * section
Definition: fvm_writer_helper.h:63
fvm_writer_section_t::num_shift
cs_lnum_t num_shift
Definition: fvm_writer_helper.h:68
fvm_writer_export_list
fvm_writer_section_t * fvm_writer_export_list(const fvm_nodal_t *mesh, int min_export_dim, bool group_by_type, bool group_all, bool discard_polygons, bool discard_polyhedra, bool divide_polygons, bool divide_polyhedra)
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
fvm_writer_field_helper_datatype
cs_datatype_t fvm_writer_field_helper_datatype(const fvm_writer_field_helper_t *helper)
fvm_writer_field_helper_step_el
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)
cs_part_to_block_t
struct _cs_part_to_block_t cs_part_to_block_t
Definition: cs_part_to_block.h:57
fvm_writer.h
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_part_to_block.h
fvm_writer_section_t
Definition: fvm_writer_helper.h:58
fvm_writer_extra_vertex_coords
cs_coord_t * fvm_writer_extra_vertex_coords(const fvm_nodal_t *mesh, cs_lnum_t n_extra_vertices)
mesh
Definition: mesh.f90:26
fvm_writer_section_t::type
fvm_element_t type
Definition: fvm_writer_helper.h:70
cs_datatype_t
cs_datatype_t
Definition: cs_defs.h:260
cs_block_dist_info_t
Definition: cs_block_dist.h:50
fvm_element_t
fvm_element_t
Definition: fvm_defs.h:48
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_interlace_t
cs_interlace_t
Definition: cs_defs.h:439
fvm_writer_field_helper_create
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_writer_count_extra_vertices
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)
fvm_writer_field_helper_output_e
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_field_helper_destroy
void fvm_writer_field_helper_destroy(fvm_writer_field_helper_t **helper)
fvm_writer_field_helper_get_size
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)
fvm_nodal.h
fvm_nodal_section_t
Definition: fvm_nodal_priv.h:58
fvm_writer_field_helper_t
struct _fvm_writer_field_helper_t fvm_writer_field_helper_t
Definition: fvm_writer_helper.h:89
cs_coord_t
double cs_coord_t
Definition: cs_defs.h:299
fvm_defs.h
fvm_writer_field_helper_output_n
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_field_component_name
void fvm_writer_field_component_name(char *s, size_t s_size, bool lowercase, int dimension, int component_id)
fvm_writer_section_t::continues_previous
bool continues_previous
Definition: fvm_writer_helper.h:74
fvm_writer_section_t::extra_vertex_base
cs_gnum_t extra_vertex_base
Definition: fvm_writer_helper.h:65
cs_block_dist.h