Line data Source code
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 : 16 : registerMooseObject("MooseApp", SubdomainsDivision); 17 : 18 : InputParameters 19 14315 : SubdomainsDivision::validParams() 20 : { 21 14315 : InputParameters params = MeshDivision::validParams(); 22 14315 : params += BlockRestrictable::validParams(); 23 14315 : 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 14315 : return params; 27 0 : } 28 : 29 26 : SubdomainsDivision::SubdomainsDivision(const InputParameters & parameters) 30 26 : : MeshDivision(parameters), BlockRestrictable(this) 31 : { 32 26 : SubdomainsDivision::initialize(); 33 26 : _mesh_fully_indexed = true; 34 26 : } 35 : 36 : void 37 26 : SubdomainsDivision::initialize() 38 : { 39 26 : if (!blockRestricted()) 40 : { 41 : // The subdomains may not be contiguously numbered 42 13 : const auto & subdomain_ids = blockIDs(); 43 13 : setNumDivisions(subdomain_ids.size()); 44 13 : unsigned int i = 0; 45 91 : for (const auto sub_id : subdomain_ids) 46 78 : _subdomain_ids_to_division_index[sub_id] = i++; 47 : } 48 : else 49 : { 50 : // Follow the user input order, use a vector instead of a set 51 13 : const auto subdomain_ids = _mesh.getSubdomainIDs(blocks()); 52 13 : setNumDivisions(subdomain_ids.size()); 53 13 : unsigned int i = 0; 54 52 : for (const auto sub_id : subdomain_ids) 55 39 : _subdomain_ids_to_division_index[sub_id] = i++; 56 13 : } 57 26 : } 58 : 59 : unsigned int 60 1280 : SubdomainsDivision::divisionIndex(const Elem & elem) const 61 : { 62 1280 : const auto id_it = _subdomain_ids_to_division_index.find(elem.subdomain_id()); 63 1280 : if (id_it != _subdomain_ids_to_division_index.end()) 64 960 : return id_it->second; 65 : else 66 : { 67 : mooseAssert(blockRestricted(), "We should be block restricted"); 68 320 : return MooseMeshDivision::INVALID_DIVISION_INDEX; 69 : } 70 : } 71 : 72 : unsigned int 73 0 : SubdomainsDivision::divisionIndex(const Point & pt) const 74 : { 75 0 : 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 0 : std::set<const Elem *> candidates; 78 0 : (*pl)(pt, candidates); 79 : 80 : // By convention we will use the element with the lowest subdomain id 81 0 : const Elem * elem = nullptr; 82 0 : unsigned int min_sub_id = Moose::INVALID_BLOCK_ID; 83 0 : for (const auto elem_ptr : candidates) 84 0 : if (elem_ptr->subdomain_id() < min_sub_id) 85 : { 86 0 : elem = elem_ptr; 87 0 : min_sub_id = elem_ptr->subdomain_id(); 88 : } 89 : 90 0 : return libmesh_map_find(_subdomain_ids_to_division_index, elem->subdomain_id()); 91 0 : }