# Adjoint Approach

This is also an analytical approach, where finite differencing is not used.

The cost of this method, however, is proportional to the number of response
variables, *N _{y}*, in the model. The number of design variables does
not govern the cost. This approach is quite robust and is preferred when the numbers
of design variables is larger than the number of response variables, in other words,
when

*N*

_{b}>

*N*.

_{y}All three approaches rely on having a designable model, which means the model is parameterized in terms of design variables.

## Example

The example below illustrates the different ways in which DSA may be performed in
MotionSolve.

- The setting dsa=“AUTO” will select the best approach based
on the problem characteristics.
- If the number of design variables > number of responses, the Adjoint method is used.
- If the number of design variables < number of responses, the Direct method is used.
- If the analysis is of type Dynamics, the FD method is always used.

- The setting dsa=”Direct” will select the direct differentiation method for computing the design sensitivity matrix.
- The setting dsa=”Adjoint” will select the adjoint method for computing the design sensitivity matrix.
- The setting dsa=”FD” will select the finite differencing method for computing the design sensitivity matrix. Finite differencing calculations are done in parallel.
- The setting dsa=”FD_Serial” will also select the finite differencing method for computing the design sensitivity matrix. However, the finite differencing calculations are done in serial.

```
>>> # Create a model and store it in the variable m. Sliding_block (...) creates a model.
>>> m = sliding_block ("lugre1")
>>> # Perform a statics simulation followed by a DSA with the AUTO method
>>> m.simulate (type="STATIC", dsa=”AUTO”, end=4, dtout=.01)
>>> # Perform a statics simulation followed by a DSA with the DIRECT method
>>> m.simulate (type="STATIC", dsa=”DIRECT”, end=8, dtout=.01)
>>> # Perform a statics simulation followed by a DSA with the ADJOINT method
>>> m.simulate (type="STATIC", dsa=”ADJOINT”, end=12, dtout=.01)
>>> # Perform a statics simulation followed by a DSA with the FD method
>>> m.simulate (type="STATIC", dsa=”FD”, end=16, dtout=.01)
>>> # Perform a statics simulation followed by a DSA with the FD_SERIAL method
>>> m.simulate (type="STATIC", dsa=”FD_SERIAL”, end=20, dtout=.01)
```