// Here we only pass the callback for the function evaluation
// The tangent system will be approximated via matrix-free finite
// differencing.
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X[0];
auto y = X[1];
F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F(1) = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
// Test attaching a user-defined monitoring routine
solver.monitor = [&](const VectorType & X,
const unsigned int step,
- const real_type fval) -> int {
+ const real_type fval) -> void {
out << "# " << step << ": " << fval << std::endl;
- return 0;
};
// Create and initialize solution vector
Solver solver(data);
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X[0];
auto y = X[1];
F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F(1) = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
// Here we use the Jacobian callback following the PETSc style,
// will handle the case of users requesting Jacobian-free Newton
// Krylov (i.e. using -snes_mf_operator)
solver.jacobian =
- [&](const VectorType &X, MatrixType &A, MatrixType &P) -> int {
+ [&](const VectorType &X, MatrixType &A, MatrixType &P) -> void {
auto x = X[0];
auto y = X[1];
auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2);
P.set(1, 0, 1);
P.set(1, 1, 2);
P.compress(VectorOperation::insert);
- return 0;
};
VectorType x(MPI_COMM_SELF, 2, 2);
Solver solver(data);
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X[0];
auto y = X[1];
F(0) = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F(1) = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
// When users want to be in full control of the linear system
// during setup_jacobian and we use it in the solve phase
FullMatrix<double> Jinv(2, 2);
- solver.setup_jacobian = [&](const VectorType &X) -> int {
+ solver.setup_jacobian = [&](const VectorType &X) -> void {
auto x = X[0];
auto y = X[1];
auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2);
J(1, 0) = 1;
J(1, 1) = 2;
Jinv.invert(J);
- return 0;
};
// Solve phase. By default, PETSc will use this callback as a preconditioner
// solvers can still be used in a Jacobian-free way and selected at command
// line or within user code.
solver.solve_with_jacobian = [&](const VectorType &src,
- VectorType & dst) -> int {
+ VectorType & dst) -> void {
dst(0) = Jinv(0, 0) * src(0) + Jinv(0, 1) * src(1);
dst(1) = Jinv(1, 0) * src(0) + Jinv(1, 1) * src(1);
dst.compress(VectorOperation::insert);
- return 0;
};
VectorType x(MPI_COMM_SELF, 2, 2);
out << "# Solution " << x[0] << ", " << x[1] << std::endl;
out << "# Iterations " << nit << std::endl;
}
-
- return 0;
}
Solver solver;
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X.block(0)[0];
auto y = X.block(1)[0];
F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F.block(1)[0] = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
VectorType x(2, MPI_COMM_SELF, 1, 1);
Solver solver;
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X.block(0)[0];
auto y = X.block(1)[0];
F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F.block(1)[0] = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
solver.jacobian =
- [&](const VectorType &X, MatrixType &A, MatrixType &P) -> int {
+ [&](const VectorType &X, MatrixType &A, MatrixType &P) -> void {
auto x = X.block(0)[0];
auto y = X.block(1)[0];
auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2);
P.block(1, 0).set(0, 0, 1);
P.block(1, 1).set(0, 0, 2);
P.compress(VectorOperation::insert);
- return 0;
};
VectorType x(2, MPI_COMM_SELF, 1, 1);
Solver solver;
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
auto x = X.block(0)[0];
auto y = X.block(1)[0];
F.block(0)[0] = std::pow(x - std::pow(y, 3) + 1, 3) - std::pow(y, 3);
F.block(1)[0] = x + 2 * y - 3;
F.compress(VectorOperation::insert);
- return 0;
};
FullMatrix<double> Jinv(2, 2);
- solver.setup_jacobian = [&](const VectorType &X) -> int {
+ solver.setup_jacobian = [&](const VectorType &X) -> void {
auto x = X.block(0)[0];
auto y = X.block(1)[0];
auto f0_x = 3 * std::pow(x - std::pow(y, 3) + 1, 2);
J(1, 0) = 1;
J(1, 1) = 2;
Jinv.invert(J);
- return 0;
};
solver.solve_with_jacobian = [&](const VectorType &src,
- VectorType & dst) -> int {
+ VectorType & dst) -> void {
dst.block(0)[0] =
Jinv(0, 0) * src.block(0)[0] + Jinv(0, 1) * src.block(1)[0];
dst.block(1)[0] =
Jinv(1, 0) * src.block(0)[0] + Jinv(1, 1) * src.block(1)[0];
dst.compress(VectorOperation::insert);
- return 0;
};
VectorType x(2, MPI_COMM_SELF, 1, 1);
out << "# Solution " << x[0] << ", " << x[1] << std::endl;
out << "# Iterations " << nit << std::endl;
}
-
- return 0;
}
{
deallog << exc.what() << std::endl;
}
- return 0;
}
{
Solver solver;
- solver.energy = [&](const VectorType &X, real_type &v) -> int {
+ solver.energy = [&](const VectorType &X, real_type &v) -> void {
v = X.norm_sqr();
- return 0;
};
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
F.equ(2, X);
- return 0;
};
auto commsize = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
deallog << "Iterations " << nit << std::endl;
x.print(deallog.get_file_stream());
}
- return 0;
}
Solver solver(data);
- solver.residual = [&](const VectorType &X, VectorType &F) -> int {
+ solver.residual = [&](const VectorType &X, VectorType &F) -> void {
F.equ(2, X);
- return 0;
};
auto commsize = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
deallog << exc.what() << std::endl;
}
}
- return 0;
}