www.mooseframework.org
SubdomainBoundingBox.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 
10 #include "SubdomainBoundingBox.h"
11 #include "Conversion.h"
12 #include "MooseMesh.h"
13 
14 #include "libmesh/elem.h"
15 
17 
18 template <>
21 {
22  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
23 
25  params.addClassDescription("Changes the subdomain ID of elements either (XOR) inside or outside "
26  "the specified box to the specified ID.");
28  "bottom_left", "The bottom left point (in x,y,z with spaces in-between).");
30  "top_right", "The bottom left point (in x,y,z with spaces in-between).");
31  params.addRequiredParam<SubdomainID>("block_id",
32  "Subdomain id to set for inside/outside the bounding box");
33  params.addParam<SubdomainName>(
34  "block_name", "Subdomain name to set for inside/outside the bounding box (optional)");
35  params.addParam<MooseEnum>(
36  "location", location, "Control of where the subdomain id is to be set");
37 
38  return params;
39 }
40 
42  : MeshModifier(parameters),
43  _location(parameters.get<MooseEnum>("location")),
44  _block_id(parameters.get<SubdomainID>("block_id")),
45  _bounding_box(parameters.get<RealVectorValue>("bottom_left"),
46  parameters.get<RealVectorValue>("top_right"))
47 {
48 }
49 
50 void
52 {
53  // Check that we have access to the mesh
54  if (!_mesh_ptr)
55  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
56 
57  // Loop over the elements
58  for (const auto & elem : _mesh_ptr->getMesh().active_element_ptr_range())
59  {
60  bool contains = _bounding_box.contains_point(elem->centroid());
61  if (contains && _location == "INSIDE")
62  elem->subdomain_id() = _block_id;
63  else if (!contains && _location == "OUTSIDE")
64  elem->subdomain_id() = _block_id;
65  }
66 
67  // Assign block name, if provided
68  if (isParamValid("block_name"))
69  _mesh_ptr->getMesh().subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
70 }
BoundingBox _bounding_box
Bounding box for testing element centroids against.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
SubdomainBoundingBox(const InputParameters &parameters)
Class constructor.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", SubdomainBoundingBox)
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
MooseEnum _location
ID location (inside of outside of box)
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
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
InputParameters validParams< SubdomainBoundingBox >()
MeshModifier for defining a Subdomain inside or outside of a bounding box.
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...
SubdomainID _block_id
Block ID to assign to the region.
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15