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 }
 

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
 
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 27 of file SmoothCircleFromFileIC.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

SmoothCircleFromFileIC::SmoothCircleFromFileIC ( const InputParameters &  parameters)

Definition at line 20 of file SmoothCircleFromFileIC.C.

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

void SmoothCircleFromFileIC::computeCircleCenters ( )
protectedvirtual

Implements SmoothCircleBaseIC.

Definition at line 69 of file SmoothCircleFromFileIC.C.

70 {
71  _centers.resize(_n_circles);
72  for (unsigned int i = 0; i < _n_circles; ++i)
73  {
74  _centers[i](0) = _data[_col_map[X]][i];
75  _centers[i](1) = _data[_col_map[Y]][i];
76  _centers[i](2) = _data[_col_map[Z]][i];
77  }
78 }
std::vector< Point > _centers
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data
RealGradient SmoothCircleBaseIC::computeCircleGradient ( const Point &  p,
const Point &  center,
const Real &  radius 
)
protectedvirtualinherited

Definition at line 127 of file SmoothCircleBaseIC.C.

Referenced by SmoothCircleBaseIC::gradient().

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

Implements SmoothCircleBaseIC.

Definition at line 63 of file SmoothCircleFromFileIC.C.

64 {
65  _radii.assign(_data[_col_map[R]].begin(), _data[_col_map[R]].end());
66 }
std::vector< Real > _radii
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data
Real SmoothCircleBaseIC::computeCircleValue ( const Point &  p,
const Point &  center,
const Real &  radius 
)
protectedvirtualinherited

Reimplemented in RndSmoothCircleIC.

Definition at line 100 of file SmoothCircleBaseIC.C.

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

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 }
virtual Real value(const Point &p)
RealGradient SmoothCircleBaseIC::gradient ( const Point &  p)
virtualinherited

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 77 of file SmoothCircleBaseIC.C.

Referenced by PolycrystalVoronoiVoidIC::gradient().

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

Reimplemented in PolycrystalVoronoiVoidIC, LatticeSmoothCircleIC, and MultiSmoothCircleIC.

Definition at line 47 of file SmoothCircleBaseIC.C.

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

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 }
std::vector< Real > _radii
std::vector< Point > _centers
virtual void computeCircleRadii()=0
virtual void computeCircleCenters()=0
Real SmoothCircleBaseIC::value ( const Point &  p)
virtualinherited

Reimplemented in PolycrystalVoronoiVoidIC.

Definition at line 61 of file SmoothCircleBaseIC.C.

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

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 }
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

bool SmoothCircleBaseIC::_3D_spheres
protectedinherited
std::vector<Point> SmoothCircleBaseIC::_centers
protectedinherited
std::array<int, 4> SmoothCircleFromFileIC::_col_map = {{-1, -1, -1, -1}}
protected
std::vector<std::string> SmoothCircleFromFileIC::_col_names
protected

Definition at line 48 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

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

Definition at line 46 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

Real SmoothCircleBaseIC::_int_width
protectedinherited
Real SmoothCircleBaseIC::_invalue
protectedinherited
MooseMesh& SmoothCircleBaseIC::_mesh
protectedinherited
unsigned int SmoothCircleFromFileIC::_n_circles
protected

Definition at line 49 of file SmoothCircleFromFileIC.h.

Referenced by computeCircleCenters(), and SmoothCircleFromFileIC().

unsigned int SmoothCircleBaseIC::_num_dim
protectedinherited

Definition at line 50 of file SmoothCircleBaseIC.h.

Real SmoothCircleBaseIC::_outvalue
protectedinherited
std::vector<Real> SmoothCircleBaseIC::_radii
protectedinherited
MooseRandom SmoothCircleBaseIC::_random
protectedinherited
MooseUtils::DelimitedFileReader SmoothCircleFromFileIC::_txt_reader
protected

Definition at line 47 of file SmoothCircleFromFileIC.h.

Referenced by SmoothCircleFromFileIC().

bool SmoothCircleBaseIC::_zero_gradient
protectedinherited

Definition at line 48 of file SmoothCircleBaseIC.h.

Referenced by SmoothCircleBaseIC::gradient().


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