def testOrthogonalization(self): myRandom = Random(self.mpi_rank, self.mpi_size) myRandom.normal(1.,self.Q) _ = self.Q.orthogonalize() QtQ = self.Q.dot_mv(self.Q) if self.mpi_rank == 0: assert np.linalg.norm(QtQ - np.eye(QtQ.shape[0])) < 1e-8
def setUp(self): mesh = dl.UnitSquareMesh(10, 10) self.mpi_rank = dl.MPI.rank(mesh.mpi_comm()) self.mpi_size = dl.MPI.size(mesh.mpi_comm()) Vh1 = dl.FunctionSpace(mesh, 'Lagrange', 1) uh, vh = dl.TrialFunction(Vh1), dl.TestFunction(Vh1) mh, test_mh = dl.TrialFunction(Vh1), dl.TestFunction(Vh1) ## Set up B ndim = 2 ntargets = 200 np.random.seed(seed=1) targets = np.random.uniform(0.1, 0.9, [ntargets, ndim]) B = assemblePointwiseObservation(Vh1, targets) ## Set up Asolver alpha = dl.Constant(1.0) varfA = ufl.inner(ufl.grad(uh), ufl.grad(vh))*ufl.dx +\ alpha*ufl.inner(uh,vh)*ufl.dx A = dl.assemble(varfA) Asolver = PETScKrylovSolver(A.mpi_comm(), "cg", amg_method()) Asolver.set_operator(A) Asolver.parameters["maximum_iterations"] = 100 Asolver.parameters["relative_tolerance"] = 1e-12 ## Set up C varfC = ufl.inner(mh, vh) * ufl.dx C = dl.assemble(varfC) self.Hop = Hop(B, Asolver, C) ## Set up RHS Matrix M. varfM = ufl.inner(mh, test_mh) * ufl.dx self.M = dl.assemble(varfM) self.Minv = PETScKrylovSolver(self.M.mpi_comm(), "cg", amg_method()) self.Minv.set_operator(self.M) self.Minv.parameters["maximum_iterations"] = 100 self.Minv.parameters["relative_tolerance"] = 1e-12 myRandom = Random(self.mpi_rank, self.mpi_size) x_vec = dl.Vector(mesh.mpi_comm()) self.Hop.init_vector(x_vec, 1) k_evec = 10 p_evec = 50 self.Omega = MultiVector(x_vec, k_evec + p_evec) self.k_evec = k_evec myRandom.normal(1., self.Omega)
def testBOrthogonalization(self): myRandom = Random(self.mpi_rank, self.mpi_size) myRandom.normal(1.,self.Q) self.Q.Borthogonalize(self.M) MQ = MultiVector(self.Q) MQ.zero() MatMvMult(self.M, self.Q, MQ) QtMQ = self.Q.dot_mv(MQ) if self.mpi_rank == 0: assert np.linalg.norm(QtMQ - np.eye(QtMQ.shape[0])) < 1e-8