When using MatSetValuesStencil() for dof > 1 note that
typedef struct {
PetscInt k,j,i,c;
} MatStencil;
For dof > 1 you need to assign the k,j,i AND c value. (c corresponds to the
dof) for each entry you put in the matrix. For example
row[0].k = 2; row[0].j=3; row[0].i= 9; row[0].c = 1 (this is for the second dof
at the grid point 9,3,2) c=0 is for the first dof
Only use the blocked stencil form if you really have blocks of non zeros in
the matrix (i.e. all the dof are fully coupled with each other and the
neighboring points).
Barry
On Sep 20, 2014, at 12:55 AM, Feng Shi <[email protected]> wrote:
> I'm sorry I've no idea on the finite element, but for the finite difference,
> say for a 3-D case, we could use 7-point differentiation method, so the
> routine would be MatSetValuesStencil(A_mat, 1, &row, 7, col, val,
> INSERT_VALUES). I know 7 denotes the 7-points in space for differentiation
> and array val[0:6]. If I use MatSetValuesBlockedStencil, am I right using
> MatSetValuesBlockedStencil(A_mat, 1, &row, 7, col, val, INSERT_VALUES), where
> array is val[0:1][0:7] for dof=2?
>
> Best regards,
>
> ________________________________________
> From: Jed Brown [[email protected]]
> Sent: Saturday, September 20, 2014 1:16 AM
> To: Feng Shi; [email protected]
> Subject: Re: [petsc-users] How to set matrix values using
> "MatSetValuesStencil" when dof>1 idxn -
>
> Feng Shi <[email protected]> writes:
>
>> Hi Folks,
>>
>> I get hard times in using the routine MatSetValuesStencil for
>> dof>1. There numerous examples for dof=1 but dof>1, neither in the
>> Petsc manual. The routine on-line manual
>> (http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesStencil.html)
>> says, idxm/idxn are grid coordinates (and component number when dof > 1)
>> for matrix columns being entered. What is the general form of these indices?
>
> If you have dof>1, please use MatSetValuesBlockedStencil. See
> src/snes/examples/tutorials/ex48.c for an example usage for a
> finite-element method.
>
>> Am I right, for example, for idxn, if I write idxn[ix, dof].i?
>
> That's not valid syntax, so I don't know what you're asking.