Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ 4 : /* */ 5 : /* Copyright 2017 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #include "PointLocatorRegularOrthogonal.h" 10 : #include "PointLocatorRegularOrthogonalData.h" 11 : #include "MooseError.h" 12 : 13 : #include "libmesh/elem.h" 14 : #include "libmesh/mesh_base.h" 15 : 16 481 : PointLocatorRegularOrthogonal::PointLocatorRegularOrthogonal(const MeshBase & mesh, 17 481 : const PointLocatorBase * master) 18 481 : : PointLocatorBase(mesh, master), _out_of_mesh_mode(false), _data(nullptr) 19 : { 20 481 : if (master != nullptr) 21 : { 22 : const PointLocatorRegularOrthogonal * my_master = 23 : cast_ptr<const PointLocatorRegularOrthogonal *>(master); 24 : 25 386 : if (!my_master->initialized()) 26 0 : mooseError("Linking a slave point locator to an uninitialized master is not allowed."); 27 : 28 386 : _data = my_master->_data; 29 386 : _initialized = true; 30 : } 31 481 : } 32 : 33 962 : PointLocatorRegularOrthogonal::~PointLocatorRegularOrthogonal() { this->clear(); } 34 : 35 : void 36 481 : PointLocatorRegularOrthogonal::clear() 37 : { 38 : // only delete the root element table when we are the master 39 481 : if (this->_data != nullptr) 40 : { 41 481 : if (this->_master == nullptr) 42 : // we own the root element table 43 95 : delete this->_data; 44 : else 45 : // someone else owns and therefore deletes the root element table 46 386 : this->_data = nullptr; 47 : } 48 : 49 481 : _initialized = false; 50 481 : } 51 : 52 : void 53 0 : PointLocatorRegularOrthogonal::init() 54 : { 55 0 : mooseError( 56 : "PointLocatorRegularOrthogonal needs to be explicitly initialized with mesh meta data."); 57 : } 58 : 59 : void 60 95 : PointLocatorRegularOrthogonal::init(const std::vector<unsigned int> & cell_count, 61 : const Point & min_corner, 62 : const Point & max_corner) 63 : { 64 : // initialize root element table on the master point locator only 65 95 : if (this->_master == nullptr) 66 95 : _data = new PointLocatorRegularOrthogonalData(cell_count, min_corner, max_corner, _mesh); 67 : 68 95 : _initialized = true; 69 95 : } 70 : 71 : const Elem * 72 73438975 : PointLocatorRegularOrthogonal::operator()( 73 : const Point & p, const std::set<subdomain_id_type> * /* allowed_subdomains */) const 74 : { 75 : Point el_pos; 76 73438975 : const Elem * el = _data->rootElement(p, el_pos); 77 : 78 : while (true) 79 : { 80 : // element has no active children (or point is out of mesh) 81 74893804 : if (el == nullptr || el->active()) 82 73438975 : return el; 83 : 84 : // bisect the children 85 : unsigned int child = 0; 86 5684535 : for (unsigned int i = 0; i < _data->_dim; ++i) 87 4229706 : if (el_pos(i) >= 0.5) 88 : { 89 : // fortunately the libMesh child ordering is this simple (bit 0/1 for left right of center 90 : // point, etc.) 91 2165304 : child += 1 << i; 92 2165304 : el_pos(i) = (el_pos(i) - 0.5) * 2.0; 93 : } 94 : else 95 2064402 : el_pos(i) *= 2.0; 96 : 97 : el = el->child_ptr(child); 98 1454829 : } 99 : } 100 : 101 : void 102 0 : PointLocatorRegularOrthogonal::operator()( 103 : const Point & p, 104 : std::set<const Elem *> & candidate_elements, 105 : const std::set<subdomain_id_type> * /* allowed_subdomains */) const 106 : { 107 : // return just one match, the exact one TODO: return all neighbors if we are fuzzily on a 108 : // face/edge/node 109 0 : candidate_elements.insert((*this)(p)); 110 0 : return; 111 : }