Skip to content

Commit

Permalink
Remove more CNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrichardson committed Aug 23, 2023
1 parent d301c0e commit 4d017d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
38 changes: 12 additions & 26 deletions ffcx/codegeneration/C/dofmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def generator(ir, options):
d["num_element_support_dofs"] = ir.num_element_support_dofs
d["num_sub_dofmaps"] = ir.num_sub_dofmaps

import ffcx.codegeneration.C.cnodes as L

flattened_entity_dofs = []
entity_dof_offsets = [0]
for dim in ir.entity_dofs:
Expand All @@ -39,19 +37,13 @@ def generator(ir, options):
flattened_entity_dofs.append(v)
entity_dof_offsets.append(len(flattened_entity_dofs))
d["entity_dofs"] = f"entity_dofs_{ir.name}"
d["entity_dofs_init"] = L.ArrayDecl(
"int",
f"entity_dofs_{ir.name}",
values=flattened_entity_dofs,
sizes=len(flattened_entity_dofs),
)
values = ", ".join(str(i) for i in flattened_entity_dofs)
sizes = len(flattened_entity_dofs)
d["entity_dofs_init"] = f"int entity_dofs_{ir.name}[{sizes}] = {{{values}}};"
d["entity_dof_offsets"] = f"entity_dof_offsets_{ir.name}"
d["entity_dof_offsets_init"] = L.ArrayDecl(
"int",
f"entity_dof_offsets_{ir.name}",
values=entity_dof_offsets,
sizes=len(entity_dof_offsets),
)
values = ", ".join(str(i) for i in entity_dof_offsets)
sizes = len(entity_dof_offsets)
d["entity_dof_offsets_init"] = f"int entity_dof_offsets_{ir.name}[{sizes}] = {{{values}}};"

# Closure
flattened_entity_closure_dofs = []
Expand All @@ -62,19 +54,13 @@ def generator(ir, options):
flattened_entity_closure_dofs.append(v)
entity_closure_dof_offsets.append(len(flattened_entity_closure_dofs))
d["entity_closure_dofs"] = f"entity_closure_dofs_{ir.name}"
d["entity_closure_dofs_init"] = L.ArrayDecl(
"int",
f"entity_closure_dofs_{ir.name}",
values=flattened_entity_closure_dofs,
sizes=len(flattened_entity_closure_dofs),
)
values = ", ".join(str(i) for i in flattened_entity_closure_dofs)
sizes = len(flattened_entity_closure_dofs)
d["entity_closure_dofs_init"] = f"int entity_closure_dofs_{ir.name}[{sizes}] = {{{values}}};"
d["entity_closure_dof_offsets"] = f"entity_closure_dof_offsets_{ir.name}"
d["entity_closure_dof_offsets_init"] = L.ArrayDecl(
"int",
f"entity_closure_dof_offsets_{ir.name}",
values=entity_closure_dof_offsets,
sizes=len(entity_closure_dof_offsets),
)
values = ", ".join(str(i) for i in entity_closure_dof_offsets)
sizes = len(entity_dof_offsets)
d["entity_closure_dof_offsets_init"] = f"int entity_closure_dof_offsets_{ir.name}[{sizes}] = {{{values}}};"

d["block_size"] = ir.block_size

Expand Down
29 changes: 13 additions & 16 deletions ffcx/codegeneration/C/finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import logging

import ffcx.codegeneration.basix_custom_element_template as ufcx_basix_custom_finite_element
import ffcx.codegeneration.C.basix_custom_element_template as ufcx_basix_custom_finite_element
import ffcx.codegeneration.C.finite_element_template as ufcx_finite_element
import ufl

Expand Down Expand Up @@ -63,30 +63,29 @@ def generator(ir, options):
else:
d["basix_cell"] = int(ir.basix_cell)

import ffcx.codegeneration.C.cnodes as L

if len(ir.value_shape) > 0:
d["value_shape"] = f"value_shape_{ir.name}"
d["value_shape_init"] = L.ArrayDecl(
"int", f"value_shape_{ir.name}", values=ir.value_shape, sizes=len(ir.value_shape))
values = ", ".join(str(i) for i in ir.values_shape)
sizes = len(ir.value_shape)
d["value_shape_init"] = f"int value_shape_{ir.name}[{sizes}] = {{{values}}};"
else:
d["value_shape"] = "NULL"
d["value_shape_init"] = ""

if len(ir.reference_value_shape) > 0:
d["reference_value_shape"] = f"reference_value_shape_{ir.name}"
d["reference_value_shape_init"] = L.ArrayDecl(
"int", f"reference_value_shape_{ir.name}",
values=ir.reference_value_shape, sizes=len(ir.reference_value_shape))
values = ", ".join(str(i) for i in ir.reference_value_shape)
sizes = len(ir.reference_value_shape)
d["reference_value_shape_init"] = "int reference_value_shape_{ir.name}[{sizes}] = {{{values}}};"
else:
d["reference_value_shape"] = "NULL"
d["reference_value_shape_init"] = ""

if len(ir.sub_elements) > 0:
d["sub_elements"] = f"sub_elements_{ir.name}"
d["sub_elements_init"] = L.ArrayDecl(
"ufcx_finite_element*", f"sub_elements_{ir.name}",
values=[L.AddressOf(L.Symbol(el)) for el in ir.sub_elements], sizes=len(ir.sub_elements))
values = ", ".join(f"&{el}" for el in ir.sub_elements)
sizes = len(ir.sub_elements)
d["sub_elements_init"] = f"ufcx_finite_element* sub_elements_{ir.name}[{sizes}] = {{{values}}};"
else:
d["sub_elements"] = "NULL"
d["sub_elements_init"] = ""
Expand Down Expand Up @@ -126,14 +125,12 @@ def generate_custom_element(name, ir):
d["highest_degree"] = ir.highest_degree
d["discontinuous"] = "true" if ir.discontinuous else "false"
d["interpolation_nderivs"] = ir.interpolation_nderivs

import ffcx.codegeneration.C.cnodes as L

d["value_shape_length"] = len(ir.value_shape)
if len(ir.value_shape) > 0:
d["value_shape"] = f"value_shape_{name}"
d["value_shape_init"] = L.ArrayDecl(
"int", f"value_shape_{name}", values=ir.value_shape, sizes=len(ir.value_shape))
values = ", ".join(str(i) for i in ir.value_shape)
sizes = len(ir.value_shape)
d["value_shape_init"] = f"int value_shape_{name}[{sizes}] = {{{values}}};"
else:
d["value_shape"] = "NULL"
d["value_shape_init"] = ""
Expand Down

0 comments on commit 4d017d3

Please sign in to comment.