kinnala / scikit-fem

Simple finite element assemblers
https://scikit-fem.readthedocs.io
BSD 3-Clause "New" or "Revised" License
495 stars 79 forks source link

Examples providing your own mesh and retriving the basis functions? #666

Closed cottrell closed 3 years ago

cottrell commented 3 years ago

Are there any examples for supplying your own mesh (for example from scipy Delaunay) and extracting basis functions of some degree?

For example you might evaluate the basis functions at a set of points for fitting against data as a kind of smoothing spline.

gdmcbain commented 3 years ago

O. K., great. This is sounding good and very interesting. Girolami et al looks like the reference I needed. Thanks very much.

I see that statFEM depends on Firedrake. That's an impressive package but it is difficult to install. It was very similar considerations that led me from there to here.

On the branch pr, I hope I'm not holding things up by not having reviewed #667 #668; if so I'll get onto that tomorrow.

kinnala commented 3 years ago

No hurry, I'll look into combining #667 and #668 at some point. #668 is missing MeshTet1.element_finder and some additional tests and fixes that I added in #667. I'll try to also evaluate which approach gives better performance.

cottrell commented 3 years ago

Another thing that I'm wondering is if the intention is to include the data term as a bilinear form (with a sum of diracs)? Seems like it would match the flow more ... trying to see if there are examples like this. It might be that probes is still the main target for this kind of flow.

One thing I'm also looking for is if there is an established way of doing probes for a derivative or integral of the basis functions. For example if you have observational data about the derivatives instead of the the actual values of the solution.

gdmcbain commented 3 years ago

include the data term as a bilinear form (with a sum of diracs)? Seems like it would match the flow more ... trying to see if there are examples like this. It might be that probes is still the main target for this kind of flow.

Close. A Dirac point source or force is a linear form (RHS, rather than LHS for the bilinear forms). It's actually given by the transpose of CellBasis.probes which is here implemented in

https://scikit-fem.readthedocs.io/en/latest/listofexamples.html#example-38-point-source

https://github.com/kinnala/scikit-fem/blob/d08af2a3f4607e28023656b1b6ad025b1a530aa1/docs/examples/ex38.py#L46

But is this exactly what's wanted in your problem? I'm not sure.

gdmcbain commented 3 years ago

One thing I'm also looking for is if there is an established way of doing probes for a derivative or integral of the basis functions. For example if you have observational data about the derivatives instead of the the actual values of the solution.

No, there isn't an established way but it's an interesting idea. If it's a functional it should be possible to express it as a matrix (ndarray) like that returned by CellBasis.probes. This matrix is really not a matrix like the discretization of a linear form, it's a stack of row vectors, one per probe-point.

For integrals there is

https://github.com/kinnala/scikit-fem/blob/d08af2a3f4607e28023656b1b6ad025b1a530aa1/skfem/assembly/form/functional.py#L10

Really a point-probe is mathematically a functional too but because its expression involves Dirac's δ it needs to be treated specially. Integrals over domains or boundaries or parts thereof are typically much better behaved and can just use Functional; I use them for things like lift coefficient, kinetic energy, &c.

cottrell commented 3 years ago

include the data term as a bilinear form (with a sum of diracs)? Seems like it would match the flow more ... trying to see if there are examples like this. It might be that probes is still the main target for this kind of flow.

Close. A Dirac point source or force is a linear form (RHS, rather than LHS for the bilinear forms). It's actually given by the transpose of CellBasis.probes which is here implemented in

https://scikit-fem.readthedocs.io/en/latest/listofexamples.html#example-38-point-source

https://github.com/kinnala/scikit-fem/blob/d08af2a3f4607e28023656b1b6ad025b1a530aa1/docs/examples/ex38.py#L46

But is this exactly what's wanted in your problem? I'm not sure.

So I am just kind of remembering (and misremembering) how all this fits together now. I was writing down the attached variational formulation and it made me realize that yes, we could think of a "dirac" basis for the point evalutions as mentioned in the docstring, but it is probably not super useful to literally implement a Form in the code against a Dirac basis. I mean, that is exactly what probes is doing but I'm not sure expressing the probes evaluation as some Form against this particular basis is ever useful for the current solver flows.

... unless of course there are examples with representations in different bases (perhaps the boudary examples) that I am not aware of yet.

image

gdmcbain commented 3 years ago

What about splitting the right-hand side? The term (δ(xs) u (x), h (x)) is a bilinear form and so could go on the left, the term (δ(xs) y (x), h (x)) is a linear form and stays on the right.

gdmcbain commented 3 years ago

Since (δ(xs) u (x), h (x)) = u (s) h (s), the ij-th element of that discretized bilinear form would be the product of the values of the i-th and j-th basis functions at the probe-point s. But I'll leave it at that till I've read Girolami et al; I'm sure they would've sorted all this out already.