[petsc-users] Non-uniform Cartisian Grid

Barry Smith bsmith at mcs.anl.gov
Thu Feb 28 19:40:16 CST 2013


   Why do you have the -1 at the end of the loops. If you fix that it will run as you would like. Note use a small imax,jmax, and kmax for testing.


    for (k = sk; k < sk+nz-1; k++) {
    for (j = sj; j < sj+ny-1; j++) {
      for (i = si; i < si+nx-1; i++) {


On Feb 28, 2013, at 6:19 PM, "Zhenglun (Alan) Wei" <zhenglun.wei at gmail.com> wrote:

> Dear folks,
>    Here are several questions following up my previous ones:
> 1, I modified my code based on ex49.c. However, I found that if I don't call 'DMDASetUniformCoordinates' before calling 'DMDAVecGetArray', then an error comes up:
> [0]PETSC ERROR: Null argument, when expecting valid pointer!
> [0]PETSC ERROR: Null Object: Parameter # 2!
>    The code do works if I add a call for 'DMDASetUniformCoordinates' in it. However, I feel it is a waste of calling 'DMDASetUniformCoordinates' since what follows this calling is to change the coordinate to a non-uniform gird. Does it have any way to bypass this call or you think it is fine to keep it here.
> 
> 2, Also, if I do by this way, the outputted mesh looks weird, as shown in the figure.
>    I was trying to double the dy value manually in the SetNonUniformGrid(). However, the only mesh changed is just on the z=0 and x=0 plane. Here I attached my code. Do I need to do anything else except DMDAVecRestoreArray() after I modified the coordinate information?
> 
> thanks,
> Alan
> 
> 
> On 2/26/2013 8:46 PM, Barry Smith wrote:
>> On Feb 26, 2013, at 4:49 PM, "Zhenglun (Alan) Wei"<zhenglun.wei at gmail.com>  wrote:
>> 
>>> Dear folks,
>>>      I have one question for the ex49.
>>>      It do show a way to 'get' the 'coord' by the 'DMDAVecGetArray'. Should I just modified the coordinate on the 'coord' in order to obtain a non-uniform grid? and then, use DMDAVecRestoreArray to link the modified 'coord' back to 'cda' so that the 'coord' will be updated to the mesh I want?
>>    Yes, you can do this.
>> 
>> 
>>> thanks,
>>> Alan
>>> 
>>> On 2/22/2013 3:20 PM, Matthew Knepley wrote:
>>>> On Fri, Feb 22, 2013 at 3:57 PM, Zhenglun (Alan) Wei<zhenglun.wei at gmail.com>  wrote:
>>>> Dear all,
>>>> I hope you're having a nice day.
>>>> I wonder if anyone could point out a example for me about the
>>>> DMDASetCoordinates(). I found this
>>>> (http://www.mcs.anl.gov/petsc/petsc-current/src/dm/impls/da/dacorn.c.html#DMDASetCoordinates)
>>>> online; however it does not really demonstrate how to create the
>>>> 'coordinate vector - c'.
>>>> Also, I found that in the petsc sub-folder:
>>>> /petsc-dev/src/dm/impls/patch has a patch.c, which I suppose that it
>>>> does a local refinement for mesh. Does this a mature model that we can
>>>> use or just a testing code?
>>>> 
>>>> Look at KSP ex49. In the routine DMDACoordViewGnuplot2d() it reads out the coordinates.
>>>> You could just as easily set them in this fashion.
>>>> 
>>>>    Matt
>>>>  thanks,
>>>> Alan
>>>> 
>>>> On 11/7/2012 6:55 PM, Barry Smith wrote:
>>>>> On Nov 7, 2012, at 6:50 PM, Alan<zhenglun.wei at gmail.com>  wrote:
>>>>> 
>>>>>> Dear folks,
>>>>>> I hope you're having a nice day.
>>>>>> I'm testing the Poisson solver in /src/ksp/ksp/examples/tutorials/ex45.
>>>>>> It uses the 'DMDACreate3d' to generate a Cartisian structured grid and
>>>>>> solve it with uniform grid size. However, I attempt to modify it to
>>>>>> obtain solution with a Cartsian structured grid and non-uniform grid (It
>>>>>> is not unstructured local refined mesh). Should I still use the
>>>>>> 'DMDACreate3d' and implement different grid size in 'ComputeMatrix' and
>>>>>> 'ComputeRHS'? In other words, does 'DMDACreate3d' itself include any
>>>>>> mesh size information?
>>>>>    You can use DMDASetCoordinates() and DMDAGetCoordinates() (called DMSetCoordinates() and DMGetCoordinates() in petsc-dev) to keep track of the coordinates but you are responsible for generating the correctly scaled entries in the matrix etc.
>>>>> 
>>>>>    Barry
>>>>> 
>>>>>> thanks,
>>>>>> Alan
>>>> 
>>>> 
>>>> -- 
>>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
>>>> -- Norbert Wiener
> 
> <export.jpg><Test.zip>



More information about the petsc-users mailing list