efficient way of storing tensors

Asked by B. Emek Abali

Dear all,

in a dynamic problem, a trial of storing the history (the values of a tensor from the all the last time values) like:
-------------------------------
history=[]

def tensor(u):
  .....
  return as_tensor(...)

while t < end:
  ...
  ...
  solve(u)
  history.append(tensor(u))
------------------------------

is working perfectly fine, but after couple of time steps, this listing is not really efficient anymore and 'append' takes more time than the solution itself :)

Is there a better way of storing tensors?

Question information

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

On Wed, Jun 13, 2012 at 05:01:03PM -0000, B. Emek Abali wrote:
> New question #200330 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/200330
>
> Dear all,
>
> in a dynamic problem, a trial of storing the history (the values of a tensor from the all the last time values) like:
> -------------------------------
> history=[]
>
> def tensor(u):
> .....
> return as_tensor(...)
>
> while t < end:
> ...
> ...
> solve(u)
> history.append(tensor(u))
> ------------------------------
>
> is working perfectly fine, but after couple of time steps, this listing is not really efficient anymore and 'append' takes more time than the solution itself :)
>
> Is there a better way of storing tensors?

I'm not sure what you are trying to do here, but you can try the
TimeSeries class. It provides efficient (as in binary read/write to
files) storage of meshes and vectors.

--
Anders

Revision history for this message
B. Emek Abali (bilenemek) said :
#2

Thanks Anders Logg, that solved my question.

Revision history for this message
B. Emek Abali (bilenemek) said :
#3

thanks for this answer, here is the version with time series, it is working like a dream :)

-------------------------------
from dolfin import *
TensorSpace=TensorFunctionSpace(...)

history=TimeSeries("hist_name_of_the_files_to_store")

def tensor(u):
  .....
  return as_tensor(...)

while t < end:
  ...
  ...
  solve(u)
  values=project(tensor(u),TensorSpace)
  history.store(values.vector(),t)
------------------------------