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 variablespenalization (
soupy.Penalization) – Penalization term to checkz (
dolfin.Vectoror similar) – The control variabledz (
dolfin.Vectoror similar) – The perturbation to the control variabledelta (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 variablesqoi (
soupy.ControlQoI) – Quantity of interest to checkx (list of
dolfin.Vectoror similar) – The list of state, parameter, adjoint, and control variablesdu (
dolfin.Vectoror similar) – The perturbation to the state variableorder (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:
objectClass to interface the
soupy.ControlCostFunctionalwith a scipy optimizer. Converts inputs to functions taking and returningnumpyarraysConstructor
- 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
- 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