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
|
"""Unit tests for the XML io library for vectors"""
# 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/>.
import pytest
from dolfin import *
import os
from dolfin_utils.test import skip_if_not_PETSc, fixture, cd_tempdir
@skip_if_not_PETSc
def test_save_vector_petsc(cd_tempdir):
# Create vector and write file
x = PETScVector(MPI.comm_world, 197)
x[:] = 1.0
f = File("x.xml")
f << x
@skip_if_not_PETSc
def test_save_gzipped_vector(cd_tempdir):
# Create vector and write file
x = PETScVector(MPI.comm_world, 197)
x[:] = 1.0
f = File("x.xml.gz")
f << x
@skip_if_not_PETSc
def test_read_vector_petcs(cd_tempdir):
# Create vector and write file
x = PETScVector(MPI.comm_world, 197)
x[:] = 1.0
f = File("x.xml")
f << x
# Read vector from previous write
y = PETScVector()
f >> y
assert x.size() == y.size()
assert round(x.norm("l2") - y.norm("l2"), 7) == 0
@skip_if_not_PETSc
def test_read_gzipped_vector(cd_tempdir):
# Create vector and write file
x = PETScVector(MPI.comm_world, 197)
x[:] = 1.0
f = File("x.xml")
f << x
# Read vector from previous write
y = PETScVector()
f >> y
assert x.size() == y.size()
assert round(x.norm("l2") - y.norm("l2"), 7) == 0
def test_save_read_vector(cd_tempdir):
size = 512
x = Vector(MPI.comm_world, size)
x[:] = 1.0
out_file = File("test_vector_xml.xml")
out_file << x
y = Vector()
out_file >> y
assert x.size() == y.size()
assert round((x - y).norm("l2") - 0.0, 7) == 0
|