Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
SubdomainsDivision.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 
10 #include "SubdomainsDivision.h"
11 #include "MooseMesh.h"
12 
13 #include "libmesh/mesh_base.h"
14 #include "libmesh/elem.h"
15 
17 
20 {
23  params.addClassDescription(
24  "Divide the mesh by increasing subdomain ids. The division will be contiguously "
25  "numbered even if the subdomain ids are not");
26  return params;
27 }
28 
30  : MeshDivision(parameters), BlockRestrictable(this)
31 {
33  _mesh_fully_indexed = true;
34 }
35 
36 void
38 {
39  if (!blockRestricted())
40  {
41  // The subdomains may not be contiguously numbered
42  const auto & subdomain_ids = blockIDs();
43  setNumDivisions(subdomain_ids.size());
44  unsigned int i = 0;
45  for (const auto sub_id : subdomain_ids)
47  }
48  else
49  {
50  // Follow the user input order, use a vector instead of a set
51  const auto subdomain_ids = _mesh.getSubdomainIDs(blocks());
52  setNumDivisions(subdomain_ids.size());
53  unsigned int i = 0;
54  for (const auto sub_id : subdomain_ids)
56  }
57 }
58 
59 unsigned int
60 SubdomainsDivision::divisionIndex(const Elem & elem) const
61 {
62  const auto id_it = _subdomain_ids_to_division_index.find(elem.subdomain_id());
63  if (id_it != _subdomain_ids_to_division_index.end())
64  return id_it->second;
65  else
66  {
67  mooseAssert(blockRestricted(), "We should be block restricted");
69  }
70 }
71 
72 unsigned int
73 SubdomainsDivision::divisionIndex(const Point & pt) const
74 {
75  const auto & pl = _mesh.getMesh().sub_point_locator();
76  // There could be more than one elem if we are on the edge between two elements
77  std::set<const Elem *> candidates;
78  (*pl)(pt, candidates);
79 
80  // By convention we will use the element with the lowest subdomain id
81  const Elem * elem = nullptr;
82  unsigned int min_sub_id = Moose::INVALID_BLOCK_ID;
83  for (const auto elem_ptr : candidates)
84  if (elem_ptr->subdomain_id() < min_sub_id)
85  {
86  elem = elem_ptr;
87  min_sub_id = elem_ptr->subdomain_id();
88  }
89 
90  return libmesh_map_find(_subdomain_ids_to_division_index, elem->subdomain_id());
91 }
SubdomainsDivision(const InputParameters &parameters)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
registerMooseObject("MooseApp", SubdomainsDivision)
Base class for MeshDivision objects.
Definition: MeshDivision.h:35
const MooseMesh & _mesh
Mesh that is being divided.
Definition: MeshDivision.h:74
static InputParameters validParams()
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3437
unsigned int INVALID_DIVISION_INDEX
Invalid subdomain id to return when outside the mesh division.
Definition: MeshDivision.h:28
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index...
Definition: MeshDivision.h:77
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
Definition: MeshDivision.h:65
const std::vector< SubdomainName > & blocks() const
Return the block names for this object.
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
Divides the mesh based on the subdomains.
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
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...
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1734
static InputParameters validParams()
Class constructor.
Definition: MeshDivision.C:14
std::unordered_map< SubdomainID, unsigned int > _subdomain_ids_to_division_index
Map from subdomain ids to division index. Created on calls to initialize()