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

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