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 /****************************************************************/
11 #include "FeatureFloodCount.h"
12 #include "GrainTrackerInterface.h"
14 #include "libmesh/mesh_tools.h"
16 class GrainTracker;
18 struct GrainDistance;
20 template <>
21 InputParameters validParams<GrainTracker>();
24 {
25 public:
26  GrainTracker(const InputParameters & parameters);
27  virtual ~GrainTracker();
29  virtual void initialize() override;
30  virtual void execute() override;
31  virtual void finalize() override;
33  virtual std::size_t getTotalFeatureCount() const override;
35  // Struct used to transfer minimal data to all ranks
37  {
39  unsigned int id;
40  Point centroid;
42  };
44  struct CacheValues
45  {
46  Real current;
47  Real old;
48  Real older;
49  };
51  enum class RemapCacheMode
52  {
53  FILL,
54  USE,
56  };
58  // GrainTrackerInterface methods
59  virtual Real getEntityValue(dof_id_type node_id,
60  FieldType field_type,
61  std::size_t var_index = 0) const override;
62  virtual const std::vector<unsigned int> &
63  getVarToFeatureVector(dof_id_type elem_id) const override;
64  virtual unsigned int getFeatureVar(unsigned int feature_id) const override;
65  virtual std::size_t getNumberActiveGrains() const override;
66  virtual Point getGrainCentroid(unsigned int grain_id) const override;
67  virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const override;
68  virtual std::vector<unsigned int> getNewGrainIDs() const override;
70 protected:
71  virtual void updateFieldInfo() override;
72  virtual Real getThreshold(std::size_t current_index) const override;
80  void prepopulateState(const FeatureFloodCount & ffc_object);
84  void communicateHaloMap();
90  void assignGrains();
99  void trackGrains();
105  virtual void newGrainCreated(unsigned int new_grain_id);
110  void remapGrains();
123  void computeMinDistancesFromGrain(FeatureData & grain,
124  std::vector<std::list<GrainDistance>> & min_distances);
130  bool attemptGrainRenumber(FeatureData & grain, unsigned int depth, unsigned int max_depth);
137  void swapSolutionValues(FeatureData & grain,
138  std::size_t new_var_index,
139  std::vector<std::map<Node *, CacheValues>> & cache,
140  RemapCacheMode cache_mode);
145  void swapSolutionValuesHelper(Node * curr_node,
146  std::size_t curr_var_index,
147  std::size_t new_var_index,
148  std::vector<std::map<Node *, CacheValues>> & cache,
149  RemapCacheMode cache_mode);
155  Real boundingRegionDistance(std::vector<MeshTools::BoundingBox> & bboxes1,
156  std::vector<MeshTools::BoundingBox> & bboxes2) const;
162  Real centroidRegionDistance(std::vector<MeshTools::BoundingBox> & bboxes1,
163  std::vector<MeshTools::BoundingBox> & bboxes2) const;
170  unsigned int getNextUniqueID();
172  /*************************************************
173  *************** Data Structures *****************
174  ************************************************/
177  const int _tracking_step;
180  const unsigned int _halo_level;
183  static const unsigned int _max_renumbering_recursion = 4;
186  const unsigned short _n_reserve_ops;
190  const std::size_t _reserve_op_index;
196  const bool _remap;
199  NonlinearSystemBase & _nl;
205  std::vector<FeatureData> & _feature_sets_old;
223 private:
228  unsigned int _old_max_grain_id;
231  unsigned int _max_curr_grain_id;
234  const bool _is_transient;
235 };
242 {
243  GrainDistance(Real distance, std::size_t var_index);
245  GrainDistance(Real distance,
246  std::size_t var_index,
247  std::size_t grain_index,
248  unsigned int grain_id);
250  // Copy constructors
251  GrainDistance(const GrainDistance & f) = default;
252  GrainDistance & operator=(const GrainDistance & f) = default;
254  // Move constructors
255  GrainDistance(GrainDistance && f) = default;
256  GrainDistance & operator=(GrainDistance && f) = default;
258  bool operator<(const GrainDistance & rhs) const;
260  Real _distance;
261  std::size_t _var_index;
262  std::size_t _grain_index;
263  unsigned int _grain_id;
264 };
266 template <>
267 void dataStore(std::ostream & stream, GrainTracker::PartialFeatureData & feature, void * context);
268 template <>
269 void dataLoad(std::istream & stream, GrainTracker::PartialFeatureData & feature, void * context);
271 #endif
void remapGrains()
This method is called after trackGrains to remap grains that are too close to each other...
Definition: GrainTracker.C:715
virtual std::size_t getNumberActiveGrains() const override
Returns the number of active grains current stored in the GrainTracker.
Definition: GrainTracker.C:107
virtual const std::vector< unsigned int > & getVarToFeatureVector(dof_id_type elem_id) const override
Returns a list of active unique feature ids for a particular element.
Definition: GrainTracker.C:95
void dataLoad(std::istream &stream, GrainTracker::PartialFeatureData &feature, void *context)
Definition: GrainTracker.C:36
This class defines the interface for the GrainTracking objects.
Real centroidRegionDistance(std::vector< MeshTools::BoundingBox > &bboxes1, std::vector< MeshTools::BoundingBox > &bboxes2) const
This method returns the minimum periodic distance between the centroids of two vectors of bounding bo...
virtual void execute() override
Definition: GrainTracker.C:173
virtual std::size_t getTotalFeatureCount() const override
Returns the total feature count (active and inactive ids, useful for sizing vectors) ...
Definition: GrainTracker.C:114
static const unsigned int _max_renumbering_recursion
Depth of renumbering recursion (a depth of zero means no recursion)
Definition: GrainTracker.h:183
This enumeration is used to indicate status of the grains in the _unique_grains data structure...
void trackGrains()
On subsequent time_steps, incoming FeatureData objects are compared to previous time_step information...
Definition: GrainTracker.C:398
This object provides the base capability for creating proper polycrystal ICs.
unsigned int _old_max_grain_id
The previous max grain id (needed to figure out which ids are new in a given step) ...
Definition: GrainTracker.h:228
void swapSolutionValuesHelper(Node *curr_node, std::size_t curr_var_index, std::size_t new_var_index, std::vector< std::map< Node *, CacheValues >> &cache, RemapCacheMode cache_mode)
Helper method for actually performing the swaps.
virtual void finalize() override
Definition: GrainTracker.C:232
std::size_t _var_index
Definition: GrainTracker.h:261
virtual Real getThreshold(std::size_t current_index) const override
Return the starting comparison threshold to use when inspecting an entity during the flood stage...
Definition: GrainTracker.C:188
This struct is used to hold distance information to other grains in the simulation.
Definition: GrainTracker.h:241
virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature intersects any boundary.
Definition: GrainTracker.C:139
NonlinearSystemBase & _nl
A reference to the nonlinear system (used for retrieving solution vectors)
Definition: GrainTracker.h:199
virtual void updateFieldInfo() override
This method is used to populate any of the data structures used for storing field data (nodal or elem...
std::size_t _grain_index
Definition: GrainTracker.h:262
void communicateHaloMap()
unsigned int _max_curr_grain_id
Holds the next "regular" grain ID (a grain found or remapped to the standard op vars) ...
Definition: GrainTracker.h:231
GrainTracker(const InputParameters &parameters)
Definition: GrainTracker.C:56
unsigned int _grain_id
Definition: GrainTracker.h:263
bool _first_time
Boolean to indicate the first time this object executes.
Definition: GrainTracker.h:214
const PolycrystalUserObjectBase * _poly_ic_uo
An optional IC UserObject which can provide initial data structures to this object.
Definition: GrainTracker.h:208
void prepopulateState(const FeatureFloodCount &ffc_object)
This method extracts the necessary state from the passed in object necessary to continue tracking gra...
Definition: GrainTracker.C:200
void broadcastAndUpdateGrainData()
Broadcast essential Grain information to all processors.
Definition: GrainTracker.C:297
This object will mark nodes or elements of continuous regions all with a unique number for the purpos...
const Real _reserve_op_threshold
The threshold above (or below) where a grain may be found on a reserve op field.
Definition: GrainTracker.h:193
virtual void initialize() override
Definition: GrainTracker.C:155
void computeMinDistancesFromGrain(FeatureData &grain, std::vector< std::list< GrainDistance >> &min_distances)
Populates and sorts a min_distances vector with the minimum distances to all grains in the simulation...
Definition: GrainTracker.C:954
void swapSolutionValues(FeatureData &grain, std::size_t new_var_index, std::vector< std::map< Node *, CacheValues >> &cache, RemapCacheMode cache_mode)
A routine for moving all of the solution values from a given grain to a new variable number...
void dataStore(std::ostream &stream, GrainTracker::PartialFeatureData &feature, void *context)
Definition: GrainTracker.C:26
virtual unsigned int getFeatureVar(unsigned int feature_id) const override
Returns the variable representing the passed in feature.
Definition: GrainTracker.C:101
Real boundingRegionDistance(std::vector< MeshTools::BoundingBox > &bboxes1, std::vector< MeshTools::BoundingBox > &bboxes2) const
This method returns the minimum periodic distance between two vectors of bounding boxes...
virtual Point getGrainCentroid(unsigned int grain_id) const override
Returns the centroid for the given grain number.
Definition: GrainTracker.C:121
const unsigned int _halo_level
The thickness of the halo surrounding each grain.
Definition: GrainTracker.h:180
const bool _remap
Inidicates whether remapping should be done or not (remapping is independent of tracking) ...
Definition: GrainTracker.h:196
bool attemptGrainRenumber(FeatureData &grain, unsigned int depth, unsigned int max_depth)
This is the recursive part of the remapping algorithm.
virtual Real getEntityValue(dof_id_type node_id, FieldType field_type, std::size_t var_index=0) const override
Definition: GrainTracker.C:84
InputParameters validParams< GrainTracker >()
Definition: GrainTracker.C:46
virtual ~GrainTracker()
Definition: GrainTracker.C:81
const bool _is_transient
Boolean to indicate whether this is a Steady or Transient solve.
Definition: GrainTracker.h:234
bool _error_on_grain_creation
Boolean to terminate with an error if a new grain is created during the simulation.
Definition: GrainTracker.h:221
void assignGrains()
When the tracking phase starts (_t_step == _tracking_step) it assigns a unique id to every FeatureDat...
Definition: GrainTracker.C:357
const int _tracking_step
The timestep to begin tracking grains.
Definition: GrainTracker.h:177
unsigned int _reserve_grain_first_index
Holds the first unique grain index when using _reserve_op (all the remaining indices are sequential) ...
Definition: GrainTracker.h:225
const std::size_t _reserve_op_index
The cutoff index where if variable index >= this number, no remapping TO that variable will occur...
Definition: GrainTracker.h:190
std::vector< FeatureData > & _feature_sets_old
This data structure holds the map of unique grains from the previous time step.
Definition: GrainTracker.h:205
virtual void newGrainCreated(unsigned int new_grain_id)
This method is called when a new grain is detected.
Definition: GrainTracker.C:682
unsigned int getNextUniqueID()
Retrieve the next unique grain number if a new grain is detected during trackGrains.
const unsigned short _n_reserve_ops
The number of reserved order parameters.
Definition: GrainTracker.h:186
virtual std::vector< unsigned int > getNewGrainIDs() const override
This method returns all of the new ids generated in an invocation of the GrainTracker.
Definition: GrainTracker.C:703