[petsc-users] KSPSetComputeRHS and KSPSetComputeOperators

iwaddington . iwaddington at gmail.com
Thu Nov 21 19:08:49 CST 2013


Thanks Matthew, but how exactly do I do that in a user defined function of
the form used by KSPSetComputeOperators:

#undef __FUNCT__
#define __FUNCT__ "ComputeMatrix"
PetscErrorCode ComputeMatrix(KSP ksp, Mat J,Mat jac,MatStructure *str, void
*ctx)
{

/* variables */

  PetscFunctionBeginUser;

/* Setting the system linear matrix J*/

/* Now I want to set jac=J which is the preconditioning matrix in this part
, my first idea was to use matcopy, but I would like something more
efficient */

 PetscFunctionReturn(0);

}




On Thu, Nov 21, 2013 at 10:26 PM, Matthew Knepley <knepley at gmail.com> wrote:

> On Thu, Nov 21, 2013 at 6:21 PM, iwaddington . <iwaddington at gmail.com>wrote:
>
>> Sorry Matthew, but I didn't understand what you said, because it is not
>> the case of passing arguments to a function, I have to write the function
>> which I will later pass to KSPSetComputeOperators, and in the function I
>> have to set the system linear matrix and preconditioning matrix.
>>
>
> You can return the same matrix for the system and preconditioner.
>
>    Matt
>
>
>> On Thu, Nov 21, 2013 at 10:00 PM, Matthew Knepley <knepley at gmail.com>wrote:
>>
>>> On Thu, Nov 21, 2013 at 5:44 PM, iwaddington . <iwaddington at gmail.com>wrote:
>>>
>>>> HI everybody, I have a doubt concerning how the function
>>>> KSPSetComputeRHS works, because according to its prototype one of its
>>>> arguments is a pointer to a function that takes a vector object as
>>>> argument, not a pointer towards a vector object, so how is it able to set
>>>> the rhs if the passage of the vector is done by value and not by reference ?
>>>>
>>>
>>> The values of the Vec can be set, rather than changing the object
>>> pointer itself.
>>>
>>>
>>>> Another thing is the functioning of KSPSetComputeOperators. I want to
>>>> set the linear system matrix and I want the preconditioning matrix to be
>>>> equal, so can I just set the linar system matrix in the function that is
>>>> argument of KSPSetComputeOperators, or do I need to make a matcopy in it ?
>>>>
>>>
>>> No, just give the same argument twice.
>>>
>>>    Matt
>>>
>>> --
>>> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131121/439a2cc6/attachment-0001.html>


More information about the petsc-users mailing list