-
Notifications
You must be signed in to change notification settings - Fork 5
Covariant Advection in DGMulti #111
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| ############################################################################### | ||
| # DGSEM for the linear advection equation on a prismed icosahedral grid | ||
| ############################################################################### | ||
| # To run a convergence test, use | ||
| # convergence_test("../examples/elixir_spherical_advection_covariant_prismed_icosahedron.jl", 4, initial_refinement_level = 1) | ||
|
|
||
| using OrdinaryDiffEq, Trixi, TrixiAtmo | ||
|
|
||
| ############################################################################### | ||
| # Spatial discretization | ||
|
|
||
| initial_condition = initial_condition_gaussian | ||
|
|
||
| equations = CovariantLinearAdvectionEquation2D(global_coordinate_system = GlobalCartesianCoordinates()) | ||
|
|
||
| ############################################################################### | ||
| # Build DG solver. | ||
|
|
||
| tensor_polydeg = (2, 1) | ||
|
|
||
| dg = DGMulti(element_type = Wedge(), | ||
| approximation_type = Polynomial(), | ||
| surface_flux = flux_central, | ||
| polydeg = tensor_polydeg) | ||
|
|
||
| ############################################################################### | ||
| # Build mesh. | ||
|
|
||
| initial_refinement_level = 3 | ||
|
|
||
| mesh = DGMultiMeshPrismIcosahedron(dg; | ||
| inner_radius = 0.999 * EARTH_RADIUS, | ||
| outer_radius = EARTH_RADIUS, | ||
| initial_refinement = initial_refinement_level) | ||
|
|
||
| # Transform the initial condition to the proper set of conservative variables | ||
| 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, dg) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| # Create ODE problem with time span from 0 to T | ||
| ode = semidiscretize(semi, (0.0, 12 * SECONDS_PER_DAY)) | ||
|
|
||
| # At the beginning of the main loop, the SummaryCallback prints a summary of the simulation | ||
| # setup and resets the timers | ||
| summary_callback = SummaryCallback() | ||
|
|
||
| # The AnalysisCallback allows to analyse the solution in regular intervals and prints the | ||
| # results | ||
| analysis_callback = AnalysisCallback(semi, interval = 10, | ||
| save_analysis = true, | ||
| extra_analysis_errors = (:conservation_error,), | ||
| uEltype = real(dg)) | ||
|
|
||
| # The SaveSolutionCallback allows to save the solution to a file in regular intervals | ||
| save_solution = SaveSolutionCallback(interval = 10, | ||
| solution_variables = contravariant2global) | ||
|
|
||
| # The StepsizeCallback handles the re-calculation of the maximum Δt after each time step | ||
| stepsize_callback = StepsizeCallback(cfl = 0.7) | ||
|
|
||
| # Create a CallbackSet to collect all callbacks such that they can be passed to the ODE | ||
| # solver | ||
| callbacks = CallbackSet(summary_callback, analysis_callback, save_solution, | ||
| stepsize_callback) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
|
|
||
| # OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed | ||
| # callbacks | ||
| sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), | ||
| dt = 1.0, save_everystep = true, callback = callbacks) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ using Printf: @sprintf | |
| using Static: True, False | ||
| using StrideArrays: PtrArray | ||
| using StaticArrayInterface: static_size | ||
| using LinearAlgebra: cross, norm, dot, det | ||
| using LinearAlgebra: Diagonal, cross, norm, dot, det | ||
| using Reexport: @reexport | ||
| using LoopVectorization: @turbo | ||
| using QuadGK: quadgk | ||
|
|
@@ -35,6 +35,9 @@ using HDF5: HDF5, h5open, attributes, create_dataset, datatype, dataspace | |
|
|
||
| using Trixi: ln_mean, stolarsky_mean, inv_ln_mean | ||
|
|
||
| # DGMulti solvers | ||
| using StartUpDG: RefElemData, MeshData, AbstractElemShape | ||
|
Collaborator
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. Are all of these needed in this PR, or maybe in some upcoming PR? |
||
|
|
||
| include("auxiliary/auxiliary.jl") | ||
| include("equations/equations.jl") | ||
| include("meshes/meshes.jl") | ||
|
|
@@ -69,9 +72,9 @@ export source_terms_lagrange_multiplier, clean_solution_lagrange_multiplier! | |
|
|
||
| export cons2prim_and_vorticity, contravariant2global | ||
|
|
||
| export P4estMeshCubedSphere2D, P4estMeshQuadIcosahedron2D, MetricTermsCrossProduct, | ||
| MetricTermsInvariantCurl, MetricTermsCovariantSphere, ChristoffelSymbolsAutodiff, | ||
| ChristoffelSymbolsCollocationDerivative | ||
| export P4estMeshCubedSphere2D, P4estMeshQuadIcosahedron2D, DGMultiMeshPrismIcosahedron, | ||
| MetricTermsCrossProduct, MetricTermsInvariantCurl, MetricTermsCovariantSphere, | ||
| ChristoffelSymbolsAutodiff, ChristoffelSymbolsCollocationDerivative | ||
|
|
||
| export EARTH_RADIUS, EARTH_GRAVITATIONAL_ACCELERATION, | ||
| EARTH_ROTATION_RATE, SECONDS_PER_DAY | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,29 @@ function Trixi.analyze(::typeof(Trixi.entropy_timederivative), du, u, t, | |
| end | ||
| end | ||
|
|
||
| # Entropy time derivative for cons2entropy function which depends on auxiliary variables | ||
| function Trixi.analyze(::typeof(Trixi.entropy_timederivative), du, u, t, | ||
| mesh::DGMultiMesh, equations::AbstractCovariantEquations, dg::DGMulti, cache) | ||
| rd = dg.basis | ||
| md = mesh.md | ||
| @unpack u_values, aux_quad_values = cache | ||
|
|
||
| # interpolate u, du to quadrature points | ||
| du_values = similar(u_values) # TODO: DGMulti. Can we move this to the analysis cache somehow? | ||
|
Collaborator
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. Is this a general TODO that is addressed somewhere else?
Collaborator
Author
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. I copied this over from the corresponding Trixi function. I will add a note pointing to Trixi somehow |
||
| Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), du_values, du) | ||
| Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), u_values, u) | ||
|
|
||
| # compute ∫v(u) * du/dt = ∫dS/dt. We can directly compute v(u) instead of computing the entropy | ||
| # projection here, since the RHS will be projected to polynomials of degree N and testing with | ||
| # the L2 projection of v(u) would be equivalent to testing with v(u) due to the moment-preserving | ||
| # property of the L2 projection. | ||
| dS_dt = zero(eltype(first(du))) | ||
| for i in Base.OneTo(length(md.wJq)) | ||
| dS_dt += dot(cons2entropy(u_values[i], aux_quad_values[i], equations), du_values[i]) * md.wJq[i] | ||
| end | ||
| return dS_dt | ||
| end | ||
|
|
||
| # L2 and Linf error calculation for the covariant form | ||
| function Trixi.calc_error_norms(func, u, t, analyzer, mesh::P4estMesh{2}, | ||
| equations::AbstractCovariantEquations{2}, | ||
|
|
@@ -124,4 +147,27 @@ function Trixi.calc_error_norms(func, u, t, analyzer, mesh::P4estMesh{2}, | |
|
|
||
| return l2_error, linf_error | ||
| end | ||
|
|
||
| # L2 and Linf error calculation for the covariant form | ||
| function Trixi.calc_error_norms(func, u, t, analyzer, | ||
| mesh::DGMultiMesh{NDIMS}, equations::AbstractCovariantEquations, initial_condition, | ||
| dg::DGMulti{NDIMS}, cache, cache_analysis) where {NDIMS} | ||
| rd = dg.basis | ||
| md = mesh.md | ||
| @unpack u_values, aux_quad_values = cache | ||
|
|
||
| # interpolate u to quadrature points | ||
| Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), u_values, u) | ||
|
|
||
| component_l2_errors = zero(eltype(u_values)) | ||
| component_linf_errors = zero(eltype(u_values)) | ||
| for i in Trixi.each_quad_node_global(mesh, dg, cache) | ||
| u_exact = initial_condition(SVector(getindex.(md.xyzq, i)), t, aux_quad_values[i], equations) | ||
| error_at_node = func(u_values[i], equations) - func(u_exact, equations) | ||
| component_l2_errors += md.wJq[i] * error_at_node .^ 2 | ||
| component_linf_errors = max.(component_linf_errors, abs.(error_at_node)) | ||
| end | ||
| total_volume = sum(md.wJq) | ||
| return sqrt.(component_l2_errors ./ total_volume), component_linf_errors | ||
| end | ||
| end # @muladd | ||
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.
You could use
ode_default_options()here.