17 coord_sys_type_(cs_type),
25 constexpr std::string_view fname =
"chi_math::SpatialDiscretization::"
34 catch (
const std::out_of_range& oor)
36 throw std::out_of_range(std::string(fname) +
37 ": Failed to obtain cell mapping.");
80const std::vector<chi_mesh::Vector3>&
86std::pair<std::set<uint32_t>, std::set<uint32_t>>
91 const size_t num_faces = cell.
faces_.size();
92 const size_t num_nodes = cell_mapping.NumNodes();
96 std::set<uint32_t> boundary_nodes;
97 for (
size_t f = 0; f < num_faces; ++f)
99 if (not cell.
faces_[f].has_neighbor_)
101 const size_t num_face_nodes = cell_mapping.NumFaceNodes(f);
102 for (
size_t fi = 0; fi < num_face_nodes; ++fi)
103 boundary_nodes.insert(cell_mapping.MapFaceNode(f, fi));
108 std::set<uint32_t> internal_nodes;
109 for (
size_t i = 0; i < num_nodes; ++i)
110 if (boundary_nodes.find(i) == boundary_nodes.end())
111 internal_nodes.insert(i);
113 return {internal_nodes, boundary_nodes};
152std::vector<std::vector<std::vector<int>>>
154 const double tolerance )
const
156 typedef std::vector<int> FaceAdjMapping;
157 typedef std::vector<FaceAdjMapping> PerFaceAdjMapping;
158 typedef std::vector<PerFaceAdjMapping> CellAdjMapping;
160 const auto& grid = this->ref_grid_;
162 CellAdjMapping cell_adj_mapping;
163 for (
const auto& cell : grid.local_cells)
165 const auto& cell_mapping = this->GetCellMapping(cell);
166 const auto& node_locations = cell_mapping.GetNodeLocations();
167 const size_t num_faces = cell.faces_.size();
169 PerFaceAdjMapping per_face_adj_mapping;
171 for (
size_t f = 0; f < num_faces; ++f)
173 const auto& face = cell.faces_[f];
174 const auto num_face_nodes = cell_mapping.NumFaceNodes(f);
175 FaceAdjMapping face_adj_mapping(num_face_nodes, -1);
176 if (face.has_neighbor_)
178 const auto& adj_cell = grid.cells[face.neighbor_id_];
179 const auto& adj_cell_mapping = this->GetCellMapping(adj_cell);
180 const auto& adj_node_locations = adj_cell_mapping.GetNodeLocations();
181 const size_t adj_num_nodes = adj_cell_mapping.NumNodes();
183 for (
size_t fi = 0; fi < num_face_nodes; ++fi)
185 const int i = cell_mapping.MapFaceNode(f, fi);
186 const auto& ivec3 = node_locations[i];
188 for (
size_t ai = 0; ai < adj_num_nodes; ++ai)
190 const auto& aivec3 = adj_node_locations[ai];
191 if ((ivec3 - aivec3).NormSquare() < tolerance)
193 face_adj_mapping[fi] =
static_cast<int>(ai);
197 if (face_adj_mapping[fi] < 0)
198 throw std::logic_error(
"Face node mapping failed");
202 per_face_adj_mapping.push_back(std::move(face_adj_mapping));
205 cell_adj_mapping.push_back(std::move(per_face_adj_mapping));
208 return cell_adj_mapping;
228 const std::vector<double>& from_vector,
229 std::vector<double>& to_vector,
231 const unsigned int from_vec_uk_id,
233 const unsigned int to_vec_uk_id)
const
235 const std::string fname =
"chi_math::SpatialDiscretization::"
236 "CopyVectorWithUnknownScope";
237 const auto& ukmanF = from_vec_uk_structure;
238 const auto& ukmanT = to_vec_uk_structure;
239 const auto& ukidF = from_vec_uk_id;
240 const auto& ukidT = to_vec_uk_id;
243 const auto& ukA = from_vec_uk_structure.
unknowns_.at(from_vec_uk_id);
244 const auto& ukB = to_vec_uk_structure.
unknowns_.at(to_vec_uk_id);
246 if (ukA.num_components_ != ukB.num_components_)
247 throw std::logic_error(fname +
" Unknowns do not have the "
248 "same number of components");
250 const size_t num_comps = ukA.num_components_;
255 const size_t num_nodes = cell_mapping.NumNodes();
257 for (
size_t i = 0; i < num_nodes; ++i)
259 for (
size_t c = 0; c < num_comps; ++c)
261 const int64_t fmap =
MapDOFLocal(cell, i, ukmanF, ukidF, c);
262 const int64_t imap =
MapDOFLocal(cell, i, ukmanT, ukidT, c);
264 to_vector[imap] = from_vector[fmap];
269 catch (
const std::out_of_range& oor)
271 throw std::out_of_range(fname +
272 ": either from_vec_uk_id or to_vec_uk_id is "
273 "out of range for its respective "
282 std::vector<double>& local_vector,
288 petsc_vector, local_vector, num_local_dofs);
295 std::vector<double>& local_vector,
301 petsc_vector, local_vector, num_local_dofs);
313 return 2.0 * M_PI * point[0];
319 const double r = point[2];
320 return 4.0 * M_PI * r * r;
#define ChiLogicalError(message)
const std::vector< chi_mesh::Vector3 > & GetNodeLocations() const
std::function< double(const chi_mesh::Vector3 &)> SpatialWeightFunction
size_t GetNumLocalAndGhostDOFs(const UnknownManager &unknown_manager) const
SpatialDiscretizationType Type() const
const CellMapping & GetCellMapping(const chi_mesh::Cell &cell) const
static double CylindricalRZSpatialWeightFunction(const chi_mesh::Vector3 &point)
static double Spherical1DSpatialWeightFunction(const chi_mesh::Vector3 &point)
static double CartesianSpatialWeightFunction(const chi_mesh::Vector3 &point)
std::vector< std::unique_ptr< CellMapping > > cell_mappings_
size_t GetNumGlobalDOFs(const UnknownManager &unknown_manager) const
uint64_t globl_base_block_size_
CoordinateSystemType GetCoordinateSystemType() const
const chi_mesh::MeshContinuum & Grid() const
void CopyVectorWithUnknownScope(const std::vector< double > &from_vector, std::vector< double > &to_vector, const UnknownManager &from_vec_uk_structure, unsigned int from_vec_uk_id, const UnknownManager &to_vec_uk_structure, unsigned int to_vec_uk_id) const
std::map< uint64_t, std::shared_ptr< CellMapping > > nb_cell_mappings_
size_t GetNumLocalDOFs(const UnknownManager &unknown_manager) const
uint64_t local_base_block_size_
SpatialWeightFunction GetSpatialWeightingFunction() const
const SpatialDiscretizationType type_
std::pair< std::set< uint32_t >, std::set< uint32_t > > MakeCellInternalAndBndryNodeIDs(const chi_mesh::Cell &cell) const
virtual int64_t MapDOFLocal(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const =0
virtual void LocalizePETScVectorWithGhosts(Vec petsc_vector, std::vector< double > &local_vector, const UnknownManager &unknown_manager) const
virtual void LocalizePETScVector(Vec petsc_vector, std::vector< double > &local_vector, const UnknownManager &unknown_manager) const
const std::vector< chi_mesh::Vector3 > & GetCellNodeLocations(const chi_mesh::Cell &cell) const
size_t GetCellNumNodes(const chi_mesh::Cell &cell) const
std::vector< std::vector< std::vector< int > > > MakeInternalFaceNodeMappings(double tolerance=1.0e-12) const
For each local cell, for each face, for each face-node, provides a mapping to the adjacent cell's nod...
virtual size_t GetNumGhostDOFs(const UnknownManager &unknown_manager) const =0
const CoordinateSystemType coord_sys_type_
SpatialDiscretization(const chi_mesh::MeshContinuum &grid, CoordinateSystemType cs_type, SDMType sdm_type)
const chi_mesh::MeshContinuum & ref_grid_
std::vector< Unknown > unknowns_
unsigned int GetTotalUnknownStructureSize() const
std::vector< CellFace > faces_
LocalCellHandler local_cells
void CopyVecToSTLvectorWithGhosts(Vec x, std::vector< double > &data, size_t N, bool resize_STL=true)
void CopyVecToSTLvector(Vec x, std::vector< double > &data, size_t N, bool resize_STL=true)
SpatialDiscretizationType