Flow123d  jenkins-Flow123d-windows32-release-multijob-51
mass_balance.hh
Go to the documentation of this file.
1 #ifndef MASS_BALANCE_HH_
2 #define MASS_BALANCE_HH_
3 
4 
5 
6 /**
7  * Interface class for equation which implements methods required for mass balance.
8  */
9 
11 public:
12 
13  // TODO: Think if we really need TimeIntegrationScheme.
14  // Currently the cummulative quantities are calculated by the method calculate()
15  // in the same way for both explicit and implicit methods.
21  };
22 
24 
25  /// Returns number of trnasported substances.
26  virtual unsigned int n_substances() = 0;
27 
28  /// Returns reference to the vector of substnace names.
29  virtual vector<string> &substance_names() = 0;
30 
31  /// Returns the time integration scheme of the equation.
32  virtual TimeIntegrationScheme time_scheme() = 0;
33 
34 
35 protected:
36 
37  /**
38  * Calculates the total flux through boundaries of all regions, and additionally positive and negative fluxes.
39  * The actual calculation depends on the numerical scheme, so each descendant of TransportBase implements this method.
40  * @param bcd_balance bcd_balance[i][j] is the calculated total flux
41  * of @p ith substance through boundary of @p jth region.
42  * @param bcd_plus_balance bcd_plus_balance[i][j] is the total positive flux
43  * of @p ith substance through boundary of @p jth region.
44  * @param bcd_minus_balance bcd_minus_balance[i][j] is the total negative flux
45  * of @p ith substance through boundary of @p jth region.
46  */
47  virtual void calc_fluxes(vector<vector<double> > &bcd_balance, vector<vector<double> > &bcd_plus_balance, vector<vector<double> > &bcd_minus_balance) = 0;
48 
49  /**
50  * Calculates the substance mass and sources on all regions.
51  * The actual calculation depends on the numerical scheme, so each descendant of TransportBase implements this method.
52  * @param mass mass[i][j] is the calculated mass of @p ith
53  * substance on @p jth region.
54  * @param src_balance src_balance[i][j] is the source mass
55  * of @p ith substance on @p jth region.
56  */
57  virtual void calc_elem_sources(vector<vector<double> > &mass, vector<vector<double> > &src_balance) = 0;
58 
59  /// Returns the region database.
60  virtual const RegionDB *region_db() = 0;
61 
62  friend class MassBalance;
63 
64 };
65 
66 
67 /**
68  * @brief Class for calculation and writing the balance of mass, volume sources and fluxes.
69  *
70  * At each time instant we calculate:
71  * - Flux rate through all boundary regions
72  * - Volume sources rate on all bulk regions
73  * - Mass on all bulk regions
74  *
75  * In addition, the quantities are summed over all regions and integrated in time,
76  * so that the cumulative (integrated) quantities should satisfy:
77  *
78  * INITIAL_MASS + INTEGRATED_SOURCES - INTEGRATED_FLUXES = CURRENT_MASS.
79  *
80  * All quantities are written to the file "mass_balance.txt" in the output directory.
81  */
82 class MassBalance {
83 public:
84 
86 
87  ~MassBalance();
88 
89  /**
90  * @brief Write computed fields to file.
91  */
92  void output(double time);
93 
94  /**
95  * Calculate mass balance: flux through boundary, mass and volume sources
96  */
97  void calculate(double time);
98 
99 
101 
102 
103 protected:
104 
105  /// Pointer to the class which implements calculation of mass, sources and fluxes.
107 
108  /// Handle for output file for output of balance and total fluxes over individual regions and region sets.
110 
111  // Vectors storing mass and balances of fluxes and volumes.
112  vector<vector<double> > bcd_balance;
113  vector<vector<double> > bcd_plus_balance;
114  vector<vector<double> > bcd_minus_balance;
115  vector<vector<double> > mass;
116  vector<vector<double> > src_balance;
117 
118  vector<double> bcd_total_balance;
119  vector<double> bcd_total_inflow;
120  vector<double> bcd_total_outflow;
121  vector<double> mass_total;
122  vector<double> src_total_balance;
123 
124  vector<double> initial_mass;
125  vector<double> integrated_sources;
126  vector<double> integrated_fluxes;
127 
128  /// initial time
129  double initial_time;
130 
131  /// time of last calculated balance
132  double last_time;
133 
134  /// true before calculating the mass at initial time, otherwise false
135  bool initial;
136 
137  /// if true then cumulative balance is computed
139 
140 };
141 
142 
143 
144 
145 
146 
147 
148 
149 #endif // MASS_BALANCE_HH_
void calculate(double time)
Definition: mass_balance.cc:89
vector< double > src_total_balance
virtual ~EquationForMassBalance()
Definition: mass_balance.hh:23
static Input::Type::Record input_type
virtual void calc_elem_sources(vector< vector< double > > &mass, vector< vector< double > > &src_balance)=0
vector< double > bcd_total_inflow
double initial_time
initial time
double last_time
time of last calculated balance
vector< vector< double > > bcd_plus_balance
FILE * balance_output_file
Handle for output file for output of balance and total fluxes over individual regions and region sets...
EquationForMassBalance * equation_
Pointer to the class which implements calculation of mass, sources and fluxes.
bool cumulative
if true then cumulative balance is computed
MassBalance(EquationForMassBalance *eq, const Input::Record &in_rec)
Definition: mass_balance.cc:56
vector< double > initial_mass
virtual unsigned int n_substances()=0
Returns number of trnasported substances.
vector< double > integrated_sources
Class for calculation and writing the balance of mass, volume sources and fluxes. ...
Definition: mass_balance.hh:82
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
virtual vector< string > & substance_names()=0
Returns reference to the vector of substnace names.
vector< vector< double > > bcd_balance
void output(double time)
Write computed fields to file.
virtual TimeIntegrationScheme time_scheme()=0
Returns the time integration scheme of the equation.
virtual void calc_fluxes(vector< vector< double > > &bcd_balance, vector< vector< double > > &bcd_plus_balance, vector< vector< double > > &bcd_minus_balance)=0
vector< vector< double > > bcd_minus_balance
vector< vector< double > > src_balance
vector< double > bcd_total_balance
bool initial
true before calculating the mass at initial time, otherwise false
vector< double > bcd_total_outflow
vector< double > mass_total
Record type proxy class.
Definition: type_record.hh:161
virtual const RegionDB * region_db()=0
Returns the region database.
vector< vector< double > > mass
vector< double > integrated_fluxes