www.mooseframework.org
BimodalSuperellipsoidsIC.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 
10 // MOOSE includes
11 #include "MooseMesh.h"
12 #include "MooseVariable.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<SpecifiedSmoothSuperellipsoidIC>();
19  params.addClassDescription("Bimodal size distribution of large particles (specified in input "
20  "file) and small particles (placed randomly outside the larger "
21  "particles)");
22  params.addRequiredParam<unsigned int>("npart", "The number of random (small) particles to place");
23  params.addRequiredParam<Real>(
24  "small_spac",
25  "minimum spacing between small particles, measured from closest edge to closest edge");
26  params.addRequiredParam<Real>("large_spac",
27  "minimum spacing between large and small particles, "
28  "measured from closest edge to closest edge");
29  params.addRequiredParam<Real>(
30  "small_a", "Mean semiaxis a value for the randomly placed (small) superellipsoids");
31  params.addRequiredParam<Real>(
32  "small_b", "Mean semiaxis b value for the randomly placed (small) superellipsoids");
33  params.addRequiredParam<Real>(
34  "small_c", "Mean semiaxis c value for the randomly placed (small) superellipsoids");
35  params.addRequiredParam<Real>("small_n",
36  "Exponent n for the randomly placed (small) superellipsoids");
37  params.addParam<Real>("size_variation",
38  0.0,
39  "Plus or minus fraction of random variation in the "
40  "semiaxes for uniform, standard deviation for "
41  "normal");
42  MooseEnum rand_options("uniform normal none", "none");
43  params.addParam<MooseEnum>(
44  "size_variation_type", rand_options, "Type of distribution that random semiaxes will follow");
45  params.addParam<unsigned int>(
46  "numtries", 1000, "The number of tries to place the random particles");
47  return params;
48 }
49 
50 BimodalSuperellipsoidsIC::BimodalSuperellipsoidsIC(const InputParameters & parameters)
51  : SpecifiedSmoothSuperellipsoidIC(parameters),
52  _npart(getParam<unsigned int>("npart")),
53  _small_spac(getParam<Real>("small_spac")),
54  _large_spac(getParam<Real>("large_spac")),
55  _small_a(getParam<Real>("small_a")),
56  _small_b(getParam<Real>("small_b")),
57  _small_c(getParam<Real>("small_c")),
58  _small_n(getParam<Real>("small_n")),
59  _size_variation(getParam<Real>("size_variation")),
60  _size_variation_type(getParam<MooseEnum>("size_variation_type")),
61  _max_num_tries(getParam<unsigned int>("numtries"))
62 {
63 }
64 
65 void
67 {
68  // Set up domain bounds with mesh tools
69  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
70  {
71  _bottom_left(i) = _mesh.getMinInDimension(i);
72  _top_right(i) = _mesh.getMaxInDimension(i);
73  }
75 
76  if (_size_variation_type == 2 && _size_variation > 0.0)
77  mooseError("If size_variation > 0.0, you must pass in a size_variation_type in "
78  "BimodalSuperellipsoidsIC");
79 
81 }
82 
83 void
85 {
86  _as.resize(_input_as.size() + _npart);
87  _bs.resize(_input_bs.size() + _npart);
88  _cs.resize(_input_cs.size() + _npart);
89 
90  // First fill in the specified (large) superellipsoids from the input file
91  for (unsigned int i = 0; i < _input_as.size(); ++i)
92  {
93  _as[i] = _input_as[i];
94  _bs[i] = _input_bs[i];
95  _cs[i] = _input_cs[i];
96  }
97 
98  // Then fill in the randomly positioned (small) superellipsoids
99  for (unsigned int i = _input_as.size(); i < _input_as.size() + _npart; ++i)
100  {
101  // Vary semiaxes
102  switch (_size_variation_type)
103  {
104  case 0: // Random distrubtion, maintaining constant shape
105  {
106  Real rand_num = _random.rand(_tid);
107  _as[i] = _small_a * (1.0 + (1.0 - 2.0 * rand_num) * _size_variation);
108  _bs[i] = _small_b * (1.0 + (1.0 - 2.0 * rand_num) * _size_variation);
109  _cs[i] = _small_c * (1.0 + (1.0 - 2.0 * rand_num) * _size_variation);
110  break;
111  }
112  case 1: // Normal distribution of semiaxis size, maintaining constant shape
113  _as[i] = _random.randNormal(_tid, _small_a, _size_variation);
114  _bs[i] = _as[i] * _small_b / _small_a;
115  _cs[i] = _as[i] * _small_c / _small_a;
116  break;
117  case 2: // No variation
118  _as[i] = _small_a;
119  _bs[i] = _small_b;
120  _cs[i] = _small_c;
121  }
122 
123  if (_as[i] < 0.0)
124  _as[i] = 0.0;
125  if (_bs[i] < 0.0)
126  _bs[i] = 0.0;
127  if (_cs[i] < 0.0)
128  _cs[i] = 0.0;
129  }
130 }
131 
132 void
134 {
135  _ns.resize(_input_ns.size() + _npart);
136 
137  // First fill in the specified (large) superellipsoids from the input file
138  for (unsigned int i = 0; i < _input_ns.size(); ++i)
139  _ns[i] = _input_ns[i];
140 
141  // Then fill in the randomly positioned (small) superellipsoids
142  // The shape is assumed to stay constant so n does not vary
143  for (unsigned int i = _input_ns.size(); i < _input_ns.size() + _npart; ++i)
144  _ns[i] = _small_n;
145 }
146 
147 void
149 {
150  _centers.resize(_x_positions.size() + _npart);
151 
152  // First place the specified (large) particles from the input file
153  for (unsigned int i = 0; i < _x_positions.size(); ++i)
154  {
155  _centers[i](0) = _x_positions[i];
156  _centers[i](1) = _y_positions[i];
157  _centers[i](2) = _z_positions[i];
158  }
159 
160  // Next place the randomly positioned (small) particles
161  for (unsigned int i = _x_positions.size(); i < _x_positions.size() + _npart; ++i)
162  {
163  unsigned int num_tries = 0;
164 
165  while (num_tries < _max_num_tries)
166  {
167  num_tries++;
168 
169  RealTensorValue ran;
170  ran(0, 0) = _random.rand(_tid);
171  ran(1, 1) = _random.rand(_tid);
172  ran(2, 2) = _random.rand(_tid);
173 
174  _centers[i] = _bottom_left + ran * _range;
175 
176  // check for collisions with the specified (large) and randomly placed small particles
177  for (unsigned int j = 0; j < i; ++j)
178  {
179  // Compute the distance r1 from the center of each specified superellipsoid to its
180  // outside edge along the vector between the specified superellipsoid and the current
181  // randomly positioned one.
182  // This uses the equation for a superellipse in polar coordinates and substitutes
183  // distances for sin, cos functions.
184  Point dist_vec = _mesh.minPeriodicVector(_var.number(), _centers[i], _centers[j]);
185  const Real dist = dist_vec.norm();
186 
187  // First calculate rmn1 = r1^(-n), replacing sin, cos functions with distances
188  Real rmn1 = (std::pow(std::abs(dist_vec(0) / dist / _as[j]), _ns[j]) +
189  std::pow(std::abs(dist_vec(1) / dist / _bs[j]), _ns[j]) +
190  std::pow(std::abs(dist_vec(2) / dist / _cs[j]), _ns[j]));
191  // Then calculate r1 from rmn1
192  const Real r1 = std::pow(rmn1, (-1.0 / _ns[j]));
193 
194  // Now calculate the distance r2 from the center of the randomly placed
195  // superellipsoid to its outside edge in the same manner
196  Real rmn2 = (std::pow(std::abs(dist_vec(0) / dist / _as[i]), _ns[i]) +
197  std::pow(std::abs(dist_vec(1) / dist / _bs[i]), _ns[i]) +
198  std::pow(std::abs(dist_vec(2) / dist / _cs[i]), _ns[i]));
199  const Real r2 = std::pow(rmn2, (-1.0 / _ns[i]));
200 
201  // Calculate the distance between the edges (first in the list are the large then come the
202  // small)
203  if ((dist - r1 - r2) < (j < _x_positions.size() ? _large_spac : _small_spac))
204  goto fail;
205  }
206 
207  // accept the position of the new center
208  goto accept;
209 
210  // retry a new position until tries are exhausted
211  fail:
212  continue;
213  }
214 
215  if (num_tries == _max_num_tries)
216  mooseError("Too many tries in MultiSmoothCircleIC");
217 
218  accept:
219  continue;
220  }
221 }
InputParameters validParams< SpecifiedSmoothSuperellipsoidIC >()
virtual void computeSuperellipsoidSemiaxes()
SpecifiedSmoothSuperellipsoidIC creates multiple SmoothSuperellipsoids (number = size of x_positions)...
unsigned int _npart
Variables to describe the randomly placed (smaller) superellipsoids.
BimodalSuperellipsoidsIC(const InputParameters &parameters)
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
InputParameters validParams< BimodalSuperellipsoidsIC >()