Skip to content

Commit df6fdbc

Browse files
atb1995JHopeCollins
authored andcommitted
Add in riesz map and remove pc update (#713)
Co-authored-by: Josh Hope-Collins <joshua.hope-collins13@imperial.ac.uk>
1 parent 1fc9407 commit df6fdbc

11 files changed

Lines changed: 78 additions & 52 deletions

gusto/solvers/preconditioners.py

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from firedrake import (dot, jump, dS_h, ds_b, ds_t, ds,
44
FacetNormal, Tensor, AssembledVector,
5-
AuxiliaryOperatorPC, PETSc)
5+
AuxiliaryOperatorPC, PETSc, RieszMap)
66

77
from firedrake.preconditioners import PCBase
88
from firedrake.matrix_free.operators import ImplicitMatrixContext
@@ -460,35 +460,6 @@ class CompressibleHybridisedSCPC(PCBase):
460460

461461
_prefix = "compressible_hybrid_scpc"
462462

463-
scpc_parameters = {
464-
'mat_type': 'matfree',
465-
'ksp_type': 'preonly',
466-
'pc_type': 'python',
467-
'pc_python_type': 'firedrake.SCPC',
468-
'pc_sc_eliminate_fields': '0, 1',
469-
# The reduced operator is not symmetric
470-
'condensed_field': {
471-
'ksp_type': 'fgmres',
472-
'ksp_rtol': 1.0e-8,
473-
'ksp_atol': 1.0e-8,
474-
'ksp_max_it': 100,
475-
'pc_type': 'gamg',
476-
'pc_gamg_sym_graph': None,
477-
'mg_levels': {
478-
'ksp_type': 'gmres',
479-
'ksp_max_it': 5,
480-
'pc_type': 'bjacobi',
481-
'sub_pc_type': 'ilu'
482-
}
483-
}
484-
}
485-
486-
cg_ilu_parameters = {
487-
'ksp_type': 'cg',
488-
'pc_type': 'bjacobi',
489-
'sub_pc_type': 'ilu'
490-
}
491-
492463
def initialize(self, pc):
493464
"""
494465
Set up problem and solver
@@ -507,15 +478,14 @@ def initialize(self, pc):
507478
raise ValueError("Expecting PC type python")
508479

509480
self._process_context(pc)
481+
prefix = pc.getOptionsPrefix()
510482

511-
self.hybridised_scpc_parameters = self.scpc_parameters
512-
self.rho_avg_solver_parameters = self.cg_ilu_parameters
513-
self.theta_solver_parameters = self.cg_ilu_parameters
514-
self.exner_avg_solver_parameters = self.cg_ilu_parameters
483+
# Unpack sub-solver parameters from the options prefix
484+
self.riesz_map_parameters = PETSc.Options(prefix + "riesz_map_").getAll()
515485

516486
if logger.isEnabledFor(DEBUG):
517-
self.hybridised_scpc_parameters['ksp_monitor_true_residual'] = None
518-
self.hybridised_scpc_parameters['ksp_converged_reason'] = None
487+
self.scpc_solve_parameters['ksp_monitor_true_residual'] = None
488+
self.scpc_solve_parameters['ksp_converged_reason'] = None
519489

520490
# Equations and parameters
521491
equations = self.equations
@@ -548,6 +518,11 @@ def initialize(self, pc):
548518
self.xrhs = Function(self.W)
549519
self.y = Function(self.W)
550520

521+
# Riesz map for the dual of the original function space
522+
self.riesz_map = RieszMap(self.W.dual(),
523+
solver_parameters=self.riesz_map_parameters,
524+
constant_jacobian=True)
525+
551526
self.y_hybrid = Function(self.W_hyb)
552527

553528
# Split input functions
@@ -632,12 +607,12 @@ def L_tr(f):
632607
constant_jacobian=True)
633608

634609
self.rho_avg_solver = LinearVariationalSolver(
635-
rho_avg_prb, solver_parameters=self.rho_avg_solver_parameters,
636-
options_prefix=pc.getOptionsPrefix()+'rhobar_avg_solver'
610+
rho_avg_prb,
611+
options_prefix=pc.getOptionsPrefix()+'rhobar_avg'
637612
)
638613
self.exner_avg_solver = LinearVariationalSolver(
639-
exner_avg_prb, solver_parameters=self.exner_avg_solver_parameters,
640-
options_prefix=pc.getOptionsPrefix()+'exnerbar_avg_solver'
614+
exner_avg_prb,
615+
options_prefix=pc.getOptionsPrefix()+'exnerbar_avg'
641616
)
642617

643618
# "broken" u, rho, and trace system
@@ -691,8 +666,9 @@ def L_tr(f):
691666
aeqn, Leqn, self.y_hybrid, constant_jacobian=True
692667
)
693668
self.hybridized_solver = LinearVariationalSolver(
694-
hybridized_prb, solver_parameters=self.hybridised_scpc_parameters,
695-
options_prefix=pc.getOptionsPrefix()+self._prefix, appctx=appctx
669+
hybridized_prb,
670+
options_prefix=pc.getOptionsPrefix()+self._prefix,
671+
appctx=appctx
696672
)
697673

698674
if logger.isEnabledFor(DEBUG):
@@ -725,8 +701,8 @@ def L_tr(f):
725701
)
726702

727703
self.theta_solver = LinearVariationalSolver(
728-
theta_problem, solver_parameters=self.theta_solver_parameters,
729-
options_prefix=pc.getOptionsPrefix()+'thetabacksubstitution'
704+
theta_problem,
705+
options_prefix=pc.getOptionsPrefix()+'theta_backsub'
730706
)
731707

732708
if logger.isEnabledFor(DEBUG):
@@ -753,7 +729,7 @@ def apply(self, pc, x, y):
753729
with self.xstar.dat.vec_wo as xv:
754730
x.copy(xv)
755731

756-
self.xrhs.assign(self.xstar.riesz_representation())
732+
self.xrhs.assign(self.riesz_map(self.xstar))
757733
# Solve hybridized system
758734
self.hybridized_solver.solve()
759735

gusto/solvers/solver_presets.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,69 @@ def trace_nullsp(T):
6767
# Compressible Euler equations - (u, rho, theta) system. We use a
6868
# bespoke hybridization preconditioner for this system owing to the
6969
# nonlinear pressure gradient term.
70+
r_tol = 1e-8
71+
72+
theta_backsub_settings = {
73+
'ksp_type': 'cg',
74+
'pc_type': 'bjacobi',
75+
'sub_pc_type': 'ilu',
76+
'ksp_rtol': r_tol
77+
}
78+
79+
exnerbar_avg_settings = {
80+
'ksp_type': 'cg',
81+
'pc_type': 'bjacobi',
82+
'sub_pc_type': 'ilu',
83+
'ksp_rtol': r_tol
84+
}
85+
86+
rhobar_avg_settings = {
87+
'ksp_type': 'cg',
88+
'pc_type': 'bjacobi',
89+
'sub_pc_type': 'ilu',
90+
'ksp_rtol': r_tol
91+
}
92+
93+
riesz_map_settings = {
94+
'ksp_type': 'cg',
95+
'pc_type': 'bjacobi',
96+
'sub_pc_type': 'ilu',
97+
'ksp_rtol': r_tol
98+
}
99+
100+
scpc_solve_settings = {
101+
'mat_type': 'matfree',
102+
'ksp_type': 'preonly',
103+
'pc_type': 'python',
104+
'pc_python_type': 'firedrake.SCPC',
105+
'pc_sc_eliminate_fields': '0,1',
106+
# The reduced operator is not symmetric
107+
'condensed_field': {
108+
'ksp_type': 'fgmres',
109+
'ksp_rtol': r_tol,
110+
'ksp_max_it': 100,
111+
'pc_type': 'gamg',
112+
'pc_gamg_sym_graph': None,
113+
'mg_levels': {
114+
'ksp_type': 'gmres',
115+
'ksp_max_it': 5,
116+
'pc_type': 'bjacobi',
117+
'sub_pc_type': 'ilu'
118+
}
119+
}
120+
}
121+
70122
settings = {
71123
'ksp_monitor': None,
72124
'ksp_type': 'preonly',
73125
'mat_type': 'matfree',
74126
'pc_type': 'python',
75127
'pc_python_type': 'gusto.CompressibleHybridisedSCPC',
128+
'theta_backsub': theta_backsub_settings,
129+
'exnerbar_avg': exnerbar_avg_settings,
130+
'rhobar_avg': rhobar_avg_settings,
131+
'riesz_map': riesz_map_settings,
132+
'compressible_hybrid_scpc': scpc_solve_settings,
76133
}
77134

78135
# We pass the implicit weighting parameter (alpha) and tau_values to the

gusto/timestepping/semi_implicit_quasi_newton.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from gusto.time_discretisation.time_discretisation import ExplicitTimeDiscretisation
2121
from gusto.timestepping.timestepper import BaseTimestepper
2222
from gusto.solvers.solver_presets import hybridised_solver_parameters
23-
from gusto.equations.compressible_euler_equations import CompressibleEulerEquations
2423

2524

2625
__all__ = ["SemiImplicitQuasiNewton", "Forcing", "QuasiNewtonLinearSolver"]
@@ -937,12 +936,6 @@ def update_reference_profiles(self):
937936
self.equation.update_reference_profiles()
938937
self.solver.invalidate_jacobian()
939938

940-
# TODO: Issue #686 is to address this reference profile update bug (pythonPC update not called)
941-
# this line forces it to update for now
942-
pc = self.solver.snes.getKSP().getPC()
943-
if (isinstance(self.equation, CompressibleEulerEquations) and pc.getType() == "python"):
944-
pc.getPythonContext().update(pc)
945-
946939
def zero_non_prognostics(self, equation, xrhs, field_names, prognostic_names):
947940
"""
948941
Zero rhs term F(x) for non-prognostics.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)