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 THMMesh;
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
246
250 virtual void integrityCheck() const;
251
256 virtual void advanceState();
257
261 virtual void controlDataIntegrityCheck();
262
266 virtual void couplingMatrixIntegrityCheck() const;
267
274 template <typename T>
275 bool hasControlData(const std::string & name)
276 {
277 if (_control_data.find(name) == _control_data.end())
278 return false;
279 else
280 return dynamic_cast<ControlData<T> *>(_control_data[name]) != NULL;
281 }
282
289 template <typename T>
290 ControlData<T> * getControlData(const std::string & name)
291 {
292 ControlData<T> * data = nullptr;
293 if (_control_data.find(name) == _control_data.end())
294 {
295 data = new ControlData<T>(_thm_app, name);
296 _control_data[name] = data;
297 }
298 else
299 data = dynamic_cast<ControlData<T> *>(_control_data[name]);
300
301 return data;
302 }
303
310 template <typename T>
311 ControlData<T> * declareControlData(const std::string & name, THMControl * ctrl)
312 {
313 ControlData<T> * data = getControlData<T>(name);
314 if (!data->getDeclared())
315 {
316 // Mark the data for error checking
317 data->setDeclared();
318 data->setControl(ctrl);
319 }
320 else
321 logError("Trying to declare '", name, "', but it was already declared.");
322
323 return data;
324 }
325
330
336 bool hasInitialConditionsFromFile() const;
337
338 Logger & log() { return _log; }
339
345 void setCheckJacobian(bool state) { _check_jacobian = state; }
346
352 virtual void augmentSparsity(const dof_id_type & elem_id1, const dof_id_type & elem_id2);
353
360
364 void setVectorValuedVelocity(bool vector_velocity) { _output_vector_velocity = vector_velocity; }
365
370
371protected:
386
389
392
395
398
400 std::vector<std::shared_ptr<Component>> _components;
402 std::map<std::string, std::shared_ptr<Component>> _comp_by_name;
404 std::map<std::string, std::string> _component_name_to_loop_name;
406 std::map<std::string, THM::FlowModelID> _loop_name_to_model_id;
407
409 std::map<std::string, std::shared_ptr<ClosuresBase>> _closures_by_name;
410
412 std::map<VariableName, VariableInfo> _vars;
413
414 struct ICInfo
415 {
416 std::string _type;
418
420 ICInfo(const std::string & type, const InputParameters & params) : _type(type), _params(params)
421 {
422 }
423 };
424 std::map<std::string, ICInfo> _ics;
425
428
431
436
442
444
449
454
455 std::vector<OutputName> _outputters_all;
456 std::vector<OutputName> _outputters_file;
457 std::vector<OutputName> _outputters_screen;
458
460 std::map<std::string, ControlDataValue *> _control_data;
461
464
466
469
471 std::map<dof_id_type, std::vector<dof_id_type>> _sparsity_elem_augmentation;
472
475
476public:
477 Real _zero;
478
479private:
485 std::vector<VariableName> sortAddedComponentVariables() const;
486
488 static std::map<VariableName, int> _component_variable_order_map;
489};
490
491template <typename T>
492bool
493Simulation::hasComponentOfType(const std::string & name) const
494{
495 auto it = _comp_by_name.find(name);
496 if (it != _comp_by_name.end())
497 return dynamic_cast<T *>((it->second).get()) != nullptr;
498 else
499 return false;
500}
501
502template <typename T>
503const T &
504Simulation::getComponentByName(const std::string & name) const
505{
506 auto it = _comp_by_name.find(name);
507 if (it != _comp_by_name.end())
508 return *dynamic_cast<T *>((it->second).get());
509 else
510 mooseError("Component '",
511 name,
512 "' does not exist in the simulation. Use hasComponent or "
513 "checkComponnetByName before calling getComponent.");
514}
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:248
void addComponentScalarIC(const VariableName &var_name, const std::vector< Real > &value)
Definition Simulation.C:565
void addControl(const std::string &type, const std::string &name, InputParameters params)
Add a control.
Definition Simulation.C:487
THMMesh & _thm_mesh
THM mesh.
Definition Simulation.h:388
std::map< std::string, std::shared_ptr< Component > > _comp_by_name
Map of components by their names.
Definition Simulation.h:402
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:364
const T & getComponentByName(const std::string &name) const
Get component by its name.
Definition Simulation.h:504
bool hasComponentOfType(const std::string &name) const
Find out if simulation has a component with the given name and specified type.
Definition Simulation.h:493
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:474
std::map< VariableName, VariableInfo > _vars
variables for this simulation (name and info about the var)
Definition Simulation.h:412
std::map< std::string, ControlDataValue * > _control_data
Control data created in the control logic system.
Definition Simulation.h:460
void addConstantScalarIC(const VariableName &var_name, Real value)
Definition Simulation.C:552
const std::vector< std::shared_ptr< Component > > & getComponents() const
Return list of components available in the simulation.
Definition Simulation.h:117
FEProblemBase & _fe_problem
Pointer to FEProblem representing this simulation.
Definition Simulation.h:391
ThermalHydraulicsApp & _thm_app
The application this is associated with.
Definition Simulation.h:394
static std::map< VariableName, int > _component_variable_order_map
Component variable order map; see setComponentVariableOrder for more info.
Definition Simulation.h:488
ThermalHydraulicsApp & getApp()
Get the ThermalHydraulicsApp.
Definition Simulation.h:245
libMesh::FEType _flow_fe_type
finite element type for the flow in the simulation
Definition Simulation.h:430
std::vector< OutputName > _outputters_file
Definition Simulation.h:456
void addConstantIC(const VariableName &var_name, Real value, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:512
virtual void integrityCheck() const
Check the integrity of the simulation.
Definition Simulation.C:846
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:634
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:71
const InputParameters & _thm_pars
"Global" of this simulation
Definition Simulation.h:427
void addFunctionIC(const VariableName &var_name, const std::string &func_name, const std::vector< SubdomainName > &block_names)
Definition Simulation.C:532
virtual void initComponents()
Initialize this simulation's components.
Definition Simulation.C:151
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:311
std::vector< OutputName > _outputters_all
Definition Simulation.h:455
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:404
virtual void couplingMatrixIntegrityCheck() const
Check integrity of coupling matrix used by the preconditioner.
Definition Simulation.C:807
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:345
const bool & getImplicitTimeIntegrationFlag()
Gets the flag indicating whether an implicit time integration scheme is being used.
Definition Simulation.h:329
void addRelationshipManagers()
Add additional relationship managers to run the simulation.
Definition Simulation.C:745
virtual void setupMesh()
Perform mesh setup actions such as setting up the coordinate system(s) and creating ghosted elements.
Definition Simulation.C:798
std::vector< OutputName > _outputters_screen
Definition Simulation.h:457
void checkVariableNameLength(const std::string &name) const
Reports an error if the variable name is too long.
Definition Simulation.C:479
bool hasControlData(const std::string &name)
Query if control data with name 'name' exists.
Definition Simulation.h:275
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:64
virtual void controlDataIntegrityCheck()
Check the integrity of the control data.
Definition Simulation.C:911
std::map< std::string, ICInfo > _ics
Definition Simulation.h:424
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:290
std::shared_ptr< ClosuresBase > getClosures(const std::string &name) const
Get a pointer to a closures object.
Logger & log()
Definition Simulation.h:338
void identifyLoops()
Identifies the component loops.
Definition Simulation.C:164
virtual void initSimulation()
Initialize this simulation.
Definition Simulation.C:135
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.
Definition Simulation.C:271
static void setComponentVariableOrder(const VariableName &var, int index)
Sets a component variable order index.
Definition Simulation.C:40
virtual void addComponent(const std::string &type, const std::string &name, InputParameters params)
Add a component into this simulation.
Definition Simulation.C:991
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:409
virtual void addMooseObjects()
Add component MOOSE objects.
Definition Simulation.C:738
bool _implicit_time_integration
true if using implicit time integration scheme
Definition Simulation.h:463
virtual void buildMesh()
Create mesh for this simulation.
Definition Simulation.C:87
virtual void setupQuadrature()
Sets up quadrature rules.
Definition Simulation.C:98
Factory & _thm_factory
The Factory associated with the MooseApp.
Definition Simulation.h:397
std::vector< std::shared_ptr< Component > > _components
List of components in this simulation.
Definition Simulation.h:400
std::vector< VariableName > sortAddedComponentVariables() const
Returns a sorted list of the variables added by components.
Definition Simulation.C:578
void setupInitialConditionObjects()
Definition Simulation.C:727
void addFileOutputter(const std::string &name)
bool getVectorValuedVelocity()
Is velocity output as vector-valued field.
Definition Simulation.h:359
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:770
virtual void run()
Run the simulation.
Definition Simulation.C:986
Logger _log
Definition Simulation.h:465
void setupInitialConditionsFromFile()
Setup reading initial conditions from a specified file, see 'initial_from_file' and 'initial_from_fil...
Definition Simulation.C:686
std::map< std::string, THM::FlowModelID > _loop_name_to_model_id
Map of loop name to model type.
Definition Simulation.h:406
bool _check_jacobian
True if checking jacobian.
Definition Simulation.h:468
void addSimInitialCondition(const std::string &type, const std::string &name, InputParameters params)
Definition Simulation.C:495
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:471
void addScreenOutputter(const std::string &name)
Mesh for THM.
Definition THMMesh.h:19
Specialization of FEProblem to run with component subsystem.
Definition THMProblem.h:19
InputParameters _params
Definition Simulation.h:417
ICInfo(const std::string &type, const InputParameters &params)
Definition Simulation.h:420
std::string _type
Definition Simulation.h:416
Variable information.
Definition Simulation.h:376
bool _nl
True if the variable is a nonlinear (solution) variable; otherwise, aux.
Definition Simulation.h:378
InputParameters _params
Input parameters.
Definition Simulation.h:382
std::string _var_type
Type (class) of the variable.
Definition Simulation.h:380