https://mooseframework.inl.gov
PFCFreezingIC.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "PFCFreezingIC.h"
11 #include "MooseRandom.h"
12 
13 registerMooseObject("PhaseFieldApp", PFCFreezingIC);
14 
17 {
19  params.addRequiredParam<Real>("x1",
20  "The x coordinate of the lower left-hand corner of the frozen box");
21  params.addRequiredParam<Real>("y1",
22  "The y coordinate of the lower left-hand corner of the frozen box");
23  params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
24 
25  params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
26  params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
27  params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
28 
29  params.addParam<Real>("min", 0.0, "Lower bound of the randomly generated values");
30  params.addParam<Real>("max", 1.0, "Upper bound of the randomly generated values");
31  params.addParam<Real>("inside", 1.0, "Value inside sinusoids");
32  params.addParam<Real>("outside", 0.0, "Value outside sinusoids");
33 
34  params.addRequiredParam<Real>("lc", "The lattice constant off the crystal structure");
35 
36  MooseEnum crystal_structures("FCC BCC");
37  params.addParam<MooseEnum>(
38  "crystal_structure", crystal_structures, "The type of crystal structure");
39 
40  return params;
41 }
42 
44  : RandomICBase(parameters),
45  _x1(getParam<Real>("x1")),
46  _y1(getParam<Real>("y1")),
47  _z1(getParam<Real>("z1")),
48  _x2(getParam<Real>("x2")),
49  _y2(getParam<Real>("y2")),
50  _z2(getParam<Real>("z2")),
51  _lc(getParam<Real>("lc")),
52  _crystal_structure(getParam<MooseEnum>("crystal_structure")),
53  _bottom_left(_x1, _y1, _z1),
54  _top_right(_x2, _y2, _z2),
55  _range(_top_right - _bottom_left),
56  _min(getParam<Real>("min")),
57  _max(getParam<Real>("max")),
58  _val_range(_max - _min),
59  _inside(getParam<Real>("inside")),
60  _outside(getParam<Real>("outside"))
61 {
62  for (const auto i : make_range(Moose::dim))
63  if (_range(i) < 0.0)
64  mooseError("x1, y1 or z1 is not less than x2, y2 or z2");
65 
66  if (_range(1) == 0.0)
67  _icdim = 1;
68  else if (_range(2) < 1.0e-10 * _range(0))
69  _icdim = 2;
70  else
71  _icdim = 3;
72 }
73 
74 Real
75 PFCFreezingIC::value(const Point & p)
76 {
77  // If out of bounds, set random value
78  for (const auto i : make_range(Moose::dim))
79  if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
80  return _min + _val_range * generateRandom();
81 
82  // If in bounds, set sinusoid IC to make atoms
83  Real val = 0.0;
84  if (_crystal_structure == "FCC")
85  {
86  // Note: this effectively (and now explicitly) returns 0.0 for FCC.
87  return 0.0;
88 
89  for (unsigned int i = 0; i < _icdim; i++)
90  val += std::cos((2.0 / _lc * p(i)) * libMesh::pi);
91  }
92  else
93  {
94  if (_icdim > 2)
95  {
96  for (unsigned int i = 0; i < _icdim; i++)
97  // one mode approximation for initial condition
98  val += (std::cos((2.0 / _lc * p(i % 3)) * libMesh::pi) *
99  std::cos((2.0 / _lc * p((i + 1) % 3)) * libMesh::pi)) /
100  4.0; // Doesn't work in 2D
101  }
102  else
103  {
104  for (unsigned int i = 0; i < _icdim; i++)
105  val *= std::cos((2.0 / _lc * p(i)) * libMesh::pi); // 2D IC for 111 plane
106 
107  val = val / 2.0 + 0.5;
108  }
109  }
110 
111  Real amp = _inside - _outside;
112  val = amp * val + _outside;
113 
114  return val;
115 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Real generateRandom()
static InputParameters validParams()
Definition: PFCFreezingIC.C:16
Point _bottom_left
Definition: PFCFreezingIC.h:42
static constexpr std::size_t dim
MooseEnum _crystal_structure
Definition: PFCFreezingIC.h:40
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObject("PhaseFieldApp", PFCFreezingIC)
PFCFreezingIC creates an initial density for a PFC model that has one area of a set crystal structure...
Definition: PFCFreezingIC.h:21
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real value(const Point &p)
Definition: PFCFreezingIC.C:75
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
PFCFreezingIC(const InputParameters &parameters)
Definition: PFCFreezingIC.C:43
static InputParameters validParams()
unsigned int _icdim
Definition: PFCFreezingIC.h:49
const Real pi