refineable_linearised_navier_stokes_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// Version 1.0; svn revision $LastChangedRevision: 1097 $
7 //LIC//
8 //LIC// $LastChangedDate: 2015-12-17 11:53:17 +0000 (Thu, 17 Dec 2015) $
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 // Non-inline functions for the refineable linearised axisymmetric
31 // Navier-Stokes elements
32 
33 // oomph-lib includes
35 
36 namespace oomph
37 {
38 
39  //=======================================================================
40  /// Compute the residuals for the refineable linearised axisymmetric
41  /// Navier--Stokes equations; flag=1(or 0): do (or don't) compute the
42  /// Jacobian as well.
43  //=======================================================================
46  Vector<double> &residuals,
47  DenseMatrix<double> &jacobian,
48  DenseMatrix<double> &mass_matrix,
49  unsigned flag)
50  {
51  // Get the time from the first node in the element
52  const double time = this->node_pt(0)->time_stepper_pt()->time();
53 
54  // Determine number of nodes in the element
55  const unsigned n_node = nnode();
56 
57  // Determine how many pressure values there are associated with
58  // a single pressure component
59  const unsigned n_pres = npres_linearised_nst();
60 
61  const unsigned n_veloc = 4*DIM;
62 
63  // Get the nodal indices at which the velocity is stored
64  unsigned u_nodal_index[n_veloc];
65  for(unsigned i=0;i<n_veloc;++i)
66  {
67  u_nodal_index[i] = u_index_linearised_nst(i);
68  }
69 
70  // Which nodal values represent the two pressure components?
71  // (Negative if pressure is not based on nodal interpolation).
72  Vector<int> p_index(2);
73  for(unsigned i=0;i<2;i++)
74  {
75  p_index[i] = this->p_index_linearised_nst(i);
76  }
77 
78  // Local array of booleans that are true if the l-th pressure value is
79  // hanging (avoid repeated virtual function calls)
80  bool pressure_dof_is_hanging[n_pres];
81 
82  // If the pressure is stored at a node
83  if(p_index[0] >= 0)
84  {
85  // Read out whether the pressure is hanging
86  for(unsigned l=0;l<n_pres;++l)
87  {
88  pressure_dof_is_hanging[l] =
89  pressure_node_pt(l)->is_hanging(p_index[0]);
90  }
91  }
92  // Otherwise the pressure is not stored at a node and so cannot hang
93  else
94  {
95  for(unsigned l=0;l<n_pres;++l)
96  {
97  pressure_dof_is_hanging[l] = false;
98  }
99  }
100 
101 
102  // Set up memory for the fluid shape and test functions
103  Shape psif(n_node), testf(n_node);
104  DShape dpsifdx(n_node,DIM), dtestfdx(n_node,DIM);
105 
106  // Set up memory for the pressure shape and test functions
107  Shape psip(n_pres), testp(n_pres);
108 
109  // Determine number of integration points
110  const unsigned n_intpt = integral_pt()->nweight();
111 
112  // Set up memory for the vector to hold local coordinates (two dimensions)
113  Vector<double> s(DIM);
114 
115  // Get physical variables from the element
116  // (Reynolds number must be multiplied by the density ratio)
117  const double scaled_re = re()*density_ratio();
118  const double scaled_re_st = re_st()*density_ratio();
119  const double visc_ratio = viscosity_ratio();
120 
121  const double eval_real = lambda();
122  const double eval_imag = omega();
123 
124  const std::complex<double> eigenvalue(eval_real,eval_imag);
125 
126  // Integers used to store the local equation numbers
127  int local_eqn = 0;
128 
129  // Local storage for pointers to hang info objects
130  HangInfo *hang_info_pt=0;
131 
132  // Loop over the integration points
133  for(unsigned ipt=0;ipt<n_intpt;ipt++)
134  {
135  // Assign values of the local coordinates s
136  for(unsigned i=0;i<DIM;i++) { s[i] = integral_pt()->knot(ipt,i); }
137 
138  // Get the integral weight
139  const double w = integral_pt()->weight(ipt);
140 
141  // Calculate the fluid shape and test functions, and their derivatives
142  // w.r.t. the global coordinates
143  const double J =
145  testf,dtestfdx);
146 
147  // Calculate the pressure shape and test functions
148  pshape_linearised_nst(s,psip,testp);
149 
150  // Premultiply the weights and the Jacobian of the mapping between
151  // local and global coordinates
152  const double W = w*J;
153 
154  // Allocate storage for the position and the derivative of the
155  // mesh positions w.r.t. time
157  //Vector<double> mesh_velocity(2,0.0);
158 
159  // Allocate storage for the velocity components (six of these)
160  // and their derivatives w.r.t. time
161  Vector<std::complex< double> > interpolated_u(DIM);
162  //Vector<double> dudt(6,0.0);
163  //Allocate storage for the eigen function normalisation
164  Vector<std::complex<double> >interpolated_u_normalisation(DIM);
165  for(unsigned i=0;i<DIM;++i)
166  {
167  interpolated_u[i].real(0.0); interpolated_u[i].imag(0.0);
168  interpolated_u_normalisation[i].real(0.0);
169  interpolated_u_normalisation[i].imag(0.0);
170  }
171 
172  // Allocate storage for the pressure components (two of these
173  std::complex<double> interpolated_p(0.0,0.0);
174  std::complex<double> interpolated_p_normalisation(0.0,0.0);
175 
176  // Allocate storage for the derivatives of the velocity components
177  // w.r.t. global coordinates (r and z)
178  Vector<Vector<std::complex<double> > >interpolated_dudx(DIM);
179  for(unsigned i=0;i<DIM;++i)
180  {
181  interpolated_dudx[i].resize(DIM);
182  for(unsigned j=0;j<DIM;++j)
183  {
184  interpolated_dudx[i][j].real(0.0);
185  interpolated_dudx[i][j].imag(0.0);
186  }
187  }
188 
189  // Calculate pressure at the integration point
190  // -------------------------------------------
191 
192  // Loop over pressure degrees of freedom (associated with a single
193  // pressure component) in the element
194  for(unsigned l=0;l<n_pres;l++)
195  {
196  // Cache the shape function
197  const double psip_ = psip(l);
198 
199  //Get the complex nodal pressure values
200  const std::complex<double>
201  p_value(this->p_linearised_nst(l,0),this->p_linearised_nst(l,1));
202 
203  // Add contribution
204  interpolated_p += p_value*psip_;
205 
206  //Repeat for normalisation
207  const std::complex<double>
208  p_norm_value(this->p_linearised_nst(l,2),this->p_linearised_nst(l,3));
209  interpolated_p_normalisation += p_norm_value*psip_;
210  }
211  // End of loop over the pressure degrees of freedom in the element
212 
213  // Calculate velocities and their derivatives at the integration point
214  // -------------------------------------------------------------------
215 
216  // Loop over the element's nodes
217  for(unsigned l=0;l<n_node;l++)
218  {
219  // Cache the shape function
220  const double psif_ = psif(l);
221 
222  // Loop over the DIM coordinate directions
223  for(unsigned i=0;i<DIM;i++)
224  {
225  interpolated_x[i] += this->nodal_position(l,i)*psif_;
226  }
227 
228  // Loop over the DIM complex velocity components
229  for(unsigned i=0;i<DIM;i++)
230  {
231  // Get the value
232  const std::complex<double>
233  u_value(this->nodal_value(l,u_nodal_index[2*i+0]),
234  this->nodal_value(l,u_nodal_index[2*i+1]));
235 
236  // Add contribution
237  interpolated_u[i] += u_value*psif_;
238 
239  // Add contribution to dudt
240  //dudt[i] += du_dt_linearised_nst(l,i)*psif_;
241 
242  // Loop over two coordinate directions (for derivatives)
243  for(unsigned j=0;j<DIM;j++)
244  {
245  interpolated_dudx[i][j] += u_value*dpsifdx(l,j);
246  }
247 
248  //Interpolate the normalisation function
249  const std::complex<double>
250  normalisation_value(this->nodal_value(l,u_nodal_index[2*(DIM+i)]),
251  this->nodal_value(l,
252  u_nodal_index[2*(DIM+i)+1]));
253  interpolated_u_normalisation[i] += normalisation_value*psif_;
254  }
255  } // End of loop over the element's nodes
256 
257  // Get the mesh velocity if ALE is enabled
258  /*if(!ALE_is_disabled)
259  {
260  // Loop over the element's nodes
261  for(unsigned l=0;l<n_node;l++)
262  {
263  // Loop over the two coordinate directions
264  for(unsigned i=0;i<2;i++)
265  {
266  mesh_velocity[i] += this->raw_dnodal_position_dt(l,i)*psif(l);
267  }
268  }
269  }*/
270 
271  // Get velocities and their derivatives from base flow problem
272  // -----------------------------------------------------------
273 
274  // Allocate storage for the velocity components of the base state
275  // solution (initialise to zero)
276  Vector<double> base_flow_u(DIM,0.0);
277 
278  // Get the user-defined base state solution velocity components
279  get_base_flow_u(time,ipt,interpolated_x,base_flow_u);
280 
281  // Allocate storage for the derivatives of the base state solution's
282  // velocity components w.r.t. global coordinate (r and z)
283  // N.B. the derivatives of the base flow components w.r.t. the
284  // azimuthal coordinate direction (theta) are always zero since the
285  // base flow is axisymmetric
286  DenseMatrix<double> base_flow_dudx(DIM,DIM,0.0);
287 
288  // Get the derivatives of the user-defined base state solution
289  // velocity components w.r.t. global coordinates
290  get_base_flow_dudx(time,ipt,interpolated_x,base_flow_dudx);
291 
292 
293  //MOMENTUM EQUATIONS
294  //------------------
295 
296  // Number of master nodes
297  unsigned n_master = 1;
298 
299  // Storage for the weight of the shape function
300  double hang_weight = 1.0;
301 
302  //Loop over the test functions
303  for(unsigned l=0;l<n_node;l++)
304  {
305  //Local boolean to indicate whether the node is hanging
306  bool is_node_hanging = node_pt(l)->is_hanging();
307 
308  if(is_node_hanging)
309  {
310  hang_info_pt = node_pt(l)->hanging_pt();
311 
312  //Read out number of master nodes from hanging data
313  n_master = hang_info_pt->nmaster();
314  }
315  //Otherwise the node is its own master
316  else
317  {
318  n_master = 1;
319  }
320 
321  //Loop over the master nodes
322  for(unsigned m=0;m<n_master;m++)
323  {
324  //Loop over the velocity components
325  for(unsigned i=0;i<DIM;i++)
326  {
327  //Assemble the residuals
328  //Time dependent term
329  std::complex<double> residual_contribution
330  = -scaled_re_st*eigenvalue*interpolated_u[i]*testf[l]*W;
331  //Pressure term
332  residual_contribution += interpolated_p*dtestfdx(l,i)*W;
333  //Viscous terms
334  for(unsigned k=0;k<DIM;++k)
335  {
336  residual_contribution -= visc_ratio*
337  (interpolated_dudx[i][k] + Gamma[i]*interpolated_dudx[k][i])*
338  dtestfdx(l,k)*W;
339  }
340 
341  //Advective terms
342  for(unsigned k=0;k<DIM;++k)
343  {
344  residual_contribution -= scaled_re*(
345  base_flow_u[k]*interpolated_dudx[i][k]
346  + interpolated_u[k]*base_flow_dudx(i,k))*testf[l]*W;
347  }
348 
349  //Now separate real and imaginary parts
350 
351  if(is_node_hanging)
352  {
353  local_eqn = this->local_hang_eqn(hang_info_pt->master_node_pt(m),
354  u_nodal_index[2*i]);
355  hang_weight = hang_info_pt->master_weight(m);
356  }
357  //If node is not hanging number or not
358  else
359  {
360  local_eqn = nodal_local_eqn(l,u_nodal_index[2*i]);
361  hang_weight = 1.0;
362  }
363 
364  if(local_eqn >= 0)
365  {
366  residuals[local_eqn] += residual_contribution.real()*hang_weight;
367  }
368 
369 
370  if(is_node_hanging)
371  {
372  local_eqn = this->local_hang_eqn(hang_info_pt->master_node_pt(m),
373  u_nodal_index[2*i+1]);
374  hang_weight = hang_info_pt->master_weight(m);
375  }
376  //If node is not hanging number or not
377  else
378  {
379  local_eqn = nodal_local_eqn(l,u_nodal_index[2*i+1]);
380  hang_weight = 1.0;
381  }
382  if(local_eqn >= 0)
383  {
384  residuals[local_eqn] += residual_contribution.imag()*hang_weight;
385  }
386 
387 
388  //CALCULATE THE JACOBIAN
389  /*if(flag)
390  {
391  //Loop over the velocity shape functions again
392  for(unsigned l2=0;l2<n_node;l2++)
393  {
394  //Loop over the velocity components again
395  for(unsigned i2=0;i2<DIM;i2++)
396  {
397  //If at a non-zero degree of freedom add in the entry
398  local_unknown = nodal_local_eqn(l2,u_nodal_index[i2]);
399  if(local_unknown >= 0)
400  {
401  //Add contribution to Elemental Matrix
402  jacobian(local_eqn,local_unknown)
403  -= visc_ratio*Gamma[i]*dpsifdx(l2,i)*dtestfdx(l,i2)*W;
404 
405  //Extra component if i2 = i
406  if(i2 == i)
407  {
408  //Loop over velocity components
409  for(unsigned k=0;k<DIM;k++)
410  {
411  jacobian(local_eqn,local_unknown)
412  -= visc_ratio*dpsifdx(l2,k)*dtestfdx(l,k)*W;
413  }
414  }
415 
416  //Now add in the inertial terms
417  jacobian(local_eqn,local_unknown)
418  -= scaled_re*psif[l2]*interpolated_dudx(i,i2)*testf[l]*W;
419 
420  //Extra component if i2=i
421  if(i2 == i)
422  {
423  //Add the mass matrix term (only diagonal entries)
424  //Note that this is positive because the mass matrix
425  //is taken to the other side of the equation when
426  //formulating the generalised eigenproblem.
427  if(flag==2)
428  {
429  mass_matrix(local_eqn,local_unknown) +=
430  scaled_re_st*psif[l2]*testf[l]*W;
431  }
432 
433  //du/dt term
434  jacobian(local_eqn,local_unknown)
435  -= scaled_re_st*
436  node_pt(l2)->time_stepper_pt()->weight(1,0)*
437  psif[l2]*testf[l]*W;
438 
439  //Loop over the velocity components
440  for(unsigned k=0;k<DIM;k++)
441  {
442  double tmp=scaled_re*interpolated_u[k];
443  if (!ALE_is_disabled) tmp-=scaled_re_st*mesh_velocity[k];
444  jacobian(local_eqn,local_unknown) -=
445  tmp*dpsifdx(l2,k)*testf[l]*W;
446  }
447  }
448 
449  }
450  }
451  }
452 
453  //Now loop over pressure shape functions
454  //This is the contribution from pressure gradient
455  for(unsigned l2=0;l2<n_pres;l2++)
456  {
457  //If we are at a non-zero degree of freedom in the entry
458  local_unknown = p_local_eqn(l2);
459  if(local_unknown >= 0)
460  {
461  jacobian(local_eqn,local_unknown)
462  += psip[l2]*dtestfdx(l,i)*W;
463  }
464  }
465  } //End of Jacobian calculation
466 
467  }*/ //End of if not boundary condition statement
468 
469  } //End of loop over dimension
470  } //End of loop over master nodes
471  } //End of loop over shape functions
472 
473 
474 
475  //CONTINUITY EQUATION
476  //-------------------
477 
478  //Loop over the shape functions
479  for(unsigned l=0;l<n_pres;l++)
480  {
481  if(pressure_dof_is_hanging[l])
482  {
483  hang_info_pt = this->pressure_node_pt(l)->hanging_pt(p_index[0]);
484  n_master = hang_info_pt->nmaster();
485  }
486  else
487  {
488  n_master=1;
489  }
490 
491  //Loop over the master nodes
492  for(unsigned m=0;m<n_master;++m)
493  {
494  //Assemble the residuals
495  std::complex<double> residual_contribution
496  = interpolated_dudx[0][0];
497  for(unsigned k=1;k<DIM;++k)
498  {
499  residual_contribution += interpolated_dudx[k][k];
500  }
501 
502  if(pressure_dof_is_hanging[l])
503  {
504  local_eqn = this->local_hang_eqn(hang_info_pt->master_node_pt(m),
505  p_index[0]);
506  hang_weight = hang_info_pt->master_weight(m);
507  }
508  else
509  {
510  local_eqn = this->p_local_eqn(l,0);
511  hang_weight = 1.0;
512  }
513 
514  //If not a boundary conditions
515  if(local_eqn >= 0)
516  {
517  residuals[local_eqn] +=
518  residual_contribution.real()*testp[l]*W*hang_weight;
519  }
520 
521  if(pressure_dof_is_hanging[l])
522  {
523  local_eqn = this->local_hang_eqn(hang_info_pt->master_node_pt(m),
524  p_index[1]);
525  hang_weight = hang_info_pt->master_weight(m);
526  }
527  else
528  {
529  local_eqn = this->p_local_eqn(l,1);
530  hang_weight = 1.0;
531  }
532 
533  //If not a boundary conditions
534  if(local_eqn >= 0)
535  {
536  residuals[local_eqn] +=
537  residual_contribution.imag()*testp[l]*W*hang_weight;
538  }
539 
540  } //End of loop over master nodes
541  } //End of loop over l
542 
543  //Normalisation condition. Leave this alone because there is
544  //no test function involved.
545  std::complex<double> residual_contribution =
546  interpolated_p_normalisation*interpolated_p;
547  for(unsigned k=0;k<DIM;++k)
548  {
549  residual_contribution +=
550  interpolated_u_normalisation[k]*interpolated_u[k];
551  }
552 
553  local_eqn = this->eigenvalue_local_eqn(0);
554  if(local_eqn >= 0)
555  {
556  residuals[local_eqn] += residual_contribution.real()*W;
557  }
558 
559  local_eqn = this->eigenvalue_local_eqn(1);
560  if(local_eqn >= 0)
561  {
562  residuals[local_eqn] += residual_contribution.imag()*W;
563  }
564 
565  } // End of loop over the integration points
566 
567  } // End of fill_in_generic_residual_contribution_linearised_nst
568 
569 } // End of namespace oomph
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 ...
virtual double dshape_and_dtest_eulerian_at_knot_linearised_nst(const unsigned &ipt, Shape &psi, DShape &dpsidx, Shape &test, DShape &dtestdx) const =0
Compute the shape functions and their derivatives w.r.t. global coordinates at the ipt-th integration...
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:2227
HangInfo *const & hanging_pt() const
Return pointer to hanging node data (this refers to the geometric hanging node status) (const version...
Definition: nodes.h:1148
cstr elem_len * i
Definition: cfortran.h:607
double & time()
Return current value of continous time.
Definition: timesteppers.h:324
const double & re_st() const
Product of Reynolds and Strouhal number (=Womersley number)
const double & density_ratio() const
Density ratio for element: element&#39;s density relative to the viscosity used in the definition of the ...
virtual double p_linearised_nst(const unsigned &n_p, const unsigned &i) const =0
Return the i-th pressure value at local pressure "node" n_p. Uses suitably interpolated value for han...
double const & master_weight(const unsigned &i) const
Return weight for dofs on i-th master node.
Definition: nodes.h:753
unsigned nmaster() const
Return the number of master nodes.
Definition: nodes.h:733
bool is_hanging() const
Test whether the node is geometrically hanging.
Definition: nodes.h:1207
virtual double weight(const unsigned &i) const =0
Return weight of i-th integration point.
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:3881
Integral *const & integral_pt() const
Return the pointer to the integration scheme (const version)
Definition: elements.h:1908
virtual unsigned u_index_linearised_nst(const unsigned &i) const
Return the index at which the i-th unknown velocity component is stored. The default value...
virtual void get_base_flow_dudx(const double &time, const unsigned &ipt, const Vector< double > &x, DenseMatrix< double > &result) const
Calculate the derivatives of the velocity components of the base flow solution w.r.t. global coordinates (r and z) at a given time and Eulerian position.
static char t char * s
Definition: cfortran.h:572
virtual double knot(const unsigned &i, const unsigned &j) const =0
Return local coordinate s[j] of i-th integration point.
static Vector< double > Gamma
Vector to decide whether the stress-divergence form is used or not.
virtual unsigned npres_linearised_nst() const =0
Return the number of pressure degrees of freedom associated with a single pressure component in the e...
Node *const & master_node_pt(const unsigned &i) const
Return a pointer to the i-th master node.
Definition: nodes.h:736
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition: elements.h:2109
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:2470
Class that contains data for hanging nodes.
Definition: nodes.h:684
virtual void pshape_linearised_nst(const Vector< double > &s, Shape &psi) const =0
Compute the pressure shape functions at local coordinate s.
virtual Node * pressure_node_pt(const unsigned &n_p)
Pointer to n_p-th pressure node (Default: NULL, indicating that pressure is not based on nodal interp...
virtual unsigned nweight() const =0
Return the number of integration points of the scheme.
virtual int p_index_linearised_nst(const unsigned &i) const
Which nodal value represents the pressure?
TimeStepper *& time_stepper_pt()
Return the pointer to the timestepper.
Definition: nodes.h:246
virtual int p_local_eqn(const unsigned &n, const unsigned &i)=0
Access function for the local equation number information for the i-th component of the pressure...
virtual void get_base_flow_u(const double &time, const unsigned &ipt, const Vector< double > &x, Vector< double > &result) const
Calculate the velocity components of the base flow solution at a given time and Eulerian position...
const double & re() const
Reynolds number.
const double & viscosity_ratio() const
Viscosity ratio for element: element&#39;s viscosity relative to the viscosity used in the definition of ...
unsigned nnode() const
Return the number of nodes.
Definition: elements.h:2146
void fill_in_generic_residual_contribution_linearised_nst(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix, unsigned flag)
Add element&#39;s contribution to the elemental residual vector and/or Jacobian matrix flag=1: compute bo...
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:1386