GRINS-0.6.0
multiphysics_sys.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/multiphysics_sys.h"
28 
29 // GRINS
30 #include "grins/assembly_context.h"
31 
32 // libMesh
33 #include "libmesh/composite_function.h"
34 #include "libmesh/getpot.h"
35 #include "libmesh/parameter_multipointer.h"
36 
37 namespace GRINS
38 {
39 
40  MultiphysicsSystem::MultiphysicsSystem( libMesh::EquationSystems& es,
41  const std::string& name,
42  const unsigned int number )
43  : FEMSystem(es, name, number),
44  _use_numerical_jacobians_only(false)
45  {
46  return;
47  }
48 
50  {
51  return;
52  }
53 
55  {
56  _physics_list = physics_list;
57  return;
58  }
59 
60  void MultiphysicsSystem::read_input_options( const GetPot& input )
61  {
62  // Read options for MultiphysicsSystem first
63  this->verify_analytic_jacobians = input("linear-nonlinear-solver/verify_analytic_jacobians", 0.0 );
64  this->print_solution_norms = input("screen-options/print_solution_norms", false );
65  this->print_solutions = input("screen-options/print_solutions", false );
66  this->print_residual_norms = input("screen-options/print_residual_norms", false );
67 
68  // backwards compatibility with old config files.
70  this->print_residuals = input("screen-options/print_residual", false );
71  if (this->print_residuals)
72  libmesh_deprecated();
73 
74  this->print_residuals = input("screen-options/print_residuals", this->print_residuals );
75  this->print_jacobian_norms = input("screen-options/print_jacobian_norms", false );
76  this->print_jacobians = input("screen-options/print_jacobians", false );
77  this->print_element_solutions = input("screen-options/print_element_solutions", false );
78  this->print_element_residuals = input("screen-options/print_element_residuals", false );
79  this->print_element_jacobians = input("screen-options/print_element_jacobians", false );
80 
81  _use_numerical_jacobians_only = input("linear-nonlinear-solver/use_numerical_jacobians_only", false );
82 
83  numerical_jacobian_h =
84  input("linear-nonlinear-solver/numerical_jacobian_h",
85  numerical_jacobian_h);
86  }
87 
89  {
90  // Need this to be true because of our overloading of the
91  // mass_residual function.
92  // This is data in FEMSystem. MUST be set before FEMSystem::init_data.
93  use_fixed_solution = true;
94 
95  // Initalize all the variables. We pass this pointer for the system.
96  /* NOTE: We CANNOT fuse this loop with the others. This loop
97  MUST complete first. */
100  for( PhysicsListIter physics_iter = _physics_list.begin();
101  physics_iter != _physics_list.end();
102  physics_iter++ )
103  {
104  (physics_iter->second)->init_variables( this );
105  }
106 
107  // Now set time_evolving variables
108  for( PhysicsListIter physics_iter = _physics_list.begin();
109  physics_iter != _physics_list.end();
110  physics_iter++ )
111  {
112  (physics_iter->second)->set_time_evolving_vars( this );
113  }
114 
115  // Set whether the problem we're solving is steady or not
116  // Since the variable is static, just call one Physics class
117  {
118  (_physics_list.begin()->second)->set_is_steady((this->time_solver)->is_steady());
119  }
120 
121  for( PhysicsListIter physics_iter = _physics_list.begin();
122  physics_iter != _physics_list.end();
123  physics_iter++ )
124  {
125  // Initialize builtin BC's for each physics
126  (physics_iter->second)->init_bcs( this );
127  }
128 
129  // Next, call parent init_data function to intialize everything.
130  libMesh::FEMSystem::init_data();
131 
132  // After solution has been initialized we can project initial
133  // conditions to it
135  for( PhysicsListIter physics_iter = _physics_list.begin();
136  physics_iter != _physics_list.end();
137  physics_iter++ )
138  {
139  // Initialize builtin IC's for each physics
140  (physics_iter->second)->init_ics( this, ic_function );
141  }
142 
143  if (ic_function.n_subfunctions())
144  {
145  this->project_solution(&ic_function);
146  }
147 
148  // Now do any auxillary initialization required by each Physics
149  for( PhysicsListIter physics_iter = _physics_list.begin();
150  physics_iter != _physics_list.end();
151  physics_iter++ )
152  {
153  (physics_iter->second)->auxiliary_init( *this );
154  }
155 
156  return;
157  }
158 
159  libMesh::AutoPtr<libMesh::DiffContext> MultiphysicsSystem::build_context()
160  {
161  AssemblyContext* context = new AssemblyContext(*this);
162 
163  libMesh::AutoPtr<libMesh::DiffContext> ap(context);
164 
165  libMesh::DifferentiablePhysics* phys = libMesh::FEMSystem::get_physics();
166 
167  libmesh_assert(phys);
168 
169  // If we are solving a moving mesh problem, tell that to the Context
170  context->set_mesh_system(phys->get_mesh_system());
171  context->set_mesh_x_var(phys->get_mesh_x_var());
172  context->set_mesh_y_var(phys->get_mesh_y_var());
173  context->set_mesh_z_var(phys->get_mesh_z_var());
174 
175  ap->set_deltat_pointer( &deltat );
176 
177  // If we are solving the adjoint problem, tell that to the Context
178  ap->is_adjoint() = this->get_time_solver().is_adjoint();
179 
180  return ap;
181  }
182 
185  {
186  for( PhysicsListIter physics_iter = _physics_list.begin();
187  physics_iter != _physics_list.end();
188  physics_iter++ )
189  {
190  (physics_iter->second)->register_postprocessing_vars( input, postprocessing );
191  }
192 
193  return;
194  }
195 
197  ( const std::string & param_name,
199  {
200  //Loop over each physics to ask each for the requested parameter
201  for( PhysicsListIter physics_iter = _physics_list.begin();
202  physics_iter != _physics_list.end();
203  physics_iter++ )
204  {
205  (physics_iter->second)->register_parameter( param_name,
206  param_pointer );
207  }
208  }
209 
210 
211 
212  void MultiphysicsSystem::init_context( libMesh::DiffContext& context )
213  {
214  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
215 
216  //Loop over each physics to initialize relevant variable structures for assembling system
217  for( PhysicsListIter physics_iter = _physics_list.begin();
218  physics_iter != _physics_list.end();
219  physics_iter++ )
220  {
221  (physics_iter->second)->init_context( c );
222  }
223 
224  return;
225  }
226 
227 
228  bool MultiphysicsSystem::_general_residual( bool request_jacobian,
229  libMesh::DiffContext& context,
230  ResFuncType resfunc,
231  CacheFuncType cachefunc)
232  {
233  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
234 
235  bool compute_jacobian = true;
236  if( !request_jacobian || _use_numerical_jacobians_only ) compute_jacobian = false;
237 
238  CachedValues cache;
239 
240  // Now compute cache for this element
241  for( PhysicsListIter physics_iter = _physics_list.begin();
242  physics_iter != _physics_list.end();
243  physics_iter++ )
244  {
245  // boost::shared_ptr gets confused by operator->*
246  ((*(physics_iter->second)).*cachefunc)( c, cache );
247  }
248 
249  // Loop over each physics and compute their contributions
250  for( PhysicsListIter physics_iter = _physics_list.begin();
251  physics_iter != _physics_list.end();
252  physics_iter++ )
253  {
254  if(c.has_elem())
255  {
256  if( (physics_iter->second)->enabled_on_elem( &c.get_elem() ) )
257  {
258  ((*(physics_iter->second)).*resfunc)( compute_jacobian, c, cache );
259  }
260  }
261  else
262  {
263  ((*(physics_iter->second)).*resfunc)( compute_jacobian, c, cache );
264  }
265  }
266 
267  // TODO: Need to think about the implications of this because there might be some
268  // TODO: jacobian terms we don't want to compute for efficiency reasons
269  return compute_jacobian;
270  }
271 
272  bool MultiphysicsSystem::element_time_derivative( bool request_jacobian,
273  libMesh::DiffContext& context )
274  {
275  return this->_general_residual
276  (request_jacobian,
277  context,
280  }
281 
282  bool MultiphysicsSystem::side_time_derivative( bool request_jacobian,
283  libMesh::DiffContext& context )
284  {
285  return this->_general_residual
286  (request_jacobian,
287  context,
290  }
291 
292  bool MultiphysicsSystem::nonlocal_time_derivative( bool request_jacobian,
293  libMesh::DiffContext& context )
294  {
295  return this->_general_residual
296  (request_jacobian,
297  context,
300  }
301 
302  bool MultiphysicsSystem::element_constraint( bool request_jacobian,
303  libMesh::DiffContext& context )
304  {
305  return this->_general_residual
306  (request_jacobian,
307  context,
310  }
311 
312  bool MultiphysicsSystem::side_constraint( bool request_jacobian,
313  libMesh::DiffContext& context )
314  {
315  return this->_general_residual
316  (request_jacobian,
317  context,
320  }
321 
322  bool MultiphysicsSystem::nonlocal_constraint( bool request_jacobian,
323  libMesh::DiffContext& context )
324  {
325  return this->_general_residual
326  (request_jacobian,
327  context,
330  }
331 
332  bool MultiphysicsSystem::mass_residual( bool request_jacobian,
333  libMesh::DiffContext& context )
334  {
335  return this->_general_residual
336  (request_jacobian,
337  context,
340  }
341 
342  bool MultiphysicsSystem::nonlocal_mass_residual( bool request_jacobian,
343  libMesh::DiffContext& context )
344  {
345  return this->_general_residual
346  (request_jacobian,
347  context,
350  }
351 
352  std::tr1::shared_ptr<Physics> MultiphysicsSystem::get_physics( const std::string physics_name )
353  {
354  if( _physics_list.find( physics_name ) == _physics_list.end() )
355  {
356  std::cerr << "Error: Could not find physics " << physics_name << std::endl;
357  libmesh_error();
358  }
359 
360  return _physics_list[physics_name];
361  }
362 
363  bool MultiphysicsSystem::has_physics( const std::string physics_name ) const
364  {
365  bool has_physics = false;
366 
367  if( _physics_list.find(physics_name) != _physics_list.end() )
368  has_physics = true;
369 
370  return has_physics;
371  }
372 
373  void MultiphysicsSystem::compute_postprocessed_quantity( unsigned int quantity_index,
374  const AssemblyContext& context,
375  const libMesh::Point& point,
376  libMesh::Real& value )
377  {
378  for( PhysicsListIter physics_iter = _physics_list.begin();
379  physics_iter != _physics_list.end();
380  physics_iter++ )
381  {
382  // Only compute if physics is active on current subdomain or globally
383  if( (physics_iter->second)->enabled_on_elem( &context.get_elem() ) )
384  {
385  (physics_iter->second)->compute_postprocessed_quantity( quantity_index, context, point, value );
386  }
387  }
388  return;
389  }
390 
391 #ifdef GRINS_USE_GRVY_TIMERS
392  void MultiphysicsSystem::attach_grvy_timer( GRVY::GRVY_Timer_Class* grvy_timer )
393  {
394  _timer = grvy_timer;
395 
396  // Attach timers to each physics
397  for( PhysicsListIter physics_iter = _physics_list.begin();
398  physics_iter != _physics_list.end();
399  physics_iter++ )
400  {
401  (physics_iter->second)->attach_grvy_timer( grvy_timer );
402  }
403 
404  return;
405  }
406 #endif
407 
408 
409 } // namespace GRINS
bool has_physics(const std::string physics_name) const
Query to check if a particular physics has been enabled.
void attach_physics_list(PhysicsList physics_list)
PhysicsList gets built by GRINS::PhysicsFactory and attached here.
std::map< std::string, std::tr1::shared_ptr< GRINS::Physics > > PhysicsList
Container for GRINS::Physics object pointers.
Definition: var_typedefs.h:57
std::tr1::shared_ptr< GRINS::Physics > get_physics(const std::string physics_name)
virtual void init_data()
System initialization. Calls each physics implementation of init_variables()
void register_postprocessing_vars(const GetPot &input, PostProcessedQuantities< libMesh::Real > &postprocessing)
Each Physics will register their postprocessed quantities with this call.
virtual bool side_constraint(bool request_jacobian, libMesh::DiffContext &context)
Boundary contributions to which do not have time varying components.
std::map< std::string, std::tr1::shared_ptr< GRINS::Physics > >::const_iterator PhysicsListIter
Iterator for PhysicsList.
Definition: var_typedefs.h:60
virtual void nonlocal_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for scalar variables.
Definition: physics.C:229
void register_parameter(const std::string &param_name, libMesh::ParameterMultiPointer< libMesh::Number > &param_pointer)
Each Physics will register its copy(s) of an independent variable.
PhysicsList _physics_list
Container of pointers to GRINS::Physics classes requested at runtime.
virtual void compute_mass_residual_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:203
virtual void compute_element_time_derivative_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:167
virtual bool nonlocal_time_derivative(bool request_jacobian, libMesh::DiffContext &context)
Contributions to on SCALAR variables which have time varying components.
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for element interiors.
Definition: physics.C:236
virtual void compute_side_constraint_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:191
virtual void compute_postprocessed_quantity(unsigned int quantity_index, const AssemblyContext &context, const libMesh::Point &point, libMesh::Real &value)
GRINS namespace.
~MultiphysicsSystem()
Destructor. Clean up all physics allocations.
virtual bool nonlocal_mass_residual(bool request_jacobian, libMesh::DiffContext &context)
Contributions to on SCALAR variables.
virtual bool element_time_derivative(bool request_jacobian, libMesh::DiffContext &context)
Element interior contributions to which have time varying components.
virtual void compute_element_constraint_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:185
virtual void compute_side_time_derivative_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:173
virtual libMesh::AutoPtr< libMesh::DiffContext > build_context()
Override FEMSystem::build_context in order to use our own AssemblyContext.
virtual bool nonlocal_constraint(bool request_jacobian, libMesh::DiffContext &context)
Contributions to on SCALAR variables which do not have time varying components.
virtual void side_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for boundaries of elements on the domain boundary.
Definition: physics.C:243
virtual void nonlocal_mass_residual(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Mass matrix part(s) for scalar variables.
Definition: physics.C:264
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.
Definition: physics.C:215
bool _general_residual(bool request_jacobian, libMesh::DiffContext &context, ResFuncType resfunc, CacheFuncType cachefunc)
virtual void side_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for boundaries of elements on the domain boundary.
Definition: physics.C:222
virtual bool element_constraint(bool request_jacobian, libMesh::DiffContext &context)
virtual bool mass_residual(bool request_jacobian, libMesh::DiffContext &context)
Contributions to .
virtual void compute_nonlocal_mass_residual_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:209
virtual void compute_nonlocal_time_derivative_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:179
virtual void compute_nonlocal_constraint_cache(const AssemblyContext &context, CachedValues &cache)
Definition: physics.C:197
MultiphysicsSystem(libMesh::EquationSystems &es, const std::string &name, const unsigned int number)
Constructor. Will be called by libMesh only.
virtual bool side_time_derivative(bool request_jacobian, libMesh::DiffContext &context)
Boundary contributions to which have time varying components.
virtual void init_context(libMesh::DiffContext &context)
Context initialization. Calls each physics implementation of init_context()
virtual void nonlocal_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for scalar variables.
Definition: physics.C:250
virtual void read_input_options(const GetPot &input)
Reads input options for this class and all physics that are enabled.
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...
Definition: physics.C:257

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