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

MultismoothCircleIC creates multiple SmoothCircles (number = numbub) that are randomly positioned around the domain with a minimum spacing equal to bubspac. More...

#include <MultiSmoothCircleIC.h>

Inheritance diagram for MultiSmoothCircleIC:
[legend]

Public Member Functions

 MultiSmoothCircleIC (const InputParameters &parameters)
 
virtual void initialSetup () override
 
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 () override
 
virtual void computeCircleCenters () override
 
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

const unsigned int _numbub
 
const Real _bubspac
 
const unsigned int _max_num_tries
 
const Real _radius
 
const Real _radius_variation
 
const MooseEnum _radius_variation_type
 
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

MultismoothCircleIC creates multiple SmoothCircles (number = numbub) that are randomly positioned around the domain with a minimum spacing equal to bubspac.

The system attempts to randomly place bubbles in the domain until the desired number of distinct bubbles are placed. If the number of attempts exceeds "max_tries", a mooseError will be thrown and the program will terminate.

Definition at line 27 of file MultiSmoothCircleIC.h.

Member Enumeration Documentation

◆ ProfileType

enum SmoothCircleBaseIC::ProfileType
strongprotectedinherited
Enumerator
COS 
TANH 

Definition at line 57 of file SmoothCircleBaseIC.h.

58  {
59  COS,
60  TANH
61  } _profile;

Constructor & Destructor Documentation

◆ MultiSmoothCircleIC()

MultiSmoothCircleIC::MultiSmoothCircleIC ( const InputParameters &  parameters)

Definition at line 41 of file MultiSmoothCircleIC.C.

42  : SmoothCircleBaseIC(parameters),
43  _numbub(getParam<unsigned int>("numbub")),
44  _bubspac(getParam<Real>("bubspac")),
45  _max_num_tries(getParam<unsigned int>("numtries")),
46  _radius(getParam<Real>("radius")),
47  _radius_variation(getParam<Real>("radius_variation")),
48  _radius_variation_type(getParam<MooseEnum>("radius_variation_type"))
49 {
50 }

Member Function Documentation

◆ computeCircleCenters()

void MultiSmoothCircleIC::computeCircleCenters ( )
overrideprotectedvirtual

Implements SmoothCircleBaseIC.

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 96 of file MultiSmoothCircleIC.C.

97 {
98  _centers.resize(_numbub);
99  for (unsigned int i = 0; i < _numbub; ++i)
100  {
101  // Vary circle center positions
102  unsigned int num_tries = 0;
103  while (num_tries < _max_num_tries)
104  {
105  num_tries++;
106 
107  RealTensorValue ran;
108  ran(0, 0) = _random.rand(_tid);
109  ran(1, 1) = _random.rand(_tid);
110  ran(2, 2) = _random.rand(_tid);
111 
112  _centers[i] = _bottom_left + ran * _range;
113 
114  for (unsigned int j = 0; j < i; ++j)
115  if (_mesh.minPeriodicDistance(_var.number(), _centers[j], _centers[i]) < _bubspac)
116  goto fail;
117 
118  // accept the position of the new center
119  goto accept;
120 
121  // retry a new position until tries are exhausted
122  fail:
123  continue;
124  }
125 
126  if (num_tries == _max_num_tries)
127  mooseError("Too many tries in MultiSmoothCircleIC");
128 
129  accept:
130  continue;
131  }
132 }

◆ computeCircleGradient()

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

Definition at line 149 of file SmoothCircleBaseIC.C.

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

Referenced by SmoothCircleBaseIC::gradient().

◆ computeCircleRadii()

void MultiSmoothCircleIC::computeCircleRadii ( )
overrideprotectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 72 of file MultiSmoothCircleIC.C.

73 {
74  _radii.resize(_numbub);
75 
76  for (unsigned int i = 0; i < _numbub; i++)
77  {
78  // Vary bubble radius
79  switch (_radius_variation_type)
80  {
81  case 0: // Uniform distribution
82  _radii[i] = _radius * (1.0 + (1.0 - 2.0 * _random.rand(_tid)) * _radius_variation);
83  break;
84  case 1: // Normal distribution
85  _radii[i] = _random.randNormal(_tid, _radius, _radius_variation);
86  break;
87  case 2: // No variation
88  _radii[i] = _radius;
89  }
90 
91  _radii[i] = std::max(_radii[i], 0.0);
92  }
93 }

◆ 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.

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 * (std::tanh(2.0 * (radius - dist) / _int_width) + 1.0) +
141  _outvalue;
142 
143  default:
144  mooseError("Internal error.");
145  }
146 }

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

◆ gradient()

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

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 87 of file SmoothCircleBaseIC.C.

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 }

Referenced by PolycrystalVoronoiVoidIC::gradient().

◆ initialSetup()

void MultiSmoothCircleIC::initialSetup ( )
overridevirtual

Reimplemented from SmoothCircleBaseIC.

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 53 of file MultiSmoothCircleIC.C.

54 {
55  // Set up domain bounds with mesh tools
56  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
57  {
58  _bottom_left(i) = _mesh.getMinInDimension(i);
59  _top_right(i) = _mesh.getMaxInDimension(i);
60  }
62 
63  // a variation is provided, but the type is set to 'none'
64  if (_radius_variation > 0.0 && _radius_variation_type == 2)
65  mooseError("If radius_variation > 0.0, you must pass in a radius_variation_type in "
66  "MultiSmoothCircleIC");
67 
69 }

Referenced by PolycrystalVoronoiVoidIC::initialSetup().

◆ value()

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

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 71 of file SmoothCircleBaseIC.C.

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 }

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

Member Data Documentation

◆ _3D_spheres

bool SmoothCircleBaseIC::_3D_spheres
protectedinherited

◆ _bottom_left

Point MultiSmoothCircleIC::_bottom_left
protected

◆ _bubspac

const Real MultiSmoothCircleIC::_bubspac
protected

◆ _centers

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

◆ _int_width

Real SmoothCircleBaseIC::_int_width
protectedinherited

◆ _invalue

Real SmoothCircleBaseIC::_invalue
protectedinherited

◆ _max_num_tries

const unsigned int MultiSmoothCircleIC::_max_num_tries
protected

◆ _mesh

MooseMesh& SmoothCircleBaseIC::_mesh
protectedinherited

◆ _num_dim

unsigned int SmoothCircleBaseIC::_num_dim
protectedinherited

Definition at line 52 of file SmoothCircleBaseIC.h.

◆ _numbub

const unsigned int MultiSmoothCircleIC::_numbub
protected

◆ _outvalue

Real SmoothCircleBaseIC::_outvalue
protectedinherited

◆ _profile

enum SmoothCircleBaseIC::ProfileType SmoothCircleBaseIC::_profile
protectedinherited

◆ _radii

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

◆ _radius

const Real MultiSmoothCircleIC::_radius
protected

◆ _radius_variation

const Real MultiSmoothCircleIC::_radius_variation
protected

Definition at line 44 of file MultiSmoothCircleIC.h.

Referenced by computeCircleRadii(), and initialSetup().

◆ _radius_variation_type

const MooseEnum MultiSmoothCircleIC::_radius_variation_type
protected

Definition at line 45 of file MultiSmoothCircleIC.h.

Referenced by computeCircleRadii(), and initialSetup().

◆ _random

MooseRandom SmoothCircleBaseIC::_random
protectedinherited

◆ _range

Point MultiSmoothCircleIC::_range
protected

◆ _top_right

Point MultiSmoothCircleIC::_top_right
protected

◆ _zero_gradient

bool SmoothCircleBaseIC::_zero_gradient
protectedinherited

Definition at line 50 of file SmoothCircleBaseIC.h.

Referenced by SmoothCircleBaseIC::gradient().


The documentation for this class was generated from the following files:
SmoothCircleBaseIC::_random
MooseRandom _random
Definition: SmoothCircleBaseIC.h:63
SmoothCircleBaseIC::_centers
std::vector< Point > _centers
Definition: SmoothCircleBaseIC.h:54
SmoothCircleBaseIC::ProfileType::COS
SmoothCircleBaseIC::value
virtual Real value(const Point &p)
Definition: SmoothCircleBaseIC.C:71
SmoothCircleBaseIC::computeCircleValue
virtual Real computeCircleValue(const Point &p, const Point &center, const Real &radius)
Definition: SmoothCircleBaseIC.C:110
libMesh::RealGradient
VectorValue< Real > RealGradient
Definition: GrainForceAndTorqueInterface.h:17
MultiSmoothCircleIC::_max_num_tries
const unsigned int _max_num_tries
Definition: MultiSmoothCircleIC.h:41
MultiSmoothCircleIC::_bottom_left
Point _bottom_left
Definition: MultiSmoothCircleIC.h:47
SmoothCircleBaseIC::_profile
enum SmoothCircleBaseIC::ProfileType _profile
MultiSmoothCircleIC::_radius_variation_type
const MooseEnum _radius_variation_type
Definition: MultiSmoothCircleIC.h:45
SmoothCircleBaseIC::_radii
std::vector< Real > _radii
Definition: SmoothCircleBaseIC.h:55
SmoothCircleBaseIC::ProfileType::TANH
SmoothCircleBaseIC::_invalue
Real _invalue
Definition: SmoothCircleBaseIC.h:46
SmoothCircleBaseIC::computeCircleGradient
virtual RealGradient computeCircleGradient(const Point &p, const Point &center, const Real &radius)
Definition: SmoothCircleBaseIC.C:149
MultiSmoothCircleIC::_top_right
Point _top_right
Definition: MultiSmoothCircleIC.h:48
SmoothCircleBaseIC::_mesh
MooseMesh & _mesh
Definition: SmoothCircleBaseIC.h:44
SmoothCircleBaseIC::_outvalue
Real _outvalue
Definition: SmoothCircleBaseIC.h:47
SmoothCircleBaseIC::_zero_gradient
bool _zero_gradient
Definition: SmoothCircleBaseIC.h:50
MultiSmoothCircleIC::_numbub
const unsigned int _numbub
Definition: MultiSmoothCircleIC.h:38
SmoothCircleBaseIC::_int_width
Real _int_width
Definition: SmoothCircleBaseIC.h:48
SmoothCircleBaseIC::gradient
virtual RealGradient gradient(const Point &p)
Definition: SmoothCircleBaseIC.C:87
SmoothCircleBaseIC::_3D_spheres
bool _3D_spheres
Definition: SmoothCircleBaseIC.h:49
MultiSmoothCircleIC::_radius
const Real _radius
Definition: MultiSmoothCircleIC.h:43
SmoothCircleBaseIC::initialSetup
virtual void initialSetup()
Definition: SmoothCircleBaseIC.C:57
MultiSmoothCircleIC::_range
Point _range
Definition: MultiSmoothCircleIC.h:49
SmoothCircleBaseIC::SmoothCircleBaseIC
SmoothCircleBaseIC(const InputParameters &parameters)
Definition: SmoothCircleBaseIC.C:38
MultiSmoothCircleIC::_radius_variation
const Real _radius_variation
Definition: MultiSmoothCircleIC.h:44
MultiSmoothCircleIC::_bubspac
const Real _bubspac
Definition: MultiSmoothCircleIC.h:39