https://mooseframework.inl.gov
OrientedSubdomainBoundingBoxGenerator.C
Go to the documentation of this file.
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 
11 #include "CastUniquePointer.h"
12 
13 #include "libmesh/elem.h"
14 
16 
19 {
22 
23  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
24 
25  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
27  "block_id", "Subdomain id to set for inside/outside the bounding box");
28  params.addParam<MooseEnum>(
29  "location", location, "Control of where the subdomain id is to be set");
30  params.addClassDescription(
31  "Defines a subdomain inside or outside of a bounding box with arbitrary orientation.");
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->vertex_average());
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  mesh->set_isnt_prepared();
62  return dynamic_pointer_cast<MeshBase>(mesh);
63 }
bool containsPoint(const Point &point)
Test if the supplied point is within the defined oriented bounding box.
static InputParameters validParams()
Class constructor.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
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...
MeshGenerator for defining a Subdomain inside or outside of a bounding box with arbitrary orientation...
registerMooseObject("MooseApp", OrientedSubdomainBoundingBoxGenerator)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
static InputParameters validParams()
Definition: MeshGenerator.C:23
const subdomain_id_type _block_id
Block ID to assign to the region.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
OrientedSubdomainBoundingBoxGenerator(const InputParameters &parameters)
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
const MooseEnum _location
ID location (inside or outside of the bounding box)