def make_all_element_classnames(prefix, elements, coordinate_elements, element_numbers, parameters, jit): if jit: # Make unique classnames to match separately jit-compiled # module classnames = { "finite_element": { e: make_finite_element_jit_classname(e, parameters) for e in elements }, "dofmap": { e: make_dofmap_jit_classname(e, parameters) for e in elements }, "coordinate_mapping": { e: make_coordinate_mapping_jit_classname(e, parameters) for e in coordinate_elements }, } else: # Make unique classnames only within this module (using a # shared prefix and element numbers that are only unique # within this module) classnames = { "finite_element": { e: make_classname(prefix, "finite_element", element_numbers[e]) for e in elements }, "dofmap": { e: make_classname(prefix, "dofmap", element_numbers[e]) for e in elements }, "coordinate_mapping": { e: make_classname(prefix, "coordinate_mapping", element_numbers[e]) for e in coordinate_elements }, } return classnames
def _instantiate_element_and_dofmap(module, prefix): "Instantiate objects of the jit-compiled finite_element and dofmap." import dijitso fe_classname = make_classname(prefix, "finite_element", "main") dm_classname = make_classname(prefix, "dofmap", "main") fe = dijitso.extract_factory_function(module, "create_" + fe_classname)() dm = dijitso.extract_factory_function(module, "create_" + dm_classname)() return (fe, dm)
def _encapsule_form(prefix, object_names, form_data, i, element_map, superclassname=None): element_numbers = [element_map[e] for e in form_data.argument_elements + form_data.coefficient_elements] if superclassname is None: superclassname = "Form" form_names = UFCFormNames( object_names.get(id(form_data.original_form), "%d" % i), [object_names.get(id(obj), "w%d" % j) for j, obj in enumerate(form_data.reduced_coefficients)], make_classname(prefix, "form", i), [make_classname(prefix, "finite_element", j) for j in element_numbers], [make_classname(prefix, "dofmap", j) for j in element_numbers], superclassname) return form_names
def generate_factory_functions(prefix, kind, classname): publicname = make_classname(prefix, kind, "main") code_h = factory_decl % { "basename": "ufc::%s" % kind, "publicname": publicname, } code_c = factory_impl % { "basename": "ufc::%s" % kind, "publicname": publicname, "privatename": classname } return code_h, code_c
def make_all_element_classnames(prefix, elements, coordinate_elements, element_numbers, parameters, jit): if jit: # Make unique classnames to match separately jit-compiled # module classnames = { "finite_element": { e: make_finite_element_jit_classname(e, parameters) for e in elements }, "dofmap": {e: make_dofmap_jit_classname(e, parameters) for e in elements}, "coordinate_mapping": { e: make_coordinate_mapping_jit_classname(e, parameters) for e in coordinate_elements }, } else: # Make unique classnames only within this module (using a # shared prefix and element numbers that are only unique # within this module) classnames = { "finite_element": { e: make_classname(prefix, "finite_element", element_numbers[e]) for e in elements }, "dofmap": { e: make_classname(prefix, "dofmap", element_numbers[e]) for e in elements }, "coordinate_mapping": { e: make_classname(prefix, "coordinate_mapping", element_numbers[e]) for e in coordinate_elements }, } return classnames
def _instantiate_coordinate_mapping(module, prefix): "Instantiate an object of the jit-compiled coordinate_mapping." import dijitso classname = make_classname(prefix, "coordinate_mapping", "main") form = dijitso.extract_factory_function(module, "create_" + classname)() return form
def make_coordinate_mapping_jit_classname(ufl_mesh, parameters): from ffc.jitcompiler import compute_jit_prefix # FIXME circular file dependency kind, prefix = compute_jit_prefix(ufl_mesh, parameters, kind="coordinate_mapping") return make_classname(prefix, "coordinate_mapping", "main")
def make_dofmap_jit_classname(ufl_element, parameters): from ffc.jitcompiler import compute_jit_prefix # FIXME circular file dependency kind, prefix = compute_jit_prefix(ufl_element, parameters) return make_classname(prefix, "dofmap", "main")
def _compute_form_ir(form_data, form_id, prefix, element_numbers, classnames, parameters, jit=False): "Compute intermediate representation of form." # For consistency, all jit objects now have classnames with postfix "main" if jit: assert form_id == 0 form_id = "main" # Store id ir = {"id": form_id} # Storing prefix here for reconstruction of classnames on code # generation side ir["prefix"] = prefix # Remember jit status ir["jit"] = jit # Compute common data ir["classname"] = make_classname(prefix, "form", form_id) # ir["members"] = None # unused # ir["constructor"] = None # unused # ir["destructor"] = None # unused ir["signature"] = form_data.original_form.signature() ir["rank"] = len(form_data.original_form.arguments()) ir["num_coefficients"] = len(form_data.reduced_coefficients) ir["original_coefficient_position"] = form_data.original_coefficient_positions # TODO: Remove create_coordinate_{finite_element,dofmap} and # access through coordinate_mapping instead in dolfin, when that's # in place ir["create_coordinate_finite_element"] = [ classnames["finite_element"][e] for e in form_data.coordinate_elements ] ir["create_coordinate_dofmap"] = [ classnames["dofmap"][e] for e in form_data.coordinate_elements ] ir["create_coordinate_mapping"] = [ classnames["coordinate_mapping"][e] for e in form_data.coordinate_elements ] ir["create_finite_element"] = [ classnames["finite_element"][e] for e in form_data.argument_elements + form_data.coefficient_elements ] ir["create_dofmap"] = [ classnames["dofmap"][e] for e in form_data.argument_elements + form_data.coefficient_elements ] # Create integral ids and names using form prefix # (integrals are always generated as part of form so don't get # their own prefix) for integral_type in ufc_integral_types: ir["max_%s_subdomain_id" % integral_type] = \ form_data.max_subdomain_ids.get(integral_type, 0) ir["has_%s_integrals" % integral_type] = \ _has_foo_integrals(prefix, form_id, integral_type, form_data) ir["create_%s_integral" % integral_type] = \ _create_foo_integral(prefix, form_id, integral_type, form_data) ir["create_default_%s_integral" % integral_type] = \ _create_default_foo_integral(prefix, form_id, integral_type, form_data) return ir
def _encapsule_element(prefix, elements): element_number = len(elements) - 1 # eh? this doesn't make any sense args = ("0", [make_classname(prefix, "finite_element", element_number)], [make_classname(prefix, "dofmap", element_number)]) return UFCElementNames(*args)