18
18
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
20
20
# First added: 2007-03-16
21
# Last changed: 2010-05-18
23
# Hacked by Marie E. Rognes, 2013.
21
# Last changed: 2014-04-23
23
# Hacked by Marie E. Rognes 2013
24
# Modified by Anders Logg 2014
29
30
from ffc.log import debug, error, ffc_assert
30
31
from ffc.cpp import format
32
def create_psi_tables(tables, eliminate_zeros, entitytype):
33
def create_psi_tables(tables, eliminate_zeros, entity_type):
33
34
"Create names and maps for tables and non-zero entries if appropriate."
35
36
debug("\nQG-utils, psi_tables:\n" + str(tables))
36
38
# Create element map {points:{element:number,},}
37
39
# and a plain dictionary {name:values,}.
38
element_map, flat_tables = flatten_psi_tables(tables, entitytype)
40
element_map, flat_tables = flatten_psi_tables(tables, entity_type)
39
41
debug("\nQG-utils, psi_tables, flat_tables:\n" + str(flat_tables))
41
43
# Reduce tables such that we only have those tables left with unique values
42
44
# Create a name map for those tables that are redundant.
43
45
name_map, unique_tables = unique_psi_tables(flat_tables, eliminate_zeros)
45
46
debug("\nQG-utils, psi_tables, unique_tables:\n" + str(unique_tables))
46
47
debug("\nQG-utils, psi_tables, name_map:\n" + str(name_map))
48
49
return (element_map, name_map, unique_tables)
50
def flatten_psi_tables(tables, entitytype):
51
def flatten_psi_tables(tables, entity_type):
51
52
"""Create a 'flat' dictionary of tables with unique names and a name
52
53
map that maps number of quadrature points and element name to a unique
106
107
# Iterate over the innermost tables for each scalar component
107
108
for component, psi_table in component_tables:
108
109
# Generate the table name.
109
name = generate_psi_name(counter, entitytype, entity, component, derivs, avg)
110
name = generate_psi_name(counter, entity_type, entity, component, derivs, avg)
111
112
# Verify shape of basis (can be omitted for speed if needed).
112
ffc_assert(len(numpy.shape(psi_table)) == 2 and numpy.shape(psi_table)[0] == num_points,
113
"This table has the wrong shape: " + str(psi_table))
113
ffc_assert(num_points is None or (len(numpy.shape(psi_table)) == 2 and numpy.shape(psi_table)[0] == num_points),
114
"This table has the wrong shape: " + str(psi_table))
114
115
# Verify uniqueness of names
115
116
ffc_assert(name not in flat_tables,
116
117
"Table name is not unique, something is wrong:\n name = %s\n table = %s\n" % (name, flat_tables))
300
306
# Check if dimensions match.
301
307
if numpy.shape(val0) == numpy.shape(val1):
302
308
# Check if values are the same.
303
if abs(val0 - val1).max() < format_epsilon:
309
if len(val0) > 0 and abs(val0 - val1).max() < format_epsilon:
304
310
mapped.append(name1)
305
311
del tables[name1]
306
312
if name0 in name_map: