diff --git a/examples/advect-eqn/test/CMakeLists.txt b/examples/advect-eqn/test/CMakeLists.txt index 11dbcaee..09796dcc 100644 --- a/examples/advect-eqn/test/CMakeLists.txt +++ b/examples/advect-eqn/test/CMakeLists.txt @@ -1,5 +1,7 @@ include(TesterExodusII) +if(${PETSC_VERSION} VERSION_LESS "3.21.0") + add_test_exodiff( NAME advect BIN ${PROJECT_NAME} @@ -8,3 +10,5 @@ add_test_exodiff( GOLD ${PROJECT_SOURCE_DIR}/test/gold/1d.exo ARGS -Floor 1e-16 ) + +endif() \ No newline at end of file diff --git a/src/FVProblemInterface.cpp b/src/FVProblemInterface.cpp index 3b57d582..11488668 100644 --- a/src/FVProblemInterface.cpp +++ b/src/FVProblemInterface.cpp @@ -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 diff --git a/test/src/ExplicitFVLinearProblem_test.cpp b/test/src/ExplicitFVLinearProblem_test.cpp index d19113da..c66c2189 100644 --- a/test/src/ExplicitFVLinearProblem_test.cpp +++ b/test/src/ExplicitFVLinearProblem_test.cpp @@ -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" @@ -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; + mesh_pars.set("nx") = 2; + mesh_pars.set("ny") = 1; + RectangleMesh mesh(mesh_pars); +#else Parameters mesh_pars = LineMesh::parameters(); mesh_pars.set("_app") = &app; mesh_pars.set("nx") = 2; LineMesh mesh(mesh_pars); +#endif Parameters prob_pars = TestExplicitFVLinearProblem::parameters(); prob_pars.set("_app") = &app; @@ -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; + mesh_pars.set("nx") = 2; + mesh_pars.set("ny") = 1; + RectangleMesh mesh(mesh_pars); +#else Parameters mesh_pars = LineMesh::parameters(); mesh_pars.set("_app") = &app; mesh_pars.set("nx") = 2; LineMesh mesh(mesh_pars); +#endif Parameters prob_pars = TestExplicitFVLinearProblem::parameters(); prob_pars.set("_app") = &app; @@ -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; + mesh_pars.set("nx") = 3; + mesh_pars.set("ny") = 1; + mesh_pars.set("ymax") = 3.; + RectangleMesh mesh(mesh_pars); +#else Parameters mesh_pars = LineMesh::parameters(); mesh_pars.set("_app") = &app; mesh_pars.set("nx") = 3; LineMesh mesh(mesh_pars); +#endif Parameters prob_pars = TestExplicitFVLinearProblem::parameters(); prob_pars.set("_app") = &app; @@ -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; mesh_pars.set("nx") = 2; @@ -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; + mesh_pars.set("nx") = 2; + mesh_pars.set("ny") = 1; + RectangleMesh mesh(mesh_pars); +#else Parameters mesh_pars = LineMesh::parameters(); mesh_pars.set("_app") = &app; mesh_pars.set("nx") = 2; LineMesh mesh(mesh_pars); +#endif Parameters prob_pars = TestExplicitFVLinearProblem::parameters(); prob_pars.set("_app") = &app; @@ -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; + mesh_pars.set("nx") = 2; + mesh_pars.set("ny") = 1; + RectangleMesh mesh(mesh_pars); +#else Parameters mesh_pars = LineMesh::parameters(); mesh_pars.set("_app") = &app; mesh_pars.set("nx") = 2; LineMesh mesh(mesh_pars); +#endif Parameters prob_pars = TestExplicitFVLinearProblem::parameters(); prob_pars.set("_app") = &app;