www.mooseframework.org
SubdomainBoundingBoxGenerator.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 "Conversion.h"
12 #include "CastUniquePointer.h"
13 
14 #include "libmesh/elem.h"
15 
17 
18 template <>
21 {
22  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
23 
25 
26  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
27  params.addClassDescription("Changes the subdomain ID of elements either (XOR) inside or outside "
28  "the specified box to the specified ID.");
30  "bottom_left", "The bottom left point (in x,y,z with spaces in-between).");
32  "top_right", "The bottom left point (in x,y,z with spaces in-between).");
33  params.addRequiredParam<subdomain_id_type>(
34  "block_id", "Subdomain id to set for inside/outside the bounding box");
35  params.addParam<SubdomainName>(
36  "block_name", "Subdomain name to set for inside/outside the bounding box (optional)");
37  params.addParam<MooseEnum>(
38  "location", location, "Control of where the subdomain id is to be set");
39 
40  return params;
41 }
42 
44  : MeshGenerator(parameters),
45  _input(getMesh("input")),
46  _location(parameters.get<MooseEnum>("location")),
47  _block_id(parameters.get<subdomain_id_type>("block_id")),
48  _bounding_box(parameters.get<RealVectorValue>("bottom_left"),
49  parameters.get<RealVectorValue>("top_right"))
50 {
51 }
52 
53 std::unique_ptr<MeshBase>
55 {
56  std::unique_ptr<MeshBase> mesh = std::move(_input);
57 
58  // Loop over the elements
59  for (const auto & elem : mesh->active_element_ptr_range())
60  {
61  bool contains = _bounding_box.contains_point(elem->centroid());
62  if (contains && _location == "INSIDE")
63  elem->subdomain_id() = _block_id;
64  else if (!contains && _location == "OUTSIDE")
65  elem->subdomain_id() = _block_id;
66  }
67 
68  // Assign block name, if provided
69  if (isParamValid("block_name"))
70  mesh->subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
71 
72  return dynamic_pointer_cast<MeshBase>(mesh);
73 }
MeshGenerator for defining a Subdomain inside or outside of a bounding box.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
SubdomainBoundingBoxGenerator(const InputParameters &parameters)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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.
std::unique_ptr< MeshBase > & _input
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...
subdomain_id_type _block_id
Block ID to assign to the region.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
registerMooseObject("MooseApp", SubdomainBoundingBoxGenerator)
MooseEnum _location
ID location (inside of outside of box)
InputParameters validParams< SubdomainBoundingBoxGenerator >()
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 option parameter and a documentation string to the InputParameters object...
InputParameters validParams< MeshGenerator >()
Definition: MeshGenerator.C:16
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
BoundingBox _bounding_box
Bounding box for testing element centroids against.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:30