Saving 1-d solution in simple text format

Asked by Praveen C

Hello

How can I save the solution of a 1-d problem as a two column output "x u(x)". I would like to use gnuplot or some such program to see the solution.

Thanks
praveen

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
Johan Hake (johan-hake) said :
#1

Have you tried using

  plot(u, interactive=True)

or saving to vtk files which can be view using Paraview?

If you prefer Gnuplot you should be able to do something like:

  f = open("data.txt", "w")
  for x in some_x_range:
      f.write("%f, %f\n"%(x, u(x)))
  f.close()

Johan

On Monday May 30 2011 21:45:54 Praveen C wrote:
> New question #159696 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/159696
>
> Hello
>
> How can I save the solution of a 1-d problem as a two column output "x
> u(x)". I would like to use gnuplot or some such program to see the
> solution.
>
> Thanks
> praveen

Revision history for this message
Praveen C (cpraveen) said :
#2

Thats close. I need to save the degree of freedom (u) and its associated location (x). I dont know how to access these from the solution u and the mesh.

praveen

Revision history for this message
Anders Logg (logg) said :
#3

On Tue, May 31, 2011 at 06:55:50AM -0000, Praveen C wrote:
> Question #159696 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/159696
>
> Status: Answered => Open
>
> Praveen C is still having a problem:
> Thats close. I need to save the degree of freedom (u) and its associated
> location (x). I dont know how to access these from the solution u and
> the mesh.

Just call u.vector().array() and you will get a NumPy array that you
can iterate over.

--
Anders

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#4

On 31 May 2011 13:58, Anders Logg <email address hidden> wrote:
> On Tue, May 31, 2011 at 06:55:50AM -0000, Praveen C wrote:
>> Question #159696 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/159696
>>
>>     Status: Answered => Open
>>
>> Praveen C is still having a problem:
>> Thats close. I need to save the degree of freedom (u) and its associated
>> location (x). I dont know how to access these from the solution u and
>> the mesh.
>
> Just call u.vector().array() and you will get a NumPy array that you
> can iterate over.

And mesh.coordinates() to get a NumPy array with the coordinates.
For linear Lagrange, the numberings should match.

Martin

Revision history for this message
Praveen C (cpraveen) said :
#5

Thanks to all. One final question. How do I get the spatial locations corresponding to a dof ?

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

On Tuesday May 31 2011 09:35:55 Praveen C wrote:
> Question #159696 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/159696
>
> Status: Answered => Open
>
> Praveen C is still having a problem:
> Thanks to all. One final question. How do I get the spatial locations
> corresponding to a dof ?

In your case it is the same as the coordinates you get out from

  mesh.coordinates()

Johan

Revision history for this message
Praveen C (cpraveen) said :
#7

Thanks Johan Hake, that solved my question.