www.mooseframework.org
SmoothCircleBaseIC.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 "SmoothCircleBaseIC.h"
9 
10 // MOOSE includes
11 #include "MooseMesh.h"
12 #include "MooseVariable.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<InitialCondition>();
19  params.addRequiredParam<Real>("invalue", "The variable value inside the circle");
20  params.addRequiredParam<Real>("outvalue", "The variable value outside the circle");
21  params.addParam<Real>(
22  "int_width", 0.0, "The interfacial width of the void surface. Defaults to sharp interface");
23  params.addParam<bool>("3D_spheres", true, "in 3D, whether the objects are spheres or columns");
24  params.addParam<bool>("zero_gradient",
25  false,
26  "Set the gradient DOFs to zero. This can avoid "
27  "numerical problems with higher order shape "
28  "functions and overlapping circles.");
29  params.addParam<unsigned int>("rand_seed", 12345, "Seed value for the random number generator");
30  return params;
31 }
32 
33 SmoothCircleBaseIC::SmoothCircleBaseIC(const InputParameters & parameters)
34  : InitialCondition(parameters),
35  _mesh(_fe_problem.mesh()),
36  _invalue(parameters.get<Real>("invalue")),
37  _outvalue(parameters.get<Real>("outvalue")),
38  _int_width(parameters.get<Real>("int_width")),
39  _3D_spheres(parameters.get<bool>("3D_spheres")),
40  _zero_gradient(parameters.get<bool>("zero_gradient")),
41  _num_dim(_3D_spheres ? 3 : 2)
42 {
43  _random.seed(_tid, getParam<unsigned int>("rand_seed"));
44 }
45 
46 void
48 {
49  // Compute radii and centers and initialize vector sizes
52 
53  if (_centers.size() != _radii.size())
54  mooseError("_center and _radii vectors are not the same size in the Circle IC");
55 
56  if (_centers.size() < 1)
57  mooseError("_center and _radii were not initialized in the Circle IC");
58 }
59 
60 Real
61 SmoothCircleBaseIC::value(const Point & p)
62 {
63  Real value = _outvalue;
64  Real val2 = 0.0;
65 
66  for (unsigned int circ = 0; circ < _centers.size() && value != _invalue; ++circ)
67  {
68  val2 = computeCircleValue(p, _centers[circ], _radii[circ]);
69  if ((val2 > value && _invalue > _outvalue) || (val2 < value && _outvalue > _invalue))
70  value = val2;
71  }
72 
73  return value;
74 }
75 
76 RealGradient
78 {
79  if (_zero_gradient)
80  return 0.0;
81 
82  RealGradient gradient = 0.0;
83  Real value = _outvalue;
84  Real val2 = 0.0;
85 
86  for (unsigned int circ = 0; circ < _centers.size(); ++circ)
87  {
88  val2 = computeCircleValue(p, _centers[circ], _radii[circ]);
89  if ((val2 > value && _invalue > _outvalue) || (val2 < value && _outvalue > _invalue))
90  {
91  value = val2;
92  gradient = computeCircleGradient(p, _centers[circ], _radii[circ]);
93  }
94  }
95 
96  return gradient;
97 }
98 
99 Real
100 SmoothCircleBaseIC::computeCircleValue(const Point & p, const Point & center, const Real & radius)
101 {
102  Point l_center = center;
103  Point l_p = p;
104  if (!_3D_spheres) // Create 3D cylinders instead of spheres
105  {
106  l_p(2) = 0.0;
107  l_center(2) = 0.0;
108  }
109  // Compute the distance between the current point and the center
110  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);
111 
112  // Return value
113  Real value = _outvalue; // Outside circle
114 
115  if (dist <= radius - _int_width / 2.0) // Inside circle
116  value = _invalue;
117  else if (dist < radius + _int_width / 2.0) // Smooth interface
118  {
119  Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
120  value = _outvalue + (_invalue - _outvalue) * (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
121  }
122 
123  return value;
124 }
125 
126 RealGradient
128  const Point & center,
129  const Real & radius)
130 {
131  Point l_center = center;
132  Point l_p = p;
133  if (!_3D_spheres) // Create 3D cylinders instead of spheres
134  {
135  l_p(2) = 0.0;
136  l_center(2) = 0.0;
137  }
138  // Compute the distance between the current point and the center
139  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);
140 
141  Real DvalueDr = 0.0;
142 
143  if (dist < radius + _int_width / 2.0 && dist > radius - _int_width / 2.0)
144  {
145  Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
146  Real Dint_posDr = 1.0 / _int_width;
147  DvalueDr = Dint_posDr * (_invalue - _outvalue) *
148  (-std::sin(int_pos * libMesh::pi) * libMesh::pi) / 2.0;
149  }
150 
151  // Set gradient over the smooth interface
152  if (dist != 0.0)
153  return _mesh.minPeriodicVector(_var.number(), center, p) * (DvalueDr / dist);
154  else
155  return 0.0;
156 }
virtual Real computeCircleValue(const Point &p, const Point &center, const Real &radius)
std::vector< Real > _radii
InputParameters validParams< SmoothCircleBaseIC >()
std::vector< Point > _centers
virtual Real value(const Point &p)
virtual RealGradient computeCircleGradient(const Point &p, const Point &center, const Real &radius)
SmoothCircleBaseIC(const InputParameters &parameters)
virtual void initialSetup()
virtual RealGradient gradient(const Point &p)
virtual void computeCircleRadii()=0
virtual void computeCircleCenters()=0