GRINS-0.6.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-2015 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"
32 
33 // libMesh
34 #include "libmesh/getpot.h"
35 #include "libmesh/fem_system.h"
36 #include "libmesh/quadrature.h"
37 
38 namespace GRINS
39 {
40  template<class Mu>
41  BoussinesqBuoyancySPGSMStabilization<Mu>::BoussinesqBuoyancySPGSMStabilization( const std::string& physics_name, const GetPot& input )
42  : BoussinesqBuoyancyBase(physics_name,input),
43  _flow_stab_helper(physics_name+"FlowStabHelper", input),
44  _temp_stab_helper(physics_name+"TempStabHelper", input),
45  _rho(1.0),
46  _Cp(1.0),
47  _k(1.0),
48  _mu(input)
49  {
50  this->set_parameter
51  (_rho, input,
52  "Physics/"+incompressible_navier_stokes+"/rho", _rho);
53 
54  this->set_parameter
55  (_Cp, input, "Physics/"+heat_transfer+"/Cp", _Cp);
56 
57  this->set_parameter
58  (_k, input, "Physics/"+heat_transfer+"/k", _k);
59  }
60 
61  template<class Mu>
63  {
64  return;
65  }
66 
67  template<class Mu>
69  AssemblyContext& context,
70  CachedValues& /*cache*/ )
71  {
72 #ifdef GRINS_USE_GRVY_TIMERS
73  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::element_time_derivative");
74 #endif
75 
76  // The number of local degrees of freedom in each variable.
77  const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size();
78 
79  // Element Jacobian * quadrature weights for interior integration.
80  const std::vector<libMesh::Real> &JxW =
81  context.get_element_fe(_flow_vars.u_var())->get_JxW();
82 
83  /*
84  const std::vector<std::vector<libMesh::Real> >& u_phi =
85  context.get_element_fe(this->_flow_vars.u_var())->get_phi();
86  */
87 
88  const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
89  context.get_element_fe(this->_flow_vars.u_var())->get_dphi();
90 
91  // Get residuals
92  libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u_var()); // R_{u}
93  libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v_var()); // R_{v}
94  libMesh::DenseSubVector<libMesh::Number> *Fw = NULL;
95  if(this->_dim == 3)
96  {
97  Fw = &context.get_elem_residual(this->_flow_vars.w_var()); // R_{w}
98  }
99 
100  // Now we will build the element Jacobian and residual.
101  // Constructing the residual requires the solution and its
102  // gradient from the previous timestep. This must be
103  // calculated at each quadrature point by summing the
104  // solution degree-of-freedom values by the appropriate
105  // weight functions.
106  unsigned int n_qpoints = context.get_element_qrule().n_points();
107 
108  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var());
109 
110  for (unsigned int qp=0; qp != n_qpoints; qp++)
111  {
112  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
113  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
114 
115  libMesh::RealGradient U( context.interior_value( this->_flow_vars.u_var(), qp ),
116  context.interior_value( this->_flow_vars.v_var(), qp ) );
117  if( this->_dim == 3 )
118  {
119  U(2) = context.interior_value( this->_flow_vars.w_var(), qp );
120  }
121 
122  // Compute the viscosity at this qp
123  libMesh::Real mu_qp = this->_mu(context, qp);
124 
125  libMesh::Real tau_M = this->_flow_stab_helper.compute_tau_momentum( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady );
126 
127  //libMesh::Real tau_E = this->_temp_stab_helper.compute_tau_energy( context, G, _rho, _Cp, _k, U, this->_is_steady );
128 
129  //libMesh::Real RE = this->_temp_stab_helper.compute_res_energy_steady( context, qp, _rho, _Cp, _k );
130 
131  // Compute the solution & its gradient at the old Newton iterate.
132  libMesh::Number T;
133  T = context.interior_value(_temp_vars.T_var(), qp);
134 
135  libMesh::RealGradient residual = _rho_ref*_beta_T*(T-_T_ref)*_g;
136 
137  for (unsigned int i=0; i != n_u_dofs; i++)
138  {
139  Fu(i) += ( -tau_M*residual(0)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
140  // + _rho_ref*_beta_T*tau_E*RE*_g(0)*u_phi[i][qp] )*JxW[qp];
141 
142  Fv(i) += ( -tau_M*residual(1)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
143  // + _rho_ref*_beta_T*tau_E*RE*_g(1)*u_phi[i][qp] )*JxW[qp];
144 
145  if (_dim == 3)
146  {
147  (*Fw)(i) += ( -tau_M*residual(2)*_rho*U*u_gradphi[i][qp] )*JxW[qp];
148  // + _rho_ref*_beta_T*tau_E*RE*_g(2)*u_phi[i][qp] )*JxW[qp];
149  }
150 
151  if (compute_jacobian)
152  {
153  libmesh_not_implemented();
154  } // End compute_jacobian check
155 
156  } // End i dof loop
157  } // End quadrature loop
158 
159 #ifdef GRINS_USE_GRVY_TIMERS
160  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::element_time_derivative");
161 #endif
162 
163  return;
164  }
165 
166  template<class Mu>
168  AssemblyContext& context,
169  CachedValues& /*cache*/ )
170  {
171 #ifdef GRINS_USE_GRVY_TIMERS
172  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::element_constraint");
173 #endif
174 
175  // The number of local degrees of freedom in each variable.
176  const unsigned int n_p_dofs = context.get_dof_indices(_flow_vars.p_var()).size();
177 
178  // Element Jacobian * quadrature weights for interior integration.
179  const std::vector<libMesh::Real> &JxW =
180  context.get_element_fe(_flow_vars.u_var())->get_JxW();
181 
182  const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
183  context.get_element_fe(this->_flow_vars.p_var())->get_dphi();
184 
185  libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_flow_vars.p_var()); // R_{p}
186 
187  // Now we will build the element Jacobian and residual.
188  // Constructing the residual requires the solution and its
189  // gradient from the previous timestep. This must be
190  // calculated at each quadrature point by summing the
191  // solution degree-of-freedom values by the appropriate
192  // weight functions.
193  unsigned int n_qpoints = context.get_element_qrule().n_points();
194 
195  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var());
196 
197  for (unsigned int qp=0; qp != n_qpoints; qp++)
198  {
199  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
200  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
201 
202  libMesh::RealGradient U( context.interior_value( this->_flow_vars.u_var(), qp ),
203  context.interior_value( this->_flow_vars.v_var(), qp ) );
204  if( this->_dim == 3 )
205  {
206  U(2) = context.interior_value( this->_flow_vars.w_var(), qp );
207  }
208 
209  // Compute the viscosity at this qp
210  libMesh::Real mu_qp = this->_mu(context, qp);
211 
212  libMesh::Real tau_M = this->_flow_stab_helper.compute_tau_momentum( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady );
213 
214  // Compute the solution & its gradient at the old Newton iterate.
215  libMesh::Number T;
216  T = context.interior_value(_temp_vars.T_var(), qp);
217 
218  libMesh::RealGradient residual = _rho_ref*_beta_T*(T-_T_ref)*_g;
219 
220  // First, an i-loop over the velocity degrees of freedom.
221  // We know that n_u_dofs == n_v_dofs so we can compute contributions
222  // for both at the same time.
223  for (unsigned int i=0; i != n_p_dofs; i++)
224  {
225  Fp(i) += -tau_M*residual*p_dphi[i][qp]*JxW[qp];
226 
227  if (compute_jacobian)
228  {
229  libmesh_not_implemented();
230  } // End compute_jacobian check
231 
232  } // End i dof loop
233 
234  } // End quadrature loop
235 
236 #ifdef GRINS_USE_GRVY_TIMERS
237  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::element_constraint");
238 #endif
239 
240  return;
241  }
242 
243  template<class Mu>
245  AssemblyContext& /*context*/,
246  CachedValues& /*cache*/ )
247  {
248  /*
249 #ifdef GRINS_USE_GRVY_TIMERS
250  this->_timer->BeginTimer("BoussinesqBuoyancySPGSMStabilization::mass_residual");
251 #endif
252 
253  // The number of local degrees of freedom in each variable.
254  const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size();
255 
256  // Element Jacobian * quadrature weights for interior integration.
257  const std::vector<libMesh::Real> &JxW =
258  context.get_element_fe(_flow_vars.u_var())->get_JxW();
259 
260  const std::vector<std::vector<libMesh::Real> >& u_phi =
261  context.get_element_fe(this->_flow_vars.u_var())->get_phi();
262 
263  // Get residuals
264  libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u_var()); // R_{u}
265  libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v_var()); // R_{v}
266  libMesh::DenseSubVector<libMesh::Number> *Fw = NULL;
267  if(this->_dim == 3)
268  {
269  Fw = &context.get_elem_residual(this->_flow_vars.w_var()); // R_{w}
270  }
271 
272  // Now we will build the element Jacobian and residual.
273  // Constructing the residual requires the solution and its
274  // gradient from the previous timestep. This must be
275  // calculated at each quadrature point by summing the
276  // solution degree-of-freedom values by the appropriate
277  // weight functions.
278  unsigned int n_qpoints = context.get_element_qrule().n_points();
279 
280  libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var());
281 
282  for (unsigned int qp=0; qp != n_qpoints; qp++)
283  {
284  libMesh::RealGradient g = this->_flow_stab_helper.compute_g( fe, context, qp );
285  libMesh::RealTensor G = this->_flow_stab_helper.compute_G( fe, context, qp );
286 
287  libMesh::RealGradient U( context.fixed_interior_value( this->_flow_vars.u_var(), qp ),
288  context.fixed_interior_value( this->_flow_vars.v_var(), qp ) );
289  if( this->_dim == 3 )
290  {
291  U(2) = context.fixed_interior_value( this->_flow_vars.w_var(), qp );
292  }
293 
294  libMesh::Real tau_E = this->_temp_stab_helper.compute_tau_energy( context, G, _rho, _Cp, _k, U, false );
295 
296  libMesh::Real RE = this->_temp_stab_helper.compute_res_energy_transient( context, qp, _rho, _Cp );
297 
298 
299  for (unsigned int i=0; i != n_u_dofs; i++)
300  {
301  Fu(i) += -_rho_ref*_beta_T*tau_E*RE*_g(0)*u_phi[i][qp]*JxW[qp];
302 
303  Fv(i) += -_rho_ref*_beta_T*tau_E*RE*_g(1)*u_phi[i][qp]*JxW[qp];
304 
305  if (_dim == 3)
306  {
307  (*Fw)(i) += -_rho_ref*_beta_T*tau_E*RE*_g(2)*u_phi[i][qp]*JxW[qp];
308  }
309 
310  if (compute_jacobian)
311  {
312  libmesh_not_implemented();
313  } // End compute_jacobian check
314 
315  } // End i dof loop
316  } // End quadrature loop
317 
318 #ifdef GRINS_USE_GRVY_TIMERS
319  this->_timer->EndTimer("BoussinesqBuoyancySPGSMStabilization::mass_residual");
320 #endif
321  */
322 
323  return;
324  }
325 
326  template<class Mu>
328  ( const std::string & param_name,
330  const
331  {
332  ParameterUser::register_parameter(param_name, param_pointer);
333  _mu.register_parameter(param_name, param_pointer);
334  }
335 
336 
337 } // namespace GRINS
338 
339 // Instantiate
340 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.
const PhysicsName incompressible_navier_stokes
INSTANTIATE_INC_NS_SUBCLASS(BoussinesqBuoyancySPGSMStabilization)
virtual void register_parameter(const std::string &param_name, libMesh::ParameterMultiPointer< libMesh::Number > &param_pointer) const
Each subclass will register its copy of an independent.
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...
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for element interiors.
virtual void register_parameter(const std::string &param_name, libMesh::ParameterMultiPointer< libMesh::Number > &param_pointer) const
Each subclass will register its copy of an independent.
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.
const PhysicsName heat_transfer

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1