| 1 |
#!/usr/bin/env py.test |
| 2 |
|
| 3 |
"""Unit tests for the FunctionSpaceProduct class""" |
| 4 |
|
| 5 |
# Copyright (C) 2011 Johan Hake |
| 6 |
# |
| 7 |
# This file is part of DOLFIN. |
| 8 |
# |
| 9 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 10 |
# it under the terms of the GNU Lesser General Public License as published by |
| 11 |
# the Free Software Foundation, either version 3 of the License, or |
| 12 |
# (at your option) any later version. |
| 13 |
# |
| 14 |
# DOLFIN is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU Lesser General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU Lesser General Public License |
| 20 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
# |
| 22 |
# Modified by Cecile Daversin-Catty 2017 |
| 23 |
# |
| 24 |
# First added: 2017-07-25 |
| 25 |
# Last changed: 2017-07-25 |
| 26 |
|
| 27 |
import pytest |
| 28 |
from dolfin import * |
| 29 |
from ufl_legacy.log import UFLException |
| 30 |
|
| 31 |
from dolfin_utils.test import fixture |
| 32 |
|
| 33 |
@fixture |
| 34 |
def mesh(): |
| 35 |
return UnitCubeMesh(8, 8, 8) |
| 36 |
|
| 37 |
@fixture |
| 38 |
def V1(mesh): |
| 39 |
return FunctionSpace(mesh, 'CG', 1) |
| 40 |
|
| 41 |
@fixture |
| 42 |
def V2(mesh): |
| 43 |
return VectorFunctionSpace(mesh, 'CG', 1) |
| 44 |
|
| 45 |
@fixture |
| 46 |
def V3(mesh): |
| 47 |
return FunctionSpace(mesh, 'CG', 2) |
| 48 |
|
| 49 |
@fixture |
| 50 |
def W(V1,V2,V3): |
| 51 |
return FunctionSpaceProduct(V1,V2,V3) |
| 52 |
|
| 53 |
@fixture |
| 54 |
def W11(V1): |
| 55 |
return FunctionSpaceProduct(V1,V1) |
| 56 |
|
| 57 |
@fixture |
| 58 |
def W12(V1,V2): |
| 59 |
return FunctionSpaceProduct(V1,V2) |
| 60 |
|
| 61 |
@fixture |
| 62 |
def W13(V1,V3): |
| 63 |
return FunctionSpaceProduct(V1,V3) |
| 64 |
|
| 65 |
@fixture |
| 66 |
def f(W): |
| 67 |
return Function(W) |
| 68 |
|
| 69 |
def test_python_interface(W, W11, W12, W13): |
| 70 |
assert isinstance(W11, FunctionSpaceProduct) |
| 71 |
assert isinstance(W12, FunctionSpaceProduct) |
| 72 |
assert isinstance(W13, FunctionSpaceProduct) |
| 73 |
assert isinstance(W, FunctionSpaceProduct) |
| 74 |
|
| 75 |
spaces_list = [W, W11, W12, W13] |
| 76 |
for space in spaces_list: |
| 77 |
assert len(space.sub_spaces()) == space.num_sub_spaces() |
| 78 |
for f in space.sub_spaces(): |
| 79 |
assert isinstance(f, FunctionSpace) |
| 80 |
|
| 81 |
def test_function(f): |
| 82 |
for i in f.num_sub_spaces(): |
| 83 |
assert isinstance(f.sub(i).function_space(), FunctionSpace) |
| 84 |
|
| 85 |
|