| 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 pytest |
| 24 |
import numpy |
| 25 |
from dolfin import * |
| 26 |
from dolfin_utils.test import skip_in_parallel |
| 27 |
|
| 28 |
|
| 29 |
def test_radius_ratio_triangle(): |
| 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 |
assert round(ratios[c] - 0.828427124746, 7) == 0 |
| 36 |
|
| 37 |
|
| 38 |
def test_radius_ratio_tetrahedron(): |
| 39 |
|
| 40 |
# Create mesh and compute ratios |
| 41 |
mesh = UnitCubeMesh(14, 14, 14) |
| 42 |
ratios = MeshQuality.radius_ratios(mesh) |
| 43 |
for c in cells(mesh): |
| 44 |
assert round(ratios[c] - 0.717438935214, 7) == 0 |
| 45 |
|
| 46 |
|
| 47 |
def test_radius_ratio_triangle_min_max(): |
| 48 |
|
| 49 |
# Create mesh, collpase and compute min ratio |
| 50 |
mesh = UnitSquareMesh(12, 12) |
| 51 |
|
| 52 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh) |
| 53 |
assert rmax <= rmax |
| 54 |
|
| 55 |
x = mesh.coordinates() |
| 56 |
x[:, 0] *= 0.0 |
| 57 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh) |
| 58 |
assert round(rmin - 0.0, 7) == 0 |
| 59 |
assert round(rmax - 0.0, 7) == 0 |
| 60 |
|
| 61 |
|
| 62 |
def test_radius_ratio_tetrahedron_min_max(): |
| 63 |
|
| 64 |
# Create mesh, collpase and compute min ratio |
| 65 |
mesh = UnitCubeMesh(12, 12, 12) |
| 66 |
|
| 67 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh) |
| 68 |
assert rmax <= rmax |
| 69 |
|
| 70 |
x = mesh.coordinates() |
| 71 |
x[:, 0] *= 0.0 |
| 72 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh) |
| 73 |
assert round(rmax - 0.0, 7) == 0 |
| 74 |
assert round(rmax - 0.0, 7) == 0 |
| 75 |
|
| 76 |
|
| 77 |
def test_radius_ratio_matplotlib(): |
| 78 |
# Create mesh, collpase and compute min ratio |
| 79 |
mesh = UnitCubeMesh(12, 12, 12) |
| 80 |
test = MeshQuality.radius_ratio_matplotlib_histogram(mesh, 5) |
| 81 |
print(test) |
| 82 |
|
| 83 |
|
| 84 |
@skip_in_parallel |
| 85 |
def test_radius_ratio_min_radius_ratio_max(): |
| 86 |
mesh1d = UnitIntervalMesh(4) |
| 87 |
mesh1d.coordinates()[4] = mesh1d.coordinates()[3] |
| 88 |
|
| 89 |
# Create 2D mesh with one equilateral triangle |
| 90 |
mesh2d = UnitSquareMesh(1, 1, 'left') |
| 91 |
mesh2d.coordinates()[3] += 0.5*(sqrt(3.0)-1.0) |
| 92 |
|
| 93 |
# Create 3D mesh with regular tetrahedron and degenerate cells |
| 94 |
mesh3d = UnitCubeMesh(1, 1, 1) |
| 95 |
mesh3d.coordinates()[2][0] = 1.0 |
| 96 |
mesh3d.coordinates()[7][1] = 0.0 |
| 97 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh1d) |
| 98 |
assert round(rmin - 0.0, 7) == 0 |
| 99 |
assert round(rmax - 1.0, 7) == 0 |
| 100 |
|
| 101 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh2d) |
| 102 |
assert round(rmin - 2.0*sqrt(2.0)/(2.0+sqrt(2.0)), 7) == 0 |
| 103 |
assert round(rmax - 1.0, 7) == 0 |
| 104 |
|
| 105 |
rmin, rmax = MeshQuality.radius_ratio_min_max(mesh3d) |
| 106 |
assert round(rmin - 0.0, 7) == 0 |
| 107 |
assert round(rmax - 1.0, 7) == 0 |
| 108 |
|
| 109 |
|
| 110 |
def test_dihedral_angles_min_max(): |
| 111 |
# Create 3D mesh with regular tetrahedron |
| 112 |
mesh = UnitCubeMesh(2, 2, 2) |
| 113 |
dang_min, dang_max = MeshQuality.dihedral_angles_min_max(mesh) |
| 114 |
assert round(dang_min*(180/numpy.pi) - 45.0) == 0 |
| 115 |
assert round(dang_max*(180/numpy.pi) - 90.0) == 0 |
| 116 |
|
| 117 |
|
| 118 |
def test_dihedral_angles_matplotlib(): |
| 119 |
# Create mesh, collpase and compute min ratio |
| 120 |
mesh = UnitCubeMesh(12, 12, 12) |
| 121 |
test = MeshQuality.dihedral_angles_matplotlib_histogram(mesh, 5) |
| 122 |
print(test) |