| 1 |
"""Unit tests for reported multimesh issues""" |
| 2 |
|
| 3 |
# Copyright (C) 2016 Anders Logg |
| 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 |
# Modified by August Johansson 2016 |
| 21 |
# |
| 22 |
# First added: 2016-05-03 |
| 23 |
# Last changed: 2017-06-19 |
| 24 |
|
| 25 |
import pytest |
| 26 |
|
| 27 |
from dolfin import * |
| 28 |
from dolfin_utils.test import skip_in_parallel |
| 29 |
|
| 30 |
@skip_in_parallel |
| 31 |
def test_issue_754(): |
| 32 |
N = 3 |
| 33 |
meshes = [UnitSquareMesh(2*N, 2*N), |
| 34 |
RectangleMesh(Point(0.1, 0.15), Point(0.6, 0.65), N, N), |
| 35 |
RectangleMesh(Point(0.4, 0.35), Point(0.9, 0.85), N, N)] |
| 36 |
|
| 37 |
multimesh = MultiMesh() |
| 38 |
for mesh in meshes: |
| 39 |
multimesh.add(mesh) |
| 40 |
multimesh.build() |
| 41 |
|
| 42 |
V = MultiMeshFunctionSpace(multimesh, "CG", 1) |
| 43 |
u, v = TrialFunction(V), TestFunction(V) |
| 44 |
|
| 45 |
a = inner(u,v) * dX |
| 46 |
b = a + inner(jump(u),jump(v)) * dI |
| 47 |
A = assemble_multimesh(a) |
| 48 |
B = assemble_multimesh(b) |
| 49 |
|
| 50 |
# create multimesh function w such that |
| 51 |
# w(x) = 1 if x is in the last mesh |
| 52 |
# = 0 otherwise |
| 53 |
V_1 = FunctionSpace(multimesh.part(len(meshes)-1), "CG", 1) |
| 54 |
v_1 = interpolate(Constant(1),V_1) |
| 55 |
w = MultiMeshFunction(V) |
| 56 |
w.assign_part((len(meshes)-1), v_1) |
| 57 |
|
| 58 |
# Compute the area and perimeter of the last mesh |
| 59 |
a = w.vector().inner(A * w.vector()) |
| 60 |
p = w.vector().inner(B * w.vector()) - a |
| 61 |
|
| 62 |
# print("Computed area (a) and perimeter (p) of last mesh:") |
| 63 |
# print(" a = {0:1.4f} (exact value is .25)".format(a)) |
| 64 |
# print(" p = {0:1.4f} (exact value is 2.0)".format(p)) |
| 65 |
assert(abs(a - 0.25) < DOLFIN_EPS_LARGE) |
| 66 |
assert(abs(p - 2.) < DOLFIN_EPS_LARGE) |