https://mooseframework.inl.gov
ClosePackIC.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 // MOOSE includes
11 #include "ClosePackIC.h"
12 #include "MooseMesh.h"
13 #include "FEProblemBase.h"
14 
15 #include "libmesh/mesh_tools.h"
16 
17 registerMooseObject("PhaseFieldApp", ClosePackIC);
18 
21 {
23  params.addClassDescription("Close packed arrangement of smooth circles");
24  params.addRequiredParam<Real>("radius", "The radius of a circle");
25  return params;
26 }
27 
29  : SmoothCircleBaseIC(parameters), _radius(parameters.get<Real>("radius"))
30 {
31 }
32 
33 void
35 {
36  // Determine the extents of the mesh
37  BoundingBox bbox = MeshTools::create_bounding_box(_fe_problem.mesh().getMesh());
38  const Point & min = bbox.min();
39  const Point & max = bbox.max();
40 
41  // Create the x,y,z limits for the while loops
42  Real x_min = min(0);
43  Real x_max = max(0) + 2.0 * _radius;
44 
45  Real y_min = min(1) - 2.0 * std::sqrt(3.0) * _radius + _radius;
46  Real y_max = max(1) + 2.0 * _radius;
47 
48  // Real z_min = min(2) - 2*std::sqrt(3.0)*_radius + _radius;
49  Real z_max = 0.0;
50 
51  // Initialize the coordinates that will be used in looping
52  Real x = x_min;
53  Real y = y_min;
54  Real z = 0.0;
55 
56  // Adjust the 3D z-dimension maximum
57  if (_fe_problem.mesh().dimension() == 3)
58  z_max = max(2) + 2.0 * _radius;
59 
60  // Counters for offsetting every other row column in x,y dimensions
61  unsigned int i = 0;
62  unsigned int j = 0;
63 
64  while (z <= z_max)
65  {
66  // Offset the y-coordinate by sqrt(3)*r every other loop
67  if (j % 2 != 0)
68  y += std::sqrt(3) * _radius / 2.0;
69 
70  while (y <= y_max)
71  {
72 
73  // Offset the x-coordinate by r every other loop
74  if (i % 2 == 0)
75  x += _radius;
76 
77  while (x <= x_max)
78  {
79  _centers.push_back(Point(x, y, z));
80  _radii.push_back(_radius);
81  x += 2.0 * _radius;
82  }
83 
84  // Reset x-coord and increment y-coord
85  x = x_min;
86  y += std::sqrt(3.0) * _radius;
87  i++;
88  }
89 
90  // Reset y-coord and increment z-coord
91  y = y_min;
92  z += std::sqrt(3.0) * _radius;
93  j++;
94  }
95 }
static InputParameters validParams()
std::vector< Real > _radii
const Real _radius
User-supplied circle radius.
Definition: ClosePackIC.h:33
std::vector< Point > _centers
An InitialCondition for initializing phase variable in close packed circles/spheres pattern...
Definition: ClosePackIC.h:18
const std::vector< double > y
void addRequiredParam(const std::string &name, const std::string &doc_string)
auto max(const L &left, const R &right)
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
MeshBase & getMesh()
const std::vector< double > x
registerMooseObject("PhaseFieldApp", ClosePackIC)
virtual unsigned int dimension() const
ClosePackIC(const InputParameters &parameters)
Definition: ClosePackIC.C:28
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeCircleCenters()
Compute the close packed centers and radii.
Definition: ClosePackIC.C:34
virtual MooseMesh & mesh() override
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
FEProblemBase & _fe_problem
static InputParameters validParams()
Definition: ClosePackIC.C:20
auto min(const L &left, const R &right)
const Elem & get(const ElemType type_in)