refineable_axisym_advection_diffusion_elements.cc
Go to the documentation of this file.
1// LIC// ====================================================================
2// LIC// This file forms part of oomph-lib, the object-oriented,
3// LIC// multi-physics finite-element library, available
4// LIC// at http://www.oomph-lib.org.
5// LIC//
6// LIC// Copyright (C) 2006-2022 Matthias Heil and Andrew Hazel
7// LIC//
8// LIC// This library is free software; you can redistribute it and/or
9// LIC// modify it under the terms of the GNU Lesser General Public
10// LIC// License as published by the Free Software Foundation; either
11// LIC// version 2.1 of the License, or (at your option) any later version.
12// LIC//
13// LIC// This library is distributed in the hope that it will be useful,
14// LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// LIC// Lesser General Public License for more details.
17// LIC//
18// LIC// You should have received a copy of the GNU Lesser General Public
19// LIC// License along with this library; if not, write to the Free Software
20// LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21// LIC// 02110-1301 USA.
22// LIC//
23// LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24// LIC//
25// LIC//====================================================================
27
28namespace oomph
29{
30 //==========================================================================
31 /// Add the element's contribution to the elemental residual vector
32 /// and/or elemental jacobian matrix.
33 /// This function overloads the standard version so that the possible
34 /// presence of hanging nodes is taken into account.
35 //=========================================================================
38 Vector<double>& residuals,
39 DenseMatrix<double>& jacobian,
40 DenseMatrix<double>& mass_matrix,
41 unsigned flag)
42 {
43 // Find out how many nodes there are in the element
44 const unsigned n_node = nnode();
45
46 // Get the nodal index at which the unknown is stored
47 const unsigned u_nodal_index = this->u_index_axi_adv_diff();
48
49 // Set up memory for the shape and test functions
50 Shape psi(n_node), test(n_node);
51 DShape dpsidx(n_node, 2), dtestdx(n_node, 2);
52
53 // Set the value of n_intpt
54 const unsigned n_intpt = integral_pt()->nweight();
55
56 // Set the Vector to hold local coordinates
58
59 // Get Peclet number
60 const double scaled_peclet = this->pe();
61
62 // Get the Peclet number multiplied by the Strouhal number
63 const double scaled_peclet_st = this->pe_st();
64
65 // Integers used to store the local equation number and local unknown
66 // indices for the residuals and jacobians
67 int local_eqn = 0, local_unknown = 0;
68
69 // Local storage for pointers to hang_info objects
70 HangInfo *hang_info_pt = 0, *hang_info2_pt = 0;
71
72 // Local variable to determine the ALE stuff
73 bool ALE_is_disabled_flag = this->ALE_is_disabled;
74
75 // Loop over the integration points
76 for (unsigned ipt = 0; ipt < n_intpt; ipt++)
77 {
78 // Assign values of s
79 for (unsigned i = 0; i < 2; i++) s[i] = integral_pt()->knot(ipt, i);
80
81 // Get the integral weight
82 double w = integral_pt()->weight(ipt);
83
84 // Call the derivatives of the shape and test functions
86 ipt, psi, dpsidx, test, dtestdx);
87
88 // Premultiply the weights and the Jacobian
89 double W = w * J;
90
91 // Calculate local values of the function, initialise to zero
92 double dudt = 0.0;
93 double interpolated_u = 0.0;
94
95 // These need to be a Vector to be ANSI C++, initialise to zero
97 Vector<double> interpolated_dudx(2, 0.0);
98 Vector<double> mesh_velocity(2, 0.0);
99
100 // Calculate function value and derivatives:
101 //-----------------------------------------
102
103 // Loop over nodes
104 for (unsigned l = 0; l < n_node; l++)
105 {
106 // Get the value at the node
107 double u_value = this->nodal_value(l, u_nodal_index);
108 interpolated_u += u_value * psi(l);
109 dudt += this->du_dt_axi_adv_diff(l) * psi(l);
110 // Loop over directions
111 for (unsigned j = 0; j < 2; j++)
112 {
113 interpolated_x[j] += nodal_position(l, j) * psi(l);
114 interpolated_dudx[j] += u_value * dpsidx(l, j);
115 }
116 }
117
118 // Get the mesh velocity, if required
119 if (!ALE_is_disabled_flag)
120 {
121 for (unsigned l = 0; l < n_node; l++)
122 {
123 // Loop over directions
124 for (unsigned j = 0; j < 2; j++)
125 {
126 mesh_velocity[j] += dnodal_position_dt(l, j) * psi(l);
127 }
128 }
129 }
130
131
132 // Get body force
133 double source;
134 this->get_source_axi_adv_diff(ipt, interpolated_x, source);
135
136
137 // Get wind
138 //--------
139 Vector<double> wind(3);
140 this->get_wind_axi_adv_diff(ipt, s, interpolated_x, wind);
141
142 // r is the first position component
143 double r = interpolated_x[0];
144
145 // Assemble residuals and Jacobian
146 //================================
147
148 // Loop over the nodes for the test functions
149 for (unsigned l = 0; l < n_node; l++)
150 {
151 // Local variables to store the number of master nodes and
152 // the weight associated with the shape function if the node is hanging
153 unsigned n_master = 1;
154 double hang_weight = 1.0;
155 // Local bool (is the node hanging)
156 bool is_node_hanging = this->node_pt(l)->is_hanging();
157
158 // If the node is hanging, get the number of master nodes
159 if (is_node_hanging)
160 {
161 hang_info_pt = this->node_pt(l)->hanging_pt();
162 n_master = hang_info_pt->nmaster();
163 }
164 // Otherwise there is just one master node, the node itself
165 else
166 {
167 n_master = 1;
168 }
169
170 // Loop over the number of master nodes
171 for (unsigned m = 0; m < n_master; m++)
172 {
173 // Get the local equation number and hang_weight
174 // If the node is hanging
175 if (is_node_hanging)
176 {
177 // Read out the local equation from the master node
178 local_eqn = this->local_hang_eqn(hang_info_pt->master_node_pt(m),
179 u_nodal_index);
180 // Read out the weight from the master node
181 hang_weight = hang_info_pt->master_weight(m);
182 }
183 // If the node is not hanging
184 else
185 {
186 // The local equation number comes from the node itself
187 local_eqn = this->nodal_local_eqn(l, u_nodal_index);
188 // The hang weight is one
189 hang_weight = 1.0;
190 }
191
192 // If the nodal equation is not a boundary conditino
193 if (local_eqn >= 0)
194 {
195 // Add du/dt and body force/source term here
196 residuals[local_eqn] -= (scaled_peclet_st * dudt + source) * r *
197 test(l) * W * hang_weight;
198
199 // The Advection Diffusion bit itself
200 residuals[local_eqn] -=
201 // radial terms
202 (interpolated_dudx[0] *
203 (scaled_peclet * wind[0] * test(l) + dtestdx(l, 0)) +
204 // azimuthal terms
205 (interpolated_dudx[1] *
206 (scaled_peclet * wind[1] * test(l) + dtestdx(l, 1)))) *
207 r * W * hang_weight;
208
209 // ALE terms
210 if (!ALE_is_disabled)
211 {
212 residuals[local_eqn] +=
213 scaled_peclet_st *
214 (mesh_velocity[0] * interpolated_dudx[0] +
215 mesh_velocity[1] * interpolated_dudx[1]) *
216 test(l) * r * W * hang_weight;
217 }
218
219
220 // Calculate the Jacobian
221 if (flag)
222 {
223 // Local variables to store the number of master nodes
224 // and the weights associated with each hanging node
225 unsigned n_master2 = 1;
226 double hang_weight2 = 1.0;
227 // Loop over the nodes for the variables
228 for (unsigned l2 = 0; l2 < n_node; l2++)
229 {
230 // Local bool (is the node hanging)
231 bool is_node2_hanging = this->node_pt(l2)->is_hanging();
232 // If the node is hanging, get the number of master nodes
233 if (is_node2_hanging)
234 {
235 hang_info2_pt = this->node_pt(l2)->hanging_pt();
236 n_master2 = hang_info2_pt->nmaster();
237 }
238 // Otherwise there is one master node, the node itself
239 else
240 {
241 n_master2 = 1;
242 }
243
244 // Loop over the master nodes
245 for (unsigned m2 = 0; m2 < n_master2; m2++)
246 {
247 // Get the local unknown and weight
248 // If the node is hanging
249 if (is_node2_hanging)
250 {
251 // Read out the local unknown from the master node
252 local_unknown = this->local_hang_eqn(
253 hang_info2_pt->master_node_pt(m2), u_nodal_index);
254 // Read out the hanging weight from the master node
255 hang_weight2 = hang_info2_pt->master_weight(m2);
256 }
257 // If the node is not hanging
258 else
259 {
260 // The local unknown number comes from the node
261 local_unknown = this->nodal_local_eqn(l2, u_nodal_index);
262 // The hang weight is one
263 hang_weight2 = 1.0;
264 }
265
266 // If the unknown is not pinned
267 if (local_unknown >= 0)
268 {
269 // Add contribution to Elemental Matrix
270 // Mass matrix du/dt term
271 jacobian(local_eqn, local_unknown) -=
272 scaled_peclet_st * test(l) * psi(l2) *
273 this->node_pt(l2)->time_stepper_pt()->weight(1, 0) * r *
274 W * hang_weight * hang_weight2;
275
276 // Add contribution to mass matrix
277 if (flag == 2)
278 {
279 mass_matrix(local_eqn, local_unknown) +=
280 scaled_peclet_st * test(l) * psi(l2) * r * W *
281 hang_weight * hang_weight2;
282 }
283
284 // Add contribution to Elemental Matrix
285 // Assemble Jacobian term
286 jacobian(local_eqn, local_unknown) -=
287 // radial terms
288 (dpsidx(l2, 0) *
289 (scaled_peclet * wind[0] * test(l) + dtestdx(l, 0)) +
290 // azimuthal terms
291 (dpsidx(l2, 1) *
292 (scaled_peclet * wind[1] * test(l) + dtestdx(l, 1)))) *
293 r * W * hang_weight * hang_weight2;
294
295 if (!ALE_is_disabled)
296 {
297 jacobian(local_eqn, local_unknown) +=
298 scaled_peclet_st *
299 (mesh_velocity[0] * dpsidx(l2, 0) +
300 mesh_velocity[1] * dpsidx(l2, 1)) *
301 test(l) * r * W * hang_weight * hang_weight2;
302 }
303 }
304 } // End of loop over master nodes
305 } // End of loop over nodes
306 } // End of Jacobian calculation
307
308 } // End of non-zero equation
309
310 } // End of loop over the master nodes for residual
311 } // End of loop over nodes
312
313 } // End of loop over integration points
314 }
315
316
317 //====================================================================
318 // Force build of templates
319 //====================================================================
323
324} // namespace oomph
static char t char * s
Definition: cfortran.h:568
cstr elem_len * i
Definition: cfortran.h:603
virtual void get_wind_axi_adv_diff(const unsigned &ipt, const Vector< double > &s, const Vector< double > &x, Vector< double > &wind) const
Get wind at (Eulerian) position x and/or local coordinate s. This function is virtual to allow overlo...
virtual unsigned u_index_axi_adv_diff() const
Broken assignment operator.
double du_dt_axi_adv_diff(const unsigned &n) const
du/dt at local node n. Uses suitably interpolated value for hanging nodes.
const double & pe_st() const
Peclet number multiplied by Strouhal number.
virtual double dshape_and_dtest_eulerian_at_knot_axi_adv_diff(const unsigned &ipt, Shape &psi, DShape &dpsidx, Shape &test, DShape &dtestdx) const =0
Shape/test functions and derivs w.r.t. to global coords at integration point ipt; return Jacobian of ...
bool ALE_is_disabled
Boolean flag to indicate whether AlE formulation is disable.
virtual void get_source_axi_adv_diff(const unsigned &ipt, const Vector< double > &x, double &source) const
Get source term at (Eulerian) position x. This function is virtual to allow overloading in multi-phys...
A Class for the derivatives of shape functions The class design is essentially the same as Shape,...
Definition: shape.h:278
TimeStepper *& time_stepper_pt()
Return the pointer to the timestepper.
Definition: nodes.h:238
Integral *const & integral_pt() const
Return the pointer to the integration scheme (const version)
Definition: elements.h:1963
double nodal_value(const unsigned &n, const unsigned &i) const
Return the i-th value stored at local node n. Produces suitably interpolated values for hanging nodes...
Definition: elements.h:2593
virtual double interpolated_x(const Vector< double > &s, const unsigned &i) const
Return FE interpolated coordinate x[i] at local coordinate s.
Definition: elements.cc:3962
int nodal_local_eqn(const unsigned &n, const unsigned &i) const
Return the local equation number corresponding to the i-th value at the n-th local node.
Definition: elements.h:1432
unsigned nnode() const
Return the number of nodes.
Definition: elements.h:2210
double nodal_position(const unsigned &n, const unsigned &i) const
Return the i-th coordinate at local node n. If the node is hanging, the appropriate interpolation is ...
Definition: elements.h:2317
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition: elements.h:2175
double dnodal_position_dt(const unsigned &n, const unsigned &i) const
Return the i-th component of nodal velocity: dx/dt at local node n.
Definition: elements.h:2333
Class that contains data for hanging nodes.
Definition: nodes.h:742
Node *const & master_node_pt(const unsigned &i) const
Return a pointer to the i-th master node.
Definition: nodes.h:791
unsigned nmaster() const
Return the number of master nodes.
Definition: nodes.h:785
double const & master_weight(const unsigned &i) const
Return weight for dofs on i-th master node.
Definition: nodes.h:808
virtual double knot(const unsigned &i, const unsigned &j) const =0
Return local coordinate s[j] of i-th integration point.
virtual unsigned nweight() const =0
Return the number of integration points of the scheme.
virtual double weight(const unsigned &i) const =0
Return weight of i-th integration point.
bool is_hanging() const
Test whether the node is geometrically hanging.
Definition: nodes.h:1285
HangInfo *const & hanging_pt() const
Return pointer to hanging node data (this refers to the geometric hanging node status) (const version...
Definition: nodes.h:1228
void fill_in_generic_residual_contribution_axi_adv_diff(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix, unsigned flag)
Add the element's contribution to the elemental residual vector and/or Jacobian matrix flag=1: comput...
int local_hang_eqn(Node *const &node_pt, const unsigned &i)
Access function that returns the local equation number for the hanging node variables (values stored ...
Refineable version of QAxisymAdvectionDiffusionElement. Inherit from the standard QAxisymAdvectionDif...
A Class for shape functions. In simple cases, the shape functions have only one index that can be tho...
Definition: shape.h:76
virtual double weight(const unsigned &i, const unsigned &j) const
Access function for j-th weight for the i-th derivative.
Definition: timesteppers.h:594
//////////////////////////////////////////////////////////////////// ////////////////////////////////...