-
Notifications
You must be signed in to change notification settings - Fork 21
Add Dirichlet Boundary Projectors #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
|
Good job @jowezarek! I will look into the details shortly. @FrederikSchnack: How much work do you think is needed to extend this PR to multi-patch domains? |
|
Good catch! The conforming projectors are not very well tested on single-patch domains. Since the single-patch geometry behaves fundamentally different than in the multi-patch setting, at least when it comes to boundaries, we did not check if the periodicity is enforced by the FEM spaces. There is a very easy fix to this, should I push it to this pull-request? |
|
I think the extension to multi-patch should not be too difficult, the question is if/ for what this is needed? As I see it, this PR is mainly used for the 3D cases, where we don't have conforming projections (w/ BC) at hand. Everything else in 2D can be done by conforming projections and other multi-patch examples like a Nitsche method enforce the BC weakly. |
FrederikSchnack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main remark is to integrate the DBP a little better into the feec-api, otherwise the additions look good to me.
|
@FrederikSchnack On the topic of API consistency between the Dirichlet boundary projectors and the conforming projectors... I have just noticed that the boolean parameter
If this is an important parameter, I think it should be included in the docstrings. Or maybe it could be skipped altogether given that the parameter |
yguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
I have a few comments, mostly on the unit tests.
Further, I would like to see some tests run in parallel, could this be done?
Good catch! The parameter Together with your other comments on the conforming projections, should we do the changes here or as a separate PR? |
This should be a small change, so we could include it here directly |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
yguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! I have some other remarks
yguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing (most of) my comments! I have a few more 😄
…atch to MultipatchDiscreteDeRham
|
Good job for addressing my comments! The one (important) thing which is still missing is parallel tests. I asked this in a previous review last week 😉 |
Out of the three new tests @pytest.mark.parametrize('dim', [1, 2, 3])
def test_function_space_boundary_projector(dim)
@pytest.mark.parametrize('dim', [1, 2, 3])
def test_discrete_derham_boundary_projector_parallel(dim)
def test_discrete_derham_boundary_projector_multipatch()the first two are rather slow (in particular the 3D parts). @pytest.mark.parametrize('dim', [1, 2])
def test_function_space_boundary_projector(dim)
@pytest.mark.parametrize('dim', [1, 3])
@pytest.mark.parallel
def test_discrete_derham_boundary_projector_parallel(dim) # here now passing comm=MPI.COMM_WORLD instead of None
def test_discrete_derham_boundary_projector_multipatch()This way, we still test all dimensions, the tests run faster, and we have a parallel test. What do you think @yguclu ? |
yguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are my last comments!
yguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Good job!
We implement the class `DirichletProjector` and
`MultipatchDirichletProjector` and include tests.
DirichletProjector
---------------------------
is a subclass of `LinearOperator`. Projects coefficients of functions
belonging to a `fem_space` of `space_kind` $\in$ `{"h1", "hcurl",
"hdiv", "l2"}` to coefficients of functions satisfying the corresponding
homogeneous Dirichlet boundary conditions. These projectors **respect
periodicity**, i.e., coefficients corresponding to "periodic boundaries"
**will not be changed**.
Take for example the constant function $f(x, y) = 1$ on an Annulus.
```python
P0, _, _ = derham_h.projectors()
f = lambda x, y : 1
F = P0(f)
plot_field_2d(fem_field=F, domain=domain, N_vis=100, cmap='plasma')
```
See [image](https://github.com/user-attachments/assets/83dc42c6-5ecc-46ae-a0a0-6ceae85526fe).
Applying the `DirichletProjector` sets correctly only the DOFs to 0 that
belong to basis functions that are different from 0 on the
"x1-direction-boundary".
```python
DP0, _ = derham_h.dirichlet_projectors(kind='linop')
F_dp = FemField(derham_h.V0, DP0 @ F.coeffs)
plot_field_2d(fem_field=F_dp, domain=domain, N_vis=100, cmap='plasma')
```
See [image](https://github.com/user-attachments/assets/a117c5c6-8379-4bcf-b8a8-71e59d2d0eeb).
Usage
---------
Obtain these projectors in the **FEEC context** directly from a
`DiscreteDeRham` object
```python
DP0, DP1 = derham_h.dirichlet_projectors(kind='linop') # in 1D
DP0, DP1, DP2 = derham_h.dirichlet_projectors(kind='linop') # in 2D
DP0, DP1, DP2, DP3 = derham_h.dirichlet_projectors(kind='linop') # in 3D
```
The last projector is simply an `IdentityOperator`.
When instead working with **FEM** objects only:
```python
from psydac.fem.projectors import DirichletProjector
# working with a space that has a kind
V = ScalarFunctionSpace('V', domain, kind='h1')
Vh = discretize(V, domain_h, degree=degree)
DP = DirichletProjector(Vh)
# working with a space that has no kind
V = VectorFunctionSpace('V', domain)
Vh = discretize(V, domain_h, degree=degree)
DP = DirichletProjector(Vh, kind='hcurl') # or 'hdiv'
```
Similarity with `conforming_projectors`
--------------------------------------------------------
Identical to `derham_h.conforming_projectors(kind='linop', hom_bc=True)`
**on a single-patch**.
On **multi-patch** domains, `derham_h.conforming_projectors` also affect
the solution at the **interfaces** between patches, as required by the
broken-FEEC theory. If required, they have the additional ability to
preserve moments of the solution.
Unfortunately, the conforming projectors are only implemented in 2D.
---------
Co-authored-by: Frederik Schnack <frederik.schnack@ipp.mpg.de>
We implement the class
DirichletProjectorandMultipatchDirichletProjectorand include tests.DirichletProjector
is a subclass of$\in$
LinearOperator. Projects coefficients of functions belonging to afem_spaceofspace_kind{"h1", "hcurl", "hdiv", "l2"}to coefficients of functions satisfying the corresponding homogeneous Dirichlet boundary conditions. These projectors respect periodicity, i.e., coefficients corresponding to "periodic boundaries" will not be changed.Take for example the constant function$f(x, y) = 1$ on an Annulus.
Applying the
DirichletProjectorsets correctly only the DOFs to 0 that belong to basis functions that are different from 0 on the "x1-direction-boundary".Note: Low resolution!
ncells = [3, 3]; degree = [1, 1]Usage
Obtain these projectors in the FEEC context directly from a
DiscreteDeRhamobjectThe last projector is simply an
IdentityOperator.When instead working with FEM objects only:
Similarity with
conforming_projectorsIdentical to
derham_h.conforming_projectors(kind='linop', hom_bc=True)on a single-patch.On multi-patch domains,
derham_h.conforming_projectorsalso affect the solution at the interfaces between patches, as required by the broken-FEEC theory. If required, they have the additional ability to preserve moments of the solution.Unfortunately, the conforming projectors are only implemented in 2D.