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)
 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 (const System &system, 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...
 

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 51 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 ( const System system,
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 82 of file petsc_dm_wrapper.h.

References _dms.

83  { libmesh_assert(level < _dms.size());
84  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 90 of file petsc_dm_wrapper.h.

References _sections.

91  { libmesh_assert(level < _sections.size());
92  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 98 of file petsc_dm_wrapper.h.

References _star_forests.

99  { libmesh_assert(level < _star_forests.size());
100  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)
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

◆ _dms

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

Vector of DMs for all grid levels.

Definition at line 67 of file petsc_dm_wrapper.h.

Referenced by get_dm().

◆ _sections

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

Vector of PETScSections for all grid levels.

Definition at line 70 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 73 of file petsc_dm_wrapper.h.

Referenced by get_star_forest().


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