www.mooseframework.org
PolycrystalUserObjectBase.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 #ifndef POLYCRYSTALUSEROBJECTBASE_H
8 #define POLYCRYSTALUSEROBJECTBASE_H
9 
10 #include "FeatureFloodCount.h"
11 
12 #include "libmesh/dense_matrix.h"
13 
14 // Forward Declarations
16 
17 template <>
19 
26 {
27 public:
28  PolycrystalUserObjectBase(const InputParameters & parameters);
29 
34  virtual void precomputeGrainStructure() {}
35 
42  virtual void getGrainsBasedOnPoint(const Point & point,
43  std::vector<unsigned int> & grains) const = 0;
44 
50  virtual void getGrainsBasedOnElem(const Elem & elem, std::vector<unsigned int> & grains) const
51  {
52  getGrainsBasedOnPoint(elem.centroid(), grains);
53  }
54 
59  virtual unsigned int getNumGrains() const = 0;
60 
67  virtual Real getVariableValue(unsigned int op_index, const Point & p) const = 0;
68 
73  virtual Real getNodalVariableValue(unsigned int op_index, const Node & n) const
74  {
75  return getVariableValue(op_index, static_cast<const Point &>(n));
76  }
77 
81  virtual const std::vector<unsigned int> & getGrainToOps() const { return _grain_to_op; }
82 
86  static MooseEnum coloringAlgorithms();
87 
91  static std::string coloringAlgorithmDescriptions();
92 
96  virtual void initialSetup() override;
97  virtual void initialize() override;
98  virtual void execute() override;
99  virtual void finalize() override;
100 
101 protected:
102  virtual bool areFeaturesMergeable(const FeatureData & f1, const FeatureData & f2) const override;
103  virtual bool isNewFeatureOrConnectedRegion(const DofObject * dof_object,
104  std::size_t & current_index,
105  FeatureData *& feature,
106  Status & status,
107  unsigned int & new_id) override;
108 
114 
118  void assignOpsToGrains();
119 
123  bool colorGraph(unsigned int vertex);
124 
128  bool isGraphValid(unsigned int vertex, unsigned int color);
129 
133  void printGrainAdjacencyMatrix() const;
134 
135  /*************************************************
136  *************** Data Structures *****************
137  ************************************************/
139  std::unique_ptr<DenseMatrix<Real>> _adjacency_matrix;
140 
142  const unsigned int _dim;
143 
145  const unsigned int _op_num;
146 
148  std::vector<unsigned int> _grain_to_op;
149 
151  const MooseEnum _coloring_algorithm;
152 
155 
158 
160  static const unsigned int INVALID_COLOR;
161 
163  static const unsigned int HALO_THICKNESS;
164 
165 private:
167  std::vector<unsigned int> _prealloc_tmp_grains;
168 };
169 
170 #endif // POLYCRYSTALUSEROBJECTBASE_H
std::vector< unsigned int > _prealloc_tmp_grains
Temporary storage area for current grains at a point to avoid memory churn.
virtual void finalize() override
std::unique_ptr< DenseMatrix< Real > > _adjacency_matrix
The dense adjacency matrix.
void buildGrainAdjacencyMatrix()
Builds a dense adjacency matrix based on the discovery of grain neighbors and halos surrounding each ...
static std::string coloringAlgorithmDescriptions()
Returns corresponding descriptions of available coloring algorithms.
virtual void getGrainsBasedOnElem(const Elem &elem, std::vector< unsigned int > &grains) const
This method may be defined in addition to the point based initialization to speed up lookups...
PolycrystalUserObjectBase(const InputParameters &parameters)
virtual unsigned int getNumGrains() const =0
Must be overridden by the deriving class to provide the number of grains in the polycrystal structure...
Status
This enumeration is used to indicate status of the grains in the _unique_grains data structure...
void printGrainAdjacencyMatrix() const
Prints out the adjacency matrix in a nicely spaced integer format.
virtual Real getNodalVariableValue(unsigned int op_index, const Node &n) const
Similarly to the getVariableValue method, this method also returns values but may be optimized for re...
void assignOpsToGrains()
Method that runs a coloring algorithm to assign OPs to grains.
This object provides the base capability for creating proper polycrystal ICs.
virtual const std::vector< unsigned int > & getGrainToOps() const
Method for retrieving the initial grain OP assignments.
std::vector< unsigned int > _grain_to_op
A vector indicating which op is assigned to each grain.
const unsigned int _op_num
The maximum number of order parameters (colors) available to assign to the grain structure.
const unsigned int _dim
mesh dimension
static const unsigned int HALO_THICKNESS
Used to hold the thickness of the halo that should be constructed for detecting adjacency.
bool isGraphValid(unsigned int vertex, unsigned int color)
Helper method for the back-tracking graph coloring algorithm.
virtual void precomputeGrainStructure()
This callback is triggered after the object is initialized and may be optionally overridden to do pre...
bool _colors_assigned
A Boolean indicating whether the object has assigned colors to grains (internal use) ...
This object will mark nodes or elements of continuous regions all with a unique number for the purpos...
virtual void getGrainsBasedOnPoint(const Point &point, std::vector< unsigned int > &grains) const =0
Method for retrieving active grain IDs based on some point in the mesh.
bool colorGraph(unsigned int vertex)
Built-in simple "back-tracking" algorithm to assign colors to a graph.
InputParameters validParams< PolycrystalUserObjectBase >()
virtual bool isNewFeatureOrConnectedRegion(const DofObject *dof_object, std::size_t &current_index, FeatureData *&feature, Status &status, unsigned int &new_id) override
Method called during the recursive flood routine that should return whether or not the current entity...
virtual Real getVariableValue(unsigned int op_index, const Point &p) const =0
Returns the variable value for a given op_index and mesh point.
static MooseEnum coloringAlgorithms()
Returns all available coloring algorithms as an enumeration type for input files. ...
virtual bool areFeaturesMergeable(const FeatureData &f1, const FeatureData &f2) const override
Method for determining whether two features are mergeable.
virtual void execute() override
virtual void initialize() override
const bool _output_adjacency_matrix
A user controllable Boolean which can be used to print the adjacency matrix to the console...
static const unsigned int INVALID_COLOR
Used to indicate an invalid coloring for the built-in back-tracking algorithm.
const MooseEnum _coloring_algorithm
The selected graph coloring algorithm used by this object.
virtual void initialSetup() override
UserObject interface overrides.