File: test_time_series.py

package info (click to toggle)
dolfin 2018.1.0.post1-16
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,764 kB
  • sloc: xml: 104,040; cpp: 98,856; python: 22,511; makefile: 204; sh: 182
file content (93 lines) | stat: -rwxr-xr-x 2,757 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Unit tests for TimeSeries"""

# Copyright (C) 2011-2014 Marie E. Rognes
#
# This file is part of DOLFIN.
#
# DOLFIN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DOLFIN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.

import pytest
from dolfin import *
import os
from dolfin_utils.test import skip_in_parallel, skip_if_not_HDF5, fixture, tempdir

@skip_in_parallel
@skip_if_not_HDF5
def test_retrieve_all_connectivities(tempdir):
    _test_retrieve(tempdir, "test_retrieve_all_connectivities")

def _test_retrieve(tempdir, basename):
    filename = os.path.join(tempdir, basename)

    times = [t/10.0 for t in range(1, 11)]

    mesh_size = (2, 2, 2)
    mesh = UnitCubeMesh(*mesh_size)
    mesh.init()
    V = FunctionSpace(mesh, "CG", 2)

    u = Function(V)
    series = TimeSeries(MPI.comm_world, filename)
    for t in times:
        u.vector()[:] = t
        series.store(u.vector(), t)
        series.store(mesh, t)

    series = TimeSeries(MPI.comm_world, filename)
    t0 = series.vector_times()[0]
    T = series.mesh_times()[-1]

    assert round(t0 - times[0], 7) == 0
    assert round(T - times[-1], 7) == 0

    # Test retreiving of mesh
    mesh_retreived = Mesh()
    series.retrieve(mesh_retreived, 0.1)

    mesh_test = mesh

    for entity in range(4):
        mesh_retreived.init(entity)
        assert mesh_retreived.topology().size(entity) == \
            mesh_test.topology().size(entity)

    for i in range(4):
        for j in range(4):
            mesh_retreived.init(i, j)
            assert mesh_retreived.topology()(i, j).size() == \
                              mesh_test.topology()(i, j).size()


@skip_in_parallel
@skip_if_not_HDF5
def test_subdirectory(tempdir):
    "Test that retrieve/store works with nonexisting subdirectory"
    filename = os.path.join(tempdir, "test_subdirectory")

    m0 = UnitSquareMesh(3, 3)

    series0 = TimeSeries(MPI.comm_world, filename)
    x0 = Vector(MPI.comm_world, 10)

    # Test storage of only one time point for the mesh
    series0.store(m0, 0.1)
    series0.store(x0, 0.1)
    series0.store(x0, 0.2)

    series1 = TimeSeries(MPI.comm_world, filename)
    m1 = Mesh()
    x1 = Vector()

    series1.retrieve(m1, 0.1)
    series1.retrieve(x1, 0.15)