#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 §ion) |
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 §ion, 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 §ion, 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 §ion) |
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 §ion) |
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... | |
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.
Definition at line 51 of file petsc_dm_wrapper.h.
|
default |
libMesh::PetscDMWrapper::~PetscDMWrapper | ( | ) |
Definition at line 36 of file petsc_dm_wrapper.C.
References clear().
|
private |
Helper function to reduce code duplication when setting dofs in section.
Definition at line 407 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::get(), ierr, libMesh::DofObject::n_dofs(), libMesh::System::n_vars(), and libMesh::System::number().
Referenced by add_dofs_to_section().
|
private |
Helper function for build_section.
This function will set the DoF info for each "point" in the PetscSection.
Definition at line 340 of file petsc_dm_wrapper.C.
References add_dofs_helper(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::get(), libMesh::System::get_mesh(), libMesh::OrderWrapper::get_order(), ierr, mesh, libMesh::ParallelObject::n_processors(), libMesh::FEType::order, libMesh::ParallelObject::processor_id(), libMesh::Variable::type(), and libMesh::System::variable().
Referenced by build_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.
Definition at line 98 of file petsc_dm_wrapper.C.
References add_dofs_to_section(), check_section_n_dofs(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::get(), ierr, libMesh::System::n_local_dofs(), libMesh::System::n_vars(), libMesh::on_command_line(), set_point_range_in_section(), and libMesh::System::variable_name().
Referenced by init_and_attach_petscdm().
|
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
Definition at line 163 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::DofMap::dof_owner(), libMesh::DofMap::first_dof(), libMesh::Parallel::Communicator::get(), libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), ierr, libMesh::DofMap::n_local_dofs(), and PETSC_COPY_VALUES.
Referenced by init_and_attach_petscdm().
|
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.
Definition at line 440 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::get(), and ierr.
Referenced by build_section().
void libMesh::PetscDMWrapper::clear | ( | ) |
Destroys and clears all build DM-related data.
Definition at line 41 of file petsc_dm_wrapper.C.
References _dms, _sections, and _star_forests.
Referenced by libMesh::PetscDiffSolver::clear(), and ~PetscDMWrapper().
|
inlineprivate |
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.
Referenced by init_and_attach_petscdm().
|
inlineprivate |
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.
Referenced by init_and_attach_petscdm().
|
inlineprivate |
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.
Referenced by init_and_attach_petscdm().
void libMesh::PetscDMWrapper::init_and_attach_petscdm | ( | System & | system, |
SNES & | snes | ||
) |
Definition at line 54 of file petsc_dm_wrapper.C.
References build_section(), build_sf(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::get(), get_dm(), get_section(), get_star_forest(), ierr, init_dm_data(), libMesh::MeshTools::n_levels(), and libMesh::ParallelObject::n_processors().
Referenced by libMesh::PetscDiffSolver::setup_petsc_data().
|
private |
Init all the n_mesh_level dependent data structures.
Definition at line 461 of file petsc_dm_wrapper.C.
References _dms, _sections, _star_forests, and libMesh::MeshTools::n_levels().
Referenced by init_and_attach_petscdm().
|
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.
Definition at line 224 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::DofMap::dof_indices(), libMesh::FEType::family, libMesh::Parallel::Communicator::get(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofObject::id(), ierr, libMesh::DofMap::local_index(), mesh, libMesh::DofMap::n_local_dofs(), libMesh::ParallelObject::n_processors(), libMesh::DofMap::n_SCALAR_dofs(), libMesh::System::n_vars(), libMesh::System::number(), libMesh::ParallelObject::processor_id(), libMesh::SCALAR, libMesh::Variable::type(), and libMesh::System::variable().
Referenced by build_section().
|
private |
Vector of DMs for all grid levels.
Definition at line 67 of file petsc_dm_wrapper.h.
Referenced by clear(), get_dm(), and init_dm_data().
|
private |
Vector of PETScSections for all grid levels.
Definition at line 70 of file petsc_dm_wrapper.h.
Referenced by clear(), get_section(), and init_dm_data().
|
private |
Vector of star forests for all grid levels.
Definition at line 73 of file petsc_dm_wrapper.h.
Referenced by clear(), get_star_forest(), and init_dm_data().