dougshidong / PHiLiP

Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
Other
45 stars 36 forks source link

Jacobian-free Newton-Krylov implicit solver for diagonally-implicit RK schemes #169

Closed cpethrick closed 1 year ago

cpethrick commented 2 years ago

PR for introducing implicit RK using Jacobian-free Newton-Krylov (JFNK) for the implicit solver. JFNK can be quite fast as no Jacobian matrix needs to be stored. Rather, the Jacobian-vector product which arises during Newton iterations is approximated on-the-fly using finite differences. The absence of a Jacobian implies that automatic differentiation is not required. In the scope of this PR, there will be no preconditioner used.

This PR has also improved the RK ODE solver to use better object-oriented programming practices.

Changes related to JFNK:

Other changes to clean up RungeKuttaODESolver:

cpethrick commented 2 years ago

I added the "c" part of the butcher tableau to all of the RK methods. This is unused in the current RK solver, but I have added it because PR #111 uses it for some unsteady manufactured solutions.

cpethrick commented 1 year ago

In the development of this PR, I also tested implicit RK using the AD-based linear solver already implemented in PHiLiP. I thought it would be interesting to compare the two now that JFNK is functioning well. I modified runge_kutta_ode_solver.cpp (see attachment) such that I could compare AD to JFNK for the test 1D_TIME_REFINEMENT_STUDY_ADVECTION_IMPLICIT. A summary of the comparison is as follows:

I've attached the modified runge_kutta_ode_solver.cpp which uses AD, the .prm file with reduced initial timestep, as well as the full output of 1D_TIME_REFINEMENT_STUDY_ADVECTION_IMPLICIT using AD and JFNK.

runge_kutta_ode_solver_ADversion.cpp.txt time_refinement_study_advection_implicit.prm.txt time_refinement_study_advection_implicit_AD_convergence.txt time_refinement_study_advection_implicit_JFNK_convergence.txt

dougshidong commented 1 year ago

Nice analysis.

As a side note, you can assemble the matrix-vector product using AD such that it becomes a JFNM. The real comparison is AD vs Fréchet FD.

As you mentioned both have opportunities for code optimization to speed them up. The real saving we're obtaining is the memory usage as we get to higher and higher orders.

cpethrick commented 1 year ago

I was discussing with @jbrillon how to best set up this PR for compatibility with PR #111. We decided that it would be easiest to rename the files runge_kutta_ode_solver.<cpp/h> back to explicit_ode_solver.<cpp/h> such that GIT recognizes it as the same file. The parameter names, etc. are unchanged from previous commits. I have opened an issue (#174) to change the names to runge_kutta_ode_solver.<cpp/h> once #111 has been merged into master.

dougshidong commented 1 year ago

What's left for this PR to be merged?

cpethrick commented 1 year ago

@dougshidong It should be ready to merge soon (within a week, I would guess). @jbrillon was going to do a final review in the coming days. I have confirmed that ctest behaves the same as before, and the time taken for explicit timestepping has not changed.