GRINS-0.7.0
convection_diffusion.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 
26 // This class
28 
29 // GRINS
30 #include "grins/common.h"
31 #include "grins/assembly_context.h"
35 
36 // libMesh
37 #include "libmesh/getpot.h"
38 #include "libmesh/string_to_enum.h"
39 #include "libmesh/quadrature.h"
40 #include "libmesh/fem_system.h"
41 
42 namespace GRINS
43 {
45  const GetPot& input )
46  : Physics(physics_name,input),
47  _v(3,libMesh::ParsedFunction<libMesh::Number>("0.0") ),
48  _kappa("0.0"),
49  _var(input,physics_name)
50  {
51  unsigned int n_v_comps = input.vector_variable_size("Physics/"+physics_name+"/velocity_field");
52 
53  for( unsigned int v = 0; v < n_v_comps; v++ )
54  _v[v].reparse( input("Physics/"+physics_name+"/velocity_field", "0.0", v) );
55 
56  std::string material_name = MaterialsParsing::material_name(input,physics_name);
57 
58  this->set_parameter(this->_kappa, input,
59  "Materials/"+material_name+"/Diffusivity/value",
60  "DIE!");
61 
63 
64  _ic_handler = new GenericICHandler(physics_name,input);
65  }
66 
67  void ConvectionDiffusion::init_variables( libMesh::FEMSystem* system )
68  {
69  _var.init(system);
70  }
71 
72  void ConvectionDiffusion::set_time_evolving_vars( libMesh::FEMSystem* system )
73  {
74  system->time_evolving(_var.var());
75  }
76 
78  {
79  context.get_element_fe(_var.var())->get_JxW();
80  context.get_element_fe(_var.var())->get_phi();
81  context.get_element_fe(_var.var())->get_dphi();
82  context.get_element_fe(_var.var())->get_xyz();
83  }
84 
85  void ConvectionDiffusion::element_time_derivative( bool compute_jacobian,
86  AssemblyContext& context,
87  CachedValues& /*cache*/ )
88  {
89  const unsigned int n_dofs = context.get_dof_indices(_var.var()).size();
90 
91  const std::vector<libMesh::Real> &JxW =
92  context.get_element_fe(_var.var())->get_JxW();
93 
94  const std::vector<std::vector<libMesh::Real> >& phi =
95  context.get_element_fe(_var.var())->get_phi();
96 
97  const std::vector<std::vector<libMesh::RealGradient> >& grad_phi =
98  context.get_element_fe(_var.var())->get_dphi();
99 
100  const std::vector<libMesh::Point>& x =
101  context.get_element_fe(_var.var())->get_xyz();
102 
103  libMesh::DenseSubVector<libMesh::Number> &F = context.get_elem_residual(_var.var());
104 
105  libMesh::DenseSubMatrix<libMesh::Number> &K = context.get_elem_jacobian(_var.var(), _var.var());
106 
107  unsigned int n_qpoints = context.get_element_qrule().n_points();
108 
109  for (unsigned int qp=0; qp != n_qpoints; qp++)
110  {
111  libMesh::Number c = context.interior_value(_var.var(), qp);
112 
113  libMesh::Gradient grad_c;
114  context.interior_gradient(_var.var(), qp, grad_c);
115 
116  libMesh::RealGradient v_qp;
117  v_qp(0) = this->_v[0](x[qp], context.get_time());
118  v_qp(1) = this->_v[1](x[qp], context.get_time());
119  v_qp(2) = this->_v[2](x[qp], context.get_time());
120 
121  libMesh::Real kappa_qp = this->_kappa(x[qp], context.time);
122 
123  for (unsigned int i=0; i != n_dofs; i++)
124  {
125  F(i) += JxW[qp]*( c*(v_qp*grad_phi[i][qp])
126  - kappa_qp*(grad_c*grad_phi[i][qp]) );
127 
128  if (compute_jacobian)
129  {
130  for (unsigned int j=0; j != n_dofs; j++)
131  {
132  K(i,j) += context.get_elem_solution_derivative()*
133  JxW[qp]*( phi[j][qp]*(v_qp*grad_phi[i][qp])
134  - kappa_qp*(grad_phi[j][qp]*grad_phi[i][qp]) );
135  }
136  }
137  }
138  }
139  }
140 
141  void ConvectionDiffusion::mass_residual( bool compute_jacobian,
142  AssemblyContext& context,
143  CachedValues& /*cache*/ )
144  {
145  const unsigned int n_dofs = context.get_dof_indices(_var.var()).size();
146 
147  const std::vector<libMesh::Real> &JxW =
148  context.get_element_fe(_var.var())->get_JxW();
149 
150  const std::vector<std::vector<libMesh::Real> >& phi =
151  context.get_element_fe(_var.var())->get_phi();
152 
153  libMesh::DenseSubVector<libMesh::Number> &F = context.get_elem_residual(_var.var());
154 
155  libMesh::DenseSubMatrix<libMesh::Number> &M = context.get_elem_jacobian(_var.var(), _var.var());
156 
157  unsigned int n_qpoints = context.get_element_qrule().n_points();
158 
159  for (unsigned int qp=0; qp != n_qpoints; qp++)
160  {
161  libMesh::Real c_dot;
162  context.interior_rate(_var.var(), qp, c_dot);
163 
164  for (unsigned int i=0; i != n_dofs; i++)
165  {
166  F(i) -= JxW[qp]*( c_dot*phi[i][qp] );
167 
168  if (compute_jacobian)
169  {
170  for (unsigned int j=0; j != n_dofs; j++)
171  {
172  M(i,j) -=
173  context.get_elem_solution_rate_derivative()*
174  JxW[qp]*( phi[j][qp]*phi[i][qp] );
175  }
176  }
177  }
178  }
179  }
180 
181 } // end namespace GRINS
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 init_variables(libMesh::FEMSystem *system)
Initialize variables for this physics.
GRINS::ICHandlingBase * _ic_handler
Definition: physics.h:269
Physics abstract base class. Defines API for physics to be added to MultiphysicsSystem.
Definition: physics.h:107
virtual void set_time_evolving_vars(libMesh::FEMSystem *system)
Set which variables are time evolving.
virtual void init(libMesh::FEMSystem *system)
Add variables to the system.
static void check_and_register_variable(const std::string &var_name, const FEVariablesBase &variable)
First check if var_name is registered and then register.
Base class for reading and handling initial conditions for physics classes.
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.
libMesh::ParsedFunction< libMesh::Number > _kappa
Diffusivity, .
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...
std::string PhysicsName
GenericFETypeVariable _var
static std::string material_name(const GetPot &input, const std::string &physics)
Get the name of the material in the Physics/physics section.
std::vector< libMesh::ParsedFunction< libMesh::Number > > _v
Velocity field, ;.
std::string section_name(const std::string &physics_name) const
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.

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