soupy.utils module

soupy.utils.penalizationFiniteDifference

soupy.utils.penalizationFiniteDifference.penalizationFiniteDifference(Vh, penalization, z, dz, order=1, delta=0.0001, plotting=False)[source]

Finite difference checks the gradient of the penalization

Parameters:
  • Vh (list of dolfin.FunctionSpace) – List of function spaces for the state, parameter, adjoint, and control variables

  • penalization (soupy.Penalization) – Penalization term to check

  • z (dolfin.Vector or similar) – The control variable

  • dz (dolfin.Vector or similar) – The perturbation to the control variable

  • delta (float) – The finite difference step size

  • plotting (bool) – If true, plots the finite difference Hessian and analytic Hessian

soupy.utils.qoiFiniteDifference

soupy.utils.qoiFiniteDifference.qoiFiniteDifference(Vh, qoi, x, du, order=1, delta=0.0001, plotting=False)[source]

Finite difference checks the gradient of the quantity of interest with respect to the state variable, as well as the parameter and control variables

Parameters:
  • Vh (list of dolfin.FunctionSpace) – List of function spaces for the state, parameter, adjoint, and control variables

  • qoi (soupy.ControlQoI) – Quantity of interest to check

  • x (list of dolfin.Vector or similar) – The list of state, parameter, adjoint, and control variables

  • du (dolfin.Vector or similar) – The perturbation to the state variable

  • order (int) – Order of derivative to check. 1 for gradient, 2 for Hessian

  • delta (float) – The finite difference step size

  • plotting (bool) – If true, plots the finite difference Hessian and analytic Hessian

soupy.utils.stochasticCostFiniteDifference

soupy.utils.stochasticCostFiniteDifference.SAACostFiniteDifference(pde_cost, z, dz, delta=0.001)[source]

Finite difference check for a deterministic/SAA cost functional

Parameters:
  • pde_cost – Stochastic cost functional to check

  • z – Point of cost and derivative evaluation

  • dz – Direction for finite difference derivative

  • delta – Step size

  • sample_size – sample size for expectation computations

soupy.utils.stochasticCostFiniteDifference.stochasticCostFiniteDifference(pde_cost, z, dz, delta=0.001, sample_size=1)[source]

Finite difference check for a stochastic cost function by fixing the random number generator seed

Parameters:
  • pde_cost – Stochastic cost functional to check

  • z – Point of cost and derivative evaluation

  • dz – Direction for finite difference derivative

  • delta – Step size

  • sample_size – sample size for expectation computations

soupy.utils.scipyCostWrapper module

class soupy.utils.scipyCostWrapper.ScipyCostWrapper(cost_functional, verbose=False)[source]

Bases: object

Class to interface the soupy.ControlCostFunctional with a scipy optimizer. Converts inputs to functions taking and returning numpy arrays

Constructor

Parameters:

cost_functional (ControlCostFunctional) – The cost functional to wrap

cost(z_np)[source]

Evaluates the cost functional at given control

Parameters:

z_np (numpy.ndarray) – The control as a numpy array

Returns:

The value of the cost functional

Return type:

float

function()[source]
Returns:

A function that evaluates the cost functional at a given control

grad(z_np)[source]

Evaluates the gradient of the cost functional at given control

Parameters:

z_np (numpy.ndarray) – The control as a numpy array

Returns:

The gradient

Return type:

numpy.ndarray

hessian(z_np, zhat_np)[source]
hessp()[source]
Returns:

A function that evaluates the Hessian of the cost functional at a given control x: applied in a direction p

jac()[source]
Returns:

A function that evaluates the gradient of the cost functional at a given control