Beispiel #1
0
    def solve(self, op, rhs, tol, maxit):
        solver_parameters = self.parameters.sublist('Solver')

        iterative_solver_parameters = solver_parameters.sublist(
            'Iterative Solver')
        iterative_solver_parameters.set('Convergence Tolerance',
                                        tol if maxit > 1 else 1e-3)
        # iterative_solver_parameters.set('Maximum Iterations', maxit)

        solver_parameters.set('Complex', True)

        x = EpetraInterface.Vector(rhs.real.Map(), 2)
        y = EpetraInterface.Vector(rhs.real.Map(), 2)
        x[:, 0] = rhs.real
        x[:, 1] = rhs.imag

        epetra_op = ComplexEpetraInterface.Operator(op)
        if self.preconditioned_solve:
            epetra_precop = ComplexJadaHYMLSPrecOp(
                op, self.interface.preconditioner)
            solver = HYMLS.Solver(epetra_op, epetra_precop, self.parameters)
        else:
            solver = HYMLS.Solver(epetra_op, epetra_op, self.parameters)
        solver.ApplyInverse(x, y)

        out = ComplexEpetraInterface.ComplexVector(y[:, 0], y[:, 1])
        return out
Beispiel #2
0
    def prec(self, x, *args):
        y = EpetraInterface.Vector(x.real.Map(), 2)
        z = EpetraInterface.Vector(x.real.Map(), 2)
        y[:, 0] = x.real
        y[:, 1] = x.imag

        self.interface.preconditioner.ApplyInverse(y, z)

        out = ComplexEpetraInterface.ComplexVector(z[:, 0], z[:, 1])
        return out
Beispiel #3
0
    def Apply(self, x, y):
        assert x.NumVectors() == 2
        # Create a view here because this is an Epetra.MultiVector.
        x = EpetraInterface.Vector(Epetra.View, x, 0, x.NumVectors())
        y = EpetraInterface.Vector(Epetra.View, y, 0, y.NumVectors())

        x = ComplexVector(x[:, 0], x[:, 1])
        z = self.op.matvec(x)
        ret = y[:, 0].Update(1.0, z.real, 0.0)
        ret += y[:, 1].Update(1.0, z.imag, 0.0)
        return ret
Beispiel #4
0
    def __matmul__(self, x):
        if isinstance(x, numpy.ndarray):
            local_map = Epetra.LocalMap(x.shape[0], 0, self.Comm())
            x = ComplexVector(EpetraInterface.Vector(local_map, x.T.real), EpetraInterface.Vector(local_map, x.T.imag))

        tmp = ComplexVector(self.real.Map(), x.shape[1])

        tmp.real.Multiply('N', 'N', 1.0, self.real, x.real, 0.0)
        tmp.real.Multiply('N', 'N', -1.0, self.imag, x.imag, 1.0)

        tmp.imag.Multiply('N', 'N', 1.0, self.real, x.imag, 0.0)
        tmp.imag.Multiply('N', 'N', 1.0, self.imag, x.real, 1.0)

        return tmp
Beispiel #5
0
    def solve(self, op, rhs, tol, maxit):
        solver_parameters = self.parameters.sublist('Solver')

        iterative_solver_parameters = solver_parameters.sublist(
            'Iterative Solver')
        iterative_solver_parameters.set('Convergence Tolerance',
                                        tol if maxit > 1 else 1e-3)
        # iterative_solver_parameters.set('Maximum Iterations', maxit)

        if rhs.shape[1] == 2:
            solver_parameters.set('Complex', True)
        else:
            solver_parameters.set('Complex', False)

        out = EpetraInterface.Vector(rhs)

        epetra_op = EpetraInterface.Operator(op)
        if self.preconditioned_solve:
            epetra_precop = JadaHYMLSPrecOp(op, self.interface.preconditioner)
            solver = HYMLS.Solver(epetra_op, epetra_precop, self.parameters)
        else:
            solver = HYMLS.Solver(epetra_op, epetra_op, self.parameters)
        solver.ApplyInverse(rhs, out)

        return out
Beispiel #6
0
    def solve(self, op, rhs, tol, maxit):
        solver_parameters = self.parameters.sublist('Solver')

        iterative_solver_parameters = solver_parameters.sublist(
            'Iterative Solver')
        iterative_solver_parameters.set('Convergence Tolerance',
                                        tol if maxit > 1 else 1e-3)
        # iterative_solver_parameters.set('Maximum Iterations', maxit)

        if rhs.shape[1] == 2:
            solver_parameters.set('Complex', True)
        else:
            solver_parameters.set('Complex', False)
        solver_parameters.set('Use Bordering', True)

        out = EpetraInterface.Vector(rhs)

        epetra_op = EpetraInterface.Operator(ShiftedOperator(op))
        if self.preconditioned_solve:
            solver = HYMLS.Solver(epetra_op, self.interface.preconditioner,
                                  self.parameters)
            solver.SetBorder(op.Z, op.Q)
            self.interface.preconditioner.Compute()
            solver.ApplyInverse(rhs, out)
            solver.UnsetBorder()
        else:
            raise Exception('Not implemented')

        return out
Beispiel #7
0
    def ApplyInverse(self, x, y):
        self.prec.ApplyInverse(x, y)

        # Create a view here because this is an Epetra.MultiVector.
        z = EpetraInterface.Vector(Epetra.View, y, 0, y.NumVectors())
        z = self.op.proj(z)
        return y.Update(1.0, z, 0.0)
Beispiel #8
0
    def ApplyInverse(self, x, y):
        self.prec.ApplyInverse(x, y)

        assert x.NumVectors() == 2
        # Create a view here because this is an Epetra.MultiVector.
        y = EpetraInterface.Vector(Epetra.View, y, 0, y.NumVectors())
        y = ComplexEpetraInterface.ComplexVector(y[:, 0], y[:, 1])

        z = self.op.proj(y)
        y *= 0.0
        y += z
        return 0
Beispiel #9
0
    def solve(self, op, rhs, tol, maxit):
        solver_parameters = self.parameters.sublist('Solver')

        iterative_solver_parameters = solver_parameters.sublist(
            'Iterative Solver')
        iterative_solver_parameters.set('Convergence Tolerance',
                                        tol if maxit > 1 else 1e-3)
        # iterative_solver_parameters.set('Maximum Iterations', maxit)

        solver_parameters.set('Complex', True)
        solver_parameters.set('Use Bordering', True)

        x = EpetraInterface.Vector(rhs.real.Map(), 2)
        y = EpetraInterface.Vector(rhs.real.Map(), 2)
        x[:, 0] = rhs.real
        x[:, 1] = rhs.imag

        m = op.Q.real.NumVectors()

        Q = EpetraInterface.Vector(rhs.real.Map(), m * 2)
        Q[:, 0:m] = op.Q.real
        Q[:, m:2 * m] = op.Q.imag

        Z = EpetraInterface.Vector(rhs.real.Map(), m * 2)
        Z[:, 0:m] = op.Z.real
        Z[:, m:2 * m] = op.Z.imag

        epetra_op = ComplexEpetraInterface.Operator(ShiftedOperator(op))
        if self.preconditioned_solve:
            solver = HYMLS.Solver(epetra_op, self.interface.preconditioner,
                                  self.parameters)
            solver.SetBorder(Z, Q)
            self.interface.preconditioner.Compute()
            solver.ApplyInverse(x, y)
            solver.UnsetBorder()
        else:
            raise Exception('Not implemented')

        out = ComplexEpetraInterface.ComplexVector(y[:, 0], y[:, 1])
        return out
Beispiel #10
0
    def __init__(self, *args, **kwargs):
        self.real = None
        self.imag = None

        if len(args) > 1 and isinstance(args[0],
                                        EpetraInterface.Vector) and isinstance(
                                            args[1], EpetraInterface.Vector):
            self.real = args[0]
            self.imag = args[1]
        elif len(args) > 0 and isinstance(args[0], ComplexVector):
            self.real = EpetraInterface.Vector(args[0].real, *args[1:],
                                               **kwargs)
            self.imag = EpetraInterface.Vector(args[0].imag, *args[1:],
                                               **kwargs)
        elif len(args) > 1 and isinstance(args[1], ComplexVector):
            self.real = EpetraInterface.Vector(args[0], args[1].real,
                                               *args[1:], **kwargs)
            self.imag = EpetraInterface.Vector(args[0], args[1].imag,
                                               *args[1:], **kwargs)
        else:
            self.real = EpetraInterface.Vector(*args, **kwargs)
            self.imag = EpetraInterface.Vector(*args, **kwargs)

        self.shape = self.real.shape
        self.dtype = numpy.dtype(self.real.dtype.char.upper())
Beispiel #11
0
def test_orthonormalization_multiple_vectors_epetra(otype):
    try:
        from PyTrilinos import Epetra
        from jadapy import EpetraInterface
    except ImportError:
        pytest.skip("Trilinos not found")

    dtype = numpy.float64
    atol = numpy.finfo(dtype).eps * 100
    n = 20
    k = 5

    comm = Epetra.PyComm()
    map = Epetra.Map(n, 0, comm)
    x = EpetraInterface.Vector(map, k)
    x.Random()

    orthogonalization.orthonormalize(x, method=otype)
    for i in range(k):
        for j in range(k):
            if i == j:
                continue
            assert_allclose(x[:, i].dot(x[:, j]), 0, rtol=0, atol=atol)
        assert_allclose(norm(x[:, i]), 1, rtol=0, atol=atol)
Beispiel #12
0
 def prec(self, x, *args):
     out = EpetraInterface.Vector(x)
     self.interface.preconditioner.ApplyInverse(x, out)
     return out