/usr/lib/python2.7/dist-packages/ffc/representationutils.py is in python-ffc 1.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | """This module contains utility functions for some code shared between
quadrature and tensor representation."""
# Copyright (C) 2012-2014 Marie Rognes
#
# This file is part of FFC.
#
# FFC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Martin Alnaes 2013
# Modified by Anders Logg 2014
#
# First added: 2013-01-08
# Last changed: 2014-04-15
from ufl.measure import integral_type_to_measure_name
from ffc.fiatinterface import create_element
from ffc.fiatinterface import cellname_to_num_entities
from ffc.cpp import format
from ffc.log import error
def transform_component(component, offset, ufl_element):
"""
This function accounts for the fact that if the geometrical and
topological dimension does not match, then for native vector
elements, in particular the Piola-mapped ones, the physical value
dimensions and the reference value dimensions are not the
same. This has certain consequences for mixed elements, aka 'fun
with offsets'.
"""
# This code is used for tensor/monomialtransformation.py and
# quadrature/quadraturetransformerbase.py.
domain, = ufl_element.domains() # Assuming single domain
gdim = domain.geometric_dimension()
tdim = domain.topological_dimension()
# Do nothing if we are not in a special case: The special cases
# occur if we have piola mapped elements (for which value_shape !=
# ()), and if gdim != tdim)
if gdim == tdim:
return component, offset
all_mappings = create_element(ufl_element).mapping()
special_case = (any(['piola' in m for m in all_mappings])
and ufl_element.num_sub_elements() > 1)
if not special_case:
return component, offset
# Extract lists of reference and physical value dimensions by
# sub-element
reference_value_dims = []
physical_value_dims = []
for sub_element in ufl_element.sub_elements():
assert (len(sub_element.value_shape()) < 2), \
"Vector-valued assumption failed"
if sub_element.value_shape() == ():
reference_value_dims += [1]
physical_value_dims += [1]
else:
reference_value_dims += [sub_element.value_shape()[0]
- (gdim - tdim)]
physical_value_dims += [sub_element.value_shape()[0]]
# Figure out which sub-element number 'component' is in,
# 'sub_element_number' contains the result
tot = physical_value_dims[0]
for sub_element_number in range(len(physical_value_dims)):
if component < tot:
break
else:
tot += physical_value_dims[sub_element_number+1]
# Compute the new reference offset:
reference_offset = sum(reference_value_dims[:sub_element_number])
physical_offset = sum(physical_value_dims[:sub_element_number])
shift = physical_offset - reference_offset
# Compute the component relative to the reference frame
reference_component = component - shift
return reference_component, reference_offset
def needs_oriented_jacobian(form_data):
# Check whether this form needs an oriented jacobian (only forms
# involgin contravariant piola mappings seem to need it)
for ufl_element in form_data.unique_elements:
element = create_element(ufl_element)
if "contravariant piola" in element.mapping():
return True
return False
def initialize_integral_ir(representation, itg_data, form_data, form_id):
"""Initialize a representation dict with common information that is
expected independently of which representation is chosen."""
# Mapping from recognized domain types to entity types
entity_type = {"cell": "cell",
"exterior_facet": "facet",
"interior_facet": "facet",
"point": "vertex",
"custom": "cell"}[itg_data.integral_type]
# Extract data
cellname = itg_data.domain.cell().cellname()
tdim = itg_data.domain.topological_dimension()
assert all(tdim == itg.domain().topological_dimension() for itg in itg_data.integrals)
# Set number of cells if not set TODO: Get automatically from number of domains
num_cells = itg_data.metadata.get("num_cells")
return {"representation": representation,
"integral_type": itg_data.integral_type,
"subdomain_id": itg_data.subdomain_id,
"form_id": form_id,
"rank": form_data.rank,
"geometric_dimension": form_data.geometric_dimension,
"topological_dimension": tdim,
"entitytype": entity_type,
"num_facets": cellname_to_num_entities[cellname][-2],
"num_vertices": cellname_to_num_entities[cellname][0],
"needs_oriented": needs_oriented_jacobian(form_data),
"num_cells": num_cells,
"enabled_coefficients": itg_data.enabled_coefficients,
}
def generate_enabled_coefficients(enabled_coefficients):
# TODO: I don't know how to implement this using the format dict, this will do for now:
initializer_list = ", ".join("true" if enabled else "false"
for enabled in enabled_coefficients)
code = '\n'.join([
"static const std::vector<bool> enabled({%s});" % initializer_list,
"return enabled;",
])
return code
def initialize_integral_code(ir, prefix, parameters):
"Representation independent default initialization of code dict for integral from intermediate representation."
code = {}
code["restrict"] = parameters["restrict_keyword"]
code["classname"] = format["classname " + ir["integral_type"] + "_integral"](prefix, ir["form_id"], ir["subdomain_id"])
code["members"] = ""
code["constructor"] = format["do nothing"]
code["constructor_arguments"] = ""
code["initializer_list"] = ""
code["destructor"] = format["do nothing"]
code["enabled_coefficients"] = generate_enabled_coefficients(ir["enabled_coefficients"])
#code["additional_includes_set"] = set() #ir["additional_includes_set"]
return code
|