gusto.recovery package

Submodules

gusto.recovery.averaging module

This provides an operator for restoring continuity for discontinuous fields.

The Averager provided in this module is an operator that transforms fields from (partially-)discontinuous function spaces to their (partially-) continuous counterparts. It does this by simply averaging the values at the DoFs from the discontiuous space that correspond to those from the continuous space.

class gusto.recovery.averaging.Averager(v, v_out)[source]

Bases: object

Computes a continuous field from a broken space through averaging.

This object restores the continuity from a field in a discontinuous or broken function space. The target function space must have the same DoFs per cell as the source function space. Then the value of the continuous field at a particular DoF is the average of the corresponding DoFs from the discontinuous space.

Parameters:
  • v (Function) – the (discontinuous) field to average. Can also be a ufl.Expr.

  • v_out (Function) – the (continuous) field to compute.

Raises:
  • RuntimeError – the geometric shape of the two fields must be equal.

  • RuntimeError – the number of DoFs per cell must be equal.

project()[source]

Apply the recovery.

gusto.recovery.recovery module

Operators to recover fields from a discontinuous to a continuous function space.

The recovery operators provided in this module are used to restore continuity in a discontinuous field, or to reconstruct a higher-order field from a lower- order field, which can be used to improve the accuracy of lowest-order spatial discretisations.

class gusto.recovery.recovery.BoundaryMethod(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Method for correcting the recovery at the domain boundaries.

An enumerator object encoding methods for correcting boundary recovery: extruded: which corrects a scalar field on an extruded mesh at the top and bottom boundaries.

hcurl: this corrects the recovery of a HDiv field into a HCurl space at the top and bottom boundaries of an extruded mesh.

taylor: uses a Taylor expansion to correct the field at all the boundaries of the domain. Should only be used in Cartesian domains.

extruded = 0
hcurl = 1
taylor = 2
class gusto.recovery.recovery.BoundaryRecoverer(x_inout, method=BoundaryMethod.extruded, eff_coords=None)[source]

Bases: object

Corrects values in domain boundary cells that have been recovered.

An object that performs a recovery process at the domain boundaries that has second-order accuracy. This is necessary because the Averager object does not recover a field with sufficient accuracy at the boundaries.

The strategy is to expand the function at the boundary using a Taylor expansion. The quickest way to perform this is by using the analytic solution and a parloop.

This is only implemented to recover to the CG1 function space.

Parameters:
  • v_CG1 (Function) – the continuous function after the first recovery is performed. Should be in a first-order continuous FunctionSpace. This is already correct on the interior of the domain. It will be returned with corrected values.

  • method (BoundaryMethod, optional) – enumerator specifying the method to use. Defaults to BoundaryMethod.extruded.

  • eff_coords (Function, optional) – the effective coordinates corresponding to the initial recovery process. Should be in the VectorFunctionSpace corresponding to the space of the v_DG1 variable. This must be provided for the Taylor expansion boundary method. Defaults to None.

Raises:
  • ValueError – if the v_CG1 field is in a space that is not CG1 when using the Taylor boundary method.

  • ValueError – if the v_DG1 field is in a space that is not the DG1 equispaced space when using the Taylor boundary method.

  • ValueError – if the effective coordinates are not provided when using the Taylor expansion boundary method.

  • ValueError – using the extruded or hcurl boundary methods with a non-extruded mesh.

apply()[source]

Applies the boundary recovery process.

class gusto.recovery.recovery.Recoverer(x_in, x_out, method='interpolate', boundary_method=None)[source]

Bases: object

Recovers a field from a low-order space to a higher-order space.

An object that ‘recovers’ a field from a low-order space (e.g. DG0) into a higher-order space (e.g. CG1). This first interpolates or projects the field into the broken (fully-discontinuous) form of the target higher-order space, then uses the Averager to restore continuity. This may not be accurate at domain boundaries, so if specified, the field will then be corrected using the BoundaryRecoverer.

Parameters:
  • x_in (Function) – the field or ufl.Expr to project. For instance this could be in the DG0 space.

  • x_out (Function) – to field to put the result in. This could for instance lie in the CG1 space.

  • method (str, optional) – method for obtaining the field in the broken space. Must be ‘interpolate’ or ‘project’. Defaults to ‘interpolate’.

  • boundary_method (BoundaryMethod, optional) – enumerator specifying the boundary method to use. Defaults to None.

Raises:

ValueError – the VDG argument must be specified if the boundary_method is not None.

project()[source]

Perform the whole recovery step.

gusto.recovery.recovery_kernels module

This module provides the kernels for the recovery processes.

Kernels are held in classes containing the instructions and an apply method, which calls the kernel using a par_loop. The code snippets used in the kernels are written using loopy: https://documen.tician.de/loopy/index.html

class gusto.recovery.recovery_kernels.AverageKernel(V)[source]

Bases: object

Evaluates values at DoFs shared between elements using averaging.

This kernel restores the continuity of a broken field using an averaging operation. The values of DoFs shared between by elements are computed as the average of the corresponding DoFs of the discontinuous field.

Parameters:

V (FunctionSpace) – The FunctionSpace of the target field for the Averager operator.

apply(v_out, weighting, v_in)[source]

Performs the par_loop.

Parameters:
  • v_out (Function) – the continuous output field.

  • weighting (Function) – the weights to be used for the averaging.

  • v_in (Function) – the (discontinuous) input field.

class gusto.recovery.recovery_kernels.AverageWeightings(V)[source]

Bases: object

Finds the weights for the Averager operator.

This computes the weights used in the averaging process for each DoF. This is the multiplicity of the DoFs – as in how many elements each DoF is shared between.

Parameters:

V (FunctionSpace) – the continuous function space in which the target field of the averaging process lives.

apply(w)[source]

Performs the par loop.

Parameters:

w (Function) – the field in which to store the weights. This lives in the continuous target space.

class gusto.recovery.recovery_kernels.BoundaryGaussianElimination(DG1)[source]

Bases: object

Performs local Gaussian elimination for the BoundaryRecoverer.

The kernel is used to improve the accuracy of the recovery process into DG1 by performing local extrapolation at the domain boundaries. The kernel should be applied after an initial recovery process, which has reduced accuracy at the domain boundaries.

The inaccurate initial recovery can be treated as an accurate recovery process at an alternative (“effective”) set of coordinates. To correct this, the original field is expanded using a Taylor series in each cell, using the “effective” coordinates. This kernel performs this expansion and uses a Gaussian elimination process to obtain the coefficents in the Taylor expansion. These coefficients are then used with the actual coordinates of the cell’s vertices to extrapolate and obtain a more accurate field on the domain boundaries.

Parameters:

DG1 (FunctionSpace) – The equispaced DG1 function space.

apply(v_DG1_old, v_DG1, act_coords, eff_coords, num_ext)[source]

Perform the par loop.

Takes a scalar field in DG1, the coordinates of the equispaced DG1 DoFs and the “effective” coordinates of those DoFs. These “effective” coordinates correspond to the locations of the DoFs from the original space (i.e. the one being recovered from), with the recovery process applied to them.

Parameters:
  • v_DG1_old (Function) – the originally recovered field in the equispaced DG1 FunctionSpace.

  • v_DG1 (Function) – the output field in the equispaced DG1 FunctionSpace.

  • act_coords (Function) – a field whose values contain the actual coordinates (in Cartesian components) of the DoFs of the equispaced DG1 FunctionSpace. This field should be in the equispaced DG1 VectorFunctionSpace.

  • eff_coords (Function) – a field whose values contain coordinates (in Cartesian components) of the DoFs corresponding to the effective locations of the original recovery process. This field should be in the equispaced DG1 VectorFunctionSpace.

  • num_ext (Function) – a field in the DG0 FunctionSpace whose DoFs contain the number of DoFs of the equispaced DG1 FunctionSpace that are on the exterior of the domain.

class gusto.recovery.recovery_kernels.BoundaryRecoveryExtruded(V)[source]

Bases: object

Performs the “extruded” boundary recovery at the top and bottom boundaries.

A kernel for improving the accuracy at the top and bottom boundaries of the domain for the operator for recovering a scalar field on an extruded mesh. The kernel is called as part of the “extruded” method of the BoundaryRecovery operator.

apply(x_out, x_in)[source]

Performs the par loop.

Parameters:
  • x_out (Function) – the target field to be corrected. It should be in a continuous FunctionSpace.

  • x_in (Function) – the uncorrected field (after the initial recovery process). It should be in the same continuous FunctionSpace.

class gusto.recovery.recovery_kernels.BoundaryRecoveryHCurl(V)[source]

Bases: object

Performs the “hcurl” boundary recovery at the top and bottom boundaries.

A kernel for improving the accuracy at the top and bottom boundaries of the domain for the operator for recovering a vector HDiv field to a HCurl field on an extruded mesh. The kernel is called as part of the “hcurl” method of the BoundaryRecovery operator. Only the horizontal component of the HCurl field should be adjusted.

apply(x_out, x_in)[source]

Performs the par loop.

Parameters:
  • x_out (Function) – the target field to be corrected. It should be in a continuous FunctionSpace.

  • x_in (Function) – the uncorrected field (after the initial recovery process). It should be in the same continuous FunctionSpace.

gusto.recovery.recovery_options module

Contains an object to generate the set of spaces used for the recovery wrapper

class gusto.recovery.recovery_options.RecoverySpaces(domain, boundary_method=None, use_vector_spaces=False)[source]

Bases: object

Finds or builds necessary spaces to carry out recovery transport for lowest and mixed order domains (0,0), (0,1) and (1,0)

Parameters:
  • domain (Domain) – the model’s domain object, containing the mesh and the compatible function spaces.

  • ( (boundary_method) – variable:’dict’, optional): A dictionary containing the space the boundary method is to be applied to along with specified method. Acceptable keys are “DG”, “HDiv” and “theta”. Acceptable values are (BoundaryMethod.taylor/hcurl/extruded). Defaults to None.

  • use_vector_spaces (bool, optional) – . Determines if we need to use the vector DG1 / CG1 space for the embedded and recovery space for the HDiv field instead of the usual HDiv, HCurl spaces. Defaults to False.

gusto.recovery.reversible_recovery module

This file provides an object for reconstructing a discontinuous field in a higher-order function space.

class gusto.recovery.reversible_recovery.ReversibleRecoverer(source_field, target_field, reconstruct_opts)[source]

Bases: object

An object for performing a reconstruction of a low-order discontinuous field into a higher-order discontinuous space. This uses the recovery operator, but with further adjustments to ensure reversibility.

Parameters:
  • source_field – the source field.

  • target_field – the target_field.

  • reconstruct_opts – an object containing the various options for the reconstruction.

project()[source]

Module contents