https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Simulation.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
13#include "FlowModel.h"
14#include "Logger.h"
15#include "ControlData.h"
16#include "LoggingInterface.h"
17#include "NamingInterface.h"
18#include "libmesh/parallel_object.h"
19
20class ActionWarehouse;
21class Component;
22class ClosuresBase;
23class MooseMesh;
24class THMProblem;
25
30{
31public:
40 static void setComponentVariableOrder(const VariableName & var, int index);
41
42 Simulation(FEProblemBase & fe_problem, const InputParameters & params);
43 virtual ~Simulation();
44
48 const libMesh::FEType & getFlowFEType() const { return _flow_fe_type; }
49
53 virtual void setupQuadrature();
54
58 virtual void initSimulation();
59
63 virtual void initComponents();
64
68 void identifyLoops();
69
73 void printComponentLoops() const;
74
78 virtual void run();
79
86 virtual void
87 addComponent(const std::string & type, const std::string & name, InputParameters params);
88
94 bool hasComponent(const std::string & name) const;
95
102 template <typename T>
103 bool hasComponentOfType(const std::string & name) const;
104
111 template <typename T>
112 const T & getComponentByName(const std::string & name) const;
113
117 const std::vector<std::shared_ptr<Component>> & getComponents() const { return _components; }
118
126 virtual void
127 addClosures(const std::string & type, const std::string & name, InputParameters params);
128
134 bool hasClosures(const std::string & name) const;
135
141 std::shared_ptr<ClosuresBase> getClosures(const std::string & name) const;
142
153 void addSimVariable(bool nl,
154 const VariableName & name,
155 libMesh::FEType fe_type,
156 Real scaling_factor = 1.0,
157 const SolverSystemName & solver_sys = "nl0");
158
170 void addSimVariable(bool nl,
171 const VariableName & name,
172 libMesh::FEType fe_type,
173 const std::vector<SubdomainName> & subdomain_names,
174 Real scaling_factor = 1.0,
175 const SolverSystemName & solver_sys = "nl0");
176
185 void addSimVariable(bool nl,
186 const std::string & var_type,
187 const VariableName & name,
188 const InputParameters & params);
189
193 void checkVariableNameLength(const std::string & name) const;
194
195 void addConstantIC(const VariableName & var_name,
196 Real value,
197 const std::vector<SubdomainName> & block_names);
198 void addFunctionIC(const VariableName & var_name,
199 const std::string & func_name,
200 const std::vector<SubdomainName> & block_names);
201 void addConstantScalarIC(const VariableName & var_name, Real value);
202 void addComponentScalarIC(const VariableName & var_name, const std::vector<Real> & value);
203
204 void addSimInitialCondition(const std::string & type,
205 const std::string & name,
206 InputParameters params);
207
214 void addControl(const std::string & type, const std::string & name, InputParameters params);
215
216 void addFileOutputter(const std::string & name);
217 void addScreenOutputter(const std::string & name);
218
225 std::vector<OutputName> getOutputsVector(const std::string & key) const;
226
230 virtual void buildMesh();
231
235 virtual void addVariables();
236
240 virtual void addMooseObjects();
241
246 virtual void setupMesh();
247
251 virtual void integrityCheck() const;
252
257 virtual void advanceState();
258
262 virtual void controlDataIntegrityCheck();
263
267 virtual void couplingMatrixIntegrityCheck() const;
268
275 template <typename T>
276 bool hasControlData(const std::string & name)
277 {
278 if (_control_data.find(name) == _control_data.end())
279 return false;
280 else
281 return dynamic_cast<ControlData<T> *>(_control_data[name]) != NULL;
282 }
283
290 template <typename T>
291 ControlData<T> * getControlData(const std::string & name)
292 {
293 ControlData<T> * data = nullptr;
294 if (_control_data.find(name) == _control_data.end())
295 {
296 data = new ControlData<T>(_thm_app, name);
297 _control_data[name] = data;
298 }
299 else
300 data = dynamic_cast<ControlData<T> *>(_control_data[name]);
301
302 return data;
303 }
304
311 template <typename T>
312 ControlData<T> * declareControlData(const std::string & name, THMControl * ctrl)
313 {
314 ControlData<T> * data = getControlData<T>(name);
315 if (!data->getDeclared())
316 {
317 // Mark the data for error checking
318 data->setDeclared();
319 data->setControl(ctrl);
320 }
321 else
322 logError("Trying to declare '", name, "', but it was already declared.");
323
324 return data;
325 }
326
331
337 bool hasInitialConditionsFromFile() const;
338
339 Logger & log() { return _log; }
340
346 void setCheckJacobian(bool state) { _check_jacobian = state; }
347
353 virtual void augmentSparsity(const dof_id_type & elem_id1, const dof_id_type & elem_id2);
354
361
365 void setVectorValuedVelocity(bool vector_velocity) { _output_vector_velocity = vector_velocity; }
366
371
372protected:
387
390
393
396
399
401 std::vector<std::shared_ptr<Component>> _components;
403 std::map<std::string, std::shared_ptr<Component>> _comp_by_name;
405 std::map<std::string, std::string> _component_name_to_loop_name;
407 std::map<std::string, THM::FlowModelID> _loop_name_to_model_id;
408
410 std::map<std::string, std::shared_ptr<ClosuresBase>> _closures_by_name;
411
413 std::map<VariableName, VariableInfo> _vars;
414
415 struct ICInfo
416 {
417 std::string _type;
419
421 ICInfo(const std::string & type, const InputParameters & params) : _type(type), _params(params)
422 {
423 }
424 };
425 std::map<std::string, ICInfo> _ics;
426
429
432
437
443
445
450
455
456 std::vector<OutputName> _outputters_all;
457 std::vector<OutputName> _outputters_file;
458 std::vector<OutputName> _outputters_screen;
459
461 std::map<std::string, ControlDataValue *> _control_data;
462
465
467
470
472 std::map<dof_id_type, std::vector<dof_id_type>> _sparsity_elem_augmentation;
473
476
477public:
478 Real _zero;
479
480private:
486 std::vector<VariableName> sortAddedComponentVariables() const;
487
489 static std::map<VariableName, int> _component_variable_order_map;
490};
491
492template <typename T>
493bool
494Simulation::hasComponentOfType(const std::string & name) const
495{
496 auto it = _comp_by_name.find(name);
497 if (it != _comp_by_name.end())
498 return dynamic_cast<T *>((it->second).get()) != nullptr;
499 else
500 return false;
501}
502
503template <typename T>
504const T &
505Simulation::getComponentByName(const std::string & name) const
506{
507 auto it = _comp_by_name.find(name);
508 if (it != _comp_by_name.end())
509 return *dynamic_cast<T *>((it->second).get());
510 else
511 mooseError("Component '",
512 name,
513 "' does not exist in the simulation. Use hasComponent or "
514 "checkComponnetByName before calling getComponent.");
515}
const double T
InputParameters emptyInputParameters()
void mooseError(Args &&... args)
const std::string name
Definition Setup.h:21
Base class for closures implementations.
Base class for THM components.
Definition Component.h:32
bool getDeclared()
Get the declared state.
Definition ControlData.h:70
void setControl(THMControl *ctrl)
Set the pointer to the control object that declared this control data.
Definition ControlData.h:60
void setDeclared()
Mark the data as declared.
Definition ControlData.h:65
Concrete definition of a parameter value for a specified type.
Definition ControlData.h:92
Keeps the error and warning messages.
Definition Logger.h:18
Interface class for logging errors and warnings.
void logError(Args &&... args) const
Logs an error.
Interface for handling names.
Main class for simulation (the driver of the simulation)
Definition Simulation.h:30
void printComponentLoops() const
Prints the component loops.
Definition Simulation.C:245
void addComponentScalarIC(const VariableName &var_name, const std::vector< Real > &value)
Definition Simulation.C:574
void addControl(const std::string &type, const std::string &name, InputParameters params)
Add a control.
Definition Simulation.C:496
std::map< std::string, std::shared_ptr< Component > > _comp_by_name
Map of components by their names.
Definition Simulation.h:403
void setupCriticalHeatFluxTable()
Setup ctirical heat flux table user object.
void setVectorValuedVelocity(bool vector_velocity)
Set if velocity is being output as a vector-valued field.
Definition Simulation.h:365
const T & getComponentByName(const std::string &name) const
Get component by its name.
Definition Simulation.h:505
bool hasComponentOfType(const std::string &name) const
Find out if simulation has a component with the given name and specified type.
Definition Simulation.h:494
bool hasInitialConditionsFromFile() const
Are initial conditions specified from a file.
bool _output_vector_velocity
Flag indicating if velocity is output as vector-valued field.
Definition Simulation.h:475
std::map< VariableName, VariableInfo > _vars
variables for this simulation (name and info about the var)
Definition Simulation.h:413
std::map< std::string, ControlDataValue * > _control_data
Control data created in the control logic system.
Definition Simulation.h:461
void addConstantScalarIC(const VariableName &var_name, Real value)
Definition Simulation.C:561
const std::vector< std::shared_ptr< Component > > & getComponents() const
Return list of components available in the simulation.
Definition Simulation.h:117
MooseMesh & _thm_mesh
THM mesh.
Definition Simulation.h:389
FEProblemBase & _fe_problem
Pointer to FEProblem representing this simulation.
Definition Simulation.h:392
static std::map< VariableName, int > _component_variable_order_map
Component variable order map; see setComponentVariableOrder for more info.
Definition Simulation.h:489
libMesh::FEType _flow_fe_type
finite element type for the flow in the simulation
Definition Simulation.h:431
std::vector< OutputName > _outputters_file
Definition Simulation.h:457
void addConstantIC(const VariableName &var_name, Real value, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:521
virtual void integrityCheck() const
Check the integrity of the simulation.
Definition Simulation.C:871
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep.
virtual void addVariables()
Add variables involved in this simulation.
Definition Simulation.C:643
virtual void augmentSparsity(const dof_id_type &elem_id1, const dof_id_type &elem_id2)
Hint how to augment sparsity pattern between two elements.
Definition Simulation.C:68
const InputParameters & _thm_pars
"Global" of this simulation
Definition Simulation.h:428
void addFunctionIC(const VariableName &var_name, const std::string &func_name, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:541
virtual void initComponents()
Initialize this simulation's components.
Definition Simulation.C:148
ControlData< T > * declareControlData(const std::string &name, THMControl *ctrl)
Declare control data of type T and name 'name', if it does not exist it will be created.
Definition Simulation.h:312
std::vector< OutputName > _outputters_all
Definition Simulation.h:456
void setupEquations()
Setup equations to be solved in this simulation.
std::map< std::string, std::string > _component_name_to_loop_name
Map of component name to component loop name.
Definition Simulation.h:405
virtual void couplingMatrixIntegrityCheck() const
Check integrity of coupling matrix used by the preconditioner.
Definition Simulation.C:832
virtual void addClosures(const std::string &type, const std::string &name, InputParameters params)
Add a closures object into this simulation.
void setCheckJacobian(bool state)
Enable Jacobian checking.
Definition Simulation.h:346
const bool & getImplicitTimeIntegrationFlag()
Gets the flag indicating whether an implicit time integration scheme is being used.
Definition Simulation.h:330
void addRelationshipManagers()
Add additional relationship managers to run the simulation.
Definition Simulation.C:770
virtual void setupMesh()
Perform mesh setup actions such as setting up the coordinate system(s) and creating ghosted elements.
Definition Simulation.C:823
std::vector< OutputName > _outputters_screen
Definition Simulation.h:458
void checkVariableNameLength(const std::string &name) const
Reports an error if the variable name is too long.
Definition Simulation.C:488
bool hasControlData(const std::string &name)
Query if control data with name 'name' exists.
Definition Simulation.h:276
const libMesh::FEType & getFlowFEType() const
Gets the FE type for the flow in this simulation.
Definition Simulation.h:48
bool hasComponent(const std::string &name) const
Find out if simulation has a component with the given name.
virtual ~Simulation()
Definition Simulation.C:61
virtual void controlDataIntegrityCheck()
Check the integrity of the control data.
Definition Simulation.C:936
std::map< std::string, ICInfo > _ics
Definition Simulation.h:425
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name 'name', if it does not exist it will be created.
Definition Simulation.h:291
std::shared_ptr< ClosuresBase > getClosures(const std::string &name) const
Get a pointer to a closures object.
Logger & log()
Definition Simulation.h:339
void identifyLoops()
Identifies the component loops.
Definition Simulation.C:161
virtual void initSimulation()
Initialize this simulation.
Definition Simulation.C:132
void addSimVariable(bool nl, const VariableName &name, libMesh::FEType fe_type, const std::vector< SubdomainName > &subdomain_names, Real scaling_factor=1.0, const SolverSystemName &solver_sys="nl0")
Queues a variable of type MooseVariable to be added to the nonlinear or aux system.
static void setComponentVariableOrder(const VariableName &var, int index)
Sets a component variable order index.
Definition Simulation.C:37
virtual void addComponent(const std::string &type, const std::string &name, InputParameters params)
Add a component into this simulation.
bool hasClosures(const std::string &name) const
Return whether the simulation has a closures object.
std::map< std::string, std::shared_ptr< ClosuresBase > > _closures_by_name
Map of closures by their names.
Definition Simulation.h:410
virtual void addMooseObjects()
Add component MOOSE objects.
Definition Simulation.C:763
bool _implicit_time_integration
true if using implicit time integration scheme
Definition Simulation.h:464
virtual void buildMesh()
Create mesh for this simulation.
Definition Simulation.C:84
MooseApp & _thm_app
The application this is associated with.
Definition Simulation.h:395
virtual void setupQuadrature()
Sets up quadrature rules.
Definition Simulation.C:95
Factory & _thm_factory
The Factory associated with the MooseApp.
Definition Simulation.h:398
std::vector< std::shared_ptr< Component > > _components
List of components in this simulation.
Definition Simulation.h:401
std::vector< VariableName > sortAddedComponentVariables() const
Returns a sorted list of the variables added by components.
Definition Simulation.C:587
void setupInitialConditionObjects()
Definition Simulation.C:752
void addFileOutputter(const std::string &name)
bool getVectorValuedVelocity()
Is velocity output as vector-valued field.
Definition Simulation.h:360
std::vector< OutputName > getOutputsVector(const std::string &key) const
Gets the vector of output names corresponding to a 1-word key string.
void setupCoordinateSystem()
Sets the coordinate system for each subdomain.
Definition Simulation.C:795
virtual void run()
Run the simulation.
Logger _log
Definition Simulation.h:466
void setupInitialConditionsFromFile()
Setup reading initial conditions from a specified file, see 'initial_from_file', 'initial_from_file_t...
Definition Simulation.C:695
std::map< std::string, THM::FlowModelID > _loop_name_to_model_id
Map of loop name to model type.
Definition Simulation.h:407
bool _check_jacobian
True if checking jacobian.
Definition Simulation.h:469
void addSimInitialCondition(const std::string &type, const std::string &name, InputParameters params)
Definition Simulation.C:504
std::map< dof_id_type, std::vector< dof_id_type > > _sparsity_elem_augmentation
Additional sparsity pattern that needs to be added into the Jacobian matrix.
Definition Simulation.h:472
void addScreenOutputter(const std::string &name)
void addSimVariable(bool nl, const VariableName &name, libMesh::FEType fe_type, Real scaling_factor=1.0, const SolverSystemName &solver_sys="nl0")
Queues a variable of type MooseVariableScalar to be added to the nonlinear or aux system.
Specialization of FEProblem to run with component subsystem.
Definition THMProblem.h:19
InputParameters _params
Definition Simulation.h:418
ICInfo(const std::string &type, const InputParameters &params)
Definition Simulation.h:421
std::string _type
Definition Simulation.h:417
Variable information.
Definition Simulation.h:377
bool _nl
True if the variable is a nonlinear (solution) variable; otherwise, aux.
Definition Simulation.h:379
InputParameters _params
Input parameters.
Definition Simulation.h:383
std::string _var_type
Type (class) of the variable.
Definition Simulation.h:381