<div dir="ltr"><div dir="ltr">Dear all,<div><br></div><div>I am using petsc4py and can't seem to figure out an issue.</div><div>I need to solve the linear system KU = P, and K and U are correctly set up, and using default ksp solvers i can easily solve the system. However, I am trying to solve with pcmg and have two issues:</div><div>a) I get 'PETSC Error code 73 - object is in wrong state' when i try to solve or setup the ksp.</div><div>b) What is the petsc4py equivalent to PCMGSetGalerkin? Can't seem to figure it out.</div><div><br></div><div>Below is how I set up the solver, next is the error message, and lastly is the result from KSPView()</div><div><br></div><div>Thanks in advance for any help you can provide!</div><div><br></div><div><u>THE CODE:</u></div><div><div><font face="arial, helvetica, sans-serif">        RTOL = 1.0e-5</font></div><div><font face="arial, helvetica, sans-serif">        ATOL = 1.0e-50</font></div><div><font face="arial, helvetica, sans-serif">        DTOL = 1.0e3</font></div><div><font face="arial, helvetica, sans-serif">        MAXITSGLOBAL = 200</font></div><div><font face="arial, helvetica, sans-serif">        COARSE_RTOL = 1.0e-8</font></div><div><font face="arial, helvetica, sans-serif">        COARSE_ATOL = 1.0e-50</font></div><div><font face="arial, helvetica, sans-serif">        COARSE_DTOL = 1e3</font></div><div><font face="arial, helvetica, sans-serif">        COARSE_MAXITS = 30</font></div><div><font face="arial, helvetica, sans-serif">        COARSE_RESTART = 30</font></div><div><font face="arial, helvetica, sans-serif">        SMOOTH_SWEEPS = 4</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Fine grid Krylov Method</font></div><div><font face="arial, helvetica, sans-serif">        self.ksp = petsc.KSP().create()</font></div><div><font face="arial, helvetica, sans-serif">        self.ksp.setType('fgmres')</font></div><div><font face="arial, helvetica, sans-serif">        self.ksp.setTolerances(rtol=RTOL, atol=ATOL, divtol=DTOL, max_it=MAXITSGLOBAL)</font></div><div><font face="arial, helvetica, sans-serif">        self.ksp.setInitialGuessNonzero(True)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Set operators</font></div><div><font face="arial, helvetica, sans-serif">        self.ksp.setOperators(mesh.K, mesh.K)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Get Preconditioner and set it up</font></div><div><font face="arial, helvetica, sans-serif">        pc = self.ksp.getPC()</font></div><div><font face="arial, helvetica, sans-serif">        pc.setType('mg')</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        self.ksp.setFromOptions()</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Set all levels in the PCMG (zeroth entry is finest level):</font></div><div><font face="arial, helvetica, sans-serif">        da_list = list()</font></div><div><font face="arial, helvetica, sans-serif">        da_list.append(mesh.da_nodes)</font></div><div><font face="arial, helvetica, sans-serif">        da_list.extend([da_obj for da_obj in mesh.da_nodes.coarsenHierarchy(3)])</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # PCMG specific options</font></div><div><font face="arial, helvetica, sans-serif">        pc.setMGLevels(mesh.mg_levels)</font></div><div><font face="arial, helvetica, sans-serif">        pc.setMGType(0)  # multiplicative</font></div><div><font face="arial, helvetica, sans-serif">        pc.setMGCycleType(1)  # v</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        for k in range(1, mesh.mg_levels):</font></div><div><font face="arial, helvetica, sans-serif">            r, _ = da_list[k].createInterpolation(da_list[k-1])</font></div><div><font face="arial, helvetica, sans-serif">            pc.setMGInterpolation(k, r)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Avoid the default for the mg part</font></div><div><font face="arial, helvetica, sans-serif">        cksp = pc.getMGCoarseSolve()</font></div><div><font face="arial, helvetica, sans-serif">        cksp.setType('gmres')</font></div><div><font face="arial, helvetica, sans-serif">        cksp.setGMRESRestart(COARSE_RESTART)</font></div><div><font face="arial, helvetica, sans-serif">        cksp.setTolerances(rtol=COARSE_RTOL, atol=COARSE_ATOL, divtol=COARSE_DTOL, max_it=COARSE_MAXITS)</font></div><div><font face="arial, helvetica, sans-serif">        cpc = cksp.getPC()</font></div><div><font face="arial, helvetica, sans-serif">        cpc.setType('sor')</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">        # Set smoothers on all levels</font></div><div><font face="arial, helvetica, sans-serif">        for k in range(1, mesh.mg_levels):</font></div><div><font face="arial, helvetica, sans-serif">            dksp = pc.getMGSmoother(k)</font></div><div><font face="arial, helvetica, sans-serif">            dpc = dksp.getPC()</font></div><div><font face="arial, helvetica, sans-serif">            dksp.setType('gmres')</font></div><div><font face="arial, helvetica, sans-serif">            dksp.setGMRESRestart(SMOOTH_SWEEPS)</font></div><div><font face="arial, helvetica, sans-serif">            dksp.setTolerances(max_it=SMOOTH_SWEEPS)</font></div><div><font face="arial, helvetica, sans-serif">            dpc.setType('sor')</font></div></div><div><br></div><div><u><br></u></div><div><u>The Error:</u></div><div><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">petsc4py.PETSc.Error: error code 73</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] KSPSolve() line 725 in
/tmp/pip-req-build-goqa79r0/src/ksp/ksp/interface/itfunc.c</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] KSPSetUp() line 391 in /tmp/pip-req-build-goqa79r0/src/ksp/ksp/interface/itfunc.c</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] PCSetUp() line 932 in
/tmp/pip-req-build-goqa79r0/src/ksp/pc/interface/precon.c</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] PCSetUp_MG() line 819 in
/tmp/pip-req-build-goqa79r0/src/ksp/pc/impls/mg/mg.c</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] KSPCreateVecs() line 947 in
/tmp/pip-req-build-goqa79r0/src/ksp/ksp/interface/iterativ.c</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] Object is in wrong state</font></p>

<p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif">[0] You requested a vector from a KSP that cannot provide one</font></p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif"><br></font></p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt"><font face="arial, helvetica, sans-serif"><u>The KSPView():</u></font></p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">KSP Object: 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  type: fgmres</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    restart=30, using
Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative
refinement</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    happy breakdown
tolerance 1e-30</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  maximum
iterations=200, nonzero initial guess</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  tolerances:  relative=1e-05, absolute=1e-50,
divergence=1000.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  left preconditioning</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  using DEFAULT norm
type for convergence test</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">PC Object: 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  type: mg</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  PC has not been set
up so information may be incomplete</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    type is
MULTIPLICATIVE, levels=4 cycles=v</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      Cycles per
PCApply=1</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      Not using
Galerkin computed coarse grid matrices</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Coarse grid solver --
level -------------------------------</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    KSP Object:
(mg_coarse_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: gmres</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        restart=30,
using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative
refinement</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        happy breakdown
tolerance 1e-30</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      maximum
iterations=30, initial guess is zero</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      tolerances:  relative=1e-08, absolute=1e-50,
divergence=1000.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      left
preconditioning</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      using DEFAULT
norm type for convergence test</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    PC Object:
(mg_coarse_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: sor</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      PC has not been set up so information may be
incomplete</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        type =
local_symmetric, iterations = 1, local iterations = 1, omega = 1.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Down solver
(pre-smoother) on level 1 -------------------------------</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    KSP Object:
(mg_levels_1_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: gmres</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        restart=4,
using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative
refinement</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        happy breakdown
tolerance 1e-30</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      maximum
iterations=4, initial guess is zero</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      tolerances:  relative=1e-05, absolute=1e-50,
divergence=10000.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      left
preconditioning</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      using NONE norm
type for convergence test</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    PC Object:
(mg_levels_1_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: sor</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      PC has not been
set up so information may be incomplete</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        type = local_symmetric,
iterations = 1, local iterations = 1, omega = 1.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Up solver
(post-smoother) same as down solver (pre-smoother)</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Down solver
(pre-smoother) on level 2 -------------------------------</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    KSP Object:
(mg_levels_2_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: gmres</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        restart=4,
using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative
refinement</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        happy breakdown
tolerance 1e-30</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      maximum
iterations=4, initial guess is zero</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      tolerances:  relative=1e-05, absolute=1e-50,
divergence=10000.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      left
preconditioning</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      using NONE norm
type for convergence test</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    PC Object:
(mg_levels_2_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: sor</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      PC has not been
set up so information may be incomplete</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        type =
local_symmetric, iterations = 1, local iterations = 1, omega = 1.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Up solver
(post-smoother) same as down solver (pre-smoother)</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Down solver
(pre-smoother) on level 3 -------------------------------</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    KSP Object:
(mg_levels_3_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: gmres</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        restart=4,
using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative
refinement</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        happy breakdown
tolerance 1e-30</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      maximum
iterations=4, initial guess is zero</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      tolerances:  relative=1e-05, absolute=1e-50,
divergence=10000.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      left
preconditioning</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      using NONE norm
type for convergence test</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    PC Object:
(mg_levels_3_) 1 MPI processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      type: sor</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      PC has not been
set up so information may be incomplete</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">        type =
local_symmetric, iterations = 1, local iterations = 1, omega = 1.</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Up solver
(post-smoother) same as down solver (pre-smoother)</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  linear system matrix
= precond matrix:</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">  Mat Object: 1 MPI
processes</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    type: seqaij</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    rows=4131,
cols=4131, bs=3</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    total:
nonzeros=275625, allocated nonzeros=275625</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">    total number of
mallocs used during MatSetValues calls =0</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt">





















































































































































</p><p class="gmail-Standard" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Liberation Serif",serif">      using I-node
routines: found 1377 nodes, limit used is 5</p></div><div><u><br></u></div></div></div>