| 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 |
// This program demonstrates the use of the TimeSeries |
| 22 |
// class for storing a series of meshes and vectors. |
| 23 |
|
| 24 |
#include <dolfin.h> |
| 25 |
|
| 26 |
using namespace dolfin; |
| 27 |
|
| 28 |
int main() |
| 29 |
{ |
| 30 |
if (dolfin::MPI::size(MPI_COMM_WORLD) > 1) |
| 31 |
{ |
| 32 |
std::cout << "This demo does not work in parallel" << std::endl; |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
#ifdef HAS_HDF5 |
| 37 |
|
| 38 |
// Create empty time series |
| 39 |
TimeSeries series(MPI_COMM_WORLD, "primal"); |
| 40 |
|
| 41 |
// Create a mesh and a vector |
| 42 |
UnitSquareMesh unit_square(2, 2); |
| 43 |
Mesh mesh(unit_square); |
| 44 |
|
| 45 |
// Add a bunch of meshes and vectors to the series |
| 46 |
double t = 0.0; |
| 47 |
while (t < 1.0) |
| 48 |
{ |
| 49 |
// Refine mesh and resize vector |
| 50 |
mesh = refine(mesh); |
| 51 |
Vector x(mesh.mpi_comm(), mesh.num_vertices()); |
| 52 |
|
| 53 |
// Set some vector values |
| 54 |
std::vector<double> values(x.local_size()); |
| 55 |
const std::size_t offset = x.local_range().first; |
| 56 |
for (std::size_t i = 0; i < x.local_size(); i++) |
| 57 |
values[i] = (t + 1.0)*static_cast<double>(offset + i); |
| 58 |
x.set_local(values); |
| 59 |
x.apply("insert"); |
| 60 |
|
| 61 |
// Append to series |
| 62 |
series.store(mesh, t); |
| 63 |
series.store(x, t); |
| 64 |
|
| 65 |
t += 0.2; |
| 66 |
} |
| 67 |
|
| 68 |
// Retrieve mesh and vector at some point in time |
| 69 |
series.retrieve(mesh, 0.29); |
| 70 |
Vector x; |
| 71 |
series.retrieve(x, 0.31, false); |
| 72 |
|
| 73 |
#endif |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |