Re: [petsc-users] petsc4py: reuse setup for multiple solver calls?

2018-04-06 Thread Lisandro Dalcin
On 6 April 2018 at 08:48, Robert Speck  wrote:
> Thank you for your answer! Please see below for comments/questions.
>
> On 05.04.18 12:53, Matthew Knepley wrote:
>> On Thu, Apr 5, 2018 at 6:39 AM, Robert Speck >
>> For nonlinear solves which stay the same size, you do nothing.
>
> "nothing" in terms of "nothing you can do" or "nothing you have to do"?
>

I would say "nothing you have to do". Nonlinear solvers work by just
setting two callback routines to compute the residual and the
Jacobian. The user-defined residual routine receives a vector you have
to put values in, same for the Jacobian routine, you have to put
values in the (already preallocated) matrix that is reused on each
newton step, and on each successive solve. SNES will take care of
everything else (in particular, updating the KSP linear solver, and
refreshing the preconditioner, always trying to reuse
already-preallocated internal data structures as much as possible).
All what what I said for SNES applies to TS, in case you ever want to
give it a chance.



-- 
Lisandro Dalcin

Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/

4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa

Office Phone: +966 12 808-0459


Re: [petsc-users] petsc4py: reuse setup for multiple solver calls?

2018-04-06 Thread Dave May
On Fri, 6 Apr 2018 at 07:48, Robert Speck  wrote:

> Thank you for your answer! Please see below for comments/questions.
>
> On 05.04.18 12:53, Matthew Knepley wrote:
> > On Thu, Apr 5, 2018 at 6:39 AM, Robert Speck  > > wrote:
> >
> > Hi!
> >
> > I would like to use petsc4py for my own Python library. Installation
> > went well, first tests (serial and parallel) look good.
> >
> > Here is what I want to do: I have my own time-stepping playground
> and I
> > want petsc4py to be one of my backbones for the data types and
> (linear
> > or non-linear, serial or parallel) solvers. I don't want to use
> PETSc's
> > time-steppers, at least not for now. So, I saw in some examples, in
> > particular the ones shipped with petsc4py, that the standard way of
> > running one of PETSc's solvers is a bunch of setup routines, then
> > setting the right-hand side and solve.
> >
> > Now, I don't want to rerun the whole setup part each time I call the
> > solver. I know that I can change the right-hand side without having
> to
> > do so, but what if I change a parameter of my operator like, say, the
> > time-step size or some material parameter?
> >
> > Take the simplest case: Say I have my own implicit Euler written in
> > Python. I know the right-hand side F of my ODE, so in each step I
> want
> > to solve "I - dt*F". But the time-step changes every now and then,
> so I
> > cannot pre-assemble everything once and for all (or I don't want to).
> > What do I need to rerun before I can use the solver again, what can I
> > reuse? Could I just assemble F and combine it with the identity and
> the
> > parameter dt right before I call the solver? How would that look
> like?
> >
> > I'm pretty new to PETSc and to petsc4py, so please forgive any
> stupidity
> > or ignorance in these questions. I'm happy to take any advice, links
> to
> > examples or previous questions. Thanks!
> >
> >
> > For linear solves which stay the same size, you just have to call
> > SetOperators
> > again with the new operator.
>
> OK, this sounds straightforward. Thanks!
>
> >
> > For nonlinear solves which stay the same size, you do nothing.
>
> "nothing" in terms of "nothing you can do" or "nothing you have to do"?


Nothing you have to do.


>
> >
> > If the system size changes, it generally better to create the object.
>
> What does this mean?


Possibly a typo - Matt is advising to "re-create" the objects if the system
sizes change. Petsc objects are typically not dynamic with respect to their
size (e.g. Mat, Vec), however creating new instances is generally cheap
(matrices can be the exception if you don't preallocate)



>
> Thanks again!
> -Robert-
>
>
>
>
>
>
> 
>
> 
> Forschungszentrum Juelich GmbH
> 52425 Juelich
> Sitz der Gesellschaft: Juelich
> Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
> Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
> Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender),
> Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
> Prof. Dr. Sebastian M. Schmidt
>
> 
>
> 
>
>


Re: [petsc-users] petsc4py: reuse setup for multiple solver calls?

2018-04-05 Thread Robert Speck
Thank you for your answer! Please see below for comments/questions.

On 05.04.18 12:53, Matthew Knepley wrote:
> On Thu, Apr 5, 2018 at 6:39 AM, Robert Speck  > wrote:
>
> Hi!
>
> I would like to use petsc4py for my own Python library. Installation
> went well, first tests (serial and parallel) look good.
>
> Here is what I want to do: I have my own time-stepping playground and I
> want petsc4py to be one of my backbones for the data types and (linear
> or non-linear, serial or parallel) solvers. I don't want to use PETSc's
> time-steppers, at least not for now. So, I saw in some examples, in
> particular the ones shipped with petsc4py, that the standard way of
> running one of PETSc's solvers is a bunch of setup routines, then
> setting the right-hand side and solve.
>
> Now, I don't want to rerun the whole setup part each time I call the
> solver. I know that I can change the right-hand side without having to
> do so, but what if I change a parameter of my operator like, say, the
> time-step size or some material parameter?
>
> Take the simplest case: Say I have my own implicit Euler written in
> Python. I know the right-hand side F of my ODE, so in each step I want
> to solve "I - dt*F". But the time-step changes every now and then, so I
> cannot pre-assemble everything once and for all (or I don't want to).
> What do I need to rerun before I can use the solver again, what can I
> reuse? Could I just assemble F and combine it with the identity and the
> parameter dt right before I call the solver? How would that look like?
>
> I'm pretty new to PETSc and to petsc4py, so please forgive any stupidity
> or ignorance in these questions. I'm happy to take any advice, links to
> examples or previous questions. Thanks!
>
>
> For linear solves which stay the same size, you just have to call
> SetOperators
> again with the new operator.

OK, this sounds straightforward. Thanks!

>
> For nonlinear solves which stay the same size, you do nothing.

"nothing" in terms of "nothing you can do" or "nothing you have to do"?

>
> If the system size changes, it generally better to create the object.

What does this mean?

Thanks again!
-Robert-







Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender),
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt





Re: [petsc-users] petsc4py: reuse setup for multiple solver calls?

2018-04-05 Thread Matthew Knepley
On Thu, Apr 5, 2018 at 6:39 AM, Robert Speck  wrote:

> Hi!
>
> I would like to use petsc4py for my own Python library. Installation
> went well, first tests (serial and parallel) look good.
>
> Here is what I want to do: I have my own time-stepping playground and I
> want petsc4py to be one of my backbones for the data types and (linear
> or non-linear, serial or parallel) solvers. I don't want to use PETSc's
> time-steppers, at least not for now. So, I saw in some examples, in
> particular the ones shipped with petsc4py, that the standard way of
> running one of PETSc's solvers is a bunch of setup routines, then
> setting the right-hand side and solve.
>
> Now, I don't want to rerun the whole setup part each time I call the
> solver. I know that I can change the right-hand side without having to
> do so, but what if I change a parameter of my operator like, say, the
> time-step size or some material parameter?
>
> Take the simplest case: Say I have my own implicit Euler written in
> Python. I know the right-hand side F of my ODE, so in each step I want
> to solve "I - dt*F". But the time-step changes every now and then, so I
> cannot pre-assemble everything once and for all (or I don't want to).
> What do I need to rerun before I can use the solver again, what can I
> reuse? Could I just assemble F and combine it with the identity and the
> parameter dt right before I call the solver? How would that look like?
>
> I'm pretty new to PETSc and to petsc4py, so please forgive any stupidity
> or ignorance in these questions. I'm happy to take any advice, links to
> examples or previous questions. Thanks!
>

For linear solves which stay the same size, you just have to call
SetOperators
again with the new operator.

For nonlinear solves which stay the same size, you do nothing.

If the system size changes, it generally better to create the object. If
that is hard,
then you can use KSPReset().

   Matt


> Kind regards
> -Robert-
>
> --
> Dr. Robert Speck
> Juelich Supercomputing Centre
> Institute for Advanced Simulation
> Forschungszentrum Juelich GmbH
> 52425 Juelich, Germany
>
> Tel: +49 2461 61 1644
> Fax: +49 2461 61 6656
>
> Email:   r.sp...@fz-juelich.de
> Website: http://www.fz-juelich.de/ias/jsc/speck_r
> PinT:http://www.fz-juelich.de/ias/jsc/pint
>
>
>
> 
> 
> 
> 
> Forschungszentrum Juelich GmbH
> 52425 Juelich
> Sitz der Gesellschaft: Juelich
> Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
> Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
> Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender),
> Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
> Prof. Dr. Sebastian M. Schmidt
> 
> 
> 
> 
>
>


-- 
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

https://www.cse.buffalo.edu/~knepley/ 


[petsc-users] petsc4py: reuse setup for multiple solver calls?

2018-04-05 Thread Robert Speck
Hi!

I would like to use petsc4py for my own Python library. Installation
went well, first tests (serial and parallel) look good.

Here is what I want to do: I have my own time-stepping playground and I
want petsc4py to be one of my backbones for the data types and (linear
or non-linear, serial or parallel) solvers. I don't want to use PETSc's
time-steppers, at least not for now. So, I saw in some examples, in
particular the ones shipped with petsc4py, that the standard way of
running one of PETSc's solvers is a bunch of setup routines, then
setting the right-hand side and solve.

Now, I don't want to rerun the whole setup part each time I call the
solver. I know that I can change the right-hand side without having to
do so, but what if I change a parameter of my operator like, say, the
time-step size or some material parameter?

Take the simplest case: Say I have my own implicit Euler written in
Python. I know the right-hand side F of my ODE, so in each step I want
to solve "I - dt*F". But the time-step changes every now and then, so I
cannot pre-assemble everything once and for all (or I don't want to).
What do I need to rerun before I can use the solver again, what can I
reuse? Could I just assemble F and combine it with the identity and the
parameter dt right before I call the solver? How would that look like?

I'm pretty new to PETSc and to petsc4py, so please forgive any stupidity
or ignorance in these questions. I'm happy to take any advice, links to
examples or previous questions. Thanks!

Kind regards
-Robert-

--
Dr. Robert Speck
Juelich Supercomputing Centre
Institute for Advanced Simulation
Forschungszentrum Juelich GmbH
52425 Juelich, Germany

Tel: +49 2461 61 1644
Fax: +49 2461 61 6656

Email:   r.sp...@fz-juelich.de
Website: http://www.fz-juelich.de/ias/jsc/speck_r
PinT:http://www.fz-juelich.de/ias/jsc/pint





Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender),
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt