Chi-Tech
CellMapping.cc
Go to the documentation of this file.
2
3#include <utility>
4
6
8
9namespace chi_math
10{
11
13 const chi_mesh::Cell& cell,
14 size_t num_nodes,
15 std::vector<chi_mesh::Vector3> node_locations,
16 std::vector<std::vector<int>> face_node_mappings,
17 const VandAFunction& volume_area_function)
18 : ref_grid_(grid),
19 cell_(cell),
20 num_nodes_(num_nodes),
21 node_locations_(std::move(node_locations)),
22 face_node_mappings_(std::move(face_node_mappings))
23{
24 volume_area_function(ref_grid_, cell, volume_, areas_);
25}
26
28
30{
31 return ref_grid_;
32}
33
34size_t CellMapping::NumNodes() const { return num_nodes_; }
35
36size_t CellMapping::NumFaceNodes(size_t face_index) const
37{
38 return face_node_mappings_.at(face_index).size();
39}
40
41const std::vector<std::vector<int>>& CellMapping::GetFaceNodeMappings() const
42{
44}
45
46double CellMapping::CellVolume() const { return volume_; }
47
48double CellMapping::FaceArea(size_t face_index) const
49{
50 return areas_[face_index];
51}
52
53int CellMapping::MapFaceNode(size_t face_index, size_t face_node_index) const
54{
55 try
56 {
57 return face_node_mappings_.at(face_index).at(face_node_index);
58 }
59 catch (const std::out_of_range& oor)
60 {
61 throw std::out_of_range(
62 "chi_math::CellMapping::MapFaceNode: "
63 "Either face_index or face_node_index is out of range");
64 }
65}
66
68 const chi_mesh::Cell& cell,
69 double& volume,
70 std::vector<double>& areas)
71{
72 switch (cell.Type())
73 {
75 {
76 const auto& v0 = grid.vertices[cell.vertex_ids_[0]];
77 const auto& v1 = grid.vertices[cell.vertex_ids_[1]];
78
79 volume = (v1 - v0).Norm();
80 areas = {1.0, 1.0};
81 break;
82 }
84 {
85 volume = 0.0;
86 const auto& v2 = cell.centroid_;
87
88 size_t num_faces = cell.faces_.size();
89 areas.reserve(num_faces);
90
91 for (size_t f = 0; f < num_faces; ++f)
92 {
93 const uint64_t v0i = cell.faces_[f].vertex_ids_[0];
94 const uint64_t v1i = cell.faces_[f].vertex_ids_[1];
95
96 const auto& v0 = grid.vertices[v0i];
97 const auto& v1 = grid.vertices[v1i];
98
99 areas.push_back((v1 - v0).Norm());
100
101 const chi_mesh::Vector3 sidev01 = v1 - v0;
102 const chi_mesh::Vector3 sidev02 = v2 - v0;
103
104 double sidedetJ =
105 ((sidev01.x) * (sidev02.y) - (sidev02.x) * (sidev01.y));
106
107 volume += sidedetJ / 2.0;
108 } // for face
109
110 break;
111 }
113 {
114 volume = 0.0;
115 const auto& vcc = cell.centroid_;
116
117 size_t num_faces = cell.faces_.size();
118 areas.assign(num_faces, 0.0);
119 for (size_t f = 0; f < num_faces; f++)
120 {
121 const auto& face = cell.faces_[f];
122 const size_t num_edges = face.vertex_ids_.size();
123 for (size_t e = 0; e < num_edges; ++e)
124 {
125 size_t ep1 = (e < (num_edges - 1)) ? e + 1 : 0;
126 uint64_t v0i = face.vertex_ids_[e];
127 uint64_t v1i = face.vertex_ids_[ep1];
128
129 const auto& v0 = grid.vertices[v0i];
130 const auto& v1 = cell.faces_[f].centroid_;
131 const auto& v2 = grid.vertices[v1i];
132 const auto& v3 = vcc;
133
134 const auto sidev01 = v1 - v0;
135 const auto sidev02 = v2 - v0;
136 const auto sidev03 = v3 - v0;
137
139
140 J.SetColJVec(0, sidev01);
141 J.SetColJVec(1, sidev02);
142 J.SetColJVec(2, sidev03);
143
144 areas[f] += (sidev01.Cross(sidev02)).Norm() / 2.0;
145 volume += J.Det() / 6.0;
146 } // for edge
147 } // for face
148 break;
149 }
150 default:
151 throw std::logic_error("chi_math::CellMapping::ComputeCellVolume: "
152 "Unsupported cell type.");
153 }
154}
155
156const std::vector<chi_mesh::Vector3>& CellMapping::GetNodeLocations() const
157{
158 return node_locations_;
159}
160
161
162} // namespace chi_math
double CellVolume() const
Definition: CellMapping.cc:46
const std::vector< std::vector< int > > & GetFaceNodeMappings() const
Definition: CellMapping.cc:41
int MapFaceNode(size_t face_index, size_t face_node_index) const
Definition: CellMapping.cc:53
const chi_mesh::MeshContinuum & ReferenceGrid() const
Definition: CellMapping.cc:29
CellMapping(const chi_mesh::MeshContinuum &grid, const chi_mesh::Cell &cell, size_t num_nodes, std::vector< chi_mesh::Vector3 > node_locations, std::vector< std::vector< int > > face_node_mappings, const VandAFunction &volume_area_function)
Definition: CellMapping.cc:12
const std::vector< std::vector< int > > face_node_mappings_
Definition: CellMapping.h:130
static void ComputeCellVolumeAndAreas(const chi_mesh::MeshContinuum &grid, const chi_mesh::Cell &cell, double &volume, std::vector< double > &areas)
Definition: CellMapping.cc:67
size_t NumNodes() const
Definition: CellMapping.cc:34
std::function< void(const chi_mesh::MeshContinuum &, const chi_mesh::Cell &, double &, std::vector< double > &)> VandAFunction
Definition: CellMapping.h:102
const std::vector< chi_mesh::Vector3 > node_locations_
Definition: CellMapping.h:121
double FaceArea(size_t face_index) const
Definition: CellMapping.cc:48
const chi_mesh::MeshContinuum & ref_grid_
Definition: CellMapping.h:117
const size_t num_nodes_
Definition: CellMapping.h:120
std::vector< double > areas_
Definition: CellMapping.h:124
size_t NumFaceNodes(size_t face_index) const
Definition: CellMapping.cc:36
const chi_mesh::Cell & ReferenceCell() const
Definition: CellMapping.cc:27
const std::vector< chi_mesh::Vector3 > & GetNodeLocations() const
Definition: CellMapping.cc:156
const chi_mesh::Cell & cell_
Definition: CellMapping.h:118
std::vector< CellFace > faces_
Definition: cell.h:82
CellType Type() const
Definition: cell.h:98
Vertex centroid_
Definition: cell.h:78
std::vector< uint64_t > vertex_ids_
Definition: cell.h:81
void SetColJVec(int j, Vector3 vec)
double Det(int row=0)
double x
Element-0.
double y
Element-1.