https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ChemicalCompositionAction Class Reference

The ChemicalCompositionAction sets up user objects, aux kernels, and aux variables for a thermochemistry calculation using Thermochimica. More...

#include <ChemicalCompositionAction.h>

Inheritance diagram for ChemicalCompositionAction:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 ChemicalCompositionAction (const InputParameters &params)
 
const std::vector< unsigned int > & elementIDs () const
 
const std::vector< std::string > & phases () const
 
const std::vector< std::string > & elementPotentials () const
 
const std::vector< std::pair< std::string, std::string > > & speciesPhasePairs () const
 
const std::vector< std::pair< std::string, std::string > > & vaporPhasePairs () const
 
const std::vector< std::pair< std::string, std::string > > & phaseElementPairs () const
 
virtual void act ()
 
void timedAct ()
 
virtual void addRelationshipManagers (Moose::RelationshipManagerType when_type)
 
MooseObjectName uniqueActionName () const
 
const std::string & specificTaskName () const
 
const std::set< std::string > & getAllTasks () const
 
void appendTask (const std::string &task)
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
PerfGraphperfGraph ()
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string unique_action_name_param
 
static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 
static constexpr auto SYSTEM
 
static constexpr auto NAME
 

Protected Member Functions

void readCSV ()
 
bool addRelationshipManagers (Moose::RelationshipManagerType when_type, const InputParameters &moose_object_pars)
 
void associateWithParameter (const std::string &param_name, InputParameters &params) const
 
void associateWithParameter (const InputParameters &from_params, const std::string &param_name, InputParameters &params) const
 
const TgetMeshProperty (const std::string &data_name, const std::string &prefix)
 
const TgetMeshProperty (const std::string &data_name)
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name) const
 
bool hasMeshProperty (const std::string &data_name) const
 
std::string meshPropertyName (const std::string &data_name) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 

Static Protected Member Functions

static std::string meshPropertyName (const std::string &data_name, const std::string &prefix)
 

Protected Attributes

std::vector< std::string > _elements
 Element names.
 
std::map< std::string, Real > _initial_conditions
 Initial conditions for each element: [element name] => initial condition value.
 
std::vector< std::string > _phases
 List of phases tracked by Thermochimica.
 
std::vector< unsigned int_element_ids
 Atomic numbers of the selected elements.
 
std::vector< std::pair< std::string, std::string > > _tokenized_species
 Tokenized versions of the output variables to avoid redoing tokenization.
 
std::vector< std::string > _tokenized_element_potentials
 
std::vector< std::pair< std::string, std::string > > _tokenized_vapor_species
 
std::vector< std::pair< std::string, std::string > > _tokenized_phase_elements
 
std::string _registered_identifier
 
std::string _specific_task_name
 
std::set< std::string > _all_tasks
 
ActionWarehouse_awh
 
const std::string & _current_task
 
std::shared_ptr< MooseMesh > & _mesh
 
std::shared_ptr< MooseMesh > & _displaced_mesh
 
std::shared_ptr< FEProblemBase > & _problem
 
PerfID _act_timer
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Private Member Functions

bool addRelationshipManager (Moose::RelationshipManagerType input_rm_type, const InputParameters &moose_object_pars, std::string rm_name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback rm_input_parameter_func, Moose::RMSystemType sys_type=Moose::RMSystemType::NONE)
 
virtual std::string meshPropertyPrefix (const std::string &data_name) const
 
const RestartableDataValuegetMeshPropertyInternal (const std::string &data_name, const std::string &prefix) const
 
void mooseErrorInternal (Args &&... args) const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const ParallelParamObject_parent
 
MooseApp_meta_data_app
 
const MooseObject *const _meta_data_object
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 

Detailed Description

The ChemicalCompositionAction sets up user objects, aux kernels, and aux variables for a thermochemistry calculation using Thermochimica.

Definition at line 19 of file ChemicalCompositionAction.h.

Constructor & Destructor Documentation

◆ ChemicalCompositionAction()

ChemicalCompositionAction::ChemicalCompositionAction ( const InputParameters params)

Definition at line 88 of file ChemicalCompositionAction.C.

90{
91 const auto & params = _app.getInputParameterWarehouse().getInputParameters();
92 InputParameters & pars(*(params.find(uniqueActionName())->second.get()));
93
94 // check if a container block with common parameters is found
96 if (action.size() == 1)
97 pars.applyParameters(action[0]->parameters());
98
99 if (!isParamValid("tunit"))
101 "tunit",
102 "The temperature unit must be specified for Thermochimica objects to be constructed");
103
104 if (!isParamValid("punit"))
105 paramError("punit",
106 "The pressure unit must be specified for Thermochimica objects to be constructed");
107
108 if (!isParamValid("munit"))
109 paramError("munit",
110 "The mass unit must be specified for Thermochimica objects to be constructed");
111
112 if (!isParamValid("temperature"))
113 paramError("temperature",
114 "Temperature variable must be specified for this object to be constructed");
115
116 if ((isParamValid("output_species") || isParamValid("output_element_phases")) &&
117 !isParamValid("output_species_unit"))
119 "output_species_unit",
120 "Output mass unit must be specified for Thermochimica user object to be constructed");
121
123
124#ifdef THERMOCHIMICA_ENABLED
125 // Initialize database in Thermochimica
126 if (isParamValid("thermofile"))
127 {
128 const auto thermo_file = getParam<FileName>("thermofile");
129
130 if (thermo_file.length() > 1024)
131 paramError("thermofile",
132 "Path exceeds Thermochimica's maximal permissible length of 1024 with ",
133 thermo_file.length(),
134 " characters: ",
135 thermo_file);
136
137 Thermochimica::setThermoFilename(thermo_file);
138
139 // Read in thermodynamics model for setting up variables
140 Thermochimica::parseThermoFile();
141
142 const auto idbg = Thermochimica::checkInfoThermo();
143 if (idbg != 0)
144 paramError("thermofile", "Thermochimica data file cannot be parsed. ", idbg);
145 }
146
147 // Set thermochimica units
148 auto tunit = Moose::stringify(getParam<MooseEnum>("tunit"));
149 Thermochimica::checkTemperature(tunit);
150 Thermochimica::setUnitTemperature(tunit);
151 int idbg = Thermochimica::checkInfoThermo();
152 if (idbg != 0)
153 paramError("tunit", "Cannot set temperature unit in Thermochimica", idbg);
154
155 auto punit = Moose::stringify(getParam<MooseEnum>("punit"));
156 Thermochimica::checkPressure(punit);
157 Thermochimica::setUnitPressure(punit);
158 idbg = Thermochimica::checkInfoThermo();
159 if (idbg != 0)
160 paramError("punit", "Cannot set pressure unit in Thermochimica", idbg);
161
162 auto munit = Moose::stringify(getParam<MooseEnum>("munit"));
163 std::replace(munit.begin(), munit.end(), '_', ' ');
164 Thermochimica::checkMass(munit);
165 Thermochimica::setUnitMass(munit);
166 idbg = Thermochimica::checkInfoThermo();
167 if (idbg != 0)
168 paramError("munit", "Cannot set mass unit in Thermochimica", idbg);
169
170 _elements = getParam<std::vector<std::string>>("elements");
171 if (_elements.size() == 1 && _elements[0] == "ALL")
172 {
173 _elements.resize(Thermochimica::getNumberElementsDatabase());
174 _elements = Thermochimica::getElementsDatabase();
175 mooseInfo("Thermochimica elements: 'ALL' specified in input file. Using: ",
177 }
178 else
179 {
180 std::vector<std::string> db_elements(Thermochimica::getNumberElementsDatabase());
181 db_elements = Thermochimica::getElementsDatabase();
182 for (const auto i : index_range(_elements))
183 if (std::find(db_elements.begin(), db_elements.end(), _elements[i]) == db_elements.end())
184 paramError("elements", "Element '", _elements[i], "' was not found in the database.");
185 }
186 _element_ids.resize(_elements.size());
187 for (const auto i : index_range(_elements))
188 _element_ids[i] = Thermochimica::atomicNumber(_elements[i]);
189
190 // I want to check all the input parameters here and have a list of possible phases and species
191 // for setting up the Aux variables with "ALL" option
192
193 // Temporarily set Thermochimica state space to get the list of possible phases and species
194 Thermochimica::setTemperaturePressure(1000.0, 1.0);
195 Thermochimica::setElementMass(0, 0.0);
196
197 for (const auto i : make_range(_elements.size()))
198 Thermochimica::setElementMass(Thermochimica::atomicNumber(_elements[i]), 1.0);
199
200 Thermochimica::setup();
201
202 if (isParamValid("output_phases"))
203 {
204 _phases = getParam<std::vector<std::string>>("output_phases");
205 if (_phases.size() == 1 && _phases[0] == "ALL")
206 {
207 auto [soln_phases, stoich_phases] = Thermochimica::getNumberPhasesSystem();
208 _phases.resize(soln_phases + stoich_phases);
209 _phases = Thermochimica::getPhaseNamesSystem();
210 mooseInfo("ChemicalCompositionAction phases: 'ALL' specified in input file. Using: ",
212 }
213 else
214 {
215 auto db_phases = Thermochimica::getPhaseNamesSystem();
216 for (const auto i : index_range(_phases))
217 if (std::find(db_phases.begin(), db_phases.end(), _phases[i]) == db_phases.end())
218 paramError("output_phases", "Phase '", _phases[i], "' was not found in the simulation.");
219 }
220 }
221
222 if (isParamValid("output_species"))
223 {
224 auto species = getParam<std::vector<std::string>>("output_species");
225 auto db_phases = Thermochimica::getPhaseNamesSystem();
226 auto n_db_species = Thermochimica::getNumberSpeciesSystem();
227 auto db_species = Thermochimica::getSpeciesSystem();
228 for (auto i : index_range(n_db_species))
229 if (Thermochimica::isPhaseMQM(i))
230 {
231 auto [pairs, quads, idbg] =
232 Thermochimica::getMqmqaNumberPairsQuads(Thermochimica::getPhaseNamesSystem()[i]);
233 n_db_species[i] = pairs;
234 }
235
236 if (species.size() == 1 && species[0] == "ALL")
237 {
238 if (!n_db_species.empty())
239 species.resize(n_db_species.back());
240 else
241 mooseInfo("ChemicalCompositionAction species: 'ALL' specified in input file. Thermochimica "
242 "returned no possible species.");
243
244 species.clear();
245 _tokenized_species.clear();
246 for (const auto i : make_range(db_species.size()))
247 for (const auto j : index_range(db_species[i]))
248 {
249 species.push_back(db_phases[i] + ":" + db_species[i][j]);
250 _tokenized_species.push_back(std::make_pair(db_phases[i], db_species[i][j]));
251 }
252 mooseInfo("ChemicalCompositionAction species: 'ALL' specified in input file. Using: ",
253 Moose::stringify(species));
254 }
255 else
256 for (const auto i : index_range(species))
257 {
258 _tokenized_species.resize(species.size());
259 std::vector<std::string> tokens;
260 MooseUtils::tokenize(species[i], tokens, 1, ":");
261 if (tokens.size() == 1)
262 paramError("output_species", "No ':' separator found in variable '", species[i], "'");
263
264 auto phase_index = std::find(db_phases.begin(), db_phases.end(), tokens[0]);
265 if (phase_index == db_phases.end())
266 paramError("output_species",
267 "Phase '",
268 tokens[0],
269 "' of output species '",
270 species[i],
271 "' not found in the simulation.");
272 auto sp = db_species[std::distance(db_phases.begin(), phase_index)];
273 if (std::find(sp.begin(), sp.end(), tokens[1]) == sp.end())
275 "output_species", "Species '", tokens[1], "' was not found in the simulation.");
276 _tokenized_species[i] = std::make_pair(tokens[0], tokens[1]);
277 }
278 }
279
280 if (isParamValid("output_element_potentials"))
281 {
282 auto element_potentials = getParam<std::vector<std::string>>("output_element_potentials");
283 if (element_potentials.size() == 1 && element_potentials[0] == "ALL")
284 {
287 element_potentials.resize(_elements.size());
288 for (const auto i : index_range(_elements))
289 element_potentials[i] = "mu:" + _elements[i];
290 mooseInfo(
291 "ChemicalCompositionAction element potentials: 'ALL' specified in input file. Using: ",
292 Moose::stringify(element_potentials));
293 }
294 else
295 {
296 _tokenized_element_potentials.resize(element_potentials.size());
297 for (const auto i : index_range(element_potentials))
298 {
299 std::vector<std::string> tokens;
300 MooseUtils::tokenize(element_potentials[i], tokens, 1, ":");
301 if (tokens.size() == 1)
302 paramError("output_element_potentials",
303 "No ':' separator found in variable '",
304 element_potentials[i],
305 "'");
306 if (std::find(_elements.begin(), _elements.end(), tokens[1]) == _elements.end())
307 paramError("output_element_potentials",
308 "Element '",
309 tokens[1],
310 "' was not found in the simulation.");
311 _tokenized_element_potentials[i] = tokens[1];
312 }
313 }
314 }
315
316 if (isParamValid("output_vapor_pressures"))
317 {
318 auto vapor_pressures = getParam<std::vector<std::string>>("output_vapor_pressures");
319 if (!Thermochimica::isPhaseGas(0))
320 paramError("output_vapor_pressures",
321 "No gas phase found in the simulation. Cannot output vapor pressures.");
322 if (vapor_pressures.size() == 1 && vapor_pressures[0] == "ALL")
323 {
324 vapor_pressures.resize(Thermochimica::getNumberSpeciesSystem()[0]);
325 _tokenized_vapor_species.resize(Thermochimica::getNumberSpeciesSystem()[0]);
326 auto db_gas_species = Thermochimica::getSpeciesInPhase(0);
327 auto gas_name = Thermochimica::getPhaseNamesSystem()[0];
328 for (const auto i : index_range(db_gas_species))
329 {
330 vapor_pressures[i] = "vp:" + gas_name + ':' + db_gas_species[i];
331 _tokenized_vapor_species[i] = std::make_pair(gas_name, db_gas_species[i]);
332 }
333 mooseInfo("ChemicalCompositionAction vapor pressures: 'ALL' specified in input file. Using: ",
334 Moose::stringify(vapor_pressures));
335 }
336 else
337 {
338 auto db_gas_species = Thermochimica::getSpeciesInPhase(0);
339 _tokenized_vapor_species.resize(vapor_pressures.size());
340 for (const auto i : index_range(vapor_pressures))
341 {
342 std::vector<std::string> tokens;
343 MooseUtils::tokenize(vapor_pressures[i], tokens, 1, ":");
344 if (tokens.size() == 1)
345 paramError("output_vapor_pressures",
346 "No ':' separator found in variable '",
347 vapor_pressures[i],
348 "'");
349 if (tokens[1] != Thermochimica::getPhaseNamesSystem()[0])
350 paramError("output_vapor_pressures",
351 "Phase '",
352 tokens[1],
353 "' of vapor species '",
354 vapor_pressures[i],
355 "' is not a gas phase. Cannot calculate vapor pressure.");
356 if (std::find(db_gas_species.begin(), db_gas_species.end(), tokens[2]) ==
357 db_gas_species.end())
358 paramError("output_vapor_pressures",
359 "Species '",
360 tokens[2],
361 "' was not found in the gas phase of simulation.");
362 _tokenized_vapor_species[i] = std::make_pair(tokens[1], tokens[2]);
363 }
364 }
365 }
366
367 if (isParamValid("output_element_phases"))
368 {
369 auto element_phases = getParam<std::vector<std::string>>("output_element_phases");
370 auto db_phases = Thermochimica::getPhaseNamesSystem();
371 if (element_phases.size() == 1 && element_phases[0] == "ALL")
372 {
373 element_phases.resize(_elements.size() * db_phases.size());
374 _tokenized_phase_elements.resize(_elements.size() * db_phases.size());
375 for (const auto i : index_range(db_phases))
376 for (const auto j : index_range(_elements))
377 {
378 element_phases[i * _elements.size() + j] = db_phases[i] + ':' + _elements[j];
379 _tokenized_phase_elements[i * _elements.size() + j] =
380 std::make_pair(db_phases[i], _elements[j]);
381 }
382 mooseInfo(
383 "ChemicalCompositionAction elements in phase: 'ALL' specified in input file. Using: ",
384 Moose::stringify(element_phases));
385 }
386 else
387 {
388 _tokenized_phase_elements.resize(element_phases.size());
389 for (const auto i : index_range(element_phases))
390 {
391 std::vector<std::string> tokens;
392 MooseUtils::tokenize(element_phases[i], tokens, 1, ":");
393 if (tokens.size() == 1)
394 paramError("output_element_phases",
395 "No ':' separator found in variable '",
396 element_phases[i],
397 "'");
398 if (std::find(db_phases.begin(), db_phases.end(), tokens[1]) == db_phases.end())
399 paramError("output_element_phases",
400 "Phase '",
401 tokens[1],
402 "' of '",
403 element_phases[i],
404 "' not found in the simulation.");
405 if (std::find(_elements.begin(), _elements.end(), tokens[2]) == _elements.end())
406 paramError("output_element_phases",
407 "Element '",
408 tokens[2],
409 "' was not found in the simulation.");
410 _tokenized_phase_elements[i] = std::make_pair(tokens[1], tokens[2]);
411 }
412 }
413 }
414
415 Thermochimica::resetThermoAll();
416
417#endif
418}
for(PetscInt i=0;i< nvars;++i)
std::vector< const T * > getActions()
MooseObjectName uniqueActionName() const
MooseApp & _app
ActionWarehouse & _awh
std::vector< unsigned int > _element_ids
Atomic numbers of the selected elements.
std::vector< std::string > _tokenized_element_potentials
std::vector< std::pair< std::string, std::string > > _tokenized_phase_elements
std::vector< std::pair< std::string, std::string > > _tokenized_species
Tokenized versions of the output variables to avoid redoing tokenization.
std::vector< std::string > _phases
List of phases tracked by Thermochimica.
std::vector< std::string > _elements
Element names.
std::vector< std::pair< std::string, std::string > > _tokenized_vapor_species
Store common ChemicalComposition action parameters.
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
InputParameterWarehouse & getInputParameterWarehouse()
const InputParameters & parameters() const
void paramError(const std::string &param, Args... args) const
void mooseInfo(Args &&... args) const
bool isParamValid(const std::string &name) const
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
std::string stringify(const T &t)
void checkLibraryAvailability(MooseObject &self)
Check if thermochimica is available and throw an error if it is not.
auto index_range(const T &sizable)
if(subdm)
IntRange< T > make_range(T beg, T end)

Member Function Documentation

◆ act()

void ChemicalCompositionAction::act ( )
virtual

Implements Action.

Definition at line 421 of file ChemicalCompositionAction.C.

422{
423#ifdef THERMOCHIMICA_ENABLED
424 //
425 // Add AuxVariables
426 //
427 if (_current_task == "add_aux_variable")
428 {
429 auto aux_var_type = AddVariableAction::variableType(
430 FEType(Utility::string_to_enum<Order>(_problem->mesh().hasSecondOrderElements() ? "SECOND"
431 : "FIRST"),
432 Utility::string_to_enum<libMesh::FEFamily>("LAGRANGE")),
433 /* is_fv = */ getParam<bool>("is_fv"),
434 /* is_array = */ false);
435 auto params = _factory.getValidParams(aux_var_type);
436 params.applySpecificParameters(parameters(), {"block"});
437
438 for (const auto i : index_range(_elements))
439 _problem->addAuxVariable(aux_var_type, _elements[i], params);
440
441 for (const auto i : index_range(_phases))
442 _problem->addAuxVariable(aux_var_type, _phases[i], params);
443
444 for (const auto i : index_range(_tokenized_species))
445 _problem->addAuxVariable(
446 aux_var_type, Moose::stringify(_tokenized_species[i], /* delim = */ ":"), params);
447
448 for (const auto i : index_range(_tokenized_element_potentials))
449 _problem->addAuxVariable(aux_var_type, "mu:" + _tokenized_element_potentials[i], params);
450
451 for (const auto i : index_range(_tokenized_vapor_species))
452 _problem->addAuxVariable(aux_var_type,
453 "vp:" +
454 Moose::stringify(_tokenized_vapor_species[i], /* delim = */ ":"),
455 params);
456
457 for (const auto i : index_range(_tokenized_phase_elements))
458 _problem->addAuxVariable(
459 aux_var_type,
460 "ep:" + Moose::stringify(_tokenized_phase_elements[i], /* delim = */ ":"),
461 params);
462 }
463
464 //
465 // Set up initial conditions from a file
466 //
467 if (_current_task == "add_ic" && isParamValid("initial_values"))
468 {
469 readCSV();
470 for (auto it : _initial_conditions)
471 {
472 const std::string class_name = "ConstantIC";
473 auto params = _factory.getValidParams(class_name);
474 params.set<VariableName>("variable") = it.first;
475 params.set<Real>("value") = it.second;
476 params.applySpecificParameters(parameters(), {"block"});
477 _problem->addInitialCondition(class_name, it.first + "_ic", params);
478 }
479 }
480
481 //
482 // Set up user object
483 //
484 if (_current_task == "add_user_object")
485 {
486 std::string uo_name = getParam<std::string>("uo_name");
487
488 if (isParamValid("block") && !isParamSetByUser("uo_name"))
489 uo_name += "_" + Moose::stringify(getParam<std::vector<SubdomainName>>("block"));
490
491 const auto uo_type =
492 getParam<bool>("is_fv") ? "ThermochimicaElementData" : "ThermochimicaNodalData";
493
494 auto uo_params = _factory.getValidParams(uo_type);
495
496 std::copy(_elements.begin(),
497 _elements.end(),
498 std::back_inserter(uo_params.set<std::vector<VariableName>>("elements")));
499
500 if (isParamValid("output_phases"))
501 std::copy(_phases.begin(),
502 _phases.end(),
503 std::back_inserter(uo_params.set<std::vector<VariableName>>("output_phases")));
504
505 if (isParamValid("output_species"))
506 {
507 std::vector<std::string> species;
508 for (auto token : _tokenized_species)
509 species.push_back(Moose::stringify(token, ":"));
510 uo_params.set<std::vector<VariableName>>("output_species")
511 .insert(uo_params.set<std::vector<VariableName>>("output_species").end(),
512 species.begin(),
513 species.end());
514 }
515
516 if (isParamValid("output_element_potentials"))
517 {
518 std::vector<std::string> element_potentials;
520 element_potentials.push_back("mu:" + token);
521 uo_params.set<std::vector<VariableName>>("output_element_potentials")
522 .insert(uo_params.set<std::vector<VariableName>>("output_element_potentials").end(),
523 element_potentials.begin(),
524 element_potentials.end());
525 }
526
527 if (isParamValid("output_vapor_pressures"))
528 {
529 std::vector<std::string> vapor_pressures;
531 vapor_pressures.push_back("vp:" + Moose::stringify(token, ":"));
532 uo_params.set<std::vector<VariableName>>("output_vapor_pressures")
533 .insert(uo_params.set<std::vector<VariableName>>("output_vapor_pressures").end(),
534 vapor_pressures.begin(),
535 vapor_pressures.end());
536 }
537
538 if (isParamValid("output_element_phases"))
539 {
540 std::vector<std::string> element_phases;
542 element_phases.push_back("ep:" + Moose::stringify(token, ":"));
543 uo_params.set<std::vector<VariableName>>("output_element_phases")
544 .insert(uo_params.set<std::vector<VariableName>>("output_element_phases").end(),
545 element_phases.begin(),
546 element_phases.end());
547 }
548 uo_params.set<std::vector<VariableName>>("temperature") =
549 getParam<std::vector<VariableName>>("temperature");
550
551 uo_params.set<ChemicalCompositionAction *>("_chemical_composition_action") = this;
552
553 uo_params.set<FileName>("thermofile") = getParam<FileName>("thermofile");
554
555 uo_params.set<MooseEnum>("reinit_type") = getParam<MooseEnum>("reinitialization_type");
556
557 uo_params.set<MooseEnum>("output_species_unit") = getParam<MooseEnum>("output_species_unit");
558
559 uo_params.applyParameters(parameters());
560
561 _problem->addUserObject(uo_type, uo_name, uo_params);
562 }
563
564#endif
565}
std::shared_ptr< FEProblemBase > & _problem
const std::string & _current_task
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
The ChemicalCompositionAction sets up user objects, aux kernels, and aux variables for a thermochemis...
std::map< std::string, Real > _initial_conditions
Initial conditions for each element: [element name] => initial condition value.
InputParameters getValidParams(const std::string &name) const
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
T & set(const std::string &name, bool quiet_mode=false)
bool isParamSetByUser(const std::string &name) const
const T & getParam(const std::string &name) const
Factory & _factory
T string_to_enum(const std::string &s)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ elementIDs()

const std::vector< unsigned int > & ChemicalCompositionAction::elementIDs ( ) const
inline

Definition at line 25 of file ChemicalCompositionAction.h.

25{ return _element_ids; }

◆ elementPotentials()

const std::vector< std::string > & ChemicalCompositionAction::elementPotentials ( ) const
inline

Definition at line 28 of file ChemicalCompositionAction.h.

29 {
31 }

◆ phaseElementPairs()

const std::vector< std::pair< std::string, std::string > > & ChemicalCompositionAction::phaseElementPairs ( ) const
inline

Definition at line 43 of file ChemicalCompositionAction.h.

44 {
46 }

◆ phases()

const std::vector< std::string > & ChemicalCompositionAction::phases ( ) const
inline

Definition at line 27 of file ChemicalCompositionAction.h.

27{ return _phases; }

◆ readCSV()

void ChemicalCompositionAction::readCSV ( )
protected

Definition at line 568 of file ChemicalCompositionAction.C.

569{
570 const auto & filename = getParam<FileName>("initial_values");
571 std::ifstream file(filename.c_str());
572 if (!file.good())
573 paramError("initial_values", "Error opening file '", filename, "'.");
574
575 std::string line;
576 std::vector<std::string> items;
577
578 // skip header
579 std::getline(file, line);
580 while (std::getline(file, line))
581 {
582 MooseUtils::tokenize(line, items, 1, ",");
583 if (items.empty())
584 continue;
585 if (items.size() != 2)
586 paramError("initial_value", "Unexpected line in CSV file: ", line);
587
588 _initial_conditions[items[0]] = MooseUtils::convert<Real>(items[1]);
589 }
590}

Referenced by act().

◆ speciesPhasePairs()

const std::vector< std::pair< std::string, std::string > > & ChemicalCompositionAction::speciesPhasePairs ( ) const
inline

Definition at line 33 of file ChemicalCompositionAction.h.

34 {
35 return _tokenized_species;
36 }

◆ validParams()

InputParameters ChemicalCompositionAction::validParams ( )
static

Definition at line 32 of file ChemicalCompositionAction.C.

33{
36
38 "Sets up the thermodynamic model and variables for the "
39 "thermochemistry solve using Thermochimica.");
40
41 // Required variables
42 params.addParam<std::vector<std::string>>(
43 "elements", {"ALL"}, "List of chemical elements (or ALL)");
44 params.addCoupledVar("temperature", "Name of temperature variable");
45 params.addCoupledVar("pressure", "Name of pressure variable");
46 MooseEnum reinit_type("none time nodal", "nodal");
47 params.addParam<MooseEnum>(
48 "reinitialization_type", reinit_type, "Reinitialization scheme to use with Thermochimica");
49 params.addParam<FileName>("initial_values", "The CSV file name with initial conditions.");
50 params.addParam<FileName>("thermofile", "Thermodynamics model file");
51
52 MooseEnum tUnit("K C F R");
53 params.addParam<MooseEnum>("tunit", tUnit, "Temperature Unit");
54 MooseEnum pUnit("atm psi bar Pa kPa");
55 params.addParam<MooseEnum>("punit", pUnit, "Pressure Unit");
56 MooseEnum mUnit(
57 "mole_fraction atom_fraction atoms moles gram-atoms mass_fraction kilograms grams pounds");
58 params.addParam<MooseEnum>("munit", mUnit, "Mass Unit");
60 exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END};
61 params.addParam<ExecFlagEnum>(
62 "execute_on", exec_enum, "When to execute the ThermochimicaData UO");
63 params.addParam<bool>("is_fv", false, "Should the variables set up by action be of FV type");
64
65 params.addParam<std::vector<std::string>>("output_phases", {}, "List of phases to be output");
66 params.addParam<std::vector<std::string>>(
67 "output_species", {}, "List species for which concentration in the phases is needed");
68 MooseEnum mUnit_op("moles mole_fraction");
69 params.addParam<MooseEnum>(
70 "output_species_unit", mUnit_op, "Mass unit for output species: mole_fractions or moles");
71 params.addParam<std::vector<std::string>>(
72 "output_element_potentials",
73 {},
74 "List of chemical elements for which chemical potentials are requested");
75 params.addParam<std::vector<std::string>>(
76 "output_vapor_pressures",
77 {},
78 "List of gas phase species for which vapor pressures are requested");
79 params.addParam<std::vector<std::string>>(
80 "output_element_phases",
81 {},
82 "List of elements whose molar amounts in specific phases are requested");
83 params.addParam<std::string>(
84 "uo_name", "Thermochimica", "Name of the ThermochimicaDataUserObject.");
85 return params;
86}
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_INITIAL
static InputParameters validParams()
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
ExecFlagEnum getDefaultExecFlagEnum()
void addClassDescription(InputParameters &params, const std::string &desc)
Add the supplied class description if thermochimica is available, otherwise add a warning message.

Referenced by CommonChemicalCompositionAction::validParams().

◆ vaporPhasePairs()

const std::vector< std::pair< std::string, std::string > > & ChemicalCompositionAction::vaporPhasePairs ( ) const
inline

Definition at line 38 of file ChemicalCompositionAction.h.

39 {
41 }

Member Data Documentation

◆ _element_ids

std::vector<unsigned int> ChemicalCompositionAction::_element_ids
protected

Atomic numbers of the selected elements.

Definition at line 63 of file ChemicalCompositionAction.h.

Referenced by ChemicalCompositionAction(), and elementIDs().

◆ _elements

std::vector<std::string> ChemicalCompositionAction::_elements
protected

Element names.

Definition at line 54 of file ChemicalCompositionAction.h.

Referenced by act(), and ChemicalCompositionAction().

◆ _initial_conditions

std::map<std::string, Real> ChemicalCompositionAction::_initial_conditions
protected

Initial conditions for each element: [element name] => initial condition value.

Definition at line 57 of file ChemicalCompositionAction.h.

Referenced by act(), and readCSV().

◆ _phases

std::vector<std::string> ChemicalCompositionAction::_phases
protected

List of phases tracked by Thermochimica.

Definition at line 60 of file ChemicalCompositionAction.h.

Referenced by act(), ChemicalCompositionAction(), and phases().

◆ _tokenized_element_potentials

std::vector<std::string> ChemicalCompositionAction::_tokenized_element_potentials
protected

Definition at line 67 of file ChemicalCompositionAction.h.

Referenced by act(), ChemicalCompositionAction(), and elementPotentials().

◆ _tokenized_phase_elements

std::vector<std::pair<std::string, std::string> > ChemicalCompositionAction::_tokenized_phase_elements
protected

Definition at line 69 of file ChemicalCompositionAction.h.

Referenced by act(), ChemicalCompositionAction(), and phaseElementPairs().

◆ _tokenized_species

std::vector<std::pair<std::string, std::string> > ChemicalCompositionAction::_tokenized_species
protected

Tokenized versions of the output variables to avoid redoing tokenization.

Definition at line 66 of file ChemicalCompositionAction.h.

Referenced by act(), ChemicalCompositionAction(), and speciesPhasePairs().

◆ _tokenized_vapor_species

std::vector<std::pair<std::string, std::string> > ChemicalCompositionAction::_tokenized_vapor_species
protected

Definition at line 68 of file ChemicalCompositionAction.h.

Referenced by act(), ChemicalCompositionAction(), and vaporPhasePairs().


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