~ubuntu-branches/ubuntu/wily/dolfin/wily-proposed

« back to all changes in this revision

Viewing changes to test/unit/mesh/python/MeshQuality.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2015-03-17 07:57:11 UTC
  • mfrom: (1.1.18) (19.1.24 experimental)
  • Revision ID: package-import@ubuntu.com-20150317075711-1v207zbty9qmygow
Tags: 1.5.0-1
* New upstream release (closes: #780359).
* debian/control:
  - Bump Standards-Version to 3.9.6 (no changes needed).
  - Bump X-Python-Version to >= 2.7.
  - Update package names for new SONAME 1.5 (libdolfin1.4 ->
    libdolfin1.5, libdolfin1.4-dbg -> libdolfin1.5-dbg and
    libdolfin1.4-dev -> libdolfin1.5-dev).
  - Bump minimum required version for python-instant, python-ufl and
    python-ffc to 1.5.0.
  - Add python-sympy and python-six to Depends for binary package
    python-dolfin.
  - Add dh-python to Build-Depends.
  - Remove libcgal-dev from {Build-}Depends.
* Remove CSGCGALMeshGenerator3D-oom.patch since CGAL is no longer used
  by DOLFIN.
* Move debian/libdolfin1.4.install -> debian/libdolfin1.5.install.
* debian/rules: No longer any non DFSG-free stuff to remove, so update
  get-orig-source target (update debian/watch accordingly).
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"Unit tests for the MeshQuality class"
2
 
 
3
 
# Copyright (C) 2013 Garth N. Wells
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
 
# First added:  2013-10-07
21
 
# Last changed:
22
 
 
23
 
import unittest
24
 
import numpy
25
 
from dolfin import *
26
 
 
27
 
class MeshQualityTest(unittest.TestCase):
28
 
 
29
 
    def test_radius_ratio_triangle(self):
30
 
 
31
 
        # Create mesh and compute rations
32
 
        mesh = UnitSquareMesh(12, 12)
33
 
        ratios = MeshQuality.radius_ratios(mesh)
34
 
        for c in cells(mesh):
35
 
            self.assertAlmostEqual(ratios[c], 0.828427124746)
36
 
 
37
 
    def test_radius_ratio_tetrahedron(self):
38
 
 
39
 
        # Create mesh and compute ratios
40
 
        mesh = UnitCubeMesh(14, 14, 14)
41
 
        ratios = MeshQuality.radius_ratios(mesh)
42
 
        for c in cells(mesh):
43
 
            self.assertAlmostEqual(ratios[c], 0.717438935214)
44
 
            #print ratio[c]
45
 
 
46
 
    def test_radius_ratio_triangle_min_max(self):
47
 
 
48
 
        # Create mesh, collpase and compute min ratio
49
 
        mesh = UnitSquareMesh(12, 12)
50
 
 
51
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(mesh)
52
 
        self.assertTrue(rmax <= rmax)
53
 
 
54
 
        x = mesh.coordinates()
55
 
        x[:, 0] *= 0.0
56
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(mesh)
57
 
        self.assertAlmostEqual(rmin, 0.0)
58
 
        self.assertAlmostEqual(rmax, 0.0)
59
 
 
60
 
    def test_radius_ratio_tetrahedron_min_max(self):
61
 
 
62
 
        # Create mesh, collpase and compute min ratio
63
 
        mesh = UnitCubeMesh(12, 12, 12)
64
 
 
65
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(mesh)
66
 
        self.assertTrue(rmax <= rmax)
67
 
 
68
 
        x = mesh.coordinates()
69
 
        x[:, 0] *= 0.0
70
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(mesh)
71
 
        self.assertAlmostEqual(rmax, 0.0)
72
 
        self.assertAlmostEqual(rmax, 0.0)
73
 
 
74
 
    def test_radius_ratio_matplotlib(self):
75
 
 
76
 
        # Create mesh, collpase and compute min ratio
77
 
        mesh = UnitCubeMesh(12, 12, 12)
78
 
        test = MeshQuality.radius_ratio_matplotlib_histogram(mesh, 5)
79
 
        print test
80
 
 
81
 
@unittest.skipIf(MPI.size(mpi_comm_world()) > 1, "Skipping unit test(s) not working in parallel")
82
 
class CellRadii(unittest.TestCase):
83
 
 
84
 
    def setUp(self):
85
 
 
86
 
        # Create 1D mesh with degenerate cell
87
 
        self.mesh1d = UnitIntervalMesh(4)
88
 
        self.mesh1d.coordinates()[4] = self.mesh1d.coordinates()[3]
89
 
 
90
 
        # Create 2D mesh with one equilateral triangle
91
 
        self.mesh2d = UnitSquareMesh(1, 1, 'left')
92
 
        self.mesh2d.coordinates()[3] += 0.5*(sqrt(3.0)-1.0)
93
 
 
94
 
        # Create 3D mesh with regular tetrahedron and degenerate cells
95
 
        self.mesh3d = UnitCubeMesh(1, 1, 1)
96
 
        self.mesh3d.coordinates()[2][0] = 1.0
97
 
        self.mesh3d.coordinates()[7][1] = 0.0
98
 
 
99
 
    def test_radius_ratio_min_radius_ratio_max(self):
100
 
 
101
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(self.mesh1d)
102
 
        self.assertAlmostEqual(rmin, 0.0)
103
 
        self.assertAlmostEqual(rmax, 1.0)
104
 
 
105
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(self.mesh2d)
106
 
        self.assertAlmostEqual(rmin, 2.0*sqrt(2.0)/(2.0+sqrt(2.0)) )
107
 
        self.assertAlmostEqual(rmax, 1.0)
108
 
 
109
 
        rmin, rmax = MeshQuality.radius_ratio_min_max(self.mesh3d)
110
 
        self.assertAlmostEqual(rmin, 0.0)
111
 
        self.assertAlmostEqual(rmax, 1.0)
112
 
 
113
 
if __name__ == "__main__":
114
 
    unittest.main()