https://mooseframework.inl.gov
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 
12 #include "ThermalHydraulicsApp.h"
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 
20 class ActionWarehouse;
21 class Component;
22 class ClosuresBase;
23 class THMMesh;
24 class THMProblem;
25 
30 {
31 public:
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() { 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 
371 protected:
376  {
378  bool _nl;
380  std::string _var_type;
383 
385  };
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 
435  void setupEquations();
436 
442 
444 
448  void setupCoordinateSystem();
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 
476 public:
478 
479 private:
485  std::vector<VariableName> sortAddedComponentVariables() const;
486 
488  static std::map<VariableName, int> _component_variable_order_map;
489 };
490 
491 template <typename T>
492 bool
493 Simulation::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 
502 template <typename T>
503 const T &
504 Simulation::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 }
Keeps the error and warning messages.
Definition: Logger.h:17
virtual void run()
Run the simulation.
Definition: Simulation.C:986
Specialization of FEProblem to run with component subsystem.
Definition: THMProblem.h:18
bool _implicit_time_integration
true if using implicit time integration scheme
Definition: Simulation.h:463
std::shared_ptr< ClosuresBase > getClosures(const std::string &name) const
Get a pointer to a closures object.
Definition: Simulation.C:1025
void setDeclared()
Mark the data as declared.
Definition: ControlData.h:65
virtual void setupMesh()
Perform mesh setup actions such as setting up the coordinate system(s) and creating ghosted elements...
Definition: Simulation.C:798
Interface for handling names.
void setupInitialConditionObjects()
Definition: Simulation.C:727
void mooseError(Args &&... args)
Main class for simulation (the driver of the simulation)
Definition: Simulation.h:29
void identifyLoops()
Identifies the component loops.
Definition: Simulation.C:164
Real _zero
Definition: Simulation.h:477
std::map< std::string, ICInfo > _ics
Definition: Simulation.h:424
virtual void controlDataIntegrityCheck()
Check the integrity of the control data.
Definition: Simulation.C:911
virtual ~Simulation()
Definition: Simulation.C:64
bool _check_jacobian
True if checking jacobian.
Definition: Simulation.h:468
FEProblemBase & _fe_problem
Pointer to FEProblem representing this simulation.
Definition: Simulation.h:391
THMMesh & _thm_mesh
THM mesh.
Definition: Simulation.h:388
void addFileOutputter(const std::string &name)
Definition: Simulation.C:1035
InputParameters _params
Definition: Simulation.h:417
bool getVectorValuedVelocity()
Is velocity output as vector-valued field.
Definition: Simulation.h:359
virtual void addClosures(const std::string &type, const std::string &name, InputParameters params)
Add a closures object into this simulation.
Definition: Simulation.C:1009
void printComponentLoops() const
Prints the component loops.
Definition: Simulation.C:248
ICInfo(const std::string &type, const InputParameters &params)
Definition: Simulation.h:420
Interface class for logging errors and warnings.
Mesh for THM.
Definition: THMMesh.h:18
virtual void couplingMatrixIntegrityCheck() const
Check integrity of coupling matrix used by the preconditioner.
Definition: Simulation.C:807
InputParameters emptyInputParameters()
void addFunctionIC(const VariableName &var_name, const std::string &func_name, const std::vector< SubdomainName > &block_names)
Definition: Simulation.C:532
void addRelationshipManagers()
Add additional relationship managers to run the simulation.
Definition: Simulation.C:745
virtual void initSimulation()
Initialize this simulation.
Definition: Simulation.C:135
Base class for closures implementations.
Definition: ClosuresBase.h:28
std::map< std::string, ControlDataValue * > _control_data
Control data created in the control logic system.
Definition: Simulation.h:460
static std::map< VariableName, int > _component_variable_order_map
Component variable order map; see setComponentVariableOrder for more info.
Definition: Simulation.h:488
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
std::string _type
Definition: Simulation.h:416
void checkVariableNameLength(const std::string &name) const
Reports an error if the variable name is too long.
Definition: Simulation.C:479
bool hasComponent(const std::string &name) const
Find out if simulation has a component with the given name.
Definition: Simulation.C:1002
Concrete definition of a parameter value for a specified type.
Definition: ControlData.h:91
libMesh::FEType _flow_fe_type
finite element type for the flow in the simulation
Definition: Simulation.h:430
Variable information.
Definition: Simulation.h:375
virtual void initComponents()
Initialize this simulation&#39;s components.
Definition: Simulation.C:151
bool getDeclared()
Get the declared state.
Definition: ControlData.h:70
bool hasControlData(const std::string &name)
Query if control data with name &#39;name&#39; exists.
Definition: Simulation.h:275
std::map< VariableName, VariableInfo > _vars
variables for this simulation (name and info about the var)
Definition: Simulation.h:412
ThermalHydraulicsApp & getApp()
Get the ThermalHydraulicsApp.
Definition: Simulation.h:245
const std::string name
Definition: Setup.h:20
void logError(Args &&... args) const
Logs an error.
std::vector< OutputName > _outputters_file
Definition: Simulation.h:456
Factory & _thm_factory
The Factory associated with the MooseApp.
Definition: Simulation.h:397
void setupInitialConditionsFromFile()
Setup reading initial conditions from a specified file, see &#39;initial_from_file&#39; and &#39;initial_from_fil...
Definition: Simulation.C:686
virtual void integrityCheck() const
Check the integrity of the simulation.
Definition: Simulation.C:846
std::vector< OutputName > getOutputsVector(const std::string &key) const
Gets the vector of output names corresponding to a 1-word key string.
Definition: Simulation.C:1049
Logger & log()
Definition: Simulation.h:338
InputParameters _params
Input parameters.
Definition: Simulation.h:382
void setControl(THMControl *ctrl)
Set the pointer to the control object that declared this control data.
Definition: ControlData.h:60
void setCheckJacobian(bool state)
Enable Jacobian checking.
Definition: Simulation.h:345
const T & getComponentByName(const std::string &name) const
Get component by its name.
Definition: Simulation.h:504
Base class for THM components.
Definition: Component.h:27
ControlData< T > * declareControlData(const std::string &name, THMControl *ctrl)
Declare control data of type T and name &#39;name&#39;, if it does not exist it will be created.
Definition: Simulation.h:311
virtual void addMooseObjects()
Add component MOOSE objects.
Definition: Simulation.C:738
std::vector< std::shared_ptr< Component > > _components
List of components in this simulation.
Definition: Simulation.h:400
bool _output_vector_velocity
Flag indicating if velocity is output as vector-valued field.
Definition: Simulation.h:474
std::map< std::string, std::string > _component_name_to_loop_name
Map of component name to component loop name.
Definition: Simulation.h:404
std::map< std::string, std::shared_ptr< Component > > _comp_by_name
Map of components by their names.
Definition: Simulation.h:402
void addConstantScalarIC(const VariableName &var_name, Real value)
Definition: Simulation.C:552
const InputParameters & _thm_pars
"Global" of this simulation
Definition: Simulation.h:427
void addScreenOutputter(const std::string &name)
Definition: Simulation.C:1042
virtual void setupQuadrature()
Sets up quadrature rules.
Definition: Simulation.C:98
std::map< std::string, std::shared_ptr< ClosuresBase > > _closures_by_name
Map of closures by their names.
Definition: Simulation.h:409
bool hasClosures(const std::string &name) const
Return whether the simulation has a closures object.
Definition: Simulation.C:1019
std::string _var_type
Type (class) of the variable.
Definition: Simulation.h:380
void addSimInitialCondition(const std::string &type, const std::string &name, InputParameters params)
Definition: Simulation.C:495
const libMesh::FEType & getFlowFEType() const
Gets the FE type for the flow in this simulation.
Definition: Simulation.h:48
void addComponentScalarIC(const VariableName &var_name, const std::vector< Real > &value)
Definition: Simulation.C:565
virtual void buildMesh()
Create mesh for this simulation.
Definition: Simulation.C:87
std::vector< VariableName > sortAddedComponentVariables() const
Returns a sorted list of the variables added by components.
Definition: Simulation.C:578
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void addComponent(const std::string &type, const std::string &name, InputParameters params)
Add a component into this simulation.
Definition: Simulation.C:991
Simulation(FEProblemBase &fe_problem, const InputParameters &params)
Definition: Simulation.C:45
bool _nl
True if the variable is a nonlinear (solution) variable; otherwise, aux.
Definition: Simulation.h:378
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name &#39;name&#39;, if it does not exist it will be created.
Definition: Simulation.h:290
static void setComponentVariableOrder(const VariableName &var, int index)
Sets a component variable order index.
Definition: Simulation.C:40
const bool & getImplicitTimeIntegrationFlag()
Gets the flag indicating whether an implicit time integration scheme is being used.
Definition: Simulation.h:329
void setVectorValuedVelocity(bool vector_velocity)
Set if velocity is being output as a vector-valued field.
Definition: Simulation.h:364
std::map< std::string, THM::FlowModelID > _loop_name_to_model_id
Map of loop name to model type.
Definition: Simulation.h:406
virtual void addVariables()
Add variables involved in this simulation.
Definition: Simulation.C:634
std::vector< OutputName > _outputters_screen
Definition: Simulation.h:457
void setupCoordinateSystem()
Sets the coordinate system for each subdomain.
Definition: Simulation.C:770
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 setupEquations()
Setup equations to be solved in this simulation.
const std::vector< std::shared_ptr< Component > > & getComponents()
Return list of components available in the simulation.
Definition: Simulation.h:117
Logger _log
Definition: Simulation.h:465
ThermalHydraulicsApp & _thm_app
The application this is associated with.
Definition: Simulation.h:394
void addConstantIC(const VariableName &var_name, Real value, const std::vector< SubdomainName > &block_names)
Definition: Simulation.C:512
std::vector< OutputName > _outputters_all
Definition: Simulation.h:455
bool hasInitialConditionsFromFile() const
Are initial conditions specified from a file.
Definition: Simulation.C:1070
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
uint8_t dof_id_type
void setupCriticalHeatFluxTable()
Setup ctirical heat flux table user object.
void addControl(const std::string &type, const std::string &name, InputParameters params)
Add a control.
Definition: Simulation.C:487
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
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
Definition: Simulation.C:1076