www.mooseframework.org
SubdomainBoundingBox.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "SubdomainBoundingBox.h"
16 #include "Conversion.h"
17 #include "MooseMesh.h"
18 
19 template <>
22 {
23  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
24 
26  params.addClassDescription("Changes the subdomain ID of elements either (XOR) inside or outside "
27  "the specified box to the specified ID.");
29  "bottom_left", "The bottom left point (in x,y,z with spaces in-between).");
31  "top_right", "The bottom left point (in x,y,z with spaces in-between).");
32  params.addRequiredParam<SubdomainID>("block_id",
33  "Subdomain id to set for inside/outside the bounding box");
34  params.addParam<SubdomainName>(
35  "block_name", "Subdomain name to set for inside/outside the bounding box (optional)");
36  params.addParam<MooseEnum>(
37  "location", location, "Control of where the subdomain id is to be set");
38 
39  return params;
40 }
41 
43  : MeshModifier(parameters),
44  _location(parameters.get<MooseEnum>("location")),
45  _block_id(parameters.get<SubdomainID>("block_id")),
46  _bounding_box(parameters.get<RealVectorValue>("bottom_left"),
47  parameters.get<RealVectorValue>("top_right"))
48 {
49 }
50 
51 void
53 {
54  // Check that we have access to the mesh
55  if (!_mesh_ptr)
56  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
57 
58  // Loop over the elements
59  for (const auto & elem : _mesh_ptr->getMesh().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_ptr->getMesh().subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
71 }
BoundingBox _bounding_box
Bounding box for testing element centroids against.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:31
SubdomainBoundingBox(const InputParameters &parameters)
Class constructor.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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:74
MooseEnum _location
ID location (inside of outside of box)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
InputParameters validParams< SubdomainBoundingBox >()
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20