Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 61 additions & 2 deletions examples/boussinesq/skamarock_klemp_compressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from gusto import (
Domain, IO, OutputParameters, SemiImplicitQuasiNewton, SSPRK3, DGUpwind,
TrapeziumRule, SUPGOptions, Divergence, Perturbation, CourantNumber,
BoussinesqParameters, BoussinesqEquations, BoussinesqSolver,
BoussinesqParameters, BoussinesqEquations, BoussinesqSolver, LinearTimesteppingSolver,
boussinesq_hydrostatic_balance
)

Expand Down Expand Up @@ -91,7 +91,66 @@ def skamarock_klemp_compressible_bouss(
]

# Linear solver
linear_solver = BoussinesqSolver(eqns)
solver_parameters = {
'ksp_monitor_true_residual': None,
'ksp_view': ':ksp_view.log',
'ksp_error_if_not_converged': None,
'mat_type': 'matfree',
'ksp_type': 'preonly',
'pc_type': 'fieldsplit',
'pc_fieldsplit_type': 'schur',
'pc_fieldsplit_schur_fact_type': 'full',
'pc_fieldsplit_1_fields': '0,1',
'pc_fieldsplit_0_fields': '2', # eliminate temperature
'fieldsplit_theta': {
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'firedrake.AssembledPC',
'assembled_pc_type': 'bjacobi',
'assembled_sub_pc_type': 'ilu',
},
'fieldsplit_1': {
'ksp_monitor': None,
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'gusto.AuxiliaryPC',
'aux': {
'mat_type': 'matfree',
'pc_type': 'python',
'pc_python_type': 'firedrake.HybridizationPC',
'hybridization': {
'ksp_type': 'cg',
'pc_type': 'gamg',
'ksp_rtol': 1e-8,
'mg_levels': {
'ksp_type': 'chebyshev',
'ksp_max_it': 2,
'pc_type': 'bjacobi',
'sub_pc_type': 'ilu'
},
'mg_coarse': {
'ksp_type': 'preonly',
'pc_type': 'lu',
'pc_factor_mat_solver_type': 'mumps',
},
},
},
},
}

def trace_nullsp(T):
return VectorSpaceBasis(constant=True)

appctx = {
'auxform': eqns.schur_complement_form(alpha=0.5),
"trace_nullspace": trace_nullsp,
}

linear_solver = LinearTimesteppingSolver(
eqns, alpha=0.5, options_prefix="boussinesq",
solver_parameters=solver_parameters,
appctx=appctx
)

# Time stepper
stepper = SemiImplicitQuasiNewton(
Expand Down
68 changes: 64 additions & 4 deletions examples/compressible_euler/skamarock_klemp_nonhydrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
"""
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter

from petsc4py import PETSc
PETSc.Sys.popErrorHandler()
import itertools
from firedrake import (
as_vector, SpatialCoordinate, PeriodicIntervalMesh, ExtrudedMesh, exp, sin,
Function, pi, COMM_WORLD, sqrt
PETSc, Function, pi, COMM_WORLD, sqrt
)
import numpy as np
from gusto import (
Expand All @@ -28,6 +26,7 @@
compressible_hydrostatic_balance, RungeKuttaFormulation, CompressibleSolver,
hydrostatic_parameters, SubcyclingOptions,
)
PETSc.Sys.popErrorHandler()

skamarock_klemp_nonhydrostatic_defaults = {
'ncolumns': 150,
Expand Down Expand Up @@ -138,6 +137,65 @@ def skamarock_klemp_nonhydrostatic(
DGUpwind(eqns, "theta", ibp=theta_opts.ibp)
]

lu_params = {
'ksp_type': 'preonly',
'pc_type': 'lu',
'pc_factor_mat_solver_type': 'mumps',
}

gamg_params = {
'ksp_type': 'fgmres',
'ksp_rtol': 1.0e-8,
'ksp_atol': 1.0e-8,
'ksp_max_it': 100,
'pc_type': 'gamg',
'pc_gamg_sym_graph': None,
'mg_levels': {
'ksp_type': 'gmres',
'ksp_max_it': 5,
'pc_type': 'bjacobi',
'sub_pc_type': 'ilu',
},
'mg_coarse': lu_params
}

scpc_parameters = {
'mat_type': 'matfree',
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'firedrake.SCPC',
'pc_sc_eliminate_fields': '0, 1',
'condensed_field': gamg_params
}

slate_parameters = {
'mat_type': 'matfree',
'ksp_type': 'preonly',
'pc_type': 'fieldsplit',
'pc_fieldsplit_type': 'additive',
'pc_fieldsplit_type': 'schur',
'pc_fieldsplit_schur_fact_type': 'full',
'pc_fieldsplit_0_fields': '0,1',
'pc_fieldsplit_1_fields': '2',
'fieldsplit_0': {
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'firedrake.AssembledPC',
'assembled_pc_type': 'ilu',
},
'fieldsplit_1': {
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'gusto.SlateSchurPC',
'pc_slateschur_fields': 2,
'slateschur': gamg_params
},
}

solver_parameters = scpc_parameters
# solver_parameters = slate_parameters


# Linear solver
if hydrostatic:
if timestepper == 'TR-BDF2':
Expand All @@ -148,7 +206,9 @@ def skamarock_klemp_nonhydrostatic(
overwrite_solver_parameters=True
)
else:
linear_solver = CompressibleSolver(eqns)
linear_solver = CompressibleSolver(
eqns, solver_parameters=solver_parameters,
overwrite_solver_parameters=True)

# Time stepper
if timestepper == 'TR-BDF2':
Expand Down
58 changes: 56 additions & 2 deletions examples/shallow_water/linear_thermal_galewsky_jet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Domain, IO, OutputParameters, SemiImplicitQuasiNewton, DefaultTransport,
DGUpwind, ForwardEuler, ShallowWaterParameters, NumericalIntegral,
LinearThermalShallowWaterEquations, GeneralIcosahedralSphereMesh,
ZonalComponent, ThermalSWSolver, lonlatr_from_xyz, xyz_vector_from_lonlatr,
ZonalComponent, LinearTimesteppingSolver, lonlatr_from_xyz, xyz_vector_from_lonlatr,
RelativeVorticity, MeridionalComponent
)

Expand Down Expand Up @@ -84,7 +84,61 @@ def linear_thermal_galewsky_jet(
transport_methods = [DefaultTransport(eqns, "D"), DGUpwind(eqns, "b")]

# Linear solver
linear_solver = ThermalSWSolver(eqns)
solver_parameters = {
'ksp_monitor_true_residual': None,
'ksp_view': ':ksp_view.log',
'ksp_error_if_not_converged': None,
'mat_type': 'matfree',
'ksp_type': 'preonly',
'pc_type': 'fieldsplit',
'pc_fieldsplit_type': 'schur',
'pc_fieldsplit_schur_fact_type': 'full',
'pc_fieldsplit_1_fields': '0,1',
'pc_fieldsplit_0_fields': '2', # eliminate temperature
'fieldsplit_L2': {
'ksp_monitor': None,
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'firedrake.AssembledPC',
'assembled_pc_type': 'bjacobi',
'assembled_sub_pc_type': 'ilu',
},
'fieldsplit_1': {
'ksp_monitor': None,
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'gusto.AuxiliaryPC',
'aux': {
'mat_type': 'matfree',
'pc_type': 'python',
'pc_python_type': 'firedrake.HybridizationPC',
'hybridization': {
'ksp_type': 'cg',
'pc_type': 'gamg',
'ksp_rtol': 1e-8,
'mg_levels': {
'ksp_type': 'chebyshev',
'ksp_max_it': 2,
'pc_type': 'bjacobi',
'sub_pc_type': 'ilu'
},
'mg_coarse': {
'ksp_type': 'preonly',
'pc_type': 'lu',
'pc_factor_mat_solver_type': 'mumps',
},
},
},
},
}

appctx = {'auxform': eqns.schur_complement_form(alpha=0.5)}

linear_solver = LinearTimesteppingSolver(
eqns, alpha=0.5, options_prefix="swe",
solver_parameters=solver_parameters,
appctx=appctx
)

# Time stepper
stepper = SemiImplicitQuasiNewton(
Expand Down
56 changes: 53 additions & 3 deletions examples/shallow_water/moist_convective_williamson_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
"""

from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from firedrake import SpatialCoordinate, sin, cos, exp, Function
from firedrake import (
SpatialCoordinate, sin, cos, exp, Function, errornorm, norm,
VectorSpaceBasis, COMM_WORLD
)
from gusto import (
Domain, IO, OutputParameters, SemiImplicitQuasiNewton, SSPRK3, DGUpwind,
TrapeziumRule, ShallowWaterParameters, ShallowWaterEquations,
ZonalComponent, MeridionalComponent, SteadyStateError, lonlatr_from_xyz,
DG1Limiter, InstantRain, MoistConvectiveSWSolver, ForwardEuler,
DG1Limiter, InstantRain, ForwardEuler, LinearTimesteppingSolver,
RelativeVorticity, SWSaturationAdjustment, WaterVapour, CloudWater, Rain,
GeneralIcosahedralSphereMesh, xyz_vector_from_lonlatr
)
Expand Down Expand Up @@ -127,7 +130,46 @@ def sat_func(x_in):
SSPRK3(domain, "rain", limiter=limiter)
]

linear_solver = MoistConvectiveSWSolver(eqns)
solver_parameters = {
'mat_type': 'matfree',
'ksp_type': 'preonly',
"pc_type": "fieldsplit",
"pc_fieldsplit_type": "additive",
"pc_fieldsplit_0_fields": "0,1", # (u, D)
"pc_fieldsplit_1_fields": "2,3,4", # (scalars,)
"fieldsplit_0": { # hybridisation on the (u,D) system
'ksp_monitor_true_residual': None,
'ksp_type': 'preonly',
'pc_type': 'python',
'pc_python_type': 'firedrake.HybridizationPC',
'hybridization': {
'ksp_type': 'cg',
'pc_type': 'gamg',
'ksp_rtol': 1e-8,
'mg_levels': {
'ksp_type': 'chebyshev',
'ksp_max_it': 2,
'pc_type': 'bjacobi',
'sub_pc_type': 'ilu'
}
}
},
"fieldsplit_1": { # Don't touch the transported fields
"ksp_type": "preonly",
"pc_type": "none"
},
}

# Provide callback for the nullspace of the trace system
def trace_nullsp(T):
return VectorSpaceBasis(constant=True, comm=COMM_WORLD)
appctx = {"trace_nullspace": trace_nullsp}

linear_solver = LinearTimesteppingSolver(
eqns, alpha=0.5,
reference_dependent=True,
solver_parameters=solver_parameters,
options_prefix="swe", appctx=appctx)

# Physics schemes
sat_adj = SWSaturationAdjustment(
Expand Down Expand Up @@ -158,6 +200,8 @@ def sat_func(x_in):
D0 = stepper.fields("D")
v0 = stepper.fields("water_vapour")

D_init = Function(D0.function_space())

uexpr = xyz_vector_from_lonlatr(u_max*cos(phi), 0, 0, (x, y, z))
g = parameters.g
w = Omega*radius*u_max + (u_max**2)/2
Expand All @@ -184,6 +228,8 @@ def sat_func(x_in):
D0.interpolate(Dexpr)
v0.interpolate(vexpr)

D_init.interpolate(Dexpr)

# Set reference profiles
Dbar = Function(D0.function_space()).assign(mean_depth)
stepper.set_reference_profiles([('D', Dbar)])
Expand All @@ -194,6 +240,10 @@ def sat_func(x_in):

stepper.run(t=0, tmax=tmax)

error_D = errornorm(D0, D_init, mesh=mesh)/norm(D_init, mesh=mesh)

print("Error D:", error_D)

# ---------------------------------------------------------------------------- #
# MAIN
# ---------------------------------------------------------------------------- #
Expand Down
Loading
Loading