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

Allow to reuse the preconditioner in the Newton solver #1102

Merged
merged 22 commits into from
Apr 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0d5feeb
Move operators and transfers to constructor
lpsaavedra Apr 10, 2024
92a71e1
Clean a bit and enable CG output
lpsaavedra Apr 16, 2024
b9f3b3b
Set up preconditioner at the nonlinear solver level
lpsaavedra Apr 18, 2024
4d57730
Computing timer, setup preconditioner and use constant modes in LSMG
lpsaavedra Apr 18, 2024
dd2656a
Correct MG times output
lpsaavedra Apr 19, 2024
d9cfa65
Remove setuppreconditioner from all auxiliary physics
lpsaavedra Apr 22, 2024
80e2f14
Revert extra line
lpsaavedra Apr 22, 2024
6256f62
Allow all GLS solvers to reuse the preconditioner or not
lpsaavedra Apr 22, 2024
612be8d
Fix coarse grid output
lpsaavedra Apr 22, 2024
60d6a17
Use setup preconditioner call in inexact newton
lpsaavedra Apr 22, 2024
8ebd580
Fix indent
lpsaavedra Apr 22, 2024
20b63af
Add this specifier within GMG precond functions
lpsaavedra Apr 22, 2024
780fb71
Add new reuse precond parameter to doc
lpsaavedra Apr 22, 2024
480df70
Fix newton tests and add setup preconditioner call to kinsol newton s…
lpsaavedra Apr 22, 2024
2d843c5
Move transfer of previous solutions to initialize function
lpsaavedra Apr 23, 2024
83dea9b
Fix if condition in Newton solver
lpsaavedra Apr 23, 2024
c837884
Merge initialize functions
lpsaavedra Apr 23, 2024
632778b
Slight changes to test output
lpsaavedra Apr 23, 2024
e2776d9
Fix local smoothing when min cells or min level specified
lpsaavedra Apr 24, 2024
3f93ca9
Fix comments
lpsaavedra Apr 24, 2024
a1b2608
Add changelog entry
lpsaavedra Apr 24, 2024
0c30a8a
Remove commented lines
lpsaavedra Apr 24, 2024
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
Prev Previous commit
Next Next commit
Set up preconditioner at the nonlinear solver level
lpsaavedra committed Apr 24, 2024
commit b9f3b3b59123064d0d1e145f438e1b53a1b99b32
4 changes: 4 additions & 0 deletions include/core/newton_non_linear_solver.h
Original file line number Diff line number Diff line change
@@ -95,6 +95,10 @@ NewtonNonLinearSolver<VectorType>::solve(const bool is_initial_step)
evaluation_point = present_solution;

solver->assemble_system_matrix();

if (!this->params.reuse_preconditioner || this->outer_iteration == 0)
solver->setup_preconditioner();

if (this->params.force_rhs_calculation || this->outer_iteration == 0)
solver->assemble_system_rhs();

3 changes: 3 additions & 0 deletions include/core/parameters.h
Original file line number Diff line number Diff line change
@@ -1016,6 +1016,9 @@ namespace Parameters
// Carry jacobian matrix over to the new non-linear problem
bool reuse_matrix;

// Reuse preconditioner for the next non-linear iterations
bool reuse_preconditioner;

// Abort solver if non-linear solution has not reached tolerance
bool abort_at_convergence_failure;

6 changes: 6 additions & 0 deletions include/core/physics_solver.h
Original file line number Diff line number Diff line change
@@ -55,6 +55,12 @@ class PhysicsSolver
virtual void
assemble_system_rhs() = 0;

/**
* @brief Set up preconditioner.
*
*/
virtual void
setup_preconditioner() = 0;

/**
* @brief solve_linear_system Solves the linear system of equations
6 changes: 6 additions & 0 deletions include/solvers/cahn_hilliard.h
Original file line number Diff line number Diff line change
@@ -331,6 +331,12 @@ class CahnHilliard : public AuxiliaryPhysics<dim, GlobalVectorType>
void
assemble_system_rhs() override;

/**
* @brief Set up preconditioner. Not used for this solver but
* needed for other physics solvers.
*/
void
setup_preconditioner() override;

/**
* @brief Assemble the local matrix for a given cell.
7 changes: 7 additions & 0 deletions include/solvers/gd_navier_stokes.h
Original file line number Diff line number Diff line change
@@ -98,6 +98,13 @@ class GDNavierStokesSolver
void
assemble_system_rhs() override;

/**
* @brief Set up preconditioner. Not used for this solver but
* needed for other physics solvers.
*/
void
setup_preconditioner() override;

/**
* @brief Update the average velocity field solution in the multiphysics interface
*/
2 changes: 1 addition & 1 deletion include/solvers/gls_navier_stokes.h
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ class GLSNavierStokesSolver
* @brief Set-up the appropriate preconditioner
*/
void
setup_preconditioner();
setup_preconditioner() override;

/**
* @brief Define the non-zero constraints used to solve the problem.
6 changes: 6 additions & 0 deletions include/solvers/heat_transfer.h
Original file line number Diff line number Diff line change
@@ -410,6 +410,12 @@ class HeatTransfer : public AuxiliaryPhysics<dim, GlobalVectorType>
void
assemble_system_rhs() override;

/**
* @brief Set up preconditioner. Not used for this solver but
* needed for other physics solvers.
*/
void
setup_preconditioner() override;

/**
* @brief Assemble the local matrix for a given cell.
6 changes: 6 additions & 0 deletions include/solvers/tracer.h
Original file line number Diff line number Diff line change
@@ -299,6 +299,12 @@ class Tracer : public AuxiliaryPhysics<dim, GlobalVectorType>
void
assemble_system_rhs() override;

/**
* @brief Set up preconditioner. Not used for this solver but
* needed for other physics solvers.
*/
void
setup_preconditioner() override;

/**
* @brief Assemble the local matrix for a given cell.
6 changes: 6 additions & 0 deletions include/solvers/vof.h
Original file line number Diff line number Diff line change
@@ -443,6 +443,12 @@ class VolumeOfFluid : public AuxiliaryPhysics<dim, GlobalVectorType>
void
assemble_system_rhs() override;

/**
* @brief Set up preconditioner. Not used for this solver but
* needed for other physics solvers.
*/
void
setup_preconditioner() override;

/**
* @brief Assemble the local matrix for a given cell.
7 changes: 7 additions & 0 deletions source/core/parameters.cc
Original file line number Diff line number Diff line change
@@ -1985,6 +1985,12 @@ namespace Parameters
Patterns::Bool(),
"Reuse the last jacobian matrix for the next non-linear problem solution");

prm.declare_entry(
"reuse preconditioner",
"false",
Patterns::Bool(),
"Reuse the last preconditioner for the next non-linear problem solution");

prm.declare_entry(
"abort at convergence failure",
"false",
@@ -2040,6 +2046,7 @@ namespace Parameters
display_precision = prm.get_integer("residual precision");
force_rhs_calculation = prm.get_bool("force rhs calculation");
reuse_matrix = prm.get_bool("reuse matrix");
reuse_preconditioner = prm.get_bool("reuse preconditioner");
abort_at_convergence_failure =
prm.get_bool("abort at convergence failure");
}
5 changes: 5 additions & 0 deletions source/solvers/cahn_hilliard.cc
Original file line number Diff line number Diff line change
@@ -226,6 +226,11 @@ CahnHilliard<dim>::assemble_system_rhs()
this->system_rhs.compress(VectorOperation::add);
}

template <int dim>
void
CahnHilliard<dim>::setup_preconditioner()
{}

template <int dim>
void
CahnHilliard<dim>::assemble_local_system_rhs(
4 changes: 4 additions & 0 deletions source/solvers/gd_navier_stokes.cc
Original file line number Diff line number Diff line change
@@ -384,6 +384,10 @@ GDNavierStokesSolver<dim>::assemble_system_rhs()
this->simulation_control->provide_residual(this->system_rhs.l2_norm());
}

template <int dim>
void
GDNavierStokesSolver<dim>::setup_preconditioner()
{}

template <int dim>
void
2 changes: 1 addition & 1 deletion source/solvers/gls_navier_stokes.cc
Original file line number Diff line number Diff line change
@@ -689,7 +689,7 @@ GLSNavierStokesSolver<dim>::assemble_system_matrix()
dim>::assemble_system_matrix_without_preconditioner();

// Assemble the preconditioner
this->setup_preconditioner();
// this->setup_preconditioner();
}


5 changes: 5 additions & 0 deletions source/solvers/heat_transfer.cc
Original file line number Diff line number Diff line change
@@ -590,6 +590,11 @@ HeatTransfer<dim>::assemble_system_rhs()
assemble_nitsche_heat_restriction(false);
}

template <int dim>
void
HeatTransfer<dim>::setup_preconditioner()
{}

template <int dim>
void
HeatTransfer<dim>::assemble_local_system_rhs(
5 changes: 5 additions & 0 deletions source/solvers/tracer.cc
Original file line number Diff line number Diff line change
@@ -203,6 +203,11 @@ Tracer<dim>::assemble_system_rhs()
this->system_rhs.compress(VectorOperation::add);
}

template <int dim>
void
Tracer<dim>::setup_preconditioner()
{}

template <int dim>
void
Tracer<dim>::assemble_local_system_rhs(
5 changes: 5 additions & 0 deletions source/solvers/vof.cc
Original file line number Diff line number Diff line change
@@ -219,6 +219,11 @@ VolumeOfFluid<dim>::assemble_system_rhs()
this->system_rhs.compress(VectorOperation::add);
}

template <int dim>
void
VolumeOfFluid<dim>::setup_preconditioner()
{}

template <int dim>
void
VolumeOfFluid<dim>::assemble_local_system_rhs(