15 #include "libmesh/elem.h" 23 params.
addClassDescription(
"Divide the mesh along a Cartesian grid. Numbering increases from " 24 "bottom to top and from left to right and from back to front. The " 25 "inner ordering is X, then Y, then Z");
26 params.
addParam<Point>(
"bottom_left",
"Bottom-back-left corner of the grid");
27 params.
addParam<Point>(
"top_right",
"Top-front-right corner of the grid");
28 params.
addParam<Point>(
"center",
"Center of the Cartesian grid");
29 params.
addParam<PositionsName>(
"center_positions",
30 "Positions of the centers of divided Cartesian grids");
31 params.
addParam<Point>(
"widths",
"Widths in the X, Y and Z directions");
36 "assign_domain_outside_grid_to_border",
38 "Whether to map the domain outside the grid back to the border of the grid");
45 _bottom_left(isParamValid(
"bottom_left") ? getParam<Point>(
"bottom_left") : Point(0, 0, 0)),
46 _top_right(isParamValid(
"top_right") ? getParam<Point>(
"top_right") : Point(0, 0, 0)),
47 _center(isParamValid(
"center") ? &getParam<Point>(
"center") : nullptr),
49 isParamValid(
"center_positions")
50 ? &_fe_problem->getPositionsObject(getParam<PositionsName>(
"center_positions"))
52 _widths(isParamValid(
"widths") ? getParam<Point>(
"widths") : Point(_top_right - _bottom_left)),
53 _nx(getParam<unsigned
int>(
"nx")),
54 _ny(getParam<unsigned
int>(
"ny")),
55 _nz(getParam<unsigned
int>(
"nz")),
56 _outside_grid_counts_as_border(getParam<bool>(
"assign_domain_outside_grid_to_border"))
62 mooseError(
"Either the center or the edges of the grids must be specified");
65 "Both bottom_left and top_right must be passed to be able to determine the width");
77 "Top-front-right corner must be right (X axis) of bottom-left-back corner");
80 "Top-front-right corner must be in front (Y axis) of bottom-left-back corner");
83 "Top-front-right corner must be on top (Z axis) of bottom-left-back corner");
85 paramError(
"nx",
"Subdivision number must be 1 if width is 0 in X direction");
87 paramError(
"ny",
"Subdivision number must be 1 if width is 0 in Y direction");
89 paramError(
"nz",
"Subdivision number must be 1 if width is 0 in Z direction");
109 "Cartesian grids centered on the positions are too close to each other (min distance: ",
111 "), closer than the extent of each grid. Mesh division is ill-defined");
142 unsigned int offset = 0;
144 Point bottom_left, top_right, p;
151 offset = nearest_grid_center_index *
_nx *
_ny *
_nz;
152 const auto nearest_grid_center =
156 p = pt - nearest_grid_center;
179 auto ix = not_found, iy = not_found, iz = not_found;
184 const auto border_x = bottom_left(0) +
_widths(0) * jx /
_nx;
187 "Querying the division index for a point of a boundary between two regions in X: " +
189 if (border_x >= p(0))
191 ix = (jx > 0) ? jx - 1 : 0;
197 const auto border_y = bottom_left(1) +
_widths(1) * jy /
_ny;
200 "Querying the division index for a point of a boundary between two regions in Y: " +
202 if (border_y >= p(1))
204 iy = (jy > 0) ? jy - 1 : 0;
210 const auto border_z = bottom_left(2) +
_widths(2) * jz /
_nz;
213 "Querying the division index for a point of a boundary between two regions in Z: " +
215 if (border_z >= p(2))
217 iz = (jz > 0) ? jz - 1 : 0;
237 mooseAssert(ix != not_found,
"We should have found a mesh division bin in X");
238 mooseAssert(iy != not_found,
"We should have found a mesh division bin in Y");
239 mooseAssert(iz != not_found,
"We should have found a mesh division bin in Z");
241 return offset + ix +
_nx * iy + iz *
_nx *
_ny;
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Point _top_right
Top right point of the grid.
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
Divides the mesh based on a Cartesian grid.
const Point _widths
Width of the grid in all 3 axes.
const Point & getPosition(unsigned int index, bool initial) const
Getter for a single position at a known index.
const Point *const _center
Center of the grid, if user-specified.
Base class for MeshDivision objects.
const MooseMesh & _mesh
Mesh that is being divided.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
unsigned int getNearestPositionIndex(const Point &target, bool initial) const
Find the nearest Position index for a given point.
const bool _outside_grid_counts_as_border
Whether to map outside the grid onto the corner.
Point _bottom_left
Bottom left point of the grid.
const unsigned int _nx
Number of divisions in the X direction.
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
unsigned int getNumPositions(bool initial=false) const
}
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
std::string stringify(const T &t)
conversion to string
unsigned int INVALID_DIVISION_INDEX
Invalid subdomain id to return when outside the mesh division.
static InputParameters validParams()
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index...
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CartesianGridDivision(const InputParameters ¶meters)
const unsigned int _ny
Number of divisions in the Y direction.
const FEProblemBase *const _fe_problem
Pointer to the problem, needed to retrieve pointers to various objects.
IntRange< T > make_range(T beg, T end)
libMesh::BoundingBox getInflatedProcessorBoundingBox(Real inflation_multiplier=0.01) const
Get a (slightly inflated) processor bounding box.
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within an absolute ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const Positions *const _center_positions
Positions object holding the centers of the grids, if user-specified.
Real getMinDistanceBetweenPositions() const
Find the minimum distance between positions.
static InputParameters validParams()
Class constructor.
void ErrorVector unsigned int
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
const unsigned int _nz
Number of divisions in the Z direction.
registerMooseObject("MooseApp", CartesianGridDivision)
const ExecFlagType EXEC_INITIAL