Debian Codegraph @

python/test/unit/multimesh/test_multimesh_autocover.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2 """Unit tests for the MultiMeshFunction autocover functionality"""
3
4 # Copyright (C) 2018 Jørgen S. Dokken
5 #
6 # This file is part of DOLFIN.
7 #
8 # DOLFIN is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # DOLFIN is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
20 #
21 #
22 # First added: 2018-04-03
23 # Last changed: 2018-04-03
24
25
26 from dolfin import *
27 from dolfin_utils.test import fixture, skip_in_parallel
28 import numpy
29
30
31 @fixture
32 def multimesh():
33 mesh_0 = UnitSquareMesh(20, 20)
34 mesh_1 = RectangleMesh(Point(0.23, 0.23),
35 Point(0.66, 0.66), 10, 10)
36 multimesh = MultiMesh()
37 multimesh.add(mesh_0)
38 multimesh.add(mesh_1)
39 multimesh.build()
40 return multimesh
41
42
43 @fixture
44 def a():
45 return 0.3
46
47
48 @fixture
49 def b():
50 return 0.6
51
52
53 @fixture
54 def complex_multimesh(a, b):
55 meshes = [UnitSquareMesh(50, 50),
56 RectangleMesh(Point(0.105, 0.1), Point(a, 0.905), 15, 15),
57 RectangleMesh(Point(0.101, b), Point(0.903, 0.902), 15, 15),
58 RectangleMesh(Point(b, 0.08), Point(0.91, 0.91), 15, 15),
59 RectangleMesh(Point(0.102, 0.09), Point(0.92, a), 15, 13)]
60 multimesh = MultiMesh()
61 for mesh in meshes:
62 multimesh.add(mesh)
63 multimesh.build()
64 return multimesh
65
66
67 @fixture
68 def V(multimesh):
69 return MultiMeshFunctionSpace(multimesh, "CG", 1)
70
71
72 @fixture
73 def one(V):
74 return interpolate(Constant(1), V)
75
76
77 @fixture
78 def complex_mesh_one(complex_multimesh):
79 V = MultiMeshFunctionSpace(complex_multimesh, "CG", 1)
80 return interpolate(Constant(1), V)
81
82
83 @skip_in_parallel
84 def test_auto_cover_all(multimesh, one):
85 # Cover all cells
86 multimesh.auto_cover(0, Point(0, 0))
87 multimesh.auto_cover(1, Point(0.5, 0.5))
88 assert(numpy.isclose(assemble_multimesh(one * dX), 0))
89
90 # Reset auto_cover
91 multimesh.build()
92 assert(numpy.isclose(assemble_multimesh(one * dX), 1))
93
94
95 @skip_in_parallel
96 def test_auto_cover_top(multimesh, one):
97 # Cover cells on top mesh
98 multimesh.auto_cover(0, Point(0, 0))
99 assert(numpy.isclose(assemble_multimesh(one * dX), 0.1849))
100
101
102 @skip_in_parallel
103 def test_auto_cover_complex(a, b, complex_multimesh, complex_mesh_one):
104 # Cover cells inscribed by the four top meshes
105 complex_multimesh.auto_cover(0, Point(a + 0.5 * (b - a),
106 a + 0.5 * (b - a)))
107 assert(numpy.isclose(assemble_multimesh(complex_mesh_one * dX),
108 1 - (b - a)**2))