diff --git a/src/callbacks_stage/positivity_zhang_shu_dg1d.jl b/src/callbacks_stage/positivity_zhang_shu_dg1d.jl index 7797eb95b09..4345c275cd0 100644 --- a/src/callbacks_stage/positivity_zhang_shu_dg1d.jl +++ b/src/callbacks_stage/positivity_zhang_shu_dg1d.jl @@ -27,7 +27,7 @@ function limiter_zhang_shu!(u, threshold::Real, variable, u_mean += u_node * weights[i] end # note that the reference element is [-1,1]^ndims(dg), thus the weights sum to 2 - u_mean = u_mean / 2^ndims(mesh) + u_mean = u_mean / 2 # We compute the value directly with the mean values, as we assume that # Jensen's inequality holds (e.g. pressure for compressible Euler equations). diff --git a/src/callbacks_step/amr_dg1d.jl b/src/callbacks_step/amr_dg1d.jl index b4cd6a00271..9f4c2d8e5c4 100644 --- a/src/callbacks_step/amr_dg1d.jl +++ b/src/callbacks_step/amr_dg1d.jl @@ -33,7 +33,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1}, @assert nelements(dg, cache) > old_n_elements resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg) * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or refine them @@ -43,7 +43,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1}, # Refine element and store solution directly in new data structure refine_element!(u, element_id, old_u, old_element_id, adaptor, equations, dg) - element_id += 2^ndims(mesh) + element_id += 2 else # Copy old element data to new element container @views u[:, .., element_id] .= old_u[:, .., old_element_id] @@ -55,7 +55,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1}, # the counter `element_id` can have two different values at the end. @assert element_id == nelements(dg, cache) + - 1||element_id == nelements(dg, cache) + 2^ndims(mesh) "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" + 1||element_id == nelements(dg, cache) + 2 "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" end # GC.@preserve old_u_ode # re-initialize interfaces container @@ -170,7 +170,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1}, @assert nelements(dg, cache) < old_n_elements resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg) * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or coarsen them @@ -187,13 +187,15 @@ function coarsen!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1}, # If an element is to be removed, sanity check if the following elements # are also marked - otherwise there would be an error in the way the # cells/elements are sorted - @assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order" + @assert all(to_be_removed[old_element_id:(old_element_id + 2 - 1)]) "bad cell/element order" # Coarsen elements and store solution directly in new data structure coarsen_elements!(u, element_id, old_u, old_element_id, adaptor, equations, dg) + # Increment `element_id` on the coarsened mesh by one and `skip` = 1 in 1D + # because 2 children elements become 1 parent element element_id += 1 - skip = 2^ndims(mesh) - 1 + skip = 1 else # Copy old element data to new element container @views u[:, .., element_id] .= old_u[:, .., old_element_id] diff --git a/src/callbacks_step/amr_dg2d.jl b/src/callbacks_step/amr_dg2d.jl index 062020b6d42..fa517a8b5ca 100644 --- a/src/callbacks_step/amr_dg2d.jl +++ b/src/callbacks_step/amr_dg2d.jl @@ -31,7 +31,7 @@ function rebalance_solver!(u_ode::AbstractVector, mesh::TreeMesh{2}, equations, end resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache)) u = wrap_array_native(u_ode, mesh, equations, dg, cache) # Get new list of leaf cells @@ -119,7 +119,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{2}, P4estM reinitialize_containers!(mesh, equations, dg, cache) resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or refine them @@ -144,7 +144,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{2}, P4estM # Increment `element_id` on the refined mesh with the number # of children, i.e., 4 in 2D - element_id += 2^ndims(mesh) + element_id += 4 else if mesh isa P4estMesh # Copy old element data to new element container and remove Jacobian scaling @@ -165,13 +165,13 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{2}, P4estM # the counter `element_id` can have two different values at the end. @assert element_id == nelements(dg, cache) + - 1||element_id == nelements(dg, cache) + 2^ndims(mesh) "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" + 1||element_id == nelements(dg, cache) + 2^2 "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" end # GC.@preserve old_u_ode old_inverse_jacobian # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 && !mpi_isparallel() - @assert ninterfaces(cache.interfaces)==ndims(mesh) * nelements(dg, cache) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache.interfaces)==2 * nelements(dg, cache) ("For 2D and periodic domains and conforming elements, the number of interfaces must be 2 times the number of elements") end return nothing @@ -193,8 +193,8 @@ function refine!(u_ode::AbstractVector, adaptor, # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 && !mpi_isparallel() - @assert ninterfaces(cache_parabolic.interfaces)==ndims(mesh) * - nelements(dg, cache_parabolic) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache_parabolic.interfaces)==2 * + nelements(dg, cache_parabolic) ("For 2D and periodic domains and conforming elements, the number of interfaces must be 2 times the number of elements") end return nothing @@ -313,7 +313,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, reinitialize_containers!(mesh, equations, dg, cache) resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or coarsen them @@ -330,7 +330,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # If an element is to be removed, sanity check if the following elements # are also marked - otherwise there would be an error in the way the # cells/elements are sorted - @assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order" + @assert all(to_be_removed[old_element_id:(old_element_id + 2^2 - 1)]) "bad cell/element order" # Coarsen elements and store solution directly in new data structure coarsen_elements!(u, element_id, old_u, old_element_id, @@ -349,7 +349,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # Increment `element_id` on the coarsened mesh by one and `skip` = 3 in 2D # because 4 children elements become 1 parent element element_id += 1 - skip = 2^ndims(mesh) - 1 + skip = 3 else if mesh isa P4estMesh # Copy old element data to new element container and remove Jacobian scaling @@ -372,7 +372,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 && !mpi_isparallel() - @assert ninterfaces(cache.interfaces)==ndims(mesh) * nelements(dg, cache) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache.interfaces)==2 * nelements(dg, cache) ("For 2D and periodic domains and conforming elements, the number of interfaces must be 2 times the number of elements") end return nothing @@ -394,8 +394,8 @@ function coarsen!(u_ode::AbstractVector, adaptor, # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 && !mpi_isparallel() - @assert ninterfaces(cache_parabolic.interfaces)==ndims(mesh) * - nelements(dg, cache_parabolic) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache_parabolic.interfaces)==2 * + nelements(dg, cache_parabolic) ("For 2D and periodic domains and conforming elements, the number of interfaces must be 2 times the number of elements") end return nothing diff --git a/src/callbacks_step/amr_dg3d.jl b/src/callbacks_step/amr_dg3d.jl index 594c30dcca5..b41e47ae56d 100644 --- a/src/callbacks_step/amr_dg3d.jl +++ b/src/callbacks_step/amr_dg3d.jl @@ -48,7 +48,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{3}, P4estM reinitialize_containers!(mesh, equations, dg, cache) resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg)^3 * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or refine them @@ -77,7 +77,7 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{3}, P4estM # Increment `element_id` on the refined mesh with the number # of children, i.e., 8 in 3D - element_id += 2^ndims(mesh) + element_id += 8 else if mesh isa P4estMesh # Copy old element data to new element container and remove Jacobian scaling @@ -98,12 +98,12 @@ function refine!(u_ode::AbstractVector, adaptor, mesh::Union{TreeMesh{3}, P4estM # the counter `element_id` can have two different values at the end. @assert element_id == nelements(dg, cache) + - 1||element_id == nelements(dg, cache) + 2^ndims(mesh) "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" + 1||element_id == nelements(dg, cache) + 8 "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))" end # GC.@preserve old_u_ode old_inverse_jacobian # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 - @assert ninterfaces(cache.interfaces)==ndims(mesh) * nelements(dg, cache) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache.interfaces)==3 * nelements(dg, cache) ("For 3D and periodic domains and conforming elements, the number of interfaces must be 3 times the number of elements") end return nothing @@ -229,7 +229,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, reinitialize_containers!(mesh, equations, dg, cache) resize!(u_ode, - nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache)) + nvariables(equations) * nnodes(dg)^3 * nelements(dg, cache)) u = wrap_array(u_ode, mesh, equations, dg, cache) # Loop over all elements in old container and either copy them or coarsen them @@ -250,7 +250,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # If an element is to be removed, sanity check if the following elements # are also marked - otherwise there would be an error in the way the # cells/elements are sorted - @assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order" + @assert all(to_be_removed[old_element_id:(old_element_id + 2^3 - 1)]) "bad cell/element order" # Coarsen elements and store solution directly in new data structure coarsen_elements!(u, element_id, old_u, old_element_id, adaptor, @@ -269,7 +269,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # Increment `element_id` on the coarsened mesh by one and `skip` = 7 in 3D # because 8 children elements become 1 parent element element_id += 1 - skip = 2^ndims(mesh) - 1 + skip = 7 else if mesh isa P4estMesh # Copy old element data to new element container and remove Jacobian scaling @@ -291,7 +291,7 @@ function coarsen!(u_ode::AbstractVector, adaptor, # Sanity check if mesh isa TreeMesh && isperiodic(mesh.tree) && nmortars(cache.mortars) == 0 - @assert ninterfaces(cache.interfaces)==ndims(mesh) * nelements(dg, cache) ("For $(ndims(mesh))D and periodic domains and conforming elements, the number of interfaces must be $(ndims(mesh)) times the number of elements") + @assert ninterfaces(cache.interfaces)==3 * nelements(dg, cache) ("For 3D and periodic domains and conforming elements, the number of interfaces must be 3 times the number of elements") end return nothing