-
Notifications
You must be signed in to change notification settings - Fork 2
Add option to use ForwardDiff.jl to compute Christoffel symbols exactly and separate covariant form containers #78
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
base: main
Are you sure you want to change the base?
Changes from all commits
8121b38
da1a22a
a7293cc
a3d61db
f22bdd1
a24f7d9
bb9e921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -39,6 +39,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||
|
||||
# A semidiscretization collects data structures and functions for the spatial discretization | ||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||
metric_terms = MetricTermsCovariantSphere(), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
source_terms = source_terms_geometric_coriolis) | ||||
|
||||
############################################################################### | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -33,6 +33,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||
|
||||
# A semidiscretization collects data structures and functions for the spatial discretization | ||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||
metric_terms = MetricTermsCovariantSphere(), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
source_terms = source_terms_geometric_coriolis) | ||||
|
||||
############################################################################### | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -43,6 +43,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||
# specify the bottom topography. | ||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||
source_terms = source_terms_geometric_coriolis, | ||||
metric_terms = MetricTermsCovariantSphere(), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
auxiliary_field = bottom_topography_isolated_mountain) | ||||
|
||||
############################################################################### | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -39,6 +39,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||||||||||||||||||||
|
||||||||||||||||||||||
# A semidiscretization collects data structures and functions for the spatial discretization | ||||||||||||||||||||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||||||||||||||||||||
metric_terms = MetricTermsCovariantSphere(), | ||||||||||||||||||||||
source_terms = source_terms_geometric_coriolis) | ||||||||||||||||||||||
Comment on lines
40
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
############################################################################### | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -41,6 +41,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||
# discretization. Here, we pass in the additional keyword argument "auxiliary_field" to | ||||
# specify the bottom topography. | ||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||
metric_terms = MetricTermsCovariantSphere(), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
source_terms = source_terms_geometric_coriolis, | ||||
auxiliary_field = bottom_topography_unsteady_solid_body_rotation) | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -44,6 +44,7 @@ initial_condition_transformed = transform_initial_condition(initial_condition, e | |||
# specify the bottom topography, which is the same as for the standard isolated mountain | ||||
# case. | ||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||
metric_terms = MetricTermsCovariantSphere(), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
source_terms = source_terms_geometric_coriolis, | ||||
auxiliary_field = bottom_topography_isolated_mountain) | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,7 +29,8 @@ mesh = P4estMeshCubedSphere2D(cells_per_dimension[1], EARTH_RADIUS, | |||||||
initial_condition_transformed = transform_initial_condition(initial_condition, equations) | ||||||||
|
||||||||
# A semidiscretization collects data structures and functions for the spatial discretization | ||||||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver) | ||||||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||||||
metric_terms = MetricTermsCovariantSphere()) | ||||||||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
############################################################################### | ||||||||
# ODE solvers, callbacks etc. | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -28,7 +28,8 @@ mesh = P4estMeshQuadIcosahedron2D(cells_per_dimension[1], EARTH_RADIUS, | |||||||
initial_condition_transformed = transform_initial_condition(initial_condition, equations) | ||||||||
|
||||||||
# A semidiscretization collects data structures and functions for the spatial discretization | ||||||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver) | ||||||||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||||||||
metric_terms = MetricTermsCovariantSphere()) | ||||||||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
############################################################################### | ||||||||
# ODE solvers, callbacks etc. | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
MetricTermsCrossProduct() | ||
|
||
Struct used for multiple dispatch on functions that compute the metric terms. | ||
When the argument `metric_terms` is of type `MetricTermsCrossProduct`, the | ||
contravariant vectors are computed using the cross-product form. | ||
""" | ||
struct MetricTermsCrossProduct end | ||
|
||
""" | ||
MetricTermsInvariantCurl() | ||
|
||
Struct used for multiple dispatch on functions that compute the metric terms. | ||
When the argument `metric_terms` is of type `MetricTermsInvariantCurl`, the | ||
contravariant vectors are computed using the invariant curl form. | ||
## References | ||
- Kopriva, D. A. (2006). Metric identities and the discontinuous spectral element method on | ||
curvilinear meshes. Journal of Scientific Computing 26, 301-327. | ||
[DOI: 10.1007/s10915-005-9070-8](https://doi.org/10.1007/s10915-005-9070-8) | ||
- Vinokur, M. and Yee, H. C. (2001). Extension of efficient low dissipation high order | ||
schemes for 3-D curvilinear moving grids. In Caughey, D. A., and Hafez, M. M. (eds.), | ||
Frontiers of Computational Fluid Dynamics 2002, World Scientific, Singapore, pp. 129–164. | ||
[DOI: 10.1142/9789812810793_0008](https://doi.org/10.1142/9789812810793_0008) | ||
""" | ||
struct MetricTermsInvariantCurl end | ||
|
||
""" | ||
MetricTermsCovariantSphere(christoffel_symbols = ChristoffelSymbolsAutodiff()) | ||
|
||
Struct specifying options for computing geometric information for discretizations in | ||
covariant form based on an exact representation of the spherical geometry. Currently, the | ||
only field is `christoffel_symbols`, specifying the approach used to compute the | ||
Christoffel symbols, for which the options are [`ChristoffelSymbolsAutodiff`](@ref) or | ||
[`ChristoffelSymbolsCollocationDerivative`](@ref). | ||
""" | ||
struct MetricTermsCovariantSphere{ChristoffelSymbols} | ||
christoffel_symbols::ChristoffelSymbols | ||
function MetricTermsCovariantSphere(; | ||
christoffel_symbols::ChristoffelSymbols = ChristoffelSymbolsAutodiff()) where {ChristoffelSymbols} | ||
return new{ChristoffelSymbols}(christoffel_symbols) | ||
end | ||
end | ||
|
||
@doc raw""" | ||
ChristoffelSymbolsAutodiff() | ||
|
||
Struct used for multiple dispatch on functions that compute the Christoffel symbols. This | ||
option uses [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) to compute | ||
```math | ||
\Gamma_{jk}^i = | ||
\frac{1}{2}G^{il}\big(\partial_j G_{kl} + \partial_k G_{jl} - \partial_l G_{jk}\big) | ||
``` | ||
using forward-mode automatic differentiation. | ||
!!! warning | ||
Using this option with [`GlobalSphericalCoordinates`](@ref) is prone to `NaN` values as | ||
a result of the polar singularity. This is remedied through the use of | ||
[`GlobalCartesianCoordinates`](@ref). | ||
""" | ||
struct ChristoffelSymbolsAutodiff end | ||
|
||
@doc raw""" | ||
ChristoffelSymbolsCollocationDerivative() | ||
|
||
Struct used for multiple dispatch on functions that compute the Christoffel symbols. | ||
Letting $I^N$ denote the degree $N$ polynomial interpolation operator collocated with the | ||
scheme's quadrature nodes, this option computes the Christoffel symbols at each quadrature | ||
node using the approximation | ||
```math | ||
\Gamma_{jk}^i \approx | ||
\frac{1}{2}G^{il}\big(\partial_j I^N G_{kl} + \partial_k I^N G_{jl} - \partial_l I^N G_{jk}\big). | ||
``` | ||
""" | ||
struct ChristoffelSymbolsCollocationDerivative end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,2 @@ | ||
""" | ||
MetricTermsCrossProduct() | ||
|
||
Struct used for multiple dispatch on functions that compute the metric terms. | ||
When the argument `metric_terms` is of type `MetricTermsCrossProduct`, the | ||
contravariant vectors are computed using the cross-product form. | ||
""" | ||
struct MetricTermsCrossProduct end | ||
|
||
""" | ||
MetricTermsInvariantCurl() | ||
|
||
Struct used for multiple dispatch on functions that compute the metric terms. | ||
When the argument `metric_terms` is of type `MetricTermsInvariantCurl`, the | ||
contravariant vectors are computed using the invariant curl form. | ||
## References | ||
- Kopriva, D. A. (2006). Metric identities and the discontinuous spectral element method on | ||
curvilinear meshes. Journal of Scientific Computing 26, 301-327. | ||
[DOI: 10.1007/s10915-005-9070-8](https://doi.org/10.1007/s10915-005-9070-8) | ||
- Vinokur, M. and Yee, H. C. (2001). Extension of efficient low dissipation high order | ||
schemes for 3-D curvilinear moving grids. In Caughey, D. A., and Hafez, M. M. (eds.), | ||
Frontiers of Computational Fluid Dynamics 2002, World Scientific, Singapore, pp. 129–164. | ||
[DOI: 10.1142/9789812810793_0008](https://doi.org/10.1142/9789812810793_0008) | ||
""" | ||
struct MetricTermsInvariantCurl end | ||
include("metric_terms.jl") | ||
include("semidiscretization_hyperbolic_2d_manifold_in_3d.jl") |
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 understand that this line can be removed because
MetricTermsCovariantSphere()
is the default value ofmetric_terms
for this constructor. Isn't that the case? Any reason why we would like to keep it here and in all other elixirs?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 it possible to pass
metric_terms
as a parameter totrixi_include
otherwise?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 don't think it is. However, for the testing, it is only needed to specify
metric_terms
explicitly inelixir_shallowwater_covariant_rossby_haurwitz.jl
. I added a second review with code suggestions to improve the readability of the elixirs. What do you think of this variant?