54 scatter_to_seq_(nullptr),
97 unsigned int n_node_dofs = 0;
100 node_dof_starts.push_back(n_node_dofs);
101 n_node_dofs +=
ds_->n_node_dofs(nid);
103 node_dof_starts.push_back(n_node_dofs);
105 unsigned int n_edge_dofs = 0;
108 edge_dof_starts.push_back(n_edge_dofs);
109 n_edge_dofs +=
ds_->n_edge_dofs(
edge);
111 edge_dof_starts.push_back(n_edge_dofs);
122 for (
unsigned int n=0; n<cell.dim()+1; n++)
134 for (
unsigned int n=0; n<cell.dim()+1; n++)
151 for (
unsigned int n=0; n<cell.dim()+1; n++)
153 unsigned int eid = cell.elm().side(n)->edge_idx();
175 unsigned int n_dofs_sum = 0;
176 for (
auto nd : n_dofs) n_dofs_sum += nd;
177 dofs.resize(n_dofs_sum);
185 unsigned int n_elems;
222 unsigned int dof_offset=0;
223 for (
unsigned int gid=0; gid<
ghost_proc_el[proc].size(); gid++)
229 for (
unsigned int idof = 0; idof<dh_cell.
n_dofs(); ++idof)
235 unsigned int node_dof_idx = node_dof_starts[nid]+loc_node_dof_count[dof_nface_idx];
244 loc_node_dof_count[dof_nface_idx]++;
250 unsigned int edge_dof_idx = edge_dof_starts[eid]+loc_edge_dof_count[dof_nface_idx];
259 loc_edge_dof_count[dof_nface_idx]++;
267 dof_offset += dh_cell.
n_dofs();
273 if (!update_cells[cell.local_idx()])
continue;
278 for (
unsigned int idof = 0; idof<cell.n_dofs(); ++idof)
280 unsigned int dof_nface_idx = cell.cell_dof(idof).n_face_idx;
281 if (cell.cell_dof(idof).dim == 0)
286 dof_indices[
cell_starts[cell.local_idx()]+idof] = node_dofs[node_dof_starts[nid]+loc_node_dof_count[dof_nface_idx]];
288 loc_node_dof_count[dof_nface_idx]++;
289 }
else if (cell.cell_dof(idof).dim == cell.dim()-1)
293 unsigned int eid = cell.elm().side(dof_nface_idx)->edge_idx();
294 dof_indices[
cell_starts[cell.local_idx()]+idof] = edge_dofs[edge_dof_starts[eid]+loc_edge_dof_count[dof_nface_idx]];
296 loc_edge_dof_count[dof_nface_idx]++;
306 OLD_ASSERT(
ds_ ==
nullptr,
"Attempt to distribute DOFs multiple times!");
314 unsigned int next_free_dof = 0;
331 for (
unsigned int idof = 0; idof<cell.n_dofs(); ++idof)
333 unsigned int dof_dim = cell.cell_dof(idof).dim;
334 unsigned int dof_nface_idx = cell.cell_dof(idof).n_face_idx;
339 unsigned int node_dof_idx = node_dof_starts[nid]+loc_node_dof_count[dof_nface_idx];
341 switch (node_status[nid])
344 for (
int i=0; i<node_dof_starts[nid+1] - node_dof_starts[nid]; i++)
347 node_dofs[node_dof_starts[nid]+i] = next_free_dof++;
353 update_cells[cell.local_idx()] =
true;
357 loc_node_dof_count[dof_nface_idx]++;
359 else if (dof_dim == cell.dim()-1)
361 unsigned int eid = cell.elm().side(dof_nface_idx)->edge_idx();
362 unsigned int edge_dof_idx = edge_dof_starts[eid]+loc_edge_dof_count[dof_nface_idx];
363 switch (edge_status[eid])
366 for (
int i=0; i<edge_dof_starts[eid+1] - edge_dof_starts[eid]; i++)
369 edge_dofs[edge_dof_starts[eid]+i] = next_free_dof++;
375 update_cells[cell.local_idx()] =
true;
379 loc_edge_dof_count[dof_nface_idx]++;
381 else if (dof_dim == cell.dim())
387 ASSERT(
false).error(
"Unsupported dof n_face.");
396 dof_ds_ = std::make_shared<Distribution>(
lsize_, PETSC_COMM_WORLD);
409 for (
unsigned int from_higher = 0; from_higher < 2; from_higher++)
413 if ((proc >
el_ds_->
myp()) == from_higher)
433 update_cells.clear();
435 node_dof_starts.clear();
437 edge_dof_starts.clear();
443 if (
dh_seq_ !=
nullptr)
return;
447 dh_seq_ = std::make_shared<DOFHandlerMultiDim>(*this);
451 dh_seq_ = std::make_shared<DOFHandlerMultiDim>(*mesh_);
470 for (
unsigned int i=0; i<mesh_->n_elements(); i++)
dh_seq_->global_to_local_el_idx_[i] = mesh_->get_row_4_el()[i];
481 cell_starts_loc[mesh_->get_row_4_el()[cell.elm_idx()]+1] = cell.n_dofs();
483 for (
unsigned int i=0; i<mesh_->n_elements(); ++i)
484 cell_starts_loc[i+1] += cell_starts_loc[i];
487 dof_indices_loc.resize(cell_starts_loc[mesh_->n_elements()]);
490 for (
unsigned int idof=0; idof<cell.n_dofs(); idof++)
495 dh_seq_->cell_starts.resize(mesh_->n_elements()+1);
500 cell_starts_loc.size(),
506 dof_indices_loc.size(),
509 (
const int *)
distr.get_lsizes_array(),
510 (
const int *)
distr.get_starts_array(),
516 VecCreateMPI(PETSC_COMM_WORLD,
lsize_, PETSC_DETERMINE, &v_from);
523 VecCreateSeq(PETSC_COMM_SELF, n_global_dofs_, &v_seq);
524 dh_seq_->scatter_to_seq_ = std::make_shared<VecScatter>();
525 VecScatterCreateToAll(v_seq,
dh_seq_->scatter_to_seq_.get(), NULL);
546 unsigned int ndofs = 0;
548 indices.resize(ndofs);
549 for (
unsigned int k=0; k<ndofs; k++)
569 bool is_edge_local =
false;
570 for (
uint sid=0; sid<
edge.n_sides(); sid++)
573 is_edge_local =
true;
590 for (
unsigned int iel = 0; iel <
el_ds_->
lsize(); iel++ )
598 for (
unsigned int nid=0; nid<cell.elm()->n_nodes(); nid++)
607 bool has_local_node =
false;
609 for (
unsigned int nid=0; nid<cell->n_nodes(); nid++)
612 has_local_node =
true;
658 auto bgn_it = make_iter<DHCellAccessor>(
DHCellAccessor(
this, 0) );
665 auto bgn_it = make_iter<DHCellAccessor>(
DHCellAccessor(
this, 0) );
689 s <<
"DOFHandlerMultiDim structure:" << endl;
690 s <<
"- is parallel: " << (
is_parallel_?
"true":
"false") << endl;
691 s <<
"- proc id: " <<
el_ds_->
myp() << endl;
693 s <<
"- number of locally owned cells: " <<
el_ds_->
lsize() << endl;
694 s <<
"- number of ghost cells: " <<
ghost_4_loc.size() << endl;
695 s <<
"- dofs on locally owned cells:" << endl;
699 auto ndofs = cell.get_dof_indices(dofs);
700 s <<
"-- cell " << cell.elm().idx() <<
": ";
701 for (
unsigned int idof=0; idof<ndofs; idof++) s << dofs[idof] <<
" "; s << endl;
703 s <<
"- dofs on ghost cells:" << endl;
706 auto ndofs = cell.get_dof_indices(dofs);
707 s <<
"-- cell " << cell.elm().idx() <<
": ";
708 for (
unsigned int idof=0; idof<ndofs; idof++) s << dofs[idof] <<
" "; s << endl;
710 s <<
"- locally owned dofs (" <<
lsize_ <<
"): ";
714 s <<
"- global-to-local-cell map:" << endl;
718 printf(
"%s", s.str().c_str());
732 fe_idx_(component_idx)
735 ASSERT_DBG( dynamic_cast<EqualOrderDiscreteSpace *>(dh->ds().get()) !=
nullptr )
736 .error(
"sub_handler can be used only with dof handler using EqualOrderDiscreteSpace!");
742 ASSERT_DBG( fe_sys0 !=
nullptr ).error(
"sub_handler assumes that dof handler uses FESystem<0>!");
743 ASSERT_DBG( fe_sys1 !=
nullptr ).error(
"sub_handler assumes that dof handler uses FESystem<1>!");
744 ASSERT_DBG( fe_sys2 !=
nullptr ).error(
"sub_handler assumes that dof handler uses FESystem<2>!");
745 ASSERT_DBG( fe_sys3 !=
nullptr ).error(
"sub_handler assumes that dof handler uses FESystem<3>!");
747 fe_sys1->
fe()[component_idx],
748 fe_sys2->
fe()[component_idx],
749 fe_sys3->
fe()[component_idx]);
750 ds_ = std::make_shared<EqualOrderDiscreteSpace>(
mesh_, sub_mixed);
757 dynamic_cast<FESystemFunctionSpace*>( fe_sys1->
function_space_.get() ),
758 dynamic_cast<FESystemFunctionSpace*>( fe_sys2->
function_space_.get() ),
759 dynamic_cast<FESystemFunctionSpace*>( fe_sys3->
function_space_.get() ) };
760 for (
unsigned int d=0; d<=3; d++)
761 ASSERT_DBG( fs[d] !=
nullptr ).error(
"Function space must be of type FESystemFunctionSpace!" );
763 for (
unsigned int i=0; i<fe_sys0->
n_dofs(); i++)
764 if (fs[0]->
dof_indices()[i].fe_index == component_idx) sub_fe_dofs[0].push_back(i);
765 for (
unsigned int i=0; i<fe_sys1->
n_dofs(); i++)
766 if (fs[1]->
dof_indices()[i].fe_index == component_idx) sub_fe_dofs[1].push_back(i);
767 for (
unsigned int i=0; i<fe_sys2->
n_dofs(); i++)
768 if (fs[2]->
dof_indices()[i].fe_index == component_idx) sub_fe_dofs[2].push_back(i);
769 for (
unsigned int i=0; i<fe_sys3->
n_dofs(); i++)
770 if (fs[3]->
dof_indices()[i].fe_index == component_idx) sub_fe_dofs[3].push_back(i);
778 for (
auto cell : dh->local_range())
780 LocDofVec cell_dof_indices = cell.get_loc_dof_indices();
781 for (
auto sub_dof : sub_fe_dofs[cell.dim()])
783 if (cell_dof_indices[sub_dof] < static_cast<int>(dh->lsize_) &&
784 sub_local_indices[cell_dof_indices[sub_dof]] ==
INVALID_DOF)
795 for (
auto cell : dh->local_range())
797 LocDofVec cell_dof_indices = cell.get_loc_dof_indices();
798 unsigned int idof = 0;
799 for (
auto sub_dof : sub_fe_dofs[cell.dim()])
801 if (sub_local_indices[cell_dof_indices[sub_dof]] ==
INVALID_DOF)
812 dof_ds_ = std::make_shared<Distribution>(
lsize_, PETSC_COMM_WORLD);
818 for (
unsigned int i=0; i<
lsize_; i++)
823 for (
unsigned int from_higher = 0; from_higher < 2; from_higher++)
827 if ((proc >
el_ds_->
myp()) == from_higher)
846 unsigned int n_ghosts = dof_indices.size();
853 dofs.resize(n_ghosts);
857 unsigned int idof = 0;
867 unsigned int n_ghosts;
876 for (
auto global_dof : dof_indices)
877 dofs.push_back(global_to_local_dof_idx.at(global_dof) +
dof_ds_->begin());
884 ASSERT_DBG( vec.
size() ==
parent_->local_to_global_dof_idx_.size() ).error(
"Incompatible parent vector in update_subvector()!");
894 ASSERT_DBG( vec.
size() ==
parent_->local_to_global_dof_idx_.size() ).error(
"Incompatible parent vector in update_subvector()!");
#define MPI_Recv(buf, count, datatype, source, tag, comm, status)
void receive_ghost_dofs(unsigned int proc, std::vector< LongIdx > &dofs)
Obtain dof numbers on ghost elements from other processor.
std::shared_ptr< DOFHandlerMultiDim > sequential()
Returns sequential version of the current dof handler.
unsigned int size() const
Return size of output data.
const Dof & cell_dof(unsigned int idof) const
Return dof on a given cell.
virtual ~DOFHandlerBase()
Destructor.
void create_sequential()
Communicate local dof indices to all processors and create new sequential dof handler.
void init_cell_starts()
Initialize vector of starting indices for elements.
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
unsigned int n_dofs() const
Returns the number of degrees of freedom needed by the finite element.
unsigned int n_nodes() const
unsigned int elm_idx() const
Return serial idx to element of loc_ele_idx_.
const DHCellAccessor cell_accessor_from_element(unsigned int elm_idx) const
Return DHCellAccessor appropriate to ElementAccessor of given idx.
arma::Col< IntIdx > LocDofVec
LongIdx * get_row_4_el() const
void init_dof_starts(std::vector< LongIdx > &node_dof_starts, std::vector< LongIdx > &edge_dof_starts)
Initialize auxiliary vector of starting indices of nodal/edge dofs.
void update_parent_vector(VectorMPI &vec, const VectorMPI &subvec)
Update values in parent vector from values of subvector.
const std::vector< MeshObject > & objects(unsigned int dim) const
unsigned int edge_idx() const
Returns global index of the edge connected to the side.
const std::vector< std::shared_ptr< FiniteElement< dim > > > & fe() const
Distribution * el_ds_
Distribution of elements.
static const int INVALID_NFACE
std::shared_ptr< DOFHandlerMultiDim > parent_
Parent dof handler.
unsigned int dim() const
Return dimension of element appropriate to cell.
unsigned int dim
Association to n-face of given dimension (point, line, triangle, tetrahedron.
unsigned int local_idx() const
Return local index to element (index of DOF handler).
void distribute_dofs(std::shared_ptr< DiscreteSpace > ds)
Distributes degrees of freedom on the mesh needed for the given discrete space.
Cell accessor allow iterate over DOF handler cells.
std::vector< IntIdx > dof_indices
Dof numbers on local and ghost elements.
std::shared_ptr< VecScatter > sequential_scatter()
Returns scatter context from parallel to sequential vectors.
Class FESystem for compound finite elements.
std::vector< LongIdx > local_to_global_dof_idx_
Maps local and ghost dof indices to global ones.
SideIter side(const unsigned int loc_index)
#define MPI_Send(buf, count, datatype, dest, tag, comm)
SubDOFHandlerMultiDim(std::shared_ptr< DOFHandlerMultiDim > dh, unsigned int component_idx)
Creates a new dof handler for a component of FESystem.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
void init_status(std::vector< short int > &node_status, std::vector< short int > &edge_status)
Initialize node_status and edge_status.
std::shared_ptr< Distribution > dof_ds_
Distribution of dofs associated to local process.
#define MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm)
Mesh * mesh() const
Returns the mesh.
unsigned int n_dofs() const
Return number of dofs on given cell.
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
std::shared_ptr< DOFHandlerMultiDim > dh_seq_
Sequential dof handler associated to the current (parallel) one.
unsigned int lsize_
Number of dofs associated to local process.
unsigned int n_face_idx
Index of n-face to which the dof is associated.
map< unsigned int, vector< LongIdx > > ghost_proc_el
Arrays of ghost cells for each neighbouring processor.
static const int ASSIGNED_NFACE
void send_ghost_dofs(unsigned int proc)
Send dof numbers to other processor.
std::vector< LongIdx > cell_starts
Starting indices for local (owned+ghost) element dofs.
unsigned int n_vb_neighbours() const
ElementAccessor< 3 > element()
const ElementAccessor< 3 > elm() const
Return ElementAccessor to element of loc_ele_idx_.
bool is_local(unsigned int idx) const
identify local index
Compound finite element on dim dimensional simplex.
Mesh * mesh_
Pointer to the mesh to which the dof handler is associated.
unsigned int n_sides() const
Provides the numbering of the finite element degrees of freedom on the computational mesh...
static const int VALID_NFACE
Range< DHCellAccessor > ghost_range() const
Returns range over ghosts DOF handler cells.
vector< LongIdx > nb_4_loc
Local neighbour index -> global neighbour index.
unsigned int max_elem_dofs_
Max. number of dofs per element.
vector< LongIdx > ghost_4_loc
Indices of ghost cells (neighbouring with local elements).
std::unordered_map< LongIdx, LongIdx > global_to_local_el_idx_
Maps global element index into local/ghost index (obsolete).
virtual Range< ElementAccessor< 3 > > elements_range() const
Returns range of bulk elements.
unsigned int n_nodes() const
unsigned int np() const
get num of processors
Distribution * get_el_ds() const
void make_elem_partitioning()
Prepare parallel distribution of elements, edges and neighbours.
void print() const
Output structure of dof handler.
std::shared_ptr< Distribution > distr() const
std::vector< LongIdx > parent_dof_idx_
Local indices in the parent handler.
unsigned int myp() const
get my processor
void send_sub_ghost_dofs(unsigned int proc, const map< LongIdx, LongIdx > &global_to_local_dof_idx)
Send global indices of dofs that are ghost on other processors.
Support classes for parallel programing.
#define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm)
vector< Neighbour > vb_neighbours_
#define MPI_STATUS_IGNORE
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
vector< LongIdx > edg_4_loc
Local edge index -> global edge index.
Range< DHCellAccessor > own_range() const
Returns range of DOF handler cells (only range of own without ghost cells)
unsigned int loffset_
Index of the first dof on the local process.
static const int INVALID_DOF
std::shared_ptr< FunctionSpace > function_space_
Function space defining the FE.
set< unsigned int > ghost_proc
Processors of ghost elements.
~DOFHandlerMultiDim() override
Destructor.
std::shared_ptr< DiscreteSpace > ds_
Pointer to the discrete space for which the handler distributes dofs.
void receive_sub_ghost_dofs(unsigned int proc, vector< LongIdx > &dofs)
Get global dof indices of ghost dofs for sub-handler.
void update_subvector(const VectorMPI &vec, VectorMPI &subvec)
Update values in subvector from parent vector.
unsigned int get_dof_indices(const DHCellAccessor &cell, std::vector< LongIdx > &indices) const override
Returns the global indices of dofs associated to the cell.
Abstract class for description of finite elements.
virtual VectorMPI create_vector()
Allocates PETSc vector according to the dof distribution.
unsigned int n_global_dofs_
Number of global dofs assigned by the handler.
unsigned int n_edges() const
bool el_is_local(int index) const
DOFHandlerMultiDim(Mesh &_mesh, bool make_elem_part=true)
Constructor.
void update_local_dofs(unsigned int proc, const std::vector< bool > &update_cells, const std::vector< LongIdx > &dofs, const std::vector< LongIdx > &node_dof_starts, std::vector< LongIdx > &node_dofs, const std::vector< LongIdx > &edge_dof_starts, std::vector< LongIdx > &edge_dofs)
Update dofs on local elements from ghost element dofs.
Range< DHCellAccessor > local_range() const
Returns range over own and ghost cells of DOF handler.
const std::vector< unsigned int > & obj_4_el() const
bool is_parallel_
Indicator for parallel/sequential dof handler.
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
std::shared_ptr< VecScatter > scatter_to_seq_
Scatter context for parallel to sequential vectors.
LongIdx * get_el_4_loc() const
Range< Edge > edge_range() const
Returns range of edges.
Implementation of range helper class.
friend class DHCellAccessor
std::size_t hash() const override
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
std::shared_ptr< DiscreteSpace > ds() const
Return pointer to discrete space for which the handler distributes dofs.
unsigned int lsize(int proc) const
get local size