| 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 test_Elasticity_Term(): |
| 30 |
# expr: 0.25*W1*det*(FE0_C2_D001[0][j]*FE0_C2_D001[0][k]*Jinv_00*Jinv_21 + FE0_C2_D001[0][j]*FE0_C2_D001[0][k]*Jinv_00*Jinv_21) |
| 31 |
expr = Product([ |
| 32 |
FloatValue(0.25), Symbol('W1', GEO), Symbol('det', GEO), |
| 33 |
Sum([Product([Symbol('FE0_C2_D001_0_j', BASIS), Symbol('FE0_C2_D001_0_k', BASIS), |
| 34 |
Symbol('Jinv_00', GEO), Symbol('Jinv_21', GEO)]), |
| 35 |
Product([Symbol('FE0_C2_D001_0_j', BASIS), Symbol('FE0_C2_D001_0_k', BASIS), |
| 36 |
Symbol('Jinv_00', GEO), Symbol('Jinv_21', GEO)]) |
| 37 |
]) |
| 38 |
]) |
| 39 |
|
| 40 |
expr_exp = expr.expand() |
| 41 |
expr_red = expr_exp.reduce_ops() |
| 42 |
|
| 43 |
det, W1, Jinv_00, Jinv_21, FE0_C2_D001_0_j, FE0_C2_D001_0_k = [0.123 + i for i in range(6)] |
| 44 |
assert round(eval(str(expr)) - eval(str(expr_exp)), 10) == 0.0 |
| 45 |
assert round(eval(str(expr)) - eval(str(expr_red)), 10) == 0.0 |
| 46 |
assert expr.ops() == 10 |
| 47 |
assert expr_exp.ops() == 6 |
| 48 |
assert expr_red.ops() == 6 |
| 49 |
|
| 50 |
# Generate code |
| 51 |
ip_consts = {} |
| 52 |
geo_consts = {} |
| 53 |
trans_set = set() |
| 54 |
|
| 55 |
start = time.time() |
| 56 |
opt_code = optimise_code(expr, ip_consts, geo_consts, trans_set) |
| 57 |
|
| 58 |
G = [eval(str(list(geo_consts.items())[0][0]))] |
| 59 |
assert round(eval(str(expr)) - eval(str(opt_code))) == 0.0 |