-
Notifications
You must be signed in to change notification settings - Fork 109
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
WIP: modify calc_node_coordinates!
to allow for P4estMesh{2}
with 3D coordinates
#2046
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
calc_node_coordinates!
to allow for P4estMesh{2} with 3D coordinatescalc_node_coordinates!
to allow for P4estMesh{2}
with 3D coordinates
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2046 +/- ##
=======================================
Coverage 96.30% 96.30%
=======================================
Files 466 466
Lines 37227 37227
=======================================
Hits 35850 35850
Misses 1377 1377
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
StaticInt(2), static_length(nodes), static_length(mesh.nodes)) | ||
StaticInt(size(mesh.tree_node_coordinates, 1)), | ||
static_length(nodes), static_length(mesh.nodes)) |
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.
Did you check the performance and type stability of this?
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.
I hadn't thought about the fact that this would get called repeatedly when using mesh adaptation, so I initially wasn't too concerned about performance. I've now done some tests with a 2D mesh.
julia> using Trixi, BenchmarkTools
julia> using StaticArrayInterface: static_length
julia> using StrideArrays: StrideArray, StaticInt
julia> solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs);
julia> mesh = P4estMesh((8, 8), polydeg = 3,
coordinates_min = (-1.0, -1.0), coordinates_max = (1.0, 1.0),
initial_refinement_level = 1);
Existing code:
julia> @benchmark StrideArray(undef, real(mesh),
StaticInt(2),
static_length(solver.basis.nodes), static_length(mesh.nodes))
BenchmarkTools.Trial: 10000 samples with 195 evaluations.
Range (min … max): 489.103 ns … 539.166 μs ┊ GC (min … max): 0.00% … 99.88%
Time (median): 505.769 ns ┊ GC (median): 0.00%
Time (mean ± σ): 583.345 ns ± 5.396 μs ┊ GC (mean ± σ): 11.83% ± 4.49%
▃██▂
▁▁▁▂▃▆████▅▂▂▂▂▂▂▁▁▁▂▂▃▃▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
489 ns Histogram: frequency by time 607 ns <
Memory estimate: 880 bytes, allocs estimate: 6.
New code:
julia> @benchmark StrideArray(undef, real(mesh),
StaticInt(size(mesh.tree_node_coordinates, 1)),
static_length(solver.basis.nodes), static_length(mesh.nodes))
BenchmarkTools.Trial: 10000 samples with 142 evaluations.
Range (min … max): 701.296 ns … 750.380 μs ┊ GC (min … max): 0.00% … 99.87%
Time (median): 717.725 ns ┊ GC (median): 0.00%
Time (mean ± σ): 819.442 ns ± 7.505 μs ┊ GC (mean ± σ): 10.81% ± 3.66%
▂▅▇█▇▆▅▂▁▁▂▃▂▃▃▄▄▄▃▃▃▂▂▂▂▂▁▁▁ ▁ ▂
▆███████████████████████████████████▇▇▇▆▆▆▆▆▆▆▄▅▅▅▄▅▃▆▆▆▅▅▆▄▃ █
701 ns Histogram: log(frequency) by time 851 ns <
Memory estimate: 880 bytes, allocs estimate: 6.
As we can see, here is some additional cost, but it seems to be a fixed overhead that doesn't depend on the mesh size, so I'm not sure if it's a significant regression in performance or not. I don't see any type instabilities from @code_warntype
.
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.
Can you please also report benchmarks of a full call to calc_node_coordinates!
?
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.
Ok, actually there seems to be a type instability when I call the full calc_node_coordinates!
, and the performance is worse. See below.
julia> using Trixi, BenchmarkTools
julia> using StaticArrayInterface: static_length
julia> using StrideArrays: StrideArray, StaticInt
julia> solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs);
julia> mesh = P4estMesh((8, 8), polydeg = 3,
coordinates_min = (-1.0, -1.0), coordinates_max = (1.0, 1.0),
initial_refinement_level = 1);
julia> elements = Trixi.init_elements(mesh, LinearScalarAdvectionEquation2D((1.0,1.0)), solver.basis, Float64);
Benchmark using the existing code:
julia> @benchmark Trixi.calc_node_coordinates!(elements.node_coordinates, mesh, solver.basis.nodes)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 23.250 μs … 50.042 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 23.500 μs ┊ GC (median): 0.00%
Time (mean ± σ): 23.528 μs ± 487.328 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
▁ ▆ █ ▆ ▅ ▄ ▁
▂▁▁▃▁▁▁█▁▁█▁▁▁█▁▁█▁▁▁█▁▁█▁▁▁█▁▁▇▁▁▁▆▁▁▅▁▁▁▄▁▁▃▁▁▁▃▁▁▃▁▁▁▂▁▁▂ ▃
23.2 μs Histogram: frequency by time 24 μs <
Memory estimate: 4.23 KiB, allocs estimate: 73.
Benchmark with the proposed change:
julia> @benchmark Trixi.calc_node_coordinates!(elements.node_coordinates, mesh, solver.basis.nodes)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 66.459 μs … 114.210 ms ┊ GC (min … max): 0.00% … 99.92%
Time (median): 69.958 μs ┊ GC (median): 0.00%
Time (mean ± σ): 82.256 μs ± 1.142 ms ┊ GC (mean ± σ): 14.26% ± 1.39%
▂▁ ▁ █▇▅ ▃▂▂
▁▄██▇▃▂▂▄▇█▅▃▂▃▆███▇███▆▆▄▅▄▅▄▄▄▃▃▃▄▃▃▂▃▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁ ▃
66.5 μs Histogram: frequency by time 77.7 μs <
Memory estimate: 45.66 KiB, allocs estimate: 784.
Because of these performance regressions, I will mark this PR as a draft until they are resolved, since we can work around this in TrixiAtmo.jl for now. Thanks @ranocha for the suggestions!
Add numerical support of other real types (`laplace`) (trixi-framework#2025)
By the way, you should create a new branch for PRs and not work from |
calc_node_coordinates!
to allow for P4estMesh{2}
with 3D coordinatescalc_node_coordinates!
to allow for P4estMesh{2}
with 3D coordinates
This will not be pursued further; instead, a new PR will be made with the ambient dimension stored as a type parameter. |
In TrixiAtmo.jl, we solve PDEs on two-dimensional surfaces in three-dimensional space by using
P4estMesh{2}
with three-dimensional node coordinates and redefininginit_elements
accordingly to set up the appropriate containers for such meshes. We currently replacecalc_node_coordinates!
with a function which is otherwise identical to the corresponding Trixi.jl function, but changes the lineto the following:
If this doesn't cause any issues elsewhere, it would be helpful for our purposes to have this change be part of Trixi.jl, not only because it avoids repetition of the entire function in TrixiAtmo.jl, but also because Trixi2Vtk.jl calls
Trixi.calc_node_coordinates!
and thus requires such a change in order for this PR to be used for plotting 2D surfaces in 3D. Similar modifications could be made to other mesh types/dimensions, but since I don't see a use case for that currently, I haven't done that in this PR.