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

Add StructuredMeshView as proxy between solver and actual StructuredMesh #1624

Merged
merged 93 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
a291620
Add StructuredMeshView as proxy between solver and actual StructuredMesh
sloede Sep 6, 2023
f3d2056
Enable StructuredMeshView on submesh
sloede Sep 6, 2023
37b9242
Attempt to using coupled with meshviews.
SimonCan Sep 7, 2023
43e41e6
Merge branch 'main' into msl/structuredmesh-view
SimonCan Oct 20, 2023
f0684f9
Update structured_mesh_view.jl
SimonCan Oct 20, 2023
4a3062f
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 9, 2023
c555b18
Applied autoformatter on smview elixir.
SimonCan Nov 9, 2023
11645a9
Applied autoformatter on meshview.
SimonCan Nov 9, 2023
7898405
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 10, 2023
548348c
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 13, 2023
125ee34
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 20, 2023
7e5d65e
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 21, 2023
9f46a12
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 21, 2023
de3f8c3
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 22, 2023
a9caff8
Corected minor typo with StructuredMeshView.
SimonCan Nov 22, 2023
1c7a833
Corrected x-boundaries for smview example elixir.
SimonCan Nov 22, 2023
607b623
Removed parent's periodicity for smview.
SimonCan Nov 22, 2023
bc2303a
Removed redundant and problematic redifintion of StructuredMeshView f…
SimonCan Nov 22, 2023
d4624f7
Applied auto formatter on files affected by the structured mesh view.
SimonCan Nov 23, 2023
6f4d21e
Applied autoforatter.
SimonCan Nov 24, 2023
e4f6035
Merge branch 'main' into msl/structuredmesh-view
SimonCan Nov 24, 2023
cc3eb28
Merge branch 'main' into msl/structuredmesh-view
SimonCan Dec 4, 2023
d6d0f11
Added entries for meshview IO.
SimonCan Dec 6, 2023
6291a67
Merge branch 'msl/structuredmesh-view' of github.com:trixi-framework/…
SimonCan Dec 6, 2023
a64bbc2
Added structuresd mesh view to parametric types.
SimonCan Dec 7, 2023
0b56f47
Merge branch 'main' into msl/structuredmesh-view
SimonCan Dec 8, 2023
076fd24
Added unctionality of writing out mesh files for StructuredMeshView
SimonCan Dec 14, 2023
67b7761
Merge branch 'main' into msl/structuredmesh-view
SimonCan Jan 4, 2024
65d0413
Added temptative code for dynamically changing mesh view sizes.
SimonCan Jan 5, 2024
c5ba740
Merge branch 'msl/structuredmesh-view' of github.com:trixi-framework/…
SimonCan Jan 5, 2024
798ea22
Applied autoformatter.
SimonCan Jan 11, 2024
3ff18d5
Merge branch 'main' into msl/structuredmesh-view
SimonCan Feb 29, 2024
5b9bcc3
Corrected the calculation of the coordinate mapping for mesh views.
iomsn Feb 29, 2024
0be8c08
Merge branch 'msl/structuredmesh-view' of https://github.com/trixi-fr…
iomsn Feb 29, 2024
f0ab06d
Added cells_per_dimension to the StructuredMeshView.
iomsn Mar 1, 2024
82b2014
Added StructuredMeshView to max_dt clculations.
iomsn Mar 7, 2024
5ebe6e9
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 7, 2024
c6a318e
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 11, 2024
51eb64a
Applied autoformatter.
iomsn Mar 11, 2024
619382a
Applied autoformatter.
iomsn Mar 11, 2024
5ecf188
Cleaned up meshview coupled example.
iomsn Mar 11, 2024
781a164
Added 2d structured mesh views to periodicity checks.
iomsn Mar 11, 2024
4bc13bf
Cleaned up coupled strucutred mesh view example so that it
iomsn Mar 11, 2024
2d74615
Added 2d structured mesh view to the tests.
iomsn Mar 11, 2024
7e32f7a
Added analysis_interval variable.
iomsn Mar 11, 2024
ad94584
Applied updated autoformatter.
iomsn Mar 12, 2024
3c7265e
Removed unused lines of code.
iomsn Mar 13, 2024
e977aea
Added explanatory comments.
iomsn Mar 13, 2024
40e1acb
Removed unused code.
iomsn Mar 13, 2024
7aaa3df
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 15, 2024
0aac5df
Update examples/structured_2d_dgsem/elixir_advection_smview.jl
SimonCan Mar 18, 2024
cb22c76
Update examples/structured_2d_dgsem/elixir_advection_smview.jl
SimonCan Mar 18, 2024
48716e3
Update examples/structured_2d_dgsem/elixir_advection_smview.jl
SimonCan Mar 18, 2024
e34e01d
Update src/meshes/mesh_io.jl
SimonCan Mar 18, 2024
70435c0
Update src/meshes/structured_mesh_view.jl
SimonCan Mar 18, 2024
4f6a9d2
Corrected comment on solver.
iomsn Mar 18, 2024
d313117
Changed order of imported meshes.
iomsn Mar 18, 2024
8ebecea
Update src/meshes/structured_mesh_view.jl
SimonCan Mar 18, 2024
7b2f0a3
Added comment about coupling interface indexing.
iomsn Mar 18, 2024
78dbcf3
Merge branch 'msl/structuredmesh-view' of https://github.com/trixi-fr…
iomsn Mar 18, 2024
b68b6c5
Applied autoformatter.
iomsn Mar 18, 2024
8d19521
Update src/meshes/structured_mesh_view.jl
SimonCan Mar 19, 2024
7e0ec93
Renamed index_min and index_max to indices_min and indices_max.
iomsn Mar 19, 2024
92c682d
Removed relative tolerance from meshview test.
iomsn Mar 19, 2024
dc93b0e
Removed further relative tolerance as it is not needed.
iomsn Mar 19, 2024
e141342
Update examples/structured_2d_dgsem/elixir_advection_smview.jl
SimonCan Mar 19, 2024
062d598
Fixed typo on parent mesh generation.
iomsn Mar 19, 2024
824fcc6
Applied autoformatter.
SimonCan Mar 21, 2024
6cc3cb8
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 21, 2024
4579576
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 22, 2024
6b31f82
Merge branch 'main' into msl/structuredmesh-view
SimonCan Mar 29, 2024
4333186
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 2, 2024
ce55cfd
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 3, 2024
09750d4
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 5, 2024
4a2c26e
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 15, 2024
59c14c3
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 16, 2024
6afd4b9
Updated test results for elixir_advection_smview.jl.
SimonCan Apr 16, 2024
54a10e8
Merge branch 'main' into msl/structuredmesh-view
sloede Apr 23, 2024
541f2c6
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 26, 2024
96fbb2b
Update src/meshes/mesh_io.jl
SimonCan Apr 29, 2024
c529e85
Update src/meshes/mesh_io.jl
SimonCan Apr 29, 2024
cbdf685
Renamed elixir_advection_smview.jl to elixir_advection_meshview.jl
SimonCan Apr 29, 2024
56394d2
Renamed elixir_advection_smview.jl to elixir_advection_meshview.jl.
SimonCan Apr 29, 2024
bf8441e
Merge branch 'msl/structuredmesh-view' of https://github.com/trixi-fr…
SimonCan Apr 29, 2024
282dc9b
Moved save_mesh_file function for StructuredMeshView.
SimonCan Apr 29, 2024
29a422b
Update src/meshes/structured_mesh_view.jl
SimonCan Apr 29, 2024
30bb10d
Removed redundant check for structured mesh views.
SimonCan Apr 29, 2024
b085b06
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 29, 2024
688b0af
Merge branch 'main' into msl/structuredmesh-view
SimonCan Apr 30, 2024
bca7b93
Merge branch 'main' into msl/structuredmesh-view
SimonCan May 2, 2024
71d1512
Merge branch 'main' into msl/structuredmesh-view
SimonCan May 2, 2024
c561bb3
Merge branch 'main' into msl/structuredmesh-view
SimonCan May 8, 2024
169dd1c
Merge branch 'main' into msl/structuredmesh-view
sloede May 9, 2024
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
122 changes: 122 additions & 0 deletions examples/structured_2d_dgsem/elixir_advection_meshview.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# Coupled semidiscretization of two linear advection systems using converter functions
# and mesh views for the semidiscretizations. First we define a parent mesh
# for the entire physical domain, then we define the two mesh views on this parent.
#
# In this elixir, we have a square domain that is divided into left and right subdomains.
# On each half of the domain, a completely independent `SemidiscretizationHyperbolic`
# is created for the linear advection equations. The two systems are coupled in the
# x-direction.
# For a high-level overview, see also the figure below:
#
# (-1, 1) ( 1, 1)
# ┌────────────────────┬────────────────────┐
# │ ↑ periodic ↑ │ ↑ periodic ↑ │
# │ │ │
# │ ========= │ ========= │
# │ system #1 │ system #2 │
# │ ========= │ ========= │
# │ │ │
# │<-- coupled │<-- coupled │
# │ coupled -->│ coupled -->│
# │ │ │
# │ ↓ periodic ↓ │ ↓ periodic ↓ │
# └────────────────────┴────────────────────┘
# (-1, -1) ( 1, -1)

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

# Create DG solver with polynomial degree = 3
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

# Domain size of the parent mesh.
coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.0)

# Cell dimensions of the parent mesh.
cells_per_dimension = (16, 16)

# Create parent mesh with 16 x 16 elements
parent_mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

# Create the two mesh views, each of which takes half of the parent mesh.
mesh1 = StructuredMeshView(parent_mesh; indices_min = (1, 1), indices_max = (8, 16))
mesh2 = StructuredMeshView(parent_mesh; indices_min = (9, 1), indices_max = (16, 16))

# The coupling function is simply the identity, as we are dealing with two identical systems.
coupling_function = (x, u, equations_other, equations_own) -> u

# Define the coupled boundary conditions
# The indices (:end, :i_forward) and (:begin, :i_forward) denote the interface indexing.
# For a system with coupling in x and y see examples/structured_2d_dgsem/elixir_advection_coupled.jl.
boundary_conditions1 = (
# Connect left boundary with right boundary of left mesh
x_neg = BoundaryConditionCoupled(2, (:end, :i_forward), Float64,
coupling_function),
x_pos = BoundaryConditionCoupled(2, (:begin, :i_forward), Float64,
coupling_function),
y_neg = boundary_condition_periodic,
y_pos = boundary_condition_periodic)
boundary_conditions2 = (
# Connect left boundary with right boundary of left mesh
x_neg = BoundaryConditionCoupled(1, (:end, :i_forward), Float64,
coupling_function),
x_pos = BoundaryConditionCoupled(1, (:begin, :i_forward), Float64,
coupling_function),
y_neg = boundary_condition_periodic,
y_pos = boundary_condition_periodic)

# A semidiscretization collects data structures and functions for the spatial discretization
semi1 = SemidiscretizationHyperbolic(mesh1, equations, initial_condition_convergence_test,
solver,
boundary_conditions = boundary_conditions1)
semi2 = SemidiscretizationHyperbolic(mesh2, equations, initial_condition_convergence_test,
solver,
boundary_conditions = boundary_conditions2)
semi = SemidiscretizationCoupled(semi1, semi2)

###############################################################################
# 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_callback1 = AnalysisCallback(semi1, interval = 100)
analysis_callback2 = AnalysisCallback(semi2, interval = 100)
analysis_callback = AnalysisCallbackCoupled(semi, analysis_callback1, analysis_callback2)

analysis_interval = 100
alive_callback = AliveCallback(analysis_interval = analysis_interval)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
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)

###############################################################################
# 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 = 5.0e-2, # 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()
3 changes: 2 additions & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ export entropy, energy_total, energy_kinetic, energy_internal, energy_magnetic,
export lake_at_rest_error
export ncomponents, eachcomponent

export TreeMesh, StructuredMesh, UnstructuredMesh2D, P4estMesh, T8codeMesh
export TreeMesh, StructuredMesh, StructuredMeshView, UnstructuredMesh2D, P4estMesh,
T8codeMesh

export DG,
DGSEM, LobattoLegendreBasis,
Expand Down
22 changes: 13 additions & 9 deletions src/callbacks_step/analysis_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function create_cache_analysis(analyzer, mesh::TreeMesh{2},
end

function create_cache_analysis(analyzer,
mesh::Union{StructuredMesh{2}, UnstructuredMesh2D,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D,
P4estMesh{2}, T8codeMesh{2}},
equations, dg::DG, cache,
RealT, uEltype)
Expand Down Expand Up @@ -107,8 +108,9 @@ function calc_error_norms(func, u, t, analyzer,
end

function calc_error_norms(func, u, t, analyzer,
mesh::Union{StructuredMesh{2}, UnstructuredMesh2D,
P4estMesh{2}, T8codeMesh{2}}, equations,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D, P4estMesh{2}, T8codeMesh{2}},
equations,
initial_condition, dg::DGSEM, cache, cache_analysis)
@unpack vandermonde, weights = analyzer
@unpack node_coordinates, inverse_jacobian = cache.elements
Expand Down Expand Up @@ -175,8 +177,10 @@ function integrate_via_indices(func::Func, u,
end

function integrate_via_indices(func::Func, u,
mesh::Union{StructuredMesh{2}, UnstructuredMesh2D,
P4estMesh{2}, T8codeMesh{2}}, equations,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D, P4estMesh{2},
T8codeMesh{2}},
equations,
dg::DGSEM, cache, args...; normalize = true) where {Func}
@unpack weights = dg.basis

Expand All @@ -203,8 +207,8 @@ function integrate_via_indices(func::Func, u,
end

function integrate(func::Func, u,
mesh::Union{TreeMesh{2}, StructuredMesh{2}, UnstructuredMesh2D,
P4estMesh{2}, T8codeMesh{2}},
mesh::Union{TreeMesh{2}, StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D, P4estMesh{2}, T8codeMesh{2}},
equations, dg::DG, cache; normalize = true) where {Func}
integrate_via_indices(u, mesh, equations, dg, cache;
normalize = normalize) do u, i, j, element, equations, dg
Expand Down Expand Up @@ -232,8 +236,8 @@ function integrate(func::Func, u,
end

function analyze(::typeof(entropy_timederivative), du, u, t,
mesh::Union{TreeMesh{2}, StructuredMesh{2}, UnstructuredMesh2D,
P4estMesh{2}, T8codeMesh{2}},
mesh::Union{TreeMesh{2}, StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D, P4estMesh{2}, T8codeMesh{2}},
equations, dg::DG, cache)
# Calculate ∫(∂S/∂u ⋅ ∂u/∂t)dΩ
integrate_via_indices(u, mesh, equations, dg, cache,
Expand Down
1 change: 1 addition & 0 deletions src/callbacks_step/save_solution_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

function save_solution_file(u, time, dt, timestep,
mesh::Union{SerialTreeMesh, StructuredMesh,
StructuredMeshView,
UnstructuredMesh2D, SerialP4estMesh,
SerialT8codeMesh},
equations, dg::DG, cache,
Expand Down
4 changes: 2 additions & 2 deletions src/callbacks_step/stepsize_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end

function max_dt(u, t,
mesh::Union{StructuredMesh{2}, UnstructuredMesh2D, P4estMesh{2},
T8codeMesh{2}},
T8codeMesh{2}, StructuredMeshView{2}},
constant_speed::False, equations, dg::DG, cache)
# to avoid a division by zero if the speed vanishes everywhere,
# e.g. for steady-state linear advection
Expand Down Expand Up @@ -113,7 +113,7 @@ end

function max_dt(u, t,
mesh::Union{StructuredMesh{2}, UnstructuredMesh2D, P4estMesh{2},
T8codeMesh{2}},
T8codeMesh{2}, StructuredMeshView{2}},
constant_speed::True, equations, dg::DG, cache)
@unpack contravariant_vectors, inverse_jacobian = cache.elements

Expand Down
7 changes: 5 additions & 2 deletions src/meshes/mesh_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ end
# of the mesh, like its size and the type of boundary mapping function.
# Then, within Trixi2Vtk, the StructuredMesh and its node coordinates are reconstructured from
# these attributes for plotting purposes
function save_mesh_file(mesh::StructuredMesh, output_directory; system = "")
# Note: the `timestep` argument is needed for compatibility with the method for
# `StructuredMeshView`
function save_mesh_file(mesh::StructuredMesh, output_directory; system = "",
timestep = 0)
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
# Create output directory (if it does not exist)
mkpath(output_directory)

Expand Down Expand Up @@ -256,7 +259,7 @@ function load_mesh_serial(mesh_file::AbstractString; n_cells_max, RealT)
end
mesh = TreeMesh(SerialTree{ndims}, max(n_cells_max, capacity))
load_mesh!(mesh, mesh_file)
elseif mesh_type == "StructuredMesh"
elseif mesh_type in ("StructuredMesh", "StructuredMeshView")
size_, mapping_as_string = h5open(mesh_file, "r") do file
return read(attributes(file)["size"]),
read(attributes(file)["mapping"])
Expand Down
1 change: 1 addition & 0 deletions src/meshes/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

include("tree_mesh.jl")
include("structured_mesh.jl")
include("structured_mesh_view.jl")
include("surface_interpolant.jl")
include("unstructured_mesh.jl")
include("face_interpolant.jl")
Expand Down
132 changes: 132 additions & 0 deletions src/meshes/structured_mesh_view.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin
#! format: noindent

"""
StructuredMeshView{NDIMS, RealT <: Real} <: AbstractMesh{NDIMS}

A view on a structured curved mesh.
"""
mutable struct StructuredMeshView{NDIMS, RealT <: Real} <: AbstractMesh{NDIMS}
parent::StructuredMesh{NDIMS, RealT}
cells_per_dimension::NTuple{NDIMS, Int}
mapping::Any # Not relevant for performance
mapping_as_string::String
current_filename::String
indices_min::NTuple{NDIMS, Int}
indices_max::NTuple{NDIMS, Int}
unsaved_changes::Bool
end

"""
StructuredMeshView(parent; indices_min, indices_max)

Create a StructuredMeshView on a StructuredMesh parent.

# Arguments
- `parent`: the parent StructuredMesh.
- `indices_min`: starting indices of the parent mesh.
- `indices_max`: ending indices of the parent mesh.
"""
function StructuredMeshView(parent::StructuredMesh{NDIMS, RealT};
indices_min = ntuple(_ -> 1, Val(NDIMS)),
indices_max = size(parent)) where {NDIMS, RealT}
@assert indices_min <= indices_max
@assert all(indices_min .> 0)
@assert indices_max <= size(parent)

cells_per_dimension = indices_max .- indices_min .+ 1

# Compute cell sizes `deltas`
deltas = (parent.mapping.coordinates_max .- parent.mapping.coordinates_min) ./
parent.cells_per_dimension
# Calculate the domain boundaries.
coordinates_min = parent.mapping.coordinates_min .+ deltas .* (indices_min .- 1)
coordinates_max = parent.mapping.coordinates_min .+ deltas .* indices_max
mapping = coordinates2mapping(coordinates_min, coordinates_max)
mapping_as_string = """
coordinates_min = $coordinates_min
coordinates_max = $coordinates_max
mapping = coordinates2mapping(coordinates_min, coordinates_max)
"""

return StructuredMeshView{NDIMS, RealT}(parent, cells_per_dimension, mapping,
mapping_as_string,
parent.current_filename,
indices_min, indices_max,
parent.unsaved_changes)
end

# Check if mesh is periodic
function isperiodic(mesh::StructuredMeshView)
@unpack parent = mesh
return isperiodic(parent) && size(parent) == size(mesh)
end

function isperiodic(mesh::StructuredMeshView, dimension)
@unpack parent, indices_min, indices_max = mesh
return (isperiodic(parent, dimension) &&
indices_min[dimension] == 1 &&
indices_max[dimension] == size(parent, dimension))
end

@inline Base.ndims(::StructuredMeshView{NDIMS}) where {NDIMS} = NDIMS
@inline Base.real(::StructuredMeshView{NDIMS, RealT}) where {NDIMS, RealT} = RealT
function Base.size(mesh::StructuredMeshView)
@unpack indices_min, indices_max = mesh
return indices_max .- indices_min .+ 1
end
function Base.size(mesh::StructuredMeshView, i)
@unpack indices_min, indices_max = mesh
return indices_max[i] - indices_min[i] + 1
end
Base.axes(mesh::StructuredMeshView) = map(Base.OneTo, size(mesh))
Base.axes(mesh::StructuredMeshView, i) = Base.OneTo(size(mesh, i))

function calc_node_coordinates!(node_coordinates, element,
cell_x, cell_y, mapping,
mesh::StructuredMeshView{2},
basis)
@unpack nodes = basis

# Get cell length in reference mesh
dx = 2 / size(mesh, 1)
dy = 2 / size(mesh, 2)

# Calculate node coordinates of reference mesh
cell_x_offset = -1 + (cell_x - 1) * dx + dx / 2
cell_y_offset = -1 + (cell_y - 1) * dy + dy / 2

for j in eachnode(basis), i in eachnode(basis)
# node_coordinates are the mapped reference node_coordinates
node_coordinates[:, i, j, element] .= mapping(cell_x_offset + dx / 2 * nodes[i],
cell_y_offset + dy / 2 * nodes[j])
end
end

# Does not save the mesh itself to an HDF5 file. Instead saves important attributes
# of the mesh, like its size and the type of boundary mapping function.
# Then, within Trixi2Vtk, the StructuredMesh and its node coordinates are reconstructured from
# these attributes for plotting purposes.
function save_mesh_file(mesh::StructuredMeshView, output_directory; system = "",
timestep = 0)
# Create output directory (if it does not exist)
mkpath(output_directory)

filename = joinpath(output_directory, @sprintf("mesh_%s_%06d.h5", system, timestep))

# Open file (clobber existing content)
h5open(filename, "w") do file
# Add context information as attributes
attributes(file)["mesh_type"] = get_name(mesh)
attributes(file)["ndims"] = ndims(mesh)
attributes(file)["size"] = collect(size(mesh))
attributes(file)["mapping"] = mesh.mapping_as_string
end

return filename
end
end # @muladd
Loading
Loading