Transport solver
transport_solver
This module provides a minimal solver, independent of any approximation, for generic
transport equations, which may include advection, diffusion, sink, and source terms, and
a fine-tuned solver class for the energy conservation equation. Users instantiate the
GenericTransportSolver or EnergySolver classes by providing the appropriate
documented parameters and call the solve method to request a solver update.
iterative_energy_solver_parameters = {'mat_type': 'aij', 'snes_type': 'ksponly', 'ksp_type': 'gmres', 'ksp_rtol': 1e-05, 'pc_type': 'sor'}
module-attribute
Default iterative solver parameters for solution of energy equation.
Configured to use the GMRES Krylov scheme with Successive Over Relaxation (SOR) preconditioning. Note that default energy solver parameters can be augmented or adjusted by accessing the solver_parameter dictionary.
Examples:
>>> energy_solver.solver_parameters['ksp_converged_reason'] = None
>>> energy_solver.solver_parameters['ksp_rtol'] = 1e-4
Note
G-ADOPT defaults to iterative solvers in 3-D.
direct_energy_solver_parameters = {'mat_type': 'aij', 'snes_type': 'ksponly', 'ksp_type': 'preonly', 'pc_type': 'lu', 'pc_factor_mat_solver_type': 'mumps'}
module-attribute
Default direct solver parameters for solution of energy equation.
Configured to use LU factorisation performed via the MUMPS library.
Note
G-ADOPT defaults to direct solvers in 2-D.
GenericTransportBase(solution, /, delta_t, timestepper, *, solution_old=None, eq_attrs={}, bcs={}, solver_parameters=None, solver_parameters_extra=None, timestepper_kwargs=None, su_advection=False)
Bases: SolverConfigurationMixin, ABC
Base class for advancing a generic transport equation in time.
All combinations of advection, diffusion, sink, and source terms are handled.
Note: The solution field is updated in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function for the field of interest |
required |
delta_t
|
Constant
|
Simulation time step |
required |
timestepper
|
IrksomeIntegrator
|
Runge-Kutta time integrator employing an explicit or implicit numerical scheme |
required |
solution_old
|
Function | None
|
Firedrake function holding the solution field at the previous time step |
None
|
eq_attrs
|
dict[str, float]
|
Dictionary of terms arguments and their values |
{}
|
bcs
|
dict[int, dict[str, Number]]
|
Dictionary specifying boundary conditions (identifier, type, and value) |
{}
|
solver_parameters
|
ConfigType | str | None
|
Dictionary of solver parameters or a string specifying a default configuration provided to PETSc |
None
|
solver_parameters_extra
|
ConfigType | None
|
Dictionary of PETSc solver options used to update the default G-ADOPT options |
None
|
timestepper_kwargs
|
dict[str, Any] | None
|
Dictionary of additional keyword arguments passed to the timestepper constructor. Useful for parameterised schemes (e.g., {'order': 5} for IrksomeRadauIIA) |
None
|
su_advection
|
bool
|
Boolean activating the streamline-upwind stabilisation scheme when using continuous finite elements |
False
|
Source code in g-adopt/gadopt/transport_solver.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
set_boundary_conditions()
Sets up boundary conditions.
Source code in g-adopt/gadopt/transport_solver.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
set_su_nubar()
Sets up the advection streamline-upwind scheme (Donea & Huerta, 2003).
Columns of Jacobian J are the vectors that span the quad/hex and can be seen as unit vectors scaled with the dx/dy/dz in that direction (assuming physical coordinates x, y, z aligned with local coordinates). Thus u^T J is (dx * u , dy * v). Following (2.44c), Pe = u^T J / 2 kappa, and beta(Pe) is the xibar vector in (2.44a). Finally, we get the artificial diffusion nubar from (2.49).
Donea, J., & Huerta, A. (2003). Finite element methods for flow problems. John Wiley & Sons.
Source code in g-adopt/gadopt/transport_solver.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
set_equation()
abstractmethod
Sets up the term contributions in the equation.
Source code in g-adopt/gadopt/transport_solver.py
203 204 205 206 | |
set_solver_options(solver_preset, solver_extras=None)
Sets PETSc solver parameters.
Source code in g-adopt/gadopt/transport_solver.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
setup_solver()
Sets up the timestepper using specified parameters.
Source code in g-adopt/gadopt/transport_solver.py
241 242 243 244 245 246 247 248 249 250 251 | |
solver_callback()
Optional instructions to execute right after a solve.
Source code in g-adopt/gadopt/transport_solver.py
253 254 255 | |
solve(t=None)
Advances solver in time.
Source code in g-adopt/gadopt/transport_solver.py
257 258 259 260 261 | |
GenericTransportSolver(terms, solution, /, delta_t, timestepper, **kwargs)
Bases: GenericTransportBase
Advances in time a generic transport equation.
Note: The solution field is updated in place.
Terms and Attributes
This solver handles all combinations of advection, diffusion, sink, and source terms. Depending on the included terms, specific attributes must be provided according to:
| Term | Required attribute(s) | Optional attribute(s) |
|---|---|---|
| advection | u | advective_velocity_scaling, su_nubar |
| diffusion | diffusivity | reference_for_diffusion, interior_penalty |
| source | source | |
| sink | sink_coeff |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms
|
str | list[str]
|
List of equation terms to include (a string for a single term is accepted) |
required |
solution
|
Function
|
Firedrake function for the field of interest |
required |
delta_t
|
Constant
|
Simulation time step |
required |
timestepper
|
IrksomeIntegrator
|
Runge-Kutta time integrator employing an explicit or implicit numerical scheme |
required |
solution_old
|
Firedrake function holding the solution field at the previous time step |
required | |
eq_attrs
|
Dictionary of terms arguments and their values |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
solver_parameters
|
Dictionary of solver parameters or a string specifying a default configuration provided to PETSc |
required | |
timestepper_kwargs
|
Dictionary of additional keyword arguments passed to the timestepper constructor. Useful for parameterized schemes (e.g., {'order': 5} for IrksomeRadauIIA) |
required | |
su_advection
|
Boolean activating the streamline-upwind stabilisation scheme when using continuous finite elements |
required |
Source code in g-adopt/gadopt/transport_solver.py
310 311 312 313 314 315 316 317 318 319 320 321 | |
EnergySolver(solution, u, approximation, /, delta_t, timestepper, **kwargs)
Bases: GenericTransportBase
Advances in time the energy conservation equation.
Note: The solution field is updated in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
Firedrake function for temperature |
required |
u
|
Function
|
Firedrake function for velocity |
required |
approximation
|
BaseApproximation
|
G-ADOPT approximation defining terms in the system of equations |
required |
delta_t
|
Constant
|
Simulation time step |
required |
timestepper
|
IrksomeIntegrator
|
Runge-Kutta time integrator employing an explicit or implicit numerical scheme |
required |
solution_old
|
Firedrake function holding the solution field at the previous time step |
required | |
bcs
|
Dictionary specifying boundary conditions (identifier, type, and value) |
required | |
solver_parameters
|
Dictionary of solver parameters or a string specifying a default configuration provided to PETSc |
required | |
timestepper_kwargs
|
Dictionary of additional keyword arguments passed to the timestepper constructor. Useful for parameterized schemes (e.g., {'order': 5} for IrksomeRadauIIA) |
required | |
su_advection
|
Boolean activating the streamline-upwind stabilisation scheme when using continuous finite elements |
required |
Source code in g-adopt/gadopt/transport_solver.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
DiffusiveSmoothingSolver(solution, wavelength, K=1, bcs=None, solver_parameters=None, integration_quad_degree=None, **kwargs)
Bases: GenericTransportSolver
A class to perform diffusive smoothing by inheriting from GenericTransportSolver.
This class provides functionality to solve a diffusion equation for smoothing a scalar function, using clean inheritance from GenericTransportSolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
Function
|
The solution function to store the smoothed result. |
required |
wavelength
|
Number
|
The wavelength for diffusion. |
required |
K
|
Union[Function, Number]
|
Diffusion tensor. Defaults to 1. |
1
|
bcs
|
dict[int, dict[str, int | float]] | None
|
Boundary conditions to impose on the solution. |
None
|
solver_parameters
|
dict[str, str | float] | None
|
Solver parameters for the solver. Defaults to None. |
None
|
integration_quad_degree
|
int | None
|
Quadrature degree for integrating the diffusion tensor. If None, defaults to 2p+1 where p is the polynomial degree. |
None
|
**kwargs
|
Additional keyword arguments to pass to the solver. |
{}
|
Source code in g-adopt/gadopt/transport_solver.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
action(field)
Apply smoothing action to an input field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Function
|
The input field to be smoothed. |
required |
Note
The smoothed result is stored in the solution function passed to the constructor.
Source code in g-adopt/gadopt/transport_solver.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |