programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cs_mesh.h
Go to the documentation of this file.
1 #ifndef __CS_MESH_H__
2 #define __CS_MESH_H__
3 
4 /*============================================================================
5  * Main structure associated to a mesh
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2013 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 #include "fvm_group.h"
37 #include "fvm_selector.h"
38 #include "fvm_periodicity.h"
39 
40 #include "cs_base.h"
41 #include "cs_halo.h"
42 #include "cs_interface.h"
43 #include "cs_numbering.h"
44 
45 #include "cs_mesh_builder.h"
46 
47 /*----------------------------------------------------------------------------*/
48 
50 
51 /*=============================================================================
52  * Macro definitions
53  *============================================================================*/
54 
55 /*============================================================================
56  * Type definitions
57  *============================================================================*/
58 
59 /* Mesh structure definition */
60 /* ------------------------- */
61 
62 typedef struct {
63 
64  /* General features */
65 
66  cs_lnum_t dim; /* Space dimension */
67  cs_lnum_t domain_num; /* Local domain number */
68  cs_lnum_t n_domains; /* Number of domains */
69 
70 
71  /* Local dimensions */
72 
73  cs_lnum_t n_cells; /* Number of cells */
74  cs_lnum_t n_i_faces; /* Number of interior faces */
75  cs_lnum_t n_b_faces; /* Number of boundary faces */
76  cs_lnum_t n_vertices; /* Number of vertices */
77 
78  cs_lnum_t i_face_vtx_connect_size; /* Size of the connectivity
79  interior faces -> vertices */
80  cs_lnum_t b_face_vtx_connect_size; /* Size of the connectivity
81  boundary faces -> vertices */
82 
83  /* Local structures */
84 
85  cs_real_t *vtx_coord; /* Vertex coordinates */
86 
87  cs_lnum_t *i_face_cells; /* Interior faces -> cells connectivity */
88  cs_lnum_t *b_face_cells; /* Boundary faces -> cells connectivity */
89 
90  cs_lnum_t *i_face_vtx_idx; /* Interior faces -> vertices index */
91  cs_lnum_t *i_face_vtx_lst; /* Interior faces -> vertices connectivity */
92 
93  cs_lnum_t *b_face_vtx_idx; /* Boundary faces -> vertices index */
94  cs_lnum_t *b_face_vtx_lst; /* Boundary faces -> vertices connectivity */
95 
96  /* Global dimension */
97 
98  cs_gnum_t n_g_cells; /* Global number of cells */
99  cs_gnum_t n_g_i_faces; /* Global number of interior faces */
100  cs_gnum_t n_g_b_faces; /* Global number of boundary faces */
101  cs_gnum_t n_g_vertices; /* Global number of vertices */
102 
103  /* Global numbering */
104 
105  cs_gnum_t *global_cell_num; /* Global cell numbering */
106  cs_gnum_t *global_i_face_num; /* Global interior face numbering */
107  cs_gnum_t *global_b_face_num; /* Global boundary face numbering */
108  cs_gnum_t *global_vtx_num; /* Global vertex numbering */
109 
110  /* Periodictity features */
111 
112  int n_init_perio; /* Number of initial periodicities */
113  int n_transforms; /* Number of transformations */
114 
115  int have_rotation_perio; /* Periodicity rotation indicator */
116 
117  fvm_periodicity_t *periodicity; /* parameters of each periodicity */
118 
119  /* Parallelism and/or periodic features */
120 
121  cs_halo_type_t halo_type; /* Halo type */
122 
123  cs_lnum_t n_cells_with_ghosts; /* Total number of cells on the local rank
124  (n_cells + n_ghost_cells) */
125  cs_lnum_t n_ghost_cells; /* Number of "ghost" cells */
126 
127  cs_interface_set_t *vtx_interfaces; /* Vertices interface set */
128  cs_halo_t *halo; /* Ghost cells structure */
129 
130  cs_numbering_t *i_face_numbering; /* Interior face numbering info */
131  cs_numbering_t *b_face_numbering; /* Boundary face numbering info */
132 
133  /* Re-computable connectivity features */
134 
135  cs_lnum_t n_b_cells; /* Number of boundary cells */
136  cs_lnum_t *b_cells; /* Boundary cell list */
137 
138  /* Extended neighborhood features */
139 
140  cs_lnum_t *cell_cells_idx; /* "cell -> cells" connectivity index for
141  extended halo. Only defined if extended
142  neighborhood is built. */
143  cs_lnum_t *cell_cells_lst; /* "cell -> cells" connectivity list for
144  extended halo. Only defined if extended
145  neighborhood is built. */
146 
147  cs_lnum_t *gcell_vtx_idx; /* ghost cells -> vertices index */
148  cs_lnum_t *gcell_vtx_lst; /* ghost cells -> vertices list */
149 
150  /* Group and family features */
151 
152  cs_lnum_t n_groups; /* Number of groups */
153  cs_lnum_t *group_idx; /* Starting index in the in group_lst */
154  char *group_lst; /* List of group names */
155 
156  cs_lnum_t n_families; /* Number of families */
157  cs_lnum_t n_max_family_items; /* Max. number of items for one family */
158  cs_lnum_t *family_item; /* Family items */
159  cs_lnum_t *cell_family; /* Cell family */
160  cs_lnum_t *i_face_family; /* Interior face family */
161  cs_lnum_t *b_face_family; /* Boundary face family */
162 
163  fvm_group_class_set_t *class_defs; /* Definition of group classes for
164  selection and postprocessing (built
165  from element families and their
166  descriptions) */
167  fvm_selector_t *select_cells; /* Cells selection object */
168  fvm_selector_t *select_i_faces; /* Interior faces selection object */
169  fvm_selector_t *select_b_faces; /* Boundary faces selection object */
170 
171  /* Status flags */
172 
173  cs_gnum_t n_g_free_faces; /* Global number of boundary faces
174  which are in fact isolated */
175  int verbosity; /* Current verbosity level */
176  int modified; /* Modification status */
177 
178 } cs_mesh_t;
179 
180 /*============================================================================
181  * Static global variables
182  *============================================================================*/
183 
184 extern cs_mesh_t *cs_glob_mesh; /* Pointer to main mesh structure */
185 
186 /*============================================================================
187  * Public function prototypes for Fortran API
188  *============================================================================*/
189 
190 /*----------------------------------------------------------------------------
191  * Update a scalar array in case of parallelism and/or periodicity.
192  *
193  * Fortran interface:
194  *
195  * subroutine synsca(var)
196  * *****************
197  *
198  * var : <-> : scalar array
199  *----------------------------------------------------------------------------*/
200 
201 void CS_PROCF(synsca, SYNSCA)
202 (
203  cs_real_t var[]
204 );
205 
206 /*----------------------------------------------------------------------------
207  * Update a scalar array in case of parallelism and/or periodicity,
208  * using an extended halo.
209  *
210  * Fortran interface:
211  *
212  * subroutine synsce(var)
213  * *****************
214  *
215  * var : <-> : scalar array
216  *----------------------------------------------------------------------------*/
217 
218 void CS_PROCF(synsce, SYNSCE)
219 (
220  cs_real_t var[]
221 );
222 
223 /*----------------------------------------------------------------------------
224  * Update a scalar array in case of parallelism and/or periodicity,
225  * ignoring periodicity of rotation
226  *
227  * Fortran interface:
228  *
229  * subroutine syncmp(var)
230  * *****************
231  *
232  * var : <-> : scalar array
233  *----------------------------------------------------------------------------*/
234 
235 void CS_PROCF(syncmp, SYNCMP)
236 (
237  cs_real_t var[]
238 );
239 
240 /*----------------------------------------------------------------------------
241  * Update a vector array in case of parallelism and/or periodicity.
242  *
243  * Fortran interface:
244  *
245  * subroutine synvec(var)
246  * *****************
247  *
248  * var1 : <-> : vector component 1 array
249  * var2 : <-> : vector component 2 array
250  * var3 : <-> : vector component 3 array
251  *----------------------------------------------------------------------------*/
252 
253 void CS_PROCF(synvec, SYNVEC)
254 (
255  cs_real_t var1[],
256  cs_real_t var2[],
257  cs_real_t var3[]
258 );
259 
260 /*----------------------------------------------------------------------------
261  * Update a vector array in case of parallelism and/or periodicity.
262  *
263  * Fortran interface:
264  *
265  * subroutine synvin(var)
266  * *****************
267  *
268  * var : <-> : interleaved vector (of dimension 3)
269  *----------------------------------------------------------------------------*/
270 
271 void CS_PROCF(synvin, SYNVIN)
272 (
273  cs_real_t var[]
274 );
275 
276 /*----------------------------------------------------------------------------
277  * Update a vector array in case of parallelism and/or periodicity,
278  * ignoring periodicity of rotation.
279  *
280  * Fortran interface:
281  *
282  * subroutine synvnr(var)
283  * *****************
284  *
285  * var : <-> : interleaved vector (of dimension 3)
286  *----------------------------------------------------------------------------*/
287 
288 void
289 CS_PROCF (synvnr, SYNVNR)
290 (
291  cs_real_t var[]
292 );
293 
294 /*----------------------------------------------------------------------------
295  * Update a diagonal tensor array in case of parallelism and/or periodicity.
296  *
297  * Fortran interface:
298  *
299  * subroutine syndia(var)
300  * *****************
301  *
302  * var11 : <-> : diagonal tensor component 11 array
303  * var22 : <-> : diagonal tensor component 22 array
304  * var33 : <-> : diagonal tensor component 33 array
305  *----------------------------------------------------------------------------*/
306 
307 void CS_PROCF(syndia, SYNDIA)
308 (
309  cs_real_t var11[],
310  cs_real_t var22[],
311  cs_real_t var33[]
312 );
313 
314 /*----------------------------------------------------------------------------
315  * Update a diagonal tensor array in case of parallelism and/or periodicity.
316  *
317  * Fortran interface:
318  *
319  * subroutine syndin(var)
320  * *****************
321  *
322  * var : <-> : interleaved diagonal tensor (of dimension 3)
323  *----------------------------------------------------------------------------*/
324 
325 void CS_PROCF(syndin, SYNDIN)
326 (
327  cs_real_t var[]
328 );
329 
330 /*----------------------------------------------------------------------------
331  * Update a tensor array in case of parallelism and/or periodicity.
332  *
333  * Fortran interface:
334  *
335  * subroutine synten(var)
336  * *****************
337  *
338  * var11 : <-> : tensor component 11 array
339  * var12 : <-> : tensor component 12 array
340  * var13 : <-> : tensor component 13 array
341  * var21 : <-> : tensor component 21 array
342  * var22 : <-> : tensor component 22 array
343  * var23 : <-> : tensor component 23 array
344  * var31 : <-> : tensor component 31 array
345  * var32 : <-> : tensor component 32 array
346  * var33 : <-> : tensor component 33 array
347  *----------------------------------------------------------------------------*/
348 
349 void CS_PROCF(synten, SYNTEN)
350 (
351  cs_real_t var11[],
352  cs_real_t var12[],
353  cs_real_t var13[],
354  cs_real_t var21[],
355  cs_real_t var22[],
356  cs_real_t var23[],
357  cs_real_t var31[],
358  cs_real_t var32[],
359  cs_real_t var33[]
360 );
361 
362 /*----------------------------------------------------------------------------
363  * Update a tensor array in case of parallelism and/or periodicity.
364  *
365  * Fortran interface:
366  *
367  * subroutine syntin(var)
368  * *****************
369  *
370  * var : <-> : interleaved tensor (of dimension 3x3)
371  *----------------------------------------------------------------------------*/
372 
373 void CS_PROCF(syntin, SYNTIN)
374 (
375  cs_real_t var[]
376 );
377 
378 /*----------------------------------------------------------------------------
379  * Update a symmetric tensor array in case of parallelism and/or periodicity.
380  *
381  * Fortran interface:
382  *
383  * subroutine syntis(var)
384  * *****************
385  *
386  * var : <-> : interleaved symmetric tensor (of dimension 6)
387  *----------------------------------------------------------------------------*/
388 
389 void CS_PROCF(syntis, SYNTIS)
390 (
391  cs_real_t var[]
392 );
393 
394 /*=============================================================================
395  * Public function prototypes
396  *============================================================================*/
397 
398 /*----------------------------------------------------------------------------
399  * Create an empty mesh structure
400  *
401  * returns:
402  * pointer to created mesh structure
403  *----------------------------------------------------------------------------*/
404 
405 cs_mesh_t *
406 cs_mesh_create(void);
407 
408 /*----------------------------------------------------------------------------
409  * Destroy a mesh structure
410  *
411  * mesh <-> pointer to a mesh structure
412  *
413  * returns:
414  * NULL pointer
415  *----------------------------------------------------------------------------*/
416 
417 cs_mesh_t *
419 
420 /*----------------------------------------------------------------------------
421  * Remove arrays and structures that mey be rebuilt.
422  *
423  * mesh <-> pointer to a mesh structure
424  * free_halos <-- if true, free halos and parallel/periodic interface
425  * structures
426  *----------------------------------------------------------------------------*/
427 
428 void
430  bool free_halos);
431 
432 /*----------------------------------------------------------------------------
433  * Discard free (isolated) faces from a mesh.
434  *
435  * This should always be done before using the mesh for computation.
436  *
437  * parameters:
438  * mesh <-> pointer to mesh structure
439  *----------------------------------------------------------------------------*/
440 
441 void
443 
444 /*----------------------------------------------------------------------------
445  * Compute or update mesh structure members the depend on other members,
446  * but whose results may be reused, such as global number of elements
447  * (cells, vertices, interior and boundary faces) and sync cell family.
448  *
449  * parameters:
450  * mesh <-> pointer to a cs_mesh_t structure
451  *----------------------------------------------------------------------------*/
452 
453 void
455 
456 /*----------------------------------------------------------------------------
457  * Creation and initialization of mesh face and vertex interfaces.
458  *
459  * parameters:
460  * mesh <-> pointer to mesh structure
461  * mb <-> pointer to mesh builder (in case of periodicity)
462  *----------------------------------------------------------------------------*/
463 
464 void
466  cs_mesh_builder_t *mb);
467 
468 /*----------------------------------------------------------------------------
469  * Creation and initialization of halo structures.
470  *
471  * Treatment of parallel and/or periodic halos for standard and extended
472  * ghost cells according to halo type requested by global options.
473  *
474  * parameters:
475  * mesh <-> pointer to mesh structure
476  * mb <-> pointer to mesh builder (in case of periodicity)
477  * halo_type <-> type of halo (standard or extended)
478  *----------------------------------------------------------------------------*/
479 
480 void
482  cs_mesh_builder_t *mb,
483  cs_halo_type_t halo_type);
484 
485 /*----------------------------------------------------------------------------
486  * Get the global number of ghost cells.
487  *
488  * parameters:
489  * mesh <-- pointer to a mesh structure
490  *
491  * returns:
492  * Global number of ghost cells
493  *---------------------------------------------------------------------------*/
494 
495 cs_int_t
497 
498 /*----------------------------------------------------------------------------
499  * Update a scalar array in case of parallelism and/or periodicity.
500  *
501  * Note: this function is only present so that a C equivalent to the
502  * Fortran wrappers is available. In C code, directly using
503  * cs_halo_sync_var() is preferred.
504  *
505  * parameters:
506  * var <-> scalar array
507  *----------------------------------------------------------------------------*/
508 
509 void
511 
512 /*----------------------------------------------------------------------------
513  * Update a scalar array in case of parallelism and/or periodicity,
514  * using an extended halo.
515  *
516  * Note: this function is only present so that a C equivalent to the
517  * Fortran wrappers is available. In C code, directly using the
518  * cs_halo_sync_var() is preferred.
519  *
520  * parameters:
521  * var <-> scalar array
522  *----------------------------------------------------------------------------*/
523 
524 void
526 
527 /*----------------------------------------------------------------------------
528  * Update a component of a vector for parallelism and/or periodicity,
529  * ignoring periodicity of rotation.
530  *
531  * Note: this function is only present so that a C equivalent to the
532  * Fortran wrappers is available. In C code, directly using the
533  * cs_halo_sync_var() is preferred.
534  *
535  * parameters:
536  * var <-> scalar array
537  *----------------------------------------------------------------------------*/
538 
539 void
541 
542 /*----------------------------------------------------------------------------
543  * Update a vector array in case of parallelism and/or periodicity.
544  *
545  * parameters:
546  * var1 <-> vector component 1 array
547  * var2 <-> vector component 2 array
548  * var3 <-> vector component 3 array
549  *----------------------------------------------------------------------------*/
550 
551 void
553  cs_real_t *var2,
554  cs_real_t *var3);
555 
556 /*----------------------------------------------------------------------------
557  * Update a vector array in case of parallelism and/or periodicity.
558  *
559  * parameters:
560  * var <-> interleaved vector (of dimension 3)
561  *----------------------------------------------------------------------------*/
562 
563 void
565 
566 /*----------------------------------------------------------------------------
567  * Update a components of a vector for parallelism and/or periodicity,
568  * ignoring periodicity of rotation.
569  *
570  * var <-> gradient components (interleaved)
571  *----------------------------------------------------------------------------*/
572 
573 void
575 
576 /*----------------------------------------------------------------------------
577  * Update a diagonal tensor array in case of parallelism and/or periodicity.
578  *
579  * parameters:
580  * var11 <-> diagonal tensor component 11 array
581  * var22 <-> diagonal tensor component 22 array
582  * var33 <-> diagonal tensor component 33 array
583  *----------------------------------------------------------------------------*/
584 
585 void
587  cs_real_t *var22,
588  cs_real_t *var33);
589 
590 /*----------------------------------------------------------------------------
591  * Update a diagonal tensor array in case of parallelism and/or periodicity.
592  *
593  * parameters:
594  * var <-> diagonal tensor interleaved array
595  *----------------------------------------------------------------------------*/
596 
597 void
599 
600 /*----------------------------------------------------------------------------
601  * Update a tensor array in case of parallelism and/or periodicity.
602  *
603  * parameters:
604  * var11 <-> tensor component 11 array
605  * var12 <-> tensor component 12 array
606  * var13 <-> tensor component 13 array
607  * var21 <-> tensor component 21 array
608  * var22 <-> tensor component 22 array
609  * var23 <-> tensor component 23 array
610  * var31 <-> tensor component 31 array
611  * var32 <-> tensor component 32 array
612  * var33 <-> tensor component 33 array
613  *----------------------------------------------------------------------------*/
614 
615 void
617  cs_real_t *var12,
618  cs_real_t *var13,
619  cs_real_t *var21,
620  cs_real_t *var22,
621  cs_real_t *var23,
622  cs_real_t *var31,
623  cs_real_t *var32,
624  cs_real_t *var33);
625 
626 /*----------------------------------------------------------------------------
627  * Update a tensor array in case of parallelism and/or periodicity.
628  *
629  * parameters:
630  * var <-> interleaved tensor (of dimension 3x3)
631  *----------------------------------------------------------------------------*/
632 
633 void
635 
636 /*----------------------------------------------------------------------------
637  * Update a symmetric tensor array in case of parallelism and/or periodicity.
638  *
639  * parameters:
640  * var <-> symmetric interleaved tensor (of dimension 6)
641  *----------------------------------------------------------------------------*/
642 
643 void
645 
646 /*----------------------------------------------------------------------------
647  * Order family numbers and remove duplicates
648  *
649  * parameters
650  * mesh <-> pointer to mesh structure
651  *----------------------------------------------------------------------------*/
652 
653 void
655 
656 /*----------------------------------------------------------------------------
657  * Define group classes for a mesh based on its family definitions.
658  *
659  * parameters:
660  * mesh <-> pointer to mesh structure
661  *----------------------------------------------------------------------------*/
662 
663 void
665 
666 /*----------------------------------------------------------------------------
667  * Assign selectors to global mesh.
668  *
669  * Should be called once the mesh is fully built.
670  *----------------------------------------------------------------------------*/
671 
672 void
674 
675 /*----------------------------------------------------------------------------
676  * Get global lists of periodic face couples.
677  *
678  * In parallel, each face couple may appear on only one rank.
679  *
680  * The caller is responsible for freeing the arrays allocated and returned
681  * by this function once they are no onger needed.
682  *
683  * parameters:
684  * mesh <-- pointer to mesh structure
685  * n_perio_face_couples --> global number of periodic couples per
686  * periodicity (size: mesh->n_init_perio)
687  * perio_face_couples --> arrays of global periodic couple face numbers,
688  * for each periodicity
689  *----------------------------------------------------------------------------*/
690 
691 void
693  cs_lnum_t **n_perio_face_couples,
694  cs_gnum_t ***perio_face_couples);
695 
696 /*----------------------------------------------------------------------------
697  * Build global cell numbering array extended to ghost cell values.
698  *
699  * If the blank_perio flag is nonzero, periodic ghost cell numbers
700  * are set to zero instead of the value of the matching cell.
701  *
702  * The caller is responsible for freeing the returned array when it
703  * is no longer useful.
704  *
705  * parameters:
706  * mesh <-- pointer to mesh structure
707  * blank_perio <-- flag to zeroe periodic cell values
708  *----------------------------------------------------------------------------*/
709 
710 cs_gnum_t *
712  int blank_perio);
713 
714 /*----------------------------------------------------------------------------
715  * Mark interior faces with the number of their associated periodic
716  * transform id.
717  *
718  * parameters:
719  * mesh <-- pointer to mesh structure
720  * perio_num --> periodicity number associated with each face, signed for
721  * direct/reverse transform, 0 for non-periodic faces
722  * (size: mesh->n_i_faces)
723  *----------------------------------------------------------------------------*/
724 
725 void
727  int perio_num[]);
728 
729 /*----------------------------------------------------------------------------
730  * Print information on a mesh structure.
731  *
732  * parameters:
733  * mesh <-- pointer to mesh structure.
734  * name <-- associated name.
735  *----------------------------------------------------------------------------*/
736 
737 void
739  const char *name);
740 
741 /*----------------------------------------------------------------------------
742  * Compute global face connectivity size.
743  *
744  * Faces on simple parallel boundaries are counted only once, but periodic
745  * faces are counted twice.
746  *
747  * parameters:
748  * mesh <-- pointer to a cs_mesh_t structure
749  * g_i_face_vertices_size --> global interior face connectivity size, or NULL
750  * g_b_face_vertices_size --> global boundary face connectivity size, or NULL
751  *----------------------------------------------------------------------------*/
752 
753 void
755  cs_gnum_t *g_i_face_vertices_size,
756  cs_gnum_t *g_b_face_vertices_size);
757 
758 /*----------------------------------------------------------------------------
759  * Print statistics about mesh selectors usage to log.
760  *
761  * parameters:
762  * mesh <-- pointer to a mesh structure
763  *----------------------------------------------------------------------------*/
764 
765 void
767 
768 /*----------------------------------------------------------------------------
769  * Dump of a mesh structure.
770  *
771  * parameters:
772  * mesh <-> pointer to mesh structure.
773  *----------------------------------------------------------------------------*/
774 
775 void
776 cs_mesh_dump(const cs_mesh_t *mesh);
777 
778 /*----------------------------------------------------------------------------*/
779 
781 
782 #endif /* __CS_MESH_H__ */