www.mooseframework.org
MultiSmoothCircleIC.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 
8 #include "MultiSmoothCircleIC.h"
9 
10 // MOOSE includes
11 #include "MooseMesh.h"
12 #include "MooseVariable.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<SmoothCircleBaseIC>();
19  params.addClassDescription("Random distribution of smooth circles with given minimum spacing");
20  params.addRequiredParam<unsigned int>("numbub", "The number of bubbles to place");
21  params.addRequiredParam<Real>("bubspac",
22  "minimum spacing of bubbles, measured from center to center");
23  params.addParam<unsigned int>("numtries", 1000, "The number of tries");
24  params.addRequiredParam<Real>("radius", "Mean radius value for the circles");
25  params.addParam<Real>("radius_variation",
26  0.0,
27  "Plus or minus fraction of random variation in "
28  "the bubble radius for uniform, standard "
29  "deviation for normal");
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  return params;
35 }
36 
37 MultiSmoothCircleIC::MultiSmoothCircleIC(const InputParameters & parameters)
38  : SmoothCircleBaseIC(parameters),
39  _numbub(getParam<unsigned int>("numbub")),
40  _bubspac(getParam<Real>("bubspac")),
41  _max_num_tries(getParam<unsigned int>("numtries")),
42  _radius(getParam<Real>("radius")),
43  _radius_variation(getParam<Real>("radius_variation")),
44  _radius_variation_type(getParam<MooseEnum>("radius_variation_type"))
45 {
46 }
47 
48 void
50 {
51  // Set up domain bounds with mesh tools
52  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
53  {
54  _bottom_left(i) = _mesh.getMinInDimension(i);
55  _top_right(i) = _mesh.getMaxInDimension(i);
56  }
58 
59  // a variation is provided, but the type is set to 'none'
60  if (_radius_variation > 0.0 && _radius_variation_type == 2)
61  mooseError("If radius_variation > 0.0, you must pass in a radius_variation_type in "
62  "MultiSmoothCircleIC");
63 
65 }
66 
67 void
69 {
70  _radii.resize(_numbub);
71 
72  for (unsigned int i = 0; i < _numbub; i++)
73  {
74  // Vary bubble radius
75  switch (_radius_variation_type)
76  {
77  case 0: // Uniform distribution
78  _radii[i] = _radius * (1.0 + (1.0 - 2.0 * _random.rand(_tid)) * _radius_variation);
79  break;
80  case 1: // Normal distribution
81  _radii[i] = _random.randNormal(_tid, _radius, _radius_variation);
82  break;
83  case 2: // No variation
84  _radii[i] = _radius;
85  }
86 
87  _radii[i] = std::max(_radii[i], 0.0);
88  }
89 }
90 
91 void
93 {
94  _centers.resize(_numbub);
95  for (unsigned int i = 0; i < _numbub; ++i)
96  {
97  // Vary circle center positions
98  unsigned int num_tries = 0;
99  while (num_tries < _max_num_tries)
100  {
101  num_tries++;
102 
103  RealTensorValue ran;
104  ran(0, 0) = _random.rand(_tid);
105  ran(1, 1) = _random.rand(_tid);
106  ran(2, 2) = _random.rand(_tid);
107 
108  _centers[i] = _bottom_left + ran * _range;
109 
110  for (unsigned int j = 0; j < i; ++j)
111  if (_mesh.minPeriodicDistance(_var.number(), _centers[j], _centers[i]) < _bubspac)
112  goto fail;
113 
114  // accept the position of the new center
115  goto accept;
116 
117  // retry a new position until tries are exhausted
118  fail:
119  continue;
120  }
121 
122  if (num_tries == _max_num_tries)
123  mooseError("Too many tries in MultiSmoothCircleIC");
124 
125  accept:
126  continue;
127  }
128 }
InputParameters validParams< MultiSmoothCircleIC >()
std::vector< Real > _radii
const MooseEnum _radius_variation_type
std::vector< Point > _centers
const unsigned int _max_num_tries
virtual void computeCircleCenters()
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
virtual void initialSetup()
InputParameters validParams< SmoothCircleBaseIC >()
const unsigned int _numbub
MultiSmoothCircleIC(const InputParameters &parameters)
virtual void computeCircleRadii()
virtual void initialSetup()