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