www.mooseframework.org
SystemBase.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef SYSTEMBASE_H
16 #define SYSTEMBASE_H
17 
18 #include <vector>
19 
20 #include "DataIO.h"
21 #include "MooseTypes.h"
22 #include "VariableWarehouse.h"
23 
24 // libMesh
25 #include "libmesh/exodusII_io.h"
26 #include "libmesh/parallel_object.h"
27 #include "libmesh/dof_map.h"
28 #include "libmesh/equation_systems.h"
29 #include "libmesh/numeric_vector.h"
30 
31 // Forward declarations
32 class Factory;
33 class MooseApp;
34 class MooseVariable;
35 class MooseMesh;
36 class SubProblem;
37 class SystemBase;
38 
39 // libMesh forward declarations
40 namespace libMesh
41 {
42 class System;
43 }
44 
48 void extraSendList(std::vector<dof_id_type> & send_list, void * context);
49 
53 void extraSparsity(SparsityPattern::Graph & sparsity,
54  std::vector<dof_id_type> & n_nz,
55  std::vector<dof_id_type> & n_oz,
56  void * context);
57 
61 template <>
62 void dataStore(std::ostream & stream, SystemBase & system_base, void * context);
63 
67 template <>
68 void dataLoad(std::istream & stream, SystemBase & system_base, void * context);
69 
74 {
75  VarCopyInfo(const std::string & dest_name,
76  const std::string & source_name,
77  const std::string & timestep)
78  : _dest_name(dest_name), _source_name(source_name), _timestep(timestep)
79  {
80  }
81 
82  std::string _dest_name;
83  std::string _source_name;
84  std::string _timestep;
85 };
86 
91 class SystemBase : public libMesh::ParallelObject
92 {
93 public:
94  SystemBase(SubProblem & subproblem, const std::string & name, Moose::VarKindType var_kind);
95  virtual ~SystemBase() {}
96 
101  virtual unsigned int number();
102  virtual MooseMesh & mesh() { return _mesh; }
103  virtual SubProblem & subproblem() { return _subproblem; }
104 
108  virtual DofMap & dofMap();
109 
113  virtual System & system() = 0;
114  virtual const System & system() const = 0;
115 
119  virtual void init(){};
120 
124  virtual void initializeObjects(){};
125 
130  virtual void addExtraVectors();
131 
135  virtual void update();
136 
140  virtual void solve();
141 
142  virtual void copyOldSolutions();
143  virtual void restoreSolutions();
144 
149  virtual const NumericVector<Number> *& currentSolution() = 0;
150 
151  virtual NumericVector<Number> & solution() = 0;
152  virtual NumericVector<Number> & solutionOld() = 0;
153  virtual NumericVector<Number> & solutionOlder() = 0;
154  virtual NumericVector<Number> * solutionPreviousNewton() = 0;
155 
156  virtual Number & duDotDu() { return _du_dot_du; }
157  virtual NumericVector<Number> & solutionUDot() { return *_dummy_vec; }
158  virtual NumericVector<Number> & residualVector(Moose::KernelType /*type*/) { return *_dummy_vec; }
159  virtual bool hasResidualVector(Moose::KernelType) const { return false; };
160 
161  virtual void saveOldSolutions();
162  virtual void restoreOldSolutions();
163 
167  virtual bool hasVector(const std::string & name);
168 
172  virtual NumericVector<Number> & getVector(const std::string & name);
173 
177  virtual NumericVector<Number> & serializedSolution() = 0;
178 
179  virtual NumericVector<Number> & residualCopy()
180  {
181  mooseError("This system does not support getting a copy of the residual");
182  }
183  virtual NumericVector<Number> & residualGhosted()
184  {
185  mooseError("This system does not support getting a ghosted copy of the residual");
186  }
187 
191  virtual void augmentSendList(std::vector<dof_id_type> & send_list);
192 
196  virtual void augmentSparsity(SparsityPattern::Graph & sparsity,
197  std::vector<dof_id_type> & n_nz,
198  std::vector<dof_id_type> & n_oz) = 0;
199 
208  virtual void addVariable(const std::string & var_name,
209  const FEType & type,
210  Real scale_factor,
211  const std::set<SubdomainID> * const active_subdomains = NULL);
212 
219  virtual bool hasVariable(const std::string & var_name);
220  virtual bool hasScalarVariable(const std::string & var_name);
221 
222  virtual bool isScalarVariable(unsigned int var_name);
223 
231  virtual MooseVariable & getVariable(THREAD_ID tid, const std::string & var_name);
232 
240  virtual MooseVariable & getVariable(THREAD_ID tid, unsigned int var_number);
241 
249  virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string & var_name);
250 
258  virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, unsigned int var_number);
259 
266  virtual const std::set<SubdomainID> * getVariableBlocks(unsigned int var_number);
267 
272  virtual unsigned int nVariables();
273 
278  virtual void addVariableToZeroOnResidual(std::string var_name);
279 
284  virtual void addVariableToZeroOnJacobian(std::string var_name);
285 
292  virtual void zeroVariables(std::vector<std::string> & vars_to_be_zeroed);
293 
298  virtual void zeroVariablesForResidual();
299 
304  virtual void zeroVariablesForJacobian();
305 
310  virtual Order getMinQuadratureOrder();
311 
316  virtual void prepare(THREAD_ID tid);
317 
327  virtual void prepareFace(THREAD_ID tid, bool resize_data);
328 
333  virtual void prepareNeighbor(THREAD_ID tid);
334 
340  virtual void reinitElem(const Elem * elem, THREAD_ID tid);
341 
349  virtual void
350  reinitElemFace(const Elem * elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid);
351 
355  virtual void
356  reinitNeighborFace(const Elem * elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid);
357 
361  virtual void reinitNeighbor(const Elem * elem, THREAD_ID tid);
362 
368  virtual void reinitNode(const Node * node, THREAD_ID tid);
369 
376  virtual void reinitNodeFace(const Node * node, BoundaryID bnd_id, THREAD_ID tid);
377 
383  virtual void reinitNodeNeighbor(const Node * node, THREAD_ID tid);
384 
390  virtual void reinitNodes(const std::vector<dof_id_type> & nodes, THREAD_ID tid);
391 
397  virtual void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes, THREAD_ID tid);
398 
403  virtual void reinitScalars(THREAD_ID tid);
404 
414  virtual void addVariableToCopy(const std::string & dest_name,
415  const std::string & source_name,
416  const std::string & timestep);
417 
418  const std::vector<MooseVariable *> & getVariables(THREAD_ID tid)
419  {
420  return _vars[tid].variables();
421  }
422  const std::vector<MooseVariableScalar *> & getScalarVariables(THREAD_ID tid)
423  {
424  return _vars[tid].scalars();
425  }
426 
427  const std::set<SubdomainID> & getSubdomainsForVar(unsigned int var_number) const
428  {
429  return _var_map.at(var_number);
430  }
431 
435  virtual void removeVector(const std::string & name) { system().remove_vector(name); }
436 
450  virtual NumericVector<Number> &
451  addVector(const std::string & vector_name, const bool project, const ParallelType type);
452 
453  virtual const std::string & name() { return system().name(); }
454 
461  virtual void addScalarVariable(const std::string & var_name,
462  Order order,
463  Real scale_factor,
464  const std::set<SubdomainID> * const active_subdomains = NULL);
465 
466  const std::vector<VariableName> & getVariableNames() const { return _vars[0].names(); };
467 
468  virtual void computeVariables(const NumericVector<Number> & /*soln*/){};
469 
470  void copyVars(ExodusII_IO & io);
471 
475  virtual void copySolutionsBackwards();
476 
477 protected:
479 
482 
485  std::string _name;
486 
488  std::vector<VariableWarehouse> _vars;
490  std::map<unsigned int, std::set<SubdomainID>> _var_map;
491 
492  std::vector<std::string> _vars_to_be_zeroed_on_residual;
493  std::vector<std::string> _vars_to_be_zeroed_on_jacobian;
494 
496 
497  NumericVector<Number> * _dummy_vec; // to satisfy the interface
498 
499  // Used for saving old solutions so that they wont be accidentally changed
500  NumericVector<Real> * _saved_old;
501  NumericVector<Real> * _saved_older;
502 
505 
506  std::vector<VarCopyInfo> _var_to_copy;
507 };
508 
509 #define PARALLEL_TRY
510 
511 #define PARALLEL_CATCH _fe_problem.checkExceptionAndStopSolve();
512 
513 #endif /* SYSTEMBASE_H */
virtual void initializeObjects()
Called only once, just before the solve begins so objects can do some precalculations.
Definition: SystemBase.h:124
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition: SystemBase.h:422
std::string _source_name
Definition: SystemBase.h:83
virtual NumericVector< Number > & residualCopy()
Definition: SystemBase.h:179
Class for stuff related to variables.
Definition: MooseVariable.h:43
Generic factory class for build all sorts of objects.
Definition: Factory.h:152
std::vector< std::string > _vars_to_be_zeroed_on_residual
Definition: SystemBase.h:492
virtual void init()
Initialize the system.
Definition: SystemBase.h:119
virtual const std::string & name()
Definition: SystemBase.h:453
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void dataLoad(std::istream &stream, SystemBase &system_base, void *context)
IO Methods for restart, backup and restore.
Definition: SystemBase.C:68
Factory & _factory
Definition: SystemBase.h:481
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
virtual void removeVector(const std::string &name)
Remove a vector from the system with the given name.
Definition: SystemBase.h:435
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Base class for a system (of equations)
Definition: SystemBase.h:91
NumericVector< Real > * _saved_older
Definition: SystemBase.h:501
Real _du_dot_du
Definition: SystemBase.h:495
std::vector< VarCopyInfo > _var_to_copy
Definition: SystemBase.h:506
virtual Number & duDotDu()
Definition: SystemBase.h:156
void extraSparsity(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *context)
Free function used for a libMesh callback.
Definition: SystemBase.C:41
nl system()
virtual NumericVector< Number > & solutionUDot()
Definition: SystemBase.h:157
void extraSendList(std::vector< dof_id_type > &send_list, void *context)
///< Type of coordinate system
Definition: SystemBase.C:33
std::vector< std::string > _vars_to_be_zeroed_on_jacobian
Definition: SystemBase.h:493
Information about variables that will be copied.
Definition: SystemBase.h:73
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:156
virtual ~SystemBase()
Definition: SystemBase.h:95
const std::vector< numeric_index_type > & n_nz
std::string _dest_name
Definition: SystemBase.h:82
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
SubProblem & _subproblem
Definition: SystemBase.h:478
Moose::VarKindType _var_kind
default kind of variables in this system
Definition: SystemBase.h:504
virtual SubProblem & subproblem()
Definition: SystemBase.h:103
const std::vector< MooseVariable * > & getVariables(THREAD_ID tid)
Definition: SystemBase.h:418
std::string _timestep
Definition: SystemBase.h:84
VarCopyInfo(const std::string &dest_name, const std::string &source_name, const std::string &timestep)
Definition: SystemBase.h:75
KernelType
Definition: MooseTypes.h:162
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:490
std::string _name
The name of this system.
Definition: SystemBase.h:485
MooseApp & _app
Definition: SystemBase.h:480
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
MatType type
virtual NumericVector< Number > & residualVector(Moose::KernelType)
Definition: SystemBase.h:158
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
MooseMesh & _mesh
Definition: SystemBase.h:483
virtual MooseMesh & mesh()
Definition: SystemBase.h:102
NumericVector< Real > * _saved_old
Definition: SystemBase.h:500
Class for scalar variables (they are different).
virtual void computeVariables(const NumericVector< Number > &)
Definition: SystemBase.h:468
virtual bool hasResidualVector(Moose::KernelType) const
Definition: SystemBase.h:159
void dataStore(std::ostream &stream, SystemBase &system_base, void *context)
IO Methods for restart, backup and restore.
Definition: SystemBase.C:52
virtual NumericVector< Number > & residualGhosted()
Definition: SystemBase.h:183
const std::set< SubdomainID > & getSubdomainsForVar(unsigned int var_number) const
Definition: SystemBase.h:427
const std::vector< VariableName > & getVariableNames() const
Definition: SystemBase.h:466
NumericVector< Number > * _dummy_vec
Definition: SystemBase.h:497
const std::vector< numeric_index_type > & n_oz
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
unsigned int THREAD_ID
Definition: MooseTypes.h:79