Flow123d  jenkins-Flow123d-windows-release-multijob-285
first_order_reaction_base.cc
Go to the documentation of this file.
3 
7 
8 
9 #include "system/global_defs.h"
10 #include "system/sys_profiler.hh"
11 
12 #include "mesh/mesh.h"
13 #include "la/distribution.hh"
14 
15 using namespace Input::Type;
16 
18  : ReactionTerm(init_mesh, in_rec)
19 {
21  if ( num_it )
22  {
23  if (num_it->type() == PadeApproximant::input_type)
24  {
25  linear_ode_solver_ = new PadeApproximant(*num_it);
26  }
27  else if (num_it->type() == LinearODEAnalytic::input_type)
28  {
30  }
31  else
32  { //This point cannot be reached. The TYPE_selection will throw an error first.
33  THROW( ExcMessage()
34  << EI_Message("Linear ODEs solver selection failed (SHOULD NEVER HAPPEN).")
35  << (*num_it).ei_address());
36  }
37  }
38  else //default linear ode solver
39  {
41  }
42 }
43 
45 {
46 }
47 
49 {
50  ASSERT(distribution_ != nullptr, "Distribution has not been set yet.\n");
51  ASSERT(time_ != nullptr, "Time governor has not been set yet.\n");
53 
56 
57  // allocation
58  prev_conc_.resize(n_substances_);
59  reaction_matrix_.resize(n_substances_, n_substances_);
60  molar_matrix_.resize(n_substances_, n_substances_);
61  molar_mat_inverse_.resize(n_substances_, n_substances_);
62 
63  // initialize diagonal matrices with molar masses
64  molar_matrix_.zeros();
65  molar_mat_inverse_.zeros();
66  for (unsigned int i=0; i<n_substances_; ++i)
67  {
68  molar_matrix_(i,i) = substances_[i].molar_mass();
69  molar_mat_inverse_(i,i) = 1./substances_[i].molar_mass();
70  }
71 }
72 
73 
75 {
76  ASSERT(distribution_ != nullptr, "Distribution has not been set yet.\n");
77  ASSERT(time_ != nullptr, "Time governor has not been set yet.\n");
79 
81  // make scaling that takes into account different molar masses of substances
84 }
85 
86 
87 double **FirstOrderReactionBase::compute_reaction(double **concentrations, int loc_el) //multiplication of concentrations array by reaction matrix
88 {
89  unsigned int rows; // row in the concentration matrix, regards the substance index
90  arma::vec new_conc;
91 
92  // save previous concentrations to column vector
93  for(rows = 0; rows < n_substances_; rows++)
94  prev_conc_(rows) = concentrations[rows][loc_el];
95 
96  // compute new concetrations R*c
98 
99  // save new concentrations to the concentration matrix
100  for(rows = 0; rows < n_substances_; rows++)
101  concentrations[rows][loc_el] = new_conc(rows);
102 
103  return concentrations;
104 }
105 
107 {
108  //DBGMSG("FirstOrderReactionBases - update solution\n");
109  if(time_->is_changed_dt())
110  {
112  }
113 
114  START_TIMER("linear reaction step");
115 
116  for (unsigned int loc_el = 0; loc_el < distribution_->lsize(); loc_el++)
118 
119  END_TIMER("linear reaction step");
120 }
121 
122 
123 unsigned int FirstOrderReactionBase::find_subst_name(const string &name)
124 {
125  unsigned int k=0;
126  for(; k < n_substances_; k++)
127  if (name == substances_[k].name()) return k;
128 
129  return k;
130 }
This class implements the Pade approximation of exponential function.
virtual void initialize_from_input()=0
Initializes private members of sorption from the input record.
This class implements the analytic solution of a system of linear ODEs with constant matrix...
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
double ** concentration_matrix_
void initialize() override
Prepares the object to usage.
???
void zero_time_step() override
Moves the model to zero time.
SubstanceList substances_
Names belonging to substances.
static Input::Type::Record input_type
Definition: mesh.h:109
Iterator< Ret > find(const string &key) const
unsigned int find_subst_name(const std::string &name)
virtual void assemble_ode_matrix(void)=0
Assembles the matrix of the ODEs.
void set_step(double step)
Sets the step of the numerical method.
unsigned int size() const
Definition: substance.hh:99
void update_solution(void) override
Updates the solution.
Global macros to enhance readability and debugging, general constants.
arma::mat reaction_matrix_
Reaction matrix.
#define ASSERT(...)
Definition: global_defs.h:121
Distribution * distribution_
Pointer to reference to distribution of elements between processors.
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
#define ASSERT_LESS(a, b)
Definition: global_defs.h:164
bool is_changed_dt() const
#define START_TIMER(tag)
Starts a timer with specified tag.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:448
virtual void update_solution(arma::vec &init_vec, arma::vec &output_vec)=0
Updates solution of the ODEs system.
Support classes for parallel programing.
void set_system_matrix(const arma::mat &matrix)
Sets the matrix of ODE system.
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
Input::Record input_record_
Definition: equation.hh:220
double dt() const
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
static Input::Type::Record input_type
LinearODESolverBase * linear_ode_solver_
#define END_TIMER(tag)
Ends a timer with specified tag.
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix. ...
virtual double ** compute_reaction(double **concentrations, int loc_el) override
Computes the reaction on a specified element.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:34
~FirstOrderReactionBase(void)
Destructor.
TimeGovernor * time_
Definition: equation.hh:219
unsigned int lsize(int proc) const
get local size