Debian Codegraph @

test/unit/symbolics/test_elas_weighted.py

raw
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 testElasWeighted():
30 expr = Product([
31 Symbol('W4', IP),
32 Sum([
33 Product([
34 Symbol('FE0_C1_D01_ip_j', BASIS),
35 Symbol('FE0_C1_D01_ip_k', BASIS),
36 Symbol('Jinv_00', GEO),
37 Symbol('w1', GEO)
38 ]),
39 Product([
40 Symbol('FE0_C1_D01_ip_j', BASIS),
41 Symbol('FE0_C1_D01_ip_k', BASIS),
42 Symbol('Jinv_01', GEO),
43 Symbol('w0', GEO)
44 ]),
45 Product([
46 Symbol('w2', GEO),
47 Sum([
48 Product([
49 Symbol('FE0_C1_D01_ip_j', BASIS),
50 Symbol('FE0_C1_D01_ip_k', BASIS),
51 Symbol('Jinv_00', GEO),
52 Symbol('w1', GEO)
53 ]),
54 Product([
55 Symbol('FE0_C1_D01_ip_j', BASIS),
56 Symbol('FE0_C1_D01_ip_k', BASIS),
57 Symbol('Jinv_01', GEO),
58 Symbol('w0', GEO)
59 ])
60 ])
61 ])
62 ])
63 ])
64
65 expr_exp = expr.expand()
66 expr_red = expr_exp.reduce_ops()
67
68 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)]
69 assert round(eval(str(expr)) - eval(str(expr_exp))) == 0.0
70 assert round(eval(str(expr)) - eval(str(expr_red))) == 0.0
71 assert expr.ops() == 17
72 assert expr_exp.ops() == 21
73 assert expr_red.ops() == 10
74
75 # Generate code
76 ip_consts = {}
77 geo_consts = {}
78 trans_set = set()
79
80 start = time.time()
81 opt_code = optimise_code(expr, ip_consts, geo_consts, trans_set)
82
83 G = [eval(str(list(geo_consts.items())[0][0]))]
84 I = [eval(str(list(ip_consts.items())[0][0]))] # noqa: E741
85 assert round(eval(str(expr)) - eval(str(opt_code))) == 0.0