GRINS-0.7.0
boussinesq_buoyancy_spgsm_stab.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 // This class
26 #include "grins_config.h"
28 
29 // GRINS
30 #include "grins/assembly_context.h"
33 
34 // libMesh
35 #include "libmesh/getpot.h"
36 #include "libmesh/fem_system.h"
37 #include "libmesh/quadrature.h"
38 
39 namespace GRINS
40 {
41  template<class Mu>
42  BoussinesqBuoyancySPGSMStabilization<Mu>::BoussinesqBuoyancySPGSMStabilization( const std::string& physics_name, const GetPot& input )
43  : BoussinesqBuoyancyBase(physics_name,input),
44  _flow_stab_helper(physics_name+"FlowStabHelper", input),
45  _temp_stab_helper(physics_name+"TempStabHelper", input),
46  _Cp(0.0),
47  _k(1.0),
48  _mu(input,MaterialsParsing::material_name(input,PhysicsNaming::boussinesq_buoyancy()))
49  {
51 
52  this->set_parameter
53  (_k, input, "Physics/"+PhysicsNaming::heat_transfer()+"/k", _k);
54  }
55 
56  template<class Mu>
58  {
59  return;
60  }
61 
62  template<class Mu>
64  AssemblyContext& context,
65  CachedValues& /*cache*/ )
66  {
67 #ifdef GRINS_USE_GRVY_TIMERS
68  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::element_time_derivative");
69 #endif
70 
71  // The number of local degrees of freedom in each variable.
72  const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u()).size();
73 
74  // Element Jacobian * quadrature weights for interior integration.
75  const std::vector<libMesh::Real> &JxW =
76  context.get_element_fe(_flow_vars.u())->get_JxW();
77 
78  /*
79  const std::vector<std::vector<libMesh::Real> >& u_phi =
80  context.get_element_fe(this->_flow_vars.u())->get_phi();
81  */
82 
83  const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
84  context.get_element_fe(this->_flow_vars.u())->get_dphi();
85 
86  // Get residuals
87  libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u()); // R_{u}
88  libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v()); // R_{v}
89  libMesh::DenseSubVector<libMesh::Number> *Fw = NULL;
90  if(this->_dim == 3)
91  {
92  Fw = &context.get_elem_residual(this->_flow_vars.w()); // R_{w}
93  }
94 
95  // Now we will build the element Jacobian and residual.
96  // Constructing the residual requires the solution and its
97  // gradient from the previous timestep. This must be
98  // calculated at each quadrature point by summing the
99  // solution degree-of-freedom values by the appropriate
100  // weight functions.
101  unsigned int n_qpoints = context.get_element_qrule().n_points();
102 
103  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
104 
105  for (unsigned int qp=0; qp != n_qpoints; qp++)
106  {
107  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
108  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
109 
110  libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
111  context.interior_value( this->_flow_vars.v(), qp ) );
112  if( this->_dim == 3 )
113  {
114  U(2) = context.interior_value( this->_flow_vars.w(), qp );
115  }
116 
117  // Compute the viscosity at this qp
118  libMesh::Real mu_qp = this->_mu(context, qp);
119 
120  libMesh::Real tau_M = this->_flow_stab_helper.compute_tau_momentum( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady );
121 
122  //libMesh::Real tau_E = this->_temp_stab_helper.compute_tau_energy( context, G, _rho, _Cp, _k, U, this->_is_steady );
123 
124  //libMesh::Real RE = this->_temp_stab_helper.compute_res_energy_steady( context, qp, _rho, _Cp, _k );
125 
126  // Compute the solution & its gradient at the old Newton iterate.
127  libMesh::Number T;
128  T = context.interior_value(_temp_vars.T(), qp);
129 
130  libMesh::RealGradient residual = _rho*_beta_T*(T-_T_ref)*_g;
131 
132  for (unsigned int i=0; i != n_u_dofs; i++)
133  {
134  Fu(i) += ( -tau_M*residual(0)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
135  // + _rho*_beta_T*tau_E*RE*_g(0)*u_phi[i][qp] )*JxW[qp];
136 
137  Fv(i) += ( -tau_M*residual(1)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
138  // + _rho*_beta_T*tau_E*RE*_g(1)*u_phi[i][qp] )*JxW[qp];
139 
140  if (_dim == 3)
141  {
142  (*Fw)(i) += ( -tau_M*residual(2)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
143  // + _rho*_beta_T*tau_E*RE*_g(2)*u_phi[i][qp] )*JxW[qp];
144  }
145 
146  if (compute_jacobian)
147  {
148  libmesh_not_implemented();
149  } // End compute_jacobian check
150 
151  } // End i dof loop
152  } // End quadrature loop
153 
154 #ifdef GRINS_USE_GRVY_TIMERS
155  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::element_time_derivative");
156 #endif
157 
158  return;
159  }
160 
161  template<class Mu>
163  AssemblyContext& context,
164  CachedValues& /*cache*/ )
165  {
166 #ifdef GRINS_USE_GRVY_TIMERS
167  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::element_constraint");
168 #endif
169 
170  // The number of local degrees of freedom in each variable.
171  const unsigned int n_p_dofs = context.get_dof_indices(_press_var.p()).size();
172 
173  // Element Jacobian * quadrature weights for interior integration.
174  const std::vector<libMesh::Real> &JxW =
175  context.get_element_fe(_flow_vars.u())->get_JxW();
176 
177  const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
178  context.get_element_fe(this->_press_var.p())->get_dphi();
179 
180  libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p()); // R_{p}
181 
182  // Now we will build the element Jacobian and residual.
183  // Constructing the residual requires the solution and its
184  // gradient from the previous timestep. This must be
185  // calculated at each quadrature point by summing the
186  // solution degree-of-freedom values by the appropriate
187  // weight functions.
188  unsigned int n_qpoints = context.get_element_qrule().n_points();
189 
190  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
191 
192  for (unsigned int qp=0; qp != n_qpoints; qp++)
193  {
194  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
195  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
196 
197  libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
198  context.interior_value( this->_flow_vars.v(), qp ) );
199  if( this->_dim == 3 )
200  {
201  U(2) = context.interior_value( this->_flow_vars.w(), qp );
202  }
203 
204  // Compute the viscosity at this qp
205  libMesh::Real mu_qp = this->_mu(context, qp);
206 
207  libMesh::Real tau_M = this->_flow_stab_helper.compute_tau_momentum( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady );
208 
209  // Compute the solution & its gradient at the old Newton iterate.
210  libMesh::Number T;
211  T = context.interior_value(_temp_vars.T(), qp);
212 
213  libMesh::RealGradient residual = _rho*_beta_T*(T-_T_ref)*_g;
214 
215  // First, an i-loop over the velocity degrees of freedom.
216  // We know that n_u_dofs == n_v_dofs so we can compute contributions
217  // for both at the same time.
218  for (unsigned int i=0; i != n_p_dofs; i++)
219  {
220  Fp(i) += -tau_M*residual*p_dphi[i][qp]*JxW[qp];
221 
222  if (compute_jacobian)
223  {
224  libmesh_not_implemented();
225  } // End compute_jacobian check
226 
227  } // End i dof loop
228 
229  } // End quadrature loop
230 
231 #ifdef GRINS_USE_GRVY_TIMERS
232  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::element_constraint");
233 #endif
234 
235  return;
236  }
237 
238  template<class Mu>
240  AssemblyContext& /*context*/,
241  CachedValues& /*cache*/ )
242  {
243  /*
244 #ifdef GRINS_USE_GRVY_TIMERS
245  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::mass_residual");
246 #endif
247 
248  // The number of local degrees of freedom in each variable.
249  const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u()).size();
250 
251  // Element Jacobian * quadrature weights for interior integration.
252  const std::vector<libMesh::Real> &JxW =
253  context.get_element_fe(_flow_vars.u())->get_JxW();
254 
255  const std::vector<std::vector<libMesh::Real> >& u_phi =
256  context.get_element_fe(this->_flow_vars.u())->get_phi();
257 
258  // Get residuals
259  libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u()); // R_{u}
260  libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v()); // R_{v}
261  libMesh::DenseSubVector<libMesh::Number> *Fw = NULL;
262  if(this->_dim == 3)
263  {
264  Fw = &context.get_elem_residual(this->_flow_vars.w()); // R_{w}
265  }
266 
267  // Now we will build the element Jacobian and residual.
268  // Constructing the residual requires the solution and its
269  // gradient from the previous timestep. This must be
270  // calculated at each quadrature point by summing the
271  // solution degree-of-freedom values by the appropriate
272  // weight functions.
273  unsigned int n_qpoints = context.get_element_qrule().n_points();
274 
275  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
276 
277  for (unsigned int qp=0; qp != n_qpoints; qp++)
278  {
279  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
280  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
281 
282  libMesh::RealGradient U( context.fixed_interior_value( this->_flow_vars.u(), qp ),
283  context.fixed_interior_value( this->_flow_vars.v(), qp ) );
284  if( this->_dim == 3 )
285  {
286  U(2) = context.fixed_interior_value( this->_flow_vars.w(), qp );
287  }
288 
289  libMesh::Real tau_E = this->_temp_stab_helper.compute_tau_energy( context, G, _rho, _Cp, _k, U, false );
290 
291  libMesh::Real RE = this->_temp_stab_helper.compute_res_energy_transient( context, qp, _rho, _Cp );
292 
293 
294  for (unsigned int i=0; i != n_u_dofs; i++)
295  {
296  Fu(i) += -_rho*_beta_T*tau_E*RE*_g(0)*u_phi[i][qp]*JxW[qp];
297 
298  Fv(i) += -_rho*_beta_T*tau_E*RE*_g(1)*u_phi[i][qp]*JxW[qp];
299 
300  if (_dim == 3)
301  {
302  (*Fw)(i) += -_rho*_beta_T*tau_E*RE*_g(2)*u_phi[i][qp]*JxW[qp];
303  }
304 
305  if (compute_jacobian)
306  {
307  libmesh_not_implemented();
308  } // End compute_jacobian check
309 
310  } // End i dof loop
311  } // End quadrature loop
312 
313 #ifdef GRINS_USE_GRVY_TIMERS
314  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::mass_residual");
315 #endif
316  */
317 
318  return;
319  }
320 
321  template<class Mu>
323  ( const std::string & param_name,
325  const
326  {
327  ParameterUser::register_parameter(param_name, param_pointer);
328  _mu.register_parameter(param_name, param_pointer);
329  }
330 
331 
332 } // namespace GRINS
333 
334 // Instantiate
335 INSTANTIATE_INC_NS_SUBCLASS(BoussinesqBuoyancySPGSMStabilization);
virtual void set_parameter(libMesh::Number &param_variable, const GetPot &input, const std::string &param_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
static PhysicsName heat_transfer()
INSTANTIATE_INC_NS_SUBCLASS(BoussinesqBuoyancySPGSMStabilization)
GRINS namespace.
virtual void mass_residual(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Mass matrix part(s) for element interiors. All boundary terms lie within the time_derivative part...
static void read_specific_heat(const std::string &core_physics_name, const GetPot &input, ParameterUser &params, libMesh::Real &cp)
Helper function to reading scalar specific heat from input.
Helper functions for parsing material properties.
static PhysicsName boussinesq_buoyancy()
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for element interiors.
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.
virtual void register_parameter(const std::string &param_name, libMesh::ParameterMultiAccessor< libMesh::Number > &param_pointer) const
Each subclass will register its copy of an independent.
virtual void register_parameter(const std::string &param_name, libMesh::ParameterMultiAccessor< libMesh::Number > &param_pointer) const
Each subclass will register its copy of an independent.

Generated on Thu Jun 2 2016 21:52:27 for GRINS-0.7.0 by  doxygen 1.8.10