GRINS-0.8.0
heat_transfer.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 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_transfer.h"
28 
29 // GRINS
30 #include "grins_config.h"
31 #include "grins/assembly_context.h"
35 
36 // libMesh
37 #include "libmesh/getpot.h"
38 #include "libmesh/quadrature.h"
39 #include "libmesh/boundary_info.h"
40 
41 namespace GRINS
42 {
43 
44  template<class K>
45  HeatTransfer<K>::HeatTransfer( const std::string& physics_name, const GetPot& input )
46  : HeatTransferBase<K>(physics_name, PhysicsNaming::heat_transfer(), input),
47  _k_index(0)
48  {
49  this->_ic_handler = new GenericICHandler( physics_name, input );
50  }
51 
52  template<class K>
55  {
56  std::string section = "Physics/"+PhysicsNaming::heat_transfer()+"/output_vars";
57 
58  if( input.have_variable(section) )
59  {
60  unsigned int n_vars = input.vector_variable_size(section);
61 
62  for( unsigned int v = 0; v < n_vars; v++ )
63  {
64  std::string name = input(section,"DIE!",v);
65 
66  if( name == std::string("k") )
67  {
68  this->_k_index = postprocessing.register_quantity( name );
69  }
70  else
71  {
72  std::cerr << "Error: Invalid output_vars value for "+PhysicsNaming::heat_transfer() << std::endl
73  << " Found " << name << std::endl
74  << " Acceptable values are: k" << std::endl;
75  libmesh_error();
76  }
77  }
78  }
79 
80  return;
81  }
82 
83  template<class K>
85  ( bool compute_jacobian,
86  AssemblyContext & context )
87  {
88  // The number of local degrees of freedom in each variable.
89  const unsigned int n_T_dofs = context.get_dof_indices(this->_temp_vars.T()).size();
90  const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
91 
92  //TODO: check n_T_dofs is same as n_u_dofs, n_v_dofs, n_w_dofs
93 
94  // We get some references to cell-specific data that
95  // will be used to assemble the linear system.
96 
97  // Element Jacobian * quadrature weights for interior integration.
98  const std::vector<libMesh::Real> &JxW =
99  context.get_element_fe(this->_temp_vars.T())->get_JxW();
100 
101  // The temperature shape functions at interior quadrature points.
102  const std::vector<std::vector<libMesh::Real> >& T_phi =
103  context.get_element_fe(this->_temp_vars.T())->get_phi();
104 
105  // The velocity shape functions at interior quadrature points.
106  const std::vector<std::vector<libMesh::Real> >& vel_phi =
107  context.get_element_fe(this->_flow_vars.u())->get_phi();
108 
109  // The temperature shape function gradients (in global coords.)
110  // at interior quadrature points.
111  const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
112  context.get_element_fe(this->_temp_vars.T())->get_dphi();
113 
114  const std::vector<libMesh::Point>& u_qpoint =
115  context.get_element_fe(this->_flow_vars.u())->get_xyz();
116 
117  libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(this->_temp_vars.T(), this->_temp_vars.T()); // R_{T},{T}
118 
119  libMesh::DenseSubMatrix<libMesh::Number> &KTu = context.get_elem_jacobian(this->_temp_vars.T(), this->_flow_vars.u()); // R_{T},{u}
120  libMesh::DenseSubMatrix<libMesh::Number> &KTv = context.get_elem_jacobian(this->_temp_vars.T(), this->_flow_vars.v()); // R_{T},{v}
121  libMesh::DenseSubMatrix<libMesh::Number>* KTw = NULL;
122 
123  libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(this->_temp_vars.T()); // R_{T}
124 
125  if( this->_flow_vars.dim() == 3 )
126  {
127  KTw = &context.get_elem_jacobian(this->_temp_vars.T(), this->_flow_vars.w()); // R_{T},{w}
128  }
129 
130  // Now we will build the element Jacobian and residual.
131  // Constructing the residual requires the solution and its
132  // gradient from the previous timestep. This must be
133  // calculated at each quadrature point by summing the
134  // solution degree-of-freedom values by the appropriate
135  // weight functions.
136  unsigned int n_qpoints = context.get_element_qrule().n_points();
137 
138  for (unsigned int qp=0; qp != n_qpoints; qp++)
139  {
140  // Compute the solution & its gradient at the old Newton iterate.
141  libMesh::Number u, v;
142  u = context.interior_value(this->_flow_vars.u(), qp);
143  v = context.interior_value(this->_flow_vars.v(), qp);
144 
145  libMesh::Gradient grad_T;
146  grad_T = context.interior_gradient(this->_temp_vars.T(), qp);
147 
148  libMesh::NumberVectorValue U (u,v);
149  if (this->_flow_vars.dim() == 3)
150  U(2) = context.interior_value(this->_flow_vars.w(), qp);
151 
152  const libMesh::Number r = u_qpoint[qp](0);
153 
154  libMesh::Real jac = JxW[qp];
155 
156  // Compute the conductivity at this qp
157  libMesh::Real _k_qp = this->_k(context, qp);
158 
160  {
161  jac *= r;
162  }
163 
164  // First, an i-loop over the degrees of freedom.
165  for (unsigned int i=0; i != n_T_dofs; i++)
166  {
167  FT(i) += jac *
168  (-this->_rho*this->_Cp*T_phi[i][qp]*(U*grad_T) // convection term
169  -_k_qp*(T_gradphi[i][qp]*grad_T) ); // diffusion term
170 
171  if (compute_jacobian)
172  {
173  for (unsigned int j=0; j != n_T_dofs; j++)
174  {
175  // TODO: precompute some terms like:
176  // this->_rho*this->_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp])
177 
178  KTT(i,j) += jac * context.get_elem_solution_derivative() *
179  (-this->_rho*this->_Cp*T_phi[i][qp]*(U*T_gradphi[j][qp]) // convection term
180  -_k_qp*(T_gradphi[i][qp]*T_gradphi[j][qp])); // diffusion term
181  } // end of the inner dof (j) loop
182 
183  // Matrix contributions for the Tu, Tv and Tw couplings (n_T_dofs same as n_u_dofs, n_v_dofs and n_w_dofs)
184  for (unsigned int j=0; j != n_u_dofs; j++)
185  {
186  KTu(i,j) += jac * context.get_elem_solution_derivative()*(-this->_rho*this->_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(0)));
187  KTv(i,j) += jac * context.get_elem_solution_derivative()*(-this->_rho*this->_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(1)));
188  if (this->_flow_vars.dim() == 3)
189  (*KTw)(i,j) += jac * context.get_elem_solution_derivative()*(-this->_rho*this->_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(2)));
190  } // end of the inner dof (j) loop
191 
192  } // end - if (compute_jacobian && context.get_elem_solution_derivative())
193 
194  } // end of the outer dof (i) loop
195  } // end of the quadrature point (qp) loop
196  }
197 
198  template<class K>
200  ( bool compute_jacobian, AssemblyContext & context )
201  {
202  // First we get some references to cell-specific data that
203  // will be used to assemble the linear system.
204 
205  // Element Jacobian * quadrature weights for interior integration
206  const std::vector<libMesh::Real> &JxW =
207  context.get_element_fe(this->_temp_vars.T())->get_JxW();
208 
209  // The shape functions at interior quadrature points.
210  const std::vector<std::vector<libMesh::Real> >& phi =
211  context.get_element_fe(this->_temp_vars.T())->get_phi();
212 
213  const std::vector<libMesh::Point>& u_qpoint =
214  context.get_element_fe(this->_flow_vars.u())->get_xyz();
215 
216  // The number of local degrees of freedom in each variable
217  const unsigned int n_T_dofs = context.get_dof_indices(this->_temp_vars.T()).size();
218 
219  // The subvectors and submatrices we need to fill:
220  libMesh::DenseSubVector<libMesh::Real> &F = context.get_elem_residual(this->_temp_vars.T());
221 
222  libMesh::DenseSubMatrix<libMesh::Real> &M = context.get_elem_jacobian(this->_temp_vars.T(), this->_temp_vars.T());
223 
224  unsigned int n_qpoints = context.get_element_qrule().n_points();
225 
226  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
227  {
228  // For the mass residual, we need to be a little careful.
229  // The time integrator is handling the time-discretization
230  // for us so we need to supply M(u_fixed)*u' for the residual.
231  // u_fixed will be given by the fixed_interior_value function
232  // while u' will be given by the interior_rate function.
233  libMesh::Real T_dot;
234  context.interior_rate(this->_temp_vars.T(), qp, T_dot);
235 
236  const libMesh::Number r = u_qpoint[qp](0);
237 
238  libMesh::Real jac = JxW[qp];
239 
241  {
242  jac *= r;
243  }
244 
245  for (unsigned int i = 0; i != n_T_dofs; ++i)
246  {
247  F(i) -= this->_rho*this->_Cp*T_dot*phi[i][qp]*jac;
248 
249  if( compute_jacobian )
250  {
251  for (unsigned int j=0; j != n_T_dofs; j++)
252  {
253  // We're assuming rho, cp are constant w.r.t. T here.
254  M(i,j) -= this->_rho*this->_Cp*phi[j][qp]*phi[i][qp]*jac * context.get_elem_solution_rate_derivative();
255  }
256  }// End of check on Jacobian
257 
258  } // End of element dof loop
259 
260  } // End of the quadrature point loop
261  }
262 
263  template<class K>
264  void HeatTransfer<K>::compute_postprocessed_quantity( unsigned int quantity_index,
265  const AssemblyContext& context,
266  const libMesh::Point& point,
267  libMesh::Real& value )
268  {
269  if( quantity_index == this->_k_index )
270  value = this->_k(point, context.get_time());
271  }
272 
273 } // namespace GRINS
274 
275 // Instantiate
static bool is_axisymmetric()
Definition: physics.h:132
static PhysicsName heat_transfer()
unsigned int register_quantity(std::string name)
Register quantity to be postprocessed.
GRINS::ICHandlingBase * _ic_handler
Definition: physics.h:258
Physics class for Heat Transfer.
Base class for reading and handling initial conditions for physics classes.
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for element interiors.
Definition: heat_transfer.C:85
GRINS namespace.
virtual void mass_residual(bool compute_jacobian, AssemblyContext &context)
Mass matrix part(s) for element interiors. All boundary terms lie within the time_derivative part...
virtual void compute_postprocessed_quantity(unsigned int quantity_index, const AssemblyContext &context, const libMesh::Point &point, libMesh::Real &value)
Compute value of postprocessed quantities at libMesh::Point.
INSTANTIATE_HEAT_TRANSFER_SUBCLASS(HeatTransfer)
virtual void register_postprocessing_vars(const GetPot &input, PostProcessedQuantities< libMesh::Real > &postprocessing)
Register postprocessing variables for HeatTransfer.
Definition: heat_transfer.C:53

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1