Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write the Basix hash into generated code (or 0 if the element is not plain C++ Basix element) #688

Merged
merged 13 commits into from
May 2, 2024
2 changes: 1 addition & 1 deletion ffcx/codegeneration/C/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def generator(ir, options):
) in ir.function_spaces.items():
code += [f"static ufcx_function_space function_space_{name}_{ir.name_from_uflfile} ="]
code += ["{"]
code += [f".finite_element = {element},"]
code += [f".finite_element = {0 if element is None else element}u,"]
code += [f'.geometry_family = "{cmap_family}",']
code += [f".geometry_degree = {cmap_degree},"]
code += [f".geometry_basix_cell = {int(cmap_celltype)},"]
Expand Down
6 changes: 3 additions & 3 deletions ffcx/codegeneration/C/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def generator(ir, options):

if len(ir.finite_elements) > 0:
d["finite_elements"] = f"finite_elements_{ir.name}"
values = ", ".join(f"{el}" for el in ir.finite_elements)
values = ", ".join(f"{0 if el is None else el}u" for el in ir.finite_elements)
sizes = len(ir.finite_elements)
d["finite_elements_init"] = f"long int finite_elements_{ir.name}[{sizes}] = {{{values}}};"
d["finite_elements_init"] = f"uint64_t finite_elements_{ir.name}[{sizes}] = {{{values}}};"
else:
d["finite_elements"] = "NULL"
d["finite_elements_init"] = ""
Expand Down Expand Up @@ -131,7 +131,7 @@ def generator(ir, options):
) in ir.function_spaces.items():
code += [f"static ufcx_function_space functionspace_{name} ="]
code += ["{"]
code += [f".finite_element = {element},"]
code += [f".finite_element = {0 if element is None else element}u,"]
code += [f'.geometry_family = "{cmap_family}",']
code += [f".geometry_degree = {cmap_degree},"]
code += [f".geometry_basix_cell = {int(cmap_celltype)},"]
Expand Down
2 changes: 1 addition & 1 deletion ffcx/codegeneration/C/integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def generator(ir: IntegralIR, options):
needs_facet_permutations="true" if ir.needs_facet_permutations else "false",
scalar_type=dtype_to_c_type(options["scalar_type"]),
geom_type=dtype_to_c_type(dtype_to_scalar_dtype(options["scalar_type"])),
coordinate_element=f"{ir.coordinate_element}",
coordinate_element=f"{0 if ir.coordinate_element is None else ir.coordinate_element}u",
tabulate_tensor_float32=code["tabulate_tensor_float32"],
tabulate_tensor_float64=code["tabulate_tensor_float64"],
tabulate_tensor_complex64=code["tabulate_tensor_complex64"],
Expand Down
6 changes: 3 additions & 3 deletions ffcx/codegeneration/ufcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extern "C"
bool needs_facet_permutations;

/// Get the coordinate element associated with the geometry of the mesh.
long int coordinate_element;
uint64_t coordinate_element;
} ufcx_integral;

typedef struct ufcx_expression
Expand Down Expand Up @@ -264,7 +264,7 @@ extern "C"
///
/// @param i Argument number if 0 <= i < r Coefficient number j = i
/// - r if r + j <= i < r + n
long int* finite_elements;
uint64_t* finite_elements;

/// List of cell, interior facet and exterior facet integrals
ufcx_integral** form_integrals;
Expand All @@ -281,7 +281,7 @@ extern "C"
typedef struct ufcx_function_space
{
/// Hash of the finite element
long int finite_element;
uint64_t finite_element;

/// The family of the finite element for the geometry map
const char* geometry_family;
Expand Down
2 changes: 1 addition & 1 deletion ffcx/ir/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def compute_ir(
# Compute object names
# NOTE: This is done here for performance reasons, because repeated calls
# within each IR computation would be expensive due to UFL signature computations
finite_element_hashes = {e: hash(e) for e in analysis.unique_elements}
finite_element_hashes = {e: e.basix_hash() for e in analysis.unique_elements}
integral_names = {}
form_names = {}
for fd_index, fd in enumerate(analysis.form_data):
Expand Down