This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Converting python source code to a lower-level language, namely C or Fortran

0 votes

Is there a built-in FENICS function that effectively "converts" python source code to a lower-level language such as C or Fortran (i.e. how it would be written if you were going to solve a PDE using nothing but PETSc)? I understand that it is possible (but time consuming) to go through a simple tutorial example (e.g. 2D Poisson's equation on an unstructured mesh) and compare/contrast how FENICS and PETSc by iteslf, can be used to solve it. However, I first wanted to make sure that there was not a simple/well-known way of doing this.

asked Feb 8, 2016 by Tim FEniCS Novice (190 points)

1 Answer

0 votes

There is no general way of converting Python code to C/C++/Fortran. In general
these languages are quite different and a direct translation is not possible.

You may use sympy to generate C code for simple expressions.

Cython, F2PY, SWIG etc are various kinds of tools for mixing these languages.

FEniCS generates C++ code based on a domain-specific language (UFL)
implemented in Python.

answered Feb 8, 2016 by Kent-Andre Mardal FEniCS Expert (14,380 points)
...