# Fenics vs FreeFem

**URL:** <https://community.freefem.org/t/fenics-vs-freefem/1300>\
**Category:** General Discussion\
**Created:** [November 4, 2021, 4:56pm UTC](https://community.freefem.org/t/fenics-vs-freefem/1300 "2021-11-04T16:56:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [November 4, 2021, 4:56pm UTC](https://community.freefem.org/t/fenics-vs-freefem/1300/1 "2021-11-04T16:56:36Z")

</div>

Hi,

I am trying to rewrite the [Fenics example](https://comet-fenics.readthedocs.io/en/latest/demo/2D_plasticity/vonMises_plasticity.py.html) to FreeFem++ and I ran into some problems when I tried to rewrite the following piece

```auto
metadata = {"quadrature_degree": deg_stress, "quadrature_scheme": "default"}
dxm = dx(metadata=metadata)

a_Newton = inner(eps(v), sigma_tang(eps(u_)))*dxm
res = -inner(eps(u_), as_3D_tensor(sig))*dxm + F_ext(u_)

```

The above is then used to later assemble the final system.

Here is my freefem attempt:

```auto
int initLoadLoop = 1;

for (int t = initLoadLoop; t <= loadSteps; t++){
    if (verbosity > 1) {
        cout << "======================" << endl;
        cout << "Load step: " << t << "/" << loadSteps << "." << endl; 
        cout << "======================" << endl;
    }
    real tension = sqrt(real(t) * 1.1 / real(loadSteps)) * pres;
    // Assemble system.
    varf elasticity(tu, v) = 
        int2d(Th)(sigma(tu)' * e(v))
        + on(1, tuy = 0)
        + on(3, tux = 0)
        ;
    varf ext(tu, v) =
        - int2d(Th)(e(tu)` * sig) 
        int1d(Th, 2)(tension * [N.x, N.y, N.z]' * v) 
        + on(1, tuy = 0)
        + on(3, tux = 0)
        ;
    real[int] fExternal = ext(0, Nh);

}

```

# Question

I assume the `a_Newton ` from fenics is the same as my `varf elasticity`. But I can’t figure out how to write the `res` from fenics, because it would require to compute `int2d(Th)(e(tu)` \* sig) ` in freefem, which is for some reason not allowed.

Is there a way I can get the `sig` variable to the `varf` function?
