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

hyperbolic Serre-Green-Naghdi equations #139

Merged
merged 29 commits into from
Aug 18, 2024
Merged

Conversation

ranocha
Copy link
Collaborator

@ranocha ranocha commented Aug 17, 2024

Next step of #129

TODO

  • Discuss name clashes and decide how to proceed
  • Format
  • Add tests and more elixirs
  • How to initialize variables? Ideally, I would like to use w = -(D1 * v) instead of having to specify a value manually in the initial condition.
  • Dingemans
  • Improve performance for flat bathymetry (and test both for the soliton setup)

Copy link

codecov bot commented Aug 17, 2024

Codecov Report

Attention: Patch coverage is 99.46524% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.75%. Comparing base (2d6a6b8) to head (849d405).
Report is 1 commits behind head on main.

Files Patch % Lines
src/equations/equations.jl 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
+ Coverage   97.57%   97.75%   +0.18%     
==========================================
  Files          20       22       +2     
  Lines        1569     1741     +172     
==========================================
+ Hits         1531     1702     +171     
- Misses         38       39       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 84 to 95
# TODO: There is another name clash. For the SerreGreenNaghdiEquations1D,
# the corresponding function is called initial_condition_convergence_test
# However, we cannot use that name since it's not an analytical solution.
# How shall we handle this?
"""
initial_condition_soliton(x, t, equations::HyperbolicSerreGreenNaghdiEquations1D, mesh)

A soliton solution of the [`SerreGreenNaghdiEquations1D`](@ref)
used for convergence tests in a periodic domain.

See also [`initial_condition_convergence_test`](@ref).
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another name clash

Copy link
Owner

Choose a reason for hiding this comment

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

Good question. I would be fine keeping it like it is now (maybe with a bit more explanations in the docstring that this function is the same as initial_condition_convergence_test for SerreGreenNaghdiEquations1D, but is not an analytical solution of HyperbolicSerreGreenNaghdiEquations1D). I think it's not too bad that these two initial conditions are not called the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, they represent the same physics, so it's a bit annoying but I don't know a better solution right now 🤷

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, it' not perfect, but I can live with in (at least for now). The name initial_condition_convergence_test doesn't describe the physics, but rather the fact of it being an analytical solution of some equations, so it's not that confusing, I think.

Copy link
Owner

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

Thanks! A preliminary review regarding your comments/questions.
I saw some non-ASCII code characters in executable code. Could you replace them by ASCII code characters, please?

How to initialize variables? Ideally, I would like to use w = -(D1 * v) instead of having to specify a value manually in the initial condition.

I also thought about that. I agree that this would be really nice. I think it would be ideal if both would be possible, i.e., defining an initial condition consisting of three variables with defaults for $w$ and $\eta$ ($H$ or whatever) or defining an initial condition consisting of all five values. I haven't thought this through, but would it somehow be possible to fiddle around with compute_coefficients by adding some dispatching on HyperbolicSerreGreenNaghdiEquations1D and some branching whether the output of initial_condition is three or five elements long?

Comment on lines 84 to 95
# TODO: There is another name clash. For the SerreGreenNaghdiEquations1D,
# the corresponding function is called initial_condition_convergence_test
# However, we cannot use that name since it's not an analytical solution.
# How shall we handle this?
"""
initial_condition_soliton(x, t, equations::HyperbolicSerreGreenNaghdiEquations1D, mesh)

A soliton solution of the [`SerreGreenNaghdiEquations1D`](@ref)
used for convergence tests in a periodic domain.

See also [`initial_condition_convergence_test`](@ref).
"""
Copy link
Owner

Choose a reason for hiding this comment

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

Good question. I would be fine keeping it like it is now (maybe with a bit more explanations in the docstring that this function is the same as initial_condition_convergence_test for SerreGreenNaghdiEquations1D, but is not an analytical solution of HyperbolicSerreGreenNaghdiEquations1D). I think it's not too bad that these two initial conditions are not called the same.

@JoshuaLampert JoshuaLampert added the enhancement New feature or request label Aug 17, 2024
@ranocha
Copy link
Collaborator Author

ranocha commented Aug 18, 2024

I saw some non-ASCII code characters in executable code. Could you replace them by ASCII code characters, please?

I used them on purpose to make it easier to search and replace stuff after deciding how to call the new variables

@ranocha
Copy link
Collaborator Author

ranocha commented Aug 18, 2024

julia> convergence_test("examples/hyperbolic_serre_green_naghdi_1d/hyperbolic_serre_green_naghdi_manufactured.jl", 4);
[...]
####################################################################################################
l2
η                        v                        D                        w                        H                        
N    error     EOC       N    error     EOC       N    error     EOC       N    error     EOC       N    error     EOC       
50   5.65e-02  -         50   3.46e-02  -         50   0.00e+00  -         50   1.17e+00  -         50   5.85e-02  -         
100  3.61e-03  3.97      100  2.25e-03  3.94      100  0.00e+00  NaN       100  7.51e-02  3.96      100  3.73e-03  3.97      
200  2.26e-04  4.00      200  1.42e-04  3.99      200  0.00e+00  NaN       200  4.71e-03  3.99      200  2.34e-04  4.00      
400  1.42e-05  4.00      400  1.02e-05  3.79      400  0.00e+00  NaN       400  2.95e-04  4.00      400  1.46e-05  4.00      

mean           3.99      mean           3.91      mean           NaN       mean           3.99      mean           3.99      
----------------------------------------------------------------------------------------------------
linf
η                        v                        D                        w                        H                        
N    error     EOC       N    error     EOC       N    error     EOC       N    error     EOC       N    error     EOC       
50   1.21e-01  -         50   5.21e-02  -         50   0.00e+00  -         50   2.19e+00  -         50   1.27e-01  -         
100  7.81e-03  3.95      100  3.36e-03  3.95      100  0.00e+00  NaN       100  1.41e-01  3.96      100  8.59e-03  3.88      
200  4.91e-04  3.99      200  2.16e-04  3.96      200  0.00e+00  NaN       200  8.83e-03  3.99      200  5.38e-04  4.00      
400  3.15e-05  3.96      400  2.33e-05  3.21      400  0.00e+00  NaN       400  5.51e-04  4.00      400  3.37e-05  4.00      

mean           3.97      mean           3.71      mean           NaN       mean           3.98      mean           3.96      
----------------------------------------------------------------------------------------------------

@ranocha
Copy link
Collaborator Author

ranocha commented Aug 18, 2024

Including some optimizations for flat bathymetry:

julia> q = copy(ode.u0); dq = similar(q); @benchmark $(ode.f)($dq, $q, $(ode.p), $0.0)
BenchmarkTools.Trial: 10000 samples with 4 evaluations.
 Range (min  max):  7.864 μs   13.969 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     7.927 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   8.165 μs ± 647.504 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █▇▆▂▂▃▃           ▂▁▂▁▂                     ▁               ▂
  █████████▅▅▄▅▁▄▃█████████▇▆▅▅▆▃▆▆▆▇██▇▇▇▇▆▇▇███▇▅▅▄▆▆▅▅▃▅▆▆ █
  7.86 μs      Histogram: log(frequency) by time        11 μs <

 Memory estimate: 304 bytes, allocs estimate: 5.

julia> redirect_stdio(stdout = devnull, stderr = devnull) do
           trixi_include("examples/hyperbolic_serre_green_naghdi_1d/hyperbolic_serre_green_naghdi_soliton.jl", interval = 1000, bathymetry_type = bathymetry_mild_slope);
       end;

julia> q = copy(ode.u0); dq = similar(q); @benchmark $(ode.f)($dq, $q, $(ode.p), $0.0)
BenchmarkTools.Trial: 10000 samples with 3 evaluations.
 Range (min  max):  8.597 μs   17.208 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     8.917 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   9.159 μs ± 774.910 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▇▇▂ █▇▇▇▂               ▁▁▁▁▁▁ ▁            ▁               ▂
  ███▆██████▇███▇▇█▇█▇██████████████▇█▇▇▇▆██▇███▇▇▇▆▆▆▅▆▅▆▅▅▅ █
  8.6 μs       Histogram: log(frequency) by time      12.2 μs <

 Memory estimate: 16 bytes, allocs estimate: 2.

@ranocha ranocha requested a review from JoshuaLampert August 18, 2024 07:30
@ranocha ranocha marked this pull request as ready for review August 18, 2024 07:30
Copy link
Owner

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

This looks already really nice! I think we are not far from merging this. I especially like your trait system to allow all or only a reduced set of variables in the initial condition. I knew you would come up with a very nice idea for implementing that what was very fuzzy in my head 🙂

@JoshuaLampert
Copy link
Owner

The convergence test and benchmark look nice. Thanks!

@ranocha ranocha requested a review from JoshuaLampert August 18, 2024 08:31
Copy link
Owner

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

Looks mostly good! I have only some minor comments/suggestions/questions.

@ranocha ranocha requested a review from JoshuaLampert August 18, 2024 13:59
Copy link
Owner

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

Thanks a lot! Once my final two suggestions are resolved, this is ready to merge.

@ranocha ranocha requested a review from JoshuaLampert August 18, 2024 16:32
Copy link
Owner

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

Thanks!

@JoshuaLampert JoshuaLampert enabled auto-merge (squash) August 18, 2024 16:33
@JoshuaLampert JoshuaLampert disabled auto-merge August 18, 2024 16:47
@JoshuaLampert JoshuaLampert enabled auto-merge (squash) August 18, 2024 16:53
@JoshuaLampert JoshuaLampert merged commit 1d90e33 into main Aug 18, 2024
12 checks passed
@JoshuaLampert JoshuaLampert deleted the hr/serre_green_naghdi branch August 18, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants