[petsc-users] Declaring struct to represent field for dof > 1 for DM in Fortran

Barry Smith bsmith at mcs.anl.gov
Tue Jul 10 21:22:53 CDT 2012


On Jul 10, 2012, at 11:05 AM, Matthew Knepley wrote:

>> 
>>    Matt
> Ok, I'll try to use another mtd. 
> 
> Btw, if I declare:
> 
> PetscScalar,pointer :: array2(:,:,:)
> 
> with DMDACreate2d using dof = 2,
> 
> call DMDAVecGetArrayF90(da,x_local,array2,ierr)
> 
> access array2 ....
> 
> call DMDAVecRestoreArrayF90(da,x_local,array2,ierr)
> 
> How is the memory for "array2" allocated ? Is it allocated all the time, or only between the DMDAVecGetArrayF90 and DMDAVecRestoreArrayF90?

   It is ALWAYS allocated and the actual memory is inside the Vec object.  The array2 is just a fancy pointer that allows accessing that underlying data.

> 
> Also, can I "reuse" array2? For e.g., now for y_local:
> 
> call DMDAVecGetArrayF90(da,y_local,array2,ierr)
> 
> access array2 .... 
> 
> call DMDAVecRestoreArrayF90(da,y_local,array2,ierr) 

   Yes

> 
> The right thing to do here is to implement DMDAVecGetArratDOFF90().

   You do NOT need DMDAVecGetArrayDOFF90(). This is one place where Fortran polymorphism is actually more user friendly than C's (shock of shocks). 

    The code you provide above with dof = 2 should work fine. See src/dm/examples/tutorials/ex11f90.F (the second half of the example).

    So you are all set to write the code you wanted. 

   Barry



> 
>     Matt
>  
> Thank you!
> 
>>  
>> I'm using Fortran and for testing, I use dof = 1 and write as:
>> 
>> type field
>> 
>>     PetscScalar u        (or real(8) :: u)
>> 
>> end type field
>> 
>> type(field), pointer :: field_u(:,:)
>> 
>> When I tried to use :
>> 
>> call DMDAVecGetArrayF90(da,x_local,field_u,ierr)
>> 
>> I got the error : There is no matching specific subroutine for this generic subroutine call.   [DMDAVECGETARRAYF90]
>> 
>> The da, x_local has been defined with the specific DM routines. It worked if I use :
>> 
>> PetscScalar,pointer :: array(:,:) and
>> 
>> call DMDAVecGetArrayF90(da,x_local,array,ierr)
>> 
>> May I know what did I do wrong?
>> 
>> 
>> -- 
>> Yours sincerely,
>> 
>> TAY wee-beng
>> 
>> 
>> 
>> 
>> -- 
>> 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
> 
> 
> 
> 
> 
> -- 
> 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



More information about the petsc-users mailing list