File: test_XML_mesh_function.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 (133 lines) | stat: -rwxr-xr-x 3,082 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"Unit tests for XML input/output of MeshFunction (class XMLMeshFunction)"

# Copyright (C) 2011-2014 Garth N. Wells
#
# 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/>.
#
# Modified by Anders Logg 2011

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


@skip_in_parallel
def test_io_size_t(cd_tempdir):
    "Test input/output for size_t"

    # Write some data
    mesh = UnitSquareMesh(5, 5)
    f = MeshFunction("size_t", mesh, 1)
    f.set_all(0)
    f[2] = 3
    f[5] = 7

    filename = "XMLMeshFunction_test_io_size_t.xml"

    # Write
    output_file = File(filename)
    output_file << f

    # Read from file
    g = MeshFunction("size_t", mesh, 1)
    input_file = File(filename)
    input_file >> g

    # Check values
    for i in range(f.size()):
        assert f[i] == g[i]


@skip_in_parallel
def test_io_int(cd_tempdir):
    "Test input/output for int"

    # Write some data
    mesh = UnitSquareMesh(5, 5)
    f = MeshFunction("int", mesh, 1)
    f.set_all(0)
    f[2] = -3
    f[5] = 7

    filename = "XMLMeshFunction_test_io_int.xml"

    # Write
    output_file = File(filename)
    output_file << f

    # Read from file
    g = MeshFunction("int", mesh, 1)
    input_file = File(filename)
    input_file >> g

    # Check values
    for i in range(f.size()):
        assert f[i] == g[i]


@skip_in_parallel
def test_io_double(cd_tempdir):
    "Test input/output for double"

    # Write some data
    mesh = UnitSquareMesh(5, 5)
    f = MeshFunction("double", mesh, 1)
    f.set_all(0.0)
    f[2] = 3.14
    f[5] = 10000000.0

    filename = "XMLMeshFunction_test_io_double.xml"

    # Write
    output_file = File(filename)
    output_file << f

    # Read from file
    g = MeshFunction("double", mesh, 1)
    input_file = File(filename)
    input_file >> g

    # Check values
    for i in range(f.size()):
        assert f[i] == g[i]


@skip_in_parallel
def test_io_bool(cd_tempdir):
    "Test input/output for bool"

    # Write some data
    mesh = UnitSquareMesh(5, 5)
    f = MeshFunction("bool", mesh, 1)
    f.set_all(False)
    f[2] = True
    f[5] = False

    filename = "XMLMeshFunction_test_io_bool.xml"

    # Write
    output_file = File(filename)
    output_file << f

    # Read from file
    g = MeshFunction("bool", mesh, 1)
    input_file = File(filename)
    input_file >> g

    # Check values
    for i in range(f.size()):
        assert f[i] == g[i]