Chi-Tech
SpatialDiscretization.h
Go to the documentation of this file.
1#ifndef SPATIAL_DISCRETIZATION_H
2#define SPATIAL_DISCRETIZATION_H
3
4#include "mesh/chi_mesh.h"
6#include "math/chi_math.h"
8#include "mesh/Cell/cell.h"
10
11#include <petscksp.h>
12
13#include <vector>
14#include <map>
15
16namespace chi_math
17{
19{
20public:
22
23 /**Utility method for getting node indices seperately for domain internal
24 * local nodes, and boundary nodes.*/
25 std::pair<std::set<uint32_t>, std::set<uint32_t>>
27
28 // 01 AddViewOfContinuum
29 const CellMapping& GetCellMapping(const chi_mesh::Cell& cell) const;
31 /**Returns the reference grid on which this discretization is based.*/
32 const chi_mesh::MeshContinuum& Grid() const;
34
35 // 02 OrderNodes
36
37 // 03
38 /**Builds the sparsity pattern for a local block matrix compatible with
39 * the given unknown manager. The modified vectors are: `nodal_nnz_in_diag`
40 * which specifies for each row the number of non-zeros in the local diagonal
41 * block, `nodal_nnz_off_diag` which specifies for each row the number of
42 * non-zeros in the off-diagonal block.*/
43 virtual void
44 BuildSparsityPattern(std::vector<int64_t>& nodal_nnz_in_diag,
45 std::vector<int64_t>& nodal_nnz_off_diag,
46 const UnknownManager& unknown_manager) const = 0;
47
48 // 04 Mappings
49 /**Maps the global address of a degree of freedom.*/
50 virtual int64_t MapDOF(const chi_mesh::Cell& cell,
51 unsigned int node,
52 const UnknownManager& unknown_manager,
53 unsigned int unknown_id,
54 unsigned int component) const = 0;
55
56 /**Maps the local address of a degree of freedom. This can include
57 * ghost entries if the specific discretization has any.*/
58 virtual int64_t MapDOFLocal(const chi_mesh::Cell& cell,
59 unsigned int node,
60 const UnknownManager& unknown_manager,
61 unsigned int unknown_id,
62 unsigned int component) const = 0;
63
64 /**Maps the local address of a degree of freedom. This can include
65 * ghost entries if the specific discretization has any. Default structure
66 * here is a single scalar unknown.*/
67 virtual int64_t MapDOF(const chi_mesh::Cell& cell,
68 unsigned int node) const = 0;
69 /**Maps the local address of a degree of freedom. This can include
70 * ghost entries if the specific discretization has any. Default structure
71 * here is a single scalar unknown.*/
72 virtual int64_t MapDOFLocal(const chi_mesh::Cell& cell,
73 unsigned int node) const = 0;
74
75 // 05 Utils
76 /**For the unknown structure in the unknown manager, returns the
77 * number of local degrees-of-freedom.*/
78 size_t GetNumLocalDOFs(const UnknownManager& unknown_manager) const;
79 /**For the unknown structure in the unknown manager, returns the
80 * number of global degrees-of-freedom.*/
81 size_t GetNumGlobalDOFs(const UnknownManager& unknown_manager) const;
82
83 /**For the unknown structure in the unknown manager, returns the
84 * number of ghost degrees-of-freedom.*/
85 virtual size_t
86 GetNumGhostDOFs(const UnknownManager& unknown_manager) const = 0;
87 /**For the unknown structure in the unknown manager, returns the
88 * global IDs of all the ghost degrees-of-freedom.*/
89 virtual std::vector<int64_t>
90 GetGhostDOFIndices(const UnknownManager& unknown_manager) const = 0;
91
92 /**For the unknown structure in the unknown manager, returns the
93 * number of local- and ghost degrees-of-freedom.*/
94 size_t GetNumLocalAndGhostDOFs(const UnknownManager& unknown_manager) const;
95
96 /**For the given cell, returns the number of relevant nodes. The same can
97 * be achieved by retrieving the cell-to-element mapping first.*/
98 size_t GetCellNumNodes(const chi_mesh::Cell& cell) const;
99
100 /**For the given cell, returns a reference to the relevant node locations.
101 * The same can be achieved by retrieving the cell-to-element mapping first.*/
102 const std::vector<chi_mesh::Vector3>&
103 GetCellNodeLocations(const chi_mesh::Cell& cell) const;
104
105 /**\brief For each local cell, for each face, for each face-node, provides a
106 mapping to the adjacent cell's nodes.*/
107 std::vector<std::vector<std::vector<int>>>
108 MakeInternalFaceNodeMappings(double tolerance = 1.0e-12) const;
109
110 /**Copies DOFs from the from_vector to the to_vector, however, both vectors
111 * have the unknown-structure specified, and the given from_vec_uk_id is
112 * copied to the to_vec_uk_id.*/
113 void CopyVectorWithUnknownScope(const std::vector<double>& from_vector,
114 std::vector<double>& to_vector,
115 const UnknownManager& from_vec_uk_structure,
116 unsigned int from_vec_uk_id,
117 const UnknownManager& to_vec_uk_structure,
118 unsigned int to_vec_uk_id) const;
119
120 /**Develops a localized view of a petsc vector.
121 * Each spatial discretization can have a specialization of this
122 * method.*/
123 virtual void LocalizePETScVector(Vec petsc_vector,
124 std::vector<double>& local_vector,
125 const UnknownManager& unknown_manager) const;
126 /**Develops a localized view of a petsc vector.
127 * Each spatial discretization can have a specialization of this
128 * method.*/
129 virtual void
131 std::vector<double>& local_vector,
132 const UnknownManager& unknown_manager) const;
133
134 /**Cartesian coordinate system spatial weighting function.*/
135 static double CartesianSpatialWeightFunction(const chi_mesh::Vector3& point);
136 /**Cylindrical coordinate system (RZ) spatial weighting function.*/
137 static double
139 /**Spherical coordinate system (1D Spherical) spatial weighting function.*/
140 static double
142
143 typedef std::function<double(const chi_mesh::Vector3&)> SpatialWeightFunction;
144
145 /**Returns the spatial weighting function appropriate to the discretization's
146 * coordinate system.*/
148
149 virtual ~SpatialDiscretization() = default;
150
151protected:
153 // 00
155 CoordinateSystemType cs_type,
156 SDMType sdm_type);
157
159 std::vector<std::unique_ptr<CellMapping>> cell_mappings_;
160 std::map<uint64_t, std::shared_ptr<CellMapping>> nb_cell_mappings_;
161
163 std::vector<uint64_t> locJ_block_address_;
164 std::vector<uint64_t> locJ_block_size_;
165
168
170
171private:
173};
174} // namespace chi_math
175
176#endif
virtual std::vector< int64_t > GetGhostDOFIndices(const UnknownManager &unknown_manager) const =0
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_
virtual int64_t MapDOF(const chi_mesh::Cell &cell, unsigned int node) const =0
std::vector< uint64_t > locJ_block_size_
size_t GetNumGlobalDOFs(const UnknownManager &unknown_manager) const
virtual ~SpatialDiscretization()=default
CoordinateSystemType GetCoordinateSystemType() const
const chi_mesh::MeshContinuum & Grid() const
SpatialDiscretizationType SDMType
virtual int64_t MapDOF(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const =0
virtual void BuildSparsityPattern(std::vector< int64_t > &nodal_nnz_in_diag, std::vector< int64_t > &nodal_nnz_off_diag, const UnknownManager &unknown_manager) const =0
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
SpatialWeightFunction GetSpatialWeightingFunction() const
const SpatialDiscretizationType type_
virtual int64_t MapDOFLocal(const chi_mesh::Cell &cell, unsigned int node) const =0
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
const UnknownManager UNITARY_UNKNOWN_MANAGER
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
std::vector< uint64_t > locJ_block_address_
const CoordinateSystemType coord_sys_type_
SpatialDiscretization(const chi_mesh::MeshContinuum &grid, CoordinateSystemType cs_type, SDMType sdm_type)
const chi_mesh::MeshContinuum & ref_grid_
SpatialDiscretizationType
Definition: chi_math.h:37
CoordinateSystemType
Definition: chi_math.h:29
struct _p_Vec * Vec