-
Notifications
You must be signed in to change notification settings - Fork 112
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: p4est solver on a spherical shell #1749
Conversation
-> We manually (hard-coded) transform the Euler equations into linear advection
…Euler into linear advection
… into advection with variable coefficients, and improved formatting
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. |
@@ -40,7 +40,7 @@ struct SemidiscretizationHyperbolic{Mesh, Equations, InitialCondition, | |||
BoundaryConditions, | |||
SourceTerms, Solver, | |||
Cache} | |||
@assert ndims(mesh) == ndims(equations) | |||
#@assert ndims(mesh) == ndims(equations) |
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 removed this check because the new implementation requires a 2D mesh (P4estMesh{2}
) with a 3D equation. Should I just remove this line or maybe change the check?
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.
That's a good question. I think we should analyze where we use this kind of assumption and try to get it right. For example, I guess everything will fail badly if you use an UnstructuredMesh2D
with a 3D equation, won't it?
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.
Yes, it will fail. We would need special constructors that create those meshes using nodes with three (x, y, z) node coordinates, and we would then need to adjust the metric term computation of all mesh types. It is doable but I think it is out of the scope of the present PR and probably no one will ever use it 🤣.
Then maybe I just check for the particular case of a P4estMesh2D
with 3D node coordinates in combination with a 3D equation, allow that combination and bring back the @assert
for any other case. Does that sound like a good solution?
src/solvers/dgsem_structured/dg.jl
Outdated
# Extract contravariant vector Ja^i (i = index) as SVector | ||
# TODO: Here, size() causes a lot of allocations! Find an alternative to improve performance | ||
@inline function get_contravariant_vector(index, contravariant_vectors, indices...) | ||
SVector(ntuple(@inline(dim->contravariant_vectors[dim, index, indices...]), | ||
Val(ndims(contravariant_vectors) - 3))) | ||
Val(size(contravariant_vectors, 1)))) | ||
end |
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.
This new version of get_contravariant_vector
causes too many allocations. Unfortunately, ndims(contravariant_vectors) - 3
does not work for the simulations on the spherical shell and size()
is evaluated in runtime. Is there a better way to do 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.
Is this code only called from your code or also from existing routines? In the current implementation it is not type stable, thus the allocations.
We might get around it easily if it is only used from code you control, and harder (but not impossible) if it is in generic routines as well.
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.
No, this is called in the existing volume and surface integral routines. In fact, I temporarily changed the existing volume integral calls, such that the code runs a bit faster. See, e.g.,
Trixi.jl/src/solvers/dgsem_structured/dg_2d.jl
Lines 78 to 81 in b89e333
#Ja11, Ja12 = get_contravariant_vector(1, contravariant_vectors, i, j, element) | |
Ja11 = contravariant_vectors[1, 1, i, j, element] | |
Ja12 = contravariant_vectors[2, 1, i, j, element] | |
contravariant_flux1 = Ja11 * flux1 + Ja12 * flux2 |
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.
Hm. I wonder if what you are doing in this PR is fundamental enough of a conceptual difference to require a new mesh type. That is, to not try to shoehorn this into P4estMesh{2}
but rather something like P4estMesh{3/2}
?
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.
Alternatively, we may need to pass an additional argument to get_contravariant_vector
that determines the number of dimensions at compile time - the mesh
?
This would be a kind of semi-breaking change since it's not documented anywhere as far as I know but used in the internals. Thus, it may break the workflow for people using Trixi.jl as a library.
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.
True. The question is whether the mesh truly "owns" the dimensionality of a problem. But it would certainly be less intrusive than adding a new mesh type.
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.
Well, it looks like there isn't anything like "the dimensionality of a problem" anymore. We need to distinguish between the dimensionality of the geometry and the equations. From my point of view, the contravariant vectors are clearly associated with the geometry, i.e., the mesh
.
However, this is really a tough problem since we want to pass the contravariant vectors as normal directions to the flux
es. Thus, we assume that the dimensionality of the equations
and the mesh
are the same. This requires some really careful design to achieve a consistent splitting.
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.
We need to distinguish between the dimensionality of the geometry and the equations.
Exactly!
The contravariant vectors are actually associated with both the dimensionality of the geometry and the equations. For instance:
- For a 2D geometry and a 2D equation, the contravariant vectors are of size
2 x 2 x nnodes x nnodes x nelements
. - For a 2D geometry and a 3D equation, the contravariant vectors are of size
3 x 3 x nnodes x nnodes x nelements
. - For a 3D geometry and a 3D equation, the contravariant vectors are of size
3 x 3 x nnodes x nnodes x nnodes x nelements
.
For the first and last cases, ndims(contravariant_vectors) - 3
works. For the (new) second case, it does not.
For this particular function, we would actually need to pass the number of dimensions of the equation to define the size of the SVector... Or maybe there is a workaround. 🤔
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.
Hm. I wonder if what you are doing in this PR is fundamental enough of a conceptual difference to require a new mesh type. That is, to not try to shoehorn this into P4estMesh{2} but rather something like P4estMesh{3/2}?
This function is mesh type agnostic, so that won't fix this particular problem.
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.
In amrueda#12, I propose a workaround to this problem using a new type that extends Array
. What do you think of this solution? @sloede @ranocha
Convergence test with
####################################################################################################
l2
rho rho_v1 rho_v2 rho_v3 rho_e
error EOC error EOC error EOC error EOC error EOC
8.45e-03 - 8.23e-03 - 1.84e-03 - 0.00e+00 - 6.44e-02 -
8.47e-04 3.32 8.17e-04 3.33 2.04e-04 3.17 0.00e+00 NaN 6.46e-02 -0.00
2.30e-05 5.20 2.26e-05 5.17 4.08e-06 5.65 0.00e+00 NaN 6.46e-02 0.00
1.06e-06 4.44 9.43e-07 4.59 3.73e-07 3.45 0.00e+00 NaN 6.46e-02 0.00
mean 4.32 mean 4.36 mean 4.09 mean NaN mean -0.00
----------------------------------------------------------------------------------------------------
linf
rho rho_v1 rho_v2 rho_v3 rho_e
error EOC error EOC error EOC error EOC error EOC
9.49e-02 - 9.65e-02 - 1.37e-02 - 0.00e+00 - 4.09e-01 -
8.23e-03 3.53 8.23e-03 3.55 1.95e-03 2.82 0.00e+00 NaN 4.22e-01 -0.04
5.89e-04 3.80 5.93e-04 3.79 6.77e-05 4.85 0.00e+00 NaN 4.17e-01 0.02
3.44e-05 4.10 3.47e-05 4.10 9.36e-06 2.85 0.00e+00 NaN 4.16e-01 0.00
mean 3.81 mean 3.81 mean 3.51 mean NaN mean -0.01
----------------------------------------------------------------------------------------------------
####################################################################################################
l2
rho rho_v1 rho_v2 rho_v3 rho_e
error EOC error EOC error EOC error EOC error EOC
2.52e-03 - 2.37e-03 - 8.18e-04 - 0.00e+00 - 6.47e-02 -
3.14e-05 6.33 3.10e-05 6.26 5.44e-06 7.23 0.00e+00 NaN 6.46e-02 0.00
8.98e-07 5.13 8.81e-07 5.14 1.57e-07 5.11 0.00e+00 NaN 6.46e-02 -0.00
5.24e-08 4.10 5.02e-08 4.13 9.30e-09 4.08 0.00e+00 NaN 6.46e-02 0.00
mean 5.19 mean 5.18 mean 5.47 mean NaN mean 0.00
----------------------------------------------------------------------------------------------------
linf
rho rho_v1 rho_v2 rho_v3 rho_e
error EOC error EOC error EOC error EOC error EOC
2.04e-02 - 1.99e-02 - 6.87e-03 - 0.00e+00 - 4.20e-01 -
9.62e-04 4.41 9.69e-04 4.36 1.13e-04 5.92 0.00e+00 NaN 4.18e-01 0.01
2.86e-05 5.07 2.87e-05 5.08 4.42e-06 4.68 0.00e+00 NaN 4.16e-01 0.01
1.55e-06 4.20 1.55e-06 4.21 1.66e-07 4.73 0.00e+00 NaN 4.16e-01 0.00
mean 4.56 mean 4.55 mean 5.11 mean NaN mean 0.00
---------------------------------------------------------------------------------------------------- |
…e integral of p4est 2D
…trArray Fix allocations in get_contravariant_vector with PtrArray
This PR implements a version of the 2D p4est solver that runs on a spherical shell that is constructed from a cubed sphere. Since there are three Cartesian space dimensions on the surface of the sphere, we use the 2D p4est solver in combination with a 3D equation.
The connectivities are inherited from the p8est 3D cubed-sphere implementation, but they are adapted to p4est (2D). The metric terms are computed with a cross-product form, as it is standard for the DG implementations of the shallow-water equations on the surface of a sphere. See, e.g.,
I did not see any particular advantages of using a curl form.
The following points need to be addressed (more information in the threads below):
get_contravariant_vector
causes too many allocations.du
.The following visualization uses this version of Trixi2Vtk:
earth.mp4