Stokes integrators
stokes_integrators
Solver classes targetting systems dealing with momentum conservation.
This module provides a fine-tuned abstract base class, StokesSolverBase, from which
efficient numerical solvers can be derived, such as StokesSolver for the Stokes system
of conservation equations and ViscoelasticStokesSolver for an incremental displacement
formulation of the latter using a Maxwell rheology. The module also exposes a function,
create_stokes_nullspace, to automatically generate null spaces compatible with PETSc
solvers and a class, BoundaryNormalStressSolver, to solve for the normal stress acting
on a domain boundary. Typically, users instantiate the StokesSolver class by providing
a relevant set of arguments and then call the solve method to request a solver update.
iterative_stokes_solver_parameters = {'mat_type': 'matfree', 'ksp_type': 'preonly', 'pc_type': 'fieldsplit', 'pc_fieldsplit_type': 'schur', 'pc_fieldsplit_schur_type': 'full', 'fieldsplit_0': {'ksp_type': 'cg', 'ksp_rtol': 1e-05, 'ksp_max_it': 1000, 'pc_type': 'python', 'pc_python_type': 'gadopt.SPDAssembledPC', 'assembled_pc_type': 'gamg', 'assembled_mg_levels_pc_type': 'sor', 'assembled_pc_gamg_threshold': 0.01, 'assembled_pc_gamg_square_graph': 100, 'assembled_pc_gamg_coarse_eq_limit': 1000, 'assembled_pc_gamg_mis_k_minimum_degree_ordering': True}, 'fieldsplit_1': {'ksp_type': 'fgmres', 'ksp_rtol': 0.0001, 'ksp_max_it': 200, 'pc_type': 'python', 'pc_python_type': 'firedrake.MassInvPC', 'Mp_pc_type': 'ksp', 'Mp_ksp_ksp_rtol': 1e-05, 'Mp_ksp_ksp_type': 'cg', 'Mp_ksp_pc_type': 'sor'}}
module-attribute
Default iterative solver parameters for solution of Stokes system.
We configure the Schur complement approach as described in Section of 4.3 of Davies et al. (2022), using PETSc's fieldsplit preconditioner type, which provides a class of preconditioners for mixed problems that allows a user to apply different preconditioners to different blocks of the system.
The fieldsplit_0 entries configure solver options for the velocity block. The linear
systems associated with this matrix are solved using a combination of the Conjugate
Gradient (cg) method and an algebraic multigrid preconditioner (gamg).
The fieldsplit_1 entries contain solver options for the Schur complement solve itself.
For preconditioning, we approximate the Schur complement matrix with a mass matrix
scaled by viscosity, with the viscosity sourced from the approximation object provided
to Stokes solver. Since this preconditioner step involves an iterative solve, the Krylov
method used for the Schur complement needs to be of flexible type, and we use the
Flexible Generalized Minimal Residual (fgmres) method by default.
Note
G-ADOPT will use the above default iterative solver parameters if the argument
solver_parameters="iterative" is provided or in 3-D if the solver_parameters
argument is omitted. To make modifications to these default values, the most
convenient approach is to provide the modified values as a dictionary via the
solver_parameters_extra argument. This dictionary can also hold new pairs of keys
and values to extend the default ones.
.
direct_stokes_solver_parameters = {'mat_type': 'aij', 'ksp_type': 'preonly', 'pc_type': 'lu', 'pc_factor_mat_solver_type': 'mumps'}
module-attribute
Default direct solver parameters for solution of Stokes system.
We configure the direct solver to use the LU (lu) factorisation provided by the MUMPS
package.
Note
G-ADOPT will use the above default direct solver parameters if the argument
solver_parameters="direct" is provided or in 2-D if the solver_parameters
argument is omitted. To make modifications to these default values, the most
convenient approach is to provide the modified values as a dictionary via the
solver_parameters_extra argument. This dictionary can also hold new pairs of keys
and values to extend the default ones.
newton_stokes_solver_parameters = {'snes_type': 'newtonls', 'snes_linesearch_type': 'l2', 'snes_max_it': 100, 'snes_atol': 1e-10, 'snes_rtol': 1e-05}
module-attribute
Default non-linear solver parameters for solution of Stokes system.
We use a setup based on Newton's method (newtonls) with a secant line search over the L2-norm of the function.
Note
G-ADOPT will use the above default non-linear solver parameters in conjunction with
the above iterative or default solver parameters if the viscosity, mu, provided to
the approximation depends on the solver's solution. To make modifications to these
default values, the most convenient approach is to provide the modified values as a
dictionary via the solver_parameters_extra argument. This dictionary can also hold
new pairs of keys and values to extend the default ones.
coupled_gia_solver_parameters = {'mat_type': 'matfree', 'snes_type': 'newtonls', 'snes_linesearch_type': 'l2', 'snes_max_it': 100, 'snes_atol': 1e-15, 'snes_rtol': 0.0001, 'ksp_type': 'gmres', 'ksp_rtol': 0.001, 'pc_type': 'fieldsplit', 'pc_fieldsplit_type': 'symmetric_multiplicative', 'fieldsplit_0_ksp_type': 'cg', 'fieldsplit_0_pc_type': 'python', 'fieldsplit_0_pc_python_type': 'gadopt.SPDAssembledPC', 'fieldsplit_0_assembled_pc_type': 'gamg', 'fieldsplit_0_assembled_mg_levels_pc_type': 'sor', 'fieldsplit_0_ksp_rtol': 1e-05, 'fieldsplit_0_assembled_pc_gamg_threshold': 0.01, 'fieldsplit_0_assembled_pc_gamg_square_graph': 100, 'fieldsplit_0_assembled_pc_gamg_coarse_eq_limit': 1000, 'fieldsplit_0_assembled_pc_gamg_mis_k_minimum_degree_ordering': True, 'fieldsplit_1_ksp_type': 'cg', 'fieldsplit_1_pc_type': 'python', 'fieldsplit_1_pc_python_type': 'firedrake.AssembledPC', 'fieldsplit_1_assembled_pc_type': 'sor', 'fieldsplit_1_ksp_rtol': 1e-05}
module-attribute
Default iterative solver parameters for CoupledInternalVariableSolver (GIA problems).
Uses a Newton SNES outer loop with a GMRES/fieldsplit preconditioned inner solve. SNES is always active: for a Newtonian rheology (exponent=1) the power-law factor is identically 1 and the system is linear, so SNES converges in a single iteration at negligible extra cost. For power-law rheology (exponent > 1) the full Newton iteration is required. The snes_rtol is set looser than ksp_rtol so that the single-iteration Newtonian case is accepted without additional SNES iterations.
StokesSolverBase(solution, approximation, /, *, dt=None, theta=0.5, additional_forcing_term=None, bcs={}, quad_degree=6, solver_parameters=None, solver_parameters_extra=None, J=None, constant_jacobian=False, nullspace=None, transpose_nullspace=None, near_nullspace=None)
Bases: SolverConfigurationMixin, ABC
Solver for a system involving mass and momentum conservation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function representing the field over the mixed Stokes space |
required |
approximation
|
BaseApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
dt
|
float | None
|
Float specifying the time step if the system involves a coupled time integration |
None
|
theta
|
float
|
Float defining the theta scheme parameter used in a coupled time integration |
0.5
|
additional_forcing_term
|
Form | None
|
Firedrake form specifying an additional term contributing to the residual |
None
|
bcs
|
dict[int | str, dict[str, Any]]
|
Dictionary specifying boundary conditions (identifier, type, and value) |
{}
|
quad_degree
|
int
|
Integer denoting the quadrature degree |
6
|
solver_parameters
|
ConfigType | str | None
|
Dictionary of PETSc solver options or string matching one of the default sets |
None
|
solver_parameters_extra
|
ConfigType | None
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
None
|
J
|
Function | None
|
Firedrake function representing the Jacobian of the mixed Stokes system |
None
|
constant_jacobian
|
bool
|
Boolean specifying whether the Jacobian of the system is constant |
False
|
nullspace
|
MixedVectorSpaceBasis | None
|
A |
None
|
transpose_nullspace
|
MixedVectorSpaceBasis | None
|
A |
None
|
near_nullspace
|
MixedVectorSpaceBasis | None
|
A |
None
|
Valid keys for boundary conditions
| Condition | Type | Description |
|---|---|---|
| u | Strong | Solution |
| ux | Strong | Solution along the first Cartesian axis |
| uy | Strong | Solution along the second Cartesian axis |
| uz | Strong | Solution along the third Cartesian axis |
| un | Weak | Solution along the normal to the boundary |
| stress | Weak | Traction across the boundary |
| normal_stress | Weak | Stress component normal to the boundary |
| free_surface | Weak | Free-surface characteristics of the boundary |
Valid keys describing the free surface boundary
| Argument | Required | Description |
|---|---|---|
| delta_rho_fs | Yes (d) | Density contrast along the free surface |
| RaFS | Yes (nd) | Rayleigh number (free-surface density contrast) |
| variable_rho_fs | No | Account for buoyancy effects on interior density |
Classic theta values for coupled implicit time integration
| Theta | Scheme |
|---|---|
| 0.5 | Crank-Nicolson method |
| 1.0 | Backward Euler method |
Note: Such a coupling can arise in the case of a free-surface implementation.
Source code in g-adopt/gadopt/stokes_integrators.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
set_boundary_conditions()
Sets strong and weak boundary conditions.
Source code in g-adopt/gadopt/stokes_integrators.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
set_free_surface_boundary(params_fs, bc_id)
Sets the given boundary as a free surface.
This method calculates the normal stress at the free surface boundary. In the
coupled approach, it also sets a zero-interior strong condition away from that
boundary and populates the free_surface_map dictionary used to calculate the
free-surface contribution to the momentum weak form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params_fs
|
dict[str, int | bool]
|
Dictionary holding information about the free surface boundary |
required |
bc_id
|
int | str
|
Integer representing the index of the mesh boundary |
required |
Returns:
| Type | Description |
|---|---|
Expr
|
UFL expression for the normal stress at the free surface boundary |
Source code in g-adopt/gadopt/stokes_integrators.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
set_equations()
abstractmethod
Sets Equation instances for each equation in the system.
Equations must be ordered like solutions in the mixed space.
Source code in g-adopt/gadopt/stokes_integrators.py
363 364 365 366 367 368 | |
set_form()
Sets the weak form including linear and bilinear terms.
Source code in g-adopt/gadopt/stokes_integrators.py
370 371 372 373 374 | |
set_solver_options(solver_preset, solver_extras)
Sets PETSc solver options.
Source code in g-adopt/gadopt/stokes_integrators.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
set_solver()
Sets up the Firedrake variational problem and solver.
Source code in g-adopt/gadopt/stokes_integrators.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
solve()
Solves the system.
Source code in g-adopt/gadopt/stokes_integrators.py
469 470 471 472 | |
StokesSolver(solution, approximation, T=0.0, /, **kwargs)
Bases: StokesSolverBase
Solver for the Stokes system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function representing the field over the mixed Stokes space |
required |
approximation
|
BaseApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
T
|
Function | float
|
Firedrake function representing the temperature field |
0.0
|
dt
|
Float quantifying the time step used in a coupled time integration |
required | |
theta
|
Float quantifying the implicit contribution in a coupled time integration |
required | |
additional_forcing_term
|
Firedrake form specifying an additional term contributing to the residual |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
quad_degree
|
Integer denoting the quadrature degree |
required | |
solver_parameters
|
Dictionary of PETSc solver options or string matching one of the default sets |
required | |
solver_parameters_extra
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
required | |
J
|
Firedrake function representing the Jacobian of the mixed Stokes system |
required | |
constant_jacobian
|
Boolean specifying whether the Jacobian of the system is constant |
required | |
nullspace
|
A |
required | |
transpose_nullspace
|
A |
required | |
near_nullspace
|
A |
required |
Source code in g-adopt/gadopt/stokes_integrators.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
force_on_boundary(subdomain_id, **kwargs)
Computes the force acting on a boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdomain_id
|
int | str
|
The subdomain ID of a physical boundary. |
required |
Returns:
| Type | Description |
|---|---|
Function
|
The force acting on the boundary. |
Source code in g-adopt/gadopt/stokes_integrators.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
ViscoelasticStokesSolver(solution, approximation, stress_old, displacement, /, *, dt, **kwargs)
Bases: StokesSolverBase
Solves the Stokes system assuming an incompressible Maxwell viscoelastic rheology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function representing the field over the mixed Stokes space |
required |
approximation
|
BaseGIAApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
stress_old
|
Function
|
Firedrake function representing the deviatoric stress at the previous time step |
required |
displacement
|
Function
|
Firedrake function representing the total displacement |
required |
dt
|
float
|
Float quantifying the time step used in a coupled time integration |
required |
theta
|
Float quantifying the implicit contribution in a coupled time integration |
required | |
additional_forcing_term
|
Firedrake form specifying an additional term contributing to the residual |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
quad_degree
|
Integer denoting the quadrature degree |
required | |
solver_parameters
|
Dictionary of PETSc solver options or string matching one of the default sets |
required | |
solver_parameters_extra
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
required | |
J
|
Firedrake function representing the Jacobian of the mixed Stokes system |
required | |
constant_jacobian
|
Boolean specifying whether the Jacobian of the system is constant |
required | |
nullspace
|
A |
required | |
transpose_nullspace
|
A |
required | |
near_nullspace
|
A |
required |
Source code in g-adopt/gadopt/stokes_integrators.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
set_equations()
Sets up UFL forms for the viscoelastic Stokes equations residual.
Source code in g-adopt/gadopt/stokes_integrators.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
InternalVariableSolver(solution, approximation, /, *, internal_variables, dt, **kwargs)
Bases: StokesSolverBase
Solver for internal variable viscoelastic formulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function representing the displacement solution |
required |
approximation
|
BaseGIAApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
internal_variables
|
Function | list[Function]
|
Internal variable functions accounting for viscoelastic stress relaxation. The number of internal variables provided must be consistent with the number of viscosity and shear modulus fields provided to the approximation. |
required |
dt
|
float
|
Float quantifying the time step used for time integration |
required |
additional_forcing_term
|
Firedrake form specifying an additional term contributing to the residual |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
quad_degree
|
Integer denoting the quadrature degree |
required | |
solver_parameters
|
Dictionary of PETSc solver options or string matching one of the default sets |
required | |
solver_parameters_extra
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
required | |
J
|
Firedrake function representing the Jacobian of the mixed Stokes system |
required | |
constant_jacobian
|
Boolean specifying whether the Jacobian of the system is constant |
required | |
nullspace
|
A |
required | |
transpose_nullspace
|
A |
required | |
near_nullspace
|
A |
required |
Source code in g-adopt/gadopt/stokes_integrators.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |
update_m(m, maxwell_time)
Calculates updated internal variable using Backward Euler formula
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
Function
|
Firedrake function representing the current value of the internal variable |
required |
maxwell_time
|
Function | Expr
|
Firedrake function or UFL expression for Maxwell time associated with m terms in the system of equations |
required |
Returns:
| Type | Description |
|---|---|
Expr
|
UFL expression for the updated internal variable using Backward Euler |
Source code in g-adopt/gadopt/stokes_integrators.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
CoupledInternalVariableSolver(solution, approximation, /, *, dt, scaling_factor=1, **kwargs)
Bases: StokesSolverBase
Solver for coupled internal variable viscoelastic formulation.
Solves the momentum equation and internal variable evolution equations simultaneously as a single coupled nonlinear variational problem.
The internal variable evolution equation is:
dm/dt = deviatoric_strain(u)/tau - m/tau
discretised using backward Euler:
(m_new - m_old)/dt + m_new/tau - deviatoric_strain(u_new)/tau = 0
Only backward Euler time-stepping is currently implemented. Both the strain rate and the internal variable m are evaluated at the new time level, which is consistent with a fully implicit (backward Euler) discretisation. A proper theta scheme would require theta-weighting of both the strain rate and the sink term. In the future, this should be unified with Irksome, either by using Irksome directly or by using Irksome's Dt operator together with expand_time_derivatives and UFL replace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function representing the field over the mixed space (displacement and internal variables) |
required |
approximation
|
BaseGIAApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
dt
|
float
|
Float quantifying the time step used for time integration |
required |
scaling_factor
|
float
|
A constant factor used to rescale residual terms. |
1
|
additional_forcing_term
|
Firedrake form specifying an additional term contributing to the residual |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
quad_degree
|
Integer denoting the quadrature degree |
required | |
solver_parameters
|
Dictionary of PETSc solver options or string matching one of the default sets |
required | |
solver_parameters_extra
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
required | |
J
|
Firedrake function representing the Jacobian of the mixed Stokes system |
required | |
constant_jacobian
|
Boolean specifying whether the Jacobian of the system is constant |
required | |
nullspace
|
A |
required | |
transpose_nullspace
|
A |
required | |
near_nullspace
|
A |
required |
Source code in g-adopt/gadopt/stokes_integrators.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | |
set_solver_options(solver_preset, solver_extras)
Sets PETSc solver options for the coupled GIA system.
Overrides the base class to ensure SNES Newton is always active. For Newtonian rheology (exponent=1) the power-law factor is identically 1 and the system is linear, so SNES converges in a single iteration. For power-law rheology (exponent > 1) full Newton iteration is performed.
When solver_preset is a Mapping it is honoured verbatim. The string preset "direct" uses direct_stokes_solver_parameters plus Newton SNES. The string preset "iterative" and the default None both use coupled_gia_solver_parameters, which already includes Newton SNES and the GIA-specific fieldsplit preconditioner. iterative_stokes_solver_parameters is intentionally not used here: its Schur-complement structure is designed for the standard Stokes system, not the larger coupled GIA block.
Source code in g-adopt/gadopt/stokes_integrators.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | |
BoundaryNormalStressSolver(stokes_solver, subdomain_id, **kwargs)
Bases: SolverConfigurationMixin
A class for calculating surface forces acting on a boundary.
This solver computes topography on boundaries using the equation:
where \(sigma_(rr)\) is defined as:
Instead of assuming a unit normal vector \(hat n\), this solver uses FacetNormal
from Firedrake to accurately determine the normal vectors, which is particularly
useful for complex meshes like icosahedron meshes in spherical simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stokes_solver
|
StokesSolver
|
The Stokes solver providing the necessary fields for calculating stress. |
required |
subdomain_id
|
str | int
|
The subdomain ID of a physical boundary. |
required |
**kwargs
|
Optional keyword arguments. You can provide: - solver_parameters (dict[str, str | float]): Parameters to control the variational solver. If not provided, defaults are chosen based on whether the Stokes solver is direct or iterative. - solver_parameters_extra: Dictionary of PETSc solver options used to update the default solver options. If not provided, defaults to None (i.e. do not modify default settings) |
{}
|
Source code in g-adopt/gadopt/stokes_integrators.py
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
solve()
Solves a linear system for the force and applies necessary boundary conditions.
Returns:
| Type | Description |
|---|---|
|
The modified force after solving the linear system and applying boundary conditions. |
Source code in g-adopt/gadopt/stokes_integrators.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | |