Skip to content

Commit

Permalink
orthonormalize reduced basis by using function from PETSc eigen solver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Elarif committed Sep 7, 2022
1 parent e441033 commit 48853fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
print("--------------------------------------------")
print(" STEP I. 2: Generate L2 and H1 operator ")
print("--------------------------------------------")

Vh = feelpp.functionSpace(mesh=FineMesh) # feelpp space function
l2ScalarProducMatrix=FppOp.mass(test=Vh,trial=Vh,range=feelpp.elements(FineMesh))
h1ScalarProducMatrix=FppOp.stiffness(test=Vh,trial=Vh,range=feelpp.elements(FineMesh))
Expand All @@ -135,8 +134,8 @@
#reducedOrderBasisU=GD.Greedy(collectionProblemData,"U",l2ScalarProducMatrix,h1ScalarProducMatrix,nev) # greedy algorith
reducedOrderBasisU = SRB.PODReducedBasisPETSc(fineSnapList,l2ScalarProducMatrix)
else : #POD
# reducedOrderBasisU = SRB.PODReducedBasisPETSc(fineSnapList, l2ScalarProducMatrix)
reducedOrderBasisU = SRB.PODReducedBasisNumpy(fineSnapList, l2ScalarProducMatrix)
reducedOrderBasisU = SRB.PODReducedBasisPETSc(fineSnapList, l2ScalarProducMatrix)
# reducedOrderBasisU = SRB.PODReducedBasisNumpy(fineSnapList, l2ScalarProducMatrix)

# number of modes
nev = reducedOrderBasisU.size[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ def PODReducedBasisPETSc(snapshotList, snapshotCorrelationOperator, tolerance=1.
def TruncatedEVDPetscMat(matrix, epsilon = None, nbModes = None):
"""
Computes a truncated eigen value decomposition of a symetric definite
matrix in petsc.mat format. Only the lower triangular part needs
to be defined
matrix in petsc.mat format. Get only eigen value lambda_i > epsilon^2 lambda_max
the basis vectors returned are orthonormalized
Parameters
----------
Expand Down Expand Up @@ -401,25 +401,26 @@ def TruncatedEVDPetscMat(matrix, epsilon = None, nbModes = None):
E.setDimensions(matrix.size[1]) # set the number of eigen val to compute
# E.setTolerances(epsilon) # set the tolerance used for the convergence

# print('ok before eigen solve ')
E.solve()
nbmaxEv = E.getConverged() # number of eigenpairs

print("max number of Eigen value = ", nbmaxEv)
# print('Does it converge ? (1 or 0) =', E.getConvergenceTest())
# print('Is it positive mat ? (1 or 0)', E.isPositive() )


eigenValues = []
eigenVectors = []
eigenVectors = E.getInvariantSubspace() # Get orthonormal basis associated to eigenvalues

eigenvect = PETSc.Vec().create()
eigenvect.setSizes(nbmaxEv)
eigenvect.setFromOptions()
eigenvect.setUp()
# eigenvect = PETSc.Vec().create()
# eigenvect.setSizes(nbmaxEv)
# eigenvect.setFromOptions()
# eigenvect.setUp()

for i in range(nbmaxEv):
eigenValues.append(float(E.getEigenvalue(i).real))
E.getEigenvector(i, eigenvect)
eigenVectors.append(eigenvect)

# E.getEigenvector(i, eigenvect)
# eigenVectors.append(eigenvect)
E.destroy() # destroy the solver object

eigenValues = np.array(eigenValues)
Expand Down

0 comments on commit 48853fc

Please sign in to comment.