www.mooseframework.org
PolycrystalUserObjectBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "DenseMatrix.h"
13 #include "FeatureFloodCount.h"
14 
15 // Forward Declarations
16 
23 {
24 public:
26 
28 
33  virtual void precomputeGrainStructure() {}
34 
41  virtual void getGrainsBasedOnPoint(const Point & point,
42  std::vector<unsigned int> & grains) const = 0;
43 
49  virtual void getGrainsBasedOnElem(const Elem & elem, std::vector<unsigned int> & grains) const
50  {
51  getGrainsBasedOnPoint(elem.vertex_average(), grains);
52  }
53 
58  virtual unsigned int getNumGrains() const = 0;
59 
66  virtual Real getVariableValue(unsigned int op_index, const Point & p) const = 0;
67 
72  virtual Real getNodalVariableValue(unsigned int op_index, const Node & n) const
73  {
74  return getVariableValue(op_index, static_cast<const Point &>(n));
75  }
76 
77  /* Returns all available coloring algorithms as an enumeration type for input files.
78  */
80 
84  static std::string coloringAlgorithmDescriptions();
85 
89  virtual void initialSetup() override;
90  virtual void initialize() override;
91  virtual void execute() override;
92  virtual void finalize() override;
93 
94 protected:
95  virtual bool areFeaturesMergeable(const FeatureData & f1, const FeatureData & f2) const override;
96  virtual bool isNewFeatureOrConnectedRegion(const DofObject * dof_object,
97  std::size_t & current_index,
98  FeatureData *& feature,
99  Status & status,
100  unsigned int & new_id) override;
101  virtual void prepareDataForTransfer() override;
102  virtual void mergeSets() override;
103  virtual processor_id_type numberOfDistributedMergeHelpers() const override;
104  virtual void restoreOriginalDataStructures(std::vector<std::list<FeatureData>> & orig) override;
105 
111 
115  void assignOpsToGrains();
116 
120  bool colorGraph(unsigned int vertex);
121 
125  bool isGraphValid(unsigned int vertex, unsigned int color);
126 
130  void printGrainAdjacencyMatrix() const;
131 
132  /*************************************************
133  *************** Data Structures *****************
134  ************************************************/
136  std::unique_ptr<DenseMatrix<Real>> _adjacency_matrix;
137 
139  const unsigned int _dim;
140 
142  const unsigned int _op_num;
143 
145  std::map<unsigned int, unsigned int> _grain_to_op;
146 
149 
152 
155 
157  static const unsigned int INVALID_COLOR;
158 
160  static const unsigned int HALO_THICKNESS;
161 
162 private:
165 
167  std::vector<unsigned int> _grain_idx_to_op;
168 
170  std::vector<unsigned int> _prealloc_tmp_grains;
171 
172  std::map<dof_id_type, std::vector<unsigned int>> _entity_to_grain_cache;
173 };
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.
std::map< unsigned int, unsigned int > _grain_to_op
A map of the grain_id to op.
PolycrystalUserObjectBase(const InputParameters &parameters)
Status
This enumeration is used to indicate status of the grains in the _unique_grains data structure...
virtual Real getVariableValue(unsigned int op_index, const Point &p) const =0
Returns the variable value for a given op_index and mesh point.
virtual bool areFeaturesMergeable(const FeatureData &f1, const FeatureData &f2) const override
Method for determining whether two features are mergeable.
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.
std::map< dof_id_type, std::vector< unsigned int > > _entity_to_grain_cache
void assignOpsToGrains()
Method that runs a coloring algorithm to assign OPs to grains.
This object provides the base capability for creating proper polycrystal ICs.
void printGrainAdjacencyMatrix() const
Prints out the adjacency matrix in a nicely spaced integer format.
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...
MPI_Status status
uint8_t processor_id_type
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
processor_id_type _num_chunks
The number of chunks (for merging the features together)
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...
std::vector< unsigned int > _grain_idx_to_op
A vector indicating which op is assigned to each grain (by index of the grain)
bool colorGraph(unsigned int vertex)
Built-in simple "back-tracking" algorithm to assign colors to a graph.
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 void prepareDataForTransfer() override
This routine uses the local flooded data to build up the local feature data structures (_partial feat...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void mergeSets() override
This routine is called on the primary rank only and stitches together the partial feature pieces seen...
const InputParameters & parameters() const
virtual unsigned int getNumGrains() const =0
Must be overridden by the deriving class to provide the number of grains in the polycrystal structure...
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.
virtual processor_id_type numberOfDistributedMergeHelpers() const override
Returns a number indicating the number of merge helpers when running in parallel based on certain imp...
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...
virtual void restoreOriginalDataStructures(std::vector< std::list< FeatureData >> &orig) override
const MooseEnum _coloring_algorithm
The selected graph coloring algorithm used by this object.
static InputParameters validParams()
virtual void initialSetup() override
UserObject interface overrides.