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 "AllNodesSendListThread.h" 11 : #include "MooseMesh.h" 12 : 13 : #include "libmesh/dof_map.h" 14 : 15 152784 : AllNodesSendListThread::AllNodesSendListThread(FEProblemBase & fe_problem, 16 : const MooseMesh & mesh, 17 : const std::vector<unsigned int> & var_nums, 18 152784 : const libMesh::System & system) 19 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem), 20 152784 : _ref_mesh(mesh), 21 152784 : _var_nums(var_nums), 22 152784 : _system(system), 23 152784 : _system_number(_system.number()), 24 152784 : _first_dof(_system.get_dof_map().first_dof()), 25 152784 : _end_dof(_system.get_dof_map().end_dof()), 26 305568 : _send_list() 27 : { 28 : // We may use the same _var_num multiple times, but it's inefficient 29 : // to examine it multiple times. 30 152784 : std::sort(this->_var_nums.begin(), this->_var_nums.end()); 31 : 32 : std::vector<unsigned int>::iterator new_end = 33 152784 : std::unique(this->_var_nums.begin(), this->_var_nums.end()); 34 : 35 152784 : std::vector<unsigned int>(this->_var_nums.begin(), new_end).swap(this->_var_nums); 36 152784 : } 37 : 38 14774 : AllNodesSendListThread::AllNodesSendListThread(AllNodesSendListThread & x, Threads::split split) 39 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split), 40 14774 : _ref_mesh(x._ref_mesh), 41 14774 : _var_nums(x._var_nums), 42 14774 : _system(x._system), 43 14774 : _system_number(_system.number()), 44 14774 : _first_dof(_system.get_dof_map().first_dof()), 45 14774 : _end_dof(_system.get_dof_map().end_dof()), 46 29548 : _send_list() 47 : { 48 14774 : } 49 : 50 : void 51 18676870 : AllNodesSendListThread::onNode(ConstNodeRange::const_iterator & nd) 52 : { 53 18676870 : const Node & node = *(*nd); 54 : 55 57403774 : for (unsigned int i = 0; i < _var_nums.size(); i++) 56 : { 57 38726904 : if (node.n_dofs(_system_number, _var_nums[i]) > 0) 58 : { 59 38726776 : const dof_id_type id = node.dof_number(_system_number, _var_nums[i], 0); 60 38726776 : if (id < _first_dof || id >= _end_dof) 61 9179757 : this->_send_list.push_back(id); 62 : } 63 : } 64 18676870 : } 65 : 66 : void 67 14774 : AllNodesSendListThread::join(const AllNodesSendListThread & y) 68 : { 69 : // Joining simply requires I add the dof indices from the other object 70 14774 : this->_send_list.insert(this->_send_list.end(), y._send_list.begin(), y._send_list.end()); 71 14774 : } 72 : 73 : void 74 152784 : AllNodesSendListThread::unique() 75 : { 76 : // Sort the send list. After this duplicated 77 : // elements will be adjacent in the vector 78 152784 : std::sort(this->_send_list.begin(), this->_send_list.end()); 79 : 80 : // Now use std::unique to remove any duplicate entries. There 81 : // actually shouldn't be any, since we're hitting each node exactly 82 : // once and we pre-uniqued _var_nums. 83 : // std::vector<dof_id_type>::iterator new_end = 84 : // std::unique (this->_send_list.begin(), 85 : // this->_send_list.end()); 86 : 87 : // If we *do* need to remove duplicate entries, then afterward we should 88 : // remove the end of the send_list, using the "swap trick" from Effective 89 : // STL. 90 : // std::vector<dof_id_type> 91 : // (this->_send_list.begin(), new_end).swap (this->_send_list); 92 152784 : } 93 : 94 : const std::vector<dof_id_type> & 95 305568 : AllNodesSendListThread::send_list() const 96 : { 97 305568 : return this->_send_list; 98 : }