www.mooseframework.org
Public Member Functions | Private Attributes | List of all members
AddCoupledSolidKinSpeciesAction Class Reference

#include <AddCoupledSolidKinSpeciesAction.h>

Inheritance diagram for AddCoupledSolidKinSpeciesAction:
[legend]

Public Member Functions

 AddCoupledSolidKinSpeciesAction (const InputParameters &params)
 
virtual void act () override
 

Private Attributes

const std::vector< NonlinearVariableName > _primary_species
 Basis set of primary species. More...
 
const std::vector< AuxVariableName > _secondary_species
 Secondary species added as AuxVariables. More...
 
std::vector< VariableName > _solid_kinetic_species
 Secondary solid species read by the parser. More...
 
std::vector< std::vector< VariableName > > _primary_species_involved
 Primary species involved in the ith kinetic reaction. More...
 
std::vector< std::vector< VariableName > > _kinetic_species_involved
 Secondary solid species involved the ith primary species. More...
 
std::vector< std::vector< Real > > _stos
 Stoichiometric coefficients for each primary species in each reaction. More...
 
std::vector< std::vector< Real > > _weights
 Weight of each primary species in each reaction. More...
 
std::string _input_reactions
 Reaction network read from input file. More...
 
std::vector< std::string > _reactions
 Vector of parsed reactions. More...
 
unsigned int _num_reactions
 Number of reactions. More...
 
const std::vector< Real > _logk
 Log10 of equilibrium constant. More...
 
const std::vector< Real > _r_area
 Specific reactive surface area, m^2/L solution. More...
 
const std::vector< Real > _ref_kconst
 Reference kinetic rate constant. More...
 
const std::vector< Real > _e_act
 Activation energy. More...
 
const Real _gas_const
 Gas constant, (Default 8.314 J/mol/K) More...
 
const std::vector< Real > _ref_temp
 Reference temperature. More...
 
const std::vector< VariableName > _sys_temp
 Actual system temperature. More...
 

Detailed Description

Definition at line 20 of file AddCoupledSolidKinSpeciesAction.h.

Constructor & Destructor Documentation

◆ AddCoupledSolidKinSpeciesAction()

AddCoupledSolidKinSpeciesAction::AddCoupledSolidKinSpeciesAction ( const InputParameters &  params)

Definition at line 53 of file AddCoupledSolidKinSpeciesAction.C.

54  : Action(params),
55  _primary_species(getParam<std::vector<NonlinearVariableName>>("primary_species")),
56  _secondary_species(getParam<std::vector<AuxVariableName>>("secondary_species")),
58  _weights(_primary_species.size()),
59  _input_reactions(getParam<std::string>("kin_reactions")),
60  _logk(getParam<std::vector<Real>>("log10_keq")),
61  _r_area(getParam<std::vector<Real>>("specific_reactive_surface_area")),
62  _ref_kconst(getParam<std::vector<Real>>("kinetic_rate_constant")),
63  _e_act(getParam<std::vector<Real>>("activation_energy")),
64  _gas_const(getParam<Real>("gas_constant")),
65  _ref_temp(getParam<std::vector<Real>>("reference_temperature")),
66  _sys_temp(getParam<std::vector<VariableName>>("system_temperature"))
67 {
68  // Note: as the reaction syntax has changed, check to see if the old syntax has
69  // been used and throw an informative error. The number of = signs should be one
70  // more than the number of commas, while the smallest number of spaces possible is 2
71  bool old_syntax = false;
72  if (std::count(_input_reactions.begin(), _input_reactions.end(), '=') !=
73  std::count(_input_reactions.begin(), _input_reactions.end(), ',') + 1)
74  old_syntax = true;
75 
76  if (std::count(_input_reactions.begin(), _input_reactions.end(), ' ') < 2)
77  old_syntax = true;
78 
79  if (old_syntax)
80  mooseError("Old solid kinetic reaction syntax present.\nReactions should now be comma "
81  "separated, and must have spaces between species and +/-/= operators.\n"
82  "See #9972 for details");
83 
84  // Parse the kinetic reactions
85  pcrecpp::RE re_reactions("(.+?)" // A single reaction (any character until the comma delimiter)
86  "(?:,\\s*|$)" // comma or end of string
87  ,
88  pcrecpp::RE_Options().set_extended(true));
89 
90  pcrecpp::RE re_terms("(\\S+)");
91  pcrecpp::RE re_coeff_and_species("(?: \\(? (.*?) \\)? )" // match the leading coefficent
92  "([A-Za-z].*)" // match the species
93  ,
94  pcrecpp::RE_Options().set_extended(true));
95 
96  pcrecpp::StringPiece input(_input_reactions);
97  pcrecpp::StringPiece single_reaction, term;
98  std::string single_reaction_str;
99 
100  // Parse reaction network to extract each individual reaction
101  while (re_reactions.FindAndConsume(&input, &single_reaction_str))
102  _reactions.push_back(single_reaction_str);
103 
104  _num_reactions = _reactions.size();
105 
106  if (_num_reactions == 0)
107  mooseError("No solid kinetic reaction provided!");
108 
109  // Start parsing each reaction
110  for (unsigned int i = 0; i < _num_reactions; ++i)
111  {
112  single_reaction = _reactions[i];
113 
114  // Capture all of the terms
115  std::string species, coeff_str;
116  Real coeff;
117  int sign = 1;
118  bool secondary = false;
119 
120  std::vector<Real> local_stos;
121  std::vector<VariableName> local_species_list;
122 
123  // Find every single term in this reaction (species and operators)
124  while (re_terms.FindAndConsume(&single_reaction, &term))
125  {
126  // Separating the stoichiometric coefficients from species
127  if (re_coeff_and_species.PartialMatch(term, &coeff_str, &species))
128  {
129  if (coeff_str.length())
130  coeff = std::stod(coeff_str);
131  else
132  coeff = 1.0;
133 
134  coeff *= sign;
135 
136  if (secondary)
137  _solid_kinetic_species.push_back(species);
138  else
139  {
140  local_stos.push_back(coeff);
141  local_species_list.push_back(species);
142  }
143  }
144  // Finding the operators and assign value of -1.0 to "-" sign
145  else if (term == "+" || term == "=" || term == "-")
146  {
147  if (term == "-")
148  {
149  sign = -1;
150  term = "+";
151  }
152 
153  if (term == "=")
154  secondary = true;
155  }
156  else
157  mooseError("Error parsing term: ", term.as_string());
158  }
159 
160  _stos.push_back(local_stos);
161  _primary_species_involved.push_back(local_species_list);
162  }
163 
164  // Start picking out primary species and coupled primary species and assigning
165  // corresponding stoichiomentric coefficients
166  for (unsigned int i = 0; i < _primary_species.size(); ++i)
167  for (unsigned int j = 0; j < _num_reactions; ++j)
168  {
169  for (unsigned int k = 0; k < _primary_species_involved[j].size(); ++k)
171  {
172  _weights[i].push_back(_stos[j][k]);
174  }
175  }
176 
177  // Print out details of the solid kinetic reactions to the console
178  _console << "Solid kinetic reactions:\n";
179  for (unsigned int i = 0; i < _num_reactions; ++i)
180  _console << " Reaction " << i + 1 << ": " << _reactions[i] << "\n";
181  _console << "\n";
182 
183  // Check that all secondary species read from the reaction network have been added
184  // as AuxVariables. Note: can't sort the _solid_kinetic_species vector as it throws
185  // out the species and coefficient vectors so use std::is_permutation
186  if (!std::is_permutation(
188  mooseError("All solid kinetic species must be added as secondary species");
189 
190  // Check that the size of property vectors is equal to the number of reactions
191  if (_logk.size() != _num_reactions)
192  mooseError("The number of values entered for log10_keq is not equal to the number of solid "
193  "kinetic reactions");
194  if (_r_area.size() != _num_reactions)
195  mooseError("The number of values entered for specific_reactive_surface_area is not equal to "
196  "the number of solid kinetic reactions");
197  if (_ref_kconst.size() != _num_reactions)
198  mooseError("The number of values entered for kinetic_rate_constant is not equal to the number "
199  "of solid kinetic reactions");
200  if (_e_act.size() != _num_reactions)
201  mooseError("The number of values entered for activation_energy is not equal to the number of "
202  "solid kinetic reactions");
203  if (_ref_temp.size() != _num_reactions)
204  mooseError("The number of values entered for reference_temperature is not equal to the number "
205  "of solid kinetic reactions");
206 }
std::vector< std::vector< Real > > _stos
Stoichiometric coefficients for each primary species in each reaction.
const std::vector< Real > _ref_kconst
Reference kinetic rate constant.
std::vector< std::vector< VariableName > > _primary_species_involved
Primary species involved in the ith kinetic reaction.
const std::vector< Real > _logk
Log10 of equilibrium constant.
const std::vector< VariableName > _sys_temp
Actual system temperature.
const std::vector< Real > _ref_temp
Reference temperature.
std::vector< std::string > _reactions
Vector of parsed reactions.
unsigned int _num_reactions
Number of reactions.
std::vector< std::vector< VariableName > > _kinetic_species_involved
Secondary solid species involved the ith primary species.
const std::vector< Real > _r_area
Specific reactive surface area, m^2/L solution.
const Real _gas_const
Gas constant, (Default 8.314 J/mol/K)
const std::vector< AuxVariableName > _secondary_species
Secondary species added as AuxVariables.
const std::vector< NonlinearVariableName > _primary_species
Basis set of primary species.
const std::vector< Real > _e_act
Activation energy.
std::string _input_reactions
Reaction network read from input file.
std::vector< VariableName > _solid_kinetic_species
Secondary solid species read by the parser.
std::vector< std::vector< Real > > _weights
Weight of each primary species in each reaction.

Member Function Documentation

◆ act()

void AddCoupledSolidKinSpeciesAction::act ( )
overridevirtual

Definition at line 209 of file AddCoupledSolidKinSpeciesAction.C.

210 {
211  if (_current_task == "add_kernel")
212  {
213  // Add Kernels for each primary species
214  for (unsigned int i = 0; i < _primary_species.size(); ++i)
215  {
216  InputParameters params_kin = _factory.getValidParams("CoupledBEKinetic");
217  params_kin.set<NonlinearVariableName>("variable") = _primary_species[i];
218  params_kin.set<std::vector<Real>>("weight") = _weights[i];
219  params_kin.set<std::vector<VariableName>>("v") = _kinetic_species_involved[i];
220  _problem->addKernel("CoupledBEKinetic", _primary_species[i] + "_" + "_kin", params_kin);
221  }
222  }
223 
224  if (_current_task == "add_aux_kernel")
225  {
226  // Add AuxKernels for each solid kinetic species
227  for (unsigned int i = 0; i < _num_reactions; ++i)
228  {
229  InputParameters params_kin = _factory.getValidParams("KineticDisPreConcAux");
230  params_kin.set<AuxVariableName>("variable") = _solid_kinetic_species[i];
231  params_kin.defaultCoupledValue("log_k", _logk[i]);
232  params_kin.set<Real>("r_area") = _r_area[i];
233  params_kin.set<Real>("ref_kconst") = _ref_kconst[i];
234  params_kin.set<Real>("e_act") = _e_act[i];
235  params_kin.set<Real>("gas_const") = _gas_const;
236  params_kin.set<Real>("ref_temp") = _ref_temp[i];
237  params_kin.set<std::vector<VariableName>>("sys_temp") = _sys_temp;
238  params_kin.set<std::vector<Real>>("sto_v") = _stos[i];
239  params_kin.set<std::vector<VariableName>>("v") = _primary_species_involved[i];
240  _problem->addAuxKernel(
241  "KineticDisPreConcAux", "aux_" + _solid_kinetic_species[i], params_kin);
242  }
243  }
244 }
std::vector< std::vector< Real > > _stos
Stoichiometric coefficients for each primary species in each reaction.
const std::vector< Real > _ref_kconst
Reference kinetic rate constant.
std::vector< std::vector< VariableName > > _primary_species_involved
Primary species involved in the ith kinetic reaction.
const std::vector< Real > _logk
Log10 of equilibrium constant.
const std::vector< VariableName > _sys_temp
Actual system temperature.
const std::vector< Real > _ref_temp
Reference temperature.
unsigned int _num_reactions
Number of reactions.
std::vector< std::vector< VariableName > > _kinetic_species_involved
Secondary solid species involved the ith primary species.
const std::vector< Real > _r_area
Specific reactive surface area, m^2/L solution.
const Real _gas_const
Gas constant, (Default 8.314 J/mol/K)
const std::vector< NonlinearVariableName > _primary_species
Basis set of primary species.
const std::vector< Real > _e_act
Activation energy.
std::vector< VariableName > _solid_kinetic_species
Secondary solid species read by the parser.
std::vector< std::vector< Real > > _weights
Weight of each primary species in each reaction.

Member Data Documentation

◆ _e_act

const std::vector<Real> AddCoupledSolidKinSpeciesAction::_e_act
private

Activation energy.

Definition at line 55 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _gas_const

const Real AddCoupledSolidKinSpeciesAction::_gas_const
private

Gas constant, (Default 8.314 J/mol/K)

Definition at line 57 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act().

◆ _input_reactions

std::string AddCoupledSolidKinSpeciesAction::_input_reactions
private

Reaction network read from input file.

Definition at line 43 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

◆ _kinetic_species_involved

std::vector<std::vector<VariableName> > AddCoupledSolidKinSpeciesAction::_kinetic_species_involved
private

Secondary solid species involved the ith primary species.

Definition at line 37 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _logk

const std::vector<Real> AddCoupledSolidKinSpeciesAction::_logk
private

Log10 of equilibrium constant.

Definition at line 49 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _num_reactions

unsigned int AddCoupledSolidKinSpeciesAction::_num_reactions
private

Number of reactions.

Definition at line 47 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _primary_species

const std::vector<NonlinearVariableName> AddCoupledSolidKinSpeciesAction::_primary_species
private

Basis set of primary species.

Definition at line 29 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _primary_species_involved

std::vector<std::vector<VariableName> > AddCoupledSolidKinSpeciesAction::_primary_species_involved
private

Primary species involved in the ith kinetic reaction.

Definition at line 35 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _r_area

const std::vector<Real> AddCoupledSolidKinSpeciesAction::_r_area
private

Specific reactive surface area, m^2/L solution.

Definition at line 51 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _reactions

std::vector<std::string> AddCoupledSolidKinSpeciesAction::_reactions
private

Vector of parsed reactions.

Definition at line 45 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

◆ _ref_kconst

const std::vector<Real> AddCoupledSolidKinSpeciesAction::_ref_kconst
private

Reference kinetic rate constant.

Definition at line 53 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _ref_temp

const std::vector<Real> AddCoupledSolidKinSpeciesAction::_ref_temp
private

Reference temperature.

Definition at line 59 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _secondary_species

const std::vector<AuxVariableName> AddCoupledSolidKinSpeciesAction::_secondary_species
private

Secondary species added as AuxVariables.

Definition at line 31 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

◆ _solid_kinetic_species

std::vector<VariableName> AddCoupledSolidKinSpeciesAction::_solid_kinetic_species
private

Secondary solid species read by the parser.

Definition at line 33 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _stos

std::vector<std::vector<Real> > AddCoupledSolidKinSpeciesAction::_stos
private

Stoichiometric coefficients for each primary species in each reaction.

Definition at line 39 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

◆ _sys_temp

const std::vector<VariableName> AddCoupledSolidKinSpeciesAction::_sys_temp
private

Actual system temperature.

Definition at line 61 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act().

◆ _weights

std::vector<std::vector<Real> > AddCoupledSolidKinSpeciesAction::_weights
private

Weight of each primary species in each reaction.

Definition at line 41 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().


The documentation for this class was generated from the following files: