www.mooseframework.org
ClosePackIC.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 // MOOSE includes
11 #include "ClosePackIC.h"
12 #include "MooseMesh.h"
13 
14 #include "libmesh/mesh_tools.h"
15 
16 registerMooseObject("PhaseFieldApp", ClosePackIC);
17 
18 template <>
19 InputParameters
21 {
22  InputParameters params = validParams<SmoothCircleBaseIC>();
23  params.addClassDescription("Close packed arrangement of smooth circles");
24  params.addRequiredParam<Real>("radius", "The radius of a circle");
25  return params;
26 }
27 
28 ClosePackIC::ClosePackIC(const InputParameters & parameters)
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 }
SmoothCircleBaseIC::_centers
std::vector< Point > _centers
Definition: SmoothCircleBaseIC.h:54
validParams< SmoothCircleBaseIC >
InputParameters validParams< SmoothCircleBaseIC >()
Definition: SmoothCircleBaseIC.C:18
SmoothCircleBaseIC
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
Definition: SmoothCircleBaseIC.h:26
ClosePackIC::ClosePackIC
ClosePackIC(const InputParameters &parameters)
Definition: ClosePackIC.C:28
ClosePackIC.h
SmoothCircleBaseIC::_radii
std::vector< Real > _radii
Definition: SmoothCircleBaseIC.h:55
ClosePackIC::computeCircleCenters
virtual void computeCircleCenters()
Compute the close packed centers and radii.
Definition: ClosePackIC.C:34
registerMooseObject
registerMooseObject("PhaseFieldApp", ClosePackIC)
ClosePackIC
An InitialCondition for initializing phase variable in close packed circles/spheres pattern.
Definition: ClosePackIC.h:24
validParams< ClosePackIC >
InputParameters validParams< ClosePackIC >()
Definition: ClosePackIC.C:20
ClosePackIC::_radius
const Real _radius
User-supplied circle radius.
Definition: ClosePackIC.h:37