dong
June 18, 2020, 5:04am
1
I’m finding L2 projection of a given function f on a finite element space Q.

Is there any function in Ngsolve do this job as in Fenics?

I also tried to write a find to find the L2-projection using its definition, but I met an error when finding the inverse matrix.

Could you please tell me how to fix this? Please see the attached file.
Thank you so much.

Attachment: Projection1.ipynb

You have to do it following its definition. You are building some sub-block in a huge matrix, and the solver is telling you correctly that the big matrix is not invertible

Build and invert the matrix on a single space, then you can embed the single-space vectors in your product-space,

Joachim

dong
June 18, 2020, 6:00pm
3
Thank you so much. Could you please show me how to embed a single-space vectors in a product space?
I searched a tutorial from ngsolve documentation, but I couldn’t find an example.

You can use an embedding matrix:

```
r = IntRange (a,b)
emb = Embedding(n, r)
```

This embeds a vector of length b-a into a vector of length n, starting at index a.

some use-cases you can find here:

```
from ngsolve import *
from .mt_global import *
__all__ = ["NavierStokes"]
class NavierStokes:
def __init__(self, mesh, nu, inflow, outflow, wall, uin, timestep, order=2, volumeforce=None):
self.nu = nu
self.timestep = timestep
self.uin = uin
self.inflow = inflow
self.outflow = outflow
self.wall = wall
V1 = HDiv(mesh, order=order, dirichlet=inflow+"|"+wall, RT=False)
Vhat = TangentialFacetFESpace(mesh, order=order-1, dirichlet=inflow+"|"+wall+"|"+outflow) # , hide_highest_order_dc=True)
Sigma = HCurlDiv(mesh, order = order-1, orderinner=order, discontinuous=True)
```

This file has been truncated. show original

Joachim

dong
June 25, 2020, 11:17pm
5
Thank you so much for your clarification. I think ngsolve will be more user-friendly if it has an L2-projection built-in function.