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

Remove support for PETSc < 3.5 #19197

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions framework/include/utils/MooseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,18 +750,12 @@ enum LineSearchType
LS_DEFAULT,
LS_NONE,
LS_BASIC,
#if PETSC_VERSION_LESS_THAN(3, 3, 0)
LS_CUBIC,
LS_QUADRATIC,
LS_BASICNONORMS,
#else
LS_SHELL,
LS_CONTACT,
LS_PROJECT,
LS_L2,
LS_BT,
LS_CP
#endif
};

/**
Expand Down
5 changes: 0 additions & 5 deletions framework/include/utils/PetscDMMoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

#pragma once

// This only works with petsc-3.3 and above.
#include "libmesh/petsc_macro.h"

#if !PETSC_VERSION_LESS_THAN(3, 3, 0)

// PETSc includes
#include <petscdm.h>
#define DMMOOSE "moose"
Expand Down Expand Up @@ -58,5 +55,3 @@ extern PetscErrorCode DMMooseGetSplitBlocks(DM, const std::string &, std::set<st
extern PetscErrorCode DMMooseSetSplitSides(DM, const std::string &, const std::set<std::string> &);
extern PetscErrorCode DMMooseGetSplitSides(DM, const std::string &, std::set<std::string> &);
extern PetscErrorCode SNESUpdateDMMoose(SNES snes, PetscInt iteration);

#endif // #if !PETSC_VERSION_LESS_THAN(3,3,0)
4 changes: 0 additions & 4 deletions framework/include/utils/PetscSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ void disableNonlinearConvergedReason(FEProblemBase & fe_problem);
*/
void disableLinearConvergedReason(FEProblemBase & fe_problem);

#if PETSC_VERSION_LESS_THAN(3, 4, 0)
#define SNESGETLINESEARCH SNESGetSNESLineSearch
#else
#define SNESGETLINESEARCH SNESGetLineSearch
#endif
}
}
3 changes: 0 additions & 3 deletions framework/src/preconditioners/FieldSplitPreconditioner.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "libmesh/petsc_macro.h"
#if !PETSC_VERSION_LESS_THAN(3, 3, 0)
#include "FieldSplitPreconditioner.h"

// MOOSE includes
Expand Down Expand Up @@ -97,5 +96,3 @@ FieldSplitPreconditioner::FieldSplitPreconditioner(const InputParameters & param
// apply prefix and store PETSc options
_fe_problem.getNonlinearSystemBase().setupFieldDecomposition();
}

#endif
15 changes: 1 addition & 14 deletions framework/src/splits/Split.C
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ Split::Split(const InputParameters & parameters)
void
Split::setup(const std::string & prefix)
{
// petsc 3.3.0 or later needed
#if PETSC_VERSION_LESS_THAN(3, 3, 0)
mooseError("The Splits functionality requires PETSc 3.3.0 or later.");
#endif

// The Split::setup() implementation does not actually depend on any
// specific version of PETSc, so there's no need to wrap the entire
// function.
Expand Down Expand Up @@ -147,15 +142,7 @@ Split::setup(const std::string & prefix)
petsc_schur_type[_splitting_type]);

// set Schur Preconditioner
const std::string petsc_schur_pre[] = {
"self",
"selfp",
#if PETSC_VERSION_LESS_THAN(3, 4, 0)
"diag"
#else
"a11"
#endif
};
const std::string petsc_schur_pre[] = {"self", "selfp", "a11"};
po.pairs.emplace_back(prefix + "pc_fieldsplit_schur_precondition",
petsc_schur_pre[_schur_pre]);

Expand Down
51 changes: 1 addition & 50 deletions framework/src/systems/NonlinearSystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,15 @@ NonlinearSystem::solve()
_final_residual = _nl_implicit_sys.final_nonlinear_residual();

if (_use_coloring_finite_difference)
#if PETSC_VERSION_LESS_THAN(3, 2, 0)
MatFDColoringDestroy(_fdcoloring);
#else
MatFDColoringDestroy(&_fdcoloring);
#endif
}

void
NonlinearSystem::stopSolve()
{
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
#else
PetscNonlinearSolver<Real> & solver =
static_cast<PetscNonlinearSolver<Real> &>(*sys().nonlinear_solver);
SNESSetFunctionDomainError(solver.snes());
#endif

// Insert a NaN into the residual vector. As of PETSc-3.6, this
// should make PETSc return DIVERGED_NANORINF the next time it does
Expand Down Expand Up @@ -283,11 +276,7 @@ NonlinearSystem::setupStandardFiniteDifferencedPreconditioner()
SNESSetJacobian(petsc_nonlinear_solver->snes(),
petsc_mat->mat(),
petsc_mat->mat(),
#if PETSC_VERSION_LESS_THAN(3, 4, 0)
SNESDefaultComputeJacobian,
#else
SNESComputeJacobianDefault,
#endif
nullptr);
}

Expand All @@ -304,12 +293,6 @@ NonlinearSystem::setupColoringFiniteDifferencedPreconditioner()
PetscMatrix<Number> * petsc_mat =
dynamic_cast<PetscMatrix<Number> *>(&_nl_implicit_sys.get_system_matrix());

#if PETSC_VERSION_LESS_THAN(3, 2, 0)
// This variable is only needed for PETSC < 3.2.0
PetscVector<Number> * petsc_vec =
dynamic_cast<PetscVector<Number> *>(_nl_implicit_sys.solution.get());
#endif

Moose::compute_jacobian(*_nl_implicit_sys.current_local_solution, *petsc_mat, _nl_implicit_sys);

if (!petsc_mat)
Expand All @@ -320,15 +303,6 @@ NonlinearSystem::setupColoringFiniteDifferencedPreconditioner()
PetscErrorCode ierr = 0;
ISColoring iscoloring;

#if PETSC_VERSION_LESS_THAN(3, 2, 0)
// PETSc 3.2.x
ierr = MatGetColoring(petsc_mat->mat(), MATCOLORING_LF, &iscoloring);
CHKERRABORT(libMesh::COMM_WORLD, ierr);
#elif PETSC_VERSION_LESS_THAN(3, 5, 0)
// PETSc 3.3.x, 3.4.x
ierr = MatGetColoring(petsc_mat->mat(), MATCOLORINGLF, &iscoloring);
CHKERRABORT(_communicator.get(), ierr);
#else
// PETSc 3.5.x
MatColoring matcoloring;
ierr = MatColoringCreate(petsc_mat->mat(), &matcoloring);
Expand All @@ -341,7 +315,6 @@ NonlinearSystem::setupColoringFiniteDifferencedPreconditioner()
CHKERRABORT(_communicator.get(), ierr);
ierr = MatColoringDestroy(&matcoloring);
CHKERRABORT(_communicator.get(), ierr);
#endif

MatFDColoringCreate(petsc_mat->mat(), iscoloring, &_fdcoloring);
MatFDColoringSetFromOptions(_fdcoloring);
Expand All @@ -351,36 +324,14 @@ NonlinearSystem::setupColoringFiniteDifferencedPreconditioner()
libMesh::libmesh_petsc_snes_fd_residual,
&petsc_nonlinear_solver);
// clang-format on
#if !PETSC_RELEASE_LESS_THAN(3, 5, 0)
MatFDColoringSetUp(petsc_mat->mat(), iscoloring, _fdcoloring);
#endif
#if PETSC_VERSION_LESS_THAN(3, 4, 0)
SNESSetJacobian(petsc_nonlinear_solver.snes(),
petsc_mat->mat(),
petsc_mat->mat(),
SNESDefaultComputeJacobianColor,
_fdcoloring);
#else
SNESSetJacobian(petsc_nonlinear_solver.snes(),
petsc_mat->mat(),
petsc_mat->mat(),
SNESComputeJacobianDefaultColor,
_fdcoloring);
#endif
#if PETSC_VERSION_LESS_THAN(3, 2, 0)
Mat my_mat = petsc_mat->mat();
MatStructure my_struct;

SNESComputeJacobian(
petsc_nonlinear_solver.snes(), petsc_vec->vec(), &my_mat, &my_mat, &my_struct);
#endif

#if PETSC_VERSION_LESS_THAN(3, 2, 0)
ISColoringDestroy(iscoloring);
#else
// PETSc 3.3.0
// PETSc >=3.3.0
ISColoringDestroy(&iscoloring);
#endif
}

bool
Expand Down
67 changes: 5 additions & 62 deletions framework/src/systems/NonlinearSystemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@
#include <ios>

#include "petscsnes.h"
#if !PETSC_VERSION_LESS_THAN(3, 3, 0)
#include <PetscDMMoose.h>
EXTERN_C_BEGIN
extern PetscErrorCode DMCreate_Moose(DM);
EXTERN_C_END
#endif

NonlinearSystemBase::NonlinearSystemBase(FEProblemBase & fe_problem,
System & sys,
Expand Down Expand Up @@ -1870,16 +1868,13 @@ NonlinearSystemBase::constraintJacobians(bool displaced)

auto & jacobian = getMatrix(systemMatrixTag());

#if PETSC_VERSION_LESS_THAN(3, 3, 0)
#else
if (!_fe_problem.errorOnJacobianNonzeroReallocation())
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_NEW_NONZERO_ALLOCATION_ERR,
PETSC_FALSE);
if (_fe_problem.ignoreZerosInJacobian())
MatSetOption(
static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
#endif

std::vector<numeric_index_type> zero_rows;
std::map<std::pair<unsigned int, unsigned int>, PenetrationLocator *> * penetration_locators =
Expand Down Expand Up @@ -2063,18 +2058,9 @@ NonlinearSystemBase::constraintJacobians(bool displaced)

if (constraints_applied)
{
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
#elif PETSC_VERSION_LESS_THAN(3, 1, 0)
// In Petsc 3.0.0, MatSetOption has three args...the third arg
// determines whether the option is set (true) or unset (false)
MatSetOption(
static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
#else
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
PETSC_TRUE);
#endif

jacobian.close();
jacobian.zero_rows(zero_rows, 0.0);
Expand All @@ -2091,19 +2077,9 @@ NonlinearSystemBase::constraintJacobians(bool displaced)

if (constraints_applied)
{
// Necessary for speed
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
#elif PETSC_VERSION_LESS_THAN(3, 1, 0)
// In Petsc 3.0.0, MatSetOption has three args...the third arg
// determines whether the option is set (true) or unset (false)
MatSetOption(
static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
#else
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
PETSC_TRUE);
#endif

jacobian.close();
jacobian.zero_rows(zero_rows, 0.0);
Expand Down Expand Up @@ -2294,19 +2270,9 @@ NonlinearSystemBase::constraintJacobians(bool displaced)

if (constraints_applied)
{
// Necessary for speed
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
#elif PETSC_VERSION_LESS_THAN(3, 1, 0)
// In Petsc 3.0.0, MatSetOption has three args...the third arg
// determines whether the option is set (true) or unset (false)
MatSetOption(
static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
#else
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
PETSC_TRUE);
#endif

jacobian.close();
jacobian.zero_rows(zero_rows, 0.0);
Expand Down Expand Up @@ -2402,22 +2368,12 @@ NonlinearSystemBase::computeJacobianInternal(const std::set<TagID> & tags)
// Necessary for speed
if (auto petsc_matrix = dynamic_cast<PetscMatrix<Number> *>(&jacobian))
{
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
MatSetOption(petsc_matrix->mat(), MAT_KEEP_ZEROED_ROWS);
#elif PETSC_VERSION_LESS_THAN(3, 1, 0)
// In Petsc 3.0.0, MatSetOption has three args...the third arg
// determines whether the option is set (true) or unset (false)
MatSetOption(petsc_matrix->mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
#else
MatSetOption(petsc_matrix->mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
PETSC_TRUE);
#endif // PETSC_VERSION
#if !PETSC_VERSION_LESS_THAN(3, 3, 0)
if (!_fe_problem.errorOnJacobianNonzeroReallocation())
MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
}
#endif // PETSC_VERSION
}

jacobianSetup();
Expand Down Expand Up @@ -2782,26 +2738,13 @@ NonlinearSystemBase::computeJacobianBlocks(std::vector<JacobianBlock *> & blocks
{
SparseMatrix<Number> & jacobian = blocks[i]->_jacobian;

// Necessary for speed
#if PETSC_VERSION_LESS_THAN(3, 0, 0)
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
#elif PETSC_VERSION_LESS_THAN(3, 1, 0)
// In Petsc 3.0.0, MatSetOption has three args...the third arg
// determines whether the option is set (true) or unset (false)
MatSetOption(
static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
#else
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
PETSC_TRUE);
if (!_fe_problem.errorOnJacobianNonzeroReallocation())
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
MAT_NEW_NONZERO_ALLOCATION_ERR,
PETSC_TRUE);
#endif
#if PETSC_VERSION_LESS_THAN(3, 3, 0)
#else
if (!_fe_problem.errorOnJacobianNonzeroReallocation())
MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
MAT_NEW_NONZERO_ALLOCATION_ERR,
PETSC_TRUE);
#endif

jacobian.zero();
}
Expand Down
4 changes: 0 additions & 4 deletions framework/src/utils/ColumnMajorMatrix.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include <petscsys.h>
#include <petscblaslapack.h>

#if PETSC_VERSION_LESS_THAN(3, 5, 0)
extern "C" void FORTRAN_CALL(dgetri)(...); // matrix inversion routine from LAPACK
#endif

template <typename T>
ColumnMajorMatrixTempl<T>::ColumnMajorMatrixTempl(unsigned int rows, unsigned int cols)
: _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
Expand Down
6 changes: 0 additions & 6 deletions framework/src/utils/Conversion.C
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,12 @@ initLineSearchType()
line_search_type_to_enum["NONE"] = LS_NONE;
line_search_type_to_enum["BASIC"] = LS_BASIC;

#if PETSC_VERSION_LESS_THAN(3, 3, 0)
line_search_type_to_enum["CUBIC"] = LS_CUBIC;
line_search_type_to_enum["QUADRATIC"] = LS_QUADRATIC;
line_search_type_to_enum["BASICNONORMS"] = LS_BASICNONORMS;
#else
line_search_type_to_enum["SHELL"] = LS_SHELL;
line_search_type_to_enum["L2"] = LS_L2;
line_search_type_to_enum["BT"] = LS_BT;
line_search_type_to_enum["CP"] = LS_CP;
line_search_type_to_enum["CONTACT"] = LS_CONTACT;
line_search_type_to_enum["PROJECT"] = LS_PROJECT;
#endif
}
}

Expand Down
Loading