www.mooseframework.org
PFCFreezingIC.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<RandomICBase>();
20  params.addRequiredParam<Real>("x1",
21  "The x coordinate of the lower left-hand corner of the frozen box");
22  params.addRequiredParam<Real>("y1",
23  "The y coordinate of the lower left-hand corner of the frozen box");
24  params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
25 
26  params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
27  params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
28  params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
29 
30  params.addParam<Real>("min", 0.0, "Lower bound of the randomly generated values");
31  params.addParam<Real>("max", 1.0, "Upper bound of the randomly generated values");
32  params.addParam<Real>("inside", 1.0, "Value inside sinusoids");
33  params.addParam<Real>("outside", 0.0, "Value outside sinusoids");
34 
35  params.addRequiredParam<Real>("lc", "The lattice constant off the crystal structure");
36 
37  MooseEnum crystal_structures("FCC BCC");
38  params.addParam<MooseEnum>(
39  "crystal_structure", crystal_structures, "The type of crystal structure");
40 
41  return params;
42 }
43 
44 PFCFreezingIC::PFCFreezingIC(const InputParameters & parameters)
45  : RandomICBase(parameters),
46  _x1(getParam<Real>("x1")),
47  _y1(getParam<Real>("y1")),
48  _z1(getParam<Real>("z1")),
49  _x2(getParam<Real>("x2")),
50  _y2(getParam<Real>("y2")),
51  _z2(getParam<Real>("z2")),
52  _lc(getParam<Real>("lc")),
53  _crystal_structure(getParam<MooseEnum>("crystal_structure")),
54  _bottom_left(_x1, _y1, _z1),
55  _top_right(_x2, _y2, _z2),
56  _range(_top_right - _bottom_left),
57  _min(getParam<Real>("min")),
58  _max(getParam<Real>("max")),
59  _val_range(_max - _min),
60  _inside(getParam<Real>("inside")),
61  _outside(getParam<Real>("outside"))
62 {
63  _console << "MooseEnum? " << _crystal_structure << std::endl;
64 
65  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
66  mooseAssert(_range(i) >= 0.0, "x1, y1 or z1 is not less than x2, y2 or z2");
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 * generateRandom();
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 }
PFCFreezingIC::value
virtual Real value(const Point &p)
Definition: PFCFreezingIC.C:77
PFCFreezingIC::PFCFreezingIC
PFCFreezingIC(const InputParameters &parameters)
Definition: PFCFreezingIC.C:44
PFCFreezingIC.h
PFCFreezingIC::_min
Real _min
Definition: PFCFreezingIC.h:50
registerMooseObject
registerMooseObject("PhaseFieldApp", PFCFreezingIC)
PFCFreezingIC::_crystal_structure
MooseEnum _crystal_structure
Definition: PFCFreezingIC.h:44
validParams< PFCFreezingIC >
InputParameters validParams< PFCFreezingIC >()
Definition: PFCFreezingIC.C:17
PFCFreezingIC::_val_range
Real _val_range
Definition: PFCFreezingIC.h:50
PFCFreezingIC::_lc
Real _lc
Definition: PFCFreezingIC.h:43
PFCFreezingIC::_inside
Real _inside
Definition: PFCFreezingIC.h:51
PFCFreezingIC::_top_right
Point _top_right
Definition: PFCFreezingIC.h:47
PFCFreezingIC::_outside
Real _outside
Definition: PFCFreezingIC.h:51
PFCFreezingIC::_bottom_left
Point _bottom_left
Definition: PFCFreezingIC.h:46
PFCFreezingIC
PFCFreezingIC creates an initial density for a PFC model that has one area of a set crystal structure...
Definition: PFCFreezingIC.h:27
PFCFreezingIC::_icdim
unsigned int _icdim
Definition: PFCFreezingIC.h:53
PFCFreezingIC::_range
Point _range
Definition: PFCFreezingIC.h:48