Skip to content

Commit

Permalink
fix: don't run 1D FV stuff with PETSc 3.21+
Browse files Browse the repository at this point in the history
Mass matrix formation trips a check in PETSc 3.21+. In 2D/3D all
works as expected, so we just skip the 1D stuff until it is fixed.
  • Loading branch information
andrsd committed Jan 4, 2025
1 parent 6e3194d commit 4d9cb7f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
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()
5 changes: 5 additions & 0 deletions src/FVProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ FVProblemInterface::create()
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
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

0 comments on commit 4d9cb7f

Please sign in to comment.