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