tlm_adjoint.fixed_point
Module Contents
- class tlm_adjoint.fixed_point.CustomNormSq(eqs, *, norm_sqs=None, adj_norm_sqs=None)
Defines the square of the norm of forward and adjoint solutions.
Callables are used to define squared norms for the forward and adjoint solutions of equations. The total squared norm is then the sum of the squares.
- Parameters:
eqs – A
SequenceofEquationobjects.norm_sqs – A
Sequence. Each element is either a callable, or aSequenceof callables. The callables define the squared norm associated with the corresponding components of the forward solution for the correspondingEquationin eqs. Each callable accepts a single variable and returns afloat. Defaults to the square of the \(l_2\) norm of the degrees of freedom vector.adj_norm_sqs – A
Sequence. Each element is either a callable, or aSequenceof callables. The callables define the squared norm associated with the corresponding components of the adjoint solution for the correspondingEquationin eqs. Each callable accepts a single variable and returns afloat. Defaults to the square of the \(l_2\) norm of the degrees of freedom vector.
- class tlm_adjoint.fixed_point.FixedPointSolver(eqs, solver_parameters, *, norm_sqs=None, adj_norm_sqs=None)
A fixed-point solver. Solves the given equations in sequence until either an absolute or relative tolerance is reached.
Derives tangent-linear and adjoint information using the approach described in:
Jean Charles Gilbert, ‘Automatic differentiation and iterative processes’, Optimization Methods and Software, 1(1), pp. 13–21, 1992, doi: 10.1080/10556789208805503
Bruce Christianson, ‘Reverse accumulation and attractive fixed points’, Optimization Methods and Software, 3(4), pp. 311–326, 1994, doi: 10.1080/10556789408805572
- Parameters:
eqs – A
SequenceofEquationobjects. One forward iteration consists of computing, in order, a forward solution for allEquationobjects.solver_parameters –
A
Mappingdefining solver parameters. Parameters (a number of which are based on KrylovSolver parameters in FEniCS 2017.2.0) are:absolute_tolerance: A
floatdefining the absolute tolerance for a change in the solution in one iteration. Required.relative_tolerance: A
floatdefining the relative tolerance for a change in the solution in one iteration. Required.maximum_iterations: An
intdefining the maximum permitted iterations. Defaults to 1000.nonzero_initial_guess: A
boolindicating whether to use a non-zero initial guess in a forward solve. Defaults to True.adjoint_nonzero_initial_guess: A
boolindicating whether to use a non-zero initial guess in an adjoint solve. Defaults to True.
norm_sqs – Defines the squared norm used to test for convergence in a forward solve. See
CustomNormSq.adj_norm_sqs – Defines the squared norm used to test for convergence in an adjoint solve. See
CustomNormSq.
- drop_references()
Drop references to variables which store values.
- forward_solve(X, deps=None)
Compute the forward solution.
Can assume that the currently active
EquationManageris paused.- Parameters:
X – A variable or a
Sequenceof variables storing the solution. May define an initial guess, and should be set by this method.deps – A
tupleof variables, defining values for dependencies. Only the elements corresponding to X may be modified. self.dependencies() should be used if not supplied.
- adjoint_jacobian_solve(adj_X, nl_deps, B)
Compute an adjoint solution.
- Parameters:
adj_X – Either None, or a variable or
Sequenceof variables defining the initial guess for an iterative solve. May be modified or returned.nl_deps – A
Sequenceof variables defining values for non-linear dependencies. Should not be modified.B – The right-hand-side. A variable or
Sequenceof variables storing the value of the right-hand-side. May be modified or returned.
- Returns:
A variable or
Sequenceof variables storing the value of the adjoint solution. May return None to indicate a value of zero.
- subtract_adjoint_derivative_actions(adj_X, nl_deps, dep_Bs)
Subtract terms from other adjoint right-hand-sides.
Can be overridden for an optimized implementation, but otherwise uses
Equation.adjoint_derivative_action().- Parameters:
adj_X – The adjoint solution. A variable or a
Sequenceof variables. Should not be modified.nl_deps – A
Sequenceof variables defining values for non-linear dependencies. Should not be modified.dep_Bs – A
Mappingwhose items are (dep_index, dep_B). Each dep_B is anAdjointRHSwhich should be updated by subtracting adjoint derivative information computed by differentiating with respect to self.dependencies()[dep_index].
- tangent_linear(tlm_map)
Derive an
Equationcorresponding to a tangent-linear operation.- Parameters:
tlm_map – A
TangentLinearMapstoring values for tangent-linear variables.- Returns:
An
Equation, corresponding to the tangent-linear operation.