Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for PETSc 3.21 #668

Merged
merged 4 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
python-version: "3.9"
petsc: 3.20.6
build: Release
- os: ubuntu-22.04
python-version: "3.9"
petsc: 3.21.6
build: Release
runs-on: ${{ matrix.os }}
steps:
- name: Set up miniconda
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ godzilla
[![github-pages](https://github.com/andrsd/godzilla/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/andrsd/godzilla/actions/workflows/gh-pages.yml)
[![codecov](https://codecov.io/gh/andrsd/godzilla/branch/main/graph/badge.svg?token=7KL45W9Z4G)](https://codecov.io/gh/andrsd/godzilla)
[![License](http://img.shields.io/:license-mit-blue.svg)](https://andrsd.mit-license.org/)
[![PETSc](https://img.shields.io/badge/PETSc-3.20-red)](https://petsc.org/)
[![PETSc](https://img.shields.io/badge/PETSc-3.20,%203.21-red)](https://petsc.org/)
[![Scc Count Badge](https://sloc.xyz/github/andrsd/godzilla/)](https://github.com/andrsd/godzilla/)


Expand Down
4 changes: 4 additions & 0 deletions examples/advect-eqn/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include(TesterExodusII)

if(${PETSC_VERSION} VERSION_LESS "3.21.0")

add_test_exodiff(
NAME advect
BIN ${PROJECT_NAME}
Expand All @@ -8,3 +10,5 @@ add_test_exodiff(
GOLD ${PROJECT_SOURCE_DIR}/test/gold/1d.exo
ARGS -Floor 1e-16
)

endif()
3 changes: 3 additions & 0 deletions include/godzilla/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Mesh {
/// @param c coordinate vector
void set_coordinates_local(const Vector & c);

/// If a mesh is periodic, create local coordinates for cells having periodic faces
void localize_coordinates() const;

/// Sets up the data structures inside the `DM` object
void set_up();

Expand Down
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
3 changes: 3 additions & 0 deletions src/DGProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

PETSC_CHECK(DMCopyDisc(dm, cdm));
PETSC_CHECK(DMGetCoarseDM(cdm, &cdm));
if (cdm)
PETSC_CHECK(DMLocalizeCoordinates(cdm));

Check warning on line 53 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L52-L53

Added lines #L52 - L53 were not covered by tests
}
}

Expand Down Expand Up @@ -395,6 +397,7 @@
CALL_STACK_MSG();
set_up_fields();
DiscreteProblemInterface::create();
get_unstr_mesh()->localize_coordinates();

Check warning on line 400 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L400

Added line #L400 was not covered by tests
}

void
Expand Down
3 changes: 3 additions & 0 deletions src/FEProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
this->asmbl = new AssemblyData(dim);
set_up_fields();
DiscreteProblemInterface::create();
get_unstr_mesh()->localize_coordinates();
}

void
Expand All @@ -112,6 +113,8 @@

PETSC_CHECK(DMCopyDisc(dm, cdm));
PETSC_CHECK(DMGetCoarseDM(cdm, &cdm));
if (cdm)
PETSC_CHECK(DMLocalizeCoordinates(cdm));

Check warning on line 117 in src/FEProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/FEProblemInterface.cpp#L117

Added line #L117 was not covered by tests
}

set_up_assembly_data_aux();
Expand Down
8 changes: 8 additions & 0 deletions src/FVProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@

PETSC_CHECK(DMCopyDisc(dm, cdm));
PETSC_CHECK(DMGetCoarseDM(cdm, &cdm));
if (cdm)
PETSC_CHECK(DMLocalizeCoordinates(cdm));

Check warning on line 80 in src/FVProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/FVProblemInterface.cpp#L80

Added line #L80 was not covered by tests
}
}

Expand Down Expand Up @@ -364,6 +366,12 @@
set_up_fields();
DiscreteProblemInterface::create();
get_unstr_mesh()->construct_ghost_cells();
get_unstr_mesh()->localize_coordinates();

#if PETSC_VERSION_GE(3, 21, 0)
if (get_unstr_mesh()->get_dimension() == 1)
throw Exception("FV in 1D is not possible due to a bug in PETSc. Use PETSc 3.20 instead.");
#endif
}

void
Expand Down
7 changes: 7 additions & 0 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ Mesh::set_coordinates_local(const Vector & c)
PETSC_CHECK(DMSetCoordinatesLocal(this->dm, c));
}

void
Mesh::localize_coordinates() const
{
CALL_STACK_MSG();
PETSC_CHECK(DMLocalizeCoordinates(this->dm));
}

void
Mesh::set_up()
{
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 @@
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,

Check warning on line 103 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L103

Added line #L103 was not covered by tests
n_parts,
n_vertices,
start,
adjacency,
vertex_section,
target_section,
part_section,
partition));
#endif
}

Check warning on line 113 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L113

Added line #L113 was not covered by tests

void
Partitioner::partition(Int n_parts,

Check warning on line 116 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L116

Added line #L116 was not covered by tests
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();

Check warning on line 126 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L126

Added line #L126 was not covered by tests
#if PETSC_VERSION_GE(3, 21, 0)
PETSC_CHECK(PetscPartitionerPartition(this->part,

Check warning on line 128 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L128

Added line #L128 was not covered by tests
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");

Check warning on line 139 in src/Partitioner.cpp

View check run for this annotation

Codecov / codecov/patch

src/Partitioner.cpp#L139

Added line #L139 was not covered by tests
#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 @@
{
CALL_STACK_MSG();
#if PETSC_VERSION_GE(3, 21, 0)
IS is;
PETSC_CHECK(

Check warning on line 441 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L441

Added line #L441 was not covered by tests
DMCreateSectionSubDM(get_dm(), fields.size(), fields.data(), NULL, NULL, &is, NULL));
return IndexSet(is);

Check warning on line 443 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L443

Added line #L443 was not covered by tests
#else
IS is;
PETSC_CHECK(DMCreateSectionSubDM(get_dm(), fields.size(), fields.data(), &is, NULL));
return IndexSet(is);

Check warning on line 447 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L445-L447

Added lines #L445 - L447 were not covered by tests
#endif
}

IndexSet
Problem::create_section_subis(const std::vector<Int> & fields,

Check warning on line 452 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L452

Added line #L452 was not covered by tests
const std::vector<Int> & n_comps,
const std::vector<Int> & comps) const
{
CALL_STACK_MSG();

Check warning on line 456 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L456

Added line #L456 was not covered by tests
#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");

Check warning on line 470 in src/Problem.cpp

View check run for this annotation

Codecov / codecov/patch

src/Problem.cpp#L469-L470

Added lines #L469 - L470 were not covered by tests
#endif
}

Expand Down
51 changes: 51 additions & 0 deletions test/src/ExplicitFVLinearProblem_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gmock/gmock.h"
#include "godzilla/CallStack.h"
#include "godzilla/LineMesh.h"
#include "godzilla/RectangleMesh.h"
#include "godzilla/NaturalRiemannBC.h"
#include "godzilla/ExplicitFVLinearProblem.h"
#include "godzilla/Parameters.h"
Expand Down Expand Up @@ -112,10 +113,19 @@ TEST(ExplicitFVLinearProblemTest, api)
{
TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
Parameters mesh_pars = RectangleMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
mesh_pars.set<Int>("ny") = 1;
RectangleMesh mesh(mesh_pars);
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
LineMesh mesh(mesh_pars);
#endif

Parameters prob_pars = TestExplicitFVLinearProblem::parameters();
prob_pars.set<App *>("_app") = &app;
Expand Down Expand Up @@ -201,10 +211,19 @@ TEST(ExplicitFVLinearProblemTest, fields)
{
TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
Parameters mesh_pars = RectangleMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
mesh_pars.set<Int>("ny") = 1;
RectangleMesh mesh(mesh_pars);
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
LineMesh mesh(mesh_pars);
#endif

Parameters prob_pars = TestExplicitFVLinearProblem::parameters();
prob_pars.set<App *>("_app") = &app;
Expand Down Expand Up @@ -244,10 +263,20 @@ TEST(ExplicitFVLinearProblemTest, test_mass_matrix)
{
TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
Parameters mesh_pars = RectangleMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 3;
mesh_pars.set<Int>("ny") = 1;
mesh_pars.set<Real>("ymax") = 3.;
RectangleMesh mesh(mesh_pars);
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 3;
LineMesh mesh(mesh_pars);
#endif

Parameters prob_pars = TestExplicitFVLinearProblem::parameters();
prob_pars.set<App *>("_app") = &app;
Expand Down Expand Up @@ -276,6 +305,9 @@ TEST(ExplicitFVLinearProblemTest, solve)
{
TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
Expand Down Expand Up @@ -330,16 +362,26 @@ TEST(ExplicitFVLinearProblemTest, solve)
EXPECT_NEAR(lx[2], 0., 1e-15);
EXPECT_NEAR(lx[3], 0., 1e-15);
loc_sln.restore_array_read(lx);
#endif
}

TEST(ExplicitFVLinearProblemTest, set_schemes)
{
TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
Parameters mesh_pars = RectangleMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
mesh_pars.set<Int>("ny") = 1;
RectangleMesh mesh(mesh_pars);
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
LineMesh mesh(mesh_pars);
#endif

Parameters prob_pars = TestExplicitFVLinearProblem::parameters();
prob_pars.set<App *>("_app") = &app;
Expand Down Expand Up @@ -373,10 +415,19 @@ TEST(ExplicitFVLinearProblemTest, wrong_schemes)

TestApp app;

#if PETSC_VERSION_GE(3, 21, 0)
// PETSc 3.21.0+ has a bug in forming the mass matrix in 1D, se we use 2D mesh in this test
Parameters mesh_pars = RectangleMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
mesh_pars.set<Int>("ny") = 1;
RectangleMesh mesh(mesh_pars);
#else
Parameters mesh_pars = LineMesh::parameters();
mesh_pars.set<App *>("_app") = &app;
mesh_pars.set<Int>("nx") = 2;
LineMesh mesh(mesh_pars);
#endif

Parameters prob_pars = TestExplicitFVLinearProblem::parameters();
prob_pars.set<App *>("_app") = &app;
Expand Down
Loading
Loading