branch: devel-tetsuo-xml-binary commit 5fe036fdf1cf973ca20e482a5607c2e7555a1f19 Author: Tetsuo Koyama <tkoyama...@gmail.com> AuthorDate: Sun Jul 12 04:34:44 2020 +0000
:new: check_export_vtu.py --- interface/tests/python/Makefile.am | 2 ++ interface/tests/python/check_export_vtu.py | 53 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/interface/tests/python/Makefile.am b/interface/tests/python/Makefile.am index 5c520df..c281cc0 100644 --- a/interface/tests/python/Makefile.am +++ b/interface/tests/python/Makefile.am @@ -24,6 +24,7 @@ endif EXTRA_DIST= \ check_export.py \ + check_export_vtu.py \ check_global_functions.py \ check_levelset.py \ check_asm.py \ @@ -64,6 +65,7 @@ EXTRA_DIST= \ if BUILDPYTHON TESTS = \ check_export.py \ + check_export_vtu.py \ check_global_functions.py \ check_asm.py \ check_secondary_domain.py \ diff --git a/interface/tests/python/check_export_vtu.py b/interface/tests/python/check_export_vtu.py new file mode 100644 index 0000000..e0ec891 --- /dev/null +++ b/interface/tests/python/check_export_vtu.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Python GetFEM interface +# +# Copyright (C) 2004-2020 Yves Renard, Julien Pommier. +# +# This file is a part of GetFEM +# +# GetFEM 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 2.1 of the License, or +# (at your option) any later version. +# This program 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 this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +# +############################################################################ +""" test export. + + This program is used to check that python-getfem is working. This is + also a good example of use of python-getfem.. + + $Id$ +""" +import vtk +import getfem as gf + +m0 = gf.Mesh("cartesian", [0, 1]) + +filenames = ["check_m0_ascii.vtu", "check_m0_binary.vtu"] + +m0.export_to_vtu(filenames[0], "ascii") +filenames.append(filenames[0]) + +m0.export_to_vtu(filenames[1]) +filenames.append(filenames[1]) + +for filename in filenames: + print(filename) + reader = vtk.vtkXMLUnstructuredGridReader() + reader.SetFileName(filename) + reader.Update() + output = reader.GetOutput() + cell_data = output.GetCellData() + nbpts = output.GetNumberOfPoints() + nbcvs = output.GetNumberOfCells() + array_name = cell_data.GetArrayName(0) + assert nbpts == m0.nbpts(), "Number of points is not correct." + assert nbcvs == m0.nbcvs(), "Number of cells is not correct."