11 #include "IndirectSort.h"
12 #include "MooseRandom.h"
13 #include "MooseMesh.h"
14 #include "MooseVariable.h"
15 #include "NonlinearSystemBase.h"
16 #include "DelimitedFileReader.h"
25 params.addClassDescription(
26 "Random Voronoi tessellation polycrystal (used by PolycrystalVoronoiAction)");
27 params.addParam<
unsigned int>(
28 "grain_num", 0,
"Number of grains being represented by the order parameters");
29 params.addParam<
unsigned int>(
"rand_seed", 0,
"The random seed");
30 params.addParam<
bool>(
31 "columnar_3D",
false,
"3D microstructure will be columnar in the z-direction?");
32 params.addParam<FileName>(
35 "File containing grain centroids, if file_name is provided, the centroids "
36 "from the file will be used.");
37 params.addParam<Real>(
"int_width", 0.0,
"Width of diffuse interfaces");
43 _grain_num(getParam<unsigned int>(
"grain_num")),
44 _columnar_3D(getParam<bool>(
"columnar_3D")),
45 _rand_seed(getParam<unsigned int>(
"rand_seed")),
46 _int_width(getParam<Real>(
"int_width")),
47 _file_name(getParam<FileName>(
"file_name"))
50 mooseError(
"grain_num must be provided if the grain centroids are not read from a file");
53 mooseWarning(
"grain_num is ignored and will be determined from the file.");
58 std::vector<unsigned int> & grains)
const
61 Real d_min =
_range.norm();
64 auto min_index = n_grains;
67 for (MooseIndex(
_centerpoints) grain = 0; grain < n_grains; ++grain)
76 mooseAssert(min_index < n_grains,
"Couldn't find closest Voronoi cell");
78 grains.push_back(min_index);
81 for (MooseIndex(
_centerpoints) grain = 0; grain < n_grains; ++grain)
82 if (grain != min_index)
87 distance = N * (cntr - point);
89 grains.push_back(grain);
96 std::vector<unsigned int> grain_ids;
101 for (
auto grain_id : grain_ids)
104 active_grain_on_op = grain_id;
108 Real profile_val = 0.0;
119 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
128 MooseUtils::DelimitedFileReader txt_reader(
_file_name, &_communicator);
131 std::vector<std::string> col_names = txt_reader.getNames();
132 std::vector<std::vector<Real>> data = txt_reader.getData();
136 for (
unsigned int i = 0; i < col_names.size(); ++i)
140 paramError(
"Columns in ",
_file_name,
" do not have uniform lengths.");
143 for (
unsigned int grain = 0; grain <
_grain_num; ++grain)
147 if (col_names.size() > 2)
164 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
174 const unsigned int & gr_index,
175 const std::vector<unsigned int> & grain_ids)
const
179 for (
auto i : grain_ids)
185 for (
unsigned int vcomp = 0; vcomp < 3; ++vcomp)
189 val *= 0.5 * (1.0 - std::tanh(2.0 * (point(vcomp) - L) * N(vcomp) /
_int_width));
199 Point pa = point +
_mesh.minPeriodicVector(
_vars[0]->number(), point, p1);
200 Point pb = point +
_mesh.minPeriodicVector(
_vars[0]->number(), point, p2);
208 Point pa = point +
_mesh.minPeriodicVector(
_vars[0]->number(), point, p1);
209 Point pb = point +
_mesh.minPeriodicVector(
_vars[0]->number(), point, p2);
210 return 0.5 * (pa + pb);
217 const unsigned int vcomp)
const
219 const Real l_sum = N((vcomp + 1) % 3) * (point((vcomp + 1) % 3) - cntr((vcomp + 1) % 3)) +
220 N((vcomp + 2) % 3) * (point((vcomp + 2) % 3) - cntr((vcomp + 2) % 3));
222 return cntr(vcomp) - l_sum / N(vcomp);