www.mooseframework.org
OrientedSubdomainBoundingBox.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 
11 #include "MooseMesh.h"
12 
13 #include "libmesh/elem.h"
14 
16 
17 template <>
20 {
23 
24  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
25  params.addRequiredParam<SubdomainID>("block_id",
26  "Subdomain id to set for inside/outside the bounding box");
27  params.addParam<MooseEnum>(
28  "location", location, "Control of where the subdomain id is to be set");
29 
30  return params;
31 }
32 
34  : MeshModifier(parameters),
35  OrientedBoxInterface(parameters),
36  _location(parameters.get<MooseEnum>("location")),
37  _block_id(parameters.get<SubdomainID>("block_id"))
38 
39 {
40 }
41 
42 void
44 {
45  // Check that we have access to the mesh
46  if (!_mesh_ptr)
47  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
48 
49  // Loop over the elements
50  for (const auto & elem : _mesh_ptr->getMesh().active_element_ptr_range())
51  {
52  bool contains = containsPoint(elem->centroid());
53  if (contains && _location == "INSIDE")
54  elem->subdomain_id() = _block_id;
55  else if (!contains && _location == "OUTSIDE")
56  elem->subdomain_id() = _block_id;
57  }
58 }
bool containsPoint(const Point &point)
Test if the supplied point is within the defined oriented bounding box.
MeshModifier for defining a Subdomain inside or outside of a bounding box with arbitrary orientation...
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
InputParameters validParams< OrientedSubdomainBoundingBox >()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
subdomain_id_type SubdomainID
registerMooseObject("MooseApp", OrientedSubdomainBoundingBox)
OrientedSubdomainBoundingBox(const InputParameters &parameters)
Class constructor.
const SubdomainID _block_id
Block ID to assign to the region.
const MooseEnum _location
ID location (inside of outside of box)
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15
InputParameters validParams< OrientedBoxInterface >()