-
Notifications
You must be signed in to change notification settings - Fork 114
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: DGMultiMesh from t8code forest (prototype) #2270
base: main
Are you sure you want to change the base?
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
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.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 175 in 1aa2762
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 177 to 178 in 1aa2762
EToV = zeros(Int, num_elements, num_corners) | |
VXYZ = Tuple(Vector{Float64}() for idim = 1:ndims) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 180 to 183 in 1aa2762
etov = zeros(Int, num_corners) | |
min_range = vxyz |> minimum | |
max_range = vxyz |> maximum |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 185 to 186 in 1aa2762
num_bins = 1e9 | |
inverse_bin_size = num_bins / (max_range - min_range) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 188 in 1aa2762
hashed_vertices = Dict{Tuple{Tuple(UInt128 for idim = 1:ndims)...},Int}() |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 190 to 193 in 1aa2762
cumulative_index = 0 | |
for ielem = 1:num_elements | |
for ivert = 1:num_corners | |
hashed_xyz = Tuple(trunc(UInt128, (vxyz[idim,ivert,ielem] - min_range + 0.5) * inverse_bin_size) for idim in 1:ndims) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 195 to 205 in 1aa2762
if haskey(hashed_vertices, hashed_xyz) | |
index = hashed_vertices[hashed_xyz] | |
else | |
index = cumulative_index += 1 | |
hashed_vertices[hashed_xyz] = index | |
for idim = 1:ndims | |
push!(VXYZ[idim], vxyz[idim,ivert,ielem]) | |
end | |
end | |
etov[ivert] = index | |
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 207 to 208 in 1aa2762
EToV[ielem,:] = t8code2startupdg(eclass, etov) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 210 to 211 in 1aa2762
return VXYZ, EToV | |
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 213 in 1aa2762
function compute_coordinates(forest::Ptr{t8_forest}, rd::RefElemData, md::MeshData) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 215 to 278 in 1aa2762
if rd.element_type isa StartUpDG.Tri | |
e_rst = [[ 1.0, 0.0, 0.0 ], | |
[ 1.0, 1.0, 0.0 ], | |
[ 0.0, 0.0, 0.0 ]] | |
elseif rd.element_type isa StartUpDG.Quad | |
e_rst = [[ 1.0, 0.0, 0.0 ], | |
[ 0.0, 1.0, 0.0 ], | |
[ 0.0, 0.0, 0.0 ]] | |
elseif rd.element_type isa StartUpDG.Tet | |
e_rst = [[ 1.0, 0.0, 0.0 ], | |
[ 1.0, 0.0, 1.0 ], | |
[ 1.0, 1.0, 1.0 ]] | |
elseif rd.element_type isa StartUpDG.Wedge | |
e_rst = [[ 1.0, 0.0, 0.0 ], | |
[ 1.0, 1.0, 0.0 ], | |
[ 0.0, 0.0, 1.0 ]] | |
elseif rd.element_type isa StartUpDG.Hex | |
e_rst = [[ 1.0, 0.0, 0.0 ], | |
[ 0.0, 1.0, 0.0 ], | |
[ 0.0, 0.0, 1.0 ]] | |
else | |
@error element_type | |
end | |
ndims = length(md.xyz) | |
xyz = tuple([similar(md.x) for _ = 1:ndims]...) | |
num_local_trees = t8_forest_get_num_local_trees(forest) | |
current_element = 1 | |
for itree = 0:num_local_trees-1 | |
tree_class = t8_forest_get_tree_class(forest, itree) | |
eclass_scheme = t8_forest_get_eclass_scheme(forest, tree_class) | |
eclass = t8_forest_get_eclass(forest, itree) | |
num_elements_in_tree = t8_forest_get_tree_num_elements(forest, itree) | |
for ielement = 0:num_elements_in_tree-1 | |
element = t8_forest_get_element_in_tree(forest, itree, ielement) | |
num_corners = t8_element_num_corners(eclass_scheme, element) | |
verts = zeros(3,num_corners) | |
for ivert in 1:num_corners | |
t8_forest_element_coordinate(forest, itree, element, ivert-1, @view(verts[:,ivert])) | |
end | |
_, do_perm = correct_negative_volume(eclass, verts) | |
if do_perm | |
perm = [2,1,3] | |
else | |
perm = [1,2,3] | |
end | |
for i = 1:length(rd.r) | |
ref_coords = zeros(3) | |
out_coords = Vector{Cdouble}(undef,3) | |
for iref = 1:ndims | |
rst = 0.5*(1.0 + rd.rst[perm[iref]][i]) | |
ref_coords += rst*e_rst[iref] | |
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 280 in 1aa2762
t8_forest_element_from_ref_coords(forest, itree, element, pointer(ref_coords), 1, pointer(out_coords)) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Lines 282 to 285 in 1aa2762
for idim = 1:ndims | |
xyz[idim][i,current_element] = out_coords[idim] | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 287 in 1aa2762
current_element += 1 |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 289 in 1aa2762
end |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 291 in 1aa2762
return xyz |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/meshes/dgmulti_t8code.jl
Line 304 in 1aa2762
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/dg.jl
Lines 489 to 518 in 1aa2762
num_faces_total = num_faces * md.num_elements | |
# This function was originally defined as | |
# `reshape_by_face(u) = reshape(view(u, :), num_pts_per_face, num_faces_total)`. | |
# This results in allocations due to https://github.com/JuliaLang/julia/issues/36313. | |
# To avoid allocations, we use Tim Holy's suggestion: | |
# https://github.com/JuliaLang/julia/issues/36313#issuecomment-782336300. | |
reshape_by_face(u) = Base.ReshapedArray(u, (num_pts_per_face, num_faces_total), ()) | |
u_face_values = reshape_by_face(u_face_values) | |
flux_face_values = reshape_by_face(flux_face_values) | |
Jf = reshape_by_face(Jf) | |
nxyzJ, xyzf = reshape_by_face.(nxyzJ), reshape_by_face.(xyzf) # broadcast over nxyzJ::NTuple{NDIMS,Matrix} | |
# loop through boundary faces, which correspond to columns of reshaped u_face_values, ... | |
for i in mesh.boundary_faces[boundary_key] | |
for i in Base.OneTo(num_pts_per_face) | |
face_normal = SVector{NDIMS}(getindex.(nxyzJ, i)) / Jf[i] | |
face_coordinates = SVector{NDIMS}(getindex.(xyzf, i)) | |
flux_face_values[i] = boundary_condition(u_face_values[i], | |
face_normal, face_coordinates, | |
t, | |
surface_flux, equations) * | |
Jf[i] | |
end | |
end | |
elseif mesh.boundary_faces_type == :nodes | |
for i in mesh.boundary_faces[boundary_key] | |
face_normal = SVector{NDIMS}(getindex.(nxyzJ, i)) / Jf[i] | |
face_coordinates = SVector{NDIMS}(getindex.(xyzf, i)) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/dg.jl
Lines 520 to 528 in 1aa2762
face_normal, face_coordinates, | |
t, | |
surface_flux, equations) | |
flux_face_values[i] = temp_f * Jf[i] | |
end | |
else | |
error("Unknown boundary_faces type.") | |
end | |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/types.jl
Line 441 in 1aa2762
function DGMultiMesh(dg::DGMulti, cmesh::Ptr{t8_cmesh}; initial_refinement_level = 0, is_on_boundary::Dict{Symbol, <:Function} = Dict()) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/types.jl
Line 444 in 1aa2762
forest = t8_forest_new_uniform(cmesh, scheme, initial_refinement_level, do_face_ghost, |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/types.jl
Line 454 in 1aa2762
mesh = DGMultiMesh(dg,GeometricTermsType(Curved(), dg), md, boundary_nodes) |
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/src/solvers/dgmulti/types.jl
Line 459 in 1aa2762
[JuliaFormatter] reported by reviewdog 🐶
Trixi.jl/test/test_dgmulti_3d.jl
Line 452 in 1aa2762
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2270 +/- ##
==========================================
- Coverage 96.42% 96.18% -0.24%
==========================================
Files 490 494 +4
Lines 39426 39915 +489
==========================================
+ Hits 38015 38392 +377
- Misses 1411 1523 +112
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This PR adds routines to build a
DGMultiMesh
from a t8code forest. It is a prototype implementation. It is not particular performant, robust and only supports conformal meshes with one element type (no hybrid meshes, no mortar interfaces).This is a follow-up PR to #2259.