Skip to content
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

First step towards FD methods and surface integrals/terms #617

Merged
merged 26 commits into from
Jun 11, 2021

Conversation

ranocha
Copy link
Member

@ranocha ranocha commented May 27, 2021

This PR basically collects two parts.

Part 1: Surface integrals/terms for additional dispatch (basically finished)

Summary: I introduced a surface integral/term type which is passed to every surface computation, mimicking the approach we have for our volume integrals/terms.

This could be considered to be breaking since it changes a documented constructor of our DG type. On the other hand, the documentation of this constructor was just wrong (since it contained the basis twice but not the mortar). Hence, this is more like a bug fix, I think ;).

Currently, the SurfaceintegralWeakForm is used everywhere; the SurfaceIntegralStrongForm will be used for FD methods later. This will also be useful to get more general methods of @jlchan. When we merge this, we need to remember to notify others.

Part 2: First step towards FD methods in Trixi (finished)

This is a rough draft adapting the 2D TreeMesh DG solver. TODO:

This could be considered to be breaking since it changes a documented constructor of our `DG` type. On the other hand, the documentation of this constructor was just wrong (since it contained the basis twice but not the mortar). Hence, this is more like a bug fix, I think ;).
@ranocha ranocha requested a review from sloede May 27, 2021 13:16
@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #617 (7ce35f1) into main (f2972d9) will decrease coverage by 0.04%.
The diff coverage is 90.08%.

❗ Current head 7ce35f1 differs from pull request most recent head 0c5b8cd. Consider uploading reports for the commit 0c5b8cd to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #617      +/-   ##
==========================================
- Coverage   93.36%   93.32%   -0.05%     
==========================================
  Files         155      156       +1     
  Lines       15353    15467     +114     
==========================================
+ Hits        14334    14434     +100     
- Misses       1019     1033      +14     
Flag Coverage Δ
unittests 93.32% <90.08%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Trixi.jl 83.33% <ø> (ø)
src/auxiliary/precompile.jl 0.00% <0.00%> (ø)
src/callbacks_step/analysis_dg2d.jl 96.63% <ø> (ø)
src/solvers/dg_common.jl 91.42% <33.33%> (-2.52%) ⬇️
src/solvers/dg_tree/basis_lobatto_legendre.jl 88.50% <70.00%> (-0.71%) ⬇️
src/solvers/dg_tree/dg.jl 87.96% <86.66%> (-1.22%) ⬇️
src/solvers/dg_tree/dg_2d.jl 96.84% <91.66%> (ø)
src/solvers/dg_tree/dg_3d.jl 97.50% <93.75%> (ø)
src/solvers/dg_tree/containers_2d.jl 96.22% <93.84%> (-0.60%) ⬇️
src/solvers/dg_tree/containers_1d.jl 97.72% <94.73%> (-0.03%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2972d9...0c5b8cd. Read the comment docs.

Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an initial, coarse review, since I have a few general questions. More (and more thorough) reviews not before my talk on Monday, I'm afraid :-/

src/solvers/dg_curved/dg_2d.jl Outdated Show resolved Hide resolved
Comment on lines 336 to 339
DGSEM(; RealT=Float64, polydeg::Integer,
surface_flux=flux_central,
volume_integral::AbstractVolumeIntegral=VolumeIntegralWeakForm(),
mortar=MortarL2(basis))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is redundant with the lines above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldnt it be

Suggested change
DGSEM(; RealT=Float64, polydeg::Integer,
surface_flux=flux_central,
volume_integral::AbstractVolumeIntegral=VolumeIntegralWeakForm(),
mortar=MortarL2(basis))
DGSEM(; RealT=Float64, polydeg::Integer,
surface_integral=SurfaceIntegralWeakForm(),
volume_integral::AbstractVolumeIntegral=VolumeIntegralWeakForm(),
mortar=MortarL2(basis))

for consistency? Also, why the dispatch on AbstractVolumeIntegral?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the restriction to AbstractVolumeIntegral and the other docstring in 05801bf.
DGSEM uses the SurfaceIntegralWeakForm by definition. We could allow more general surface terms, but we don't have a good reason to do so right now. We need to keep the keyword argument surface_flux for backward compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the weak/strong argument, an additional reason I see for the abstraction with the SurfaceIntegral type is to pave the way for alternative surface terms such as SAT (simultaneous approximation terms) that sometimes do not follow our "numerical flux" structure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's something I had in mind, too.

src/solvers/dg_tree/dg.jl Outdated Show resolved Hide resolved
src/solvers/dg_tree/dg.jl Outdated Show resolved Hide resolved
src/solvers/dg_tree/dg.jl Show resolved Hide resolved
src/solvers/dg_curved/dg_2d.jl Show resolved Hide resolved
@ranocha ranocha changed the title introduce surface integrals WIP: FD methods and surface integrals/terms May 28, 2021
@ranocha ranocha marked this pull request as draft May 28, 2021 05:48
@ranocha
Copy link
Member Author

ranocha commented May 31, 2021

Initial draft of SBP FD methods which needs modifications of SummatioByPartsOperators.jl that I will push later to upstream. Convergence test for linear advection:

julia> using Trixi

julia> convergence_test("examples/tree_2d_fd/elixir_advection_extended.jl", 5, initial_refinement_level=0, abstol=1.0e-10, reltol=1.0e-10, N=32)
[...]
####################################################################################################
l2
scalar              
error     EOC       
7.68e-05  -         
1.33e-05  2.53      
1.84e-06  2.86      
2.29e-07  3.00      
2.86e-08  3.00      

mean      2.85      
----------------------------------------------------------------------------------------------------
linf
scalar              
error     EOC       
2.71e-04  -         
3.59e-05  2.92      
5.22e-06  2.78      
6.51e-07  3.00      
8.67e-08  2.91      

mean      2.90      
----------------------------------------------------------------------------------------------------
Dict{Symbol, Any} with 3 entries:
  :variables => ("scalar",)
  :l2        => [2.84821]
  :linf      => [2.90261]

@ranocha
Copy link
Member Author

ranocha commented May 31, 2021

@sloede @andrewwinters5000 @gregorgassner: I implemented a first draft of FD methods. I would like to get feedback before polishing this since I have no motivation to work on this if it will be rejected anyway since people have some strong opinions on coding/naming conventions (cf. #616).

@ranocha ranocha requested a review from sloede May 31, 2021 06:32
@gregorgassner
Copy link
Contributor

This looks very nice to me. I also looked through the changed files, looks all good to me so far.
Couple of questions:

(i) Did you test the multi-element? Is your EOC test done by increasing the SBP nodes inside the element, or by increasing the number of elements?

(ii) General question: Would it make sense to have Strong Form (Volume, Surface) also for the DGSEM operator?

(iii) The current volume integral implementation is with mul!() as far as I can tell. It seems to me, that this uses the full (non-sparse) D matrix to do the multiplication. I assume, it will be relative straight forward in future, to specify the volume integral further with the specific optimized implementations for a given SBP D matrix?

@ranocha
Copy link
Member Author

ranocha commented Jun 1, 2021

Thanks for the encouraging feedback 👍

(i) Did you test the multi-element? Is your EOC test done by increasing the SBP nodes inside the element, or by increasing the number of elements?

I tested multiple elements connected via strong form surface terms/integral. The convergence test increases the number of elements since our convergence_test is constructed having only DGSEM in mind (added to the TODO list, maybe for a future PR).

(ii) General question: Would it make sense to have Strong Form (Volume, Surface) also for the DGSEM operator?

It's definitely an option. However, we don't have a use case for it right now and the weak form should be more efficient. Thus, I don't object implementing it for DGSEM but I think we shouldn't do it unless we have a use case.

(iii) The current volume integral implementation is with mul!() as far as I can tell. It seems to me, that this uses the full (non-sparse) D matrix to do the multiplication. I assume, it will be relative straight forward in future, to specify the volume integral further with the specific optimized implementations for a given SBP D matrix?

I have specialized mul! in SummationByPartsOperators.jl. Thus, it's a reasonably efficient version of in-place multiplication, taking the sparsity structure into account. Some benchmarks (running on GitHub actions) are available at https://ranocha.de/SummationByPartsOperators.jl/stable/benchmarks/.
Nevertheless, this version of the strong form volume terms/integral is only a first draft. To optimize it further, we should compare different versions, including a more intrusive approach (basically fusing the loops). But that's not necessary right now and left for future PRs (since honest optimization will take some time).

Some numbers: Using julia --threads=1 --check-bounds=no:

  • trixi_include("examples/2d/elixir_advection_extended.jl", polydeg=2, n_cells_max=10^6, initial_refinement_level=8, tspan=(0.0, 1.0)) with 589_824 DOF has a PID of ca. 7.7e-9. The L² error is 9.0e-08.
  • trixi_include("examples/tree_2d_fd/elixir_advection_extended.jl", initial_refinement_level=3, N=96, abstol=1.0e-8, reltol=1.0e-8, tspan=(0.0, 1.0), advectionvelocity=(1.0, 1.0)) with 589_824 DOF has a PID of ca. 9.3e-9. The L² error is 6.8e-08.

That's not too bad for an un-optimized implementation of the FD methods, I think.

@gregorgassner
Copy link
Contributor

I have specialized mul! in SummationByPartsOperators.jl. Thus, it's a reasonably efficient version of in-place multiplication, taking the sparsity structure into account. Some benchmarks (running on GitHub actions) are available at https://ranocha.de/SummationByPartsOperators.jl/stable/benchmarks/.

Oh, wow!

Copy link
Member

@andrewwinters5000 andrewwinters5000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is very impressive and I like the structure. It reuses the architecture from DG when it can and leaves flexibility to expand, e.g., to other SAT techniques

src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, very impressive that yet another Julia packages ties in so nicely with the Trixi structure and we get another world of solvers with just a few lines :-)

src/equations/equations.jl Show resolved Hide resolved
src/solvers/dg_tree/basis_lobatto_legendre.jl Outdated Show resolved Hide resolved
src/solvers/solvers.jl Outdated Show resolved Hide resolved
src/solvers/dg_tree/dg.jl Outdated Show resolved Hide resolved
src/solvers/dg_tree/containers_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
src/solvers/fd_tree/fd_2d.jl Outdated Show resolved Hide resolved
@sloede
Copy link
Member

sloede commented Jun 3, 2021

If you promise to finish the rest as well, I'd suggest to consider merging this with the current feature set and doing restructuring/cleanup/renaming in a separate PR

@ranocha ranocha mentioned this pull request Jun 3, 2021
18 tasks
@ranocha
Copy link
Member Author

ranocha commented Jun 4, 2021

This PR should be in a good shape and more or less ready to merge after another round of reviews. Other features and extensions can be added in new PRs later.

@ranocha
Copy link
Member Author

ranocha commented Jun 5, 2021

Tests only fail because of the following warnings on Windows:

WARNING: importing deprecated binding Colors.RGB1 into PlotUtils.
WARNING: importing deprecated binding Colors.RGB4 into PlotUtils.

How shall we handle that?

  • Add it to the list of exceptions for our tests?
  • Load the package outside of the test command checking for warnings?
  • Something else?

Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. Just two questions remaining...

src/Trixi.jl Show resolved Hide resolved
src/solvers/dg_tree/dg.jl Show resolved Hide resolved
sloede
sloede previously approved these changes Jun 10, 2021
@ranocha ranocha enabled auto-merge (squash) June 11, 2021 05:38
@ranocha ranocha disabled auto-merge June 11, 2021 05:38
@ranocha ranocha requested a review from sloede June 11, 2021 07:09
test/test_trixi.jl Outdated Show resolved Hide resolved
Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM now!

@ranocha
Copy link
Member Author

ranocha commented Jun 11, 2021

I'll merge this since the failure on windows-mpi is spurious and not related to this PR.

@ranocha ranocha merged commit e0c973d into trixi-framework:main Jun 11, 2021
@ranocha ranocha deleted the hr/FD branch June 11, 2021 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants