https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GrainTracker.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#include "FeatureFloodCount.h"
14
15#include "libmesh/bounding_box.h"
16
18struct GrainDistance;
19
21{
22public:
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
43
45 {
46 Real current;
47 Real old;
48 Real older;
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
72protected:
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
201 const Real _bound_value;
202
204 const bool _remap;
205
208
213 std::vector<FeatureData> _feature_sets_old;
214
217
221 const short _verbosity_level;
222
228
235
236private:
239
241 unsigned int _old_max_grain_id;
242
244 unsigned int & _max_curr_grain_id;
245
247 const bool _is_transient;
248
250 std::vector<std::pair<dof_id_type, dof_id_type>> _all_ranges;
251};
252
258{
259 GrainDistance(Real distance, std::size_t var_index);
260
262 std::size_t var_index,
263 std::size_t grain_index,
264 unsigned int grain_id);
265
266 // Copy constructors
267 GrainDistance(const GrainDistance & f) = default;
269
270 // Move constructors
273
274 bool operator<(const GrainDistance & rhs) const;
275
277 std::size_t _var_index;
278 std::size_t _grain_index;
279 unsigned int _grain_id;
280};
281
282template <>
283void dataStore(std::ostream & stream, GrainTracker::PartialFeatureData & feature, void * context);
284template <>
285void dataLoad(std::istream & stream, GrainTracker::PartialFeatureData & feature, void * context);
Real f(Real x)
Test function for Brents method.
void dataLoad(std::istream &stream, GrainTracker::PartialFeatureData &feature, void *context)
void dataStore(std::ostream &stream, GrainTracker::PartialFeatureData &feature, void *context)
This object will mark nodes or elements of continuous regions all with a unique number for the purpos...
Status
This enumeration is used to indicate status of the grains in the _unique_grains data structure.
BoundaryIntersection
This enumeration is used to inidacate status of boundary intersections.
This class defines the interface for the GrainTracking objects.
virtual Real getEntityValue(dof_id_type node_id, FieldType field_type, std::size_t var_index=0) const override
virtual ~GrainTracker()
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.
bool & _first_time
Boolean to indicate the first time this object executes.
void remapGrains()
This method is called after trackGrains to remap grains that are too close to each other.
unsigned int _old_max_grain_id
The previous max grain id (needed to figure out which ids are new in a given step)
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)
static InputParameters validParams()
virtual void execute() override
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.
const bool _error_on_grain_creation
Boolean to terminate with an error if a new grain is created during the simulation.
const PolycrystalUserObjectBase *const _poly_ic_uo
An optional IC UserObject which can provide initial data structures to this object.
virtual void updateFieldInfo() override
This method is used to populate any of the data structures used for storing field data (nodal or elem...
bool attemptGrainRenumber(FeatureData &grain, unsigned int depth, unsigned int max_depth)
This is the recursive part of the remapping algorithm.
const Real _reserve_op_threshold
The threshold above (or below) where a grain may be found on a reserve op field.
Real boundingRegionDistance(std::vector< BoundingBox > &bboxes1, std::vector< BoundingBox > &bboxes2) const
This method returns the minimum periodic distance between two vectors of bounding boxes.
void assignGrains()
When the tracking phase starts (_t_step == _tracking_step) it assigns a unique id to every FeatureDat...
unsigned int & _max_curr_grain_id
Holds the next "regular" grain ID (a grain found or remapped to the standard op vars)
virtual std::vector< unsigned int > getNewGrainIDs() const override
This method returns all of the new ids generated in an invocation of the GrainTracker.
virtual std::size_t getTotalFeatureCount() const override
Returns the total feature count (active and inactive ids, useful for sizing vectors)
const unsigned short _n_reserve_ops
The number of reserved order parameters.
const int _tracking_step
The timestep to begin tracking grains.
unsigned int getNextUniqueID()
Retrieve the next unique grain number if a new grain is detected during trackGrains.
void prepopulateState(const FeatureFloodCount &ffc_object)
This method extracts the necessary state from the passed in object necessary to continue tracking gra...
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.
const bool _remap
Inidicates whether remapping should be done or not (remapping is independent of tracking)
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 communicateHaloMap()
std::vector< FeatureData > _feature_sets_old
This data structure holds the map of unique grains from the previous time step.
void trackGrains()
On subsequent time_steps, incoming FeatureData objects are compared to previous time_step information...
virtual void meshChanged() override
virtual unsigned int getFeatureVar(unsigned int feature_id) const override
Returns the variable representing the passed in feature.
void broadcastAndUpdateGrainData()
Broadcast essential Grain information to all processors.
virtual void initialize() override
virtual Point getGrainCentroid(unsigned int grain_id) const override
Returns the centroid for the given grain number.
const Real _bound_value
Absolute value of the lower bound used to represent a region not assigned to this grain,...
const std::size_t _reserve_op_index
The cutoff index where if variable index >= this number, no remapping TO that variable will occur.
virtual std::size_t getNumberActiveGrains() const override
Returns the number of active grains current stored in the GrainTracker.
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...
const bool _is_transient
Boolean to indicate whether this is a Steady or Transient solve.
const short _verbosity_level
Verbosity level controlling the amount of information printed to the console.
const unsigned short _max_remap_recursion_depth
Depth of renumbering recursion (a depth of zero means no recursion)
virtual void finalize() override
virtual bool isFeaturePercolated(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature is percolated (e.g.
virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature intersects any boundary.
const bool _tolerate_failure
Indicates whether we should continue after a remap failure (will result in non-physical results)
virtual void newGrainCreated(unsigned int new_grain_id)
This method is called when a new grain is detected.
unsigned int _reserve_grain_first_index
Holds the first unique grain index when using _reserve_op (all the remaining indices are sequential)
virtual bool doesFeatureIntersectSpecifiedBoundary(unsigned int feature_id) const override
Returns a Boolean indicating whether this feature intersects boundaries in a user-supplied list.
const unsigned short _halo_level
The thickness of the halo surrounding each grain.
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...
const InputParameters & parameters() const
This object provides the base capability for creating proper polycrystal ICs.
This struct is used to hold distance information to other grains in the simulation.
bool operator<(const GrainDistance &rhs) const
GrainDistance(GrainDistance &&f)=default
GrainDistance(const GrainDistance &f)=default
GrainDistance & operator=(const GrainDistance &f)=default
GrainDistance & operator=(GrainDistance &&f)=default
unsigned int _grain_id
std::size_t _grain_index
std::size_t _var_index
BoundaryIntersection boundary_intersection
Real distance(const Point &p)