def algorithm_failure_exception_test(): "Test the AlgorithmFailureException class" try: raise PISM.AlgorithmFailureException("no good reason") return False # should not be reached except PISM.AlgorithmFailureException as e: print("calling e.reason(): ", e.reason()) print("{}".format(e)) return True
def solveForward(self, zeta, out=None): ssa = self.ssarun.ssa reason = ssa.linearize_at(zeta) if reason.failed(): raise PISM.AlgorithmFailureException(reason.description()) if out is not None: out.copy_from(ssa.solution()) else: out = ssa.solution() return out
def F(self, x, out=None, guess=None): """ Returns the value of the forward problem at the design variable ``x``. Nonlinear problems often make use of an initial guess; this can be provided in ``guess``. Storage in ``out``, if given, is used for the return value. """ if out is None: out = self.rangeVector() reason = self.ssa.linearize_at(x.core()) if reason.failed(): raise PISM.AlgorithmFailureException(reason.description()) out.core().copy_from(self.ssa.solution()) return out
def solveForward(self, zeta, out=None): r"""Given a parameterized design variable value :math:`\zeta`, solve the SSA. See :cpp:class:`IP_TaucParam` for a discussion of parameterizations. :param zeta: :cpp:class:`IceModelVec` containing :math:`\zeta`. :param out: optional :cpp:class:`IceModelVec` for storage of the computation result. :returns: An :cpp:class:`IceModelVec` contianing the computation result. """ ssa = self.ssarun.ssa reason = ssa.linearize_at(zeta) if reason.failed(): raise PISM.AlgorithmFailureException(reason) if out is not None: out.copy_from(ssa.solution()) else: out = ssa.solution() return out