| 1 |
# Copyright (C) 2013 Garth N. Wells |
| 2 |
# |
| 3 |
# This file is part of DOLFIN. |
| 4 |
# |
| 5 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# DOLFIN is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public License |
| 16 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
import pytest |
| 19 |
import numpy |
| 20 |
from dolfin import * |
| 21 |
import os |
| 22 |
from dolfin_utils.test import fixture, cd_tempdir |
| 23 |
|
| 24 |
def test_save_mesh1D(cd_tempdir): |
| 25 |
mesh = UnitIntervalMesh(16) |
| 26 |
file = File("mesh1D.x3d") |
| 27 |
#self.assertRaises(RuntimeError, file << mesh) |
| 28 |
|
| 29 |
def test_save_mesh2D(cd_tempdir): |
| 30 |
mesh = UnitSquareMesh(16, 16) |
| 31 |
file = File("mesh2D.x3d") |
| 32 |
file << mesh |
| 33 |
|
| 34 |
def test_save_mesh3D(cd_tempdir): |
| 35 |
mesh = UnitCubeMesh(16, 16, 16) |
| 36 |
file = File("mesh3D.x3d") |
| 37 |
file << mesh |
| 38 |
|
| 39 |
def test_save_cell_meshfunction2D(cd_tempdir): |
| 40 |
mesh = UnitSquareMesh(16, 16) |
| 41 |
mf = MeshFunction("size_t", mesh, mesh.topology().dim(), 12) |
| 42 |
file = File("cell_mf2D.x3d") |
| 43 |
file << mf |
| 44 |
|
| 45 |
def test_save_facet_meshfunction2D(cd_tempdir): |
| 46 |
mesh = UnitSquareMesh(16, 16) |
| 47 |
mf = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 12) |
| 48 |
file = File("facet_mf2D.x3d") |
| 49 |
#with pytest.raises(RuntimeError): |
| 50 |
# file << mf |
| 51 |
|
| 52 |
|
| 53 |
def test_save_cell_meshfunctio22D(cd_tempdir): |
| 54 |
mesh = UnitCubeMesh(16, 16, 16) |
| 55 |
mf = MeshFunction("size_t", mesh, mesh.topology().dim(), 12) |
| 56 |
file = File("cell_mf3D.x3d") |
| 57 |
file << mf |
| 58 |
|
| 59 |
|
| 60 |
def test_save_facet_meshfunction3D(cd_tempdir): |
| 61 |
mesh = UnitCubeMesh(16, 16, 16) |
| 62 |
mf = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 12) |
| 63 |
file = File("facet_mf3D.x3d") |
| 64 |
#with pytest.raises(RuntimeError): |
| 65 |
# file << mf |
| 66 |
|
| 67 |
|
| 68 |
def test_mesh_str(): |
| 69 |
mesh = UnitCubeMesh(2, 2, 2) |
| 70 |
str = X3DOM.str(mesh) |
| 71 |
mesh = UnitSquareMesh(5, 3) |
| 72 |
str = X3DOM.str(mesh) |
| 73 |
|
| 74 |
|
| 75 |
def test_mesh_html(): |
| 76 |
mesh = UnitCubeMesh(2, 2, 2) |
| 77 |
str = X3DOM.html(mesh) |
| 78 |
mesh = UnitSquareMesh(5, 3) |
| 79 |
str = X3DOM.html(mesh) |
| 80 |
# test IPython display hook: |
| 81 |
html = mesh._repr_html_() |
| 82 |
|
| 83 |
|
| 84 |
def test_x3dom_parameters(): |
| 85 |
p = X3DOMParameters() |
| 86 |
|
| 87 |
# Test Representation |
| 88 |
|
| 89 |
# Get colour |
| 90 |
c0 = p.get_diffuse_color() |
| 91 |
|
| 92 |
# Set colour |
| 93 |
c0 = [0.1, 0.2, 0.1] |
| 94 |
p.set_diffuse_color(c0) |
| 95 |
c1 = p.get_diffuse_color() |
| 96 |
assert numpy.array_equal(c0, c1) |
| 97 |
|
| 98 |
c0 = (0.1, 0.2, 0.1) |
| 99 |
p.set_diffuse_color(c0) |
| 100 |
c1 = p.get_diffuse_color() |
| 101 |
assert numpy.array_equal(c0, c1) |
| 102 |
|
| 103 |
c0 = numpy.array([0.1, 0.2, 0.1]) |
| 104 |
p.set_diffuse_color(c0) |
| 105 |
c1 = p.get_diffuse_color() |
| 106 |
assert numpy.array_equal(c0, c1) |
| 107 |
|
| 108 |
# Test wrong length color sequences |
| 109 |
with pytest.raises(TypeError): |
| 110 |
c0 = [0.1, 0.2, 0.1, 0.2] |
| 111 |
p.set_diffuse_color(c0) |
| 112 |
|
| 113 |
with pytest.raises(TypeError): |
| 114 |
c0 = [0.1, 0.2] |
| 115 |
p.set_diffuse_color(c0) |
| 116 |
|
| 117 |
# Test invalid RGB value |
| 118 |
with pytest.raises(RuntimeError): |
| 119 |
c0 = [0.1, 0.2, 1.2] |
| 120 |
p.set_diffuse_color(c0) |