libMesh
Public Member Functions | Private Member Functions | Private Attributes | List of all members
libMesh::PetscDMWrapper Class Reference

This class defines a wrapper around the PETSc DM infrastructure. More...

#include <petsc_dm_wrapper.h>

Public Member Functions

 PetscDMWrapper ()=default
 
 ~PetscDMWrapper ()
 
void clear ()
 Destroys and clears all build DM-related data. More...
 
void init_and_attach_petscdm (System &system, SNES &snes)
 

Private Member Functions

void init_dm_data (unsigned int n_levels, const Parallel::Communicator &comm)
 Init all the n_mesh_level dependent data structures. More...
 
DM & get_dm (unsigned int level)
 Get reference to DM for the given mesh level. More...
 
PetscSection & get_section (unsigned int level)
 Get reference to PetscSection for the given mesh level. More...
 
PetscSF & get_star_forest (unsigned int level)
 Get reference to PetscSF for the given mesh level. More...
 
void build_section (const System &system, PetscSection &section)
 Takes System, empty PetscSection and populates the PetscSection. More...
 
void build_sf (const System &system, PetscSF &star_forest)
 Takes System, empty PetscSF and populates the PetscSF. More...
 
void set_point_range_in_section (const System &system, PetscSection &section, std::unordered_map< dof_id_type, dof_id_type > &node_map, std::unordered_map< dof_id_type, dof_id_type > &elem_map, std::map< dof_id_type, unsigned int > &scalar_map)
 Helper function for build_section. More...
 
void add_dofs_to_section (const System &system, PetscSection &section, const std::unordered_map< dof_id_type, dof_id_type > &node_map, const std::unordered_map< dof_id_type, dof_id_type > &elem_map, const std::map< dof_id_type, unsigned int > &scalar_map)
 Helper function for build_section. More...
 
dof_id_type check_section_n_dofs (PetscSection &section)
 Helper function to sanity check PetscSection construction. More...
 
void add_dofs_helper (const System &system, const DofObject &dof_object, dof_id_type local_id, PetscSection &section)
 Helper function to reduce code duplication when setting dofs in section. More...
 

Private Attributes

std::vector< std::unique_ptr< DM > > _dms
 Vector of DMs for all grid levels. More...
 
std::vector< std::unique_ptr< PetscSection > > _sections
 Vector of PETScSections for all grid levels. More...
 
std::vector< std::unique_ptr< PetscSF > > _star_forests
 Vector of star forests for all grid levels. More...
 
std::vector< std::unique_ptr< PetscMatrix< Real > > > _pmtx_vec
 Vector of projection matrixes for all grid levels. More...
 
std::vector< std::unique_ptr< PetscMatrix< Real > > > _subpmtx_vec
 Vector of sub projection matrixes for all grid levels for fieldsplit. More...
 
std::vector< std::unique_ptr< PetscDMContext > > _ctx_vec
 Vector of internal PetscDM context structs for all grid levels. More...
 
std::vector< std::unique_ptr< PetscVector< Real > > > _vec_vec
 Vector of solution vectors for all grid levels. More...
 
std::vector< unsigned int > _mesh_dof_sizes
 Stores n_dofs for each grid level, to be used for projection matrix sizing. More...
 
std::vector< unsigned int > _mesh_dof_loc_sizes
 Stores n_local_dofs for each grid level, to be used for projection vector sizing. More...
 

Detailed Description

This class defines a wrapper around the PETSc DM infrastructure.

By coordinating DM data structures with libMesh, we can use libMesh mesh hierarchies for geometric multigrid. Additionally, by setting the DM data, we can additionally (with or without multigrid) define recursive fieldsplits of our variables.

Author
Paul T. Bauman, Boris Boutkov
Date
2018

Definition at line 86 of file petsc_dm_wrapper.h.

Constructor & Destructor Documentation

◆ PetscDMWrapper()

libMesh::PetscDMWrapper::PetscDMWrapper ( )
default

◆ ~PetscDMWrapper()

libMesh::PetscDMWrapper::~PetscDMWrapper ( )

Member Function Documentation

◆ add_dofs_helper()

void libMesh::PetscDMWrapper::add_dofs_helper ( const System system,
const DofObject dof_object,
dof_id_type  local_id,
PetscSection &  section 
)
private

Helper function to reduce code duplication when setting dofs in section.

◆ add_dofs_to_section()

void libMesh::PetscDMWrapper::add_dofs_to_section ( const System system,
PetscSection &  section,
const std::unordered_map< dof_id_type, dof_id_type > &  node_map,
const std::unordered_map< dof_id_type, dof_id_type > &  elem_map,
const std::map< dof_id_type, unsigned int > &  scalar_map 
)
private

Helper function for build_section.

This function will set the DoF info for each "point" in the PetscSection.

◆ build_section()

void libMesh::PetscDMWrapper::build_section ( const System system,
PetscSection &  section 
)
private

Takes System, empty PetscSection and populates the PetscSection.

Take the System in its current state and an empty PetscSection and then populate the PetscSection. The PetscSection is comprised of global "point" numbers, where a "point" in PetscDM parlance is a geometric entity: node, edge, face, or element. Then, we also add the DoF numbering for each variable for each of the "points". The PetscSection, together the with PetscSF will allow for recursive fieldsplits from the command line using PETSc.

◆ build_sf()

void libMesh::PetscDMWrapper::build_sf ( const System system,
PetscSF &  star_forest 
)
private

Takes System, empty PetscSF and populates the PetscSF.

The PetscSF (star forest) is a cousin of PetscSection. PetscSection has the DoF info, and PetscSF gives the parallel distribution of the DoF info. So PetscSF should only be necessary when we have more than one MPI rank. Essentially, we are copying the DofMap.send_list(): we are specifying the local dofs, what rank communicates that dof info (for off-processor dofs that are communicated) and the dofs local index on that rank.

https://jedbrown.org/files/StarForest.pdf

◆ check_section_n_dofs()

dof_id_type libMesh::PetscDMWrapper::check_section_n_dofs ( PetscSection &  section)
private

Helper function to sanity check PetscSection construction.

The PetscSection contains local dof information. This helper function just facilitates sanity checking that in fact it only has n_local_dofs.

◆ clear()

void libMesh::PetscDMWrapper::clear ( )

Destroys and clears all build DM-related data.

◆ get_dm()

DM& libMesh::PetscDMWrapper::get_dm ( unsigned int  level)
private

Get reference to DM for the given mesh level.

init_dm_data() should be called before this function.

Definition at line 135 of file petsc_dm_wrapper.h.

References _dms.

136  { libmesh_assert_less(level, _dms.size());
137  return *(_dms[level].get()); }
std::vector< std::unique_ptr< DM > > _dms
Vector of DMs for all grid levels.

◆ get_section()

PetscSection& libMesh::PetscDMWrapper::get_section ( unsigned int  level)
private

Get reference to PetscSection for the given mesh level.

init_dm_data() should be called before this function.

Definition at line 143 of file petsc_dm_wrapper.h.

References _sections.

144  { libmesh_assert_less(level, _sections.size());
145  return *(_sections[level].get()); }
std::vector< std::unique_ptr< PetscSection > > _sections
Vector of PETScSections for all grid levels.

◆ get_star_forest()

PetscSF& libMesh::PetscDMWrapper::get_star_forest ( unsigned int  level)
private

Get reference to PetscSF for the given mesh level.

init_dm_data() should be called before this function.

Definition at line 151 of file petsc_dm_wrapper.h.

References _star_forests.

152  { libmesh_assert_less(level, _star_forests.size());
153  return *(_star_forests[level].get()); }
std::vector< std::unique_ptr< PetscSF > > _star_forests
Vector of star forests for all grid levels.

◆ init_and_attach_petscdm()

void libMesh::PetscDMWrapper::init_and_attach_petscdm ( System system,
SNES &  snes 
)

◆ init_dm_data()

void libMesh::PetscDMWrapper::init_dm_data ( unsigned int  n_levels,
const Parallel::Communicator comm 
)
private

Init all the n_mesh_level dependent data structures.

◆ set_point_range_in_section()

void libMesh::PetscDMWrapper::set_point_range_in_section ( const System system,
PetscSection &  section,
std::unordered_map< dof_id_type, dof_id_type > &  node_map,
std::unordered_map< dof_id_type, dof_id_type > &  elem_map,
std::map< dof_id_type, unsigned int > &  scalar_map 
)
private

Helper function for build_section.

This function will count how many "points" on the current processor have DoFs associated with them and give that count to PETSc. We need to cache a mapping between the global node id and our local count that we do in this function because we will need the local number again in the add_dofs_to_section function.

Member Data Documentation

◆ _ctx_vec

std::vector<std::unique_ptr<PetscDMContext> > libMesh::PetscDMWrapper::_ctx_vec
private

Vector of internal PetscDM context structs for all grid levels.

Definition at line 117 of file petsc_dm_wrapper.h.

◆ _dms

std::vector<std::unique_ptr<DM> > libMesh::PetscDMWrapper::_dms
private

Vector of DMs for all grid levels.

Definition at line 102 of file petsc_dm_wrapper.h.

Referenced by get_dm().

◆ _mesh_dof_loc_sizes

std::vector<unsigned int> libMesh::PetscDMWrapper::_mesh_dof_loc_sizes
private

Stores n_local_dofs for each grid level, to be used for projection vector sizing.

Definition at line 126 of file petsc_dm_wrapper.h.

◆ _mesh_dof_sizes

std::vector<unsigned int> libMesh::PetscDMWrapper::_mesh_dof_sizes
private

Stores n_dofs for each grid level, to be used for projection matrix sizing.

Definition at line 123 of file petsc_dm_wrapper.h.

◆ _pmtx_vec

std::vector<std::unique_ptr<PetscMatrix<Real> > > libMesh::PetscDMWrapper::_pmtx_vec
private

Vector of projection matrixes for all grid levels.

Definition at line 111 of file petsc_dm_wrapper.h.

◆ _sections

std::vector<std::unique_ptr<PetscSection> > libMesh::PetscDMWrapper::_sections
private

Vector of PETScSections for all grid levels.

Definition at line 105 of file petsc_dm_wrapper.h.

Referenced by get_section().

◆ _star_forests

std::vector<std::unique_ptr<PetscSF> > libMesh::PetscDMWrapper::_star_forests
private

Vector of star forests for all grid levels.

Definition at line 108 of file petsc_dm_wrapper.h.

Referenced by get_star_forest().

◆ _subpmtx_vec

std::vector<std::unique_ptr<PetscMatrix<Real> > > libMesh::PetscDMWrapper::_subpmtx_vec
private

Vector of sub projection matrixes for all grid levels for fieldsplit.

Definition at line 114 of file petsc_dm_wrapper.h.

◆ _vec_vec

std::vector<std::unique_ptr<PetscVector<Real> > > libMesh::PetscDMWrapper::_vec_vec
private

Vector of solution vectors for all grid levels.

Definition at line 120 of file petsc_dm_wrapper.h.


The documentation for this class was generated from the following file: