tlm_adjoint.fenics.caches

This module implements finite element assembly and linear solver data caching.

Module Contents

class tlm_adjoint.fenics.caches.AssemblyCache

A Cache for finite element assembly data.

assemble(form, *, bcs=None, form_compiler_parameters=None, linear_solver_parameters=None, replace_map=None)

Perform finite element assembly and cache the result, or return a previously cached result.

Parameters:
  • form – The ufl.Form to assemble.

  • bcs – Dirichlet boundary conditions.

  • form_compiler_parameters – Form compiler parameters.

  • linear_solver_parameters – Linear solver parameters. Required for assembly parameters which appear in the linear solver parameters.

  • replace_map – A Mapping defining a map from symbolic variables to values.

Returns:

A tuple (value_ref, value), where value is the result of the finite element assembly, and value_ref is a CacheRef storing a reference to value.

  • For an arity zero or arity one form value_ref stores the assembled value.

  • For an arity two form value_ref is a tuple (A, b_bc). A is the assembled matrix, and b_bc is a boundary condition right-hand-side term which should be added after assembling a right-hand-side with homogeneous boundary conditions applied. b_bc may be None to indicate that this term is zero.

class tlm_adjoint.fenics.caches.LinearSolverCache

A Cache for linear solver data.

linear_solver(form, *, bcs=None, form_compiler_parameters=None, linear_solver_parameters=None, replace_map=None, assembly_cache=None)

Construct a linear solver and cache the result, or return a previously cached result.

Parameters:
  • form – An arity two ufl.Form, defining the matrix.

  • bcs – Dirichlet boundary conditions.

  • form_compiler_parameters – Form compiler parameters.

  • linear_solver_parameters – Linear solver parameters.

  • replace_map – A Mapping defining a map from symbolic variables to values.

  • assembly_cacheAssemblyCache to use for finite element assembly. Defaults to assembly_cache().

Returns:

A tuple (value_ref, value). value is a tuple (solver, A, b_bc), where solver is the linear solver, A is the assembled matrix, and b_bc is a boundary condition right-hand-side term which should be added after assembling a right-hand-side with homogeneous boundary conditions applied. b_bc may be None to indicate that this term is zero. value_ref is a CacheRef storing a reference to value.

class tlm_adjoint.fenics.caches.LocalSolverCache

A Cache for element-wise local block diagonal linear solvers.

local_solver(form, solver_type=None, *, replace_map=None)

Construct an element-wise local block diagonal linear solver and cache the result, or return a previously cached result.

Parameters:
  • form – An arity two ufl.Form, defining the element-wise local block diagonal matrix.

  • solver_typedolfin.LocalSolver.SolverType. Defaults to dolfin.LocalSolver.SolverType.LU.

  • replace_map – A Mapping defining a map from symbolic variables to values.

Returns:

A tuple (value_ref, value). value is a tlm_adjoint.fenics.backend_interface.LocalSolver and value_ref is a CacheRef storing a reference to value.

tlm_adjoint.fenics.caches.assembly_cache()
Returns:

The default AssemblyCache.

tlm_adjoint.fenics.caches.set_assembly_cache(assembly_cache)

Set the default AssemblyCache.

Parameters:

assembly_cache – The new default AssemblyCache.

tlm_adjoint.fenics.caches.linear_solver_cache()
Returns:

The default LinearSolverCache.

tlm_adjoint.fenics.caches.set_linear_solver_cache(linear_solver_cache)

Set the default LinearSolverCache.

Parameters:

linear_solver_cache – The new default LinearSolverCache.

tlm_adjoint.fenics.caches.local_solver_cache()
Returns:

The default LocalSolverCache.

tlm_adjoint.fenics.caches.set_local_solver_cache(local_solver_cache)

Set the default LocalSolverCache.

Parameters:

local_solver_cache – The new default LocalSolverCache.