Sorry for the long delay in getting back to you. I think there is not 
directly a problem with the code; rather, with these Q0 elements, Galerkin is 
not a good approach.
I went back to src/ksp/ksp/tutorials/ex32.c and ran a little deeper and noticed 
that when running without Galerkin it gives very good, expected convergence. 
But with Galerkin it does not.  I had to make some fixes in refinement for DMDA 
to run how I wanted they are in the branch in 
https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/7940__;!!G_uCfscf7eWS!fXCpNUu10XTTCmVzPF3jsEz72QFuFGPkzeF0He6viicBt934KYfgROb3ncB2BZnfEMWRwJnoelHdOTKlzPHkaiU$
 

  So I think the correct answer is for you to not use Galerkin but instead 
discretize on each level the matrix as is done in ex32.c 

  For this to work in your code you will need to change how you scale the 
matrix (and right hand side) you generate, see ComputeMatrix() in ex32.c Note
how the matrix entries have the scaling HxdHy etc. Similarly the RHS has the 
scaling by Hx for Hy.  Also DMStag uses .25 in the interpolation but DMDA uses 
1;  I am not sure why the 1 that DMDA uses works, but if you rescale your 
matrices and right hand side and don't get use Galerkin and still get poor 
convergence then try different scaling for the interpolation. 

Here is the performance for ex32. Note how fantastic it is, I think you should 
be virtually the same.

/ex32 -pc_type mg -pc_mg_levels 5 -ksp_monitor_true_residual -ksp_rtol 1.e-10 
-ksp_type cg -pc_mg_galerkin none -mg_levels_pc_type sor -mg_levels_ksp_type 
richardson -mg_levels_ksp_max_it 2 -mg_coarse_pc_type svd  -da_refine 5
  0 KSP preconditioned resid norm 8.707575268782e-01 true resid norm 
2.842788112864e-03 ||r(i)||/||b|| 1.000000000000e+00
  1 KSP preconditioned resid norm 5.067478574947e-03 true resid norm 
8.807970167024e-05 ||r(i)||/||b|| 3.098356197273e-02
  2 KSP preconditioned resid norm 5.566700402730e-05 true resid norm 
2.014981529883e-06 ||r(i)||/||b|| 7.088046839529e-04
  3 KSP preconditioned resid norm 2.698851702073e-07 true resid norm 
3.013479554557e-08 ||r(i)||/||b|| 1.060043673646e-05
  4 KSP preconditioned resid norm 2.689594854129e-09 true resid norm 
2.536151839771e-10 ||r(i)||/||b|| 8.921353752308e-08
  5 KSP preconditioned resid norm 2.232993540537e-11 true resid norm 
2.360948191859e-12 ||r(i)||/||b|| 8.305044548259e-10

Barry



> On Oct 8, 2024, at 2:09 PM, Gautam Luhana <gkluh...@cs.ubc.ca> wrote:
> 
> Hi Barry,
> 
> Did you get time to look through the code and see where the issue might be?
> 
> Regards,
> Gautam
> 
> On 2024-10-02 11:58 a.m., Gautam Luhana wrote:
>> Hi Barry,
>> 
>> I've stripped away the multiphyics functionality and put the remaining 
>> stokes part in the repo here:
>> 
>> https://urldefense.us/v3/__https://github.com/gkluhana/stokesToy__;!!G_uCfscf7eWS!fXCpNUu10XTTCmVzPF3jsEz72QFuFGPkzeF0He6viicBt934KYfgROb3ncB2BZnfEMWRwJnoelHdOTKl4GWg6pc$
>>  
>> 
>> Let me know if you have trouble accessing the code.
>> 
>> I apologize for old routines/multiphysics functionality that may still be 
>> there.
>> 
>> Thanks & Regards,
>> Gautam
>> 

Reply via email to