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