9
9
import itertools
10
10
import logging
11
11
12
- import numpy
13
-
14
12
import ufl
15
13
from ffcx .ir .analysis .factorization import \
16
14
compute_argument_factorization
@@ -83,7 +81,7 @@ def compute_integral_ir(cell, integral_type, entitytype, integrands, argument_sh
83
81
for i , v in S .nodes .items ()
84
82
if is_modified_terminal (v ['expression' ])}
85
83
86
- mt_unique_table_reference = build_optimized_tables (
84
+ mt_table_reference = build_optimized_tables (
87
85
quadrature_rule ,
88
86
cell ,
89
87
integral_type ,
@@ -92,18 +90,20 @@ def compute_integral_ir(cell, integral_type, entitytype, integrands, argument_sh
92
90
ir ["unique_tables" ],
93
91
rtol = p ["table_rtol" ],
94
92
atol = p ["table_atol" ])
95
- unique_tables = {v .name : v .values for v in mt_unique_table_reference .values ()}
96
- unique_table_types = {v .name : v .ttype for v in mt_unique_table_reference .values ()}
93
+
94
+ # Fetch unique tables for this quadrature rule
95
+ table_types = {v .name : v .ttype for v in mt_table_reference .values ()}
96
+ tables = {v .name : v .values for v in mt_table_reference .values ()}
97
97
98
98
S_targets = [i for i , v in S .nodes .items () if v .get ('target' , False )]
99
99
100
- if 'zeros' in unique_table_types .values () and len (S_targets ) == 1 :
100
+ if 'zeros' in table_types .values () and len (S_targets ) == 1 :
101
101
# If there are any 'zero' tables, replace symbolically and rebuild graph
102
102
#
103
103
# TODO: Implement zero table elimination for non-scalar graphs
104
104
for i , mt in initial_terminals .items ():
105
105
# Set modified terminals with zero tables to zero
106
- tr = mt_unique_table_reference .get (mt )
106
+ tr = mt_table_reference .get (mt )
107
107
if tr is not None and tr .ttype == "zeros" :
108
108
S .nodes [i ]['expression' ] = ufl .as_ufl (0.0 )
109
109
@@ -161,12 +161,12 @@ def compute_integral_ir(cell, integral_type, entitytype, integrands, argument_sh
161
161
if is_modified_terminal (expr ):
162
162
mt = analyse_modified_terminal (expr )
163
163
F .nodes [i ]['mt' ] = mt
164
- tr = mt_unique_table_reference .get (mt )
164
+ tr = mt_table_reference .get (mt )
165
165
if tr is not None :
166
166
F .nodes [i ]['tr' ] = tr
167
167
168
168
# Attach 'status' to each node: 'inactive', 'piecewise' or 'varying'
169
- analyse_dependencies (F , mt_unique_table_reference )
169
+ analyse_dependencies (F , mt_table_reference )
170
170
171
171
# Output diagnostic graph as pdf
172
172
if visualise :
@@ -208,8 +208,8 @@ def compute_integral_ir(cell, integral_type, entitytype, integrands, argument_sh
208
208
# Check if each *each* factor corresponding to this argument is piecewise
209
209
all_factors_piecewise = all (F .nodes [ifi [0 ]]["status" ] == 'piecewise' for ifi in fi_ci )
210
210
block_is_permuted = False
211
- for n in unames :
212
- if unique_tables [ n ].shape [0 ] > 1 :
211
+ for name in unames :
212
+ if tables [ name ].shape [0 ] > 1 :
213
213
block_is_permuted = True
214
214
ma_data = []
215
215
for i , ma in enumerate (ma_indices ):
@@ -240,28 +240,18 @@ def compute_integral_ir(cell, integral_type, entitytype, integrands, argument_sh
240
240
for mad in blockdata .ma_data :
241
241
active_table_names .add (mad .tabledata .name )
242
242
243
- # Record all table types before dropping tables
244
- ir ["unique_table_types" ].update (unique_table_types )
245
-
246
- # Drop tables not referenced from modified terminals
247
- # and tables of zeros and ones
248
- unused_ttypes = ("zeros" , "ones" )
249
- keep_table_names = set ()
250
243
for name in active_table_names :
251
- ttype = ir ["unique_table_types" ][name ]
252
- if ttype not in unused_ttypes :
253
- if name in unique_tables :
254
- keep_table_names .add (name )
255
- unique_tables = {name : unique_tables [name ] for name in keep_table_names }
256
-
257
- # Add to global set of all tables
258
- for name , table in unique_tables .items ():
259
- tbl = ir ["unique_tables" ].get (name )
260
- if tbl is not None and not numpy .allclose (
261
- tbl , table , rtol = p ["table_rtol" ], atol = p ["table_atol" ]):
262
- raise RuntimeError ("Table values mismatch with same name." )
263
-
264
- ir ["unique_tables" ].update (unique_tables )
244
+ # Drop tables not referenced from modified terminals
245
+ if name not in tables .keys ():
246
+ del tables [name ]
247
+ # Drop tables which are inlined
248
+ if table_types [name ] in ("zeros" , "ones" ):
249
+ del tables [name ]
250
+ del table_types [name ]
251
+
252
+ # Add tables and types for this quadrature rule to global tables dict
253
+ ir ["unique_tables" ].update (tables )
254
+ ir ["unique_table_types" ].update (table_types )
265
255
266
256
# Build IR dict for the given expressions
267
257
# Store final ir for this num_points
0 commit comments