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