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 "NestedDivision.h" 11 : #include "FEProblemBase.h" 12 : #include "libmesh/elem.h" 13 : 14 : registerMooseObject("MooseApp", NestedDivision); 15 : 16 : InputParameters 17 14290 : NestedDivision::validParams() 18 : { 19 14290 : InputParameters params = MeshDivision::validParams(); 20 14290 : params.addClassDescription("Divide the mesh using nested divisions objects"); 21 14290 : params.addRequiredParam<std::vector<MeshDivisionName>>("divisions", "Nested divisions"); 22 14290 : return params; 23 0 : } 24 : 25 13 : NestedDivision::NestedDivision(const InputParameters & parameters) : MeshDivision(parameters) 26 : { 27 39 : for (const auto & div_name : getParam<std::vector<MeshDivisionName>>("divisions")) 28 26 : _divisions.push_back(&_fe_problem->getMeshDivision(div_name)); 29 13 : if (_divisions.size() == 0) 30 0 : paramError("divisions", "You cannot pass an empty vector of divisions"); 31 13 : NestedDivision::initialize(); 32 13 : } 33 : 34 : void 35 13 : NestedDivision::initialize() 36 : { 37 13 : auto tot_divs = 1; 38 13 : _num_divs.resize(_divisions.size()); 39 : 40 39 : for (const auto i : index_range(_divisions)) 41 : { 42 26 : _num_divs[i] = _divisions[i]->getNumDivisions(); 43 26 : tot_divs *= _num_divs[i]; 44 26 : if (_num_divs[i] == 0) 45 0 : mooseError("Nested division '", _divisions[i]->name(), "' has zero bins"); 46 : } 47 13 : setNumDivisions(tot_divs); 48 : 49 : // If any division does not cover the entire mesh, nested will have the same holes 50 : // in its coverage of the mesh 51 13 : _mesh_fully_indexed = true; 52 39 : for (const auto division : _divisions) 53 26 : if (!division->coversEntireMesh()) 54 : { 55 0 : _mesh_fully_indexed = false; 56 0 : break; 57 : } 58 13 : } 59 : 60 : unsigned int 61 28672 : NestedDivision::divisionIndex(const Elem & elem) const 62 : { 63 28672 : unsigned int index = 0; 64 28672 : unsigned int running_product = 1; 65 28672 : const auto N_divs = _divisions.size(); 66 86016 : for (const auto i : index_range(_divisions)) 67 : { 68 57344 : index += _divisions[N_divs - 1 - i]->divisionIndex(elem) * running_product; 69 57344 : running_product *= _num_divs[N_divs - 1 - i]; 70 : } 71 28672 : return index; 72 : } 73 : 74 : unsigned int 75 0 : NestedDivision::divisionIndex(const Point & pt) const 76 : { 77 0 : unsigned int index = 0; 78 0 : unsigned int running_product = 1; 79 0 : const auto N_divs = _divisions.size(); 80 0 : for (const auto i : index_range(_divisions)) 81 : { 82 0 : index += _divisions[N_divs - 1 - i]->divisionIndex(pt) * running_product; 83 0 : running_product *= _num_divs[N_divs - 1 - i]; 84 : } 85 0 : return index; 86 : }