Skip to content

Commit

Permalink
Adjust tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed May 24, 2023
1 parent 8e895f3 commit 4a0288d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
22 changes: 7 additions & 15 deletions tests/petsc/petsc_ts_00.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ class HarmonicOscillator
time_stepper.implicit_function = [&](const real_type t,
const VectorType &y,
const VectorType &y_dot,
VectorType & res) -> int {
VectorType & res) -> void {
res(0) = y_dot(0) - y(1);
res(1) = y_dot(1) + kappa * kappa * y(0);
res.compress(VectorOperation::insert);
return 0;
};

// We either have the possibility of using PETSc standard
Expand All @@ -109,13 +108,12 @@ class HarmonicOscillator
const VectorType &y_dot,
const real_type shift,
MatrixType & A,
MatrixType & P) -> int {
MatrixType & P) -> void {
P.set(0, 0, shift);
P.set(0, 1, -1);
P.set(1, 0, kappa * kappa);
P.set(1, 1, shift);
P.compress(VectorOperation::insert);
return 0;
};
}
else if (user)
Expand All @@ -127,20 +125,18 @@ class HarmonicOscillator
time_stepper.setup_jacobian = [&](const real_type t,
const VectorType &y,
const VectorType &y_dot,
const real_type shift) -> int {
const real_type shift) -> void {
myshift = shift;
return 0;
};

// In the solve phase we se the stored shift to solve
// for the implicit Jacobian system
time_stepper.solve_with_jacobian = [&](const VectorType &src,
VectorType &dst) -> int {
VectorType &dst) -> void {
auto sf = 1. / (kappa * kappa + myshift * myshift);
dst(0) = sf * (myshift * src(0) + src(1));
dst(1) = sf * (-kappa * kappa * src(0) + myshift * src(1));
dst.compress(VectorOperation::insert);
return 0;
};
}
}
Expand All @@ -149,11 +145,10 @@ class HarmonicOscillator
// This is the only function one would populate in case an explicit
// solver is used.
time_stepper.explicit_function =
[&](const real_type t, const VectorType &y, VectorType &res) -> int {
[&](const real_type t, const VectorType &y, VectorType &res) -> void {
res(0) = y(1);
res(1) = -kappa * kappa * y(0);
res.compress(VectorOperation::insert);
return 0;
};

// The explicit Jacobian callback is not needed in case
Expand All @@ -165,13 +160,12 @@ class HarmonicOscillator
time_stepper.explicit_jacobian = [&](const real_type t,
const VectorType &y,
MatrixType & A,
MatrixType & P) -> int {
MatrixType & P) -> void {
P.set(0, 0, 0);
P.set(0, 1, 1);
P.set(1, 0, -kappa * kappa);
P.set(1, 1, 0);
P.compress(VectorOperation::insert);
return 0;
};
}
}
Expand All @@ -180,13 +174,12 @@ class HarmonicOscillator
// solution to the log file.
time_stepper.monitor = [&](const real_type t,
const VectorType & y,
const unsigned int step_number) -> int {
const unsigned int step_number) -> void {
std::vector<real_type> exact(2);
exact[0] = std::sin(kappa * t);
exact[1] = kappa * std::cos(kappa * t);
out << t << " " << y(0) << " (" << exact[0] << ")"
<< " " << y(1) << " (" << exact[1] << ")" << std::endl;
return 0;
};
}

Expand Down Expand Up @@ -259,5 +252,4 @@ main(int argc, char **argv)
HarmonicOscillator ode_user(1.0, data, true, true, true, out);
ode_user.run();
}
return 0;
}
1 change: 0 additions & 1 deletion tests/petsc/petsc_ts_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ main(int argc, char **argv)
{
deallog << exc.what() << std::endl;
}
return 0;
}
4 changes: 1 addition & 3 deletions tests/petsc/petsc_ts_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ class Dummy : public TimeStepper
implicit_function = [&](const real_type t,
const VectorType &y,
const VectorType &y_dot,
VectorType & res) -> int {
VectorType & res) -> void {
res(0) = y_dot(0) - y(0);
res(1) = y(1) - y(0);
res.compress(VectorOperation::insert);
return 0;
};

// Return the index set representing the
Expand Down Expand Up @@ -86,5 +85,4 @@ main(int argc, char **argv)

Dummy dae;
dae.solve();
return 0;
}

0 comments on commit 4a0288d

Please sign in to comment.