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