Chi-Tech
pwl_polyhedron_00_constrdestr.cc
Go to the documentation of this file.
2
4
5#include "chi_log.h"
7
9{
10
11// ###################################################################
12/**Constructor for the Piecewise Linear Polyhedron cell finite elment
13 * view.
14 *
15 * */
17 const chi_mesh::Cell& polyh_cell,
18 const chi_mesh::MeshContinuum& ref_grid,
19 const chi_math::QuadratureTetrahedron& volume_quadrature,
20 const chi_math::QuadratureTriangle& surface_quadrature)
22 polyh_cell,
23 polyh_cell.vertex_ids_.size(), // num_nodes
24 MakeFaceNodeMapping(polyh_cell)),
25 volume_quadrature_(volume_quadrature),
26 surface_quadrature_(surface_quadrature)
27{
28 //=========================================== Assign cell centre
29 const chi_mesh::Vertex& vcc = polyh_cell.centroid_;
30 alphac_ = 1.0 / static_cast<double>(polyh_cell.vertex_ids_.size());
31
32 //=========================================== For each face
33 size_t num_faces = polyh_cell.faces_.size();
34 face_data_.reserve(num_faces);
35 face_betaf_.reserve(num_faces);
36 for (size_t f = 0; f < num_faces; f++)
37 {
38 const chi_mesh::CellFace& face = polyh_cell.faces_[f];
39 FEface_data face_f_data;
40
41 face_f_data.normal = face.normal_;
42
43 face_betaf_.push_back(1.0 / static_cast<double>(face.vertex_ids_.size()));
44
45 const chi_mesh::Vertex& vfc = face.centroid_;
46
47 //==================================== For each edge
48 const size_t num_edges = face.vertex_ids_.size();
49 face_f_data.sides.reserve(num_edges);
50 for (size_t e = 0; e < num_edges; ++e)
51 {
52 FEside_data3d side_data;
53
54 //============================= Assign vertices of tetrahedron
55 size_t ep1 = (e < (num_edges - 1)) ? e + 1 : 0;
56 uint64_t v0index = face.vertex_ids_[e];
57 uint64_t v1index = face.vertex_ids_[ep1];
58 side_data.v_index.resize(2, -1);
59 side_data.v_index[0] = v0index;
60 side_data.v_index[1] = v1index;
61
62 const auto& v0 = ref_grid_.vertices[v0index];
63 const auto& v1 = vfc;
64 const auto& v2 = ref_grid_.vertices[v1index];
65 const auto& v3 = vcc;
66
67 side_data.v0 = v0;
68
69 //============================= Compute vectors
70 chi_mesh::Vector3 v01 = v1 - v0;
71 chi_mesh::Vector3 v02 = v2 - v0;
72 chi_mesh::Vector3 v03 = v3 - v0;
73
74 //============================= Compute determinant of surface jacobian
75 // First we compute the rotation matrix which will rotate
76 // any vector in natural coordinates to the same reference
77 // frame as the current face.
78 chi_mesh::Vector3 normal = face.normal_ * -1.0;
79 chi_mesh::Vector3 tangent = v02.Cross(normal);
80 tangent = tangent / tangent.Norm();
81 chi_mesh::Vector3 binorm = v02 / v02.Norm();
82
84 R.SetColJVec(0, tangent);
85 R.SetColJVec(1, binorm);
86 R.SetColJVec(2, normal);
87
88 // Now we compute the inverse of this matrix which
89 // will allow us to rotate any vector in the same reference
90 // frame as the face, to natural coordinates
92
93 // Compute v01 and v02 rotated to natural coordinates
94 // A test to see if this is done correctly would be to
95 // check if fabs(v01N.z) < epsilon and fabs(v02N.z) < epsilon
96 chi_mesh::Vector3 v01N = Rinv * v01;
97 chi_mesh::Vector3 v02N = Rinv * v02;
98 side_data.detJ_surf = v01N.x * v02N.y - v01N.y * v02N.x;
99
100 //============================= Compute Jacobian
102 J.SetColJVec(0, v01);
103 J.SetColJVec(1, v02);
104 J.SetColJVec(2, v03);
105
106 side_data.J = J;
107
108 //============================= Compute determinant of jacobian
109 side_data.detJ = J.Det();
110
111 //============================= Compute inverse Jacobian elements
113 chi_mesh::Matrix3x3 Jinv = J.Inverse();
114 chi_mesh::Matrix3x3 JTinv = JT.Inverse();
115
116 side_data.Jinv = Jinv;
117 side_data.JTinv = JTinv;
118
119 face_f_data.sides.push_back(side_data);
120 } // for each edge
121
122 face_data_.push_back(face_f_data);
123 } // for each face
124
125 //================================================ Compute Node-Face-Side
126 // mapping
127 // This section determines the scope of dof_i on
128 // each side (tet) of the cell. If dof_i is on
129 // either of the primary tet nodes, it is given
130 // index 0 or 1 (-1 otherwise). If the index is
131 // -1 the corresponding shapefunction will be
132 // ignored when using Ni. The flag "part_of_face"
133 // is set when dof_i is part of the same face to
134 // which the side belongs and consequently allows
135 // the determination of Nf. Nc is always evaluated
136 // so no mapping is needed.
137 for (int i = 0; i < num_nodes_; i++)
138 {
139 FEnodeMap newNodeMap;
140 for (size_t f = 0; f < face_data_.size(); f++)
141 {
142 FEnodeFaceMap newFaceMap;
143 for (size_t s = 0; s < face_data_[f].sides.size(); s++)
144 {
145 FEnodeSideMap newSideMap;
146 newSideMap.part_of_face = false;
147 const uint64_t s0 = face_data_[f].sides[s].v_index[0];
148 const uint64_t s1 = face_data_[f].sides[s].v_index[1];
149 if (polyh_cell.vertex_ids_[i] == s0)
150 {
151 newSideMap.index = 0;
152 newSideMap.part_of_face = true;
153 }
154 else if (polyh_cell.vertex_ids_[i] == s1)
155 {
156 newSideMap.index = 2;
157 newSideMap.part_of_face = true;
158 }
159 else
160 {
161 newSideMap.index = -1;
162 for (size_t v = 0; v < polyh_cell.faces_[f].vertex_ids_.size(); v++)
163 {
164 if (polyh_cell.vertex_ids_[i] ==
165 polyh_cell.faces_[f].vertex_ids_[v])
166 {
167 newSideMap.part_of_face = true;
168 break;
169 }
170 }
171 }
172 newFaceMap.side_map.push_back(newSideMap);
173 } // for s
174 newNodeMap.face_map.push_back(newFaceMap);
175 } // for f
176 node_side_maps_.push_back(newNodeMap);
177 } // for i
178}
179
180} // namespace chi_math::cell_mapping
const chi_mesh::MeshContinuum & ref_grid_
Definition: CellMapping.h:117
const size_t num_nodes_
Definition: CellMapping.h:120
std::vector< FEnodeMap > node_side_maps_
Maps nodes to side tets.
std::vector< FEface_data > face_data_
Holds determinants and data tet-by-tet.
PieceWiseLinearPolyhedronMapping(const chi_mesh::Cell &polyh_cell, const chi_mesh::MeshContinuum &ref_grid, const QuadratureTetrahedron &volume_quadrature, const QuadratureTriangle &surface_quadrature)
Normal normal_
A list of the vertices.
Definition: cell.h:39
std::vector< uint64_t > vertex_ids_
Definition: cell.h:38
Vertex centroid_
The face centroid.
Definition: cell.h:40
std::vector< CellFace > faces_
Definition: cell.h:82
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.
Vector3 Cross(const Vector3 &that) const
double y
Element-1.
double Norm() const