Line data Source code
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 : 19 : InputParameters 20 34 : ClosePackIC::validParams() 21 : { 22 34 : InputParameters params = SmoothCircleBaseIC::validParams(); 23 34 : params.addClassDescription("Close packed arrangement of smooth circles"); 24 68 : params.addRequiredParam<Real>("radius", "The radius of a circle"); 25 34 : return params; 26 0 : } 27 : 28 18 : ClosePackIC::ClosePackIC(const InputParameters & parameters) 29 18 : : SmoothCircleBaseIC(parameters), _radius(parameters.get<Real>("radius")) 30 : { 31 18 : } 32 : 33 : void 34 15 : ClosePackIC::computeCircleCenters() 35 : { 36 : // Determine the extents of the mesh 37 15 : 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 15 : Real x_min = min(0); 43 15 : Real x_max = max(0) + 2.0 * _radius; 44 : 45 15 : Real y_min = min(1) - 2.0 * std::sqrt(3.0) * _radius + _radius; 46 15 : 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 15 : if (_fe_problem.mesh().dimension() == 3) 58 9 : 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 66 : while (z <= z_max) 65 : { 66 : // Offset the y-coordinate by sqrt(3)*r every other loop 67 51 : if (j % 2 != 0) 68 18 : y += std::sqrt(3) * _radius / 2.0; 69 : 70 345 : while (y <= y_max) 71 : { 72 : 73 : // Offset the x-coordinate by r every other loop 74 294 : if (i % 2 == 0) 75 150 : x += _radius; 76 : 77 1656 : while (x <= x_max) 78 : { 79 1362 : _centers.push_back(Point(x, y, z)); 80 1362 : _radii.push_back(_radius); 81 1362 : x += 2.0 * _radius; 82 : } 83 : 84 : // Reset x-coord and increment y-coord 85 : x = x_min; 86 294 : y += std::sqrt(3.0) * _radius; 87 294 : i++; 88 : } 89 : 90 : // Reset y-coord and increment z-coord 91 : y = y_min; 92 51 : z += std::sqrt(3.0) * _radius; 93 51 : j++; 94 : } 95 15 : }