| 1 |
"""Unit test for XDMF output of DG0""" |
| 2 |
|
| 3 |
# Copyright (C) 2014 Chris Richardson |
| 4 |
# |
| 5 |
# This file is part of DOLFIN. |
| 6 |
# |
| 7 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU Lesser General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# DOLFIN is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU Lesser General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU Lesser General Public License |
| 18 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
import pytest |
| 21 |
from dolfin import * |
| 22 |
from dolfin_utils.test import * |
| 23 |
|
| 24 |
ghost_mode = set_parameters_fixture("ghost_mode", ["shared_vertex", "none"]) |
| 25 |
|
| 26 |
@skip_if_not_HDF5 |
| 27 |
@xfail_with_serial_hdf5_in_parallel |
| 28 |
def test_xdmf_cell_scalar_ghost(cd_tempdir, ghost_mode): |
| 29 |
n = 8 |
| 30 |
mesh = UnitSquareMesh(n, n) |
| 31 |
Q = FunctionSpace(mesh, "DG", 0) |
| 32 |
F = Function(Q) |
| 33 |
E = Expression("x[0]", degree=1) |
| 34 |
F.interpolate(E) |
| 35 |
|
| 36 |
with XDMFFile(mesh.mpi_comm(), "dg0.xdmf") as xdmf: |
| 37 |
xdmf.write(F) |
| 38 |
|
| 39 |
with HDF5File(mesh.mpi_comm(), "dg0.h5", "r") as hdf: |
| 40 |
vec = Vector() |
| 41 |
hdf.read(vec, "/VisualisationVector/0", False) |
| 42 |
|
| 43 |
area = MPI.sum(mesh.mpi_comm(), sum(vec.get_local())) |
| 44 |
assert abs(n*n - area) < 1e-9 |