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 17 of file AddCoupledSolidKinSpeciesAction.h.

Constructor & Destructor Documentation

AddCoupledSolidKinSpeciesAction::AddCoupledSolidKinSpeciesAction ( const InputParameters &  params)

Definition at line 46 of file AddCoupledSolidKinSpeciesAction.C.

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

void AddCoupledSolidKinSpeciesAction::act ( )
overridevirtual

Definition at line 202 of file AddCoupledSolidKinSpeciesAction.C.

203 {
204  if (_current_task == "add_kernel")
205  {
206  // Add Kernels for each primary species
207  for (unsigned int i = 0; i < _primary_species.size(); ++i)
208  {
209  InputParameters params_kin = _factory.getValidParams("CoupledBEKinetic");
210  params_kin.set<NonlinearVariableName>("variable") = _primary_species[i];
211  params_kin.set<std::vector<Real>>("weight") = _weights[i];
212  params_kin.set<std::vector<VariableName>>("v") = _kinetic_species_involved[i];
213  _problem->addKernel("CoupledBEKinetic", _primary_species[i] + "_" + "_kin", params_kin);
214  }
215  }
216 
217  if (_current_task == "add_aux_kernel")
218  {
219  // Add AuxKernels for each solid kinetic species
220  for (unsigned int i = 0; i < _num_reactions; ++i)
221  {
222  InputParameters params_kin = _factory.getValidParams("KineticDisPreConcAux");
223  params_kin.set<AuxVariableName>("variable") = _solid_kinetic_species[i];
224  params_kin.set<Real>("log_k") = _logk[i];
225  params_kin.set<Real>("r_area") = _r_area[i];
226  params_kin.set<Real>("ref_kconst") = _ref_kconst[i];
227  params_kin.set<Real>("e_act") = _e_act[i];
228  params_kin.set<Real>("gas_const") = _gas_const;
229  params_kin.set<Real>("ref_temp") = _ref_temp[i];
230  params_kin.set<std::vector<VariableName>>("sys_temp") = _sys_temp;
231  params_kin.set<std::vector<Real>>("sto_v") = _stos[i];
232  params_kin.set<std::vector<VariableName>>("v") = _primary_species_involved[i];
233  _problem->addAuxKernel(
234  "KineticDisPreConcAux", "aux_" + _solid_kinetic_species[i], params_kin);
235  }
236  }
237 }
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

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

Activation energy.

Definition at line 52 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

const Real AddCoupledSolidKinSpeciesAction::_gas_const
private

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

Definition at line 54 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act().

std::string AddCoupledSolidKinSpeciesAction::_input_reactions
private

Reaction network read from input file.

Definition at line 40 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

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

Secondary solid species involved the ith primary species.

Definition at line 34 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Log10 of equilibrium constant.

Definition at line 46 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

unsigned int AddCoupledSolidKinSpeciesAction::_num_reactions
private

Number of reactions.

Definition at line 44 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Basis set of primary species.

Definition at line 26 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Primary species involved in the ith kinetic reaction.

Definition at line 32 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

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

Definition at line 48 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Vector of parsed reactions.

Definition at line 42 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

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

Reference kinetic rate constant.

Definition at line 50 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Reference temperature.

Definition at line 56 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Secondary species added as AuxVariables.

Definition at line 28 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by AddCoupledSolidKinSpeciesAction().

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

Secondary solid species read by the parser.

Definition at line 30 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Stoichiometric coefficients for each primary species in each reaction.

Definition at line 36 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().

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

Actual system temperature.

Definition at line 58 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act().

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

Weight of each primary species in each reaction.

Definition at line 38 of file AddCoupledSolidKinSpeciesAction.h.

Referenced by act(), and AddCoupledSolidKinSpeciesAction().


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