plot in same window

Asked by Chaffra Affouda

How do I make dolfin use the same window for the next plot command?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Wed, Dec 29, 2010 at 05:57:22PM -0000, Chaffra wrote:
> New question #139524 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/139524
>
> How do I make dolfin use the same window for the next plot command?

By plotting the same object.

If you are plotting a solution, make sure that you use the same
Function object in every plot and update the values of the Function
between plots.

--
Anders

Revision history for this message
S Wood (sarah2425) said :
#2

Hi Andres,

Sorry I am new to dofin and fenics, but I was wondering if you can clarify what you mean by "update"? Here is a segment of the code I have and I don't get the plot on the same loop!

while t <= T:
    u, v = TrialFunction(V), TestFunction(V)
    Fuv = v*u*dx + ......
    u = Function(V)
    F = action(Fuv, u)
    J = derivative(F, u, du)

    # Solve nonlinear variational problem
    problem = VariationalProblem(J, F, bc, nonlinear=True)
    newton = problem.parameters['newton_solver']
    newton["maximum_iterations"] = 40
    problem.solve(u)

    # Plot u
    plot(u)

    # March in time
    t += dt
    u_prev.assign(u)

Thank you very much.

S.

Revision history for this message
Best Johan Hake (johan-hake) said :
#3

On Saturday January 1 2011 00:57:57 S Wood wrote:
> Question #139524 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/139524
>
> S Wood requested for more information:
> Hi Andres,
>
> Sorry I am new to dofin and fenics, but I was wondering if you can
> clarify what you mean by "update"? Here is a segment of the code I have
> and I don't get the plot on the same loop!
>

You are recreating the solution Function each timestep. The plot command can
then not figure out that you are plotting the same Function.

Change the code to:

 u, v = TrialFunction(V), TestFunction(V)
 Fuv = v*u*dx + ......
 u = Function(V)
 F = action(Fuv, u)
 J = derivative(F, u, du)

 # Solve nonlinear variational problem
 problem = VariationalProblem(J, F, bc, nonlinear=True)
 newton = problem.parameters['newton_solver']
 newton["maximum_iterations"] = 40

 while t <= T:
     problem.solve(u)

     # Plot u
     plot(u)

     # March in time
     t += dt
     u_prev.assign(u)

Johan

> Thank you very much.
>
> S.

Revision history for this message
S Wood (sarah2425) said :
#4

Thanks Johan.

Revision history for this message
Chaffra Affouda (chaffra) said :
#5

Thanks Johan Hake, that solved my question.