def test_low_rank_assemble(): r1, r2 = 2, 3 _, L1, C1, R1, _, _ = construct_operators_and_vectorarrays(5, 5, r1, 0) _, L2, C2, R2, _, _ = construct_operators_and_vectorarrays(5, 5, r2, 0, seed=1) LR1 = LowRankOperator(L1, C1, R1) LR2 = LowRankOperator(L2, C2, R2) op = assemble_lincomb([LR1, LR2], [1, 1]) assert isinstance(op, LowRankOperator) assert len(op.left) == r1 + r2 assert not op.inverted op = (LR1 + (LR1 + LR2) + LR2).assemble() assert isinstance(op, LowRankOperator) LR1 = LowRankOperator(L1, C1, R1, inverted=True) LR2 = LowRankOperator(L2, C2, R2, inverted=True) op = assemble_lincomb([LR1, LR2], [1, 1]) assert isinstance(op, LowRankOperator) assert len(op.left) == r1 + r2 assert op.inverted LR1 = LowRankOperator(L1, C1, R1, inverted=True) LR2 = LowRankOperator(L2, C2, R2) op = assemble_lincomb([LR1, LR2], [1, 1]) assert op is None
def jacobian(self, U, mu=None): from pymor.algorithms.lincomb import assemble_lincomb if self.linear: return self.assemble(mu) jacobians = [op.jacobian(U, mu) for op in self.operators] coefficients = self.evaluate_coefficients(mu) options = self.solver_options.get('jacobian') if self.solver_options else None jac = assemble_lincomb(jacobians, coefficients, solver_options=options, name=self.name + '_jacobian') if jac is None: return LincombOperator(jacobians, coefficients, solver_options=options, name=self.name + '_jacobian') else: return jac
def assemble(self, mu=None): from pymor.algorithms.lincomb import assemble_lincomb operators = tuple(op.assemble(mu) for op in self.operators) coefficients = self.evaluate_coefficients(mu) op = assemble_lincomb(operators, coefficients, solver_options=self.solver_options, name=self.name + '_assembled') if op: return op else: if self.parametric or operators != self.operators: return LincombOperator(operators, coefficients, solver_options=self.solver_options, name=self.name + '_assembled') else: # this can only happen when both operators and self.operators are tuples! return self # avoid infinite recursion