Skip to content
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: Unify create_cache for ControllerThreeLevel* and the different mesh types #2285

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/callbacks_step/amr_dg1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,11 @@ function coarsen_elements!(u::AbstractArray{<:Any, 3}, element_id,
end
end

# this method is called when an `ControllerThreeLevel` is constructed
function create_cache(::Type{ControllerThreeLevel}, mesh::TreeMesh{1}, equations,
dg::DG, cache)
controller_value = Vector{Int}(undef, nelements(dg, cache))
return (; controller_value)
end

function create_cache(::Type{ControllerThreeLevelCombined}, mesh::TreeMesh,
# Construct cache for ControllerThreeLevel and ControllerThreeLevelCombined.
# This method is called when a controller is constructed
function create_cache(::Union{Type{ControllerThreeLevel},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put this method in amr_dg.jl instead since it is not dimension-dependent anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or probably even in amr.jl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have amr_dg.jl as a file? Since it references the DG solver, that would be my pick

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sloede Does moving this stuff violate your "better be explicit and duplicate code for several space dimensions" policy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is precedence where we have replaced literally-identical implementations with a single function (e.g., solver functions for the different mesh types). So yes, I'd be ok with that :-)

Type{ControllerThreeLevelCombined}},
mesh::Union{TreeMesh, P4estMesh, T8codeMesh},
equations, dg::DG, cache)
controller_value = Vector{Int}(undef, nelements(dg, cache))
return (; controller_value)
Expand Down
8 changes: 0 additions & 8 deletions src/callbacks_step/amr_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,4 @@ function adapt!(u_ode::AbstractVector, adaptor, mesh::T8codeMesh{2}, equations,

return nothing
end

# this method is called when an `ControllerThreeLevel` is constructed
function create_cache(::Type{ControllerThreeLevel},
mesh::Union{TreeMesh{2}, P4estMesh{2}, T8codeMesh{2}}, equations,
dg::DG, cache)
controller_value = Vector{Int}(undef, nelements(dg, cache))
return (; controller_value)
end
end # @muladd
8 changes: 0 additions & 8 deletions src/callbacks_step/amr_dg3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,6 @@ function coarsen_elements!(u::AbstractArray{<:Any, 5}, element_id,
return nothing
end

# this method is called when an `ControllerThreeLevel` is constructed
function create_cache(::Type{ControllerThreeLevel},
mesh::Union{TreeMesh{3}, P4estMesh{3}, T8codeMesh{3}},
equations, dg::DG, cache)
controller_value = Vector{Int}(undef, nelements(dg, cache))
return (; controller_value)
end

# Coarsen and refine elements in the DG solver based on a difference list.
function adapt!(u_ode::AbstractVector, adaptor, mesh::T8codeMesh{3}, equations,
dg::DGSEM, cache, difference)
Expand Down
Loading