25 "Random Voronoi tessellation polycrystal (used by PolycrystalVoronoiAction)");
27 "grain_num", 0,
"Number of grains being represented by the order parameters");
28 params.
addParam<
unsigned int>(
"rand_seed", 0,
"The random seed");
30 "columnar_3D",
false,
"3D microstructure will be columnar in the z-direction?");
32 "use_kdtree",
false,
"Whether or not to use a KD tree to speedup grain search");
35 "point_patch_size > 0",
36 "How many nearest points KDTree should return");
39 "grain_patch_size > 0",
40 "How many nearest grains KDTree should return");
44 "File containing grain centroids, if file_name is provided, the centroids " 45 "from the file will be used.");
46 params.
addParam<
Real>(
"int_width", 0.0,
"Width of diffuse interfaces");
52 _grain_num(getParam<unsigned
int>(
"grain_num")),
53 _columnar_3D(getParam<bool>(
"columnar_3D")),
54 _rand_seed(getParam<unsigned
int>(
"rand_seed")),
55 _int_width(getParam<
Real>(
"int_width")),
56 _file_name(getParam<FileName>(
"file_name")),
58 _use_kdtree(getParam<bool>(
"use_kdtree")),
59 _point_patch_size(getParam<unsigned
int>(
"point_patch_size")),
60 _grain_patch_size(getParam<unsigned
int>(
"grain_patch_size"))
63 mooseError(
"grain_num must be provided if the grain centroids are not read from a file");
66 mooseWarning(
"grain_num is ignored and will be determined from the file.");
71 std::vector<unsigned int> & grains)
const 77 auto min_index = n_grains;
81 mooseAssert(
_kd_tree,
"KD tree is not constructed yet");
83 "The number of grain global IDs does not match that of new center points");
92 d_min = return_dist_sqr[0];
99 if (d_min > return_dist_sqr[i])
102 d_min = return_dist_sqr[i];
104 else if (d_min == return_dist_sqr[i])
114 for (MooseIndex(
_centerpoints) grain = 0; grain < n_grains; ++grain)
125 mooseAssert(min_index < n_grains,
"Couldn't find closest Voronoi cell");
127 grains.push_back(min_index);
134 "Number of neighboring grains should not exceed number of global grains");
139 std::set<dof_id_type> neighbor_grains;
144 for (
auto it = neighbor_grains.begin(); it != neighbor_grains.end(); ++it)
145 if ((*it) != min_index)
152 grains.push_back(*it);
157 for (MooseIndex(
_centerpoints) grain = 0; grain < n_grains; ++grain)
158 if (grain != min_index)
165 grains.push_back(grain);
174 std::vector<unsigned int> grain_ids;
179 for (
auto grain_id : grain_ids)
182 active_grain_on_op = grain_id;
186 Real profile_val = 0.0;
209 std::vector<std::string> col_names = txt_reader.
getNames();
210 std::vector<std::vector<Real>> data = txt_reader.
getData();
214 for (
unsigned int i = 0; i < col_names.size(); ++i)
221 for (
unsigned int grain = 0; grain <
_grain_num; ++grain)
225 if (col_names.size() > 2)
268 std::vector<std::vector<Real>> xyzs(LIBMESH_DIM);
272 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
276 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
277 xyzs[i].push_back(point(i));
283 xyzs[i].push_back(point(i) <= midplane(i) ? point(i) +
_range(i) : point(i) -
_range(i));
286 for (
auto x : xyzs[0])
287 for (
auto y : xyzs[1])
288 for (
auto z : xyzs[2])
305 const unsigned int & gr_index,
306 const std::vector<unsigned int> & grain_ids)
const 310 for (
auto i : grain_ids)
316 for (
unsigned int vcomp = 0; vcomp < 3; ++vcomp)
320 val *= 0.5 * (1.0 - std::tanh(2.0 * (point(vcomp) - L) *
N(vcomp) /
_int_width));
341 return 0.5 * (pa + pb);
348 const unsigned int vcomp)
const 350 const Real l_sum =
N((vcomp + 1) % 3) * (point((vcomp + 1) % 3) - cntr((vcomp + 1) % 3)) +
351 N((vcomp + 2) % 3) * (point((vcomp + 2) % 3) - cntr((vcomp + 2) % 3));
353 return cntr(vcomp) - l_sum /
N(vcomp);
virtual Real getMaxInDimension(unsigned int component) const
virtual void getGrainsBasedOnPoint(const Point &point, std::vector< unsigned int > &grains) const override
Method for retrieving active grain IDs based on some point in the mesh.
virtual Real getMinInDimension(unsigned int component) const
std::map< unsigned int, unsigned int > _grain_to_op
A map of the grain_id to op.
const std::vector< std::vector< double > > & getData() const
const FileName _file_name
static InputParameters validParams()
RealVectorValue minPeriodicVector(unsigned int nonlinear_var_num, Point p, Point q) const
void seed(std::size_t i, unsigned int seed)
std::vector< Point > _new_points
Original grain center points and duplicated grain center points.
bool isTranslatedPeriodic(unsigned int nonlinear_var_num, unsigned int component) const
virtual Real getVariableValue(unsigned int op_index, const Point &p) const override
Returns the variable value for a given op_index and mesh point.
static constexpr std::size_t dim
Point findCenterPoint(const Point &point, const Point &p1, const Point &p2) const
std::vector< Point > _centerpoints
This object provides the base capability for creating proper polycrystal ICs.
const std::vector< double > y
std::vector< dof_id_type > _grain_gtl_ids
The domain is extended to consider periodic boundary conditions.
const Parallel::Communicator & _communicator
Real distance(const Point &p)
void mooseWarning(Args &&... args) const
Real computeDiffuseInterface(const Point &point, const unsigned int &gr_index, const std::vector< unsigned int > &grain_ids) const
Point findNormalVector(const Point &point, const Point &p1, const Point &p2) const
std::vector< MooseVariable * > _vars
The vector of coupled in variables cast to MooseVariable.
const std::vector< double > x
virtual unsigned int dimension() const
PolycrystalVoronoi(const InputParameters ¶meters)
unsigned int getMaxLeafSize() const
Real findLinePoint(const Point &point, const Point &N, const Point &cntr, const unsigned int dim) const
static const unsigned int invalid_id
void paramError(const std::string ¶m, Args... args) const
Real minPeriodicDistance(unsigned int nonlinear_var_num, Point p, Point q) const
const std::vector< std::string > & getNames() const
std::unique_ptr< KDTree > _kd_tree
KD tree that is used to speedup grain search.
registerMooseObject("PhaseFieldApp", PolycrystalVoronoi)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void precomputeGrainStructure() override
This callback is triggered after the object is initialized and may be optionally overridden to do pre...
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
unsigned int _grain_patch_size
The number of neighboring grains.
bool _use_kdtree
Whether or not to use a KD tree to speedup grain search.
const unsigned int _rand_seed
MooseMesh & _mesh
A reference to the mesh.
MooseUnits pow(const MooseUnits &, int)
unsigned int _grain_num
The number of grains to create.
void ErrorVector unsigned int
static InputParameters validParams()
unsigned int _point_patch_size
The number of nearest points.