www.mooseframework.org
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
LatticeSmoothCircleIC Class Reference

LatticeSmoothcircleIC creates a lattice of smoothcircles as an initial condition. More...

#include <LatticeSmoothCircleIC.h>

Inheritance diagram for LatticeSmoothCircleIC:
[legend]

Public Member Functions

 LatticeSmoothCircleIC (const InputParameters &parameters)
 
virtual void initialSetup ()
 
virtual Real value (const Point &p)
 
virtual RealGradient gradient (const Point &p)
 

Protected Types

enum  ProfileType { ProfileType::COS, ProfileType::TANH }
 

Protected Member Functions

virtual void computeCircleRadii ()
 
virtual void computeCircleCenters ()
 
virtual Real computeCircleValue (const Point &p, const Point &center, const Real &radius)
 
virtual RealGradient computeCircleGradient (const Point &p, const Point &center, const Real &radius)
 

Protected Attributes

Real _lattice_variation
 
std::vector< unsigned int > _circles_per_side
 
unsigned int _numbub
 
Real _radius
 
Real _radius_variation
 
MooseEnum _radius_variation_type
 
bool _avoid_bounds
 
Point _bottom_left
 
Point _top_right
 
Point _range
 
MooseMesh & _mesh
 
Real _invalue
 
Real _outvalue
 
Real _int_width
 
bool _3D_spheres
 
bool _zero_gradient
 
unsigned int _num_dim
 
std::vector< Point > _centers
 
std::vector< Real > _radii
 
enum SmoothCircleBaseIC::ProfileType _profile
 
MooseRandom _random
 

Detailed Description

LatticeSmoothcircleIC creates a lattice of smoothcircles as an initial condition.

They are either directly on the lattice or randomly perturbed from the lattice.

Definition at line 25 of file LatticeSmoothCircleIC.h.

Member Enumeration Documentation

◆ ProfileType

enum SmoothCircleBaseIC::ProfileType
strongprotectedinherited
Enumerator
COS 
TANH 

Definition at line 58 of file SmoothCircleBaseIC.h.

59  {
60  COS,
61  TANH
62  } _profile;
enum SmoothCircleBaseIC::ProfileType _profile

Constructor & Destructor Documentation

◆ LatticeSmoothCircleIC()

LatticeSmoothCircleIC::LatticeSmoothCircleIC ( const InputParameters &  parameters)

Definition at line 40 of file LatticeSmoothCircleIC.C.

41  : SmoothCircleBaseIC(parameters),
42  _lattice_variation(isParamValid("Rnd_variation") ? getParam<Real>("Rnd_variation")
43  : getParam<Real>("pos_variation")),
44  _circles_per_side(getParam<std::vector<unsigned int>>("circles_per_side")),
45  _radius(getParam<Real>("radius")),
46  _radius_variation(getParam<Real>("radius_variation")),
47  _radius_variation_type(getParam<MooseEnum>("radius_variation_type")),
48  _avoid_bounds(getParam<bool>("avoid_bounds"))
49 {
50 }
std::vector< unsigned int > _circles_per_side
SmoothCircleBaseIC(const InputParameters &parameters)

Member Function Documentation

◆ computeCircleCenters()

void LatticeSmoothCircleIC::computeCircleCenters ( )
protectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 125 of file LatticeSmoothCircleIC.C.

126 {
127  _centers.resize(_numbub);
128 
129  Real x_sep = _range(0) / _circles_per_side[0];
130  Real y_sep = _range(1) / _circles_per_side[1];
131 
132  Real z_sep = 0.0;
133  unsigned int z_num = 1.0;
134 
135  if (_range(2) > 0.0)
136  {
137  z_sep = _range(2) / _circles_per_side[2];
138  z_num = _circles_per_side[2];
139  }
140 
141  unsigned int cnt = 0;
142  for (unsigned int i = 0; i < _circles_per_side[0]; ++i)
143  for (unsigned int j = 0; j < _circles_per_side[1]; ++j)
144  for (unsigned int k = 0; k < z_num; ++k)
145  {
146  Real xx = x_sep / 2.0 + i * x_sep;
147  Real yy = y_sep / 2.0 + j * y_sep;
148  Real zz = z_sep / 2.0 + k * z_sep;
149 
150  // Vary circle position
151  xx = xx + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
152  yy = yy + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
153 
154  if (_range(2) != 0.0)
155  zz = zz + (1.0 - 2.0 * _random.rand(_tid)) * _lattice_variation;
156 
157  // Verify not out of bounds
158  if (_avoid_bounds && xx < _radii[cnt] + _int_width)
159  xx = _radii[cnt] + _int_width;
160  if (_avoid_bounds && xx > _range(0) - (_radii[cnt] + _int_width))
161  xx = _range(0) - (_radii[cnt] + _int_width);
162  if (_avoid_bounds && yy < _radii[cnt] + _int_width)
163  yy = _radii[cnt] + _int_width;
164  if (_avoid_bounds && yy > _range(1) - (_radii[cnt] + _int_width))
165  yy = _range(1) - (_radii[cnt] + _int_width);
166  if (_range(2) != 0.0)
167  {
168  if (_avoid_bounds && zz < _radii[cnt] + _int_width)
169  zz = _radii[cnt] + _int_width;
170  if (_avoid_bounds && zz > _range(2) - (_radii[cnt] + _int_width))
171  zz = _range(2) - (_radii[cnt] + _int_width);
172  }
173 
174  _centers[cnt](0) = xx;
175  _centers[cnt](1) = yy;
176  _centers[cnt](2) = zz;
177 
178  cnt++;
179  }
180 }
std::vector< unsigned int > _circles_per_side
std::vector< Real > _radii
std::vector< Point > _centers

◆ computeCircleGradient()

RealGradient SmoothCircleBaseIC::computeCircleGradient ( const Point &  p,
const Point &  center,
const Real &  radius 
)
protectedvirtualinherited

Definition at line 150 of file SmoothCircleBaseIC.C.

Referenced by SmoothCircleBaseIC::gradient().

153 {
154  Point l_center = center;
155  Point l_p = p;
156  if (!_3D_spheres) // Create 3D cylinders instead of spheres
157  {
158  l_p(2) = 0.0;
159  l_center(2) = 0.0;
160  }
161  // Compute the distance between the current point and the center
162  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);
163 
164  // early return if we are probing the center of the circle
165  if (dist == 0.0)
166  return 0.0;
167 
168  Real DvalueDr = 0.0;
169  switch (_profile)
170  {
171  case ProfileType::COS:
172  if (dist < radius + _int_width / 2.0 && dist > radius - _int_width / 2.0)
173  {
174  const Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
175  const Real Dint_posDr = 1.0 / _int_width;
176  DvalueDr = Dint_posDr * (_invalue - _outvalue) *
177  (-std::sin(int_pos * libMesh::pi) * libMesh::pi) / 2.0;
178  }
179  break;
180 
181  case ProfileType::TANH:
182  DvalueDr = -(_invalue - _outvalue) * 0.5 / _int_width * libMesh::pi *
183  (1.0 - Utility::pow<2>(std::tanh(4.0 * (radius - dist) / _int_width)));
184  break;
185 
186  default:
187  mooseError("Internal error.");
188  }
189 
190  return _mesh.minPeriodicVector(_var.number(), center, p) * (DvalueDr / dist);
191 }
enum SmoothCircleBaseIC::ProfileType _profile

◆ computeCircleRadii()

void LatticeSmoothCircleIC::computeCircleRadii ( )
protectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 100 of file LatticeSmoothCircleIC.C.

101 {
102  _radii.resize(_numbub);
103 
104  for (unsigned int i = 0; i < _numbub; i++)
105  {
106  // Vary bubble radius
107  switch (_radius_variation_type)
108  {
109  case 0: // Uniform distrubtion
110  _radii[i] = _radius * (1.0 + (1.0 - 2.0 * _random.rand(_tid)) * _radius_variation);
111  break;
112  case 1: // Normal distribution
113  _radii[i] = _random.randNormal(_tid, _radius, _radius_variation);
114  break;
115  case 2: // No variation
116  _radii[i] = _radius;
117  }
118 
119  if (_radii[i] < 0.0)
120  _radii[i] = 0.0;
121  }
122 }
std::vector< Real > _radii

◆ computeCircleValue()

Real SmoothCircleBaseIC::computeCircleValue ( const Point &  p,
const Point &  center,
const Real &  radius 
)
protectedvirtualinherited

Reimplemented in RndSmoothCircleIC.

Definition at line 110 of file SmoothCircleBaseIC.C.

Referenced by SmoothCircleBaseIC::gradient(), and SmoothCircleBaseIC::value().

111 {
112  Point l_center = center;
113  Point l_p = p;
114  if (!_3D_spheres) // Create 3D cylinders instead of spheres
115  {
116  l_p(2) = 0.0;
117  l_center(2) = 0.0;
118  }
119  // Compute the distance between the current point and the center
120  Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);
121 
122  switch (_profile)
123  {
124  case ProfileType::COS:
125  {
126  // Return value
127  Real value = _outvalue; // Outside circle
128 
129  if (dist <= radius - _int_width / 2.0) // Inside circle
130  value = _invalue;
131  else if (dist < radius + _int_width / 2.0) // Smooth interface
132  {
133  Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
134  value = _outvalue + (_invalue - _outvalue) * (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
135  }
136  return value;
137  }
138 
139  case ProfileType::TANH:
140  return (_invalue - _outvalue) * 0.5 *
141  (std::tanh(libMesh::pi * (radius - dist) / _int_width) + 1.0) +
142  _outvalue;
143 
144  default:
145  mooseError("Internal error.");
146  }
147 }
virtual Real value(const Point &p)
enum SmoothCircleBaseIC::ProfileType _profile

◆ gradient()

RealGradient SmoothCircleBaseIC::gradient ( const Point &  p)
virtualinherited

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 87 of file SmoothCircleBaseIC.C.

Referenced by PolycrystalVoronoiVoidIC::gradient().

88 {
89  if (_zero_gradient)
90  return 0.0;
91 
92  RealGradient gradient = 0.0;
93  Real value = _outvalue;
94  Real val2 = 0.0;
95 
96  for (unsigned int circ = 0; circ < _centers.size(); ++circ)
97  {
98  val2 = computeCircleValue(p, _centers[circ], _radii[circ]);
99  if ((val2 > value && _invalue > _outvalue) || (val2 < value && _outvalue > _invalue))
100  {
101  value = val2;
102  gradient = computeCircleGradient(p, _centers[circ], _radii[circ]);
103  }
104  }
105 
106  return gradient;
107 }
virtual Real computeCircleValue(const Point &p, const Point &center, const Real &radius)
std::vector< Real > _radii
std::vector< Point > _centers
virtual Real value(const Point &p)
virtual RealGradient computeCircleGradient(const Point &p, const Point &center, const Real &radius)
virtual RealGradient gradient(const Point &p)

◆ initialSetup()

void LatticeSmoothCircleIC::initialSetup ( )
virtual

Reimplemented from SmoothCircleBaseIC.

Definition at line 53 of file LatticeSmoothCircleIC.C.

54 {
55  // pad circles per side vector to size 3 (with 0)
56  _circles_per_side.resize(3);
57 
58  // Set up domain bounds with mesh tools
59  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
60  {
61  _bottom_left(i) = _mesh.getMinInDimension(i);
62  _top_right(i) = _mesh.getMaxInDimension(i);
63  }
65 
66  // Error checks
67  if (_range(0) != 0.0 && _range(1) != 0.0 && _circles_per_side[1] == 0)
68  mooseError("If domain is > 1D, circles_per_side must have more than one value");
69 
70  if (_range(2) != 0.0 && _circles_per_side[2] == 0)
71  mooseError("If domain is 3D, circles_per_side must have three values");
72 
73  if (_range(1) == 0.0 && _range(2) == 0.0)
74  {
75  _circles_per_side[1] = 0;
76  _circles_per_side[2] = 0;
77  }
78 
79  // Set _numbub
80  if (_range(2) == 0.0)
81  {
82  _circles_per_side[2] = 0;
84  }
85  else
87 
88  switch (_radius_variation_type)
89  {
90  case 2: // No variation
91  if (_radius_variation > 0.0)
92  mooseError("If radius_variation > 0.0, you must pass in a radius_variation_type in "
93  "LatticeSmoothCircleIC");
94  break;
95  }
97 }
std::vector< unsigned int > _circles_per_side
virtual void initialSetup()

◆ value()

Real SmoothCircleBaseIC::value ( const Point &  p)
virtualinherited

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 71 of file SmoothCircleBaseIC.C.

Referenced by RndSmoothCircleIC::computeCircleValue(), SmoothCircleBaseIC::computeCircleValue(), SmoothCircleBaseIC::gradient(), and PolycrystalVoronoiVoidIC::value().

72 {
73  Real value = _outvalue;
74  Real val2 = 0.0;
75 
76  for (unsigned int circ = 0; circ < _centers.size() && value != _invalue; ++circ)
77  {
78  val2 = computeCircleValue(p, _centers[circ], _radii[circ]);
79  if ((val2 > value && _invalue > _outvalue) || (val2 < value && _outvalue > _invalue))
80  value = val2;
81  }
82 
83  return value;
84 }
virtual Real computeCircleValue(const Point &p, const Point &center, const Real &radius)
std::vector< Real > _radii
std::vector< Point > _centers
virtual Real value(const Point &p)

Member Data Documentation

◆ _3D_spheres

bool SmoothCircleBaseIC::_3D_spheres
protectedinherited

◆ _avoid_bounds

bool LatticeSmoothCircleIC::_avoid_bounds
protected

Definition at line 44 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleCenters().

◆ _bottom_left

Point LatticeSmoothCircleIC::_bottom_left
protected

Definition at line 46 of file LatticeSmoothCircleIC.h.

Referenced by initialSetup().

◆ _centers

std::vector<Point> SmoothCircleBaseIC::_centers
protectedinherited

◆ _circles_per_side

std::vector<unsigned int> LatticeSmoothCircleIC::_circles_per_side
protected

Definition at line 37 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleCenters(), and initialSetup().

◆ _int_width

Real SmoothCircleBaseIC::_int_width
protectedinherited

◆ _invalue

Real SmoothCircleBaseIC::_invalue
protectedinherited

◆ _lattice_variation

Real LatticeSmoothCircleIC::_lattice_variation
protected

Definition at line 36 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleCenters().

◆ _mesh

MooseMesh& SmoothCircleBaseIC::_mesh
protectedinherited

◆ _num_dim

unsigned int SmoothCircleBaseIC::_num_dim
protectedinherited

Definition at line 53 of file SmoothCircleBaseIC.h.

◆ _numbub

unsigned int LatticeSmoothCircleIC::_numbub
protected

Definition at line 38 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleCenters(), computeCircleRadii(), and initialSetup().

◆ _outvalue

Real SmoothCircleBaseIC::_outvalue
protectedinherited

◆ _profile

enum SmoothCircleBaseIC::ProfileType SmoothCircleBaseIC::_profile
protectedinherited

◆ _radii

std::vector<Real> SmoothCircleBaseIC::_radii
protectedinherited

◆ _radius

Real LatticeSmoothCircleIC::_radius
protected

Definition at line 40 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleRadii().

◆ _radius_variation

Real LatticeSmoothCircleIC::_radius_variation
protected

Definition at line 41 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleRadii(), and initialSetup().

◆ _radius_variation_type

MooseEnum LatticeSmoothCircleIC::_radius_variation_type
protected

Definition at line 42 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleRadii(), and initialSetup().

◆ _random

MooseRandom SmoothCircleBaseIC::_random
protectedinherited

◆ _range

Point LatticeSmoothCircleIC::_range
protected

Definition at line 48 of file LatticeSmoothCircleIC.h.

Referenced by computeCircleCenters(), and initialSetup().

◆ _top_right

Point LatticeSmoothCircleIC::_top_right
protected

Definition at line 47 of file LatticeSmoothCircleIC.h.

Referenced by initialSetup().

◆ _zero_gradient

bool SmoothCircleBaseIC::_zero_gradient
protectedinherited

Definition at line 51 of file SmoothCircleBaseIC.h.

Referenced by SmoothCircleBaseIC::gradient().


The documentation for this class was generated from the following files: