Skip to content

Commit

Permalink
Merge pull request #614 from andrsd/snes-get-set
Browse files Browse the repository at this point in the history
Adding SNESolver::{get|set}_type
  • Loading branch information
andrsd authored Sep 30, 2024
2 parents 82ac4d9 + 9011209 commit 510cb33
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/godzilla/SNESolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ class SNESolver {
/// @param dm The `DM`
void set_dm(DM dm);

/// Sets the method for the nonlinear solver.
///
/// @param A known method
void set_type(SNESType type);

/// Gets the SNES method type (as a string).
///
/// @return SNES method
std::string get_type() const;

/// Sets non-linear solver options from the options database
void set_from_options();

Expand Down
16 changes: 16 additions & 0 deletions src/SNESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ SNESolver::set_dm(DM dm)
PETSC_CHECK(SNESSetDM(this->snes, dm));
}

void
SNESolver::set_type(SNESType type)
{
CALL_STACK_MSG();
PETSC_CHECK(SNESSetType(this->snes, type));
}

std::string
SNESolver::get_type() const
{
CALL_STACK_MSG();
SNESType type;
PETSC_CHECK(SNESGetType(this->snes, &type));
return std::string(type);
}

void
SNESolver::set_from_options()
{
Expand Down
14 changes: 14 additions & 0 deletions test/src/SNESolver_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ TEST(SNESolverTest, mat_create_mf)
auto m = snes.mat_create_mf();
EXPECT_EQ(m.get_type(), "mffd");
}

TEST(SNESolverTest, type)
{
TestApp app;
TestNLProblem prob;
auto comm = app.get_comm();

SNESolver snes;
snes.create(comm);

snes.set_type("newtontr");

EXPECT_EQ(snes.get_type(), "newtontr");
}

0 comments on commit 510cb33

Please sign in to comment.