Skip to content

Commit

Permalink
feat: allow to use PETSc 3.21 with the library
Browse files Browse the repository at this point in the history
  • Loading branch information
andrsd committed Jan 2, 2025
1 parent 5ed60fe commit ca27c96
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
9 changes: 9 additions & 0 deletions include/godzilla/Partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class Partitioner {
const Section & target_section,
Section & partSection,
IndexSet & partition);
void partition(Int n_parts,
Int n_vertices,
Int start[],
Int adjacency[],
const Section & vertex_section,
const Section & edge_section,
const Section & target_section,
Section & partSection,
IndexSet & partition);

void view(PetscViewer viewer = PETSC_VIEWER_STDOUT_WORLD) const;

Expand Down
11 changes: 11 additions & 0 deletions include/godzilla/Problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ class Problem : public Object, public PrintInterface {
/// @return The global indices for the subproblem
IndexSet create_section_subis(const std::vector<Int> & fields) const;

/// Returns an IndexSet containing a Section that encapsulates a subproblem defined by
/// a subset of the fields and components in a Section in the problem.
///
/// @param fields The field numbers of the selected fields
/// @param n_comps The number of components from each field to incorporate into the subproblem
/// @param comps The component numbers of the selected fields
/// @return The global indices for the subproblem
IndexSet create_section_subis(const std::vector<Int> & fields,
const std::vector<Int> & n_comps,
const std::vector<Int> & comps) const;

protected:
/// Set vector/matrix types
virtual void set_up_types();
Expand Down
42 changes: 42 additions & 0 deletions src/Partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "godzilla/Partitioner.h"
#include "godzilla/CallStack.h"
#include "godzilla/Error.h"
#include "godzilla/Exception.h"

using namespace godzilla;

Expand Down Expand Up @@ -87,15 +88,56 @@ Partitioner::partition(Int n_parts,
IndexSet & partition)
{
CALL_STACK_MSG();
#if PETSC_VERSION_GE(3, 21, 0)
PETSC_CHECK(PetscPartitionerPartition(this->part,
n_parts,
n_vertices,
start,
adjacency,
vertex_section,
NULL,
target_section,
part_section,
partition));
#else
PETSC_CHECK(PetscPartitionerPartition(this->part,
n_parts,
n_vertices,
start,
adjacency,
vertex_section,
target_section,
part_section,
partition));
#endif
}

void
Partitioner::partition(Int n_parts,
Int n_vertices,
Int start[],
Int adjacency[],
const Section & vertex_section,
const Section & edge_section,
const Section & target_section,
Section & part_section,
IndexSet & partition)
{
CALL_STACK_MSG();
#if PETSC_VERSION_GE(3, 21, 0)
PETSC_CHECK(PetscPartitionerPartition(this->part,
n_parts,
n_vertices,
start,
adjacency,
vertex_section,
edge_section,
target_section,
part_section,
partition));
#else
throw Exception("PETSc 3.21+ is needed for Partitioner::partition with edge_section parameter");
#endif
}

Partitioner::operator PetscPartitioner() const
Expand Down
30 changes: 24 additions & 6 deletions src/Problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,37 @@ Problem::create_section_subis(const std::vector<Int> & fields) const
{
CALL_STACK_MSG();
#if PETSC_VERSION_GE(3, 21, 0)
IS is;
PETSC_CHECK(
DMCreateSectionSubDM(get_dm(), fields.size(), fields.data(), NULL, NULL, &is, NULL));
return IndexSet(is);
#else
IS is;
PETSC_CHECK(DMCreateSectionSubDM(get_dm(), fields.size(), fields.data(), &is, NULL));
return IndexSet(is);
#endif
}

IndexSet
Problem::create_section_subis(const std::vector<Int> & fields,
const std::vector<Int> & n_comps,
const std::vector<Int> & comps) const
{
CALL_STACK_MSG();
#if PETSC_VERSION_GE(3, 21, 0)
assert(fields.size() == n_comps.size());
IS is;
PETSC_CHECK(DMCreateSectionSubDM(get_dm(),
fields.size(),
fields.data(),
PETSC_DECIDE,
nullptr,
n_comps.data(),
comps.data(),
&is,
nullptr));
NULL));
return IndexSet(is);
#else
IS is;
PETSC_CHECK(DMCreateSectionSubDM(get_dm(), fields.size(), fields.data(), &is, nullptr));
return IndexSet(is);
throw Exception(
"PETSc 3.21+ is needed for Problem::create_section_subis with component support");
#endif
}

Expand Down

0 comments on commit ca27c96

Please sign in to comment.