Chi-Tech
LagrangeQuadMapping.cc
Go to the documentation of this file.
2
3#include "mesh/Cell/cell.h"
5
7
9{
10
12 const chi_mesh::Cell& cell,
13 const Quadrature& volume_quadrature,
14 const Quadrature& surface_quadrature)
16 cell,
17 4,
18 MakeFaceNodeMapping(cell),
19 volume_quadrature,
20 surface_quadrature)
21{
22}
23
24double LagrangeQuadMapping::RefShape(uint32_t i, const Vec3& qpoint) const
25{
26 ChiLogicalErrorIf(i >= 4, "Invalid shapefunction index " + std::to_string(i));
27
28 double a, b;
29 // clang-format off
30 if (i == 0) {a = -1.0; b=-1.0;}
31 if (i == 1) {a = 1.0; b=-1.0;}
32 if (i == 2) {a = 1.0; b= 1.0;}
33 if (i == 3) {a = -1.0; b= 1.0;}
34 // clang-format on
35
36 return 0.25 * (1.0 + a * qpoint.x) * (1.0 + b * qpoint.y);
37}
38
40 const Vec3& qpoint) const
41{
42 ChiLogicalErrorIf(i >= 4, "Invalid shapefunction index " + std::to_string(i));
43
44 double a, b;
45 // clang-format off
46 if (i == 0) {a = -1.0; b=-1.0;}
47 if (i == 1) {a = 1.0; b=-1.0;}
48 if (i == 2) {a = 1.0; b= 1.0;}
49 if (i == 3) {a = -1.0; b= 1.0;}
50 // clang-format on
51
52 const double ab = a * b;
53 return Vec3(0.25 * (a + ab * qpoint.y), 0.25 * (b + ab * qpoint.x), 0.0);
54}
55
58{
59 MatDbl J(3, VecDbl(3, 0.0));
60 for (size_t i = 0; i < num_nodes_; ++i)
61 {
62 const Vec3 grad_shape_i = RefGradShape(i, qpoint);
63 const auto& node_i = node_locations_[i];
64 const double x_i = node_i.x;
65 const double y_i = node_i.y;
66
67 // Loops unrolled for performance
68 J[0][0] += grad_shape_i.x * x_i;
69 J[0][1] += grad_shape_i.y * x_i;
70 J[1][0] += grad_shape_i.x * y_i;
71 J[1][1] += grad_shape_i.y * y_i;
72 }
73 J[2][2] = 1.0;
74
75 return J;
76}
77
78std::pair<double, LagrangeBaseMapping::Vec3>
80 size_t face_index, const Vec3& qpoint_face) const
81{
82 // x = sum_i N_i x_i
83 const auto& x0 = node_locations_[face_node_mappings_[face_index][0]];
84 const auto& x1 = node_locations_[face_node_mappings_[face_index][1]];
85 Vec3 dx_dxbar;
86 for (size_t i = 0; i < 2; ++i)
87 {
88 if (i == 0) dx_dxbar += -0.5 * x0;
89 if (i == 1) dx_dxbar += 0.5 * x1;
90 }
91
92 const auto cross = dx_dxbar.Cross(Vec3(0.0,0.0,1.0));
93
94 return {dx_dxbar.Norm(), cross.Normalized()};
95}
96
98 size_t face_index, const Vec3& qpoint_face) const
99{
100 // The quadrature for the face of a quad is a line-quadrature, thus
101 // only x-component has a value.
102 const double x = qpoint_face.x + 1.0;
103 if (face_index == 0) return Vec3(-1.0 + x, -1.0, 0.0);
104 if (face_index == 1) return Vec3(1.0, -1.0 + x, 0.0);
105 if (face_index == 2) return Vec3(1.0 - x, 1.0, 0.0);
106 if (face_index == 3) return Vec3(-1.0, 1.0 - x, 0.0);
107
108 ChiLogicalError("Invalid face index " + std::to_string(face_index));
109}
110
111} // namespace chi_math::cell_mapping
#define ChiLogicalErrorIf(condition, message)
#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
LagrangeQuadMapping(const chi_mesh::MeshContinuum &grid, const chi_mesh::Cell &cell, const Quadrature &volume_quadrature, const Quadrature &surface_quadrature)
Vec3 FaceToElementQPointConversion(size_t face_index, const Vec3 &qpoint_face) const override
Vec3 RefGradShape(uint32_t i, const Vec3 &qpoint) 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
double x
Element-0.
Vector3 Cross(const Vector3 &that) const
double y
Element-1.
double Norm() const