libMesh
Loading...
Searching...
No Matches
dof_map_base.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
21namespace libMesh
22{
24 : ParallelObject(comm),
25 _n_dfs(0)
26#ifdef LIBMESH_ENABLE_AMR
27 ,
28 _n_old_dfs(0)
29#endif
30{
31}
32
33std::size_t DofMapBase::compute_dof_info(const dof_id_type n_local_dofs)
34{
35 // Get DOF counts on all processors
36 const auto n_proc = this->n_processors();
37
38 std::vector<dof_id_type> dofs_on_proc(n_proc, 0);
39 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
45#endif
46
47 _first_df.resize(n_proc);
48 _end_df.resize(n_proc);
49
50 // Get DOF offsets
51 _first_df[0] = 0;
52 for (processor_id_type i = 1; i < n_proc; ++i)
53 _first_df[i] = _end_df[i - 1] = _first_df[i - 1] + dofs_on_proc[i - 1];
54 _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
59#endif
60 _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 return std::accumulate(dofs_on_proc.begin(), dofs_on_proc.end(), static_cast<std::size_t>(0));
69}
70
72{
73 _first_df.clear();
74 _end_df.clear();
75 _n_dfs = 0;
76}
77}
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
std::size_t compute_dof_info(dof_id_type n_local_dofs)
compute the key degree of freedom information given the local number of degrees of freedom on this pr...
std::vector< dof_id_type > _end_df
Last DOF index (plus 1) on processor p.
std::vector< dof_id_type > _first_df
First DOF index on processor p.
DofMapBase(const Parallel::Communicator &comm)
dof_id_type _n_dfs
Total number of degrees of freedom.
dof_id_type _n_old_dfs
Total number of degrees of freedom on old dof objects.
std::vector< dof_id_type > _first_old_df
First old DOF index on processor p.
virtual void clear()
std::vector< dof_id_type > _end_old_df
Last old DOF index (plus 1) on processor p.
An object whose state is distributed along a set of processors.
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t dof_id_type
Definition id_types.h:67
uint8_t processor_id_type
Definition id_types.h:104