Commit c0b41fb3 authored by Tim Keil's avatar Tim Keil
Browse files

[models] drop BlockOperatorBase assumption and fix some things

parent 05f0439c
......@@ -105,9 +105,10 @@ class StationaryModel(Model):
mu
|Parameter value| for which to compute the gradient
use_adjoint
Use the adjoint solution for a more efficient way of computing the gradient.
if `None` use standard approach, if `True`, use
the adjoint solution for a more efficient way of computing the gradient.
See Section 1.6.2 in [HPUU09]_ for more details.
So far, this approach is only valid for linear models.
So far, the adjoint approach is only valid for linear models.
Returns
-------
......@@ -120,11 +121,7 @@ class StationaryModel(Model):
assert self.output_functional.linear
gradients = []
for d in range(self.output_functional.range.dim):
if self.output_functional.range.dim == 1:
dual_problem = self.with_(operator=self.operator.H, rhs=self.output_functional.H)
else:
assert isinstance(self.output_functional, BlockOperatorBase)
dual_problem = self.with_(operator=self.operator.H, rhs=self.output_functional.blocks[d,0].H)
dual_problem = self.with_(operator=self.operator.H, rhs=self.output_functional.H.as_range_array(mu)[d])
dual_solution = dual_problem.solve(mu)
gradient = [] if return_array else {}
for (parameter, size) in self.parameters.items():
......
......@@ -50,7 +50,7 @@ class Model(CacheableObject, ParametricObject):
def _compute(self, solution=False, output=False, solution_d_mu=False, output_d_mu=False,
solution_error_estimate=False, output_error_estimate=False,
return_output_d_mu_array=False, mu=None, **kwargs):
output_d_mu_return_array=False, mu=None, **kwargs):
return {}
def _compute_solution(self, mu=None, **kwargs):
......@@ -261,7 +261,7 @@ class Model(CacheableObject, ParametricObject):
def compute(self, solution=False, output=False, solution_d_mu=False, output_d_mu=False,
solution_error_estimate=False, output_error_estimate=False,
return_output_d_mu_array=False, *, mu=None, **kwargs):
output_d_mu_return_array=False, *, mu=None, **kwargs):
"""Compute the solution of the model and associated quantities.
This methods computes the output of the model it's internal state
......@@ -295,7 +295,7 @@ class Model(CacheableObject, ParametricObject):
If `True`, return an error estimate for the computed internal state.
output_error_estimate
If `True`, return an error estimate for the computed output.
return_output_d_mu_array
output_d_mu_return_array
if `True`, return the output of :meth:`_compute_output_d_mu` as a |Numpy array|,
otherwise, return it as a dict w.r.t. to the parameters.
mu
......@@ -363,7 +363,7 @@ class Model(CacheableObject, ParametricObject):
if output_d_mu and 'output_d_mu' not in data:
# TODO use caching here (requires skipping args in key generation)
retval = self._compute_output_d_mu(data['solution'], mu=mu,
return_array=return_output_d_mu_array,
return_array=output_d_mu_return_array,
**kwargs)
# retval is always a dict
if isinstance(retval, dict) and 'output_d_mu' in retval:
......@@ -504,7 +504,7 @@ class Model(CacheableObject, ParametricObject):
data = self.compute(
output_d_mu=True,
mu=mu,
return_output_d_mu_array=return_array,
output_d_mu_return_array=return_array,
**kwargs
)
return data['output_d_mu']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment