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

Reads multiple circles from a text file with the columns labeled x y z r. More...

#include <SmoothCircleFromFileIC.h>

Inheritance diagram for SmoothCircleFromFileIC:
[legend]

Public Member Functions

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

Protected Types

enum  COLS { X, Y, Z, R }
 
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

std::array< int, 4 > _col_map = {{-1, -1, -1, -1}}
 
std::vector< std::vector< Real > > _data
 
FileName _file_name
 
MooseUtils::DelimitedFileReader _txt_reader
 
std::vector< std::string > _col_names
 
unsigned int _n_circles
 
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

Reads multiple circles from a text file with the columns labeled x y z r.

It expects the file to have a one-line header. Applies all of the circles to the same variable.

Definition at line 30 of file SmoothCircleFromFileIC.h.

Member Enumeration Documentation

◆ COLS

◆ 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

◆ SmoothCircleFromFileIC()

SmoothCircleFromFileIC::SmoothCircleFromFileIC ( const InputParameters &  parameters)

Definition at line 25 of file SmoothCircleFromFileIC.C.

26  : SmoothCircleBaseIC(parameters),
27  _data(0),
28  _file_name(getParam<FileName>("file_name")),
29  _txt_reader(_file_name, &_communicator),
30  _n_circles(0)
31 {
32  // Read names and vectors from file
33  _txt_reader.read();
34  _col_names = _txt_reader.getNames();
35  _data = _txt_reader.getData();
36  _n_circles = _data[0].size();
37 
38  // Check that the file has all the correct information
39  for (unsigned int i = 0; i < _col_names.size(); ++i)
40  {
41  // Check that columns have uniform lengths
42  if (_data[i].size() != _n_circles)
43  mooseError("Columns in ", _file_name, " do not have uniform lengths.");
44 
45  // Determine which columns correspond to which parameters.
46  if (_col_names[i] == "x")
47  _col_map[X] = i;
48  else if (_col_names[i] == "y")
49  _col_map[Y] = i;
50  else if (_col_names[i] == "z")
51  _col_map[Z] = i;
52  else if (_col_names[i] == "r")
53  _col_map[R] = i;
54  }
55 
56  // Check that the required columns are present
57  if (_col_map[X] == -1)
58  mooseError("No column in ", _file_name, " labeled 'x'.");
59  if (_col_map[Y] == -1)
60  mooseError("No column in ", _file_name, " labeled 'y'.");
61  if (_col_map[Z] == -1)
62  mooseError("No column in ", _file_name, " labeled 'z'.");
63  if (_col_map[R] == -1)
64  mooseError("No column in ", _file_name, " labeled 'r'.");
65 }
SmoothCircleBaseIC(const InputParameters &parameters)
MooseUtils::DelimitedFileReader _txt_reader
std::vector< std::string > _col_names
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data

Member Function Documentation

◆ computeCircleCenters()

void SmoothCircleFromFileIC::computeCircleCenters ( )
protectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 74 of file SmoothCircleFromFileIC.C.

75 {
76  _centers.resize(_n_circles);
77  for (unsigned int i = 0; i < _n_circles; ++i)
78  {
79  _centers[i](0) = _data[_col_map[X]][i];
80  _centers[i](1) = _data[_col_map[Y]][i];
81  _centers[i](2) = _data[_col_map[Z]][i];
82  }
83 }
std::vector< Point > _centers
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data

◆ 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 SmoothCircleFromFileIC::computeCircleRadii ( )
protectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 68 of file SmoothCircleFromFileIC.C.

69 {
70  _radii.assign(_data[_col_map[R]].begin(), _data[_col_map[R]].end());
71 }
std::vector< Real > _radii
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data

◆ 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 SmoothCircleBaseIC::initialSetup ( )
virtualinherited

Reimplemented in MultiSmoothCircleIC, PolycrystalVoronoiVoidIC, and LatticeSmoothCircleIC.

Definition at line 57 of file SmoothCircleBaseIC.C.

Referenced by LatticeSmoothCircleIC::initialSetup(), and MultiSmoothCircleIC::initialSetup().

58 {
59  // Compute radii and centers and initialize vector sizes
62 
63  if (_centers.size() != _radii.size())
64  mooseError("_center and _radii vectors are not the same size in the Circle IC");
65 
66  if (_centers.size() < 1)
67  mooseError("_center and _radii were not initialized in the Circle IC");
68 }
std::vector< Real > _radii
std::vector< Point > _centers
virtual void computeCircleRadii()=0
virtual void computeCircleCenters()=0

◆ 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

◆ _centers

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

◆ _col_map

std::array<int, 4> SmoothCircleFromFileIC::_col_map = {{-1, -1, -1, -1}}
protected

◆ _col_names

std::vector<std::string> SmoothCircleFromFileIC::_col_names
protected

Definition at line 51 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

◆ _data

std::vector<std::vector<Real> > SmoothCircleFromFileIC::_data
protected

◆ _file_name

FileName SmoothCircleFromFileIC::_file_name
protected

Definition at line 49 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

◆ _int_width

Real SmoothCircleBaseIC::_int_width
protectedinherited

◆ _invalue

Real SmoothCircleBaseIC::_invalue
protectedinherited

◆ _mesh

MooseMesh& SmoothCircleBaseIC::_mesh
protectedinherited

◆ _n_circles

unsigned int SmoothCircleFromFileIC::_n_circles
protected

Definition at line 52 of file SmoothCircleFromFileIC.h.

Referenced by computeCircleCenters(), and SmoothCircleFromFileIC().

◆ _num_dim

unsigned int SmoothCircleBaseIC::_num_dim
protectedinherited

Definition at line 53 of file SmoothCircleBaseIC.h.

◆ _outvalue

Real SmoothCircleBaseIC::_outvalue
protectedinherited

◆ _profile

enum SmoothCircleBaseIC::ProfileType SmoothCircleBaseIC::_profile
protectedinherited

◆ _radii

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

◆ _random

MooseRandom SmoothCircleBaseIC::_random
protectedinherited

◆ _txt_reader

MooseUtils::DelimitedFileReader SmoothCircleFromFileIC::_txt_reader
protected

Definition at line 50 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

◆ _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: