- edited description
setTarget and getTarget gives different values
Hi,
I’m trying to solve a generalized eigenvalue problem using petsc4py/slepc4py compiled with complex number.
>>> from petsc4py import PETSc
>>> PETSc.ScalarType
<class 'numpy.complex128'>
I have two differents issues:
- When I set and look at the target I always get a zero imaginary part:
...
eigensolver.setTarget(-0.1+7.0*1j)
eigensolver.setWhichEigenpairs(slepc4py.SLEPc.EPS.Which.TARGET_MAGNITUDE)
...
eigensolver.setFromOptions()
eigensolver.setUp()
print(eigensolver.getTarget())
(-0.1+0j)
- I cannot specify EPS.Which.TARGET_IMAGINARY, it raises an out of range error:
...
eigensolver.setWhichEigenpairs(SLEPc.EPS.Which.TARGET_IMAGINARY)
...
File "SLEPc/EPS.pyx", line 572, in slepc4py.SLEPc.EPS.setWhichEigenpairs
petsc4py.PETSc.Error: error code 63
Partial code:
A_mat, B_mat coming from my code
eigensolver = slepc4py.SLEPc.EPS()
eigensolver.create()
S = eigensolver.getST()
S.setType(slepc4py.SLEPc.ST.Type.SINVERT)
K = S.getKSP()
K.setType(petsc4py.PETSc.KSP.Type.PREONLY)
PC = K.getPC()
PC.setType(petsc4py.PETSc.PC.Type.LU)
PC.setFactorSolverType("mumps")
PC.setFactorShift(petsc4py.PETSc.Mat.FactorShiftType.POSITIVE_DEFINITE)
PC.setFromOptions()
K.setPC(PC)
K.setFromOptions()
S.setKSP(K)
S.setFromOptions()
eigensolver.setST(S)
eigensolver.setOperators(A_mat, B_mat)
eigensolver.setTarget(-0.1+7.0*1j)
eigensolver.setWhichEigenpairs(slepc4py.SLEPc.EPS.Which.TARGET_REAL)
eigensolver.setDimensions(nev, petsc4py.PETSc.DECIDE, petsc4py.PETSc.DECIDE)
eigensolver.setType(slepc4py.SLEPc.EPS.Type.KRYLOVSCHUR)
eigensolver.setProblemType(slepc4py.SLEPc.EPS.ProblemType.PGNHEP)
eigensolver.setFromOptions()
eigensolver.setUp()
Any help will be much appreciated !
Thibaut G.
Comments (10)
-
reporter -
This is very strange. The two issues imply that SLEPc has not been compiled with complex scalars, but the
PETSc.ScalarType
you are showing is indeed complex. Maybe it is because you are printing the ScalarType in an interactive session that has a differentPETSC_ARCH
compared to the program. Try printing the ScalarType in the program itself.By the way, the
getST()
etc. gives you a reference to the internal object, there is no need to callsetST()
afterwards. -
reporter I’ve forced PETSc to load my complex installation in my code:
import slepc4py, petsc4py petsc4py.init(arch="linux-complex") slepc4py.init(arch="linux-complex") ... eigensolver.setTarget(complex(-0.1,7.0)) #Trying this call ... print(petsc4py.PETSc.ScalarType) print(eigensolver.getTarget())
Output:
... <class 'numpy.complex128'> (-0.1+0j) ...
For information, my matrix A and B come from FEniCS and the program run in parallel.
Thanks for the tip I will remove my setST() call !
-
Then I don’t know what is happening. Maybe @Lisandro Dalcin has an idea.
-
reporter Ok, I hope we will figure out what’s going on.
-
Folks, I’ll not be able to look at this until the end of next week or so.
I’m wondering whether (from some strange reason) the global C variable
PETSc_i
is not being properly initialized to the imaginary unit. Any chance any of you can figure out usinggdb
? -
reporter Ok I will have a closer look at it then, if I figure out why I will post a comment!
-
Hi, I am having the same problem now, if you figured out to target complex number. could you please guide me? I am facing the same eigenproblem now.
-
Ekrem, I would suggest to open a new issue at GitLab (https://gitlab.com/slepc/slepc/).
Please make sure you are using a PETSc/SLEPc build with complex scalars. It would be really helpful if you could attach a minimal example reproducing the issue.
-
Thanks for your response Lisandro, I will try what you suggest.
- Log in to comment