| 1 |
// Copyright(C) 2021, 2022, 2023 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include "Cell.h" |
| 11 |
#include "Ioss_ParallelUtils.h" |
| 12 |
#include "Ioss_Region.h" |
| 13 |
#include "UnitCell.h" |
| 14 |
#include "ZE_SystemInterface.h" |
| 15 |
|
| 16 |
//! \file |
| 17 |
|
| 18 |
//! `grid` stores the data for the tessellation of size `IxJ` |
| 19 |
//! * gridI -- extent in I direction |
| 20 |
//! * gridJ -- extend in J direction |
| 21 |
//! * grid(i,j) -- return database information at i,j location |
| 22 |
//! * grid(index) -- return database information at i,j location corresponding to `index` |
| 23 |
//! * max number of element blocks in a unit_cell mesh |
| 24 |
//! * range of x, y size of unit_cell mesh. (assumes unit_cell minx, miny == 0.0) |
| 25 |
//! * Ti, Tj, Tk -- size of regular mesh on boundary of unit_cell (? may need the 3 `Tk` values for |
| 26 |
//! padding) |
| 27 |
//! * std::vector<Cell> m_grid -- contains database information... |
| 28 |
class Grid |
| 29 |
{ |
| 30 |
public: |
| 31 |
//! Create an empty grid of size `extent_i` x `extent_j`. The output mesh will |
| 32 |
//! be written to the exodus database in the Ioss::Region `region` |
| 33 |
explicit Grid(SystemInterface &interFace); |
| 34 |
|
| 35 |
void set_extent(size_t extent_i, size_t extent_j, size_t /* unused */); |
| 36 |
|
| 37 |
UnitCellMap &unit_cells() { return m_unitCells; } |
| 38 |
|
| 39 |
//! Return a reference to the Cell cell at location `(i,j)`. |
| 40 |
//! Does not check that `i` and `j` are in bounds. |
| 41 |
Cell &get_cell(size_t i, size_t j) |
| 42 |
{ |
| 43 |
size_t idx = i * m_gridJ + j; |
| 44 |
return m_grid[idx]; |
| 45 |
} |
| 46 |
|
| 47 |
//! Return `I` extent of the grid / lattice |
| 48 |
size_t II() const { return m_gridI; } |
| 49 |
//! Return `J` extent of the grid / lattice |
| 50 |
size_t JJ() const { return m_gridJ; } |
| 51 |
//! Return total number of cells in the grid / lattice |
| 52 |
size_t size() const { return m_gridI * m_gridJ; } |
| 53 |
int parallel_size() const { return m_parallelSize; } |
| 54 |
|
| 55 |
//! Set the rank that the should start processing and outputting (used for subcycling) |
| 56 |
void set_start_rank(int start_rank) { m_startRank = start_rank; } |
| 57 |
|
| 58 |
//! Determine if can keep all files open at all times, |
| 59 |
//! or if we need to close some/all after access... |
| 60 |
void handle_file_count(); |
| 61 |
|
| 62 |
//! Are nodes at the boundaries of the unit cells equivalenced. |
| 63 |
bool equivalence_nodes() const { return m_equivalenceNodes; } |
| 64 |
|
| 65 |
//! Create a Cell object referencing the UnitCell specified by `key` at location `(i,j)` |
| 66 |
bool initialize(size_t i, size_t j, const std::string &key); |
| 67 |
|
| 68 |
void add_unit_cell(const std::string &key, const std::string &unit_filename, bool ints32bit); |
| 69 |
|
| 70 |
//! Specify the X and Y location of each grid cell in the overall grid space. |
| 71 |
void set_coordinate_offsets(); |
| 72 |
|
| 73 |
//! |
| 74 |
void generate_sidesets(); |
| 75 |
|
| 76 |
//! Once all Cell objects have been initialized, Determine the coordinate extents and |
| 77 |
//! offsets of each cell, the size of the output mesh, the node and element id offsets |
| 78 |
//! for each cell, the number of nodes and elements in the output mesh and initialize |
| 79 |
//! the output mesh. |
| 80 |
template <typename INT> void process(SystemInterface &interFace, INT /* dummy */); |
| 81 |
|
| 82 |
void decompose(const std::string &method); |
| 83 |
|
| 84 |
const Ioss::ParallelUtils &util() const { return m_pu; } |
| 85 |
|
| 86 |
Ioss::Region *output_region(int rank = 0) { return m_outputRegions[rank].get(); } |
| 87 |
|
| 88 |
bool minimize_open_files(Minimize type) { return (int)m_minimizeOpenFiles & int(type); } |
| 89 |
unsigned int get_generated_sidesets() { return m_generatedSideSets; } |
| 90 |
|
| 91 |
void set_sideset_names(const std::string &names); |
| 92 |
|
| 93 |
std::array<std::string, 6> generated_surface_names{ |
| 94 |
{"min_i", "max_i", "min_j", "max_j", "min_k", "max_k"}}; |
| 95 |
|
| 96 |
private: |
| 97 |
//! Output node coordinates and element block connectivities for the output mesh. |
| 98 |
template <typename INT> void output_model(INT /*dummy*/); |
| 99 |
void internal_process(); |
| 100 |
|
| 101 |
void create_output_regions(SystemInterface &interFace); |
| 102 |
void categorize_processor_boundaries(); |
| 103 |
|
| 104 |
void output_nodal_coordinates(const Cell &cell); |
| 105 |
template <typename INT> |
| 106 |
void output_block_connectivity(Cell &cell, const std::vector<INT> &node_map); |
| 107 |
template <typename INT> |
| 108 |
void output_nodal_communication_map(Cell &cell, const std::vector<INT> &node_map); |
| 109 |
template <typename INT> void output_element_map(Cell &cell, INT /*dummy*/); |
| 110 |
template <typename INT> void output_node_map(const Cell &cell, INT /*dummy*/); |
| 111 |
|
| 112 |
template <typename INT> void output_surfaces(Cell &cell, INT /*dummy*/); |
| 113 |
template <typename INT> void output_generated_surfaces(Cell &cell, INT /*dummy*/); |
| 114 |
|
| 115 |
UnitCellMap m_unitCells; |
| 116 |
std::vector<std::unique_ptr<Ioss::Region>> m_outputRegions; |
| 117 |
std::vector<Cell> m_grid{}; |
| 118 |
Ioss::ParallelUtils m_pu{}; |
| 119 |
size_t m_gridI{0}; |
| 120 |
size_t m_gridJ{0}; |
| 121 |
vector3d m_offset{0.0, 0.0, 0.0}; |
| 122 |
double m_scaleFactor{1.0}; |
| 123 |
int m_parallelSize{1}; //! Number of ranks to decompose for |
| 124 |
int m_rankCount{1}; //! Number of ranks to process at a time. |
| 125 |
int m_startRank{0}; //! Which rank to start outputting... |
| 126 |
bool m_equivalenceNodes{true}; |
| 127 |
bool m_useInternalSidesets{true}; |
| 128 |
bool m_subCycle{false}; |
| 129 |
Minimize m_minimizeOpenFiles{Minimize::NONE}; // 1: Unit, 2: output, 3: all |
| 130 |
unsigned int m_generatedSideSets{0}; |
| 131 |
}; |