<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [petsc-users] Providing matrix vector product yourself for matrix free in SNES</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi Matt,<BR>
<BR>
Thanks, this is working. The only problem I still have is that I have to store much more than just a vector in context of MATSHELL in order to carry out the matrix vector multiplication. I basically need all the contents of an object of a certain class. I tried to store the this pointer of the object in the context of MATSHELL, but then I get an error. So it looks like it is not allowed to pass the this pointer to MatShellSetContext, is that correct?<BR>
<BR>
My current workaround is to use a global variable. That works, but I don't like to use global variables. Is there a better way to make available a pointer to an object in MATSHELL?<BR>
<BR>
Thanks again,<BR>
<BR>
Edwin<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: petsc-users-bounces@mcs.anl.gov on behalf of Matthew Knepley<BR>
Sent: Tue 12/20/2011 3:46 PM<BR>
To: PETSc users list<BR>
Subject: Re: [petsc-users] Providing matrix vector product yourself for matrix free in SNES<BR>
<BR>
On Tue, Dec 20, 2011 at 7:24 AM, <E.T.A.vanderWeide@utwente.nl> wrote:<BR>
<BR>
> **<BR>
><BR>
> Hi,<BR>
><BR>
> I was wondering if it is possible to provide PETSc the matrix vector<BR>
> product yourself for a matrix free computation inside the SNES environment.<BR>
> The reason for asking is that the truncation error in the standard finite<BR>
> difference approach may lead to some noisy behavior for our application. We<BR>
> have found a nice way to get rid off the truncation error completely by<BR>
> using dual numbers for the creation of the Jacobian matrices. The same<BR>
> technique can be used for the matrix vector product inside SNES, but this<BR>
> means that the user has to provide this product to PETSc.<BR>
><BR>
> To be more specific. I would like to solve the nonlinear problem F(U) = 0<BR>
> via the SNES environment using the matrix free option. So similarly to the<BR>
> function SNESSetFunction, which sets the function evaluation routine, I'm<BR>
> seeking for a function that sets the function to compute the matrix vector<BR>
> product dF/dU times V, where U and V are inputs. Is such a function<BR>
> available or is there a different way to provide the matrix vector product<BR>
> yourself?<BR>
><BR>
No need to use the matrix-free option. Just provide a MATSHELL (<BR>
<A HREF="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateShell.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateShell.html</A><BR>
)<BR>
as the Jacobian using SNESSetJacobian(). Then your FormJacobian() function<BR>
will get a vector 'x' as input. Update the context for the MATSHELL with<BR>
this vector in that function, which is all it would really do. Then when<BR>
the MatMult() is called on your shell matrix, compute the action using that<BR>
'x'<BR>
which is stored in the context.<BR>
<BR>
Matt<BR>
<BR>
<BR>
> Thanks,<BR>
><BR>
> Edwin<BR>
> ---------------------------------------------------<BR>
> Edwin van der Weide<BR>
> Department of Mechanical Engineering<BR>
> University of Twente<BR>
> Enschede, the Netherlands<BR>
><BR>
<BR>
<BR>
<BR>
--<BR>
What most experimenters take for granted before they begin their<BR>
experiments is infinitely more interesting than any results to which their<BR>
experiments lead.<BR>
-- Norbert Wiener<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>