Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-03-02 Thread Ed Bueler
Barry --

Works for me!

Note that

import numpy
import PetscBinaryIO
fh = open('t.dat','r')
t = numpy.fromfile(fh, dtype='>d')
fh.close()
io = PetscBinaryIO.PetscBinaryIO()
y = numpy.array(io.readBinaryFile('y.dat')).transpose()

reads the entire trajectory generated by

   -ts_monitor binary:t.dat -ts_monitor_solution binary:y.dat

Then

import matplotlib.pyplot as plt
for k in range(np.shape(y)[0]):
plt.plot(t,y[k],label='y[%d]' % k)
plt.xlabel('t')
plt.legend()

plots it with labels.  This is only a reasonable for small-dimension ODEs;
other vis. methods make more sense for PDEs.

It is hard to beat the convenience of this way of storing trajectories and
doing quick visualizations from python, so I'll probably stick to it.  Much
appreciated!

Ed


On Wed, Mar 2, 2016 at 11:00 AM, Barry Smith  wrote:

>
>   Sorry for the delay. Using master you can now do
>
>   ./ex2 -ts_monitor binary:filename -ts_monitor_solution binary:filename
>
>   and it will save each time step followed by each vector solution in the
> same file called filename.
>
>   The following python script (without error handling and end of file
> handling) will read in the time steps and solutions
>
> import PetscBinaryIO
> import numpy
> io = PetscBinaryIO.PetscBinaryIO()
> fh = open('binaryoutput')
> while True:
>   ts = numpy.fromfile(fh, dtype='>d', count=1)
>   print ts
>   objecttype = io.readObjectType(fh)
>   if objecttype == 'Vec':
> v = io.readVec(fh)
>   print v
>
>   I think this what you need/want.
>
>   As Hong noted you could also use -ts_save_trajectory 1
> -tstrajectory_type visualization and it will store the timestep and the
> vector (each timestep/vector is in the same file, one file per timestep.)
> you could then use a variation of the above python code to read from those
> files (I think the vector comes first in the trajectory file).
>
>   Barry
>
> > On Mar 1, 2016, at 1:26 AM, Ed Bueler  wrote:
> >
> > Barry --
> >
> > I am reading the resulting file successfully using
> >
> > import struct
> > import sys
> > f = open('timesteps','r')
> > while True:
> > try:
> > bytes = f.read(8)
> > except:
> > print "f.read() failed"
> > sys.exit(1)
> > if len(bytes) > 0:
> > print struct.unpack('>d',bytes)[0]
> > else:
> > break
> > f.close()
> >
> > However, was there a more elegant intended method?  I am disturbed by
> the apparent need to specify big-endian-ness (= '>d') in the
> struct.unpack() call.
> >
> > Ed
> >
> >
> > On Mon, Feb 29, 2016 at 9:39 PM, Ed Bueler  wrote:
> > Barry --
> >
> > Will try it.
> >
> > > ... since, presumably, other more powerful IO tools exist that would
> be used for "real" problems?
> >
> > I know there are tools for snapshotting from PETSc, e.g. VecView to
> .vtk.  In fact petsc binary seems fairly convenient for that.  On the other
> hand, I am not sure I've ever done anything "real".  ;-)
> >
> > Anyone out there:  Are there a good *convenient* tools for saving
> space/time-series (= movies) from PETSc TS?  I want to add frames and
> movies from PETSc into slides, etc.  I can think of NetCDF but it seems
> not-very-convenient, and I am worried not well-supported from PETSc.  Is
> setting up TS with events (=TSSetEventMonitor()) and writing separate
> snapshot files the preferred scalable usage, despite the extra effort
> compared to "-ts_monitor_solution binary:foo.dat"?
> >
> > Ed
> >
> >
> > On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:
> >
> >   Ed,
> >
> >I have added a branch barry/feature-ts-monitor-binary  that supports
> -ts_monitor binary:timesteps that will store in simple binary format each
> of the time steps associated with each solution. This in conjugation with
> -ts_monitor_solution binary:solutions will give you two files you can read
> in. But note that timesteps is a simple binary file of double precision
> numbers you should read in directly in python, you cannot use
> PetscBinaryIO.py which is what you will use to read in the solutions file.
> >
> >   Barry
> >
> > Currently PETSc has a binary file format where we can save Vec, Mat, IS,
> each is marked with a type id for PetscBinaryIO.py to detect, we do not
> have type ids for simple double precision numbers or arrays of numbers.
> This is why I have no way of saving the time steps in a way that
> PetscBinaryIO.py could read them in currently. I don't know how far we want
> to go in "spiffing up" the PETSc binary format to do more elaborate things
> since, presumably, other more power IO tools exist that would be used for
> "real" problems?
> >
> >
> > > On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
> > >
> > > Dear PETSc --
> > >
> > > I have a short C ode code that uses TS to solve  y' = g(t,y)  where
> y(t) is a 2-dim'l vector.  My code defaults to -ts_type rk so it does
> adaptive time-stepping; thus using -ts_monitor shows times at 

Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-03-02 Thread Barry Smith

  Merged branch into next for testing

> On Mar 1, 2016, at 11:18 AM, Hong Zhang  wrote:
> 
> Hi Barry,
> 
> Actually the TSTrajectory object can save both the solution and the 
> corresponding time information into binary files. Although it is designed 
> specifically for adjoint checkpointing, it does have the side benefit to 
> assist in visualization of simulation trajectories. For adjoint 
> checkpointing, not only solution is saved, but also stage values are saved. 
> So I created a new TSTrajectory type particularly for visualization purpose, 
> which can be access at my branch hongzh/tstrajectory_visualization. 
> 
> One can enable this feature using the command line options 
> 
> -ts_save_trajectory 1 -tstrajectory_type visualization
> 
> The full trajectory will be saved into a folder with multiple files, one file 
> corresponding to one time step. Then we can use a MATLAB script, such as 
> PetscBinaryRead.m, to read these binary files. But the default script coming 
> with PETSc needs to be modified a little bit. Because the trajectory is 
> always saved as a solution vector, followed by a PetscReal variable, I 
> suggest to use the following code in MATLAB:
> 
> if  header == 1211214 % Petsc Vec Object
>   %% Read state vector
>   m = double(read(fd,1,indices));
>   x = zeros(m,1);
>   v = read(fd,m,precision);
>   x(:) = v;
>   %% Read time
>   t = read(fd,1,precision);
> end
> 
> Shri (copied in this email) has successfully used this approach to do 
> visualization. Perhaps we can include this feature in the new release if it 
> is useful to some users.
> 
> Hong
>
> 
>> On Mar 1, 2016, at 10:32 AM, Barry Smith  wrote:
>> 
>>> 
>>> On Mar 1, 2016, at 12:39 AM, Ed Bueler  wrote:
>>> 
>>> Barry --
>>> 
>>> Will try it.
>>> 
 ... since, presumably, other more powerful IO tools exist that would be 
 used for "real" problems?
>>> 
>>> I know there are tools for snapshotting from PETSc, e.g. VecView to .vtk.  
>>> In fact petsc binary seems fairly convenient for that.  On the other hand, 
>>> I am not sure I've ever done anything "real".  ;-)
>>> 
>>> Anyone out there:  Are there a good *convenient* tools for saving 
>>> space/time-series (= movies) from PETSc TS?  I want to add frames and 
>>> movies from PETSc into slides, etc.  I can think of NetCDF but it seems 
>>> not-very-convenient, and I am worried not well-supported from PETSc.  Is 
>>> setting up TS with events (=TSSetEventMonitor()) and writing separate 
>>> snapshot files the preferred scalable usage, despite the extra effort 
>>> compared to "-ts_monitor_solution binary:foo.dat"?
>> 
>>   Ed,
>> 
>>As I said in my previous email since we don't have a way of indicating 
>> plain double precision numbers in our binary files it is not possible to put 
>> both the vectors and the time steps in the same file without augmenting our 
>> file format.
>> 
>>  Barry
>> 
>> 
>> 
>>> 
>>> Ed
>>> 
>>> 
>>> On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:
>>> 
>>>  Ed,
>>> 
>>>   I have added a branch barry/feature-ts-monitor-binary  that supports 
>>> -ts_monitor binary:timesteps that will store in simple binary format each 
>>> of the time steps associated with each solution. This in conjugation with 
>>> -ts_monitor_solution binary:solutions will give you two files you can read 
>>> in. But note that timesteps is a simple binary file of double precision 
>>> numbers you should read in directly in python, you cannot use 
>>> PetscBinaryIO.py which is what you will use to read in the solutions file.
>>> 
>>>  Barry
>>> 
>>> Currently PETSc has a binary file format where we can save Vec, Mat, IS, 
>>> each is marked with a type id for PetscBinaryIO.py to detect, we do not 
>>> have type ids for simple double precision numbers or arrays of numbers. 
>>> This is why I have no way of saving the time steps in a way that 
>>> PetscBinaryIO.py could read them in currently. I don't know how far we want 
>>> to go in "spiffing up" the PETSc binary format to do more elaborate things 
>>> since, presumably, other more power IO tools exist that would be used for 
>>> "real" problems?
>>> 
>>> 
 On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
 
 Dear PETSc --
 
 I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t) 
 is a 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive 
 time-stepping; thus using -ts_monitor shows times at stdout:
 
 $ ./ode -ts_monitor
 solving from t0 = 0.000 with initial time step dt = 0.1 ...
 0 TS dt 0.1 time 0.
 1 TS dt 0.170141 time 0.1
 2 TS dt 0.169917 time 0.270141
 3 TS dt 0.171145 time 0.440058
 4 TS dt 0.173931 time 0.611203
 5 TS dt 0.178719 time 0.785134
 6 TS dt 0.0361473 time 0.963853
 7 TS dt 0.188252 time 1.
 error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
 
 I want to 

Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-03-02 Thread Barry Smith

  Sorry for the delay. Using master you can now do 

  ./ex2 -ts_monitor binary:filename -ts_monitor_solution binary:filename 

  and it will save each time step followed by each vector solution in the same 
file called filename. 

  The following python script (without error handling and end of file handling) 
will read in the time steps and solutions

import PetscBinaryIO
import numpy
io = PetscBinaryIO.PetscBinaryIO()
fh = open('binaryoutput')
while True:
  ts = numpy.fromfile(fh, dtype='>d', count=1)
  print ts
  objecttype = io.readObjectType(fh)
  if objecttype == 'Vec':
v = io.readVec(fh)
  print v

  I think this what you need/want. 

  As Hong noted you could also use -ts_save_trajectory 1 -tstrajectory_type 
visualization and it will store the timestep and the vector (each 
timestep/vector is in the same file, one file per timestep.) you could then use 
a variation of the above python code to read from those files (I think the 
vector comes first in the trajectory file).

  Barry

> On Mar 1, 2016, at 1:26 AM, Ed Bueler  wrote:
> 
> Barry --
> 
> I am reading the resulting file successfully using
> 
> import struct
> import sys
> f = open('timesteps','r')
> while True:
> try:
> bytes = f.read(8)
> except:
> print "f.read() failed"
> sys.exit(1)
> if len(bytes) > 0:
> print struct.unpack('>d',bytes)[0]
> else:
> break
> f.close()
> 
> However, was there a more elegant intended method?  I am disturbed by the 
> apparent need to specify big-endian-ness (= '>d') in the struct.unpack() call.
> 
> Ed
> 
> 
> On Mon, Feb 29, 2016 at 9:39 PM, Ed Bueler  wrote:
> Barry --
> 
> Will try it.
> 
> > ... since, presumably, other more powerful IO tools exist that would be 
> > used for "real" problems?
> 
> I know there are tools for snapshotting from PETSc, e.g. VecView to .vtk.  In 
> fact petsc binary seems fairly convenient for that.  On the other hand, I am 
> not sure I've ever done anything "real".  ;-)
> 
> Anyone out there:  Are there a good *convenient* tools for saving 
> space/time-series (= movies) from PETSc TS?  I want to add frames and movies 
> from PETSc into slides, etc.  I can think of NetCDF but it seems 
> not-very-convenient, and I am worried not well-supported from PETSc.  Is 
> setting up TS with events (=TSSetEventMonitor()) and writing separate 
> snapshot files the preferred scalable usage, despite the extra effort 
> compared to "-ts_monitor_solution binary:foo.dat"?
> 
> Ed
> 
> 
> On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:
> 
>   Ed,
> 
>I have added a branch barry/feature-ts-monitor-binary  that supports 
> -ts_monitor binary:timesteps that will store in simple binary format each of 
> the time steps associated with each solution. This in conjugation with 
> -ts_monitor_solution binary:solutions will give you two files you can read 
> in. But note that timesteps is a simple binary file of double precision 
> numbers you should read in directly in python, you cannot use 
> PetscBinaryIO.py which is what you will use to read in the solutions file.
> 
>   Barry
> 
> Currently PETSc has a binary file format where we can save Vec, Mat, IS, each 
> is marked with a type id for PetscBinaryIO.py to detect, we do not have type 
> ids for simple double precision numbers or arrays of numbers. This is why I 
> have no way of saving the time steps in a way that PetscBinaryIO.py could 
> read them in currently. I don't know how far we want to go in "spiffing up" 
> the PETSc binary format to do more elaborate things since, presumably, other 
> more power IO tools exist that would be used for "real" problems?
> 
> 
> > On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
> >
> > Dear PETSc --
> >
> > I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t) is 
> > a 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive 
> > time-stepping; thus using -ts_monitor shows times at stdout:
> >
> > $ ./ode -ts_monitor
> > solving from t0 = 0.000 with initial time step dt = 0.1 ...
> > 0 TS dt 0.1 time 0.
> > 1 TS dt 0.170141 time 0.1
> > 2 TS dt 0.169917 time 0.270141
> > 3 TS dt 0.171145 time 0.440058
> > 4 TS dt 0.173931 time 0.611203
> > 5 TS dt 0.178719 time 0.785134
> > 6 TS dt 0.0361473 time 0.963853
> > 7 TS dt 0.188252 time 1.
> > error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
> >
> > I want to output the trajectory in PETSc binary and plot it in python using 
> > bin/PetscBinaryIO.py.  Clearly I need the times shown above to do that.
> >
> > Note "-ts_monitor_solution binary:XX" gives me a binary file with only y 
> > values in it, but not the corresponding times.
> >
> > My question is, how to get those times in either the same binary file 
> > (preferred) or separate binary files?  I have tried
> >
> > $ ./ode -ts_monitor binary:foo.dat# invalid
> > $ ./ode -ts_monitor_solution binary:bar.dat   

Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-03-01 Thread Barry Smith

> On Mar 1, 2016, at 12:39 AM, Ed Bueler  wrote:
> 
> Barry --
> 
> Will try it.
> 
> > ... since, presumably, other more powerful IO tools exist that would be 
> > used for "real" problems?
> 
> I know there are tools for snapshotting from PETSc, e.g. VecView to .vtk.  In 
> fact petsc binary seems fairly convenient for that.  On the other hand, I am 
> not sure I've ever done anything "real".  ;-)
> 
> Anyone out there:  Are there a good *convenient* tools for saving 
> space/time-series (= movies) from PETSc TS?  I want to add frames and movies 
> from PETSc into slides, etc.  I can think of NetCDF but it seems 
> not-very-convenient, and I am worried not well-supported from PETSc.  Is 
> setting up TS with events (=TSSetEventMonitor()) and writing separate 
> snapshot files the preferred scalable usage, despite the extra effort 
> compared to "-ts_monitor_solution binary:foo.dat"?

   Ed,

As I said in my previous email since we don't have a way of indicating 
plain double precision numbers in our binary files it is not possible to put 
both the vectors and the time steps in the same file without augmenting our 
file format.

  Barry



> 
> Ed
> 
> 
> On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:
> 
>   Ed,
> 
>I have added a branch barry/feature-ts-monitor-binary  that supports 
> -ts_monitor binary:timesteps that will store in simple binary format each of 
> the time steps associated with each solution. This in conjugation with 
> -ts_monitor_solution binary:solutions will give you two files you can read 
> in. But note that timesteps is a simple binary file of double precision 
> numbers you should read in directly in python, you cannot use 
> PetscBinaryIO.py which is what you will use to read in the solutions file.
> 
>   Barry
> 
> Currently PETSc has a binary file format where we can save Vec, Mat, IS, each 
> is marked with a type id for PetscBinaryIO.py to detect, we do not have type 
> ids for simple double precision numbers or arrays of numbers. This is why I 
> have no way of saving the time steps in a way that PetscBinaryIO.py could 
> read them in currently. I don't know how far we want to go in "spiffing up" 
> the PETSc binary format to do more elaborate things since, presumably, other 
> more power IO tools exist that would be used for "real" problems?
> 
> 
> > On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
> >
> > Dear PETSc --
> >
> > I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t) is 
> > a 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive 
> > time-stepping; thus using -ts_monitor shows times at stdout:
> >
> > $ ./ode -ts_monitor
> > solving from t0 = 0.000 with initial time step dt = 0.1 ...
> > 0 TS dt 0.1 time 0.
> > 1 TS dt 0.170141 time 0.1
> > 2 TS dt 0.169917 time 0.270141
> > 3 TS dt 0.171145 time 0.440058
> > 4 TS dt 0.173931 time 0.611203
> > 5 TS dt 0.178719 time 0.785134
> > 6 TS dt 0.0361473 time 0.963853
> > 7 TS dt 0.188252 time 1.
> > error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
> >
> > I want to output the trajectory in PETSc binary and plot it in python using 
> > bin/PetscBinaryIO.py.  Clearly I need the times shown above to do that.
> >
> > Note "-ts_monitor_solution binary:XX" gives me a binary file with only y 
> > values in it, but not the corresponding times.
> >
> > My question is, how to get those times in either the same binary file 
> > (preferred) or separate binary files?  I have tried
> >
> > $ ./ode -ts_monitor binary:foo.dat# invalid
> > $ ./ode -ts_monitor_solution binary:bar.dat   # no t in file
> > $ ./ode -ts_monitor_solution binary:baz.dat -ts_save_trajectory   # no t in 
> > file
> >
> > without success.  (I am not sure what the boolean option 
> > -ts_save_trajectory does, by the way.)
> >
> > Thanks!
> >
> > Ed
> >
> > PS Sorry if this is a "RTFM" question, but so far I can't find the 
> > documentation.
> >
> >
> > --
> > Ed Bueler
> > Dept of Math and Stat and Geophysical Institute
> > University of Alaska Fairbanks
> > Fairbanks, AK 99775-6660
> > 301C Chapman and 410D Elvey
> > 907 474-7693 and 907 474-7199  (fax 907 474-5394)
> 
> 
> 
> 
> -- 
> Ed Bueler
> Dept of Math and Stat and Geophysical Institute
> University of Alaska Fairbanks
> Fairbanks, AK 99775-6660
> 301C Chapman and 410D Elvey
> 907 474-7693 and 907 474-7199  (fax 907 474-5394)



Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-03-01 Thread Jed Brown
Ed Bueler  writes:

> Barry --
>
> I am reading the resulting file successfully using
>
> import struct
> import sys
> f = open('timesteps','r')
> while True:
> try:
> bytes = f.read(8)
> except:
> print "f.read() failed"
> sys.exit(1)

It seems odd to catch the exception and convert to sys.exit(1).  This
just loses the stack trace (which might have more detailed information)
and makes the debugger catch the wrong location.

> if len(bytes) > 0:
> print struct.unpack('>d',bytes)[0]
> else:
> break
> f.close()
>
> However, was there a more elegant intended method?  

I would use numpy.fromfile, which is one line.

> I am disturbed by the apparent need to specify big-endian-ness (=
> '>d') in the struct.unpack() call.

You need it because PETSc binary files are big-endian.  There is no
place to encode the byte order in these raw binary files, so some
convention is required for the file to portable.

HDF5 includes this information, though it is an annoying dependency.
Numpy files (*.npy) are a simpler alternative that PETSc could decide to
support.

https://docs.scipy.org/doc/numpy/neps/npy-format.html


signature.asc
Description: PGP signature


Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-02-29 Thread Ed Bueler
Barry --

I am reading the resulting file successfully using

import struct
import sys
f = open('timesteps','r')
while True:
try:
bytes = f.read(8)
except:
print "f.read() failed"
sys.exit(1)
if len(bytes) > 0:
print struct.unpack('>d',bytes)[0]
else:
break
f.close()

However, was there a more elegant intended method?  I am disturbed by the
apparent need to specify big-endian-ness (= '>d') in the struct.unpack()
call.

Ed


On Mon, Feb 29, 2016 at 9:39 PM, Ed Bueler  wrote:

> Barry --
>
> Will try it.
>
> > ... since, presumably, other more powerful IO tools exist that would be
> used for "real" problems?
>
> I know there are tools for snapshotting from PETSc, e.g. VecView to .vtk.
> In fact petsc binary seems fairly convenient for that.  On the other hand,
> I am not sure I've ever done anything "real".  ;-)
>
> Anyone out there:  Are there a good *convenient* tools for saving
> space/time-series (= movies) from PETSc TS?  I want to add frames and
> movies from PETSc into slides, etc.  I can think of NetCDF but it seems
> not-very-convenient, and I am worried not well-supported from PETSc.  Is
> setting up TS with events (=TSSetEventMonitor()) and writing separate
> snapshot files the preferred scalable usage, despite the extra effort
> compared to "-ts_monitor_solution binary:foo.dat"?
>
> Ed
>
>
> On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:
>
>>
>>   Ed,
>>
>>I have added a branch barry/feature-ts-monitor-binary  that supports
>> -ts_monitor binary:timesteps that will store in simple binary format each
>> of the time steps associated with each solution. This in conjugation with
>> -ts_monitor_solution binary:solutions will give you two files you can read
>> in. But note that timesteps is a simple binary file of double precision
>> numbers you should read in directly in python, you cannot use
>> PetscBinaryIO.py which is what you will use to read in the solutions file.
>>
>>   Barry
>>
>> Currently PETSc has a binary file format where we can save Vec, Mat, IS,
>> each is marked with a type id for PetscBinaryIO.py to detect, we do not
>> have type ids for simple double precision numbers or arrays of numbers.
>> This is why I have no way of saving the time steps in a way that
>> PetscBinaryIO.py could read them in currently. I don't know how far we want
>> to go in "spiffing up" the PETSc binary format to do more elaborate things
>> since, presumably, other more power IO tools exist that would be used for
>> "real" problems?
>>
>>
>> > On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
>> >
>> > Dear PETSc --
>> >
>> > I have a short C ode code that uses TS to solve  y' = g(t,y)  where
>> y(t) is a 2-dim'l vector.  My code defaults to -ts_type rk so it does
>> adaptive time-stepping; thus using -ts_monitor shows times at stdout:
>> >
>> > $ ./ode -ts_monitor
>> > solving from t0 = 0.000 with initial time step dt = 0.1 ...
>> > 0 TS dt 0.1 time 0.
>> > 1 TS dt 0.170141 time 0.1
>> > 2 TS dt 0.169917 time 0.270141
>> > 3 TS dt 0.171145 time 0.440058
>> > 4 TS dt 0.173931 time 0.611203
>> > 5 TS dt 0.178719 time 0.785134
>> > 6 TS dt 0.0361473 time 0.963853
>> > 7 TS dt 0.188252 time 1.
>> > error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
>> >
>> > I want to output the trajectory in PETSc binary and plot it in python
>> using bin/PetscBinaryIO.py.  Clearly I need the times shown above to do
>> that.
>> >
>> > Note "-ts_monitor_solution binary:XX" gives me a binary file with only
>> y values in it, but not the corresponding times.
>> >
>> > My question is, how to get those times in either the same binary file
>> (preferred) or separate binary files?  I have tried
>> >
>> > $ ./ode -ts_monitor binary:foo.dat# invalid
>> > $ ./ode -ts_monitor_solution binary:bar.dat   # no t in file
>> > $ ./ode -ts_monitor_solution binary:baz.dat -ts_save_trajectory   # no
>> t in file
>> >
>> > without success.  (I am not sure what the boolean option
>> -ts_save_trajectory does, by the way.)
>> >
>> > Thanks!
>> >
>> > Ed
>> >
>> > PS Sorry if this is a "RTFM" question, but so far I can't find the
>> documentation.
>> >
>> >
>> > --
>> > Ed Bueler
>> > Dept of Math and Stat and Geophysical Institute
>> > University of Alaska Fairbanks
>> > Fairbanks, AK 99775-6660
>> > 301C Chapman and 410D Elvey
>> > 907 474-7693 and 907 474-7199  (fax 907 474-5394)
>>
>>
>
>
> --
> Ed Bueler
> Dept of Math and Stat and Geophysical Institute
> University of Alaska Fairbanks
> Fairbanks, AK 99775-6660
> 301C Chapman and 410D Elvey
> 907 474-7693 and 907 474-7199  (fax 907 474-5394)
>



-- 
Ed Bueler
Dept of Math and Stat and Geophysical Institute
University of Alaska Fairbanks
Fairbanks, AK 99775-6660
301C Chapman and 410D Elvey
907 474-7693 and 907 474-7199  (fax 907 474-5394)


Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-02-29 Thread Ed Bueler
Barry --

Will try it.

> ... since, presumably, other more powerful IO tools exist that would be
used for "real" problems?

I know there are tools for snapshotting from PETSc, e.g. VecView to .vtk.
In fact petsc binary seems fairly convenient for that.  On the other hand,
I am not sure I've ever done anything "real".  ;-)

Anyone out there:  Are there a good *convenient* tools for saving
space/time-series (= movies) from PETSc TS?  I want to add frames and
movies from PETSc into slides, etc.  I can think of NetCDF but it seems
not-very-convenient, and I am worried not well-supported from PETSc.  Is
setting up TS with events (=TSSetEventMonitor()) and writing separate
snapshot files the preferred scalable usage, despite the extra effort
compared to "-ts_monitor_solution binary:foo.dat"?

Ed


On Mon, Feb 29, 2016 at 8:53 PM, Barry Smith  wrote:

>
>   Ed,
>
>I have added a branch barry/feature-ts-monitor-binary  that supports
> -ts_monitor binary:timesteps that will store in simple binary format each
> of the time steps associated with each solution. This in conjugation with
> -ts_monitor_solution binary:solutions will give you two files you can read
> in. But note that timesteps is a simple binary file of double precision
> numbers you should read in directly in python, you cannot use
> PetscBinaryIO.py which is what you will use to read in the solutions file.
>
>   Barry
>
> Currently PETSc has a binary file format where we can save Vec, Mat, IS,
> each is marked with a type id for PetscBinaryIO.py to detect, we do not
> have type ids for simple double precision numbers or arrays of numbers.
> This is why I have no way of saving the time steps in a way that
> PetscBinaryIO.py could read them in currently. I don't know how far we want
> to go in "spiffing up" the PETSc binary format to do more elaborate things
> since, presumably, other more power IO tools exist that would be used for
> "real" problems?
>
>
> > On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
> >
> > Dear PETSc --
> >
> > I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t)
> is a 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive
> time-stepping; thus using -ts_monitor shows times at stdout:
> >
> > $ ./ode -ts_monitor
> > solving from t0 = 0.000 with initial time step dt = 0.1 ...
> > 0 TS dt 0.1 time 0.
> > 1 TS dt 0.170141 time 0.1
> > 2 TS dt 0.169917 time 0.270141
> > 3 TS dt 0.171145 time 0.440058
> > 4 TS dt 0.173931 time 0.611203
> > 5 TS dt 0.178719 time 0.785134
> > 6 TS dt 0.0361473 time 0.963853
> > 7 TS dt 0.188252 time 1.
> > error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
> >
> > I want to output the trajectory in PETSc binary and plot it in python
> using bin/PetscBinaryIO.py.  Clearly I need the times shown above to do
> that.
> >
> > Note "-ts_monitor_solution binary:XX" gives me a binary file with only y
> values in it, but not the corresponding times.
> >
> > My question is, how to get those times in either the same binary file
> (preferred) or separate binary files?  I have tried
> >
> > $ ./ode -ts_monitor binary:foo.dat# invalid
> > $ ./ode -ts_monitor_solution binary:bar.dat   # no t in file
> > $ ./ode -ts_monitor_solution binary:baz.dat -ts_save_trajectory   # no t
> in file
> >
> > without success.  (I am not sure what the boolean option
> -ts_save_trajectory does, by the way.)
> >
> > Thanks!
> >
> > Ed
> >
> > PS Sorry if this is a "RTFM" question, but so far I can't find the
> documentation.
> >
> >
> > --
> > Ed Bueler
> > Dept of Math and Stat and Geophysical Institute
> > University of Alaska Fairbanks
> > Fairbanks, AK 99775-6660
> > 301C Chapman and 410D Elvey
> > 907 474-7693 and 907 474-7199  (fax 907 474-5394)
>
>


-- 
Ed Bueler
Dept of Math and Stat and Geophysical Institute
University of Alaska Fairbanks
Fairbanks, AK 99775-6660
301C Chapman and 410D Elvey
907 474-7693 and 907 474-7199  (fax 907 474-5394)


Re: [petsc-users] how to get full trajectory from TS into petsc binary

2016-02-29 Thread Barry Smith

  Ed,

   I have added a branch barry/feature-ts-monitor-binary  that supports 
-ts_monitor binary:timesteps that will store in simple binary format each of 
the time steps associated with each solution. This in conjugation with 
-ts_monitor_solution binary:solutions will give you two files you can read in. 
But note that timesteps is a simple binary file of double precision numbers you 
should read in directly in python, you cannot use PetscBinaryIO.py which is 
what you will use to read in the solutions file.

  Barry

Currently PETSc has a binary file format where we can save Vec, Mat, IS, each 
is marked with a type id for PetscBinaryIO.py to detect, we do not have type 
ids for simple double precision numbers or arrays of numbers. This is why I 
have no way of saving the time steps in a way that PetscBinaryIO.py could read 
them in currently. I don't know how far we want to go in "spiffing up" the 
PETSc binary format to do more elaborate things since, presumably, other more 
power IO tools exist that would be used for "real" problems?


> On Feb 29, 2016, at 3:24 PM, Ed Bueler  wrote:
> 
> Dear PETSc --
> 
> I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t) is a 
> 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive 
> time-stepping; thus using -ts_monitor shows times at stdout:
> 
> $ ./ode -ts_monitor
> solving from t0 = 0.000 with initial time step dt = 0.1 ...
> 0 TS dt 0.1 time 0.
> 1 TS dt 0.170141 time 0.1
> 2 TS dt 0.169917 time 0.270141
> 3 TS dt 0.171145 time 0.440058
> 4 TS dt 0.173931 time 0.611203
> 5 TS dt 0.178719 time 0.785134
> 6 TS dt 0.0361473 time 0.963853
> 7 TS dt 0.188252 time 1.
> error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484
> 
> I want to output the trajectory in PETSc binary and plot it in python using 
> bin/PetscBinaryIO.py.  Clearly I need the times shown above to do that.
> 
> Note "-ts_monitor_solution binary:XX" gives me a binary file with only y 
> values in it, but not the corresponding times.
> 
> My question is, how to get those times in either the same binary file 
> (preferred) or separate binary files?  I have tried
> 
> $ ./ode -ts_monitor binary:foo.dat# invalid
> $ ./ode -ts_monitor_solution binary:bar.dat   # no t in file
> $ ./ode -ts_monitor_solution binary:baz.dat -ts_save_trajectory   # no t in 
> file
> 
> without success.  (I am not sure what the boolean option -ts_save_trajectory 
> does, by the way.)
> 
> Thanks!
> 
> Ed
> 
> PS Sorry if this is a "RTFM" question, but so far I can't find the 
> documentation.
> 
> 
> -- 
> Ed Bueler
> Dept of Math and Stat and Geophysical Institute
> University of Alaska Fairbanks
> Fairbanks, AK 99775-6660
> 301C Chapman and 410D Elvey
> 907 474-7693 and 907 474-7199  (fax 907 474-5394)



[petsc-users] how to get full trajectory from TS into petsc binary

2016-02-29 Thread Ed Bueler
Dear PETSc --

I have a short C ode code that uses TS to solve  y' = g(t,y)  where y(t) is
a 2-dim'l vector.  My code defaults to -ts_type rk so it does adaptive
time-stepping; thus using -ts_monitor shows times at stdout:

$ ./ode -ts_monitor
solving from t0 = 0.000 with initial time step dt = 0.1 ...
0 TS dt 0.1 time 0.
1 TS dt 0.170141 time 0.1
2 TS dt 0.169917 time 0.270141
3 TS dt 0.171145 time 0.440058
4 TS dt 0.173931 time 0.611203
5 TS dt 0.178719 time 0.785134
6 TS dt 0.0361473 time 0.963853
7 TS dt 0.188252 time 1.
error at tf = 1.000 :  |y-y_exact|_inf = 0.000144484

I want to output the trajectory in PETSc binary and plot it in python using
bin/PetscBinaryIO.py.  Clearly I need the times shown above to do that.

Note "-ts_monitor_solution binary:XX" gives me a binary file with only y
values in it, but not the corresponding times.

My question is, how to get those times in either the same binary file
(preferred) or separate binary files?  I have tried

$ ./ode -ts_monitor binary:foo.dat# invalid
$ ./ode -ts_monitor_solution binary:bar.dat   # no t in file
$ ./ode -ts_monitor_solution binary:baz.dat -ts_save_trajectory   # no t in
file

without success.  (I am not sure what the boolean option
-ts_save_trajectory does, by the way.)

Thanks!

Ed

PS Sorry if this is a "RTFM" question, but so far I can't find the
documentation.


-- 
Ed Bueler
Dept of Math and Stat and Geophysical Institute
University of Alaska Fairbanks
Fairbanks, AK 99775-6660
301C Chapman and 410D Elvey
907 474-7693 and 907 474-7199  (fax 907 474-5394)