Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : #include "libmesh/dof_map_base.h" 19 : #include "libmesh/parallel_implementation.h" 20 : 21 : namespace libMesh 22 : { 23 237705 : DofMapBase::DofMapBase(const Parallel::Communicator & comm) 24 : : ParallelObject(comm), 25 224137 : _n_dfs(0) 26 : #ifdef LIBMESH_ENABLE_AMR 27 : , 28 244489 : _n_old_dfs(0) 29 : #endif 30 : { 31 237705 : } 32 : 33 262899 : std::size_t DofMapBase::compute_dof_info(const dof_id_type n_local_dofs) 34 : { 35 : // Get DOF counts on all processors 36 15228 : const auto n_proc = this->n_processors(); 37 : 38 270513 : std::vector<dof_id_type> dofs_on_proc(n_proc, 0); 39 262899 : this->comm().allgather(n_local_dofs, dofs_on_proc); 40 : 41 : #ifdef LIBMESH_ENABLE_AMR 42 : // Resize and fill the _first_df and _end_df arrays 43 262899 : _first_old_df = _first_df; 44 262899 : _end_old_df = _end_df; 45 : #endif 46 : 47 262899 : _first_df.resize(n_proc); 48 262899 : _end_df.resize(n_proc); 49 : 50 : // Get DOF offsets 51 262899 : _first_df[0] = 0; 52 2562917 : for (processor_id_type i = 1; i < n_proc; ++i) 53 2330474 : _first_df[i] = _end_df[i - 1] = _first_df[i - 1] + dofs_on_proc[i - 1]; 54 278127 : _end_df[n_proc - 1] = _first_df[n_proc - 1] + dofs_on_proc[n_proc - 1]; 55 : 56 : // Set the total number of degrees of freedom 57 : #ifdef LIBMESH_ENABLE_AMR 58 262899 : _n_old_dfs = _n_dfs; 59 : #endif 60 262899 : _n_dfs = _end_df[n_proc - 1]; 61 : 62 : // Return total number of DOFs across all procs. We compute and 63 : // return this as a std::size_t so that we can detect situations in 64 : // which the total number of DOFs across all procs would exceed the 65 : // capability of the underlying NumericVector representation to 66 : // index into it correctly (std::size_t is the largest unsigned 67 : // type, so no NumericVector representation can exceed it). 68 270513 : return std::accumulate(dofs_on_proc.begin(), dofs_on_proc.end(), static_cast<std::size_t>(0)); 69 : } 70 : 71 238694 : void DofMapBase::clear() 72 : { 73 6814 : _first_df.clear(); 74 6814 : _end_df.clear(); 75 238694 : _n_dfs = 0; 76 238694 : } 77 : }