Chi-Tech
LagrangeWedgeMapping.cc
Go to the documentation of this file.
2
3#include "mesh/Cell/cell.h"
4
6
8{
9
11 const chi_mesh::MeshContinuum& grid,
12 const chi_mesh::Cell& cell,
13 const Quadrature& volume_quadrature,
14 const Quadrature& surface_quadrature,
15 const Quadrature& aux_surface_quadrature)
17 cell,
18 6,
19 MakeFaceNodeMapping(cell),
20 volume_quadrature,
21 surface_quadrature),
22 aux_surface_quadrature_(aux_surface_quadrature)
23{
24}
25
26double LagrangeWedgeMapping::RefShape(uint32_t i, const Vec3& qpoint) const
27{
28 const double x = qpoint.x;
29 const double y = qpoint.y;
30 const double z = qpoint.z;
31
32 // clang-format off
33 if (i == 0) return (1.0 - x - y) * 0.5 * (1.0 - z);
34 if (i == 1) return x * 0.5 * (1.0 - z);
35 if (i == 2) return y * 0.5 * (1.0 - z);
36
37 if (i == 3) return (1.0 - x - y) * 0.5 * (1.0 + z);
38 if (i == 4) return x * 0.5 * (1.0 + z);
39 if (i == 5) return y * 0.5 * (1.0 + z);
40 // clang-format on
41
42 ChiLogicalError("Invalid shapefunction index " + std::to_string(i));
43}
44
46 const Vec3& qpoint) const
47{
48
49 const double x = qpoint.x;
50 const double y = qpoint.y;
51 const double z = qpoint.z;
52
53 // clang-format off
54 if (i == 0) return Vec3(-0.5 * (1.0 - z), -0.5 * (1.0 - z), -0.5 * (1.0 - x - y));
55 if (i == 1) return Vec3( 0.5 * (1.0 - z), 0.0, -0.5 * x);
56 if (i == 2) return Vec3( 0.0, 0.5 * (1.0 - z), -0.5 * y);
57
58 if (i == 3) return Vec3(-0.5 * (1.0 + z), -0.5 * (1.0 + z), 0.5 * (1.0 - x - y));
59 if (i == 4) return Vec3( 0.5 * (1.0 + z), 0.0, 0.5 * x);
60 if (i == 5) return Vec3( 0.0, 0.5 * (1.0 + z), 0.5 * y);
61 // clang-format on
62
63 ChiLogicalError("Invalid shapefunction index " + std::to_string(i));
64}
65
68{
69 MatDbl J(3, VecDbl(3, 0.0));
70 for (size_t i = 0; i < num_nodes_; ++i)
71 {
72 const Vec3 grad_shape_i = RefGradShape(i, qpoint);
73 const auto& node_i = node_locations_[i];
74 const double x_i = node_i.x;
75 const double y_i = node_i.y;
76 const double z_i = node_i.z;
77
78 // Loops unrolled for performance
79 J[0][0] += grad_shape_i.x * x_i;
80 J[0][1] += grad_shape_i.y * x_i;
81 J[0][2] += grad_shape_i.z * x_i;
82
83 J[1][0] += grad_shape_i.x * y_i;
84 J[1][1] += grad_shape_i.y * y_i;
85 J[1][2] += grad_shape_i.z * y_i;
86
87 J[2][0] += grad_shape_i.x * z_i;
88 J[2][1] += grad_shape_i.y * z_i;
89 J[2][2] += grad_shape_i.z * z_i;
90 }
91
92 return J;
93}
94
95std::pair<double, LagrangeBaseMapping::Vec3>
97 size_t face_index, const Vec3& qpoint_face) const
98{
99 if (face_index <= 2)
100 {
101 const auto& x0 = node_locations_[face_node_mappings_[face_index][0]];
102 const auto& x1 = node_locations_[face_node_mappings_[face_index][1]];
103 const auto& x2 = node_locations_[face_node_mappings_[face_index][2]];
104 const auto& x3 = node_locations_[face_node_mappings_[face_index][3]];
105
106 const double xbar = qpoint_face.x;
107 const double ybar = qpoint_face.y;
108 Vec3 dx_dxbar;
109 Vec3 dx_dybar;
110 for (size_t i = 0; i < 4; ++i)
111 {
112 double a, b;
113 Vec3 xi;
114 // clang-format off
115 if (i == 0) {a = -1.0; b=-1.0; xi = x0;}
116 if (i == 1) {a = 1.0; b=-1.0; xi = x1;}
117 if (i == 2) {a = 1.0; b= 1.0; xi = x2;}
118 if (i == 3) {a = -1.0; b= 1.0; xi = x3;}
119 // clang-format on
120
121 const double ab = a * b;
122 dx_dxbar += 0.25 * (a + ab * ybar) * xi;
123 dx_dybar += 0.25 * (b + ab * xbar) * xi;
124 }
125
126 const auto cross = dx_dxbar.Cross(dx_dybar);
127
128 return {cross.Norm(), cross.Normalized()};
129 }
130 else
131 {
132 const auto& x0 = node_locations_[face_node_mappings_[face_index][0]];
133 const auto& x1 = node_locations_[face_node_mappings_[face_index][1]];
134 const auto& x2 = node_locations_[face_node_mappings_[face_index][2]];
135
136 Vec3 dx_dxbar;
137 Vec3 dx_dybar;
138 for (size_t i = 0; i < 3; ++i)
139 {
140 double dN_dxbar, dN_dybar;
141 Vec3 xi;
142 // clang-format off
143 if (i == 0) {dN_dxbar = -1.0; dN_dybar=-1.0; xi = x0;}
144 if (i == 1) {dN_dxbar = 1.0; dN_dybar= 0.0; xi = x1;}
145 if (i == 2) {dN_dxbar = 0.0; dN_dybar= 1.0; xi = x2;}
146 // clang-format on
147
148 dx_dxbar += dN_dxbar * xi;
149 dx_dybar += dN_dybar * xi;
150 }
151
152 const auto cross = dx_dxbar.Cross(dx_dybar);
153 const double detJ = cross.Norm();
154
155 return {detJ, cross/detJ};
156 }
157}
158
160 size_t face_index, const Vec3& qpoint_face) const
161{
162 if (face_index <= 2)
163 {
164
165 const double x = 0.5*(qpoint_face.x + 1.0);
166 const double y = qpoint_face.y + 1.0;
167
168 // clang-format off
169 if (face_index == 0/*Side0*/) return Vec3( x, 0.0, -1.0 + y);
170 if (face_index == 1/*Side1*/) return Vec3(1.0-x, x, -1.0 + y);
171 if (face_index == 2/*Side2*/) return Vec3( 0.0, 1.0-x, -1.0 + y);
172 // clang-format on
173 }
174 else
175 {
176 const double x = qpoint_face.x;
177 const double y = qpoint_face.y;
178 // clang-format off
179 if (face_index == 3/*ZMAX*/) return Vec3( x, y, 1.0);
180 if (face_index == 4/*ZMIN*/) return Vec3( x, y, -1.0);
181 // clang-format on
182 }
183
184 ChiLogicalError("Invalid face index " + std::to_string(face_index));
185}
186
187const Quadrature&
189{
190 if (face_index <= 2) return surface_quadrature_;
191 else
193}
194
195} // namespace chi_math::cell_mapping
#define ChiLogicalError(message)
const std::vector< std::vector< int > > face_node_mappings_
Definition: CellMapping.h:130
const std::vector< chi_mesh::Vector3 > node_locations_
Definition: CellMapping.h:121
const size_t num_nodes_
Definition: CellMapping.h:120
MatDbl RefJacobian(const Vec3 &qpoint) const override
const Quadrature & GetSurfaceQuadrature(size_t face_index) const override
Vec3 RefGradShape(uint32_t i, const Vec3 &qpoint) const override
Vec3 FaceToElementQPointConversion(size_t face_index, const Vec3 &qpoint_face) const override
std::pair< double, Vec3 > RefFaceJacobianDeterminantAndNormal(size_t face_index, const Vec3 &qpoint_face) const override
double RefShape(uint32_t i, const Vec3 &qpoint) const override
LagrangeWedgeMapping(const chi_mesh::MeshContinuum &grid, const chi_mesh::Cell &cell, const Quadrature &volume_quadrature, const Quadrature &surface_quadrature, const Quadrature &aux_surface_quadrature)
double x
Element-0.
Vector3 Cross(const Vector3 &that) const
double y
Element-1.
double z
Element-2.
double Norm() const