GRINS-0.8.0
scalar_ode.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/scalar_ode.h"
28 
29 // GRINS
32 
33 // libMesh
34 #include "libmesh/boundary_info.h"
35 #include "libmesh/parsed_fem_function.h"
36 
37 namespace GRINS
38 {
39 
40  ScalarODE::ScalarODE( const std::string& physics_name, const GetPot& input )
41  : Physics(physics_name, input),
42  _epsilon(1e-6),
43  _input(input),
44  _var(GRINSPrivate::VariableWarehouse::get_variable_subclass<ScalarVariable>(VariablesParsing::scalar_variable_name(input,physics_name,VariablesParsing::PHYSICS)))
45  {
46  this->read_input_options(input);
47 
48  this->_ic_handler = new GenericICHandler( physics_name, input );
49  }
50 
51  void ScalarODE::set_time_evolving_vars( libMesh::FEMSystem* system )
52  {
53  system->time_evolving(this->scalar_ode_var(), 1);
54 
55  // FIXME: this doesn't fit here at all, but it's the only time
56  // we've clearly got a System to grab hold of with all it's
57  // variables initialized.
58 
61  this->time_deriv_function.reset(tdf);
62 
63  if (tdf->expression() == "0")
64  std::cout << "Warning! Zero time_deriv function specified!" << std::endl;
65 
66  this->set_parameter(*tdf, _input,
67  "Physics/"+PhysicsNaming::scalar_ode()+"/time_deriv",
68  std::string("0"));
69 
72  this->mass_residual_function.reset(mrf);
73 
74  if (mrf->expression() == "0")
75  std::cout << "Warning! Zero mass_residual function specified!" << std::endl;
76 
77  this->set_parameter(*mrf, _input,
78  "Physics/"+PhysicsNaming::scalar_ode()+"/mass_residual",
79  std::string("0"));
80 
83  this->constraint_function.reset(cf);
84 
85  this->set_parameter(*cf, _input,
86  "Physics/"+PhysicsNaming::scalar_ode()+"/constraint",
87  std::string("0"));
88  }
89 
90 
91  void ScalarODE::read_input_options( const GetPot& input )
92  {
93  this->_epsilon = input("Physics/"+PhysicsNaming::scalar_ode()+"/epsilon", 1e-6);
94  }
95 
96 
98  {
99  mass_residual_function->init_context(context);
100  time_deriv_function->init_context(context);
101  constraint_function->init_context(context);
102  }
103 
104 
106  ( bool compute_jacobian, AssemblyContext & context )
107  {
108  libMesh::DenseSubMatrix<libMesh::Number> &Kss =
109  context.get_elem_jacobian(this->scalar_ode_var(), this->scalar_ode_var()); // R_{s},{s}
110 
111  libMesh::DenseSubVector<libMesh::Number> &Fs =
112  context.get_elem_residual(this->scalar_ode_var()); // R_{s}
113 
114  const libMesh::Number time_deriv =
115  (*time_deriv_function)(context, libMesh::Point(0),
116  context.get_time());
117 
118  Fs(0) += time_deriv;
119 
120  if (compute_jacobian)
121  {
122  // FIXME: we should replace this hacky FDM with a hook to the
123  // AD fparser stuff
124  libMesh::DenseSubVector<libMesh::Number> &Us =
125  const_cast<libMesh::DenseSubVector<libMesh::Number>&>
126  (context.get_elem_solution(this->scalar_ode_var())); // U_{s}
127 
128  const libMesh::Number s = Us(0);
129  Us(0) = s + this->_epsilon;
130  libMesh::Number time_deriv_jacobian =
131  (*time_deriv_function)(context, libMesh::Point(0),
132  context.get_time());
133 
134  Us(0) = s - this->_epsilon;
135  time_deriv_jacobian -=
136  (*time_deriv_function)(context, libMesh::Point(0),
137  context.get_time());
138 
139  Us(0) = s;
140  time_deriv_jacobian /= (2*this->_epsilon);
141 
142  Kss(0,0) += time_deriv_jacobian *
143  context.get_elem_solution_derivative();
144  }
145 
146  return;
147  }
148 
149 
151  (bool compute_jacobian, AssemblyContext & context )
152  {
153  libMesh::DenseSubMatrix<libMesh::Number> &Kss =
154  context.get_elem_jacobian(this->scalar_ode_var(), this->scalar_ode_var()); // R_{s},{s}
155 
156  libMesh::DenseSubVector<libMesh::Number> &Fs =
157  context.get_elem_residual(this->scalar_ode_var()); // R_{s}
158 
159  const libMesh::Number mass_res =
160  (*mass_residual_function)(context, libMesh::Point(0),
161  context.get_time());
162 
163  Fs(0) -= mass_res;
164 
165  if (compute_jacobian)
166  {
167  // FIXME: we should replace this hacky FDM with a hook to the
168  // AD fparser stuff
169  libMesh::DenseSubVector<libMesh::Number> &Us =
170  const_cast<libMesh::DenseSubVector<libMesh::Number>&>
171  (context.get_elem_solution_rate(this->scalar_ode_var())); // U_{s}
172 
173  const libMesh::Number s = Us(0);
174  Us(0) = s + this->_epsilon;
175  libMesh::Number mass_residual_jacobian =
176  (*mass_residual_function)(context, libMesh::Point(0),
177  context.get_time());
178 
179  Us(0) = s - this->_epsilon;
180  mass_residual_jacobian -=
181  (*mass_residual_function)(context, libMesh::Point(0),
182  context.get_time());
183 
184  Us(0) = s;
185  mass_residual_jacobian /= (2*this->_epsilon);
186 
187  Kss(0,0) -= mass_residual_jacobian *
188  context.get_elem_solution_rate_derivative();
189  }
190 
191  return;
192  }
193 
194 
196  ( bool compute_jacobian, AssemblyContext & context )
197  {
198  libMesh::DenseSubMatrix<libMesh::Number> &Kss =
199  context.get_elem_jacobian(this->scalar_ode_var(), this->scalar_ode_var()); // R_{s},{s}
200 
201  libMesh::DenseSubVector<libMesh::Number> &Fs =
202  context.get_elem_residual(this->scalar_ode_var()); // R_{s}
203 
204  const libMesh::Number constraint =
205  (*constraint_function)(context, libMesh::Point(0),
206  context.get_time());
207 
208  Fs(0) += constraint;
209 
210  if (compute_jacobian)
211  {
212  // FIXME: we should replace this hacky FDM with a hook to the
213  // AD fparser stuff
214  libMesh::DenseSubVector<libMesh::Number> &Us =
215  const_cast<libMesh::DenseSubVector<libMesh::Number>&>
216  (context.get_elem_solution(this->scalar_ode_var())); // U_{s}
217 
218  const libMesh::Number s = Us(0);
219  Us(0) = s + this->_epsilon;
220  libMesh::Number constraint_jacobian =
221  (*constraint_function)(context, libMesh::Point(0),
222  context.get_time());
223 
224  Us(0) = s - this->_epsilon;
225  constraint_jacobian -=
226  (*constraint_function)(context, libMesh::Point(0),
227  context.get_time());
228 
229  Us(0) = s;
230  constraint_jacobian /= (2*this->_epsilon);
231 
232  Kss(0,0) += constraint_jacobian *
233  context.get_elem_solution_derivative();
234  }
235 
236  return;
237  }
238 
239 } // 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.
GRINS::ICHandlingBase * _ic_handler
Definition: physics.h:258
const GetPot & _input
Definition: scalar_ode.h:94
static PhysicsName scalar_ode()
Physics abstract base class. Defines API for physics to be added to MultiphysicsSystem.
Definition: physics.h:106
libMesh::UniquePtr< libMesh::FEMFunctionBase< libMesh::Number > > mass_residual_function
Definition: scalar_ode.h:87
virtual void nonlocal_mass_residual(bool compute_jacobian, AssemblyContext &context)
Mass matrix part(s) for scalar variables.
Definition: scalar_ode.C:151
Base class for reading and handling initial conditions for physics classes.
void read_input_options(const GetPot &input)
Read options from GetPot input file.
Definition: scalar_ode.C:91
virtual void init_context(AssemblyContext &context)
Prepare the context for evaluations.
Definition: scalar_ode.C:97
GRINS namespace.
virtual void nonlocal_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for scalar variables.
Definition: scalar_ode.C:106
libMesh::Number _epsilon
Definition: scalar_ode.h:92
virtual void set_time_evolving_vars(libMesh::FEMSystem *system)
Sets scalar variable(s) to be time-evolving.
Definition: scalar_ode.C:51
virtual void nonlocal_constraint(bool compute_jacobian, AssemblyContext &context)
Constraint part(s) of physics for scalar variables.
Definition: scalar_ode.C:196
Variables with a single SCALAR component.
libMesh::UniquePtr< libMesh::FEMFunctionBase< libMesh::Number > > time_deriv_function
Definition: scalar_ode.h:87
VariableIndex scalar_ode_var() const
Definition: scalar_ode.h:79
libMesh::UniquePtr< libMesh::FEMFunctionBase< libMesh::Number > > constraint_function
Definition: scalar_ode.h:87

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