Chi-Tech
pwl_polygon_02_xy_shapefunc.cc
Go to the documentation of this file.
2
4
6{
7
8//###################################################################
9/**Returns the value of the shape function given cartesian
10 * coordinates.*/
11double
13 ShapeValue(const int i, const chi_mesh::Vector3& xyz) const
14{
15 for (int s=0; s < num_of_subtris_; s++)
16 {
17 const auto& p0 = ref_grid_.vertices[sides_[s].v_index[0]];
18 chi_mesh::Vector3 xyz_ref = xyz - p0;
19
20 chi_mesh::Vector3 xi_eta_zeta = sides_[s].Jinv * xyz_ref;
21
22 double xi = xi_eta_zeta.x;
23 double eta = xi_eta_zeta.y;
24
25 //Determine if inside tet
26 if ((xi>=-1.0e-12) and (eta>=-1.0e-12) and
27 ((xi + eta)<=(1.0+1.0e-12)))
28 {
29 int index = node_to_side_map_[i][s];
30 double value = 0.0;
31
32 if (index==0)
33 {
34 value = 1.0 - xi - eta;
35 }
36 if (index==1)
37 {
38 value = xi;
39 }
40
41 value += beta_ * eta;
42
43 return value;
44 }
45 }
46
47 return 0.0;
48}
49
50//###################################################################
51/**Populates shape_values with the value of each shape function's
52 * value evaluate at the supplied point.*/
55 std::vector<double> &shape_values) const
56{
57 shape_values.resize(num_nodes_, 0.0);
58 for (int s=0; s < num_of_subtris_; s++)
59 {
60 const auto& p0 = ref_grid_.vertices[sides_[s].v_index[0]];
61 chi_mesh::Vector3 xi_eta_zeta = sides_[s].Jinv * (xyz - p0);
62
63 double xi = xi_eta_zeta.x;
64 double eta = xi_eta_zeta.y;
65
66 //Determine if inside tet
67 if ((xi>=-1.0e-12) and (eta>=-1.0e-12) and
68 ((xi + eta)<=(1.0+1.0e-12)))
69 {
70 for (int i=0; i < num_nodes_; i++)
71 {
72 int index = node_to_side_map_[i][s];
73 double value = 0.0;
74
75 if (index==0)
76 {
77 value = 1.0 - xi - eta;
78 }
79 if (index==1)
80 {
81 value = xi;
82 }
83
84 value += beta_ * eta;
85
86 shape_values[i] = value;
87 }
88 return;
89 }//if in triangle
90 }//for side
91}
92
93//###################################################################
94/**Returns the evaluation of grad-shape function i at the supplied point.*/
96 GradShapeValue(const int i,
97 const chi_mesh::Vector3& xyz) const
98{
99 chi_mesh::Vector3 grad_r;
101
102 for (int e=0; e < num_of_subtris_; e++)
103 {
104 const auto& p0 = ref_grid_.vertices[sides_[e].v_index[0]];
105 chi_mesh::Vector3 xyz_ref = xyz - p0;
106
107 chi_mesh::Vector3 xi_eta_zeta = sides_[e].Jinv * xyz_ref;
108
109 double xi = xi_eta_zeta.x;
110 double eta = xi_eta_zeta.y;
111
112 if ((xi>=-1.0e-12) and (eta>=-1.0e-12) and
113 ((xi + eta)<=(1.0+1.0e-12)))
114 {
115 int index = node_to_side_map_[i][e];
116
117 if (index == 0)
118 {
119 grad_r.x += -1.0;
120 grad_r.y += -1.0;
121 }
122 if (index == 1)
123 {
124 grad_r.x += 1.0;
125 grad_r.y += 0.0;
126 }
127
128 grad_r.y += beta_ * 1.0;
129
130 grad = sides_[e].JTinv * grad_r;
131
132 return grad;
133 }
134 }
135
136 return grad;
137}
138
139//###################################################################
140/**Populates gradshape_values with the value of each shape function's
141 * gradient evaluated at the supplied point.*/
143 const chi_mesh::Vector3 &xyz,
144 std::vector<chi_mesh::Vector3> &gradshape_values) const
145{
146 gradshape_values.clear();
147 for (int i=0; i < num_nodes_; ++i)
148 gradshape_values.emplace_back(GradShapeValue(i,xyz));
149}
150
151}
152
const chi_mesh::MeshContinuum & ref_grid_
Definition: CellMapping.h:117
const size_t num_nodes_
Definition: CellMapping.h:120
chi_mesh::Vector3 GradShapeValue(int i, const chi_mesh::Vector3 &xyz) const override
void ShapeValues(const chi_mesh::Vector3 &xyz, std::vector< double > &shape_values) const override
double ShapeValue(int i, const chi_mesh::Vector3 &xyz) const override
void GradShapeValues(const chi_mesh::Vector3 &xyz, std::vector< chi_mesh::Vector3 > &gradshape_values) const override
double x
Element-0.
double y
Element-1.