<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hello,<br>
I want to solve a linear system with conjugate gradient and multigrid preconditioner. I am using petsc4py. The solution is a Vector of type NEST and the operator is a matrix-free operator created using PETSc.Mat().createPython. The restriction and interpolation
 operators are all type NEST and their VecType is set to NEST. As smoother I am using CG without preconditioner. For the moment I am just using a classical V-cycle with 2 levels.
<br>
<br>
I am able to solve the system with CG without the MG preconditioner. However, when I try to solve it with the MG preconditioner, it throws this error:<br>
<br>
Traceback (most recent call last):<br>
  File "/home/elena-hp/code/Poisson_MG_Petsc.py", line 321, in <module><br>
    solver.solve(b, u)<br>
  File "petsc4py/PETSc/KSP.pyx", line 1782, in petsc4py.PETSc.KSP.solve<br>
petsc4py.PETSc.Error: error code 62<br>
[0] KSPSolve() at /home/elena-hp/petsc/src/ksp/ksp/interface/<a class="moz-txt-link-freetext" href="">itfunc.c:1089</a><br>
[0] KSPSolve_Private() at /home/elena-hp/petsc/src/ksp/ksp/interface/<a class="moz-txt-link-freetext" href="">itfunc.c:912</a><br>
[0] KSPSolve_CG() at /home/elena-hp/petsc/src/ksp/ksp/impls/cg/<a class="moz-txt-link-freetext" href="">cg.c:213</a><br>
[0] KSP_PCApply() at /home/elena-hp/petsc/include/petsc/private/<a class="moz-txt-link-freetext" href="">kspimpl.h:414</a><br>
[0] PCApply() at /home/elena-hp/petsc/src/ksp/pc/interface/<a class="moz-txt-link-freetext" href="">precon.c:528</a><br>
[0] PCApply_MG() at /home/elena-hp/petsc/src/ksp/pc/impls/mg/<a class="moz-txt-link-freetext" href="">mg.c:651</a><br>
[0] PCApply_MG_Internal() at /home/elena-hp/petsc/src/ksp/pc/impls/mg/<a class="moz-txt-link-freetext" href="">mg.c:629</a><br>
[0] PCMGMCycle_Private() at /home/elena-hp/petsc/src/ksp/pc/impls/mg/<a class="moz-txt-link-freetext" href="">mg.c:27</a><br>
[0] KSPSolve() at /home/elena-hp/petsc/src/ksp/ksp/interface/<a class="moz-txt-link-freetext" href="">itfunc.c:1089</a><br>
[0] KSPSolve_Private() at /home/elena-hp/petsc/src/ksp/ksp/interface/<a class="moz-txt-link-freetext" href="">itfunc.c:912</a><br>
[0] KSPSolve_CG() at /home/elena-hp/petsc/src/ksp/ksp/impls/cg/<a class="moz-txt-link-freetext" href="">cg.c:162</a><br>
[0] VecCopy() at /home/elena-hp/petsc/src/vec/vec/interface/<a class="moz-txt-link-freetext" href="">vector.c:1796</a><br>
[0] VecCopyAsync_Private() at /home/elena-hp/petsc/src/vec/vec/interface/<a class="moz-txt-link-freetext" href="">vector.c:1755</a><br>
[0] VecCopy_Nest() at /home/elena-hp/petsc/src/vec/vec/impls/nest/<a class="moz-txt-link-freetext" href="">vecnest.c:56</a><br>
[0] Invalid argument<br>
[0] Nest vector argument 2 not setup.<br>
<br>
The error does not appear when the operator is also of type NEST and the VecType is set to NEST. Unfortunately, for my application I cannot write the operator as type NEST.<br>
<br>
I think that the problem is related to the fact that the method createVecs() of the matrix-free operator does not return NEST vectors. I tried to do setVecType(PETSc.Vec.Type.NEST) on the matrix-free operator but when I call createVecs() it throws this error:<br>
<br>
Traceback (most recent call last):<br>
  File "petsc4py/PETSc/libpetsc4py.pyx", line 965, in petsc4py.PETSc.MatCreateVecs_Python<br>
petsc4py.PETSc.Error: error code 86<br>
[0] MatCreateVecs() at /home/elena-hp/petsc/src/mat/interface/<a class="moz-txt-link-freetext" href="">matrix.c:9557</a><br>
[0] VecSetType() at /home/elena-hp/petsc/src/vec/vec/interface/<a class="moz-txt-link-freetext" href="">vecreg.c:140</a><br>
[0] Unknown type. Check for miss-spelling or missing package: <a class="moz-txt-link-freetext" href="https://urldefense.us/v3/__https://petsc.org/release/install/install/*external-packages__;Iw!!G_uCfscf7eWS!dEBOuSXxIqEDpI33Xza0TlRPC5n6sN3fXNslohXzfITEmMwZLwQWJUTyNE-mMJHiXZjxQ-OlWu5625crKTR81qTlPMyhvkR09mUB$">
https://petsc.org/release/install/install/#external-packages</a><br>
[0] Unknown vector type: nest</p>
<p>The above exception was the direct cause of the following exception:<br>
<br>
Traceback (most recent call last):<br>
  File "<string>", line 1, in <module><br>
  File "petsc4py/PETSc/Mat.pyx", line 3411, in petsc4py.PETSc.Mat.createVecs<br>
petsc4py.PETSc.Error: error code 101<br>
[0] MatCreateVecs() at /home/elena-hp/petsc/src/mat/interface/<a class="moz-txt-link-freetext" href="">matrix.c:9552</a><br>
<br>
Do you know how to fix this? </p>
<p>Thank you in advance.<br>
<br>
Regards,<br>
Elena<br>
</p>
</div>
</body>
</html>