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

Feature: t8code as meshing backend #1426

Merged
merged 87 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
db1ea6b
Initial commit for the new feature using t8code as meshing backend.
May 5, 2023
2cac6c9
Delete t8code_2d_dgsem
jmark May 5, 2023
1bb2061
Added new examples and tests. Testing updates for T8code.jl.
May 17, 2023
ba920cd
Merge branch 'feature-t8code' of github.com:trixi-framework/Trixi.jl …
May 17, 2023
1cab250
Worked in the comments.
May 22, 2023
edf6a91
Merge branch 'main' into feature-t8code
jmark May 23, 2023
cdced17
Fixed spelling.
May 23, 2023
d02d32e
Update src/auxiliary/auxiliary.jl
jmark May 24, 2023
7c01df0
Added whitespace in Unions.
May 24, 2023
e6cd1ab
Adapted commented out code block reporting the no. of elements per le…
May 24, 2023
0abdcd9
Added dummy save mesh support for .
May 24, 2023
10ac87d
Added test .
May 24, 2023
349136a
Added to method signature.
May 24, 2023
3e47616
Deleted unnecessary comments.
May 24, 2023
fe6d874
Removed commented out tests.
May 24, 2023
d5d6298
Fixed Morton ordering bug in 2D at mortar interfaces.
May 25, 2023
9c0db6f
Disabled `save_solution` callbacks and added more tests.
May 25, 2023
1440f90
Added more tests.
May 26, 2023
85a34df
Merge branch 'main' into feature-t8code
jmark May 26, 2023
068558f
Updated code according to the review.
May 30, 2023
1fab9b9
Merge branch 'main' into feature-t8code
jmark May 30, 2023
6dcca7b
Merge branch 'main' into feature-t8code
jmark May 31, 2023
497f957
Update src/auxiliary/t8code.jl
jmark Jun 1, 2023
4a958c4
Update src/auxiliary/t8code.jl
jmark Jun 1, 2023
3d869b0
Update src/auxiliary/t8code.jl
jmark Jun 1, 2023
c04b0f0
Update src/auxiliary/t8code.jl
jmark Jun 1, 2023
5396b87
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
095fdbc
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
3222693
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
db52949
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
62cc2b6
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
3ec60f2
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
13169bf
Update src/solvers/dgsem_t8code/containers_2d.jl
jmark Jun 1, 2023
1eb3d4c
Update src/meshes/t8code_mesh.jl
jmark Jun 1, 2023
c3e3869
Code cleanup.
Jun 12, 2023
504b637
Merging.
Jun 12, 2023
25265e3
Updated to [email protected]
Jun 12, 2023
86b6fed
Fixing minor issues.
Jun 12, 2023
12dc4fe
Fixed typo.
Jun 12, 2023
8e118dc
Code cleanup.
Jun 12, 2023
eb3af26
Enabled `set_ghost` in examples.
Jun 13, 2023
0dd6725
Generalized type info in function signature.
Jun 13, 2023
7218b05
Added namespace qualifier.
Jun 13, 2023
aad6321
Updated comments.
Jun 13, 2023
3dea7a1
Refactored code and deleted lots of it.
Jun 13, 2023
518669b
Merge branch 'main' into feature-t8code
Jun 13, 2023
f6f67ad
Removed a copy operation.
Jun 13, 2023
dc74b89
Resolving merge conflicts.
Jun 19, 2023
c9f431d
Fixed some merging issues and formatting.
Jun 20, 2023
7c1357f
Merge branch 'main' into feature-t8code
Jun 20, 2023
27ecb8a
Merge branch 'main' into feature-t8code
jmark Jun 20, 2023
ced89df
Fixed spelling.
Jun 20, 2023
32b6711
Fixed spelling and changed assert macro.
Jun 20, 2023
c450680
Applied automatic formatting.
Jun 20, 2023
40df56f
Merge branch 'main' into feature-t8code
ranocha Jun 29, 2023
39cb7cc
Merge branch 'main' into feature-t8code
jmark Jul 11, 2023
d238db7
Backup.
Jul 11, 2023
6ac73cf
Removed superfluous outer constructor for T8codeMesh.
Jul 11, 2023
c40b650
Merge branch 'feature-t8code' of github.com:trixi-framework/Trixi.jl …
Jul 11, 2023
1e0fa0c
Added return statement for consistency.
Jul 11, 2023
0adfbe1
Fixed wrong indentation by autoformatter.
Jul 11, 2023
e42f36e
Added comments.
Jul 11, 2023
aedea64
Made sure an exception is thrown.
Jul 14, 2023
27da77e
Merge branch 'main' into feature-t8code
Jul 14, 2023
1456f1f
Changed flags for sc_init for t8code initialization.
Jul 19, 2023
3857cc3
Updated formatting.
Jul 19, 2023
83a5b81
Merge branch 'main' into feature-t8code
jmark Jul 19, 2023
df94655
Workaround for error about calling MPI routines after MPI has been fi…
Jul 20, 2023
a54377b
Merge branch 'feature-t8code' of github.com:trixi-framework/Trixi.jl …
Jul 20, 2023
40d45c9
Upped to T8code v0.4.1.
Jul 21, 2023
4fa4374
Merge branch 'main' into feature-t8code
ranocha Jul 22, 2023
6074e87
Added mpi_finailize_hook for proper memory cleanup.
Jul 24, 2023
766abc9
Added t8code to test_threaded.jl
Jul 24, 2023
99b1282
Merge branch 'feature-t8code' of github.com:trixi-framework/Trixi.jl …
Jul 24, 2023
2891e6f
Merge branch 'main' into feature-t8code
Jul 24, 2023
0d3af2a
Merge branch 'main' of github.com:trixi-framework/Trixi.jl into featu…
Jul 25, 2023
032f69e
Added a `save_mesh_file` call in order to satisfy code coverage.
Jul 25, 2023
104df24
Merge branch 'main' into feature-t8code
Jul 25, 2023
dde2802
Improved finalizer logic for T8coeMesh.
Jul 25, 2023
c9c1c64
Refined code.
Jul 25, 2023
33fced5
Restructured to do blocks.
Jul 25, 2023
b2d97a4
Moved save_mesh_file call to test file.
Jul 25, 2023
19950c8
Fixed spelling error.
Jul 25, 2023
3047e66
Merge branch 'main' into feature-t8code
ranocha Jul 26, 2023
9435b34
Merge branch 'main' into feature-t8code
ranocha Jul 26, 2023
12a20e5
Made sc_finalize optional.
Jul 26, 2023
7f9b0e2
Fixed spelling.
Jul 26, 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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StrideArrays = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240"
T8code = "d0cc0030-9a40-4274-8435-baadcfd54fa1"
ranocha marked this conversation as resolved.
Show resolved Hide resolved
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3"
Expand Down Expand Up @@ -73,6 +74,7 @@ StaticArrays = "1"
StrideArrays = "0.1.18"
StructArrays = "0.6"
SummationByPartsOperators = "0.5.25"
T8code = "0.2.0"
TimerOutputs = "0.5"
Triangulate = "2.0"
TriplotBase = "0.1"
Expand Down
66 changes: 66 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# The same setup as tree_2d_dgsem/elixir_advection_basic.jl
# to verify the StructuredMesh implementation against TreeMesh

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max = ( 1.0, 1.0) # maximum coordinates (max(x), max(y))

mapping = Trixi.coordinates2mapping(coordinates_min, coordinates_max)

trees_per_dimension = (8, 8)

# Create T8codeMesh with 8 x 8 trees and 16 x 16 elements
mesh = T8codeMesh(trees_per_dimension, polydeg=3,
mapping=mapping,
initial_refinement_level=1)

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, solver)


###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize(semi, (0.0, 1.0));

# 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=100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
# save_solution = SaveSolutionCallback(interval=100,
# solution_variables=cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl=1.6)

# 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)
callbacks = CallbackSet(summary_callback, analysis_callback, 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, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep=false, callback=callbacks);

# Print the timer summary
summary_callback()
115 changes: 115 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_nonconforming_flag.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

using OrdinaryDiffEq
using Trixi


###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

# Create DG solver with polynomial degree = 4 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg=4, surface_flux=flux_lax_friedrichs)

# Deformed rectangle that looks like a waving flag,
# lower and upper faces are sinus curves, left and right are vertical lines.
f1(s) = SVector(-1.0, s - 1.0)
f2(s) = SVector( 1.0, s + 1.0)
f3(s) = SVector(s, -1.0 + sin(0.5 * pi * s))
f4(s) = SVector(s, 1.0 + sin(0.5 * pi * s))

faces = (f1, f2, f3, f4)
mapping = Trixi.transfinite_mapping(faces)

# Create P4estMesh with 3 x 2 trees and 6 x 4 elements,
# approximate the geometry with a smaller polydeg for testing.
trees_per_dimension = (3, 2)
mesh = T8codeMesh(trees_per_dimension, polydeg=3,
mapping=mapping,
initial_refinement_level=1)

function adapt_callback(forest,
forest_from,
which_tree,
lelement_id,
ts,
is_family,
num_elements,
elements_ptr) :: Cint

vertex = Vector{Cdouble}(undef,3)

elements = unsafe_wrap(Array, elements_ptr, num_elements)

Trixi.t8_element_vertex_reference_coords(ts, elements[1], 0, pointer(vertex))

level = Trixi.t8_element_level(ts,elements[1])

# TODO: Make this condition more general.
if vertex[1] < 1e-8 && vertex[2] < 1e-8 && level < 4
# return true (refine)
return 1
else
# return false (don't refine)
return 0
end
end

@Trixi.T8_ASSERT(Trixi.t8_forest_is_committed(mesh.forest) != 0);

# Init new forest.
new_forest_ref = Ref{Trixi.t8_forest_t}()
Trixi.t8_forest_init(new_forest_ref);
new_forest = new_forest_ref[]

let set_from = C_NULL, recursive = 1, set_for_coarsening = 0, no_repartition = 0
Trixi.t8_forest_set_user_data(new_forest, C_NULL)
Trixi.t8_forest_set_adapt(new_forest, mesh.forest, @Trixi.t8_adapt_callback(adapt_callback), recursive)
Trixi.t8_forest_set_balance(new_forest, set_from, no_repartition)
Trixi.t8_forest_set_partition(new_forest, set_from, set_for_coarsening)
# t8_forest_set_ghost(new_forest, 1, T8_GHOST_FACES);
Trixi.t8_forest_commit(new_forest)
end

mesh.forest = new_forest

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, solver)


###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 0.2
ode = semidiscretize(semi, (0.0, 0.2));

# 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=100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
# save_solution = SaveSolutionCallback(interval=100,
# solution_variables=cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl=1.6)

# 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)
callbacks = CallbackSet(summary_callback, analysis_callback, 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, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep=false, callback=callbacks);

# Print the timer summary
summary_callback()
87 changes: 87 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Downloads: download
using OrdinaryDiffEq
using Trixi

###############################################################################
# Semidiscretization of the linear advection equation.

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

initial_condition = initial_condition_convergence_test

boundary_condition = BoundaryConditionDirichlet(initial_condition)
boundary_conditions = Dict(
:all => boundary_condition
)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux.
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)

# Deformed rectangle that looks like a waving flag,
# lower and upper faces are sinus curves, left and right are vertical lines.
f1(s) = SVector(-1.0, s - 1.0)
f2(s) = SVector( 1.0, s + 1.0)
f3(s) = SVector(s, -1.0 + sin(0.5 * pi * s))
f4(s) = SVector(s, 1.0 + sin(0.5 * pi * s))
faces = (f1, f2, f3, f4)

Trixi.validate_faces(faces)
mapping_flag = Trixi.transfinite_mapping(faces)

# Unstructured mesh with 24 cells of the square domain [-1, 1]^n.
mesh_file = joinpath(@__DIR__, "square_unstructured_2.inp")
isfile(mesh_file) || download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp",
mesh_file)

# INP mesh files are only support by p4est. Hence, we
# create a p4est connecvity object first from which
# we can create a t8code mesh.
conn = Trixi.read_inp_p4est(mesh_file,Val(2))

mesh = T8codeMesh{2}(conn, polydeg=3,
mapping=mapping_flag,
initial_refinement_level=2)

# A semidiscretization collects data structures and functions for the spatial discretization.
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, boundary_conditions=boundary_conditions)

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 0.2.
tspan = (0.0, 0.2)
ode = semidiscretize(semi, tspan)

# 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=100)

# The SaveSolutionCallback allows to save the solution to a file in regular
# intervals.
# save_solution = SaveSolutionCallback(interval=100,
# solution_variables=cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each
# time step.
stepsize_callback = StepsizeCallback(cfl=1.4)

# 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)
callbacks = CallbackSet(summary_callback, analysis_callback, 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, # Solve needs some value here but it will be overwritten by the stepsize_callback.
save_everystep=false, callback=callbacks);

# Print the timer summary.
summary_callback()
Loading