Flow123d  master-f44eb46
balance.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file balance.hh
15  * @brief
16  */
17 
18 #ifndef BALANCE_HH_
19 #define BALANCE_HH_
20 
21 
22 #include <fstream> // for ofstream
23 #include <string> // for string
24 #include <vector> // for vector
25 #include <unordered_map> // for unordered_map
26 #include "mesh/accessors.hh" // for SideIter
27 #include "tools/unit_si.hh" // for UnitSI
28 #include "input/accessors.hh" // for Record
29 #include "petscmat.h" // for Mat, _p_Mat
30 #include "petscvec.h" // for Vec, _p_Vec
31 #include "system/file_path.hh" // for FilePath
32 #include "tools/time_marks.hh" // for TimeMark, TimeMark::Type
33 #include "system/index_types.hh" // for LongIdx
34 
35 class Mesh;
36 class TimeGovernor;
37 class DOFHandlerMultiDim;
38 class DHCellSide;
39 class DHCellAccessor;
40 namespace Input {
41  namespace Type {
42  class Record;
43  class Selection;
44  }
45 }
46 
47 
48 
49 
50 
51 /**
52  * Design of balance class - serves as storage and writer.
53  * Equations themselves call methods of Balance that add/modify mass, source and flux
54  * of various quantities and generate output.
55  *
56  * One instance of Balance can handle several conservative quantities of the same type
57  * (e.g. mass of several substances or their phases).
58  *
59  * The mass, flux and source are calculated as follows:
60  *
61  * m(q,r) = ( M'(q) * solution + mv(q) )[r]
62  * f(q,r) = -( R' * ( F(q) * solution + fv(q) ) )[r]
63  * s(q,r) = ( S'(q) * solution + sv(q) )[r]
64  *
65  * where M' stands for matrix transpose,
66  *
67  * m(q,r)...mass of q-th substance in region r
68  * f(q,r)...incoming flux of q-th substance in region r
69  * s(q,r)...source of q-th substance in region r
70  *
71  * and
72  *
73  * M(q)...region_mass_matrix_ n_dofs x n_bulk_regions
74  * F(q)...be_flux_matrix_ n_boundary_edges x n_dofs
75  * S(q)...region_source_matrix_ n_dofs x n_bulk_regions
76  * SV(q)..region_source_rhs_ n_dofs x n_bulk_regions
77  * mv(q)..region_mass_vec_ n_bulk_regions
78  * fv(q)..be_flux_vec_ n_boundary_edges
79  * sv(q)..region_source_vec_ n_bulk_regions
80  * R......region_be_matrix_ n_boundary_edges x n_boundary_regions
81  *
82  * Remark: Matrix F and the vector fv are such that F*solution+fv produces _outcoming_ fluxes per boundary edge.
83  * However we write to output _incoming_ flux due to users' convention and consistently with input interface.
84  *
85  * Note that it holds:
86  *
87  * sv(q) = column sum of SV(q)
88  *
89  * Except for that, we also provide information on positive/negative flux and source:
90  *
91  * fp(q,r) = ( R' * EFP(q) )[r], EFP(q)[e] = max{ 0, ( F(q) * solution + fv(q) )[e] }
92  * fn(q,r) = ( R' * EFN(q) )[r], EFN(q)[e] = min{ 0, ( F(q) * solution + fv(q) )[e] }
93  * sp(q,r) = sum_{i in DOFS } max{ 0, ( S(q)[i,r] * solution[i] + SV(q)[i,r] ) }
94  * sn(q,r) = sum_{i in DOFS } min{ 0, ( S(q)[i,r] * solution[i] + SV(q)[i,r] ) }
95  *
96  * where
97  *
98  * fp(q,r)...positive (inward) flux of q-th quantity in region r
99  * fn(q,r)...negative (outward) flux of q-th quantity in region r
100  * sp(q,r)...positive source (spring) of q-th quantity in region r
101  * sn(q,r)...negative source (sink) of q-th quantity in region r
102  *
103  * Remark: The matrix R is needed only for calculation of signed fluxes.
104  * The reason is that to determine sign, we decompose flux to sum of local contributions
105  * per each boundary element and check its sign. It is not possible to decompose flux
106  * using shape functions, since their normal derivatives may have any sign.
107  *
108  *
109  *
110  * Output values (if not relevant, zero is supplied):
111  *
112  * #time bulk_region quantity 0 0 0 mass source source_in source_out 0 0 0
113  * #time boundary_region quantity flux flux_in flux_out 0 0 0 0 0 0 0
114  * #time ALL quantity flux flux_in flux_out mass source source_in source_out integrated_flux integrated_source error
115  *
116  * error = current_mass - (initial_mass + integrated_source - integrated_flux)
117  *
118  */
119 class Balance {
120 public:
121 
122  /**
123  * Class for storing internal data about conservative quantities handled by the Balance object.
124  * In the future we may store additional data or support definition of derived quantities
125  * (e.g. linear combinations of quantities).
126  */
127  class Quantity {
128  public:
129 
130  Quantity(const unsigned int index, const string &name)
131  : name_(name),
132  index_(index)
133  {}
134 
135  /// Name of quantity (for output).
136  string name_;
137 
138  /// Internal index within list of quantities.
139  const unsigned int index_;
140 
141  };
142 
143  /**
144  * Possible formats of output file.
145  */
147  {
148  legacy,//!< legacy
149  txt, //!< csv
150  gnuplot//!< gnuplot
151  };
152 
153  /// Main balance input record type.
154  static const Input::Type::Record & get_input_type();
155 
156  /// Input selection for file format.
158 
159  /// Set global variable to output balance files into YAML format (in addition to the table format).
160  static void set_yaml_output();
161 
162  /**
163  * Constructor.
164  * @param file_prefix Prefix of output file name.
165  * @param mesh Mesh.
166  */
167  Balance(const std::string &file_prefix, const Mesh *mesh);
168 
169  /**
170  * Destructor.
171  */
172  ~Balance();
173 
174 
175  /**
176  * Initialize the balance object according to the input.
177  * The balance output time marks are set according to the already existing output time marks of the same equation.
178  * So, this method must be called after Output::
179  *
180  * @param in_rec Input record of balance.
181  * @param tg TimeGovernor of the equation. We need just equation mark type.
182  *
183  */
184  void init_from_input(const Input::Record &in_rec, TimeGovernor &tg);
185 
186  /// Setter for units of conserved quantities.
187  void units(const UnitSI &unit);
188 
189  /// Getter for cumulative_.
190  inline bool cumulative() const { return cumulative_; }
191 
192 
193  /**
194  * Define a single conservative quantity.
195  * @param name Name of the quantity.
196  * @return Quantity's internal index.
197  */
198  unsigned int add_quantity(const string &name);
199 
200  /**
201  * Define a set of conservative quantities.
202  * @param names List of quantities' names.
203  * @return List of quantities' indices.
204  */
206 
207  /**
208  * Allocates matrices and vectors for balance based on DofHandler.
209  * @param dh DofHandler of the corresponding linear system (and solution).
210  * @param max_dofs_per_boundary Number of dofs contributing to one boundary edge.
211  */
212  void allocate(const std::shared_ptr<DOFHandlerMultiDim>& dh,
213  unsigned int max_dofs_per_boundary);
214 
215  /**
216  * Allocates matrices and vectors for balance.
217  * @param n_loc_dofs Number of solution dofs on the local process.
218  * @param max_dofs_per_boundary Number of dofs contributing to one boundary edge.
219  */
220  void allocate(unsigned int n_loc_dofs,
221  unsigned int max_dofs_per_boundary);
222 
223  /// Returns true if the current time step is marked for the balance output.
224  bool is_current();
225 
226  /**
227  * This method must be called before assembling the matrix for computing mass.
228  * It actually erases the matrix.
229  */
230  void start_mass_assembly(unsigned int quantity_idx);
231 
232  /// Variant of the start_mass_assembly() method for a set of quantities.
234  {
235  for (auto idx : q_idx_vec)
236  start_mass_assembly(idx);
237  }
238 
239  /**
240  * This method must be called before assembling the matrix and vector for fluxes.
241  * It actually erases the matrix and vector.
242  */
243  void start_flux_assembly(unsigned int quantity_idx);
244 
245  /// Variant of the start_flux_assembly() method for a set of quantities.
247  {
248  for (auto idx : q_idx_vec)
249  start_flux_assembly(idx);
250  }
251 
252  /**
253  * This method must be called before assembling the matrix and vectors for sources.
254  * It actually erases the matrix and vectors.
255  */
256  void start_source_assembly(unsigned int quantity_idx);
257 
258  /// Variant of the start_source_assembly() method for a set of quantities.
260  {
261  for (auto idx : q_idx_vec)
263  }
264 
265 
266  /**
267  * Adds elements into matrix for computing mass.
268  * The mass matrix M is in format [n_dofs x n_bulk_regions] for each quantity.
269  * The mass vector mv is in format [n_bulk_regions] for each quantity.
270  * The region mass is later computed using transpose multiplication (M'*u + mv)[r].
271  * See class @p Balance description above for details.
272  * @param quantity_idx Index of quantity.
273  * @param dh_cell Dofhandler cell accessor.
274  * @param loc_dof_indices Local dof indices (to the solution vector) to be added.
275  * @param mat_values Values to be added into matrix M.
276  * @param vec_value Value to be added into vector mv.
277  */
278  void add_mass_values(unsigned int quantity_idx,
279  const DHCellAccessor &dh_cell,
280  const LocDofVec &loc_dof_indices,
281  const std::vector<double> &mat_values,
282  double vec_value);
283 
284  /**
285  * Adds elements into matrix for computing (outgoing) flux.
286  * The flux matrix F is in format [n_boundary_edges x n_dofs] for each quantity.
287  * The flux vector fv is in format [n_boundary_edges] for each quantity.
288  * See class @p Balance description above for details.
289  * @param quantity_idx Index of quantity.
290  * @param side DHCellSide iterator.
291  * @param loc_dof_indices Local dof indices (to the solution vector) to be added.
292  * @param mat_values Values to be added into matrix F.
293  * @param vec_value Value to be added into vector fv.
294  */
295  void add_flux_values(unsigned int quantity_idx,
296  const DHCellSide &side,
297  const LocDofVec &loc_dof_indices,
298  const std::vector<double> &mat_values,
299  double vec_value);
300 
301  /**
302  * Adds elements into matrix and vector for computing source.
303  * The source region matrix S is in format [n_dofs x n_bulk_regions] for each quantity (multiplies solution).
304  * The source region rhs matrix SV is in format [n_dofs x n_bulk_regions] for each quantity (addition).
305  * The region source is then computed as (S'(q) * solution + sv(q))[r], while sv(q) being column sum of SV(q).
306  * The source term for a specific region and quantity is then
307  * @param quantity_idx Index of quantity.
308  * @param region_idx Index of bulk region.
309  * @param loc_dof_indices Local dof indices (to the solution vector) to be added.
310  * @param mult_mat_values Values to be added into matrix S.
311  * @param add_mat_values Values to be added into matrix SV.
312  */
313  void add_source_values(unsigned int quantity_idx,
314  unsigned int region_idx,
315  const LocDofVec &loc_dof_indices,
316  const std::vector<double> &mult_mat_values,
317  const std::vector<double> &add_mat_values);
318 
319 
320  /// This method must be called after assembling the matrix for computing mass.
321  void finish_mass_assembly(unsigned int quantity_idx);
322 
323  /// Variant of the finish_mass_assembly() method for a set of quantities.
325  {
326  for (auto idx : q_idx_vec)
328  }
329 
330  /// This method must be called after assembling the matrix and vector for computing flux.
331  void finish_flux_assembly(unsigned int quantity_idx);
332 
333  /// Variant of the finish_flux_assembly() method for a set of quantities.
335  {
336  for (auto idx : q_idx_vec)
338  }
339 
340  /// This method must be called after assembling the matrix and vectors for computing source.
341  void finish_source_assembly(unsigned int quantity_idx);
342 
343  /// Variant of the finish_source_assembly() method for a set of quantities.
345  {
346  for (auto idx : q_idx_vec)
348  }
349 
350  /**
351  * Updates cumulative quantities for balance.
352  * This method can be called in substeps even if no output is generated.
353  * It calculates the sum of source and sum of (incoming) flux over time interval.
354  * @param quantity_idx Index of quantity.
355  * @param solution Solution vector.
356  */
357  void calculate_cumulative(unsigned int quantity_idx,
358  const Vec &solution);
359 
360  /**
361  * Calculates actual mass and save it to given vector.
362  * @param quantity_idx Index of quantity.
363  * @param solution Solution vector.
364  * @param output_array Vector of output masses per region.
365  */
366  void calculate_mass(unsigned int quantity_idx,
367  const Vec &solution,
368  vector<double> &output_array);
369 
370  /**
371  * Calculates actual mass, incoming flux and source.
372  * @param quantity_idx Index of quantity.
373  * @param solution Solution vector.
374  */
375  void calculate_instant(unsigned int quantity_idx,
376  const Vec &solution);
377 
378  /**
379  * Adds provided values to the cumulative sources.
380  * @param quantity_idx Index of quantity.
381  * @param sources Sources per region.
382  * @param dt Actual time step.
383  */
384  void add_cumulative_source(unsigned int quantity_idx, double source);
385 
386  /// Perform output to file for given time instant.
387  void output();
388 
389 private:
390  /// Size of column in output (used if delimiter is space)
391  static const unsigned int output_column_width = 20;
392  /**
393  * Postponed allocation and initialization to allow calling setters in arbitrary order.
394  * In particular we need to perform adding of output times after the output time marks are set.
395  * On the other hand we need to read the input before we make the allocation.
396  *
397  * The initialization is done during the first call of any start_*_assembly method.
398  */
399  void lazy_initialize();
400 
401  /// Perform output in old format (for compatibility)
402  void output_legacy(double time);
403 
404  /// Perform output in csv format
405  void output_csv(double time, char delimiter, const std::string& comment_string, unsigned int repeat = 0);
406 
407  /// Perform output in yaml format
408  void output_yaml(double time);
409 
410  /// Return part of output represented by zero values. Count of zero values is given by cnt parameter.
411  std::string csv_zero_vals(unsigned int cnt, char delimiter);
412 
413  /// Print output header
414  void format_csv_output_header(char delimiter, const std::string& comment_string);
415 
416  /// Format string value of csv output. Wrap string into quotes and if delimiter is space, align text to column.
417  std::string format_csv_val(std::string val, char delimiter, bool initial = false);
418 
419  /// Format double value of csv output. If delimiter is space, align text to column.
420  std::string format_csv_val(double val, char delimiter, bool initial = false);
421 
422  /** Computes unique id of local boundary edge from local element index and element side index
423  *
424  * @param side is a side of locally owned element
425  */
427  { return 4*side->elem_idx() + side->side_idx();} // 4 is maximum of sides per element
428 
429  //**********************************************
430 
431  static bool do_yaml_output_;
432 
433  /// Allocation parameters. Set by the allocate method used in the lazy_initialize.
434  unsigned int n_loc_dofs_par_;
435  unsigned int n_loc_dofs_seq_;
437 
438 
439  /// Save prefix passed in in constructor.
440  std::string file_prefix_;
441 
442  /// File path for output_ stream.
444 
445  /// Handle for file for output in given OutputFormat of balance and total fluxes over individual regions and region sets.
446  std::ofstream output_;
447 
448  // The same as the previous case, but for output in YAML format.
449  std::ofstream output_yaml_;
450 
451  /// Format of output file.
453 
454  /// Names of conserved quantities.
456 
457  const Mesh *mesh_;
458 
459  /// Units of conserved quantities.
461 
462 
463  /// Matrices for calculation of mass (n_dofs x n_bulk_regions).
465 
466  /// Matrices for calculation of flux (n_boundary_edges x n_dofs).
468 
469  /// Matrices for calculation of source (n_dofs x n_bulk_regions).
471 
472  /// Matrices for calculation of signed source (n_dofs x n_bulk_regions).
474 
475  /// Vectors for calculation of flux (n_boundary_edges).
477 
478  /// Vectors for calculation of mass (n_bulk_regions).
480 
481  /** Maps unique identifier of (local bulk element idx, side idx) returned by @p get_boundary_edge_uid(side)
482  * to local boundary edge.
483  * Example usage:
484  * be_id = be_id_map_[get_boundary_edge_uid(side)]
485  */
486  std::unordered_map<LongIdx, unsigned int> be_id_map_;
487 
488  /// Maps local boundary edge to its region boundary index.
490 
491  /// Offset for local part of vector of boundary edges.
493 
494 
495  // Vectors storing mass and balances of fluxes and volumes.
496  // substance, phase, region
503 
504  // Sums of the above vectors over phases and regions
513 
514  // time integrated quantities
519 
520  /// time of last calculated balance
521  double last_time_;
522 
523  /// TimeMark type for balance output of particular equation.
525 
526  /// TimeMark type for output of particular equation.
528 
529  /// true before calculating the mass at initial time, otherwise false
530  bool initial_;
531 
532  /// if true then cumulative balance is computed
534 
535  /// true before allocating necessary internal structures (Petsc matrices etc.)
537 
538  /// If the balance is on. Balance is off in the case of no balance output time marks.
540 
541  /// Add output time marks to balance output time marks.
543 
544 
545  /// MPI rank.
546  int rank_;
547 
548  /// hold count of line printed into output_
549  unsigned int output_line_counter_;
550 
551  /// marks whether YAML output has printed header
553 
554  /// Record for current balance
556 
558 
559 
560 };
561 
562 
563 
564 
565 
566 #endif // BALANCE_HH_
Quantity(const unsigned int index, const string &name)
Definition: balance.hh:130
string name_
Name of quantity (for output).
Definition: balance.hh:136
const unsigned int index_
Internal index within list of quantities.
Definition: balance.hh:139
std::vector< double > sum_fluxes_in_
Definition: balance.hh:506
OutputFormat output_format_
Format of output file.
Definition: balance.hh:452
std::string csv_zero_vals(unsigned int cnt, char delimiter)
Return part of output represented by zero values. Count of zero values is given by cnt parameter.
Definition: balance.cc:1002
void start_source_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the start_source_assembly() method for a set of quantities.
Definition: balance.hh:259
void allocate(const std::shared_ptr< DOFHandlerMultiDim > &dh, unsigned int max_dofs_per_boundary)
Definition: balance.cc:194
void calculate_instant(unsigned int quantity_idx, const Vec &solution)
Definition: balance.cc:636
bool balance_on_
If the balance is on. Balance is off in the case of no balance output time marks.
Definition: balance.hh:539
void start_mass_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the start_mass_assembly() method for a set of quantities.
Definition: balance.hh:233
unsigned int n_loc_dofs_seq_
Definition: balance.hh:435
double last_time_
time of last calculated balance
Definition: balance.hh:521
void add_source_values(unsigned int quantity_idx, unsigned int region_idx, const LocDofVec &loc_dof_indices, const std::vector< double > &mult_mat_values, const std::vector< double > &add_mat_values)
Definition: balance.cc:513
TimeMark::Type balance_output_type_
TimeMark type for balance output of particular equation.
Definition: balance.hh:524
bool is_current()
Returns true if the current time step is marked for the balance output.
Definition: balance.cc:376
void output_yaml(double time)
Perform output in yaml format.
Definition: balance.cc:1154
unsigned int n_loc_dofs_par_
Allocation parameters. Set by the allocate method used in the lazy_initialize.
Definition: balance.hh:434
Mat * be_flux_matrix_
Matrices for calculation of flux (n_boundary_edges x n_dofs).
Definition: balance.hh:467
std::vector< double > integrated_sources_
Definition: balance.hh:515
std::vector< unsigned int > be_regions_
Maps local boundary edge to its region boundary index.
Definition: balance.hh:489
unsigned int max_dofs_per_boundary_
Definition: balance.hh:436
Mat * region_source_rhs_
Matrices for calculation of signed source (n_dofs x n_bulk_regions).
Definition: balance.hh:473
void calculate_cumulative(unsigned int quantity_idx, const Vec &solution)
Definition: balance.cc:552
bool cumulative() const
Getter for cumulative_.
Definition: balance.hh:190
void start_source_assembly(unsigned int quantity_idx)
Definition: balance.cc:405
std::string file_prefix_
Save prefix passed in in constructor.
Definition: balance.hh:440
static const Input::Type::Record & get_input_type()
Main balance input record type.
Definition: balance.cc:53
std::vector< double > integrated_fluxes_
Definition: balance.hh:516
std::unordered_map< LongIdx, unsigned int > be_id_map_
Definition: balance.hh:486
void finish_source_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the finish_source_assembly() method for a set of quantities.
Definition: balance.hh:344
void start_mass_assembly(unsigned int quantity_idx)
Definition: balance.cc:387
std::ofstream output_
Handle for file for output in given OutputFormat of balance and total fluxes over individual regions ...
Definition: balance.hh:446
std::vector< double > sum_fluxes_
Definition: balance.hh:505
static const Input::Type::Selection & get_format_selection_input_type()
Input selection for file format.
Definition: balance.cc:42
std::vector< double > sum_sources_
Definition: balance.hh:509
std::vector< std::vector< double > > masses_
Definition: balance.hh:500
void output()
Perform output to file for given time instant.
Definition: balance.cc:713
void units(const UnitSI &unit)
Setter for units of conserved quantities.
Definition: balance.cc:157
static bool do_yaml_output_
Definition: balance.hh:431
void calculate_mass(unsigned int quantity_idx, const Vec &solution, vector< double > &output_array)
Definition: balance.cc:611
TimeMark::Type output_mark_type_
TimeMark type for output of particular equation.
Definition: balance.hh:527
std::vector< std::vector< double > > fluxes_in_
Definition: balance.hh:498
int rank_
MPI rank.
Definition: balance.hh:546
void format_csv_output_header(char delimiter, const std::string &comment_string)
Print output header.
Definition: balance.cc:1096
const Mesh * mesh_
Definition: balance.hh:457
void finish_flux_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the finish_flux_assembly() method for a set of quantities.
Definition: balance.hh:334
Balance(const std::string &file_prefix, const Mesh *mesh)
Definition: balance.cc:89
bool initial_
true before calculating the mass at initial time, otherwise false
Definition: balance.hh:530
std::vector< std::vector< double > > fluxes_out_
Definition: balance.hh:499
Vec * region_mass_vec_
Vectors for calculation of mass (n_bulk_regions).
Definition: balance.hh:479
void init_from_input(const Input::Record &in_rec, TimeGovernor &tg)
Definition: balance.cc:132
std::string format_csv_val(std::string val, char delimiter, bool initial=false)
Format string value of csv output. Wrap string into quotes and if delimiter is space,...
Definition: balance.cc:1124
Input::Record input_record_
Record for current balance.
Definition: balance.hh:555
std::vector< std::vector< double > > fluxes_
Definition: balance.hh:497
void finish_source_assembly(unsigned int quantity_idx)
This method must be called after assembling the matrix and vectors for computing source.
Definition: balance.cc:436
const TimeGovernor * time_
Definition: balance.hh:557
Vec * be_flux_vec_
Vectors for calculation of flux (n_boundary_edges).
Definition: balance.hh:476
std::vector< std::vector< double > > sources_out_
Definition: balance.hh:502
std::ofstream output_yaml_
Definition: balance.hh:449
FilePath balance_output_file_
File path for output_ stream.
Definition: balance.hh:443
bool allocation_done_
true before allocating necessary internal structures (Petsc matrices etc.)
Definition: balance.hh:536
~Balance()
Definition: balance.cc:106
std::vector< std::vector< double > > sources_in_
Definition: balance.hh:501
void add_cumulative_source(unsigned int quantity_idx, double source)
Definition: balance.cc:542
void output_csv(double time, char delimiter, const std::string &comment_string, unsigned int repeat=0)
Perform output in csv format.
Definition: balance.cc:1010
unsigned int output_line_counter_
hold count of line printed into output_
Definition: balance.hh:549
Mat * region_mass_matrix_
Matrices for calculation of mass (n_dofs x n_bulk_regions).
Definition: balance.hh:464
std::vector< Quantity > quantities_
Names of conserved quantities.
Definition: balance.hh:455
void output_legacy(double time)
Perform output in old format (for compatibility)
Definition: balance.cc:856
void finish_mass_assembly(unsigned int quantity_idx)
This method must be called after assembling the matrix for computing mass.
Definition: balance.cc:414
bool output_yaml_header_
marks whether YAML output has printed header
Definition: balance.hh:552
bool add_output_times_
Add output time marks to balance output time marks.
Definition: balance.hh:542
UnitSI units_
Units of conserved quantities.
Definition: balance.hh:460
OutputFormat
Definition: balance.hh:147
@ legacy
legacy
Definition: balance.hh:148
@ gnuplot
gnuplot
Definition: balance.hh:150
@ txt
csv
Definition: balance.hh:149
std::vector< double > increment_sources_
Definition: balance.hh:518
bool cumulative_
if true then cumulative balance is computed
Definition: balance.hh:533
Mat * region_source_matrix_
Matrices for calculation of source (n_dofs x n_bulk_regions).
Definition: balance.hh:470
std::vector< double > sum_fluxes_out_
Definition: balance.hh:507
static void set_yaml_output()
Set global variable to output balance files into YAML format (in addition to the table format).
Definition: balance.cc:66
void start_flux_assembly(unsigned int quantity_idx)
Definition: balance.cc:396
void add_flux_values(unsigned int quantity_idx, const DHCellSide &side, const LocDofVec &loc_dof_indices, const std::vector< double > &mat_values, double vec_value)
Definition: balance.cc:479
void start_flux_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the start_flux_assembly() method for a set of quantities.
Definition: balance.hh:246
void finish_mass_assembly(std::vector< unsigned int > q_idx_vec)
Variant of the finish_mass_assembly() method for a set of quantities.
Definition: balance.hh:324
void finish_flux_assembly(unsigned int quantity_idx)
This method must be called after assembling the matrix and vector for computing flux.
Definition: balance.cc:425
std::vector< double > sum_masses_
Definition: balance.hh:508
int be_offset_
Offset for local part of vector of boundary edges.
Definition: balance.hh:492
std::vector< double > initial_mass_
Definition: balance.hh:512
std::vector< double > sum_sources_in_
Definition: balance.hh:510
void add_mass_values(unsigned int quantity_idx, const DHCellAccessor &dh_cell, const LocDofVec &loc_dof_indices, const std::vector< double > &mat_values, double vec_value)
Definition: balance.cc:448
std::vector< double > increment_fluxes_
Definition: balance.hh:517
std::vector< unsigned int > add_quantities(const std::vector< string > &names)
Definition: balance.cc:176
std::vector< double > sum_sources_out_
Definition: balance.hh:511
static const unsigned int output_column_width
Size of column in output (used if delimiter is space)
Definition: balance.hh:391
unsigned int add_quantity(const string &name)
Definition: balance.cc:165
void lazy_initialize()
Definition: balance.cc:205
LongIdx get_boundary_edge_uid(SideIter side)
Definition: balance.hh:426
Cell accessor allow iterate over DOF handler cells.
Side accessor allows to iterate over sides of DOF handler cell.
Provides the numbering of the finite element degrees of freedom on the computational mesh.
Definition: dofhandler.hh:151
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Record type proxy class.
Definition: type_record.hh:182
Template for classes storing finite set of named values.
Definition: mesh.h:362
unsigned int elem_idx() const
Returns index of element in Mesh::element_vec_.
Definition: accessors.hh:448
unsigned int side_idx() const
Returns local index of the side on the element.
Definition: accessors.hh:444
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Class for representation SI units of Fields.
Definition: unit_si.hh:40
arma::Col< IntIdx > LocDofVec
Definition: index_types.hh:28
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
Abstract linear system class.
Definition: balance.hh:40