Flow123d  build_with_4.0.3-86a16ad
first_order_reaction_base.cc
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.cc
15  * @brief
16  */
17 
20 
22 
23 
24 #include "system/global_defs.h"
25 #include "system/sys_profiler.hh"
26 
27 #include "mesh/mesh.h"
28 #include "la/distribution.hh"
29 #include "input/accessors.hh"
30 
31 
32 
33 using namespace Input::Type;
34 
35 
37  : ReactionTerm(init_mesh, in_rec)
38 {
39  linear_ode_solver_ = std::make_shared<LinearODESolver>();
40  this->eq_fields_base_ = std::make_shared<EqFields>();
41  this->eq_data_base_ = std::make_shared<EqData>();
42 }
43 
45 {
46 }
47 
49 {
50  ASSERT_PERMANENT(time_ != nullptr).error("Time governor has not been set yet.\n");
51  ASSERT_PERMANENT_LT(0, eq_data_base_->substances_.size()).error("No substances for rection term.\n");
52 
53  n_substances_ = eq_data_base_->substances_.size();
55 
56  // allocation
57  prev_conc_.resize(n_substances_);
61 
62  // initialize diagonal matrices with molar masses
63  molar_matrix_.zeros();
64  molar_mat_inverse_.zeros();
65  for (unsigned int i=0; i<n_substances_; ++i)
66  {
67  molar_matrix_(i,i) = eq_data_base_->substances_[i].molar_mass();
68  molar_mat_inverse_(i,i) = 1./eq_data_base_->substances_[i].molar_mass();
69  }
70 }
71 
72 
74 {
75  ASSERT(time_ != nullptr).error("Time governor has not been set yet.\n");
76  ASSERT_LT(0, eq_data_base_->substances_.size()).error("No substances for rection term.\n");
77 
79  // make scaling that takes into account different molar masses of substances
81 
82  linear_ode_solver_->set_system_matrix(reaction_matrix_);
83 }
84 
85 
87 {
88  unsigned int sbi; // row in the concentration matrix, regards the substance index
89  arma::vec new_conc;
90 
91  IntIdx dof_p0 = dh_cell.get_loc_dof_indices()[0];
92 
93  // save previous concentrations to column vector
94  for(sbi = 0; sbi < n_substances_; sbi++)
95  prev_conc_(sbi) = this->eq_fields_base_->conc_mobile_fe[sbi]->vec().get(dof_p0);
96 
97  // compute new concetrations R*c
98  linear_ode_solver_->update_solution(prev_conc_, new_conc);
99 
100  // save new concentrations to the concentration matrix
101  for(sbi = 0; sbi < n_substances_; sbi++)
102  this->eq_fields_base_->conc_mobile_fe[sbi]->vec().set( dof_p0, new_conc(sbi) );
103 }
104 
106 {
107  //DebugOut() << "FirstOrderReactionBases - update solution\n";
108  if(time_->is_changed_dt())
109  {
110  linear_ode_solver_->set_step(time_->dt());
111  }
112 
113  START_TIMER("linear reaction step");
114 
115  for ( DHCellAccessor dh_cell : eq_data_base_->dof_handler_->own_range() )
116  {
117  compute_reaction(dh_cell);
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 == eq_data_base_->substances_[k].name()) return k;
128 
129  return k;
130 }
#define ASSERT_PERMANENT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:297
#define ASSERT(expr)
Definition: asserts.hh:351
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
Cell accessor allow iterate over DOF handler cells.
LocDofVec get_loc_dof_indices() const
Returns the local indices of dofs associated to the cell on the local process.
TimeGovernor * time_
Definition: equation.hh:241
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
std::shared_ptr< LinearODESolver > linear_ode_solver_
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix.
void zero_time_step() override
Moves the model to zero time.
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
virtual void compute_reaction(const DHCellAccessor &dh_cell) override
Computes the reaction on a specified element.
arma::mat reaction_matrix_
Reaction matrix.
unsigned int find_subst_name(const std::string &name)
virtual void assemble_ode_matrix(void)=0
Assembles the matrix of the ODEs.
~FirstOrderReactionBase(void)
Destructor.
void update_solution(void) override
Updates the solution.
void initialize() override
Prepares the object to usage.
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
virtual void initialize_from_input()=0
Initializes private members of sorption from the input record.
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Definition: mesh.h:362
std::shared_ptr< EqFields > eq_fields_base_
Equation data - all fields needs in assembly class.
std::shared_ptr< EqData > eq_data_base_
Equation data - all data needs in assembly class.
double dt() const
bool is_changed_dt() const
Support classes for parallel programing.
Global macros to enhance readability and debugging, general constants.
int IntIdx
Definition: index_types.hh:25
ArmaVec< double, N > vec
Definition: armor.hh:885
Class ReactionTerm is an abstract class representing reaction term in transport.
#define END_TIMER(tag)
Ends a timer with specified tag.
#define START_TIMER(tag)
Starts a timer with specified tag.