# Project function

**URL:** <https://fenicsproject.discourse.group/t/project-function/2514>\
**Category:** Uncategorized\
**Created:** [February 24, 2020, 8:24pm UTC](https://fenicsproject.discourse.group/t/project-function/2514 "2020-02-24T20:24:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![superxi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/superxi/32/2206_2.png) [@superxi](https://fenicsproject.discourse.group/u/superxi)\
**Post date:** [February 24, 2020, 8:24pm UTC](https://fenicsproject.discourse.group/t/project-function/2514/1 "2020-02-24T20:24:01Z")

</div>

Hello all,

I want to confirm a quick question, in FEniCS, the project function is project the original function to the finite element space using the degree of freedom of that finite element space right?

Thanks

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [February 24, 2020, 10:31pm UTC](https://fenicsproject.discourse.group/t/project-function/2514/2 "2020-02-24T22:31:41Z")

</div>

Yes. In particular, it is L^2 projection onto the finite element space. See the following code example:

```python
from dolfin import *

# L^2 projection onto the space V:
def my_project(u,V):
    ut = TrialFunction(V)
    v = TestFunction(V)
    uh = Function(V)
    solve(inner(ut,v)*dx==inner(u,v)*dx,uh)
    return uh

# Compare with project function:
N = 10
mesh = UnitSquareMesh(N,N)
V = FunctionSpace(mesh,"CG",1)
x = SpatialCoordinate(mesh)
u = sin(x[0]*pi)*sin(2*x[1]*pi)
print(assemble(abs(my_project(u,V)
                   - project(u,V))*dx))

```

---

<div class="post-metadata">

**Author:** ![superxi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/superxi/32/2206_2.png) [@superxi](https://fenicsproject.discourse.group/u/superxi)\
**Post date:** [February 24, 2020, 10:46pm UTC](https://fenicsproject.discourse.group/t/project-function/2514/3 "2020-02-24T22:46:35Z")

</div>

Thank you, kamensky! But for example if you are using BDM or RT element, I guess the projection is not L^{2} projection right? It should make use of the degree of freedom of BDM or RT right?

Thanks

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [February 24, 2020, 11:55pm UTC](https://fenicsproject.discourse.group/t/project-function/2514/4 "2020-02-24T23:55:13Z")

</div>

L^2 projection still makes sense for RT/BDM elements, as the corresponding spaces are subsets of L^2. You can verify this by modifying the last part of my example above:

```python
V = FunctionSpace(mesh,"RT",1)
x = SpatialCoordinate(mesh)
u = as_vector(2*(sin(x[0]*pi)*sin(2*x[1]*pi),))
e = my_project(u,V) - project(u,V)
print(assemble(dot(e,e)*dx))

```

---

<div class="post-metadata">

**Author:** ![superxi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/superxi/32/2206_2.png) [@superxi](https://fenicsproject.discourse.group/u/superxi)\
**Post date:** [February 26, 2020, 12:20am UTC](https://fenicsproject.discourse.group/t/project-function/2514/5 "2020-02-26T00:20:30Z")

</div>

Hello Kamensky, thank you very much for the explanation in detail! For RT/BDM elements, are you aware of any projection using the degree of freedom of RT/BDM instead of the L^{2} projection?

Thanks

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [February 26, 2020, 12:37am UTC](https://fenicsproject.discourse.group/t/project-function/2514/6 "2020-02-26T00:37:20Z")

</div>

I’m not sure I understand what you’re asking. The result of L^2 projection \Pi^h: L^2\to V^h onto some finite-dimensional space V^h\subset L^2 (be it a CG space, an RT space, or some other subspace of L^2) will return a function in V^h, which will be defined by some vector of degrees of freedom for V^h. In that sense it is “using the degrees of freedom” of V^h, regardless of what type of space V^h is.

---

<div class="post-metadata">

**Author:** ![superxi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/superxi/32/2206_2.png) [@superxi](https://fenicsproject.discourse.group/u/superxi)\
**Post date:** [February 29, 2020, 10:58pm UTC](https://fenicsproject.discourse.group/t/project-function/2514/7 "2020-02-29T22:58:26Z")

</div>

Hello kamensky, thank you so much for all of your kind help and sorry for my late reply, what I am asking is actually that, you know for RT/BDM elements, they have their own degree of freedom, so if you have a H^{1} function, the degree of freedom from RT/BDM could be used to determine uniquely a function say in V\_{h}. Yeah, I agree the L^{2} projection still makes sense in the RT/BDM spaces, but what I wonder is how to use the degree of freedom say of BDM/RT themselves to do the projection.
