# FFC generates invalid C++ code

**URL:** <https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030>\
**Category:** Uncategorized\
**Created:** [February 4, 2021, 8:53am UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030 "2021-02-04T08:53:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 8:53am UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/1 "2021-02-04T08:53:09Z")

</div>

I’m somewhat new to FEniCS, but have used it for roughly half a year successfully with Python. I need to start using the C++ API but have been running into an issue. The following UFL code is compiled and then the resulting header file included. Note that simply including the header file triggers the error.

```
element = FiniteElement("Lagrange", triangle, 1)

T = Coefficient(element)
rho = Coefficient(element)
h = Coefficient(element)
eta = Coefficient(element)

dt = Coefficient(element)

v = TestFunction(element)
u = TrialFunction(element)

# Define the previous solutions which are used for the time derivative portion
z_nm1 = Coefficient(element)
z_nm2 = Coefficient(element)

p = Coefficient(element) 

a = - inner(grad(u), grad(v)) * dx
a += ((eta * h * v * ((u) / dt)) / T) * dx 
a -= ((rho / T) * (u / (dt**2)) * v) * dx

L = (- (p * v) / T) * dx
L += ((eta * h * v * ((- z_nm1) / dt)) / T) * dx 
L -= ((rho / T) * ((-2 * z_nm1 + z_nm2) / (dt**2)) * v) * dx

```

The error:

```
In file included from src/main.cpp:1:
src/Slater/SlaterModel.h:2652:8: error: ‘void slatermodel_cell_integral_0_otherwise::tabulate_tensor(double*, const double* const*, const double*, int, std::size_t) const’ marked ‘final’, but is not virtual
 2652 | void tabulate_tensor(double * A,
      | ^ ~~~~~~~~~~~~~~
In file included from src/main.cpp:1:
src/Slater/SlaterModel.h:2798:8: error: ‘void slatermodel_cell_integral_1_otherwise::tabulate_tensor(double*, const double* const*, const double*, int, std::size_t) const’ marked ‘override’, but does not override
 2798 | void tabulate_tensor(double * A,
      | ^ ~~~~~~~~~~~~~~
src/Slater/SlaterModel.h:2798:8: error: ‘void slatermodel_cell_integral_1_otherwise::tabulate_tensor(double*, const double* const*, const double*, int, std::size_t) const’ marked ‘final’, but is not virtual
src/Slater/SlaterModel.h: In member function ‘virtual ufc::cell_integral* slatermodel_form_0::create_default_cell_integral() const’:
src/Slater/SlaterModel.h:3128:54: error: invalid new-expression of abstract class type ‘slatermodel_cell_integral_0_otherwise’
 3128 | return new slatermodel_cell_integral_0_otherwise();

```

I’m compiling with g++ using the C++17 standard.

Thanks.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [February 4, 2021, 4:00pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/2 "2021-02-04T16:00:12Z")

</div>

I think this is due to the C++ standard you are using (as I cannot reproduce it in the docker container: `quay.io/fenicsproject/dev:latest`, which I am quite certain uses the C++11 standard: [Bitbucket](https://bitbucket.org/fenics-project/dolfin/src/b495043d6b3914383eb939ea6c6794442080a3a5/cmake/templates/UseDOLFIN.cmake.in?at=master#UseDOLFIN.cmake.in-16:17)

The development version of dolfin, [dolfinx](https://github.com/FEniCS/dolfinx) uses the C++ 17 standard .

---

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 8:09pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/3 "2021-02-04T20:09:22Z")

</div>

Unfortunately I tried all standards post 2000. I happen to be using anaconda to manage the installation. I link and include against the libraries provided by anaconda. Could this possibly be part of the issue? I doubt it but who knows… I might add that the examples provided by dolfin also have this same issue. I’m going to try compiling it from scratch using the link you provided to see what happens.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 4, 2021, 8:23pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/4 "2021-02-04T20:23:58Z")

</div>

would be useful to see which versions of everything your compiler is seeing. Perhaps `ufc` is being picked up from a different install somewhere? Looking at the verbose `make` or `cmake` output should help with this.

E.g. make sure it complies with what python sees.

```auto
python3 -c "import ffc, dolfin; print(f'ffc version and path: {ffc. __version__ } | {ffc. __path__ }\n DOLFIN version and path: {dolfin. __version__ } | {dolfin. __path__ }')"
>>> ffc version and path: 2019.2.0.dev0 | ['$HOME/local/lib/python3.8/site-packages/fenics_ffc-2019.2.0.dev0-py3.8.egg/ffc']
>>> DOLFIN version and path: 2019.2.0.dev0 | ['$HOME/local/lib/python3.8/site-packages/fenics_dolfin-2019.2.0.dev0-py3.8-linux-x86_64.egg/dolfin']

```

---

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 8:36pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/5 "2021-02-04T20:36:29Z")

</div>

Here are the results.

```
ffc version and path: 2019.2.0.dev0 | ['/home/user/.conda/envs/standard/lib/python3.8/site-packages/ffc']
 DOLFIN version and path: 2019.1.0 | ['/home/user/.conda/envs/standard/lib/python3.8/site-packages/dolfin']

```

I include the following:

```
/home/user/.conda/envs/standard/include
/home/user/.conda/envs/standard/include/eigen3

```

I looked at the verbose outputs and saw nothing out of the ordinary (i.e. just the usual search directories).

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 4, 2021, 8:38pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/6 "2021-02-04T20:38:11Z")

</div>

We’re particularly interested in where it’s picking up `ufc`, not Eigen. Also, your `DOLFIN` build is older than FFC.

---

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 8:46pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/7 "2021-02-04T20:46:28Z")

</div>

Yeah I saw the dolfin build being older. That is what is in the conda repositories and it works perfectly in Python.

I’ve searched for `ffc` and `ufc`, `ffc` is located at  
`/home/user/.conda/envs/standard/lib/python3.8/site-packages/ffc`

I know that `ufc` is related to the form language standard, but I thought that `ffc` was the package that actually implements the standard.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 4, 2021, 8:47pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/8 "2021-02-04T20:47:48Z")

</div>

yep. It would be useful to make sure `ufc` is being picked up by `cmake` and `make` from your `ffc` install directory.

---

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 8:53pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/9 "2021-02-04T20:53:30Z")

</div>

Its picked up here:

`~/.conda/envs/standard/lib/python3.8/site-packages/ffc/backends/ufc`

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 4, 2021, 9:03pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/10 "2021-02-04T21:03:22Z")

</div>

looks fine then. The only idea I have for checking I can come up with is the mismatch of `DOLFIN` and `ffc` versions.

---

<div class="post-metadata">

**Author:** ![Flora](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@Flora](https://fenicsproject.discourse.group/u/Flora)\
**Post date:** [February 4, 2021, 9:03pm UTC](https://fenicsproject.discourse.group/t/ffc-generates-invalid-c-code/5030/11 "2021-02-04T21:03:50Z")

</div>

I didn’t find the issue, but I found a solution. I removed the conda installation of fenics and simply re-installed. However, I needed to completely deactivate all conda environments before it took the changes. Very strange. Thanks to all that helped.
