https://mooseframework.inl.gov
SolutionUserObjectBase.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 // MOOSE includes
13 #include "GeneralUserObject.h"
14 
15 // Forward declarations
16 namespace libMesh
17 {
18 class ExodusII_IO;
19 class Nemesis_IO;
20 class EquationSystems;
21 class System;
22 class MeshFunction;
23 template <class T>
24 class NumericVector;
25 }
26 
32 {
33 public:
35 
37 
41  virtual Real solutionSampleTime() = 0;
42 
46  virtual void timestepSetup() override;
47 
53  unsigned int getLocalVarIndex(const std::string & var_name) const;
54 
67  const Point & p,
68  const std::string & var_name,
69  const MooseEnum & weighting_type = weightingType(),
70  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
71 
82  const Point & p,
83  const unsigned int local_var_index,
84  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
85 
96  const Point & p,
97  const std::string & var_name,
98  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
99 
112  std::map<const Elem *, Real>
114  Point pt,
115  const unsigned int local_var_index,
116  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
117 
130  std::map<const Elem *, Real>
132  const Point & p,
133  const std::string & var_name,
134  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
135 
149  const Point & p,
150  const std::string & var_name,
151  const MooseEnum & weighting_type = weightingType(),
152  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
153 
165  const Point & p,
166  const std::string & var_name,
167  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
168 
180  Point pt,
181  const unsigned int local_var_index,
182  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
183 
196  std::map<const Elem *, libMesh::RealGradient> discontinuousPointValueGradient(
197  Real t,
198  const Point & p,
199  const std::string & var_name,
200  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
201 
214  std::map<const Elem *, libMesh::RealGradient> discontinuousPointValueGradient(
215  Real t,
216  Point pt,
217  const unsigned int local_var_index,
218  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
219 
226  Real directValue(const Node * node, const std::string & var_name) const;
227 
234  Real directValue(const Elem * elem, const std::string & var_name) const;
235 
243  Real scalarValue(Real t, const std::string & var_name) const;
244 
245  // Required pure virtual function (not used)
246  virtual void initialize() override;
247 
248  // Required pure virtual function (not used)
249  virtual void finalize() override;
250 
251  // Required pure virtual function (not used)
252  virtual void execute() override;
253 
255  virtual void initialSetup() override;
256 
257  const std::vector<std::string> & variableNames() const;
258 
259  bool isVariableNodal(const std::string & var_name) const;
260 
262  {
263  return MooseEnum("found_first=1 average=2 smallest_element_id=4 largest_element_id=8",
264  "found_first");
265  }
266 
271  unsigned int getMeshFileDimension() const { return _mesh->spatial_dimension(); }
272 
276  const std::string getMeshFileName() const { return _mesh_file; }
277 
283  const std::map<SubdomainName, SubdomainID> & getBlockNamesToIds() const
284  {
285  return _block_name_to_id;
286  }
287 
293  const std::map<SubdomainID, SubdomainName> & getBlockIdsToNames() const
294  {
295  return _block_id_to_name;
296  }
297 
303 
304 protected:
310  void readXda();
311 
316  void readExodusIIOrNemesis();
317 
325  virtual Real directValue(dof_id_type dof_index) const;
326 
331 
336 
344  Real evalMeshFunction(const Point & p,
345  const unsigned int local_var_index,
346  unsigned int func_num,
347  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
348 
357  std::map<const Elem *, Real>
358  evalMultiValuedMeshFunction(const Point & p,
359  const unsigned int local_var_index,
360  unsigned int func_num,
361  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
362 
371  evalMeshFunctionGradient(const Point & p,
372  const unsigned int local_var_index,
373  unsigned int func_num,
374  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
375 
385  std::map<const Elem *, libMesh::RealGradient> evalMultiValuedMeshFunctionGradient(
386  const Point & p,
387  const unsigned int local_var_index,
388  unsigned int func_num,
389  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
390 
395 
398 
400  std::string _mesh_file;
401 
403  std::string _es_file;
404 
406  std::string _system_name;
407 
409  std::vector<std::string> _system_variables;
410 
412  std::map<std::string, unsigned int> _local_variable_index;
413 
415  std::vector<std::string> _nodal_variables;
416 
418  std::vector<std::string> _elemental_variables;
419 
421  std::vector<std::string> _scalar_variables;
422 
425 
428 
430  std::unique_ptr<libMesh::MeshBase> _mesh;
431 
433  std::unique_ptr<libMesh::EquationSystems> _es;
434 
437 
439  std::unique_ptr<libMesh::MeshFunction> _mesh_function;
440 
442  std::unique_ptr<libMesh::ExodusII_IO> _exodusII_io;
443 
445  std::unique_ptr<libMesh::Nemesis_IO> _nemesis_io;
446 
448  std::unique_ptr<NumericVector<Number>> _serialized_solution;
449 
451  std::unique_ptr<libMesh::EquationSystems> _es2;
452 
455 
457  std::unique_ptr<libMesh::MeshFunction> _mesh_function2;
458 
460  std::unique_ptr<NumericVector<Number>> _serialized_solution2;
461 
464 
467 
469  const std::vector<Real> * _exodus_times;
470 
473 
476 
479 
481  std::vector<Real> _scale;
482 
484  std::vector<Real> _scale_multiplier;
485 
487  std::vector<Real> _translation;
488 
491 
494 
497 
500 
503 
506 
509 
512 
515 
517  std::map<SubdomainName, SubdomainID> _block_name_to_id;
518 
520  std::map<SubdomainID, SubdomainName> _block_id_to_name;
521 
522  // All the caches are duplicated between the before-timestep and after-timestep mesh functions
524  mutable Point _cached_p = Point(std::numeric_limits<Real>::max(), 0., 0.);
525  mutable Point _cached_p2 = Point(std::numeric_limits<Real>::max(), 0., 0.);
527  mutable std::set<subdomain_id_type> _cached_subdomain_ids;
528  mutable std::set<subdomain_id_type> _cached_subdomain_ids2;
532 
533 private:
535 };
MultiMooseEnum _transformation_order
transformations (rotations, translation, scales) are performed in this order
std::vector< std::string > _system_variables
A list of variables to extract from the read system.
static InputParameters validParams()
SolutionUserObjectBase(const InputParameters &parameters)
std::unique_ptr< libMesh::MeshFunction > _mesh_function2
Pointer to second libMesh::MeshFuntion, used for interpolation.
std::unique_ptr< libMesh::EquationSystems > _es
Pointer to the libMesh::EquationSystems object.
const bool _force_replicated_source
Whether to force the source mesh to be replicated.
RealVectorValue _rotation0_vector
vector about which to rotate
const std::vector< Real > * _exodus_times
The times available in the ExodusII file.
virtual void initialSetup() override
Initialize the System and Mesh objects for the solution being read.
void updateTimeInterpolationFromFile()
Updates the times for interpolating ExodusII or Nemesis data.
virtual Real solutionSampleTime()=0
Get the time at which to sample the solution.
void readXda()
Method for reading XDA mesh and equation systems file(s) This method is called by the constructor whe...
static Threads::spin_mutex _solution_user_object_mutex
std::map< const Elem *, libMesh::RealGradient > discontinuousPointValueGradient(Real t, const Point &p, const std::string &var_name, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns the gradient at a specific location and variable for cases where the gradient is multivalued ...
User object that reads an existing solution from an input file and uses it in the current simulation...
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
bool updateInterpolationBracketingTimeIndices()
Updates the time indices to interpolate between for ExodusII or Nemesis data.
std::unique_ptr< NumericVector< Number > > _serialized_solution2
Pointer to second serial solution, used for interpolation.
std::vector< Real > _scale
Scale parameter.
std::vector< Real > _translation
Translation.
Real _rotation1_angle
angle (in degrees) which to rotate through about vector _rotation1_vector
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real _rotation0_angle
angle (in degrees) which to rotate through about vector _rotation0_vector
static MooseEnum weightingType()
MooseEnum getSolutionFileType() const
Get the type of file that was read.
int _exodus_time_index
Current ExodusII time index.
std::unique_ptr< libMesh::ExodusII_IO > _exodusII_io
Pointer to the libMesh::ExodusII used to read the files.
Real _interpolation_time
Time in the current simulation at which the solution interpolation was last updated.
std::unique_ptr< libMesh::EquationSystems > _es2
Pointer to second libMesh::EquationSystems object, used for interpolation.
std::map< const Elem *, Real > evalMultiValuedMeshFunction(const Point &p, const unsigned int local_var_index, unsigned int func_num, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
A wrapper method for calling the various MeshFunctions that calls the mesh function functionality for...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
libMesh::RealGradient evalMeshFunctionGradient(const Point &p, const unsigned int local_var_index, unsigned int func_num, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
A wrapper method interfacing with the libMesh mesh function for evaluating the gradient.
std::unique_ptr< NumericVector< Number > > _serialized_solution
Pointer to the serial solution vector.
Point _cached_p
Cached points.
bool _initialized
True if initial_setup has executed.
std::unique_ptr< libMesh::Nemesis_IO > _nemesis_io
Pointer to the libMesh::Nemesis_IO used to read the files.
std::map< SubdomainName, SubdomainID > _block_name_to_id
Map from block ID to block names. Read from the ExodusII file.
auto max(const L &left, const R &right)
virtual void timestepSetup() override
When reading ExodusII files, this will update the interpolation times.
DenseVector< Number > _cached_values2
virtual void execute() override
Execute method.
DenseVector< Number > _cached_values
Cached values.
const std::string getMeshFileName() const
Return the name of the mesh file this object read the solution from.
std::unique_ptr< libMesh::MeshBase > _mesh
Pointer the libMesh::mesh object.
TensorValue< Real > RealTensorValue
libMesh::System * _system
Pointer libMesh::System class storing the read solution.
RealVectorValue _rotation1_vector
vector about which to rotate
std::string _mesh_file
The XDA/ExodusII/XDR/Nemesis file that is being read.
std::vector< std::string > _scalar_variables
Stores names of scalar variables.
unsigned int getMeshFileDimension() const
Return the spatial dimension of the mesh file.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
RealTensorValue _r1
Rotation matrix that performs the "_rotation1_angle about rotation1_vector".
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Real evalMeshFunction(const Point &p, const unsigned int local_var_index, unsigned int func_num, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
A wrapper method for calling the various MeshFunctions used for reading the data. ...
Real scalarValue(Real t, const std::string &var_name) const
Returns a value of a global variable.
const MooseEnum _nodal_variable_order
Nodal variable order, used when reading in solution data.
libMesh::System * _system2
Pointer to a second libMesh::System object, used for interpolation.
Real directValue(const Node *node, const std::string &var_name) const
Return a value directly from a Node.
void readBlockIdMapFromExodusII()
Read block ID map from the ExodusII file.
const std::vector< std::string > & variableNames() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::map< SubdomainName, SubdomainID > & getBlockNamesToIds() const
Get the map from block name to block ID.
bool isVariableNodal(const std::string &var_name) const
std::map< std::string, unsigned int > _local_variable_index
Stores the local index need by MeshFunction.
std::map< const Elem *, libMesh::RealGradient > evalMultiValuedMeshFunctionGradient(const Point &p, const unsigned int local_var_index, unsigned int func_num, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
A wrapper method interfacing with the libMesh mesh function that calls the gradient functionality for...
Real pointValueWrapper(Real t, const Point &p, const std::string &var_name, const MooseEnum &weighting_type=weightingType(), const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns a value at a specific location and variable checking for multiple values and weighting these ...
int _exodus_index1
Time index 1, used for interpolation.
std::vector< std::string > _nodal_variables
Stores names of nodal variables.
std::string _es_file
The XDA/XDR file that contians the EquationSystems data (xda/xdr only)
RealTensorValue _r0
Rotation matrix that performs the "_rotation0_angle about rotation0_vector".
std::vector< std::string > _elemental_variables
Stores names of elemental variables.
const std::map< SubdomainID, SubdomainName > & getBlockIdsToNames() const
Get the map from block id to block name.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
void readExodusIIOrNemesis()
Method for reading an ExodusII or Nemesis file, which is called when a mesh file with a ...
MooseEnum _file_type
File type to read (0 = xda; 1 = ExodusII, 2 = xdr, 3 = Nemesis)
libMesh::RealGradient pointValueGradientWrapper(Real t, const Point &p, const std::string &var_name, const MooseEnum &weighting_type=weightingType(), const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns the gradient at a specific location and variable checking for multiple values and weighting t...
std::vector< Real > _scale_multiplier
scale_multiplier parameter
std::unique_ptr< libMesh::MeshFunction > _mesh_function
Pointer the libMesh::MeshFunction object that the read data is stored.
bool _interpolate_times
Flag for triggering interpolation of ExodusII data.
std::string _system_name
The system name to extract from the XDA/XDR file (xda/xdr only)
std::map< const Elem *, Real > discontinuousPointValue(Real t, Point pt, const unsigned int local_var_index, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns a value at a specific location and variable for cases where the solution is multivalued at el...
Real pointValue(Real t, const Point &p, const unsigned int local_var_index, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns a value at a specific location and variable (see SolutionFunction)
unsigned int getLocalVarIndex(const std::string &var_name) const
Returns the local index for a given variable name.
int _exodus_index2
Time index 2, used for interpolation.
Real _interpolation_factor
Interpolation weight factor.
std::map< SubdomainID, SubdomainName > _block_id_to_name
Map from block names to block IDs. Read from the ExodusII file.
virtual void finalize() override
Finalize.
uint8_t dof_id_type
std::set< subdomain_id_type > _cached_subdomain_ids2
libMesh::RealGradient pointValueGradient(Real t, const Point &p, const std::string &var_name, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns the gradient at a specific location and variable (see SolutionFunction)
std::set< subdomain_id_type > _cached_subdomain_ids
Cached subdomain ids.