Flow123d  jenkins-Flow123d-windows-release-multijob-285
equation.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief Abstract base class for equation clasess.
27  *
28  * @author Jan Brezina
29  */
30 
31 #ifndef EQUATION_HH_
32 #define EQUATION_HH_
33 
34 
35 #include <limits>
36 #include "tools/time_governor.hh"
37 #include "tools/time_marks.hh"
38 #include "input/accessors.hh"
39 
40 #include <petscvec.h>
41 
42 class Mesh;
43 class Region;
44 class FieldSet;
46 
47 
48 namespace Input {
49  class Record;
50 }
51 
52 /**
53  * Class EquationBase is abstract base class for a general time dependent model. This class should provide general interface
54  * that can be used for general coupling of various particular models. By a model we mean a discrete solver of
55  * an partial or ordinary differential equation. Result of the model at one discrete time level should be a discrete field class (not yet implemented).
56  * Until we have field classes we only provide method get_solution_vector(), which returns pointer to sequential C array with linear combination of
57  * base functions that represents the solution.
58  *
59  * Computation of one time step (method compute_one_step() ) is split into update_solution() and choose_next_time().
60  *
61  * This class does not implement any constructor. In particular it does not initialize mesh and time. This has to be done in the constructor
62  * of particular child class.
63  *
64  * Any constructor of child class should set solved = true. We assume, that after initialization an equation object stay solve in init time. For the first time step
65  * one calls method chose_next_time() which setup time frame of the first time step.
66  *
67  * TODO: clarify initialization of data members
68  *
69  */
70 class EquationBase {
71 public:
72 
73  /**
74  * Default constructor. Sets all virtual methods empty. Necessary to make tests fixtures for equations.
75  * TODO:
76  * Replace setting all in constructor with appropriate getters and setters.
77  * Make appropriate checks if key ingredients are initialized.
78  */
79  EquationBase();
80 
81  /**
82  * Common initialization constructor.
83  */
84  EquationBase(Mesh &mesh, const Input::Record in_rec);
85 
86  /**
87  * Require virtual destructor also for child classes.
88  */
89  virtual ~EquationBase() {};
90 
91  /**
92  * Initialization of the solution in the zero time.
93  * There is lot of things that can not be done in the constructor
94  * since we have not fully initialized fields yet. Fields coming from coupling
95  * has to be set after the constructor and before zero_time_step.
96  */
97  virtual void zero_time_step() {
98  if (equation_empty_) DBGMSG("Calling 'zero_time_step' of empty equation '%s'.\n",typeid(*this).name());
99  else DBGMSG("Method 'zero_time_step' of '%s' is not implemented.\n",typeid(*this).name());
100  }
101 
102  /**
103  * Calculation of the next time step and its output.
104  */
105  virtual void update_solution() {
106  if (equation_empty_) DBGMSG("Calling 'update_solution' of empty equation '%s'.\n",typeid(*this).name());
107  else DBGMSG("Method 'update_solution' of '%s' is not implemented.\n",typeid(*this).name());
108  }
109 
110  ///Initialize fields.
111  /**
112  * All members that are needed to set fields must be set at this moment (e.g. number of components).
113  */
114  virtual void initialize() {
115  if (equation_empty_) DBGMSG("Calling 'initialize' of empty equation '%s'.\n",typeid(*this).name());
116  else DBGMSG("Method 'initialize' of '%s' is not implemented.\n",typeid(*this).name());
117  }
118 
119  /**
120  * Fix the next discrete time for computation.
121  * Can be rewritten in child class to set possible constrains
122  * according to possible equation coefficients or other data which can be result of another model.
123  *
124  */
125  virtual void choose_next_time()
127 
128  /**
129  * Set external upper time step constrain for time governor of the equation.
130  */
131  virtual void set_time_upper_constraint(double dt)
133 
134  /**
135  * Set external lower time step constrain for time governor of the equation.
136  */
137  virtual void set_time_lower_constraint(double dt)
139 
140  /**
141  * Basic getter method returns constant TimeGovernor reference which provides full read access to the time information.
142  */
143  inline TimeGovernor const &time()
144  {
145  ASSERT( time_,"Time governor was not created.\n");
146  return *time_;
147  }
148 
149  /**
150  * Set time governor.
151  *
152  * Used to set pointer to common time governor (e.g. in Transport Operator Splitting, Reaction).
153  */
154  virtual void set_time_governor(TimeGovernor &time);
155 
156  /**
157  * Most actual planned time for solution.
158  */
159  inline double planned_time()
160  { return time_->estimate_time(); }
161 
162  /**
163  * Time of actual solution returned by get_solution_vector().
164  */
165  inline double solved_time()
166  { return time_->t(); }
167 
168  /**
169  * This getter method provides the computational mesh currently used by the model.
170  */
171  inline Mesh &mesh()
172  {
173  return *mesh_;
174  }
175 
176  /**
177  * Getter for equation time mark type.
178  */
180  {
181  return time().equation_mark_type();
182  }
183 
184  /**
185  * Return reference to the equation data object containing all fields
186  * that the equation needs or produce.
187  */
189  {
190  ASSERT(eq_data_, "The equation %s did not set eq_data_ pointer.\n", input_record_.address_string().c_str());
191  return *eq_data_;
192  }
193 
194  /**
195  * Child class have to implement getter for sequential solution vector.
196  * DEPRECATED
197  */
198  virtual void get_solution_vector(double * &vector, unsigned int &size)
199  { ASSERT(0, "If using, needs to be implemented in ancestors!"); };
200 
201  /**
202  * Child class have to implement getter for parallel solution vector.
203  * DEPRECATED
204  */
206  { ASSERT(0, "If using, needs to be implemented in ancestors!"); };
207 
208  /**
209  * @brief Write computed fields.
210  */
211  virtual void output_data() {
212  if (equation_empty_) DBGMSG("Calling 'output_data' of empty equation '%s'.\n",typeid(*this).name());
213  else DBGMSG("Method 'output_data' of '%s' is not implemented.\n",typeid(*this).name());
214  }
215 
216 protected:
217  bool equation_empty_; ///< flag is true if only default constructor was called
221 
222  /**
223  * Pointer to the equation data object. Every particular equation is responsible
224  * to set the pointer in its constructor. This is used by the general method
225  * EqData::data(). This approach is simpler than making EqData::data() a virtual method.
226  */
228 };
229 
230 
231 #endif /* EQUATION_HH_ */
FieldSet & data()
Definition: equation.hh:188
virtual void zero_time_step()
Definition: equation.hh:97
FieldSet * eq_data_
Definition: equation.hh:227
#define DBGMSG(...)
Definition: global_defs.h:196
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:51
unsigned long int Type
Definition: time_marks.hh:64
double estimate_time() const
std::vector< Region > RegionSet
Definition: equation.hh:44
virtual void initialize()
Initialize fields.
Definition: equation.hh:114
double fix_dt_until_mark()
Fixing time step until fixed time mark.
Definition: mesh.h:109
double t() const
Basic time management functionality for unsteady (and steady) solvers (class Equation).
virtual void choose_next_time()
Definition: equation.hh:125
virtual void output_data()
Write computed fields.
Definition: equation.hh:211
Basic time management class.
#define ASSERT(...)
Definition: global_defs.h:121
Mesh & mesh()
Definition: equation.hh:171
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
TimeMark::Type equation_mark_type() const
int set_lower_constraint(double lower)
Sets lower constraint for the next time step estimating.
Mesh * mesh_
Definition: equation.hh:218
virtual void get_parallel_solution_vector(Vec &vector)
Definition: equation.hh:205
virtual void get_solution_vector(double *&vector, unsigned int &size)
Definition: equation.hh:198
virtual void set_time_governor(TimeGovernor &time)
Definition: equation.cc:80
bool equation_empty_
flag is true if only default constructor was called
Definition: equation.hh:217
virtual void update_solution()
Definition: equation.hh:105
Input::Record input_record_
Definition: equation.hh:220
int set_upper_constraint(double upper)
Sets upper constraint for the next time step estimating.
TimeGovernor const & time()
Definition: equation.hh:143
double solved_time()
Definition: equation.hh:165
virtual void set_time_lower_constraint(double dt)
Definition: equation.hh:137
TimeMark::Type mark_type()
Definition: equation.hh:179
virtual ~EquationBase()
Definition: equation.hh:89
virtual void set_time_upper_constraint(double dt)
Definition: equation.hh:131
TimeGovernor * time_
Definition: equation.hh:219
string address_string() const
Definition: accessors.cc:193
double planned_time()
Definition: equation.hh:159