[petsc-users] Problems ablout setting up variables and SNES

Smith, Barry F. bsmith at mcs.anl.gov
Thu Sep 20 16:21:37 CDT 2018



    Yingjie,

     Sorry no one responded earlier to your query. 

      What you would like to do (have three field variables plus a single variable) as your unknowns in a nonlinear system is possible in PETSc but cumbersome to implement unfortunately. So first I urge you to consider alternatives that do not require the simultaneous solution of such a system. 

      If you try to setup a system that involves a single degree of freedom plus your field variables you will need to use DMCOMPOSITE. There are three examples that do this in src/snes/examples/tutorials/ ex21.c ex22.c ex28.c 

   Good luck

    Barry


> On Sep 17, 2018, at 3:22 AM, Yingjie Wu <yjwu16 at gmail.com> wrote:
> 
> Dear Petsc developer:            
> Hi, 
> Thank you very much for your previous reply, recently I encountered some problems in the implementation of the program.
> 
> 1. Previously I used DMDA to create distributed variables (Variables are different in each grids). Now I want to add a single variable (independent of the grid). How do I add it? How do I write programs with distributed variables and single variables exist at the same time? 
> 
> I've created three "Field" variables before, and I'd like to add a single variable. How should I describe it in the program? The codes are as below.
> 
> ierr=DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,10,10,PETSC_DECIDE,PETSC_DECIDE,3,1,0,0,&da);CHKERRQ(ierr);
> 
>   ierr = DMSetFromOptions(da);CHKERRQ(ierr);
> 
>   ierr = DMSetUp(da);CHKERRQ(ierr);
> 
>   ierr = SNESSetDM(snes,(DM)da);CHKERRQ(ierr);
> 
>   ierr = DMDASetFieldName(da,0,"Pressure");CHKERRQ(ierr);
> 
>   ierr = DMDASetFieldName(da,1,"Y-Velocity");CHKERRQ(ierr);
> 
>   ierr = DMDASetFieldName(da,2,"Fluid_temperature");CHKERRQ(ierr);
> 
>   ierr = DMCreateGlobalVector(da,&x);CHKERRQ(ierr);
> 
> 
> 
> 2. At present, I am solving nonlinear equations. Now I need to do one-step nonlinear calculation first, and then treat the results as coefficients for the subsequent nonlinear calculation. Now I used to use SNESSolve() directly to solve the problem. How can we calculate step by step and process the result before entering the next nonlinear step? 
> 
> Since I'm a beginner in PETSc, I would be grateful if there were any examples.
> I'm looking forward to your reply~
> 
> Thanks,
> Yingjie
> 
> 



More information about the petsc-users mailing list