| 1 |
"""Unit tests for the Edge class""" |
| 2 |
|
| 3 |
# Copyright (C) 2011 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: 2011-02-26 |
| 21 |
# Last changed: 2014-05-30 |
| 22 |
|
| 23 |
import pytest |
| 24 |
from dolfin import * |
| 25 |
from dolfin_utils.test import fixture, skip_in_parallel |
| 26 |
|
| 27 |
|
| 28 |
@fixture |
| 29 |
def cube(): |
| 30 |
return UnitCubeMesh(5, 5, 5) |
| 31 |
|
| 32 |
|
| 33 |
@fixture |
| 34 |
def square(): |
| 35 |
return UnitSquareMesh(5, 5) |
| 36 |
|
| 37 |
|
| 38 |
@pytest.fixture(scope='module', params=range(2)) |
| 39 |
def meshes(cube, square, request): |
| 40 |
mesh = [cube, square] |
| 41 |
return mesh[request.param] |
| 42 |
|
| 43 |
|
| 44 |
@skip_in_parallel |
| 45 |
def test_2DEdgeLength(square): |
| 46 |
"""Iterate over edges and sum length.""" |
| 47 |
length = 0.0 |
| 48 |
for e in edges(square): |
| 49 |
length += e.length() |
| 50 |
assert round(length - 19.07106781186544708362, 7) == 0 |
| 51 |
|
| 52 |
|
| 53 |
@skip_in_parallel |
| 54 |
def test_3DEdgeLength(cube): |
| 55 |
"""Iterate over edges and sum length.""" |
| 56 |
length = 0.0 |
| 57 |
for e in edges(cube): |
| 58 |
length += e.length() |
| 59 |
assert round(length - 278.58049080280125053832, 7) == 0 |
| 60 |
|
| 61 |
|
| 62 |
def test_EdgeDot(meshes): |
| 63 |
"""Iterate over edges compute dot product with .""" |
| 64 |
for e in edges(meshes): |
| 65 |
dot = e.dot(e)/(e.length()**2) |
| 66 |
assert round(dot - 1.0, 7) == 0 |