~ubuntu-branches/ubuntu/vivid/ffc/vivid

« back to all changes in this revision

Viewing changes to ffc/quadrature/quadratureutils.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2014-06-03 18:26:02 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140603182602-zvnubjjh7i78e1v0
Tags: 1.4.0-1
* New upstream release.
* debian/control:
  - Add swig in Build-Depends.
  - Remove python-ufc from Depends.
  - Add ufc and python-ufc to Provides, Conflicts and Replaces.
  - Remove python-ferari and python-dolfin from Suggests.
  - Bump minimum required version for python-fiat, python-instant and
    python-ufl to 1.4.0.
* debian/rules: Add override for auto clean target to remove generated
  cmake and pkg-config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
# First added:  2007-03-16
21
 
# Last changed: 2010-05-18
22
 
 
23
 
# Hacked by Marie E. Rognes, 2013.
 
21
# Last changed: 2014-04-23
 
22
#
 
23
# Hacked by Marie E. Rognes 2013
 
24
# Modified by Anders Logg 2014
24
25
 
25
26
# Python modules.
26
27
import numpy
29
30
from ffc.log import debug, error, ffc_assert
30
31
from ffc.cpp import format
31
32
 
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."
34
35
 
35
36
    debug("\nQG-utils, psi_tables:\n" + str(tables))
 
37
 
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))
40
42
 
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)
44
 
 
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))
47
48
 
48
49
    return (element_map, name_map, unique_tables)
49
50
 
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
53
54
    element number.
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)
110
111
 
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))
157
158
    non_zero_columns = {}
158
159
    if eliminate_zeros:
159
160
        for name in sorted(tables.keys()):
 
161
 
160
162
            # Get values.
161
163
            vals = tables[name]
162
164
 
 
165
            # Skip if values are missing
 
166
            if len(vals) == 0:
 
167
                continue
 
168
 
163
169
            # Use the first row as reference.
164
170
            non_zeros = list(vals[0].nonzero()[0])
165
171
 
291
297
            continue
292
298
        val0 = numpy.array(tables[name0])
293
299
 
294
 
        for j in range(i+1, len(names)):
 
300
        for j in range(i + 1, len(names)):
295
301
            name1 = names[j]
296
302
            if name1 in mapped:
297
303
                continue
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:
323
329
    names = []
324
330
    for name in tables:
325
331
        vals = tables[name]
326
 
        if abs(vals - numpy.ones(numpy.shape(vals))).max() < f_epsilon:
 
332
        if len(vals) > 0 and abs(vals - numpy.ones(numpy.shape(vals))).max() < f_epsilon:
327
333
            names.append(name)
328
334
    return names
329
335
 
333
339
    names = []
334
340
    for name in tables:
335
341
        vals = tables[name]
336
 
        if abs(vals).max() < f_epsilon:
 
342
        if len(vals) > 0 and abs(vals).max() < f_epsilon:
337
343
            names.append(name)
338
344
    return names
339
345
 
342
348
    # This is probably not used.
343
349
    if len(expr) == 0:
344
350
        return expr
 
351
 
345
352
    # Format keys and values to lists and tuples.
346
353
    if len(expr) == 1:
347
354
        new = {}
355
362
            new[key] = val
356
363
 
357
364
        return new
 
365
 
358
366
    # Create permutations of two lists.
359
367
    # TODO: there could be a cleverer way of changing types of keys and vals.
360
368
    if len(expr) == 2: