\chapter{Python utilities}
\index{Python utilities}
\index{code generation}

The UFC distribution includes a set of Python utilities for generating
code that conforms to the UFC specification. These utilities consist
of format string templates for C++ header files (\texttt{.h} files),
implementation files (\texttt{.cpp}) and combined header and
implementation files (\texttt{.h} files containing both the
declaration and definition of the UFC functions).

The following format strings are provided:

\begin{code}
function_combined_{header, implementation, combined}
finite_element_{header, implementation, combined}
dofmap_{header, implementation, combined}
cell_integral_{header, implementation, combined}
exterior_facet_integral_{header, implementation, combined}
interior_facet_integral_{header, implementation, combined}
form_{header, implementation, combined}
\end{code}

We demonstrate below how to use the format string
\texttt{form\_combined} together with a dictionary that specifies the
code to be inserted into the format string. Typically, a form compiler
will first generate the code to be inserted into the dictionary and
then in a later stage write the generated code to file in UFC format
using the provided format strings.

\begin{code}
from ufc import form_combined

code = {}
code["classname"] = "Poisson",
...
code["rank"] = "    return 2;",
code["num_coefficients"] = "    return 0;",
code["num_cell_domains"] = "    return 1;",
...

print form_combined % code
\end{code}
