www.mooseframework.org
OrientedSubdomainBoundingBoxGenerator.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 "CastUniquePointer.h"
12 
13 #include "libmesh/elem.h"
14 
16 
18 
21 {
24 
25  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
26 
27  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
28  params.addRequiredParam<subdomain_id_type>(
29  "block_id", "Subdomain id to set for inside/outside the bounding box");
30  params.addParam<MooseEnum>(
31  "location", location, "Control of where the subdomain id is to be set");
32 
33  return params;
34 }
35 
37  const InputParameters & parameters)
38  : MeshGenerator(parameters),
39  OrientedBoxInterface(parameters),
40  _input(getMesh("input")),
41  _location(parameters.get<MooseEnum>("location")),
42  _block_id(parameters.get<subdomain_id_type>("block_id"))
43 {
44 }
45 
46 std::unique_ptr<MeshBase>
48 {
49  std::unique_ptr<MeshBase> mesh = std::move(_input);
50 
51  // Loop over the elements
52  for (const auto & elem : mesh->active_element_ptr_range())
53  {
54  bool contains = containsPoint(elem->centroid());
55  if (contains && _location == "INSIDE")
56  elem->subdomain_id() = _block_id;
57  else if (!contains && _location == "OUTSIDE")
58  elem->subdomain_id() = _block_id;
59  }
60 
61  return dynamic_pointer_cast<MeshBase>(mesh);
62 }
OrientedBoxInterface::containsPoint
bool containsPoint(const Point &point)
Test if the supplied point is within the defined oriented bounding box.
Definition: OrientedBoxInterface.C:83
OrientedSubdomainBoundingBoxGenerator::OrientedSubdomainBoundingBoxGenerator
OrientedSubdomainBoundingBoxGenerator(const InputParameters &parameters)
Definition: OrientedSubdomainBoundingBoxGenerator.C:36
defineLegacyParams
defineLegacyParams(OrientedSubdomainBoundingBoxGenerator)
MeshGenerator
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
OrientedBoxInterface
Definition: OrientedBoxInterface.h:43
registerMooseObject
registerMooseObject("MooseApp", OrientedSubdomainBoundingBoxGenerator)
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
OrientedSubdomainBoundingBoxGenerator::validParams
static InputParameters validParams()
Definition: OrientedSubdomainBoundingBoxGenerator.C:20
OrientedSubdomainBoundingBoxGenerator::_location
const MooseEnum _location
ID location (inside of outside of box)
Definition: OrientedSubdomainBoundingBoxGenerator.h:39
OrientedSubdomainBoundingBoxGenerator::_block_id
const subdomain_id_type _block_id
Block ID to assign to the region.
Definition: OrientedSubdomainBoundingBoxGenerator.h:42
OrientedSubdomainBoundingBoxGenerator::_input
std::unique_ptr< MeshBase > & _input
Definition: OrientedSubdomainBoundingBoxGenerator.h:36
OrientedBoxInterface::validParams
static InputParameters validParams()
Class constructor.
Definition: OrientedBoxInterface.C:21
MeshGenerator::validParams
static InputParameters validParams()
Constructor.
Definition: MeshGenerator.C:17
OrientedSubdomainBoundingBoxGenerator.h
CastUniquePointer.h
OrientedSubdomainBoundingBoxGenerator::generate
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Definition: OrientedSubdomainBoundingBoxGenerator.C:47
OrientedSubdomainBoundingBoxGenerator
MeshGenerator for defining a Subdomain inside or outside of a bounding box with arbitrary orientation...
Definition: OrientedSubdomainBoundingBoxGenerator.h:26
InputParameters::addRequiredParam
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Definition: InputParameters.h:1176