Flow123d
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 "time_governor.hh"
37 #include "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. 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  // solve equation here ...
99  }
100 
101  /**
102  * Calculation of the next time step and its output.
103  */
104  virtual void update_solution() {
105  // solve equation here ...
106  time_->next_time();
107  }
108 
109  /**
110  * Computation of one time step is split into update_solution() and choose_next_time() in order to allow dependency of the next time step
111  * on other coupled models.
112  */
113 // virtual void compute_one_step() {
114 // update_solution();
115 // choose_next_time();
116 // }
117 
118  /**
119  * Fix the next discrete time for computation.
120  * Can be rewritten in child class to set possible constrains
121  * according to possible equation coefficients or other data which can be result of another model.
122  *
123  */
124  virtual void choose_next_time()
126 
127  /**
128  * Set external upper time step constrain for time governor of the equation.
129  */
130  virtual void set_time_upper_constraint(double dt)
132 
133  /**
134  * Set external lower time step constrain for time governor of the equation.
135  */
136  virtual void set_time_lower_constraint(double dt)
138 
139  /**
140  * Basic getter method returns constant TimeGovernor reference which provides full read access to the time information.
141  */
142  inline TimeGovernor const &time()
143  {
144  ASSERT( time_,"Time governor was not created.\n");
145  return *time_;
146  }
147 
148  /**
149  * Set time governor.
150  *
151  * Used to set pointer to common time governor (e.g. in Transport Operator Splitting, Reaction).
152  */
153  virtual void set_time_governor(TimeGovernor &time);
154 
155  /**
156  * Most actual planned time for solution.
157  */
158  inline double planned_time()
159  { return time_->estimate_time(); }
160 
161  /**
162  * Time of actual solution returned by get_solution_vector().
163  */
164  inline double solved_time()
165  { return time_->t(); }
166 
167  /**
168  * This getter method provides the computational mesh currently used by the model.
169  */
170  inline Mesh &mesh()
171  {
172  return *mesh_;
173  }
174 
175  /**
176  * Getter for equation time mark type.
177  */
179  {
180  return time().equation_mark_type();
181  }
182 
183  /**
184  * Return reference to the equation data object containing all fields
185  * that the equation needs or produce.
186  */
188  {
189  ASSERT(eq_data_, "The equation %s did not set eq_data_ pointer.\n", input_record_.address_string().c_str());
190  return *eq_data_;
191  }
192 
193  /**
194  * Child class have to implement getter for sequential solution vector.
195  * OBSOLETE
196  */
197  virtual void get_solution_vector(double * &vector, unsigned int &size) =0;
198 
199  /**
200  * Child class have to implement getter for parallel solution vector.
201  * OBSOLETE
202  */
203  virtual void get_parallel_solution_vector(Vec &vector) =0;
204 
205  /**
206  * @brief Write computed fields.
207  */
208  virtual void output_data() =0;
209 
210 protected:
213  //TimeMark::Type equation_mark_type_;
215 
216  /**
217  * Pointer to the equation data object. Every particular equation is responsible
218  * to set the pointer in its constructor. This is used by the general method
219  * EqData::data(). This approach is simpler than making EqData::data() a virtual method.
220  */
222 };
223 
224 
225 
226 
227 
228 
229 /**
230  * Demonstration of empty equation class, which can be used if user turns off some equation in the model.
231  */
233 
234 public:
236 
237  void get_solution_vector(double * &vector, unsigned int &size) override
238  {
239  vector = NULL;
240  size = 0;
241  }
242 
244  {}
245 
246 
247  virtual ~EquationNothing() {};
248 
249 };
250 
251 
252 #endif /* EQUATION_HH_ */