www.mooseframework.org
LatticeSmoothCircleIC.C
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 #include "LatticeSmoothCircleIC.h"
11 #include "MooseMesh.h"
12 
14 
17 {
19  params.addClassDescription("Perturbed square lattice of smooth circles");
20  params.addDeprecatedParam<Real>("Rnd_variation",
21  "Variation from central lattice position",
22  "use the new parameter name pos_variation");
23  params.addParam<Real>("pos_variation", 0.0, "Variation from central lattice position");
24  params.addRequiredParam<std::vector<unsigned int>>(
25  "circles_per_side", "Vector containing the number of bubbles along each side");
26  params.addParam<unsigned int>("rand_seed", 2000, "random seed");
27  params.addRequiredParam<Real>("radius", "Mean radius value for the circles");
28  params.addParam<Real>(
29  "radius_variation", 0.0, "Plus or minus fraction of random variation in the bubble radius");
30  MooseEnum rand_options("uniform normal none", "none");
31  params.addParam<MooseEnum>("radius_variation_type",
32  rand_options,
33  "Type of distribution that random circle radii will follow");
34  params.addParam<bool>(
35  "avoid_bounds", true, "Don't place any bubbles on the simulation cell boundaries");
36  return params;
37 }
38 
40  : SmoothCircleBaseIC(parameters),
41  _lattice_variation(isParamValid("Rnd_variation") ? getParam<Real>("Rnd_variation")
42  : getParam<Real>("pos_variation")),
43  _circles_per_side(getParam<std::vector<unsigned int>>("circles_per_side")),
44  _radius(getParam<Real>("radius")),
45  _radius_variation(getParam<Real>("radius_variation")),
46  _radius_variation_type(getParam<MooseEnum>("radius_variation_type")),
47  _avoid_bounds(getParam<bool>("avoid_bounds"))
48 {
49 }
50 
51 void
53 {
54  // pad circles per side vector to size 3 (with 0)
55  _circles_per_side.resize(3);
56 
57  // Set up domain bounds with mesh tools
58  for (const auto i : make_range(Moose::dim))
59  {
62  }
64 
65  // Error checks
66  if (_range(0) != 0.0 && _range(1) != 0.0 && _circles_per_side[1] == 0)
67  mooseError("If domain is > 1D, circles_per_side must have more than one value");
68 
69  if (_range(2) != 0.0 && _circles_per_side[2] == 0)
70  mooseError("If domain is 3D, circles_per_side must have three values");
71 
72  if (_range(1) == 0.0 && _range(2) == 0.0)
73  {
74  _circles_per_side[1] = 0;
75  _circles_per_side[2] = 0;
76  }
77 
78  // Set _numbub
79  if (_range(2) == 0.0)
80  {
81  _circles_per_side[2] = 0;
83  }
84  else
86 
87  switch (_radius_variation_type)
88  {
89  case 2: // No variation
90  if (_radius_variation > 0.0)
91  mooseError("If radius_variation > 0.0, you must pass in a radius_variation_type in "
92  "LatticeSmoothCircleIC");
93  break;
94  }
96 }
97 
98 void
100 {
101  _radii.resize(_numbub);
102 
103  for (unsigned int i = 0; i < _numbub; i++)
104  {
105  // Vary bubble radius
106  switch (_radius_variation_type)
107  {
108  case 0: // Uniform distrubtion
109  _radii[i] = _radius * (1.0 + (1.0 - 2.0 * _random.rand(_tid)) * _radius_variation);
110  break;
111  case 1: // Normal distribution
113  break;
114  case 2: // No variation
115  _radii[i] = _radius;
116  }
117 
118  if (_radii[i] < 0.0)
119  _radii[i] = 0.0;
120  }
121 }
122 
123 void
125 {
126  _centers.resize(_numbub);
127 
128  Real x_sep = _range(0) / _circles_per_side[0];
129  Real y_sep = _range(1) / _circles_per_side[1];
130 
131  Real z_sep = 0.0;
132  unsigned int z_num = 1.0;
133 
134  if (_range(2) > 0.0)
135  {
136  z_sep = _range(2) / _circles_per_side[2];
137  z_num = _circles_per_side[2];
138  }
139 
140  unsigned int cnt = 0;
141  for (unsigned int i = 0; i < _circles_per_side[0]; ++i)
142  for (unsigned int j = 0; j < _circles_per_side[1]; ++j)
143  for (unsigned int k = 0; k < z_num; ++k)
144  {
145  Real xx = x_sep / 2.0 + i * x_sep;
146  Real yy = y_sep / 2.0 + j * y_sep;
147  Real zz = z_sep / 2.0 + k * z_sep;
148 
149  // Vary circle position
150  xx = xx + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
151  yy = yy + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
152 
153  if (_range(2) != 0.0)
154  zz = zz + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
155 
156  // Verify not out of bounds
157  if (_avoid_bounds && xx < _radii[cnt] + _int_width)
158  xx = _radii[cnt] + _int_width;
159  if (_avoid_bounds && xx > _range(0) - (_radii[cnt] + _int_width))
160  xx = _range(0) - (_radii[cnt] + _int_width);
161  if (_avoid_bounds && yy < _radii[cnt] + _int_width)
162  yy = _radii[cnt] + _int_width;
163  if (_avoid_bounds && yy > _range(1) - (_radii[cnt] + _int_width))
164  yy = _range(1) - (_radii[cnt] + _int_width);
165  if (_range(2) != 0.0)
166  {
167  if (_avoid_bounds && zz < _radii[cnt] + _int_width)
168  zz = _radii[cnt] + _int_width;
169  if (_avoid_bounds && zz > _range(2) - (_radii[cnt] + _int_width))
170  zz = _range(2) - (_radii[cnt] + _int_width);
171  }
172 
173  _centers[cnt](0) = xx;
174  _centers[cnt](1) = yy;
175  _centers[cnt](2) = zz;
176 
177  cnt++;
178  }
179 }
static InputParameters validParams()
virtual Real getMaxInDimension(unsigned int component) const
virtual Real getMinInDimension(unsigned int component) const
std::vector< unsigned int > _circles_per_side
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObject("PhaseFieldApp", LatticeSmoothCircleIC)
std::vector< Real > _radii
std::vector< Point > _centers
virtual void computeCircleCenters()
static constexpr std::size_t dim
void addRequiredParam(const std::string &name, const std::string &doc_string)
Real randNormal(std::size_t i, Real mean, Real sigma)
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
virtual void initialSetup()
static InputParameters validParams()
LatticeSmoothcircleIC creates a lattice of smoothcircles as an initial condition. ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeCircleRadii()
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
Real rand(std::size_t i)
LatticeSmoothCircleIC(const InputParameters &parameters)
static const std::string k
Definition: NS.h:124
void ErrorVector unsigned int