Flow123d  JS_before_hm-2115-gf629a871a
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 }
42 
44 {
45 }
46 
48 {
49  ASSERT(time_ != nullptr).error("Time governor has not been set yet.\n");
50  ASSERT_LT(0, eq_data_->substances_.size()).error("No substances for rection term.\n");
51 
52  n_substances_ = eq_data_->substances_.size();
54 
55  // allocation
56  prev_conc_.resize(n_substances_);
60 
61  // initialize diagonal matrices with molar masses
62  molar_matrix_.zeros();
63  molar_mat_inverse_.zeros();
64  for (unsigned int i=0; i<n_substances_; ++i)
65  {
66  molar_matrix_(i,i) = eq_data_->substances_[i].molar_mass();
67  molar_mat_inverse_(i,i) = 1./eq_data_->substances_[i].molar_mass();
68  }
69 }
70 
71 
73 {
74  ASSERT(time_ != nullptr).error("Time governor has not been set yet.\n");
75  ASSERT_LT(0, eq_data_->substances_.size()).error("No substances for rection term.\n");
76 
78  // make scaling that takes into account different molar masses of substances
80 
81  linear_ode_solver_->set_system_matrix(reaction_matrix_);
82 }
83 
84 
86 {
87  unsigned int sbi; // row in the concentration matrix, regards the substance index
88  arma::vec new_conc;
89 
90  IntIdx dof_p0 = dh_cell.get_loc_dof_indices()[0];
91 
92  // save previous concentrations to column vector
93  for(sbi = 0; sbi < n_substances_; sbi++)
94  prev_conc_(sbi) = this->eq_fields_base_->conc_mobile_fe[sbi]->vec().get(dof_p0);
95 
96  // compute new concetrations R*c
97  linear_ode_solver_->update_solution(prev_conc_, new_conc);
98 
99  // save new concentrations to the concentration matrix
100  for(sbi = 0; sbi < n_substances_; sbi++)
101  this->eq_fields_base_->conc_mobile_fe[sbi]->vec().set( dof_p0, new_conc(sbi) );
102 }
103 
105 {
106  //DebugOut() << "FirstOrderReactionBases - update solution\n";
107  if(time_->is_changed_dt())
108  {
109  linear_ode_solver_->set_step(time_->dt());
110  }
111 
112  START_TIMER("linear reaction step");
113 
114  for ( DHCellAccessor dh_cell : eq_data_->dof_handler_->own_range() )
115  {
116  compute_reaction(dh_cell);
117  }
118  END_TIMER("linear reaction step");
119 }
120 
121 
122 unsigned int FirstOrderReactionBase::find_subst_name(const string &name)
123 {
124  unsigned int k=0;
125  for(; k < n_substances_; k++)
126  if (name == eq_data_->substances_[k].name()) return k;
127 
128  return k;
129 }
FirstOrderReactionBase::find_subst_name
unsigned int find_subst_name(const std::string &name)
Definition: first_order_reaction_base.cc:122
FirstOrderReactionBase::molar_mat_inverse_
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
Definition: first_order_reaction_base.hh:111
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
TimeGovernor::dt
double dt() const
Definition: time_governor.hh:558
FirstOrderReactionBase::update_solution
void update_solution(void) override
Updates the solution.
Definition: first_order_reaction_base.cc:104
FirstOrderReactionBase::prev_conc_
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
Definition: first_order_reaction_base.hh:108
FirstOrderReactionBase::FirstOrderReactionBase
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Definition: first_order_reaction_base.cc:36
FirstOrderReactionBase::n_substances_
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix.
Definition: first_order_reaction_base.hh:105
linear_ode_solver.hh
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
EquationBase::time_
TimeGovernor * time_
Definition: equation.hh:221
distribution.hh
Support classes for parallel programing.
FirstOrderReactionBase::~FirstOrderReactionBase
~FirstOrderReactionBase(void)
Destructor.
Definition: first_order_reaction_base.cc:43
IntIdx
int IntIdx
Definition: index_types.hh:25
FirstOrderReactionBase::compute_reaction
virtual void compute_reaction(const DHCellAccessor &dh_cell) override
Computes the reaction on a specified element.
Definition: first_order_reaction_base.cc:85
ASSERT_LT
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:296
FirstOrderReactionBase::molar_matrix_
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
Definition: first_order_reaction_base.hh:110
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FirstOrderReactionBase::initialize
void initialize() override
Prepares the object to usage.
Definition: first_order_reaction_base.cc:47
sys_profiler.hh
first_order_reaction_base.hh
accessors.hh
FirstOrderReactionBase::zero_time_step
void zero_time_step() override
Moves the model to zero time.
Definition: first_order_reaction_base.cc:72
mesh.h
Input::Type
Definition: balance.hh:41
FirstOrderReactionBase::assemble_ode_matrix
virtual void assemble_ode_matrix(void)=0
Assembles the matrix of the ODEs.
FirstOrderReactionBase::initialize_from_input
virtual void initialize_from_input()=0
Initializes private members of sorption from the input record.
Mesh
Definition: mesh.h:355
DHCellAccessor
Cell accessor allow iterate over DOF handler cells.
Definition: dh_cell_accessor.hh:43
global_defs.h
Global macros to enhance readability and debugging, general constants.
ReactionTerm::eq_fields_base_
std::shared_ptr< EqFields > eq_fields_base_
Equation data - all fields needs in assembly class.
Definition: reaction_term.hh:149
DHCellAccessor::get_loc_dof_indices
LocDofVec get_loc_dof_indices() const
Returns the local indices of dofs associated to the cell on the local process.
Definition: dh_cell_accessor.hh:88
FirstOrderReactionBase::reaction_matrix_
arma::mat reaction_matrix_
Reaction matrix.
Definition: first_order_reaction_base.hh:107
TimeGovernor::is_changed_dt
bool is_changed_dt() const
Definition: time_governor.hh:522
reaction_term.hh
Class ReactionTerm is an abstract class representing reaction term in transport.
ReactionTerm
Definition: reaction_term.hh:46
START_TIMER
#define START_TIMER(tag)
Starts a timer with specified tag.
Definition: sys_profiler.hh:115
ReactionTerm::eq_data_
std::shared_ptr< EqData > eq_data_
Equation data - all data needs in assembly class.
Definition: reaction_term.hh:152
END_TIMER
#define END_TIMER(tag)
Ends a timer with specified tag.
Definition: sys_profiler.hh:149
FirstOrderReactionBase::linear_ode_solver_
std::shared_ptr< LinearODESolver > linear_ode_solver_
Definition: first_order_reaction_base.hh:113