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
151 void addSimVariable(bool nl,
152 const VariableName & name,
153 libMesh::FEType fe_type,
154 Real scaling_factor = 1.0);
155
165 void addSimVariable(bool nl,
166 const VariableName & name,
167 libMesh::FEType fe_type,
168 const std::vector<SubdomainName> & subdomain_names,
169 Real scaling_factor = 1.0);
170
179 void addSimVariable(bool nl,
180 const std::string & var_type,
181 const VariableName & name,
182 const InputParameters & params);
183
187 void checkVariableNameLength(const std::string & name) const;
188
189 void addConstantIC(const VariableName & var_name,
190 Real value,
191 const std::vector<SubdomainName> & block_names);
192 void addFunctionIC(const VariableName & var_name,
193 const std::string & func_name,
194 const std::vector<SubdomainName> & block_names);
195 void addConstantScalarIC(const VariableName & var_name, Real value);
196 void addComponentScalarIC(const VariableName & var_name, const std::vector<Real> & value);
197
198 void addSimInitialCondition(const std::string & type,
199 const std::string & name,
200 InputParameters params);
201
208 void addControl(const std::string & type, const std::string & name, InputParameters params);
209
210 void addFileOutputter(const std::string & name);
211 void addScreenOutputter(const std::string & name);
212
219 std::vector<OutputName> getOutputsVector(const std::string & key) const;
220
224 virtual void buildMesh();
225
229 virtual void addVariables();
230
234 virtual void addMooseObjects();
235
240 virtual void setupMesh();
241
245 virtual void integrityCheck() const;
246
251 virtual void advanceState();
252
256 virtual void controlDataIntegrityCheck();
257
261 virtual void couplingMatrixIntegrityCheck() const;
262
269 template <typename T>
270 bool hasControlData(const std::string & name)
271 {
272 if (_control_data.find(name) == _control_data.end())
273 return false;
274 else
275 return dynamic_cast<ControlData<T> *>(_control_data[name]) != NULL;
276 }
277
284 template <typename T>
285 ControlData<T> * getControlData(const std::string & name)
286 {
287 ControlData<T> * data = nullptr;
288 if (_control_data.find(name) == _control_data.end())
289 {
290 data = new ControlData<T>(_thm_app, name);
291 _control_data[name] = data;
292 }
293 else
294 data = dynamic_cast<ControlData<T> *>(_control_data[name]);
295
296 return data;
297 }
298
305 template <typename T>
306 ControlData<T> * declareControlData(const std::string & name, THMControl * ctrl)
307 {
308 ControlData<T> * data = getControlData<T>(name);
309 if (!data->getDeclared())
310 {
311 // Mark the data for error checking
312 data->setDeclared();
313 data->setControl(ctrl);
314 }
315 else
316 logError("Trying to declare '", name, "', but it was already declared.");
317
318 return data;
319 }
320
325
331 bool hasInitialConditionsFromFile() const;
332
333 Logger & log() { return _log; }
334
340 void setCheckJacobian(bool state) { _check_jacobian = state; }
341
347 virtual void augmentSparsity(const dof_id_type & elem_id1, const dof_id_type & elem_id2);
348
355
359 void setVectorValuedVelocity(bool vector_velocity) { _output_vector_velocity = vector_velocity; }
360
365
366protected:
381
384
387
390
393
395 std::vector<std::shared_ptr<Component>> _components;
397 std::map<std::string, std::shared_ptr<Component>> _comp_by_name;
399 std::map<std::string, std::string> _component_name_to_loop_name;
401 std::map<std::string, THM::FlowModelID> _loop_name_to_model_id;
402
404 std::map<std::string, std::shared_ptr<ClosuresBase>> _closures_by_name;
405
407 std::map<VariableName, VariableInfo> _vars;
408
409 struct ICInfo
410 {
411 std::string _type;
413
415 ICInfo(const std::string & type, const InputParameters & params) : _type(type), _params(params)
416 {
417 }
418 };
419 std::map<std::string, ICInfo> _ics;
420
423
426
431
437
439
444
449
450 std::vector<OutputName> _outputters_all;
451 std::vector<OutputName> _outputters_file;
452 std::vector<OutputName> _outputters_screen;
453
455 std::map<std::string, ControlDataValue *> _control_data;
456
459
461
464
466 std::map<dof_id_type, std::vector<dof_id_type>> _sparsity_elem_augmentation;
467
470
471public:
472 Real _zero;
473
474private:
480 std::vector<VariableName> sortAddedComponentVariables() const;
481
483 static std::map<VariableName, int> _component_variable_order_map;
484};
485
486template <typename T>
487bool
488Simulation::hasComponentOfType(const std::string & name) const
489{
490 auto it = _comp_by_name.find(name);
491 if (it != _comp_by_name.end())
492 return dynamic_cast<T *>((it->second).get()) != nullptr;
493 else
494 return false;
495}
496
497template <typename T>
498const T &
499Simulation::getComponentByName(const std::string & name) const
500{
501 auto it = _comp_by_name.find(name);
502 if (it != _comp_by_name.end())
503 return *dynamic_cast<T *>((it->second).get());
504 else
505 mooseError("Component '",
506 name,
507 "' does not exist in the simulation. Use hasComponent or "
508 "checkComponnetByName before calling getComponent.");
509}
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 addSimVariable(bool nl, const VariableName &name, libMesh::FEType fe_type, const std::vector< SubdomainName > &subdomain_names, Real scaling_factor=1.0)
Queues a variable of type MooseVariable to be added to the nonlinear or aux system.
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:562
void addControl(const std::string &type, const std::string &name, InputParameters params)
Add a control.
Definition Simulation.C:484
std::map< std::string, std::shared_ptr< Component > > _comp_by_name
Map of components by their names.
Definition Simulation.h:397
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:359
const T & getComponentByName(const std::string &name) const
Get component by its name.
Definition Simulation.h:499
bool hasComponentOfType(const std::string &name) const
Find out if simulation has a component with the given name and specified type.
Definition Simulation.h:488
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:469
std::map< VariableName, VariableInfo > _vars
variables for this simulation (name and info about the var)
Definition Simulation.h:407
std::map< std::string, ControlDataValue * > _control_data
Control data created in the control logic system.
Definition Simulation.h:455
void addConstantScalarIC(const VariableName &var_name, Real value)
Definition Simulation.C:549
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:383
FEProblemBase & _fe_problem
Pointer to FEProblem representing this simulation.
Definition Simulation.h:386
static std::map< VariableName, int > _component_variable_order_map
Component variable order map; see setComponentVariableOrder for more info.
Definition Simulation.h:483
libMesh::FEType _flow_fe_type
finite element type for the flow in the simulation
Definition Simulation.h:425
std::vector< OutputName > _outputters_file
Definition Simulation.h:451
void addConstantIC(const VariableName &var_name, Real value, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:509
virtual void integrityCheck() const
Check the integrity of the simulation.
Definition Simulation.C:843
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:631
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:422
void addFunctionIC(const VariableName &var_name, const std::string &func_name, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:529
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:306
std::vector< OutputName > _outputters_all
Definition Simulation.h:450
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:399
virtual void couplingMatrixIntegrityCheck() const
Check integrity of coupling matrix used by the preconditioner.
Definition Simulation.C:804
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:340
const bool & getImplicitTimeIntegrationFlag()
Gets the flag indicating whether an implicit time integration scheme is being used.
Definition Simulation.h:324
void addRelationshipManagers()
Add additional relationship managers to run the simulation.
Definition Simulation.C:742
virtual void setupMesh()
Perform mesh setup actions such as setting up the coordinate system(s) and creating ghosted elements.
Definition Simulation.C:795
std::vector< OutputName > _outputters_screen
Definition Simulation.h:452
void checkVariableNameLength(const std::string &name) const
Reports an error if the variable name is too long.
Definition Simulation.C:476
bool hasControlData(const std::string &name)
Query if control data with name 'name' exists.
Definition Simulation.h:270
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.
Definition Simulation.C:999
virtual ~Simulation()
Definition Simulation.C:61
virtual void controlDataIntegrityCheck()
Check the integrity of the control data.
Definition Simulation.C:908
std::map< std::string, ICInfo > _ics
Definition Simulation.h:419
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:285
std::shared_ptr< ClosuresBase > getClosures(const std::string &name) const
Get a pointer to a closures object.
Logger & log()
Definition Simulation.h:333
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, Real scaling_factor=1.0)
Queues a variable of type MooseVariableScalar 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.
Definition Simulation.C:988
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:404
virtual void addMooseObjects()
Add component MOOSE objects.
Definition Simulation.C:735
bool _implicit_time_integration
true if using implicit time integration scheme
Definition Simulation.h:458
virtual void buildMesh()
Create mesh for this simulation.
Definition Simulation.C:84
MooseApp & _thm_app
The application this is associated with.
Definition Simulation.h:389
virtual void setupQuadrature()
Sets up quadrature rules.
Definition Simulation.C:95
Factory & _thm_factory
The Factory associated with the MooseApp.
Definition Simulation.h:392
std::vector< std::shared_ptr< Component > > _components
List of components in this simulation.
Definition Simulation.h:395
std::vector< VariableName > sortAddedComponentVariables() const
Returns a sorted list of the variables added by components.
Definition Simulation.C:575
void setupInitialConditionObjects()
Definition Simulation.C:724
void addFileOutputter(const std::string &name)
bool getVectorValuedVelocity()
Is velocity output as vector-valued field.
Definition Simulation.h:354
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:767
virtual void run()
Run the simulation.
Definition Simulation.C:983
Logger _log
Definition Simulation.h:460
void setupInitialConditionsFromFile()
Setup reading initial conditions from a specified file, see 'initial_from_file' and 'initial_from_fil...
Definition Simulation.C:683
std::map< std::string, THM::FlowModelID > _loop_name_to_model_id
Map of loop name to model type.
Definition Simulation.h:401
bool _check_jacobian
True if checking jacobian.
Definition Simulation.h:463
void addSimInitialCondition(const std::string &type, const std::string &name, InputParameters params)
Definition Simulation.C:492
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:466
void addScreenOutputter(const std::string &name)
Specialization of FEProblem to run with component subsystem.
Definition THMProblem.h:19
InputParameters _params
Definition Simulation.h:412
ICInfo(const std::string &type, const InputParameters &params)
Definition Simulation.h:415
std::string _type
Definition Simulation.h:411
Variable information.
Definition Simulation.h:371
bool _nl
True if the variable is a nonlinear (solution) variable; otherwise, aux.
Definition Simulation.h:373
InputParameters _params
Input parameters.
Definition Simulation.h:377
std::string _var_type
Type (class) of the variable.
Definition Simulation.h:375