Debian Codegraph @

python/demo/undocumented/time-series/demo_time-series.py

raw
1 # Copyright (C) 2009 Anders Logg
2 #
3 # This file is part of DOLFIN.
4 #
5 # DOLFIN is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # DOLFIN is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # First added: 2009-11-11
19 # Last changed: 2012-11-12
20
21 from dolfin import *
22 from numpy import ones
23 import matplotlib.pyplot as plt
24
25
26 # TimeSeries requires DOLFIN to be configured with HDF5
27 if has_hdf5() is False:
28 print("This demo requires DOLFIN to be configured with HDF5")
29 exit()
30
31 # Create empty time series
32 series = TimeSeries(MPI.comm_world, "primal")
33
34 # Create a mesh and a vector
35 mesh = UnitSquareMesh(2, 2)
36 x = Vector()
37
38 # Add a bunch of meshes and vectors to the series
39 t = 0.0
40 while t < 1.0:
41
42 # Refine mesh
43 mesh = refine(mesh);
44
45 # Set some vector values
46 x = Vector(mesh.mpi_comm(), mesh.num_vertices());
47 x[:] = ones(x.size())
48
49 # Append to series
50 series.store(mesh, t)
51 series.store(x, t)
52
53 t += 0.2
54
55 # Retrieve mesh and vector at some point in time
56 series.retrieve(mesh, 0.29)
57 x = Vector()
58 series.retrieve(x, 0.31, False)
59
60 # Plot mesh
61 plot(mesh)
62 plt.show()