| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright (C) 2010 Kristian B. Oelgaard |
| 3 |
# |
| 4 |
# This file is part of FFC. |
| 5 |
# |
| 6 |
# FFC is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU Lesser General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# FFC is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU Lesser General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU Lesser General Public License |
| 17 |
# along with FFC. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
import pytest |
| 20 |
import time |
| 21 |
|
| 22 |
# FFC modules |
| 23 |
from ffc.quadrature.reduce_operations import operation_count, expand_operations, reduce_operations |
| 24 |
from ffc.quadrature.symbolics import * |
| 25 |
from ffc.quadrature.cpp import format, set_float_formatting |
| 26 |
from ffc.parameters import FFC_PARAMETERS |
| 27 |
set_float_formatting(FFC_PARAMETERS['precision']) |
| 28 |
|
| 29 |
|
| 30 |
def testPoisson(): |
| 31 |
poisson = """((Jinv_00*FE0_D10_ip_j + Jinv_10*FE0_D01_ip_j)*(Jinv_00*FE0_D10_ip_k + Jinv_10*FE0_D01_ip_k) + (Jinv_01*FE0_D10_ip_j + Jinv_11*FE0_D01_ip_j)*(Jinv_01*FE0_D10_ip_k + Jinv_11*FE0_D01_ip_k))*W4_ip*det""" |
| 32 |
|
| 33 |
expr = Product([ |
| 34 |
Sum([ |
| 35 |
Product([ |
| 36 |
Sum([ |
| 37 |
Product([Symbol("Jinv_00", GEO), Symbol("FE0_D10_ip_j", BASIS)]), |
| 38 |
Product([Symbol("Jinv_10", GEO), Symbol("FE0_D01_ip_j", BASIS)]) |
| 39 |
]), |
| 40 |
Sum([ |
| 41 |
Product([Symbol("Jinv_00", GEO), Symbol("FE0_D10_ip_k", BASIS)]), |
| 42 |
Product([Symbol("Jinv_10", GEO), Symbol("FE0_D01_ip_k", BASIS)]) |
| 43 |
]) |
| 44 |
]), |
| 45 |
Product([ |
| 46 |
Sum([ |
| 47 |
Product([Symbol("Jinv_01", GEO), Symbol("FE0_D10_ip_j", BASIS)]), |
| 48 |
Product([Symbol("Jinv_11", GEO), Symbol("FE0_D01_ip_j", BASIS)]) |
| 49 |
]), |
| 50 |
Sum([ |
| 51 |
Product([Symbol("Jinv_01", GEO), Symbol("FE0_D10_ip_k", BASIS)]), |
| 52 |
Product([Symbol("Jinv_11", GEO), Symbol("FE0_D01_ip_k", BASIS)]) |
| 53 |
]) |
| 54 |
]) |
| 55 |
]), |
| 56 |
Symbol("W4_ip", IP), |
| 57 |
Symbol("det", GEO) |
| 58 |
]) |
| 59 |
|
| 60 |
expr_exp = expr.expand() |
| 61 |
poisson_exp = expand_operations(poisson, format) |
| 62 |
|
| 63 |
expr_red = expr_exp.reduce_ops() |
| 64 |
poisson_red = reduce_operations(poisson, format) |
| 65 |
|
| 66 |
poisson_exp_ops = operation_count(poisson_exp, format) |
| 67 |
poisson_red_ops = operation_count(poisson_red, format) |
| 68 |
|
| 69 |
Jinv_00, Jinv_01, Jinv_10, Jinv_11, W4_ip, det = (1.1, 1.5, -4.3, 1.7, 11, 52.3) |
| 70 |
FE0_D01_ip_j, FE0_D10_ip_j, FE0_D01_ip_k, FE0_D10_ip_k = (1.12, 5.7, -9.3, 7.4) |
| 71 |
assert round(eval(str(expr)) - eval(str(expr_exp)), 10) == 0.0 |
| 72 |
assert round(eval(str(expr)) - eval(str(expr_red)), 10) == 0.0 |
| 73 |
assert round(eval(str(expr)) - eval(str(poisson)), 10) == 0.0 |
| 74 |
assert round(eval(str(expr)) - eval(str(poisson_exp)), 10) == 0.0 |
| 75 |
assert round(eval(str(expr)) - eval(str(poisson_red)), 10) == 0.0 |
| 76 |
assert expr.ops() == 17 |
| 77 |
assert poisson_exp_ops == 47 |
| 78 |
assert expr_exp.ops() == 47 |
| 79 |
assert poisson_red_ops == 23 |
| 80 |
assert expr_red.ops() == 23 |