Closed GoogleCodeExporter closed 9 years ago
Here you have example script for solving x**2=4 using a shell matrix. Run it
with:
$ python SNES_MatShell.py -snes_monitor -snes_view
Basically, your previous code had two problems:
1 - DO NOT inherit from MatShell class. This is counter-intuitive, but I've not
found a easy way to support this. Instead, you have to write your class, next
create
an instance of this class, and then set that instance inside your PETSc shell
matrix
(or create a shell matrix and pass the instance).
2 - Your matvec computation was deadly wrong. If your nonlinear problem is
x**2=4,
then J*v = 2*x_i*v, where 'x_i' is the current nonlinear iterate, but 'v' is a
given
vector (it generally changes during the inner linear solver loop). So you have
to
save some way the current nonlinear iterate in your Jacobian routine in order
to
properly define your matvec operation.
Original comment by dalcinl
on 14 Jan 2008 at 7:13
Attachments:
Terrific! Thank you so much!
Yes, I see that the jacobian matvec was wrong. I was more focused on getting the
programming to work out at the time, I guess :)
For anyone else who may care:
You may need to change the '...' expressions seen in dalcinl's example code
with the
':' to run. I needed this, no problem though.
Thanks again!
Frank
Original comment by frank.la...@gmail.com
on 14 Jan 2008 at 7:23
One last thing -- also should be snes.solve(x,b) not (b,x).
Original comment by frank.la...@gmail.com
on 14 Jan 2008 at 9:31
A note about last comment:
- In version 0.7.5 and below, use snes.solve(x,b)
- In current SVN and future versions, use snes.solve(b,x)
Original comment by dalcinl
on 14 Jan 2008 at 9:48
Hi!,
In the current version of petsc4py, what would be the changes to make it work?
Original comment by romveg...@gmail.com
on 20 Apr 2014 at 9:21
See attached, tested with current petsc4py
(https://bitbucket.org/petsc/petsc4py).
Original comment by five...@gmail.com
on 21 Apr 2014 at 12:52
Attachments:
Original issue reported on code.google.com by
frank.la...@gmail.com
on 12 Jan 2008 at 5:50Attachments: