Skip to main content
`Ctrl`+`K`

# TSSetRHSHessianProduct

Sets the function that computes the vector-Hessian-vector product. The Hessian is the second-order derivative of `G` (RHSFunction) w.r.t. the state variable.

## Synopsis

    #include <petscts.h>
    PetscErrorCode TSSetRHSHessianProduct(TS ts, Vec rhshp1[], PetscErrorCode (*rhshessianproductfunc1)(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec VHV[], PetscCtx ctx), Vec rhshp2[], PetscErrorCode (*rhshessianproductfunc2)(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec VHV[], PetscCtx ctx), Vec rhshp3[], PetscErrorCode (*rhshessianproductfunc3)(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec VHV[], PetscCtx ctx), Vec rhshp4[], PetscErrorCode (*rhshessianproductfunc4)(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec VHV[], PetscCtx ctx), PetscCtx ctx)

Logically Collective

## Input Parameters

- ts - `TS` context obtained from `TSCreate()`

- rhshp1 - an array of vectors storing the result of vector-Hessian-vector product for \(G_{UU}\)

- rhshessianproductfunc1 - vector-Hessian-vector product function for \(G_{UU}\)

- rhshp2 - an array of vectors storing the result of vector-Hessian-vector product for \(G_{UP}\)

- rhshessianproductfunc2 - vector-Hessian-vector product function for \(G_{UP}\)

- rhshp3 - an array of vectors storing the result of vector-Hessian-vector product for \(G_{PU}\)

- rhshessianproductfunc3 - vector-Hessian-vector product function for \(G_{PU}\)

- rhshp4 - an array of vectors storing the result of vector-Hessian-vector product for \(G_{PP}\)

- rhshessianproductfunc4 - vector-Hessian-vector product function for \(G_{PP}\)

- ctx - [optional] function context

## Calling sequence of `rhshessianproductfunc1`

- ts - the `TS` context

- t - current timestep

- U - input vector (current ODE solution)

- Vl - an array of input vectors to be left-multiplied with the Hessian

- Vr - input vector to be right-multiplied with the Hessian

- VHV - an array of output vectors for vector-Hessian-vector product

- ctx - [optional] function context

## Notes

All other functions have the same calling sequence as `rhshessianproductfunc1`, so their descriptions are omitted for brevity.

The first Hessian function and the working array are required.

As an example to implement the callback functions, the second callback function calculates the vector-Hessian-vector product \( Vl_n^T*G_UP*Vr\) where the vector \(Vl_n\) (n-th element in the array \(Vl\)) and \(Vr\) are of size \(N\) and \(M\) respectively, and the Hessian \(G_{UP}\) is of size \(N x N x M\). Each entry of \(G_{UP}\) corresponds to the derivative \( G_UP[i][j][k] = \frac{\partial^2 G[i]}{\partial U[j] \partial P[k]}.\) The result of the vector-Hessian-vector product for \(Vl_n\) needs to be stored in vector \(VHV_n\) with j-th entry being \( VHV_n[j] = \sum_i \sum_k {Vl_n[i] * G_UP[i][j][k] * Vr[k]}\) If the cost function is a scalar, there will be only one vector in \(Vl\) and \(VHV\).

## See Also

`TS`, `TSAdjoint`

## Level

intermediate

## Location

src/ts/interface/sensitivity/tssen.c

## Examples

src/ts/tutorials/ex20opt_ic.c
src/ts/tutorials/ex20opt_p.c

Index of all Sensitivity routines
Table of Contents for all manual pages
Index of all manual pages