[petsc-users] difference between DMDAVecGetArrayDOF and DMDAVecGetArray?

Barry Smith bsmith at mcs.anl.gov
Sat Feb 28 14:47:58 CST 2015


> On Feb 28, 2015, at 1:50 PM, Gideon Simpson <gideon.simpson at gmail.com> wrote:
> 
> Supposing that I do not have a priori information as to the number of degrees of freedom per DA vertex; I want the number of mesh points along each sample path to be variable.  Hence, I can’t really use a statically defined structure as you suggest.  In that case, are the DOF routines the only option?

  Yes. Because the DMDAVecGetArray() requires you make a struct in the final "coordinate" of the correct size, which, of course, since it is a struct must be defined at compile time.   In fact DMDAVecGetArrayDOF() was written for you case and there is no reason or logic to use DMDAVecGetArray() then.

  Barry

> 
> -gideon
> 
>> On Feb 28, 2015, at 2:42 PM, Matthew Knepley <knepley at gmail.com> wrote:
>> 
>> On Sat, Feb 28, 2015 at 1:35 PM, Gideon Simpson <gideon.simpson at gmail.com> wrote:
>> I’m having some trouble understanding what the difference between these two routines are, though I am finding that there certainly is a difference.  I have the following monte carlo problem.  I am generating n_sample paths each of length n_points, and storing them in a 1D DA:
>> 
>> DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE, n_samples, n_points, 0, NULL, &da);
>> DMCreateGlobalVector(da,&paths_vec);
>> 
>> When I then go to access them,
>> 
>> PetscScalar **u_array;
>> 
>> I find that:
>> 
>> DMDAVecGetArrayDOF(da, paths_vec, &u_array);
>> 
>> works as exepected, in that u_array[i] is a pointer to the first index of the i-th sample path, but if I call:
>> 
>> DMDAVecGetArray(da, paths_vec, &u_array);
>> 
>> u_array[i] is something else, and my attempts to manipulate it result in segmentation faults, even though the code compiles and builds.
>> 
>> Suppose that you have 4 PetscScalar values at each vertex of the 1D DMDA. If you use 
>> 
>>   PetscScalar **u;
>> 
>>   DMDAVecGetArrayDOF(da, uVec, &u);
>> 
>>   u[i][2] /* refers to 3rd scalar on vertex i */
>> 
>> On the other hand you could use
>> 
>> typedef struct {
>>   PetscScalar a, b, c, d;
>> } Vals;
>> 
>>  Vals *u;
>> 
>>  DMDAVecGetArray(da, uVec, &u);
>> 
>>  u[i].c /* refers to the same value as above */
>> 
>> Basically the DOF version gives you an extra level of indirection for the components.
>> 
>>   Thanks,
>> 
>>      Matt
>>  
>> 
>> -gideon
>> 
>> 
>> 
>> 
>> -- 
>> 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