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

AMR for parabolic terms in 2D & 3D on TreeMeshes #1629

Merged
merged 100 commits into from
Oct 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
b33cbc2
Clean branch
DanielDoehring Aug 14, 2023
7e32e24
Un-Comment
DanielDoehring Aug 14, 2023
5e1997b
un-comment
DanielDoehring Aug 14, 2023
54e328e
test coarsen
DanielDoehring Aug 14, 2023
a9e4cb7
remove redundancy
DanielDoehring Aug 14, 2023
ebb5865
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 15, 2023
4f72a09
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 15, 2023
70568f5
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 16, 2023
ebc9cc8
Remove support for passive terms
DanielDoehring Aug 18, 2023
9c766b9
expand resize
DanielDoehring Aug 18, 2023
c63e8b7
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 18, 2023
82894d7
comments
DanielDoehring Aug 18, 2023
6ef88ca
format
DanielDoehring Aug 18, 2023
7e4a450
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 19, 2023
53f5991
Avoid code duplication
DanielDoehring Aug 20, 2023
daf6fc4
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 20, 2023
cdfe93b
Update src/callbacks_step/amr_dg1d.jl
DanielDoehring Aug 22, 2023
0f2b779
comment
DanielDoehring Aug 22, 2023
376f99e
comment & format
DanielDoehring Aug 22, 2023
1dcfed4
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
baec78f
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
8526d16
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
826553f
Try to increase coverage
DanielDoehring Aug 28, 2023
9363b52
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 28, 2023
d209629
Slightly more expressive names
DanielDoehring Aug 29, 2023
abce5ae
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 31, 2023
a7d56a1
Apply suggestions from code review
sloede Sep 1, 2023
133c6a6
Merge branch 'main' into Parabolic_AMR_1D
sloede Sep 1, 2023
d348b82
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 6, 2023
f87046d
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 6, 2023
0c7dcb0
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 7, 2023
abb6dfb
add specifier for 1d
DanielDoehring Sep 11, 2023
bfa3a24
Structs for resizing parabolic helpers
DanielDoehring Sep 11, 2023
40ad266
check if mortars are present
DanielDoehring Sep 11, 2023
4d1914b
reuse `reinitialize_containers!`
DanielDoehring Sep 11, 2023
70c8e66
resize calls for parabolic helpers
DanielDoehring Sep 11, 2023
a5db7d0
update analysis callbacks
DanielDoehring Sep 11, 2023
c9d98a2
Velocities for compr euler
DanielDoehring Sep 11, 2023
694e6bc
Init container
DanielDoehring Sep 11, 2023
07655a4
correct copy-paste error
DanielDoehring Sep 11, 2023
edd82ce
resize each dim
DanielDoehring Sep 11, 2023
ba1ef1b
add dispatch
DanielDoehring Sep 11, 2023
7d351e5
Add AMR for shear layer
DanielDoehring Sep 11, 2023
e608174
USe only amr shear layer
DanielDoehring Sep 11, 2023
6574bf5
first steps towards p4est parabolic amr
DanielDoehring Sep 11, 2023
4c35430
Add tests
DanielDoehring Sep 11, 2023
21d29f8
remove plots
DanielDoehring Sep 11, 2023
29bd213
Format
DanielDoehring Sep 11, 2023
cb3eac8
remove redundant line
DanielDoehring Sep 11, 2023
7e68d94
platform independent tests
DanielDoehring Sep 11, 2023
0eadf49
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 12, 2023
5c20c4f
No need for different flux_viscous comps after adding container_visco…
DanielDoehring Sep 12, 2023
a0b6e3a
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Sep 12, 2023
21ccff4
Laplace 3d
DanielDoehring Sep 12, 2023
06a7811
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 15, 2023
591132b
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 18, 2023
d1b8316
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
07cf0ba
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
8df117b
Longer times to allow converage to hit coarsen!
DanielDoehring Sep 20, 2023
ff77769
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Sep 20, 2023
cdaa865
Increase testing of Laplace 3D
DanielDoehring Sep 20, 2023
4699a10
Add tests for velocities
DanielDoehring Sep 20, 2023
306c9b0
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
0129b5e
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 22, 2023
ac1c1ca
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 22, 2023
5f0051c
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 4, 2023
389d89c
remove comment
DanielDoehring Oct 5, 2023
03be339
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 5, 2023
1d4486a
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 5, 2023
a79a2f6
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 10, 2023
a5ddabe
Add comments
DanielDoehring Oct 11, 2023
ed2c95d
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 11, 2023
bc34831
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 11, 2023
2d960fc
Remove some specializations
DanielDoehring Oct 11, 2023
22eeb18
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 11, 2023
9435d4e
Add comments
DanielDoehring Oct 11, 2023
77b3b02
Use tuple for outer, fixed size datastruct for internal quantities
DanielDoehring Oct 12, 2023
2297486
Format
DanielDoehring Oct 12, 2023
230b083
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 12, 2023
3079153
Add comments
DanielDoehring Oct 18, 2023
825ff34
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 18, 2023
0484fb9
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 18, 2023
1d50359
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 19, 2023
a6f21c5
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 21, 2023
e2e287a
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 21, 2023
e8f2a66
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 21, 2023
9c32ae2
Update examples/tree_2d_dgsem/elixir_navierstokes_shearlayer_amr.jl
DanielDoehring Oct 22, 2023
1a42c15
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 22, 2023
67c1027
Update src/Trixi.jl
DanielDoehring Oct 22, 2023
09f1e85
Move velocity into elixir
DanielDoehring Oct 22, 2023
67647b4
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 22, 2023
00a827d
remove tests
DanielDoehring Oct 22, 2023
fa893cb
Remove deprecated comments
DanielDoehring Oct 23, 2023
2272cda
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 23, 2023
827f6e1
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 23, 2023
d452930
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 23, 2023
202106b
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 24, 2023
b8a010d
Add news
DanielDoehring Oct 24, 2023
0353488
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 24, 2023
5877e7a
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 25, 2023
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
Prev Previous commit
Next Next commit
Avoid code duplication
  • Loading branch information
DanielDoehring committed Aug 20, 2023
commit 53f599145e001384c952843b0e540e1721f4a3b1
155 changes: 16 additions & 139 deletions src/callbacks_step/amr_dg1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,88 +79,30 @@ end
function refine!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1},
equations, dg::DGSEM, cache, cache_parabolic,
elements_to_refine)
# Return early if there is nothing to do
if isempty(elements_to_refine)
return
end

# Determine for each existing element whether it needs to be refined
needs_refinement = falses(nelements(dg, cache))
needs_refinement[elements_to_refine] .= true

# Retain current solution data
old_n_elements = nelements(dg, cache)
old_u_ode = copy(u_ode)
GC.@preserve old_u_ode begin # OBS! If we don't GC.@preserve old_u_ode, it might be GC'ed
old_u = wrap_array(old_u_ode, mesh, equations, dg, cache)

# Get new list of leaf cells
leaf_cell_ids = local_leaf_cells(mesh.tree)

# re-initialize elements container
@unpack elements = cache
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)
@assert nelements(dg, cache) > old_n_elements

@unpack elements, viscous_container = cache_parabolic
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)
@assert nelements(dg, cache_parabolic) > old_n_elements
refine!(u_ode, adaptor, mesh, equations, dg, cache, elements_to_refine)

resize!(u_ode,
nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache))
u = wrap_array(u_ode, mesh, equations, dg, cache)
# Get new list of leaf cells
leaf_cell_ids = local_leaf_cells(mesh.tree)

# Resize parabolic helper variables
resize!(viscous_container, equations, dg, cache)
@unpack elements, viscous_container = cache_parabolic
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)

# Loop over all elements in old container and either copy them or refine them
element_id = 1
for old_element_id in 1:old_n_elements
if needs_refinement[old_element_id]
# 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)
else
# Copy old element data to new element container
@views u[:, .., element_id] .= old_u[:, .., old_element_id]
element_id += 1
end
end
# If everything is correct, we should have processed all elements.
# Depending on whether the last element processed above had to be refined or not,
# 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))"
@assert element_id ==
nelements(dg, cache_parabolic) +
1||element_id == nelements(dg, cache_parabolic) + 2^ndims(mesh) "element_id = $element_id, nelements(dg, cache_parabolic) = $(nelements(dg, cache_parabolic))"
end # GC.@preserve old_u_ode
# Resize parabolic helper variables
resize!(viscous_container, equations, dg, cache)

# re-initialize interfaces container
@unpack interfaces = cache
resize!(interfaces, count_required_interfaces(mesh, leaf_cell_ids))
init_interfaces!(interfaces, elements, mesh)

@unpack interfaces = cache_parabolic
resize!(interfaces, count_required_interfaces(mesh, leaf_cell_ids))
init_interfaces!(interfaces, elements, mesh)

# re-initialize boundaries container
@unpack boundaries = cache
resize!(boundaries, count_required_boundaries(mesh, leaf_cell_ids))
init_boundaries!(boundaries, elements, mesh)

@unpack boundaries = cache_parabolic
resize!(boundaries, count_required_boundaries(mesh, leaf_cell_ids))
init_boundaries!(boundaries, elements, mesh)

# Sanity check
if isperiodic(mesh.tree)
@assert ninterfaces(interfaces)==1 * nelements(dg, cache) ("For 1D and periodic domains, the number of interfaces must be the same as the number of elements")
@assert ninterfaces(interfaces)==1 * nelements(dg, cache_parabolic) ("For 1D and periodic domains, the number of interfaces must be the same as the number of elements")
end

Expand Down Expand Up @@ -295,95 +237,30 @@ end
function coarsen!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1},
equations, dg::DGSEM, cache, cache_parabolic,
elements_to_remove)
# Return early if there is nothing to do
if isempty(elements_to_remove)
return
end
coarsen!(u_ode, adaptor, mesh, equations, dg, cache, elements_to_remove)

# Determine for each old element whether it needs to be removed
to_be_removed = falses(nelements(dg, cache))
to_be_removed[elements_to_remove] .= true

# Retain current solution data
old_n_elements = nelements(dg, cache)
old_u_ode = copy(u_ode)
GC.@preserve old_u_ode begin # OBS! If we don't GC.@preserve old_u_ode, it might be GC'ed
old_u = wrap_array(old_u_ode, mesh, equations, dg, cache)

# Get new list of leaf cells
leaf_cell_ids = local_leaf_cells(mesh.tree)

# re-initialize elements container
@unpack elements = cache
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)
@assert nelements(dg, cache) < old_n_elements

@unpack elements, viscous_container = cache_parabolic
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)
@assert nelements(dg, cache_parabolic) < old_n_elements

resize!(u_ode,
nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache))
u = wrap_array(u_ode, mesh, equations, dg, cache)

# Resize parabolic helper variables
resize!(viscous_container, equations, dg, cache)

# Loop over all elements in old container and either copy them or coarsen them
skip = 0
element_id = 1
for old_element_id in 1:old_n_elements
# If skip is non-zero, we just coarsened 2^ndims elements and need to omit the following elements
if skip > 0
skip -= 1
continue
end
# Get new list of leaf cells
leaf_cell_ids = local_leaf_cells(mesh.tree)

if to_be_removed[old_element_id]
# 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"
@unpack elements, viscous_container = cache_parabolic
resize!(elements, length(leaf_cell_ids))
init_elements!(elements, leaf_cell_ids, mesh, dg.basis)

# Coarsen elements and store solution directly in new data structure
coarsen_elements!(u, element_id, old_u, old_element_id,
adaptor, equations, dg)
element_id += 1
skip = 2^ndims(mesh) - 1
else
# Copy old element data to new element container
@views u[:, .., element_id] .= old_u[:, .., old_element_id]
element_id += 1
end
end
# If everything is correct, we should have processed all elements.
@assert element_id==nelements(dg, cache) + 1 "element_id = $element_id, nelements(dg, cache) = $(nelements(dg, cache))"
@assert element_id==nelements(dg, cache_parabolic) + 1 "element_id = $element_id, nelements(dg, cache_parabolic) = $(nelements(dg, cache_parabolic))"
end # GC.@preserve old_u_ode
# Resize parabolic helper variables
resize!(viscous_container, equations, dg, cache)

# re-initialize interfaces container
@unpack interfaces = cache
resize!(interfaces, count_required_interfaces(mesh, leaf_cell_ids))
init_interfaces!(interfaces, elements, mesh)

@unpack interfaces = cache_parabolic
resize!(interfaces, count_required_interfaces(mesh, leaf_cell_ids))
init_interfaces!(interfaces, elements, mesh)

# re-initialize boundaries container
@unpack boundaries = cache
resize!(boundaries, count_required_boundaries(mesh, leaf_cell_ids))
init_boundaries!(boundaries, elements, mesh)

@unpack boundaries = cache_parabolic
resize!(boundaries, count_required_boundaries(mesh, leaf_cell_ids))
init_boundaries!(boundaries, elements, mesh)

# Sanity check
if isperiodic(mesh.tree)
@assert ninterfaces(interfaces)==1 * nelements(dg, cache) ("For 1D and periodic domains, the number of interfaces must be the same as the number of elements")
@assert ninterfaces(interfaces)==1 * nelements(dg, cache_parabolic) ("For 1D and periodic domains, the number of interfaces must be the same as the number of elements")
end

Expand Down