Code_Saturne
CFD tool
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-2012 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 #if defined(HAVE_MPI )
31 #include <mpi.h>
32 #endif
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 #include "fvm_defs.h"
39 #include "fvm_gather.h"
40 #include "fvm_nodal.h"
41 #include "fvm_writer.h"
42 
43 /*----------------------------------------------------------------------------*/
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #if 0
48 } /* Fake brace to force back Emacs auto-indentation back to column 0 */
49 #endif
50 #endif /* __cplusplus */
51 
52 /*=============================================================================
53  * Macro definitions
54  *============================================================================*/
55 
56 /*============================================================================
57  * Type definitions
58  *============================================================================*/
59 
60 /*----------------------------------------------------------------------------
61  * FVM nodal to writer section translation list
62  *----------------------------------------------------------------------------*/
63 
64 typedef struct _fvm_writer_section_t {
65 
66  struct _fvm_writer_section_t *next; /* Pointer to next element
67  in list (NULL at end) */
68 
69  const fvm_nodal_section_t *section; /* Corresponding section in mesh */
70 
71  cs_gnum_t extra_vertex_base; /* Start global number of added
72  vertices (for tesselation) */
73 
74  cs_lnum_t num_shift; /* Element number shift when no
75  parent lists are used */
76  fvm_element_t type; /* Corresponding element type (may
77  differ from section->type when
78  using tesselations) */
79 
80  _Bool continues_previous; /* Indicates if the corresponding FVM
81  nodal section should be appended
82  to the previous one on output */
83 
85 
86 /*----------------------------------------------------------------------------
87  * FVM nodal to writer field output helper
88  *----------------------------------------------------------------------------*/
89 
90 /*
91  Pointer to structure keeping track of the status of a writer's field
92  output state. The structure itself is private, and is defined in fvm_writer.c
93 */
94 
96 
97 /*=============================================================================
98  * Semi-private function prototypes
99  *============================================================================*/
100 
101 /*----------------------------------------------------------------------------
102  * Build list of sections to output
103  *
104  * Depending on whether multiple sections of a given element type
105  * are allowed or not, sections may be ordered in different ways.
106  * Discarded element types are not added to the list.
107  *
108  * parameters:
109  * mesh <-- pointer to nodal mesh structure
110  * group_same_type <-- group sections of the same type
111  * min_export_dim <-- minimum dimension of sections to export
112  * discard_polygons <-- ignore polygonal sections
113  * discard_polyhedra <-- ignore polyhedral sections
114  * divide_polygons <-- tesselate polygonal sections
115  * divide_polyhedra <-- tesselate polyhedral sections
116  *
117  * returns:
118  * array of section translations (must be freed by caller),
119  * or NULL if section list is completely empty
120  *----------------------------------------------------------------------------*/
121 
124  int min_export_dim,
125  _Bool group_same_type,
126  _Bool discard_polygons,
127  _Bool discard_polyhedra,
128  _Bool divide_polygons,
129  _Bool divide_polyhedra);
130 
131 /*----------------------------------------------------------------------------
132  * Create field writer helper structure.
133  *
134  * Local values are initialized, ang lobal values are set to zero
135  * (they may be initialized by calling fvm_writer_field_helper_init_g()).
136  *
137  * parameters:
138  * mesh <-- pointer to nodal mesh structure
139  * section_list <-- point to export section list helper structure
140  * field_dim <-- indicates output field dimension
141  * interlace <-- indicates if output is interlaced
142  * location <-- indicates if field is cell or node based
143  * datatype <-- datatype of destination buffers
144  *
145  * returns:
146  * pointer to allocated and initialized field writer helper
147  *----------------------------------------------------------------------------*/
148 
151  const fvm_writer_section_t *section_list,
152  int field_dim,
156 
157 /*----------------------------------------------------------------------------
158  * Destroy FVM field writer helper.
159  *
160  * parameters:
161  * helper <-> pointer to structure that should be destroyed
162  *
163  * returns:
164  * NULL pointer
165  *----------------------------------------------------------------------------*/
166 
169 
170 #if defined(HAVE_MPI)
171 
172 /*----------------------------------------------------------------------------
173  * Initialize global values for an fvm_writer_field_helper structure.
174  *
175  * Internal buffers for gathering of data to rank 0 of the given
176  * communicator are also allocated.
177  *
178  * parameters:
179  * helper <-> pointer to structure that should be initialized
180  * section_list <-- point to export section list helper structure
181  * mesh <-- pointer to nodal mesh structure
182  * comm <-- associated MPI communicator
183  *
184  * returns:
185  * pointer to allocated and initialized field writer helper
186  *----------------------------------------------------------------------------*/
187 
188 void
189 fvm_writer_field_helper_init_g(fvm_writer_field_helper_t *helper,
190  const fvm_writer_section_t *section_list,
191  const fvm_nodal_t *mesh,
192  MPI_Comm comm);
193 
194 #endif /* defined(HAVE_MPI) */
195 
196 /*----------------------------------------------------------------------------
197  * Return sizes associated with a writer field helper.
198  *
199  * parameters:
200  * helper <-- pointer to helper structure
201  * input_size --> Total field locations in input (or NULL)
202  * output_size --> Total field locations in output (or NULL)
203  * max_grouped_elements_out --> Max. field locations in a single group
204  * (elements of a given type if sections are
205  * grouped, elements of a given section
206  * otherwise; NULL if unused)
207  * min_output_buffer_size --> Minimum required buffer size (or NULL)
208  *----------------------------------------------------------------------------*/
209 
210 void
212  size_t *input_size,
213  size_t *output_size,
214  size_t *max_grouped_elements_out,
215  size_t *min_output_buffer_size);
216 
217 /*----------------------------------------------------------------------------
218  * Return the output dimension associated with a writer field helper.
219  *
220  * parameters:
221  * helper <-- pointer to helper structure
222  *
223  * returns:
224  * field dimension associated with helper
225  *----------------------------------------------------------------------------*/
226 
227 int
229 
230 /*----------------------------------------------------------------------------
231  * Return the output datatype associated with a writer field helper.
232  *
233  * parameters:
234  * helper <-- pointer to helper structure
235  *
236  * returns:
237  * output datatype associated with helper
238  *----------------------------------------------------------------------------*/
239 
242 
243 /*----------------------------------------------------------------------------
244  * Partially distribute field values to an output buffer.
245  *
246  * parameters:
247  * helper <-> pointer to helper structure
248  * export_section <-- pointer to section helper structure
249  * src_dim <-- dimension of source data
250  * src_dim_shift <-- source data dimension shift (start index)
251  * src_interlace <-- indicates if field in memory is interlaced
252  * n_parent_lists <-- indicates if field values are to be obtained
253  * directly through the local entity index (when 0) or
254  * through the parent entity numbers (when 1 or more)
255  * parent_num_shift <-- parent list to common number index shifts;
256  * size: n_parent_lists
257  * datatype <-- indicates the data type of (source) field values
258  * field_values <-- array of associated field value arrays
259  * datatype <-- input data type
260  * field_values <-- pointer to input array
261  * output_buffer <-- pointer to output buffer
262  * (working array only for ranks > 0)
263  * output_buffer_size <-- size of output buffer (in datatype units)
264  * output_size --> size of output upon return (in datatype units)
265  *
266  * returns:
267  * 0 if values were distributed to the output buffer, 1 if the end of the
268  * section has already been reached and no values were left to distribute.
269  *----------------------------------------------------------------------------*/
270 
271 int
273  const fvm_writer_section_t *export_section,
274  int src_dim,
275  int src_dim_shift,
276  cs_interlace_t src_interlace,
277  int n_parent_lists,
278  const cs_lnum_t parent_num_shift[],
280  const void *const field_values[],
281  void *output_buffer,
282  size_t output_buffer_size,
283  size_t *output_size);
284 
285 /*----------------------------------------------------------------------------
286  * Partially distribute per node field values to an output buffer.
287  *
288  * parameters:
289  * helper <-> pointer to helper structure
290  * mesh <-- pointer to associated mesh
291  * src_dim <-- dimension of source data
292  * src_dim_shift <-- source data dimension shift (start index)
293  * src_interlace <-- indicates if field in memory is interlaced
294  * n_parent_lists <-- indicates if field values are to be obtained
295  * directly through the local entity index (when 0) or
296  * through the parent entity numbers (when 1 or more)
297  * parent_num_shift <-- parent list to common number index shifts;
298  * size: n_parent_lists
299  * datatype <-- indicates the data type of (source) field values
300  * field_values <-- array of associated field value arrays
301  * datatype <-- input data type
302  * field_values <-- pointer to input array
303  * output_buffer <-- pointer to output buffer
304  * (working array only for ranks > 0)
305  * output_buffer_size <-- size of output buffer (in datatype units)
306  * output_size --> size of output upon return (in datatype units)
307  *
308  * returns:
309  * 0 if values were distributed to the output buffer, 1 if the end of the
310  * section has already been reached and no values were left to distribute.
311  *----------------------------------------------------------------------------*/
312 
313 int
315  const fvm_nodal_t *mesh,
316  int src_dim,
317  int src_dim_shift,
318  cs_interlace_t src_interlace,
319  int n_parent_lists,
320  const cs_lnum_t parent_num_shift[],
322  const void *const field_values[],
323  void *output_buffer,
324  size_t output_buffer_size,
325  size_t *output_size);
326 
327 /*----------------------------------------------------------------------------*/
328 
329 #ifdef __cplusplus
330 }
331 #endif /* __cplusplus */
332 
333 #endif /* __FVM_WRITER_HELPER_H__ */
int fvm_writer_field_helper_step_n(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)
Definition: fvm_writer_helper.c:2016
cs_datatype_t
Definition: cs_defs.h:223
fvm_writer_var_loc_t location
Definition: fvm_writer_helper.c:92
fvm_writer_var_loc_t
Definition: fvm_writer.h:70
struct _fvm_writer_section_t * next
Definition: fvm_writer_helper.h:66
cs_interlace_t
Definition: cs_defs.h:347
Definition: fvm_nodal_priv.h:152
fvm_element_t
Definition: fvm_defs.h:49
fvm_writer_section_t * fvm_writer_export_list(const fvm_nodal_t *mesh, int min_export_dim, _Bool group_same_type, _Bool discard_polygons, _Bool discard_polyhedra, _Bool divide_polygons, _Bool divide_polyhedra)
Definition: fvm_writer_helper.c:1196
int cs_lnum_t
Definition: cs_defs.h:260
fvm_writer_field_helper_t * fvm_writer_field_helper_destroy(fvm_writer_field_helper_t *helper)
Definition: fvm_writer_helper.c:1581
cs_interlace_t interlace
Definition: fvm_writer_helper.c:90
int field_dim
Definition: fvm_writer_helper.c:89
unsigned cs_gnum_t
Definition: cs_defs.h:255
Definition: fvm_nodal_priv.h:60
cs_lnum_t num_shift
Definition: fvm_writer_helper.h:74
void fvm_writer_field_helper_get_size(const fvm_writer_field_helper_t *helper, size_t *input_size, size_t *output_size, size_t *max_grouped_elements_out, size_t *min_output_buffer_size)
Definition: fvm_writer_helper.c:1820
cs_gnum_t output_size
Definition: fvm_writer_helper.c:96
Definition: fvm_writer_helper.c:87
struct _fvm_writer_section_t fvm_writer_section_t
Definition: fvm_writer_helper.h:64
cs_datatype_t datatype
Definition: fvm_writer_helper.c:91
int fvm_writer_field_helper_step_e(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)
Definition: fvm_writer_helper.c:1937
_Bool continues_previous
Definition: fvm_writer_helper.h:80
cs_gnum_t input_size
Definition: fvm_writer_helper.c:94
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)
Definition: fvm_writer_helper.c:1365
cs_lnum_t max_grouped_elements_out
Definition: fvm_writer_helper.c:108
const fvm_nodal_section_t * section
Definition: fvm_writer_helper.h:69
cs_gnum_t extra_vertex_base
Definition: fvm_writer_helper.h:71
#define _Bool
Definition: cs_defs.h:154
int fvm_writer_field_helper_field_dim(const fvm_writer_field_helper_t *helper)
Definition: fvm_writer_helper.c:1887
Definition: mesh.f90:25
fvm_element_t type
Definition: fvm_writer_helper.h:76
cs_datatype_t fvm_writer_field_helper_datatype(const fvm_writer_field_helper_t *helper)
Definition: fvm_writer_helper.c:1903