www.mooseframework.org
GrainTracker.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 "FeatureFloodCount.h"
13 #include "GrainTrackerInterface.h"
14 
15 #include "libmesh/bounding_box.h"
16 
18 struct GrainDistance;
19 
21 {
22 public:
24 
26  virtual ~GrainTracker();
27 
28  virtual void meshChanged() override;
29  virtual void initialize() override;
30  virtual void execute() override;
31  virtual void finalize() override;
32 
33  virtual std::size_t getTotalFeatureCount() const override;
34 
35  // Struct used to transfer minimal data to all ranks
37  {
39  unsigned int id;
40  Point centroid;
42  };
43 
44  struct CacheValues
45  {
49  };
50 
51  enum class RemapCacheMode
52  {
53  FILL,
54  USE,
55  BYPASS
56  };
57 
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 bool doesFeatureIntersectSpecifiedBoundary(unsigned int feature_id) const override;
69  virtual bool isFeaturePercolated(unsigned int feature_id) const override;
70  virtual std::vector<unsigned int> getNewGrainIDs() const override;
71 
72 protected:
73  virtual void updateFieldInfo() override;
74  virtual Real getThreshold(std::size_t current_index) const override;
75 
82  void prepopulateState(const FeatureFloodCount & ffc_object);
83 
86  void communicateHaloMap();
87 
92  void assignGrains();
93 
101  void trackGrains();
102 
107  virtual void newGrainCreated(unsigned int new_grain_id);
108 
112  void remapGrains();
113 
119 
125  void computeMinDistancesFromGrain(FeatureData & grain,
126  std::vector<std::list<GrainDistance>> & min_distances);
127 
132  bool attemptGrainRenumber(FeatureData & grain, unsigned int depth, unsigned int max_depth);
133 
139  void swapSolutionValues(FeatureData & grain,
140  std::size_t new_var_index,
141  std::vector<std::map<Node *, CacheValues>> & cache,
142  RemapCacheMode cache_mode);
143 
147  void swapSolutionValuesHelper(Node * curr_node,
148  std::size_t curr_var_index,
149  std::size_t new_var_index,
150  std::vector<std::map<Node *, CacheValues>> & cache,
151  RemapCacheMode cache_mode);
152 
157  Real boundingRegionDistance(std::vector<BoundingBox> & bboxes1,
158  std::vector<BoundingBox> & bboxes2) const;
159 
164  Real centroidRegionDistance(std::vector<BoundingBox> & bboxes1,
165  std::vector<BoundingBox> & bboxes2) const;
166 
172  unsigned int getNextUniqueID();
173 
174  /*************************************************
175  *************** Data Structures *****************
176  ************************************************/
177 
179  const int _tracking_step;
180 
182  const unsigned short _halo_level;
183 
185  const unsigned short _max_remap_recursion_depth;
186 
188  const unsigned short _n_reserve_ops;
189 
192  const std::size_t _reserve_op_index;
193 
196 
202 
204  const bool _remap;
205 
207  const bool _tolerate_failure;
208 
211 
216  std::vector<FeatureData> _feature_sets_old;
217 
220 
224  const short _verbosity_level;
225 
230  bool & _first_time;
231 
238 
239 private:
242 
244  unsigned int _old_max_grain_id;
245 
247  unsigned int & _max_curr_grain_id;
248 
250  const bool _is_transient;
251 
253  std::vector<std::pair<dof_id_type, dof_id_type>> _all_ranges;
254 };
255 
261 {
262  GrainDistance(Real distance, std::size_t var_index);
263 
265  std::size_t var_index,
266  std::size_t grain_index,
267  unsigned int grain_id);
268 
269  // Copy constructors
270  GrainDistance(const GrainDistance & f) = default;
271  GrainDistance & operator=(const GrainDistance & f) = default;
272 
273  // Move constructors
274  GrainDistance(GrainDistance && f) = default;
275  GrainDistance & operator=(GrainDistance && f) = default;
276 
277  bool operator<(const GrainDistance & rhs) const;
278 
280  std::size_t _var_index;
281  std::size_t _grain_index;
282  unsigned int _grain_id;
283 };
284 
285 template <>
286 void dataStore(std::ostream & stream, GrainTracker::PartialFeatureData & feature, void * context);
287 template <>
288 void dataLoad(std::istream & stream, GrainTracker::PartialFeatureData & feature, void * context);
void remapGrains()
This method is called after trackGrains to remap grains that are too close to each other...
Definition: GrainTracker.C:910
virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature intersects any boundary.
Definition: GrainTracker.C:175
void dataLoad(std::istream &stream, GrainTracker::PartialFeatureData &feature, void *context)
Definition: GrainTracker.C:38
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:898
This class defines the interface for the GrainTracking objects.
virtual void execute() override
Definition: GrainTracker.C:273
virtual bool isFeaturePercolated(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature is percolated (e.g.
Definition: GrainTracker.C:208
virtual void meshChanged() override
Definition: GrainTracker.C:248
Status
This enumeration is used to indicate status of the grains in the _unique_grains data structure...
bool & _first_time
Boolean to indicate the first time this object executes.
Definition: GrainTracker.h:230
std::vector< FeatureData > _feature_sets_old
This data structure holds the map of unique grains from the previous time step.
Definition: GrainTracker.h:216
const bool _error_on_grain_creation
Boolean to terminate with an error if a new grain is created during the simulation.
Definition: GrainTracker.h:237
void trackGrains()
On subsequent time_steps, incoming FeatureData objects are compared to previous time_step information...
Definition: GrainTracker.C:499
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:244
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:330
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:247
virtual std::size_t getTotalFeatureCount() const override
Returns the total feature count (active and inactive ids, useful for sizing vectors) ...
Definition: GrainTracker.C:150
Real distance(const Point &p)
std::size_t _var_index
Definition: GrainTracker.h:280
const PolycrystalUserObjectBase *const _poly_ic_uo
An optional IC UserObject which can provide initial data structures to this object.
Definition: GrainTracker.h:219
Real centroidRegionDistance(std::vector< BoundingBox > &bboxes1, std::vector< BoundingBox > &bboxes2) const
This method returns the minimum periodic distance between the centroids of two vectors of bounding bo...
This struct is used to hold distance information to other grains in the simulation.
Definition: GrainTracker.h:260
NonlinearSystemBase & _nl
A reference to the nonlinear system (used for retrieving solution vectors)
Definition: GrainTracker.h:210
Real boundingRegionDistance(std::vector< BoundingBox > &bboxes1, std::vector< BoundingBox > &bboxes2) const
This method returns the minimum periodic distance between two vectors of bounding boxes...
virtual void updateFieldInfo() override
This method is used to populate any of the data structures used for storing field data (nodal or elem...
const Real _bound_value
Absolute value of the lower bound used to represent a region not assigned to this grain...
Definition: GrainTracker.h:201
std::size_t _grain_index
Definition: GrainTracker.h:281
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:131
void communicateHaloMap()
GrainTracker(const InputParameters &parameters)
Definition: GrainTracker.C:84
unsigned int _grain_id
Definition: GrainTracker.h:282
BoundaryIntersection boundary_intersection
Definition: GrainTracker.h:38
GrainDistance & operator=(const GrainDistance &f)=default
Real f(Real x)
Test function for Brents method.
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:298
void broadcastAndUpdateGrainData()
Broadcast essential Grain information to all processors.
Definition: GrainTracker.C:388
GrainDistance(Real distance, std::size_t var_index)
BoundaryIntersection
This enumeration is used to inidacate status of boundary intersections.
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:195
virtual void initialize() override
Definition: GrainTracker.C:230
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...
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...
const short _verbosity_level
Verbosity level controlling the amount of information printed to the console.
Definition: GrainTracker.h:224
void dataStore(std::ostream &stream, GrainTracker::PartialFeatureData &feature, void *context)
Definition: GrainTracker.C:28
virtual std::size_t getNumberActiveGrains() const override
Returns the number of active grains current stored in the GrainTracker.
Definition: GrainTracker.C:143
std::vector< std::pair< dof_id_type, dof_id_type > > _all_ranges
Data structure to hold element ID ranges when using Distributed Mesh (populated on rank 0 only) ...
Definition: GrainTracker.h:253
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const bool _remap
Inidicates whether remapping should be done or not (remapping is independent of tracking) ...
Definition: GrainTracker.h:204
bool attemptGrainRenumber(FeatureData &grain, unsigned int depth, unsigned int max_depth)
This is the recursive part of the remapping algorithm.
static InputParameters validParams()
Definition: GrainTracker.C:49
virtual ~GrainTracker()
Definition: GrainTracker.C:117
const bool _is_transient
Boolean to indicate whether this is a Steady or Transient solve.
Definition: GrainTracker.h:250
virtual bool doesFeatureIntersectSpecifiedBoundary(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature intersects boundaries in a user-supplied list...
Definition: GrainTracker.C:191
const InputParameters & parameters() const
void assignGrains()
When the tracking phase starts (_t_step == _tracking_step) it assigns a unique id to every FeatureDat...
Definition: GrainTracker.C:451
bool operator<(const GrainDistance &rhs) const
const int _tracking_step
The timestep to begin tracking grains.
Definition: GrainTracker.h:179
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:241
virtual Real getEntityValue(dof_id_type node_id, FieldType field_type, std::size_t var_index=0) const override
Definition: GrainTracker.C:120
const unsigned short _halo_level
The thickness of the halo surrounding each grain.
Definition: GrainTracker.h:182
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:192
const unsigned short _max_remap_recursion_depth
Depth of renumbering recursion (a depth of zero means no recursion)
Definition: GrainTracker.h:185
virtual Point getGrainCentroid(unsigned int grain_id) const override
Returns the centroid for the given grain number.
Definition: GrainTracker.C:157
virtual unsigned int getFeatureVar(unsigned int feature_id) const override
Returns the variable representing the passed in feature.
Definition: GrainTracker.C:137
virtual void newGrainCreated(unsigned int new_grain_id)
This method is called when a new grain is detected.
Definition: GrainTracker.C:877
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:286
const bool _tolerate_failure
Indicates whether we should continue after a remap failure (will result in non-physical results) ...
Definition: GrainTracker.h:207
unsigned int getNextUniqueID()
Retrieve the next unique grain number if a new grain is detected during trackGrains.
uint8_t dof_id_type
const unsigned short _n_reserve_ops
The number of reserved order parameters.
Definition: GrainTracker.h:188