| 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.symbolics import * |
| 24 |
from ffc.quadrature.cpp import format, set_float_formatting |
| 25 |
from ffc.parameters import FFC_PARAMETERS |
| 26 |
set_float_formatting(FFC_PARAMETERS['precision']) |
| 27 |
|
| 28 |
|
| 29 |
def testElasWeighted2(): |
| 30 |
|
| 31 |
expr = Product([ |
| 32 |
Symbol('W4', IP), |
| 33 |
Sum([ |
| 34 |
Product([ |
| 35 |
Symbol('FE0_C1_D01_ip_j', BASIS), |
| 36 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 37 |
Symbol('Jinv_00', GEO), |
| 38 |
Symbol('w1', GEO) |
| 39 |
]), |
| 40 |
Product([ |
| 41 |
Symbol('FE0_C1_D01_ip_j', BASIS), |
| 42 |
Symbol('Jinv_01', GEO), |
| 43 |
Sum([ |
| 44 |
Product([ |
| 45 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 46 |
Symbol('w0', GEO) |
| 47 |
]), |
| 48 |
Product([ |
| 49 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 50 |
Symbol('w1', GEO) |
| 51 |
]) |
| 52 |
]) |
| 53 |
]), |
| 54 |
Product([ |
| 55 |
Symbol('w2', GEO), |
| 56 |
Sum([ |
| 57 |
Product([ |
| 58 |
Symbol('FE0_C1_D01_ip_j', BASIS), |
| 59 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 60 |
Symbol('Jinv_00', GEO), |
| 61 |
Symbol('w1', GEO) |
| 62 |
]), |
| 63 |
Product([ |
| 64 |
Symbol('FE0_C1_D01_ip_j', BASIS), |
| 65 |
Symbol('Jinv_01', GEO), |
| 66 |
Sum([ |
| 67 |
Product([ |
| 68 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 69 |
Symbol('w0', GEO) |
| 70 |
]), |
| 71 |
Product([ |
| 72 |
Symbol('FE0_C1_D01_ip_k', BASIS), |
| 73 |
Symbol('w1', GEO) |
| 74 |
]) |
| 75 |
]) |
| 76 |
]) |
| 77 |
]) |
| 78 |
]) |
| 79 |
]) |
| 80 |
]) |
| 81 |
|
| 82 |
expr_exp = expr.expand() |
| 83 |
expr_red = expr_exp.reduce_ops() |
| 84 |
|
| 85 |
det, W4, w0, w1, w2, Jinv_00, Jinv_01, Jinv_11, Jinv_10, FE0_C1_D01_ip_j, FE0_C1_D01_ip_k = [0.123 + i for i in range(11)] |
| 86 |
assert round(eval(str(expr)) - eval(str(expr_exp)), 10) == 0.0 |
| 87 |
assert round(eval(str(expr)) - eval(str(expr_red)), 10) == 0.0 |
| 88 |
assert expr.ops() == 21 |
| 89 |
assert expr_exp.ops() == 32 |
| 90 |
assert expr_red.ops() == 12 |
| 91 |
|
| 92 |
# Generate code |
| 93 |
ip_consts = {} |
| 94 |
geo_consts = {} |
| 95 |
trans_set = set() |
| 96 |
|
| 97 |
start = time.time() |
| 98 |
opt_code = optimise_code(expr, ip_consts, geo_consts, trans_set) |
| 99 |
|
| 100 |
G = [eval(str(list(geo_consts.items())[0][0]))] |
| 101 |
I = [eval(str(list(ip_consts.items())[0][0]))] # noqa: E741 |
| 102 |
assert round(eval(str(expr)) - eval(str(opt_code)), 10) == 0.0 |