GRINS-0.6.0
heat_conduction.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 
26 // This class
27 #include "grins/heat_conduction.h"
28 
29 // GRINS
30 #include "grins/assembly_context.h"
35 
36 // libMesh
37 #include "libmesh/quadrature.h"
38 #include "libmesh/fem_system.h"
39 
40 namespace GRINS
41 {
42 
43  template<class K>
44  HeatConduction<K>::HeatConduction( const GRINS::PhysicsName& physics_name, const GetPot& input )
45  : Physics(physics_name,input),
46  _temp_vars(input,heat_conduction),
47  _rho(1.0),
48  _Cp(1.0),
49  _k(input)
50  {
51  // \todo same as Incompressible NS
52  this->set_parameter
53  (_rho, input, "Physics/"+heat_conduction+"/rho", _rho );
54 
55  this->set_parameter
56  (_Cp, input, "Physics/"+heat_conduction+"/Cp", _Cp );
57 
58  // This is deleted in the base class
59  this->_bc_handler = new HeatTransferBCHandling( physics_name, input );
60  this->_ic_handler = new GenericICHandler( physics_name, input );
61 
62  return;
63  }
64 
65  template<class K>
67  {
68  return;
69  }
70 
71  template<class K>
72  void HeatConduction<K>::init_variables( libMesh::FEMSystem* system )
73  {
74  // Get libMesh to assign an index for each variable
75  this->_dim = system->get_mesh().mesh_dimension();
76 
77  _temp_vars.init(system);
78 
79  return;
80  }
81 
82  template<class K>
83  void HeatConduction<K>::set_time_evolving_vars( libMesh::FEMSystem* system )
84  {
85  // Tell the system to march temperature forward in time
86  system->time_evolving(_temp_vars.T_var());
87 
88  return;
89  }
90 
91  template<class K>
93  {
94  // We should prerequest all the data
95  // we will need to build the linear system
96  // or evaluate a quantity of interest.
97  context.get_element_fe(_temp_vars.T_var())->get_JxW();
98  context.get_element_fe(_temp_vars.T_var())->get_phi();
99  context.get_element_fe(_temp_vars.T_var())->get_dphi();
100  context.get_element_fe(_temp_vars.T_var())->get_xyz();
101 
102  context.get_side_fe(_temp_vars.T_var())->get_JxW();
103  context.get_side_fe(_temp_vars.T_var())->get_phi();
104  context.get_side_fe(_temp_vars.T_var())->get_dphi();
105  context.get_side_fe(_temp_vars.T_var())->get_xyz();
106 
107  return;
108  }
109 
110  template<class K>
111  void HeatConduction<K>::element_time_derivative( bool compute_jacobian,
112  AssemblyContext& context,
113  CachedValues& /*cache*/ )
114  {
115  // The number of local degrees of freedom in each variable.
116  const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size();
117 
118  // We get some references to cell-specific data that
119  // will be used to assemble the linear system.
120 
121  // Element Jacobian * quadrature weights for interior integration.
122  const std::vector<libMesh::Real> &JxW =
123  context.get_element_fe(_temp_vars.T_var())->get_JxW();
124 
125  // The temperature shape function gradients (in global coords.)
126  // at interior quadrature points.
127  const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
128  context.get_element_fe(_temp_vars.T_var())->get_dphi();
129 
130  // The subvectors and submatrices we need to fill:
131  //
132  // K_{\alpha \beta} = R_{\alpha},{\beta} = \partial{ R_{\alpha} } / \partial{ {\beta} } (where R denotes residual)
133  // e.g., for \alpha = T and \beta = v we get: K_{Tu} = R_{T},{u}
134  //
135 
136  libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var()); // R_{T},{T}
137 
138  libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_temp_vars.T_var()); // R_{T}
139 
140  // Now we will build the element Jacobian and residual.
141  // Constructing the residual requires the solution and its
142  // gradient from the previous timestep. This must be
143  // calculated at each quadrature point by summing the
144  // solution degree-of-freedom values by the appropriate
145  // weight functions.
146  unsigned int n_qpoints = context.get_element_qrule().n_points();
147 
148  for (unsigned int qp=0; qp != n_qpoints; qp++)
149  {
150  // Compute the solution & its gradient at the old Newton iterate.
151  libMesh::Gradient grad_T;
152  grad_T = context.interior_gradient(_temp_vars.T_var(), qp);
153 
154  // Compute the conductivity at this qp
155  libMesh::Real _k_qp = this->_k(context, qp);
156 
157  // First, an i-loop over the degrees of freedom.
158  for (unsigned int i=0; i != n_T_dofs; i++)
159  {
160  FT(i) += JxW[qp]*(-_k_qp*(T_gradphi[i][qp]*grad_T));
161 
162  if (compute_jacobian)
163  {
164  for (unsigned int j=0; j != n_T_dofs; j++)
165  {
166  // TODO: precompute some terms like:
167  // _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp])
168 
169  KTT(i,j) += JxW[qp] * context.get_elem_solution_derivative() *
170  ( -_k_qp*(T_gradphi[i][qp]*T_gradphi[j][qp]) ); // diffusion term
171  } // end of the inner dof (j) loop
172 
173  } // end - if (compute_jacobian && context.get_elem_solution_derivative())
174 
175  } // end of the outer dof (i) loop
176  } // end of the quadrature point (qp) loop
177 
178  return;
179  }
180 
181  template<class K>
182  void HeatConduction<K>::mass_residual( bool compute_jacobian,
183  AssemblyContext& context,
184  CachedValues& /*cache*/ )
185  {
186  // First we get some references to cell-specific data that
187  // will be used to assemble the linear system.
188 
189  // Element Jacobian * quadrature weights for interior integration
190  const std::vector<libMesh::Real> &JxW =
191  context.get_element_fe(_temp_vars.T_var())->get_JxW();
192 
193  // The shape functions at interior quadrature points.
194  const std::vector<std::vector<libMesh::Real> >& phi =
195  context.get_element_fe(_temp_vars.T_var())->get_phi();
196 
197  // The number of local degrees of freedom in each variable
198  const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size();
199 
200  // The subvectors and submatrices we need to fill:
201  libMesh::DenseSubVector<libMesh::Real> &F =
202  context.get_elem_residual(_temp_vars.T_var());
203 
204  libMesh::DenseSubMatrix<libMesh::Real> &M =
205  context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var());
206 
207  unsigned int n_qpoints = context.get_element_qrule().n_points();
208 
209  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
210  {
211  // For the mass residual, we need to be a little careful.
212  // The time integrator is handling the time-discretization
213  // for us so we need to supply M(u_fixed)*u' for the residual.
214  // u_fixed will be given by the fixed_interior_value function
215  // while u' will be given by the interior_rate function.
216  libMesh::Real T_dot;
217  context.interior_rate(_temp_vars.T_var(), qp, T_dot);
218 
219  for (unsigned int i = 0; i != n_T_dofs; ++i)
220  {
221  F(i) -= JxW[qp]*(_rho*_Cp*T_dot*phi[i][qp] );
222 
223  if( compute_jacobian )
224  {
225  for (unsigned int j=0; j != n_T_dofs; j++)
226  {
227  // We're assuming rho, cp are constant w.r.t. T here.
228  M(i,j) -=
229  context.get_elem_solution_rate_derivative()
230  * JxW[qp]*_rho*_Cp*phi[j][qp]*phi[i][qp] ;
231  }
232  }// End of check on Jacobian
233 
234  } // End of element dof loop
235 
236  } // End of the quadrature point loop
237 
238  return;
239  }
240 
241  template<class K>
243  ( const std::string & param_name,
245  const
246  {
247  ParameterUser::register_parameter(param_name, param_pointer);
248  _k.register_parameter(param_name, param_pointer);
249  }
250 
251 
252 } // namespace GRINS
253 
254 // Instantiate
255 INSTANTIATE_HEAT_TRANSFER_SUBCLASS(HeatConduction);
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.
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...
Base class for reading and handling boundary conditions for physics classes.
GRINS::ICHandlingBase * _ic_handler
Definition: physics.h:258
libMesh::Number _Cp
GRINS::BCHandlingBase * _bc_handler
Definition: physics.h:256
Physics abstract base class. Defines API for physics to be added to MultiphysicsSystem.
Definition: physics.h:106
libMesh::Number _rho
const PhysicsName heat_conduction
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.
INSTANTIATE_HEAT_TRANSFER_SUBCLASS(HeatConduction)
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.
Base class for reading and handling initial conditions for physics classes.
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.
std::string PhysicsName
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.
virtual void set_time_evolving_vars(libMesh::FEMSystem *system)
Set which variables are time evolving.
virtual void init_variables(libMesh::FEMSystem *system)
Initialize variables for this physics.

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