db_navier_st_elements.h
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//====================================================================
26 #ifndef DOUBLE_BUOYANT_NAVIER_STOKES_ELEMENTS_HEADER
27 #define DOUBLE_BUOYANT_NAVIER_STOKES_ELEMENTS_HEADER
28 
29 //Oomph-lib headers, we require the generic, advection-diffusion-reaction,
30 //navier-stokes elements and fluid interface elements
31 #include "generic.h"
33 #include "navier_stokes.h"
34 
35 namespace oomph
36 {
37 
38 //======================class definition==============================
56 //=========================================================================
57 template<unsigned DIM>
59  public virtual QAdvectionDiffusionReactionElement<2,DIM,3>,
60  public virtual QCrouzeixRaviartElement<DIM>
61 {
62 
63 private:
64 
66  double* Ra_T_pt;
67 
69  double *Ra_S_pt;
70 
73 
74 public:
75 
82  {
85  }
86 
88  void unfix_pressure(const unsigned &p_dof)
89  {
90  this->internal_data_pt(this->P_nst_internal_index)->unpin(p_dof);
91  }
92 
93 
97  unsigned required_nvalue(const unsigned &n) const
100 
102  const double &ra_t() const {return *Ra_T_pt;}
103 
105  double* &ra_t_pt() {return Ra_T_pt;}
106 
108  const double &ra_s() const {return *Ra_S_pt;}
109 
111  double* &ra_s_pt() {return Ra_S_pt;}
112 
114  void disable_ALE()
115  {
116  //Disable ALE in both sets of equations
119  }
120 
122  void enable_ALE()
123  {
124  //Enable ALE in both sets of equations
127  }
128 
129 
131  void output(std::ostream &outfile) {FiniteElement::output(outfile);}
132 
135  // Start of output function
136  void output(std::ostream &outfile, const unsigned &nplot)
137  {
138  //vector of local coordinates
140 
141  // Tecplot header info
142  outfile << this->tecplot_zone_string(nplot);
143 
144  // Loop over plot points
145  unsigned num_plot_points=this->nplot_points(nplot);
146  for (unsigned iplot=0;iplot<num_plot_points;iplot++)
147  {
148  // Get local coordinates of plot point
149  this->get_s_plot(iplot,nplot,s);
150 
151  // Output the position of the plot point
152  for(unsigned i=0;i<DIM;i++)
153  {outfile << this->interpolated_x(s,i) << " ";}
154 
155  // Output the fluid velocities at the plot point
156  for(unsigned i=0;i<DIM;i++)
157  {outfile << this->interpolated_u_nst(s,i) << " ";}
158 
159  // Output the fluid pressure at the plot point
160  outfile << this->interpolated_p_nst(s) << " ";
161 
162  //Output the temperature and the solute concentration
163  for(unsigned i=0;i<2;i++)
164  {
165  outfile << this->interpolated_c_adv_diff_react(s,i) << " ";
166  }
167  outfile << "\n";
168  }
169  outfile << std::endl;
170 
171  // Write tecplot footer (e.g. FE connectivity lists)
172  this->write_tecplot_zone_footer(outfile,nplot);
173  } //End of output function
174 
175 
177  void output(FILE* file_pt)
178  {FiniteElement::output(file_pt);}
179 
181  void output(FILE* file_pt, const unsigned &n_plot)
182  {FiniteElement::output(file_pt,n_plot);}
183 
185  void output_fct(std::ostream &outfile, const unsigned &Nplot,
187  exact_soln_pt)
188  {FiniteElement::output_fct(outfile,Nplot,exact_soln_pt);}
189 
190 
193  void output_fct(std::ostream &outfile, const unsigned &Nplot,
194  const double& time,
196  exact_soln_pt)
197  {
199  output_fct(outfile,Nplot,time,exact_soln_pt);
200  }
201 
204  // We choose to store them after the fluid velocities.
205  inline unsigned c_index_adv_diff_react(const unsigned &i) const
206  {return DIM+i;}
207 
208 
209  //Compute norm overload to NS version
210  void compute_norm(double &norm)
212 
213 
219  void compute_error(std::ostream &outfile,
221  const double& time,
222  double& error, double& norm)
223  {FiniteElement::compute_error(outfile,exact_soln_pt,
224  time,error,norm);}
225 
231  void compute_error(std::ostream &outfile,
233  double& error, double& norm)
234  {FiniteElement::compute_error(outfile,exact_soln_pt,error,norm);}
235 
239  void get_wind_adv_diff_react(const unsigned& ipt,
240  const Vector<double> &s, const Vector<double>& x,
241  Vector<double>& wind) const
242  {
243  //The wind function is simply the velocity at the points
244  this->interpolated_u_nst(s,wind);
245  }
246 
247 
253  void get_body_force_nst(const double& time, const unsigned& ipt,
254  const Vector<double> &s, const Vector<double> &x,
255  Vector<double> &result)
256  {
257  // Get vector that indicates the direction of gravity from
258  // the Navier-Stokes equations
260 
261  //Get the indices at which the temp and concentration are stored
262  unsigned c_index[2];
263  for(unsigned r=0;r<2;r++)
264  {c_index[r] = this->c_index_adv_diff_react(r);}
265 
266  //Now get the shape function
267  const unsigned n_node = this->nnode();
268  Shape psi(n_node);
269  //Get the shape functions
270  this->shape(s,psi);
271  //Storage for the local values of advected quantities
272  Vector<double> interpolated_c(2,0.0);
273  //Get the values
274  for(unsigned l=0;l<n_node;l++)
275  {
276  for(unsigned r=0;r<2;r++)
277  {
278  interpolated_c[r] += this->raw_nodal_value(l,c_index[r])*psi(l);
279  }
280  }
281 
282  // Temperature and concentration-dependent body force:
283  for(unsigned i=0;i<DIM;i++)
284  {
285 
286  result[i] = -gravity[i]*
287  //Thermal contribution //Concentration contribution
288  (interpolated_c[0]*ra_t() + interpolated_c[1]*ra_s());
289  }
290  }
291 
298  {
299  //Fill in the residuals of the Navier-Stokes equations
301 
302  //Fill in the residuals of the advection-diffusion eqautions
305  }
306 
307 
308 #ifdef USE_FD_JACOBIAN_FOR_BUOYANT_Q_CROZIER_RAVIART_ELEMENT
309 
310 
314  DenseMatrix<double> &jacobian)
315  {
316  // This function computes the Jacobian by finite-differencing
318  }
319 
320 #else
321 
325  DenseMatrix<double> &jacobian)
326  {
327  //Local storage for the index in the nodes at which the
328  //Navier-Stokes velocities are stored (we know that this should be 0,1,2)
329  unsigned u_nodal_nst[DIM];
330  for(unsigned i=0;i<DIM;i++)
331  {u_nodal_nst[i] = this->u_index_nst(i);}
332 
333  //Local storage for the index at which the temperature and
334  //solute are stored
335  unsigned C_nodal_adv_diff_react[2];
336  for(unsigned r=0;r<2;r++)
337  {C_nodal_adv_diff_react[r] = this->c_index_adv_diff_react(r);}
338 
339 
340  //Find the total number of unknowns in the elements
341  unsigned n_dof = this->ndof();
342 
343  //Temporary storage for residuals
344  Vector<double> newres(n_dof);
345 
346  //Storage for local unknown and local equation
347  int local_unknown =0, local_eqn = 0;
348 
349  //Set the finite difference step
351 
352  //Find the number of nodes
353  unsigned n_node = this->nnode();
354 
355  //Calculate the contribution of the Navier--Stokes velocities to the
356  //advection-diffusion equations
357 
358  //Loop over the nodes
359  for(unsigned n=0;n<n_node;n++)
360  {
361  //There are DIM values of the velocities
362  for(unsigned i=0;i<DIM;i++)
363  {
364  //Get the local velocity equation number
365  local_unknown = this->nodal_local_eqn(n,u_nodal_nst[i]);
366 
367  //If it's not pinned
368  if(local_unknown >= 0)
369  {
370  //Get a pointer to the velocity value
371  double *value_pt = this->node_pt(n)->value_pt(u_nodal_nst[i]);
372 
373  //Save the old value
374  double old_var = *value_pt;
375 
376  //Increment the value
377  *value_pt += fd_step;
378 
379  //Get the altered advection-diffusion residuals.
380  //Do this using fill_in because get_residuals has never been
381  //overloaded, and will actually compute all residuals which
382  //is slightly inefficient.
383  for(unsigned m=0;m<n_dof;m++) {newres[m] = 0.0;}
386 
387  //Now fill in the Advection-Diffusion-Reaction sub-block
388  //of the jacobian
389  for(unsigned m=0;m<n_node;m++)
390  {
391  for(unsigned r=0;r<2;r++)
392  {
393  //Local equation for temperature or solute
394  local_eqn = this->nodal_local_eqn(m,C_nodal_adv_diff_react[r]);
395 
396  //If it's not a boundary condition
397  if(local_eqn >= 0)
398  {
399  double sum = (newres[local_eqn] - residuals[local_eqn])/fd_step;
400  jacobian(local_eqn,local_unknown) = sum;
401  }
402  }
403  }
404 
405  //Reset the nodal data
406  *value_pt = old_var;
407  }
408  }
409 
410 
411  //Calculate the contribution of the temperature to the Navier--Stokes
412  //equations
413  for(unsigned r=0;r<2;r++)
414  {
415  //Get the local equation number
416  local_unknown = this->nodal_local_eqn(n,C_nodal_adv_diff_react[r]);
417 
418  //If it's not pinned
419  if(local_unknown >= 0)
420  {
421  //Get a pointer to the concentration value
422  double *value_pt =
423  this->node_pt(n)->value_pt(C_nodal_adv_diff_react[r]);
424 
425  //Save the old value
426  double old_var = *value_pt;
427 
428  //Increment the value (Really need access)
429  *value_pt += fd_step;
430 
431  //Get the altered Navier--Stokes residuals
432  //Do this using fill_in because get_residuals has never been
433  //overloaded, and will actually compute all residuals which
434  //is slightly inefficient.
435  for(unsigned m=0;m<n_dof;m++) {newres[m] = 0.0;}
437 
438  //Now fill in the Navier-Stokes sub-block
439  for(unsigned m=0;m<n_node;m++)
440  {
441  //Loop over the fluid velocities
442  for(unsigned j=0;j<DIM;j++)
443  {
444  //Local fluid equation
445  local_eqn = this->nodal_local_eqn(m,u_nodal_nst[j]);
446  if(local_eqn >= 0)
447  {
448  double sum = (newres[local_eqn] - residuals[local_eqn])/fd_step;
449  jacobian(local_eqn,local_unknown) = sum;
450  }
451  }
452  }
453 
454  //Reset the nodal data
455  *value_pt = old_var;
456  }
457  } //End of loop over reagents
458 
459  } //End of loop over nodes
460  }
461 
465  DenseMatrix<double> &jacobian)
466  {
467 
468  //Calculate the Navier-Stokes contributions (diagonal block and residuals)
470  fill_in_contribution_to_jacobian(residuals,jacobian);
471 
472  //Calculate the advection-diffusion contributions
473  //(diagonal block and residuals)
475  fill_in_contribution_to_jacobian(residuals,jacobian);
476 
477  //Add in the off-diagonal blocks
478  fill_in_off_diagonal_jacobian_blocks_by_fd(residuals,jacobian);
479  } //End of jacobian calculation
480 
481 #endif
482 
483 
487  Vector<double> &residuals, DenseMatrix<double> &jacobian,
488  DenseMatrix<double> &mass_matrix)
489  {
492  residuals,jacobian,mass_matrix);
493 
496  residuals,jacobian,mass_matrix);
497 
498  fill_in_off_diagonal_jacobian_blocks_by_fd(residuals,jacobian);
499  }
500 
501 
502 };
503 
504 //=========================================================================
506 //=========================================================================
507 template<>
509 
510 
511 //=======================================================================
513 //=======================================================================
514 template<unsigned int DIM>
516 public virtual QElement<DIM-1,3>
517 {
518  public:
519  FaceGeometry() : QElement<DIM-1,3>() {}
520 };
521 
522 //=======================================================================
524 //=======================================================================
525 template<>
527 public virtual PointElement
528 {
529  public:
531 };
532 
533 } //End of the oomph namespace
534 
535 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void fill_in_contribution_to_residuals(Vector< double > &residuals)
Add the element's contribution to its residual vector (wrapper)
Definition: advection_diffusion_reaction_elements.h:519
void fill_in_contribution_to_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: advection_diffusion_reaction_elements.h:533
void enable_ALE()
Definition: advection_diffusion_reaction_elements.h:189
double interpolated_c_adv_diff_react(const Vector< double > &s, const unsigned &i) const
Return FE representation of function value c_i(s) at local coordinate s.
Definition: advection_diffusion_reaction_elements.h:556
void disable_ALE()
Definition: advection_diffusion_reaction_elements.h:180
void fill_in_contribution_to_jacobian_and_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
Definition: advection_diffusion_reaction_elements.h:544
void unpin(const unsigned &i)
Unpin the i-th stored variable.
Definition: nodes.h:391
double * value_pt(const unsigned &i) const
Definition: nodes.h:324
Definition: db_navier_st_elements.h:61
void get_body_force_nst(const double &time, const unsigned &ipt, const Vector< double > &s, const Vector< double > &x, Vector< double > &result)
Definition: db_navier_st_elements.h:253
void compute_norm(double &norm)
Definition: db_navier_st_elements.h:210
static double Default_Physical_Constant_Value
The static default value of the Rayleigh number.
Definition: db_navier_st_elements.h:72
void fill_in_off_diagonal_jacobian_blocks_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: db_navier_st_elements.h:324
void fill_in_contribution_to_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: db_navier_st_elements.h:464
void compute_error(std::ostream &outfile, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt, double &error, double &norm)
Definition: db_navier_st_elements.h:231
void compute_error(std::ostream &outfile, FiniteElement::UnsteadyExactSolutionFctPt exact_soln_pt, const double &time, double &error, double &norm)
Definition: db_navier_st_elements.h:219
void fill_in_contribution_to_jacobian_and_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
Definition: db_navier_st_elements.h:486
double * Ra_T_pt
Pointer to a private data member, the thermal Rayleigh number.
Definition: db_navier_st_elements.h:66
void output_fct(std::ostream &outfile, const unsigned &Nplot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
Output function for an exact solution: Broken default.
Definition: db_navier_st_elements.h:185
void output(std::ostream &outfile)
Overload the standard output function with the broken default.
Definition: db_navier_st_elements.h:131
const double & n() const
Access function for the number of monomers in the micelle.
Definition: two_layer_soluble_surfactant/double_buoyant_navier_stokes_elements.h:110
const double & ra_s() const
Access function for the solutal Rayleigh number (const version)
Definition: db_navier_st_elements.h:108
void unfix_pressure(const unsigned &p_dof)
UnPin p_dof-th pressure dof.
Definition: db_navier_st_elements.h:88
double *& ra_s_pt()
Access function for the pointer to the solutal Rayleigh number.
Definition: db_navier_st_elements.h:111
void fill_in_contribution_to_residuals(Vector< double > &residuals)
Definition: db_navier_st_elements.h:297
unsigned c_index_adv_diff_react(const unsigned &i) const
Definition: db_navier_st_elements.h:205
void output(std::ostream &outfile, const unsigned &nplot)
Definition: db_navier_st_elements.h:136
void output_fct(std::ostream &outfile, const unsigned &Nplot, const double &time, FiniteElement::UnsteadyExactSolutionFctPt exact_soln_pt)
Definition: db_navier_st_elements.h:193
void enable_ALE()
Final override for enable ALE.
Definition: db_navier_st_elements.h:122
const double & ra_t() const
Access function for the thermal Rayleigh number (const version)
Definition: db_navier_st_elements.h:102
void output(FILE *file_pt, const unsigned &n_plot)
C-style output function: Broken default.
Definition: db_navier_st_elements.h:181
double * Ra_S_pt
Pointer to privare data member, the solutal Rayleigh number.
Definition: db_navier_st_elements.h:69
DoubleBuoyantQCrouzeixRaviartElement()
Definition: db_navier_st_elements.h:79
double *& ra_t_pt()
Access function for the pointer to the thermal Rayleigh number.
Definition: db_navier_st_elements.h:105
void disable_ALE()
Final override for disable ALE.
Definition: db_navier_st_elements.h:114
void output(FILE *file_pt)
C-style output function: Broken default.
Definition: db_navier_st_elements.h:177
unsigned required_nvalue(const unsigned &n) const
Definition: db_navier_st_elements.h:97
void get_wind_adv_diff_react(const unsigned &ipt, const Vector< double > &s, const Vector< double > &x, Vector< double > &wind) const
Definition: db_navier_st_elements.h:239
Definition: elements.h:4998
void fill_in_contribution_to_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: elements.h:1735
virtual void output_fct(std::ostream &outfile, const unsigned &n_plot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
Output an exact solution over the element.
Definition: elements.h:3104
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition: elements.h:2175
virtual void output(std::ostream &outfile)
Definition: elements.h:3050
virtual std::string tecplot_zone_string(const unsigned &nplot) const
Definition: elements.h:3161
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
virtual void shape(const Vector< double > &s, Shape &psi) const =0
int nodal_local_eqn(const unsigned &n, const unsigned &i) const
Definition: elements.h:1432
unsigned nnode() const
Return the number of nodes.
Definition: elements.h:2210
virtual void compute_error(FiniteElement::SteadyExactSolutionFctPt exact_soln_pt, double &error, double &norm)
Calculate the norm of the error and that of the exact solution.
Definition: elements.h:3198
void(* SteadyExactSolutionFctPt)(const Vector< double > &, Vector< double > &)
Definition: elements.h:1759
virtual void get_s_plot(const unsigned &i, const unsigned &nplot, Vector< double > &s, const bool &shifted_to_interior=false) const
Definition: elements.h:3148
virtual unsigned nplot_points(const unsigned &nplot) const
Definition: elements.h:3186
double raw_nodal_value(const unsigned &n, const unsigned &i) const
Definition: elements.h:2576
virtual void write_tecplot_zone_footer(std::ostream &outfile, const unsigned &nplot) const
Definition: elements.h:3174
void(* UnsteadyExactSolutionFctPt)(const double &, const Vector< double > &, Vector< double > &)
Definition: elements.h:1765
static double Default_fd_jacobian_step
Definition: elements.h:1198
unsigned ndof() const
Return the number of equations/dofs in the element.
Definition: elements.h:835
Data *& internal_data_pt(const unsigned &i)
Return a pointer to i-th internal data object.
Definition: elements.h:622
Definition: navier_stokes_elements.h:395
void disable_ALE()
Definition: navier_stokes_elements.h:909
virtual unsigned u_index_nst(const unsigned &i) const
Definition: navier_stokes_elements.h:866
void fill_in_contribution_to_residuals(Vector< double > &residuals)
Compute the element's residual Vector.
Definition: navier_stokes_elements.h:1260
void interpolated_u_nst(const Vector< double > &s, Vector< double > &veloc) const
Compute vector of FE interpolated velocity u at local coordinate s.
Definition: navier_stokes_elements.h:1505
void fill_in_contribution_to_jacobian_and_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
Definition: navier_stokes_elements.h:1283
void enable_ALE()
Definition: navier_stokes_elements.h:918
void compute_norm(double &norm)
Compute norm of solution: square of the L2 norm of the velocities.
Definition: navier_stokes_elements.cc:186
virtual double interpolated_p_nst(const Vector< double > &s) const
Return FE interpolated pressure at local coordinate s.
Definition: navier_stokes_elements.h:1639
void fill_in_contribution_to_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: navier_stokes_elements.h:1273
Definition: elements.h:3439
Definition: advection_diffusion_reaction_elements.h:664
Definition: navier_stokes_elements.h:1749
unsigned P_nst_internal_index
Definition: navier_stokes_elements.h:1757
Definition: Qelements.h:459
Definition: shape.h:76
RealScalar s
Definition: level1_cplx_impl.h:130
int * m
Definition: level2_cplx_impl.h:294
#define DIM
Definition: linearised_navier_stokes_elements.h:44
void gravity(const double &t, const Vector< double > &xi, Vector< double > &b)
Definition: ConstraintElementsUnitTest.cpp:20
r
Definition: UniformPSDSelfTest.py:20
int error
Definition: calibrate.py:297
Definition: MortaringCantileverCompareToNonMortaring.cpp:176
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2