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-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 /*---------------------------------------------------------------------------- 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 #include "cs_range_set.h" 45 46 #include "cs_mesh_builder.h" 47 48 /*----------------------------------------------------------------------------*/ 49 50 BEGIN_C_DECLS 51 52 /*============================================================================= 53 * Macro definitions 54 *============================================================================*/ 55 56 /* 57 * Mesh modification type flags 58 */ 59 60 /*! Any type of mesh modification */ 61 #define CS_MESH_MODIFIED (1 << 0) 62 63 /*! Mesh modification has changed mesh distribution balance */ 64 #define CS_MESH_MODIFIED_BALANCE (1 << 1) 65 66 /*============================================================================ 67 * Type definitions 68 *============================================================================*/ 69 70 /*! Mesh time dependency */ 71 /* -------------------- */ 72 73 typedef enum { 74 75 CS_MESH_FIXED, /*!< Mesh definitions do not change with time */ 76 CS_MESH_TRANSIENT_COORDS, /*!< Vertex coordinates may change with time */ 77 CS_MESH_TRANSIENT_CONNECT /*!< Mesh connectivity may change with time */ 78 79 } cs_mesh_time_dep_t; 80 81 /*! Mesh structure definition */ 82 /* ------------------------- */ 83 84 typedef struct { 85 86 /* General features */ 87 88 cs_lnum_t dim; /*!< space dimension */ 89 int domain_num; /*!< local domain number */ 90 int n_domains; /*!< number of domains */ 91 92 cs_mesh_time_dep_t time_dep; /*!< time dependency */ 93 94 /* Local dimensions */ 95 96 cs_lnum_t n_cells; /*!< number of cells */ 97 cs_lnum_t n_i_faces; /*!< number of interior faces */ 98 cs_lnum_t n_b_faces; /*!< number of boundary faces */ 99 cs_lnum_t n_vertices; /*!< number of vertices */ 100 101 cs_lnum_t i_face_vtx_connect_size; /*!< interior faces -> vertices 102 connectivity size */ 103 cs_lnum_t b_face_vtx_connect_size; /*!< boundary faces -> vertices 104 connectivity size */ 105 106 /* Local structures */ 107 108 cs_real_t *vtx_coord; /*!< vertex coordinates */ 109 110 cs_lnum_2_t *i_face_cells; /*!< interior faces -> cells connectivity */ 111 cs_lnum_t *b_face_cells; /*!< boundary faces -> cells connectivity */ 112 113 cs_lnum_t *i_face_vtx_idx; /*!< interior faces -> vertices index */ 114 cs_lnum_t *i_face_vtx_lst; /*!< interior faces -> vertices connectivity */ 115 116 cs_lnum_t *b_face_vtx_idx; /*!< boundary faces -> vertices index */ 117 cs_lnum_t *b_face_vtx_lst; /*!< boundary faces -> vertices connectivity */ 118 119 /* Global dimension */ 120 121 cs_gnum_t n_g_cells; /*!< global number of cells */ 122 cs_gnum_t n_g_i_faces; /*!< global number of interior faces */ 123 cs_gnum_t n_g_b_faces; /*!< global number of boundary faces */ 124 cs_gnum_t n_g_vertices; /*!< global number of vertices */ 125 126 cs_gnum_t n_g_i_c_faces; /*!< global number of interior faces 127 for counts (with periodic faces 128 counted only once) */ 129 130 /* Global numbering */ 131 132 cs_gnum_t *global_cell_num; /*!< global cell numbering */ 133 cs_gnum_t *global_i_face_num; /*!< global interior face numbering */ 134 cs_gnum_t *global_b_face_num; /*!< global boundary face numbering */ 135 cs_gnum_t *global_vtx_num; /*!< global vertex numbering */ 136 137 /* Periodictity features */ 138 139 int n_init_perio; /*!< number of initial periodicities */ 140 int n_transforms; /*!< number of transformations */ 141 142 int have_rotation_perio; /*!< periodicity rotation indicator */ 143 144 fvm_periodicity_t *periodicity; /*!< parameters of each periodicity */ 145 146 /* Parallelism and/or periodic features */ 147 148 cs_halo_type_t halo_type; /*!< halo type */ 149 150 cs_lnum_t n_cells_with_ghosts; /*!< total number of cells on the local rank 151 (n_cells + n_ghost_cells) */ 152 cs_lnum_t n_ghost_cells; /*!< number of "ghost" cells */ 153 154 cs_interface_set_t *vtx_interfaces; /*!< vertices interface set */ 155 cs_halo_t *halo; /*!< ghost cells structure */ 156 cs_range_set_t *vtx_range_set; /*!< handle local/distant ranges for 157 vertices in parallel */ 158 159 cs_numbering_t *cell_numbering; /*!< cell numbering info */ 160 cs_numbering_t *vtx_numbering; /*!< vertex numbering info */ 161 cs_numbering_t *i_face_numbering; /*!< interior face numbering info */ 162 cs_numbering_t *b_face_numbering; /*!< boundary face numbering info */ 163 164 /* Re-computable connectivity features */ 165 166 cs_lnum_t n_b_cells; /*!< number of boundary cells */ 167 cs_lnum_t *b_cells; /*!< boundary cell list */ 168 169 /* Extended neighborhood features */ 170 171 cs_lnum_t *cell_cells_idx; /*!< "cell -> cells" connectivity index for 172 extended halo. Only defined if extended 173 neighborhood is built. */ 174 cs_lnum_t *cell_cells_lst; /*!< "cell -> cells" connectivity list for 175 extended halo. Only defined if extended 176 neighborhood is built. */ 177 178 cs_lnum_t *gcell_vtx_idx; /*!< ghost cells -> vertices index */ 179 cs_lnum_t *gcell_vtx_lst; /*!< ghost cells -> vertices list */ 180 181 /* Group and family features */ 182 183 int n_groups; /*!< number of groups */ 184 int *group_idx; /*!< starting index in group */ 185 char *group; /*!< list of group names */ 186 187 int n_families; /*!< number of families */ 188 int n_max_family_items; /*!< max. number of items for one family */ 189 int *family_item; /*!< family items */ 190 int *cell_family; /*!< cell family */ 191 int *i_face_family; /*!< interior face family */ 192 int *b_face_family; /*!< boundary face family */ 193 194 fvm_group_class_set_t *class_defs; /*!< definition of group classes for 195 selection and postprocessing (built 196 from element families and their 197 descriptions) */ 198 fvm_selector_t *select_cells; /*!< cells selection object */ 199 fvm_selector_t *select_i_faces; /*!< interior faces selection object */ 200 fvm_selector_t *select_b_faces; /*!< boundary faces selection object */ 201 202 /* Refinement features */ 203 204 char *i_face_r_gen; /*!< interior face refinement generation */ 205 206 /* Status flags */ 207 208 cs_gnum_t n_g_free_faces; /*!< global number of boundary faces 209 which are in fact isolated */ 210 211 cs_gnum_t n_g_b_faces_all; /*!< global number of boundary faces 212 inluding those ignored in FV schemes */ 213 cs_lnum_t n_b_faces_all; /*!< number of boundary faces including 214 faces ignored in FV schemes */ 215 216 int verbosity; /*!< current verbosity level */ 217 int modified; /*!< modification status */ 218 int save_if_modified; /*!< flag for mesh saving behavior: 219 0: never save 220 1: saved when modified (default) 221 2: always save */ 222 223 } cs_mesh_t; 224 225 /*============================================================================ 226 * Static global variables 227 *============================================================================*/ 228 229 extern cs_mesh_t *cs_glob_mesh; /* Pointer to main mesh structure */ 230 231 /*============================================================================ 232 * Public function prototypes for Fortran API 233 *============================================================================*/ 234 235 /*---------------------------------------------------------------------------- 236 * Update a scalar array in case of parallelism and/or periodicity. 237 * 238 * Fortran interface: 239 * 240 * subroutine synsca(var) 241 * ***************** 242 * 243 * var : <-> : scalar array 244 *----------------------------------------------------------------------------*/ 245 246 void CS_PROCF(synsca, SYNSCA) 247 ( 248 cs_real_t var[] 249 ); 250 251 /*---------------------------------------------------------------------------- 252 * Update a scalar array in case of parallelism and/or periodicity, 253 * using an extended halo. 254 * 255 * Fortran interface: 256 * 257 * subroutine synsce(var) 258 * ***************** 259 * 260 * var : <-> : scalar array 261 *----------------------------------------------------------------------------*/ 262 263 void CS_PROCF(synsce, SYNSCE) 264 ( 265 cs_real_t var[] 266 ); 267 268 /*---------------------------------------------------------------------------- 269 * Update a vector array in case of parallelism and/or periodicity. 270 * 271 * Fortran interface: 272 * 273 * subroutine synvin(var) 274 * ***************** 275 * 276 * var : <-> : interleaved vector (of dimension 3) 277 *----------------------------------------------------------------------------*/ 278 279 void CS_PROCF(synvin, SYNVIN) 280 ( 281 cs_real_t var[] 282 ); 283 284 /*---------------------------------------------------------------------------- 285 * Update a vector array in case of parallelism and/or periodicity, 286 * using an extended halo. 287 * 288 * Fortran interface: 289 * 290 * subroutine synvin(var) 291 * ***************** 292 * 293 * var : <-> : interleaved vector (of dimension 3) 294 *----------------------------------------------------------------------------*/ 295 296 void CS_PROCF(synvie, SYNVIE) 297 ( 298 cs_real_t var[] 299 ); 300 301 /*---------------------------------------------------------------------------- 302 * Update a tensor array in case of parallelism and/or periodicity. 303 * 304 * Fortran interface: 305 * 306 * subroutine syntin(var) 307 * ***************** 308 * 309 * var : <-> : interleaved tensor (of dimension 3x3) 310 *----------------------------------------------------------------------------*/ 311 312 void CS_PROCF(syntin, SYNTIN) 313 ( 314 cs_real_t var[] 315 ); 316 317 /*---------------------------------------------------------------------------- 318 * Update a symmetric tensor array in case of parallelism and/or periodicity. 319 * 320 * Fortran interface: 321 * 322 * subroutine syntis(var) 323 * ***************** 324 * 325 * var : <-> : interleaved symmetric tensor (of dimension 6) 326 *----------------------------------------------------------------------------*/ 327 328 void CS_PROCF(syntis, SYNTIS) 329 ( 330 cs_real_t var[] 331 ); 332 333 /*============================================================================= 334 * Public function prototypes 335 *============================================================================*/ 336 337 /*---------------------------------------------------------------------------- 338 * Create an empty mesh structure 339 * 340 * returns: 341 * pointer to created mesh structure 342 *----------------------------------------------------------------------------*/ 343 344 cs_mesh_t * 345 cs_mesh_create(void); 346 347 /*---------------------------------------------------------------------------- 348 * Destroy a mesh structure 349 * 350 * mesh <-> pointer to a mesh structure 351 * 352 * returns: 353 * NULL pointer 354 *----------------------------------------------------------------------------*/ 355 356 cs_mesh_t * 357 cs_mesh_destroy(cs_mesh_t *mesh); 358 359 /*---------------------------------------------------------------------------- 360 * Update (compactify) an array of global numbers. 361 * 362 * parameters: 363 * n_elts <-> number of local elements 364 * elt_gnum <-> global element numbers 365 * 366 * return: 367 * associated global number of elements 368 *----------------------------------------------------------------------------*/ 369 370 cs_gnum_t 371 cs_mesh_compact_gnum(cs_lnum_t n_elts, 372 cs_gnum_t *elt_gnum); 373 374 /*---------------------------------------------------------------------------- 375 * Remove arrays and structures that mey be rebuilt. 376 * 377 * mesh <-> pointer to a mesh structure 378 * free_halos <-- if true, free halos and parallel/periodic interface 379 * structures 380 *----------------------------------------------------------------------------*/ 381 382 void 383 cs_mesh_free_rebuildable(cs_mesh_t *mesh, 384 bool free_halos); 385 386 /*---------------------------------------------------------------------------- 387 * Discard free (isolated) faces from a mesh. 388 * 389 * This should always be done before using the mesh for computation. 390 * 391 * parameters: 392 * mesh <-> pointer to mesh structure 393 *----------------------------------------------------------------------------*/ 394 395 void 396 cs_mesh_discard_free_faces(cs_mesh_t *mesh); 397 398 /*---------------------------------------------------------------------------- 399 * Discard free (isolated) vertices from a mesh. 400 * 401 * This is recommended before using the mesh for computation. 402 * 403 * parameters: 404 * mesh <-> pointer to mesh structure 405 *----------------------------------------------------------------------------*/ 406 407 void 408 cs_mesh_discard_free_vertices(cs_mesh_t *mesh); 409 410 /*---------------------------------------------------------------------------- 411 * Generate or update list of mesh boundary cells. 412 * 413 * parameters: 414 * mesh <-> pointer to a cs_mesh_t structure 415 *----------------------------------------------------------------------------*/ 416 417 void 418 cs_mesh_update_b_cells(cs_mesh_t *mesh); 419 420 /*---------------------------------------------------------------------------- 421 * Compute or update mesh structure members that depend on other members, 422 * but whose results may be reused, such as global number of elements 423 * (cells, vertices, interior and boundary faces) and sync cell family. 424 * 425 * parameters: 426 * mesh <-> pointer to a cs_mesh_t structure 427 *----------------------------------------------------------------------------*/ 428 429 void 430 cs_mesh_update_auxiliary(cs_mesh_t *mesh); 431 432 /*---------------------------------------------------------------------------- 433 * Creation and initialization of mesh face and vertex interfaces. 434 * 435 * parameters: 436 * mesh <-> pointer to mesh structure 437 * mb <-> pointer to mesh builder (in case of periodicity) 438 *----------------------------------------------------------------------------*/ 439 440 void 441 cs_mesh_init_interfaces(cs_mesh_t *mesh, 442 cs_mesh_builder_t *mb); 443 444 /*----------------------------------------------------------------------------*/ 445 /*! 446 * Creation and initialization of halo structures. 447 * 448 * Treatment of parallel and/or periodic halos for standard and extended 449 * ghost cells according to halo type requested by global options. 450 * 451 * parameters: 452 * \param[in, out] mesh pointer to mesh structure 453 * \param[in, out] mb pointer to mesh builder 454 * (for periodicity) 455 * \param[in] halo_type type of halo (standard or extended) 456 * \param[in] verbosity verbosity 457 * \param[in] rebuild_vtx_interface also rebuild vertex interfaces ? 458 *----------------------------------------------------------------------------*/ 459 460 void 461 cs_mesh_init_halo(cs_mesh_t *mesh, 462 cs_mesh_builder_t *mb, 463 cs_halo_type_t halo_type, 464 int verbosity, 465 bool rebuild_vtx_interace); 466 467 /*---------------------------------------------------------------------------- 468 * Get the global number of ghost cells. 469 * 470 * parameters: 471 * mesh <-- pointer to a mesh structure 472 * 473 * returns: 474 * Global number of ghost cells 475 *---------------------------------------------------------------------------*/ 476 477 cs_gnum_t 478 cs_mesh_n_g_ghost_cells(cs_mesh_t *mesh); 479 480 /*---------------------------------------------------------------------------- 481 * Update a scalar array in case of parallelism and/or periodicity. 482 * 483 * Note: this function is only present so that a C equivalent to the 484 * Fortran wrappers is available. In C code, directly using 485 * cs_halo_sync_var() is preferred. 486 * 487 * parameters: 488 * var <-> scalar array 489 *----------------------------------------------------------------------------*/ 490 491 void 492 cs_mesh_sync_var_scal(cs_real_t *var); 493 494 /*---------------------------------------------------------------------------- 495 * Update a scalar array in case of parallelism and/or periodicity, 496 * using an extended halo. 497 * 498 * Note: this function is only present so that a C equivalent to the 499 * Fortran wrappers is available. In C code, directly using the 500 * cs_halo_sync_var() is preferred. 501 * 502 * parameters: 503 * var <-> scalar array 504 *----------------------------------------------------------------------------*/ 505 506 void 507 cs_mesh_sync_var_scal_ext(cs_real_t *var); 508 509 /*---------------------------------------------------------------------------- 510 * Update a vector array in case of parallelism and/or periodicity. 511 * 512 * parameters: 513 * var <-> interleaved vector (of dimension 3) 514 *----------------------------------------------------------------------------*/ 515 516 void 517 cs_mesh_sync_var_vect(cs_real_t *var); 518 519 /*---------------------------------------------------------------------------- 520 * Update a vector array in case of parallelism and/or periodicity, 521 * using an extended halo. 522 * 523 * parameters: 524 * var <-> interleaved vector (of dimension 3) 525 *----------------------------------------------------------------------------*/ 526 527 void 528 cs_mesh_sync_var_vect_ext(cs_real_t *var); 529 530 /*---------------------------------------------------------------------------- 531 * Update a tensor array in case of parallelism and/or periodicity. 532 * 533 * parameters: 534 * var <-> interleaved tensor (of dimension 3x3) 535 *----------------------------------------------------------------------------*/ 536 537 void 538 cs_mesh_sync_var_tens(cs_real_t *var); 539 540 /*---------------------------------------------------------------------------- 541 * Update a symmetric tensor array in case of parallelism and/or periodicity. 542 * 543 * parameters: 544 * var <-> symmetric interleaved tensor (of dimension 6) 545 *----------------------------------------------------------------------------*/ 546 547 void 548 cs_mesh_sync_var_sym_tens(cs_real_6_t *var); 549 550 /*---------------------------------------------------------------------------- 551 * Order family numbers and remove duplicates 552 * 553 * parameters 554 * mesh <-> pointer to mesh structure 555 *----------------------------------------------------------------------------*/ 556 557 void 558 cs_mesh_clean_families(cs_mesh_t *mesh); 559 560 /*---------------------------------------------------------------------------- 561 * Create group classes based on a mesh's family definitions. 562 * 563 * parameters: 564 * mesh <-- pointer to mesh structure 565 * 566 * returns: 567 * pointer to group classes structure based on mesh's family definitions 568 *----------------------------------------------------------------------------*/ 569 570 fvm_group_class_set_t * 571 cs_mesh_create_group_classes(cs_mesh_t *mesh); 572 573 /*---------------------------------------------------------------------------- 574 * Define group classes for a mesh based on its family definitions. 575 * 576 * parameters: 577 * mesh <-> pointer to mesh structure 578 *----------------------------------------------------------------------------*/ 579 580 void 581 cs_mesh_init_group_classes(cs_mesh_t *mesh); 582 583 /*---------------------------------------------------------------------------- 584 * Assign selectors to global mesh. 585 * 586 * Should be called once the mesh is fully built. 587 *----------------------------------------------------------------------------*/ 588 589 void 590 cs_mesh_init_selectors(void); 591 592 /*---------------------------------------------------------------------------- 593 * Update selector and associated structures. 594 * 595 * parameters: 596 * mesh <-> pointer to a mesh structure 597 *----------------------------------------------------------------------------*/ 598 599 void 600 cs_mesh_update_selectors(cs_mesh_t *mesh); 601 602 /*---------------------------------------------------------------------------- 603 * Get global lists of periodic face couples. 604 * 605 * In parallel, each face couple may appear on only one rank. 606 * 607 * The caller is responsible for freeing the arrays allocated and returned 608 * by this function once they are no onger needed. 609 * 610 * parameters: 611 * mesh <-- pointer to mesh structure 612 * n_perio_face_couples --> global number of periodic couples per 613 * periodicity (size: mesh->n_init_perio) 614 * perio_face_couples --> arrays of global periodic couple face numbers, 615 * for each periodicity 616 *----------------------------------------------------------------------------*/ 617 618 void 619 cs_mesh_get_perio_faces(const cs_mesh_t *mesh, 620 cs_lnum_t **n_perio_face_couples, 621 cs_gnum_t ***perio_face_couples); 622 623 /*---------------------------------------------------------------------------- 624 * Build global cell numbering array extended to ghost cell values. 625 * 626 * If the blank_perio flag is nonzero, periodic ghost cell numbers 627 * are set to zero instead of the value of the matching cell. 628 * 629 * The caller is responsible for freeing the returned array when it 630 * is no longer useful. 631 * 632 * parameters: 633 * mesh <-- pointer to mesh structure 634 * blank_perio <-- flag to zeroe periodic cell values 635 *----------------------------------------------------------------------------*/ 636 637 cs_gnum_t * 638 cs_mesh_get_cell_gnum(const cs_mesh_t *mesh, 639 int blank_perio); 640 641 /*---------------------------------------------------------------------------- 642 * Mark interior faces with the number of their associated periodic 643 * transform id. 644 * 645 * parameters: 646 * mesh <-- pointer to mesh structure 647 * perio_num --> periodicity number associated with each face, signed for 648 * direct/reverse transform, 0 for non-periodic faces 649 * (size: mesh->n_i_faces) 650 *----------------------------------------------------------------------------*/ 651 652 void 653 cs_mesh_get_face_perio_num(const cs_mesh_t *mesh, 654 int perio_num[]); 655 656 /*---------------------------------------------------------------------------- 657 * Print information on a mesh structure. 658 * 659 * parameters: 660 * mesh <-- pointer to mesh structure. 661 * name <-- associated name. 662 *----------------------------------------------------------------------------*/ 663 664 void 665 cs_mesh_print_info(const cs_mesh_t *mesh, 666 const char *name); 667 668 /*---------------------------------------------------------------------------- 669 * Compute global face connectivity size. 670 * 671 * Faces on simple parallel boundaries are counted only once, but periodic 672 * faces are counted twice. 673 * 674 * parameters: 675 * mesh <-- pointer to a cs_mesh_t structure 676 * g_i_face_vertices_size --> global interior face connectivity size, or NULL 677 * g_b_face_vertices_size --> global boundary face connectivity size, or NULL 678 *----------------------------------------------------------------------------*/ 679 680 void 681 cs_mesh_g_face_vertices_sizes(const cs_mesh_t *mesh, 682 cs_gnum_t *g_i_face_vertices_size, 683 cs_gnum_t *g_b_face_vertices_size); 684 685 /*---------------------------------------------------------------------------- 686 * Print statistics about mesh selectors usage to log. 687 * 688 * parameters: 689 * mesh <-- pointer to a mesh structure 690 *----------------------------------------------------------------------------*/ 691 692 void 693 cs_mesh_selector_stats(cs_mesh_t *mesh); 694 695 /*---------------------------------------------------------------------------- 696 * Dump of a mesh structure. 697 * 698 * parameters: 699 * mesh <-> pointer to mesh structure. 700 *----------------------------------------------------------------------------*/ 701 702 void 703 cs_mesh_dump(const cs_mesh_t *mesh); 704 705 /*----------------------------------------------------------------------------*/ 706 707 END_C_DECLS 708 709 #endif /* __CS_MESH_H__ */ 710