Debian Codegraph @

python/test/unit/mesh/test_periodic_boundary_computation.py

raw
1 """Unit tests for PeriodicBoundaryComputation"""
2
3 # Copyright (C) 2013 Mikael Mortensen
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-04-12
21 # Last changed: 2014-05-30
22
23 import pytest
24 import numpy as np
25 from dolfin import *
26
27 from dolfin_utils.test import *
28
29
30 @fixture
31 def periodic_boundary():
32 class PeriodicBoundary(SubDomain):
33 def inside(self, x, on_boundary):
34 return x[0] < DOLFIN_EPS
35
36 def map(self, x, y):
37 y[0] = x[0] - 1.0
38 y[1] = x[1]
39
40 return PeriodicBoundary()
41
42 @fixture
43 def mesh():
44 return UnitSquareMesh(4, 4)
45
46
47 @skip_in_parallel
48 def test_ComputePeriodicPairs(periodic_boundary, mesh):
49
50 # Verify that correct number of periodic pairs are computed
51 vertices = PeriodicBoundaryComputation.compute_periodic_pairs(mesh, periodic_boundary, 0)
52 edges = PeriodicBoundaryComputation.compute_periodic_pairs(mesh, periodic_boundary, 1)
53 assert len(vertices) == 5
54 assert len(edges) == 4
55
56
57 @skip_in_parallel
58 def test_MastersSlaves(periodic_boundary, mesh):
59
60 # Verify that correct number of masters and slaves are marked
61 mf = PeriodicBoundaryComputation.masters_slaves(mesh, periodic_boundary, 0)
62 assert len(np.where(mf.array() == 1)[0]) == 5
63 assert len(np.where(mf.array() == 2)[0]) == 5
64
65 mf = PeriodicBoundaryComputation.masters_slaves(mesh, periodic_boundary, 1)
66 assert len(np.where(mf.array() == 1)[0]) == 4
67 assert len(np.where(mf.array() == 2)[0]) == 4