Skip to content

Commit

Permalink
Remove unused functions and convert list of strings to static data (#637
Browse files Browse the repository at this point in the history
)

* Remove unused and simplify ufcx.h
  • Loading branch information
chrisrichardson committed Nov 11, 2023
1 parent 66a53ac commit ce42287
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 46 deletions.
31 changes: 15 additions & 16 deletions ffcx/codegeneration/C/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,23 @@ def generator(ir, options):
d["original_coefficient_position_init"] = ""
d["original_coefficient_position"] = "NULL"

cnames = ir.coefficient_names
assert ir.num_coefficients == len(cnames)
if len(cnames) == 0:
code = ["return NULL;"]
if len(ir.coefficient_names) > 0:
values = ", ".join(f'"{name}"' for name in ir.coefficient_names)
sizes = len(ir.coefficient_names)
d["coefficient_names_init"] = f"static const char* coefficient_names_{ir.name}[{sizes}] = {{{values}}};"
d["coefficient_names"] = f"coefficient_names_{ir.name}"
else:
values = ", ".join(f'"{name}"' for name in cnames)
code = [f"static const char* names[{len(cnames)}] = {{{values}}};",
"return names;"]
d["coefficient_name_map"] = "\n".join(code)

cstnames = ir.constant_names
if len(cstnames) == 0:
code = ["return NULL;"]
d["coefficient_names_init"] = ""
d["coefficient_names"] = "NULL"

if len(ir.constant_names) > 0:
values = ", ".join(f'"{name}"' for name in ir.constant_names)
sizes = len(ir.constant_names)
d["constant_names_init"] = f"static const char* constant_names_{ir.name}[{sizes}] = {{{values}}};"
d["constant_names"] = f"constant_names_{ir.name}"
else:
values = ", ".join(f'"{name}"' for name in cstnames)
code = [f"static const char* names[{len(cstnames)}] = {{{values}}};",
"return names;"]
d["constant_name_map"] = "\n".join(code)
d["constant_names_init"] = ""
d["constant_names"] = "NULL"

if len(ir.finite_elements) > 0:
d["finite_elements"] = f"finite_elements_{ir.name}"
Expand Down
17 changes: 4 additions & 13 deletions ffcx/codegeneration/C/form_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,8 @@
{form_integrals_init}
{form_integral_ids_init}
// Return a list of the coefficient names.
const char** coefficient_name_{factory_name}(void)
{{
{coefficient_name_map}
}}
// Return a list of the constant names.
const char** constant_name_{factory_name}(void)
{{
{constant_name_map}
}}
{coefficient_names_init}
{constant_names_init}
ufcx_form {factory_name} =
{{
Expand All @@ -49,8 +40,8 @@
.num_constants = {num_constants},
.original_coefficient_position = {original_coefficient_position},
.coefficient_name_map = coefficient_name_{factory_name},
.constant_name_map = constant_name_{factory_name},
.coefficient_name_map = {coefficient_names},
.constant_name_map = {constant_names},
.finite_elements = {finite_elements},
.dofmaps = {dofmaps},
Expand Down
21 changes: 4 additions & 17 deletions ffcx/codegeneration/ufcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ extern "C"

typedef struct ufcx_dofmap
{

/// String identifying the dofmap
const char* signature;

Expand All @@ -231,18 +230,6 @@ extern "C"
/// Offset for closure dofs of each entity in entity_closure_dofs
int *entity_closure_dof_offsets;

/// Number of dofs associated with each cell entity of dimension d
int *num_entity_dofs;

/// Tabulate the local-to-local mapping of dofs on entity (d, i)
void (*tabulate_entity_dofs)(int* restrict dofs, int d, int i);

/// Number of dofs associated with the closure of each cell entity of dimension d
int *num_entity_closure_dofs;

/// Tabulate the local-to-local mapping of dofs on the closure of entity (d, i)
void (*tabulate_entity_closure_dofs)(int* restrict dofs, int d, int i);

/// Number of sub dofmaps (for a mixed element)
int num_sub_dofmaps;

Expand Down Expand Up @@ -433,11 +420,11 @@ extern "C"
/// Original coefficient position for each coefficient
int* original_coefficient_position;

/// Return list of names of coefficients
const char** (*coefficient_name_map)(void);
/// List of names of coefficients
const char** coefficient_name_map;

/// Return list of names of constants
const char** (*constant_name_map)(void);
/// List of names of constants
const char** constant_name_map;

/// Get a finite element for the i-th argument function, where 0 <=
/// i < r + n.
Expand Down

0 comments on commit ce42287

Please sign in to comment.