www.mooseframework.org
LatticeSmoothCircleIC.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 #include "MooseMesh.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<SmoothCircleBaseIC>();
16  params.addClassDescription("Perturbed square lattice of smooth circles");
17  params.addDeprecatedParam<Real>("Rnd_variation",
18  "Variation from central lattice position",
19  "use the new parameter name pos_variation");
20  params.addParam<Real>("pos_variation", 0.0, "Variation from central lattice position");
21  params.addRequiredParam<std::vector<unsigned int>>(
22  "circles_per_side", "Vector containing the number of bubbles along each side");
23  params.addParam<unsigned int>("rand_seed", 2000, "random seed");
24  params.addRequiredParam<Real>("radius", "Mean radius value for the circels");
25  params.addParam<Real>(
26  "radius_variation", 0.0, "Plus or minus fraction of random variation in the bubble radius");
27  MooseEnum rand_options("uniform normal none", "none");
28  params.addParam<MooseEnum>("radius_variation_type",
29  rand_options,
30  "Type of distribution that random circle radii will follow");
31  params.addParam<bool>(
32  "avoid_bounds", true, "Don't place any bubbles on the simulation cell boundaries");
33  return params;
34 }
35 
36 LatticeSmoothCircleIC::LatticeSmoothCircleIC(const InputParameters & parameters)
37  : SmoothCircleBaseIC(parameters),
38  _lattice_variation(isParamValid("Rnd_variation") ? getParam<Real>("Rnd_variation")
39  : getParam<Real>("pos_variation")),
40  _circles_per_side(getParam<std::vector<unsigned int>>("circles_per_side")),
41  _radius(getParam<Real>("radius")),
42  _radius_variation(getParam<Real>("radius_variation")),
43  _radius_variation_type(getParam<MooseEnum>("radius_variation_type")),
44  _avoid_bounds(getParam<bool>("avoid_bounds"))
45 {
46 }
47 
48 void
50 {
51  // pad circles per side vector to size 3 (with 0)
52  _circles_per_side.resize(3);
53 
54  // Set up domain bounds with mesh tools
55  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
56  {
57  _bottom_left(i) = _mesh.getMinInDimension(i);
58  _top_right(i) = _mesh.getMaxInDimension(i);
59  }
61 
62  // Error checks
63  if (_range(0) != 0.0 && _range(1) != 0.0 && _circles_per_side[1] == 0)
64  mooseError("If domain is > 1D, circles_per_side must have more than one value");
65 
66  if (_range(2) != 0.0 && _circles_per_side[2] == 0)
67  mooseError("If domain is 3D, circles_per_side must have three values");
68 
69  if (_range(1) == 0.0 && _range(2) == 0.0)
70  {
71  _circles_per_side[1] = 0;
72  _circles_per_side[2] = 0;
73  }
74 
75  // Set _numbub
76  if (_range(2) == 0.0)
77  {
78  _circles_per_side[2] = 0;
80  }
81  else
83 
84  switch (_radius_variation_type)
85  {
86  case 2: // No variation
87  if (_radius_variation > 0.0)
88  mooseError("If radius_variation > 0.0, you must pass in a radius_variation_type in "
89  "LatticeSmoothCircleIC");
90  break;
91  }
93 }
94 
95 void
97 {
98  _radii.resize(_numbub);
99 
100  for (unsigned int i = 0; i < _numbub; i++)
101  {
102  // Vary bubble radius
103  switch (_radius_variation_type)
104  {
105  case 0: // Uniform distrubtion
106  _radii[i] = _radius * (1.0 + (1.0 - 2.0 * _random.rand(_tid)) * _radius_variation);
107  break;
108  case 1: // Normal distribution
109  _radii[i] = _random.randNormal(_tid, _radius, _radius_variation);
110  break;
111  case 2: // No variation
112  _radii[i] = _radius;
113  }
114 
115  if (_radii[i] < 0.0)
116  _radii[i] = 0.0;
117  }
118 }
119 
120 void
122 {
123  _centers.resize(_numbub);
124 
125  Real x_sep = _range(0) / _circles_per_side[0];
126  Real y_sep = _range(1) / _circles_per_side[1];
127 
128  Real z_sep = 0.0;
129  unsigned int z_num = 1.0;
130 
131  if (_range(2) > 0.0)
132  {
133  z_sep = _range(2) / _circles_per_side[2];
134  z_num = _circles_per_side[2];
135  }
136 
137  unsigned int cnt = 0;
138  for (unsigned int i = 0; i < _circles_per_side[0]; ++i)
139  for (unsigned int j = 0; j < _circles_per_side[1]; ++j)
140  for (unsigned int k = 0; k < z_num; ++k)
141  {
142  Real xx = x_sep / 2.0 + i * x_sep;
143  Real yy = y_sep / 2.0 + j * y_sep;
144  Real zz = z_sep / 2.0 + k * z_sep;
145 
146  // Vary circle position
147  xx = xx + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
148  yy = yy + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
149 
150  if (_range(2) != 0.0)
151  zz = zz + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
152 
153  // Verify not out of bounds
154  if (_avoid_bounds && xx < _radii[cnt] + _int_width)
155  xx = _radii[cnt] + _int_width;
156  if (_avoid_bounds && xx > _range(0) - (_radii[cnt] + _int_width))
157  xx = _range(0) - (_radii[cnt] + _int_width);
158  if (_avoid_bounds && yy < _radii[cnt] + _int_width)
159  yy = _radii[cnt] + _int_width;
160  if (_avoid_bounds && yy > _range(1) - (_radii[cnt] + _int_width))
161  yy = _range(1) - (_radii[cnt] + _int_width);
162  if (_range(2) != 0.0)
163  {
164  if (_avoid_bounds && zz < _radii[cnt] + _int_width)
165  zz = _radii[cnt] + _int_width;
166  if (_avoid_bounds && zz > _range(2) - (_radii[cnt] + _int_width))
167  zz = _range(2) - (_radii[cnt] + _int_width);
168  }
169 
170  _centers[cnt](0) = xx;
171  _centers[cnt](1) = yy;
172  _centers[cnt](2) = zz;
173 
174  cnt++;
175  }
176 }
std::vector< unsigned int > _circles_per_side
std::vector< Real > _radii
std::vector< Point > _centers
virtual void computeCircleCenters()
InputParameters validParams< LatticeSmoothCircleIC >()
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
virtual void initialSetup()
InputParameters validParams< SmoothCircleBaseIC >()
virtual void computeCircleRadii()
LatticeSmoothCircleIC(const InputParameters &parameters)