| 1 |
// Copyright(C) 2021, 2022, 2024 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 |
// |
| 9 |
// `Cell`: |
| 10 |
// -- for each location: |
| 11 |
// -- i,j location (could be calculated, but easier if entry knows it...) |
| 12 |
// -- reference to unit_cell region |
| 13 |
// -- global node offset for node ids (over all ranks if parallel) |
| 14 |
// -- local node offset for node ids (for this rank only if parallel) |
| 15 |
// -- global element block offsets for element ids for each element block (over all ranks if |
| 16 |
// parallel) |
| 17 |
// -- local element block offsets for element ids for each element block (for this rank only |
| 18 |
// if parallel) |
| 19 |
// -- offX, offY -- coordinate offsets for nodes (can be calculated?) |
| 20 |
// -- rank (for parallel -- which rank does this entry exist on) |
| 21 |
// |
| 22 |
|
| 23 |
#include <array> |
| 24 |
#include <memory> |
| 25 |
#include <string> |
| 26 |
#include <utility> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
#include "UnitCell.h" |
| 30 |
//! \file |
| 31 |
|
| 32 |
// Each entry in grid will have the following information: |
| 33 |
enum class Axis { X, Y, Z }; |
| 34 |
enum class Mode { GLOBAL, PROCESSOR }; |
| 35 |
enum class Loc { C = 0, BL, B, BR, L, R, TL, T, TR }; |
| 36 |
|
| 37 |
class Cell |
| 38 |
{ |
| 39 |
public: |
| 40 |
std::pair<double, double> get_coordinate_range(enum Axis) const; |
| 41 |
void initialize(size_t i, size_t j, std::shared_ptr<UnitCell> unit_cell); |
| 42 |
|
| 43 |
//! Provide access to the UnitCell that this cell uses. |
| 44 |
std::shared_ptr<UnitCell> unit() const { return m_unitCell; } |
| 45 |
|
| 46 |
//! Provide access to the Ioss::Region in the unit_cell that this cell uses. |
| 47 |
std::shared_ptr<Ioss::Region> region() const { return m_unitCell->m_region; } |
| 48 |
|
| 49 |
//! True if this cell has a neighbor to its "left" (lower i) |
| 50 |
bool has_neighbor_i() const { return m_i > 0; } |
| 51 |
|
| 52 |
//! True if this cell has a neighbor "below it" (lower j) |
| 53 |
bool has_neighbor_j() const { return m_j > 0; } |
| 54 |
|
| 55 |
//! Return neighbor information for each possible direction. |
| 56 |
//! This is only valid after `grid.decompose()` has been called |
| 57 |
bool has_neighbor(enum Loc loc) const { return m_ranks[(int)loc] != -1; } |
| 58 |
|
| 59 |
//! True if this cell has a processor boundary to the specified direction |
| 60 |
//! Note that cell cannot compute this, but is "told" this during decomposition |
| 61 |
//! of the owning `Grid` |
| 62 |
//! There is a processor boundary if the rank of the cell at that location is |
| 63 |
//! different than the rank of this cell... |
| 64 |
bool processor_boundary(enum Loc loc) const |
| 65 |
{ |
| 66 |
return m_ranks[(int)loc] >= 0 && (m_ranks[(int)Loc::C] != m_ranks[(int)loc]); |
| 67 |
} |
| 68 |
|
| 69 |
//! Number of nodes that will be added to global node count when this cell is added to |
| 70 |
//! grid -- accounts for coincident nodes if this cell has neighbor(s) |
| 71 |
size_t added_node_count(enum Mode mode, bool equivalence_nodes) const; |
| 72 |
|
| 73 |
//! Number of nodes that this cell adds to the processor boundary node count. |
| 74 |
//! Assumes that cells are processed in "order", so accounts for corner nodes |
| 75 |
//! shared with another cell... |
| 76 |
//! Note that a node shared by more than one processor (e.g. a corner node) counts |
| 77 |
//! for each processor it is shared with. |
| 78 |
size_t processor_boundary_node_count() const; |
| 79 |
|
| 80 |
template <typename INT> |
| 81 |
void populate_node_communication_map(const std::vector<INT> &node_map, std::vector<INT> &nodes, |
| 82 |
std::vector<INT> &procs) const; |
| 83 |
|
| 84 |
//! Returns a `std::array<int,9>` which categorizes whether the cells at each location are on the |
| 85 |
//! same rank as `rank`. A value of `1` means the cell at that location is on the same rank; a |
| 86 |
//! value of `0` means it is on a different rank. Used to determine which nodes have already been |
| 87 |
//! accounted for on this rank and which this cell will add to the processor-local count. |
| 88 |
std::array<int, 9> categorize_processor_boundary_nodes(int rank) const; |
| 89 |
|
| 90 |
//! The mpi rank that this cell, or the neighboring cells, will be on in a parallel run. |
| 91 |
int rank(enum Loc loc) const { return m_ranks[(int)loc]; } |
| 92 |
|
| 93 |
//! The mpi rank that this cell will be on in a parallel run. |
| 94 |
void set_rank(enum Loc loc, int my_rank) { m_ranks[(int)loc] = my_rank; } |
| 95 |
|
| 96 |
//! Create a vector of `node_count` length which has the following values: |
| 97 |
//! * 0: Node that is not shared with any "lower" neighbors. |
| 98 |
//! * 1: Node on `min_I` face |
| 99 |
//! * 2: Node on `min_J` face |
| 100 |
//! * 3: Node on `min_I-min_J` line |
| 101 |
//! If `mode == PROCESSOR`, then modify due to processor boundaries... |
| 102 |
std::vector<int> categorize_nodes(enum Mode mode) const; |
| 103 |
|
| 104 |
template <typename INT> |
| 105 |
std::vector<INT> generate_node_map(Mode mode, bool equivalance_nodes, INT /*dummy*/) const; |
| 106 |
|
| 107 |
template <typename INT> |
| 108 |
void populate_neighbor(Loc location, const std::vector<INT> &map, const Cell &neighbor) const; |
| 109 |
|
| 110 |
//! A vector containing the global node ids of the nodes on the `min_I` face of this |
| 111 |
//! unit cell. These nodes were generated by the "left" (lower i) neighbor. |
| 112 |
//! Once this cell uses this information, it can clear out the vector. |
| 113 |
mutable std::vector<int64_t> min_I_nodes; |
| 114 |
|
| 115 |
//! A vector containing the global node ids of the nodes on the `min_J` face of this |
| 116 |
//! unit cell. These nodes were generated by the "below" (lower j neighbor. |
| 117 |
//! Once this cell uses this information, it can clear out the vector. |
| 118 |
mutable std::vector<int64_t> min_J_nodes; |
| 119 |
|
| 120 |
//! The `i` location of this entry in the grid |
| 121 |
size_t m_i{0}; |
| 122 |
//! The `j` location of this entry in the grid |
| 123 |
size_t m_j{0}; |
| 124 |
|
| 125 |
int64_t m_globalNodeIdOffset{0}; |
| 126 |
int64_t m_localNodeIdOffset{0}; |
| 127 |
|
| 128 |
//! The offset into the commincation node output array for this cell in the file associated with |
| 129 |
//! the rank that this cell is on. Set by handle_communications() in Grid.C. |
| 130 |
mutable size_t m_communicationNodeOffset{0}; |
| 131 |
|
| 132 |
//! The number of node/proc pairs that this cell adds to the communication node map. |
| 133 |
mutable size_t m_communicationNodeCount{0}; |
| 134 |
|
| 135 |
std::map<std::string, size_t> m_globalElementIdOffset; |
| 136 |
std::map<std::string, size_t> m_localElementIdOffset; |
| 137 |
|
| 138 |
//! For each surface/sideset, this is the offset into the output element/face lists |
| 139 |
//! for this cells data. 0-based. Indexed by surface name. |
| 140 |
std::map<std::string, size_t> m_localSurfaceOffset; |
| 141 |
|
| 142 |
//! The offset that must be added to the `x` coordinates of the |
| 143 |
//! UnitCell to place it in the correct global location of the |
| 144 |
//! output mesh |
| 145 |
double m_offX{0.0}; |
| 146 |
|
| 147 |
//! The offset that must be added to the `y` coordinates of the |
| 148 |
//! UnitCell to place it in the correct global location of the |
| 149 |
//! output mesh |
| 150 |
double m_offY{0.0}; |
| 151 |
|
| 152 |
private: |
| 153 |
//! The UnitCell that occupies this location in the grid / lattice |
| 154 |
std::shared_ptr<UnitCell> m_unitCell; |
| 155 |
|
| 156 |
//! The MPI ranks of all surrounding cells in order: |
| 157 |
//! 6 7 8 TL T TR |
| 158 |
//! 4 0 5 L C R |
| 159 |
//! 1 2 3 BL B BR |
| 160 |
std::array<int, 9> m_ranks{{0, -1, -1, -1, -1, -1, -1, -1, -1}}; |
| 161 |
}; |