libMesh
|
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 §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 (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... | |
std::vector< std::unique_ptr< PetscMatrix< Number > > > | _pmtx_vec |
Vector of projection matrixes for all grid levels. More... | |
std::vector< std::unique_ptr< PetscMatrix< Number > > > | _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< Number > > > | _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... | |
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 95 of file petsc_dm_wrapper.h.
|
default |
libMesh::PetscDMWrapper::~PetscDMWrapper | ( | ) |
Definition at line 425 of file petsc_dm_wrapper.C.
References clear().
|
private |
Helper function to reduce code duplication when setting dofs in section.
Definition at line 1039 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::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 972 of file petsc_dm_wrapper.C.
References add_dofs_helper(), libMesh::ParallelObject::comm(), libMesh::System::get_mesh(), libMesh::OrderWrapper::get_order(), libMesh::ierr, libMesh::libmesh_assert(), 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 729 of file petsc_dm_wrapper.C.
References add_dofs_to_section(), check_section_n_dofs(), libMesh::ParallelObject::comm(), libMesh::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 795 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::DofMap::dof_owner(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::ierr, libMesh::index_range(), 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 1072 of file petsc_dm_wrapper.C.
References libMesh::ierr.
Referenced by build_section().
void libMesh::PetscDMWrapper::clear | ( | ) |
Destroys and clears all build DM-related data.
Definition at line 430 of file petsc_dm_wrapper.C.
References _ctx_vec, _dms, _pmtx_vec, _sections, _star_forests, and _vec_vec.
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 144 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 152 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 160 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 445 of file petsc_dm_wrapper.C.
References _ctx_vec, _dms, _mesh_dof_loc_sizes, _mesh_dof_sizes, _pmtx_vec, _subpmtx_vec, _vec_vec, build_section(), build_sf(), libMesh::ParallelObject::comm(), libMesh::command_line_next(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::end_old_dof(), libMesh::DofMap::first_old_dof(), libMesh::ReferenceElem::get(), get_dm(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), get_section(), get_star_forest(), libMesh::ierr, init_dm_data(), libMesh::libmesh_assert(), libMesh::libmesh_petsc_DMCoarsen(), libMesh::libmesh_petsc_DMCreateInterpolation(), libMesh::libmesh_petsc_DMCreateRestriction(), libMesh::libmesh_petsc_DMCreateSubDM(), libMesh::libmesh_petsc_DMRefine(), libMesh::DofMap::local_variable_indices(), mesh, libMesh::DofMap::n_dofs(), libMesh::DofMap::n_dofs_on_processor(), libMesh::MeshTools::n_levels(), libMesh::DofMap::n_local_dofs(), libMesh::ParallelObject::n_processors(), n_vars, libMesh::System::n_vars(), libMesh::ParallelObject::processor_id(), libMesh::System::projection_matrix(), libMesh::System::reinit_constraints(), libMesh::MeshRefinement::uniformly_coarsen(), and libMesh::MeshRefinement::uniformly_refine().
Referenced by libMesh::PetscDiffSolver::setup_petsc_data().
|
private |
Init all the n_mesh_level dependent data structures.
Definition at line 1096 of file petsc_dm_wrapper.C.
References _ctx_vec, _dms, _mesh_dof_loc_sizes, _mesh_dof_sizes, _pmtx_vec, _sections, _star_forests, _subpmtx_vec, _vec_vec, 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 857 of file petsc_dm_wrapper.C.
References libMesh::ParallelObject::comm(), libMesh::DofMap::dof_indices(), libMesh::FEType::family, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::ierr, libMesh::libmesh_assert(), 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 internal PetscDM context structs for all grid levels.
Definition at line 126 of file petsc_dm_wrapper.h.
Referenced by clear(), init_and_attach_petscdm(), and init_dm_data().
|
private |
Vector of DMs for all grid levels.
Definition at line 111 of file petsc_dm_wrapper.h.
Referenced by clear(), get_dm(), init_and_attach_petscdm(), and init_dm_data().
|
private |
Stores n_local_dofs for each grid level, to be used for projection vector sizing.
Definition at line 135 of file petsc_dm_wrapper.h.
Referenced by init_and_attach_petscdm(), and init_dm_data().
|
private |
Stores n_dofs for each grid level, to be used for projection matrix sizing.
Definition at line 132 of file petsc_dm_wrapper.h.
Referenced by init_and_attach_petscdm(), and init_dm_data().
|
private |
Vector of projection matrixes for all grid levels.
Definition at line 120 of file petsc_dm_wrapper.h.
Referenced by clear(), init_and_attach_petscdm(), and init_dm_data().
|
private |
Vector of PETScSections for all grid levels.
Definition at line 114 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 117 of file petsc_dm_wrapper.h.
Referenced by clear(), get_star_forest(), and init_dm_data().
|
private |
Vector of sub projection matrixes for all grid levels for fieldsplit.
Definition at line 123 of file petsc_dm_wrapper.h.
Referenced by init_and_attach_petscdm(), and init_dm_data().
|
private |
Vector of solution vectors for all grid levels.
Definition at line 129 of file petsc_dm_wrapper.h.
Referenced by clear(), init_and_attach_petscdm(), and init_dm_data().