Skip to content

Commit

Permalink
Renamed index_min and index_max to indices_min and indices_max.
Browse files Browse the repository at this point in the history
  • Loading branch information
iomsn committed Mar 19, 2024
1 parent 8d19521 commit 7e0ec93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/structured_2d_dgsem/elixir_advection_smview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ cells_per_dimension = (16, 16)
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; index_min = (1, 1), index_max = (8, 16))
mesh2 = StructuredMeshView(parent_mesh; index_min = (9, 1), index_max = (16, 16))
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
Expand Down
42 changes: 21 additions & 21 deletions src/meshes/structured_mesh_view.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ mutable struct StructuredMeshView{NDIMS, RealT <: Real} <: AbstractMesh{NDIMS}
mapping::Any # Not relevant for performance
mapping_as_string::String
current_filename::String
index_min::NTuple{NDIMS, Int}
index_max::NTuple{NDIMS, Int}
indices_min::NTuple{NDIMS, Int}
indices_max::NTuple{NDIMS, Int}
unsaved_changes::Bool
end

"""
StructuredMeshView(parent; index_min, index_max)
StructuredMeshView(parent; indices_min, indices_max)
Create a StructuredMeshView on a StructuredMesh parent.
# Arguments
- `parent`: the parent StructuredMesh.
- `index_min`: starting indices of the parent mesh.
- `index_max`: ending indices of the parent mesh.
- `indices_min`: starting indices of the parent mesh.
- `indices_max`: ending indices of the parent mesh.
"""
function StructuredMeshView(parent::StructuredMesh{NDIMS, RealT};
index_min = ntuple(_ -> 1, Val(NDIMS)),
index_max = size(parent)) where {NDIMS, RealT}
@assert index_min <= index_max
@assert all(index_min .> 0)
@assert index_max <= size(parent)
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 = index_max .- index_min .+ 1
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 .* (index_min .- 1)
coordinates_max = parent.mapping.coordinates_min .+ deltas .* index_max
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
Expand All @@ -56,7 +56,7 @@ function StructuredMeshView(parent::StructuredMesh{NDIMS, RealT};
return StructuredMeshView{NDIMS, RealT}(parent, cells_per_dimension, mapping,
mapping_as_string,
parent.current_filename,
index_min, index_max,
indices_min, indices_max,
parent.unsaved_changes)
end

Expand All @@ -67,21 +67,21 @@ function isperiodic(mesh::StructuredMeshView)
end

function isperiodic(mesh::StructuredMeshView, dimension)
@unpack parent, index_min, index_max = mesh
@unpack parent, indices_min, indices_max = mesh
return (isperiodic(parent, dimension) &&
index_min[dimension] == 1 &&
index_max[dimension] == size(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 index_min, index_max = mesh
return index_max .- index_min .+ 1
@unpack indices_min, indices_max = mesh
return indices_max .- indices_min .+ 1
end
function Base.size(mesh::StructuredMeshView, i)
@unpack index_min, index_max = mesh
return index_max[i] - index_min[i] + 1
@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))
Expand Down

0 comments on commit 7e0ec93

Please sign in to comment.