www.mooseframework.org
PFCFreezingIC.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 "PFCFreezingIC.h"
9 #include "MooseRandom.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<InitialCondition>();
16  params.addRequiredParam<Real>("x1",
17  "The x coordinate of the lower left-hand corner of the frozen box");
18  params.addRequiredParam<Real>("y1",
19  "The y coordinate of the lower left-hand corner of the frozen box");
20  params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
21 
22  params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
23  params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
24  params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
25 
26  params.addParam<Real>("min", 0.0, "Lower bound of the randomly generated values");
27  params.addParam<Real>("max", 1.0, "Upper bound of the randomly generated values");
28  params.addParam<Real>("inside", 1.0, "Value inside sinusoids");
29  params.addParam<Real>("outside", 0.0, "Value outside sinusoids");
30 
31  params.addRequiredParam<Real>("lc", "The lattice constant off the crystal structure");
32 
33  MooseEnum crystal_structures("FCC BCC");
34  params.addParam<MooseEnum>(
35  "crystal_structure", crystal_structures, "The type of crystal structure");
36 
37  params.addParam<unsigned int>("seed", 0, "Seed value for the random number generator");
38 
39  return params;
40 }
41 
42 PFCFreezingIC::PFCFreezingIC(const InputParameters & parameters)
43  : InitialCondition(parameters),
44  _x1(getParam<Real>("x1")),
45  _y1(getParam<Real>("y1")),
46  _z1(getParam<Real>("z1")),
47  _x2(getParam<Real>("x2")),
48  _y2(getParam<Real>("y2")),
49  _z2(getParam<Real>("z2")),
50  _lc(getParam<Real>("lc")),
51  _crystal_structure(getParam<MooseEnum>("crystal_structure")),
52  _bottom_left(_x1, _y1, _z1),
53  _top_right(_x2, _y2, _z2),
54  _range(_top_right - _bottom_left),
55  _min(getParam<Real>("min")),
56  _max(getParam<Real>("max")),
57  _val_range(_max - _min),
58  _inside(getParam<Real>("inside")),
59  _outside(getParam<Real>("outside"))
60 {
61  _console << "MooseEnum? " << _crystal_structure << std::endl;
62 
63  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
64  mooseAssert(_range(i) >= 0.0, "x1, y1 or z1 is not less than x2, y2 or z2");
65 
66  MooseRandom::seed(getParam<unsigned int>("seed"));
67 
68  if (_range(1) == 0.0)
69  _icdim = 1;
70  else if (_range(2) < 1.0e-10 * _range(0))
71  _icdim = 2;
72  else
73  _icdim = 3;
74 }
75 
76 Real
77 PFCFreezingIC::value(const Point & p)
78 {
79  // If out of bounds, set random value
80  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
81  if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
82  return _min + _val_range * MooseRandom::rand();
83 
84  // If in bounds, set sinusoid IC to make atoms
85  Real val = 0.0;
86  if (_crystal_structure == "FCC")
87  {
88  // Note: this effectively (and now explicitly) returns 0.0 for FCC.
89  return 0.0;
90 
91  for (unsigned int i = 0; i < _icdim; i++)
92  val += std::cos((2.0 / _lc * p(i)) * libMesh::pi);
93  }
94  else
95  {
96  if (_icdim > 2)
97  {
98  for (unsigned int i = 0; i < _icdim; i++)
99  // one mode approximation for initial condition
100  val += (std::cos((2.0 / _lc * p(i % 3)) * libMesh::pi) *
101  std::cos((2.0 / _lc * p((i + 1) % 3)) * libMesh::pi)) /
102  4.0; // Doesn't work in 2D
103  }
104  else
105  {
106  for (unsigned int i = 0; i < _icdim; i++)
107  val *= std::cos((2.0 / _lc * p(i)) * libMesh::pi); // 2D IC for 111 plane
108 
109  val = val / 2.0 + 0.5;
110  }
111  }
112 
113  Real amp = _inside - _outside;
114  val = amp * val + _outside;
115 
116  return val;
117 }
Point _bottom_left
Definition: PFCFreezingIC.h:44
MooseEnum _crystal_structure
Definition: PFCFreezingIC.h:42
InputParameters validParams< PFCFreezingIC >()
Definition: PFCFreezingIC.C:13
virtual Real value(const Point &p)
Definition: PFCFreezingIC.C:77
PFCFreezingIC(const InputParameters &parameters)
Definition: PFCFreezingIC.C:42
unsigned int _icdim
Definition: PFCFreezingIC.h:51