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

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