Flow123d  release_3.0.0-899-g9314a17
first_order_reaction_base.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 first_order_reaction_base.hh
15  * @brief
16  */
17 
18 #ifndef FIRST_ORDER_REACTION_BASE_H_
19 #define FIRST_ORDER_REACTION_BASE_H_
20 
21 #include <memory> // for shared_ptr
22 #include <string> // for string
23 #include <vector>
25 
26 #include "armadillo"
27 
28 class Mesh;
29 class LinearODESolver;
30 namespace Input { class Record; }
31 
32 /** @brief Base class for linear reactions and decay chain.
33  *
34  * The class implements common interface for linear reactions and decay chains.
35  * One step of the linear reaction or the decay is represented as a product of a reaction matrix and
36  * a vector of concentrations of transported substances on a single element.
37  *
38  * It uses armadillo to compute the reaction matrix which then multiplies to concetration vector.
39  * This class also resolves the choice of the numerical method which is used to compute the reaction matrix.
40  */
42 {
43 public:
44  /// Constructor.
45  FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec);
46 
47  /// Destructor.
49 
50  /// Prepares the object to usage.
51  /**
52  * Allocating memory, reading input, initialization of fields.
53  */
54  void initialize() override;
55 
56  /// Moves the model to zero time.
57  /** The assembly of the system matrix is called here.
58  */
59  void zero_time_step() override;
60 
61  /// Updates the solution.
62  /**
63  * Goes through local distribution of elements and calls @p compute_reaction.
64  */
65  void update_solution(void) override;
66 
67  bool evaluate_time_constraint(double &time_constraint) override;
68 
69 protected:
70  /// Assembles the matrix of the ODEs.
71  /**
72  * We solve the system of \f$N\f$ equations
73  * \f[
74  * \frac{\textrm{d} c_i}{\textrm{d}t}=-\sum\limits_{j=1}^N \frac{M_i}{M_j} \lambda_{i} b_j c_j, \qquad \textrm i=1,\ldots,N
75  * \f]
76  * where \f$M_i, M_j\f$ are the molar masses of the parent substances and products, \f$\lambda_i\f$ are the
77  * reaction rate constants (in case of decays converted from half_lives) and \f$b_j\f$ are the branching ratios.
78  * The constant coefficients \f$\mathbf{A}_{ij}=\frac{M_i}{M_j} \lambda_{i} b_j\f$ are the elements of the system matrix.
79  *
80  * It is pure virtual and must be implemented in descendants.
81  */
82  virtual void assemble_ode_matrix(void) = 0;
83 
84  /// Computes the reaction on a specified element.
85  virtual double **compute_reaction(double **concentrations, int loc_el) override;
86 
87  /// Initializes private members of sorption from the input record.
88  virtual void initialize_from_input() = 0;
89 
90  /** Help function to create mapping of substance indices.
91  * Finds a position of a string in specified array.
92  */
93  unsigned int find_subst_name(const std::string &name);
94 
95  /**
96  * Sequence of integers describing an order of isotopes.
97  * substance_ids_[reactant][local_product_idx] = global_substance_idx
98  */
100 
101  /**
102  * Two dimensional array contains mass percentage of every single decay bifurcation on every single row.
103  */
105 
106  /// Number of all transported substances. It is the dimension of the reaction matrix.
107  unsigned int n_substances_;
108 
109  arma::mat reaction_matrix_; ///< Reaction matrix.
110  arma::vec prev_conc_; ///< Column vector storing previous concetrations on an element.
111 
112  arma::mat molar_matrix_; ///< Diagonal matrix with molar masses of substances.
113  arma::mat molar_mat_inverse_; ///< Inverse of @p molar_matrix_.
114 
115  std::shared_ptr<LinearODESolver> linear_ode_solver_;
116 };
117 
118 #endif // FIRST_ORDER_REACTION_BASE_H_
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
Abstract linear system class.
Definition: balance.hh:35
Class for linear ODE solver.
Definition: mesh.h:80
Base class for linear reactions and decay chain.
Class ReactionTerm is an abstract class representing reaction term in transport.
arma::mat reaction_matrix_
Reaction matrix.
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
std::shared_ptr< LinearODESolver > linear_ode_solver_
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
std::vector< std::vector< unsigned int > > substance_ids_
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix. ...
std::vector< std::vector< double > > bifurcation_