Skip to content

Commit

Permalink
Jecco, AdS5_3_1: add TrivialCoord system, to use with a coordinate sy…
Browse files Browse the repository at this point in the history
…stem of just one point

use it in AdS5_3_1/system
  • Loading branch information
mzilhao committed Feb 8, 2024
1 parent abfb67e commit af89257
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/AdS5_3_1/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ function Jecco.Atlas(grid::SpecCartGrid3D{T}) where {T}
grid.u_outer_min + i*delta_udom, grid.u_outer_nodes)
for i in 1:N_outer_sys]

xcoord = Cartesian{2}("x", grid.x_min, grid.x_max, grid.x_nodes, endpoint=false)
ycoord = Cartesian{3}("y", grid.y_min, grid.y_max, grid.y_nodes, endpoint=false)
if grid.x_nodes > 1
xcoord = Cartesian{2}("x", grid.x_min, grid.x_max, grid.x_nodes, endpoint=false)
else
xcoord = TrivialCoord{2,T}("x", grid.x_min, grid.x_max, grid.x_nodes)
end
if grid.y_nodes > 1
ycoord = Cartesian{3}("y", grid.y_min, grid.y_max, grid.y_nodes, endpoint=false)
else
ycoord = TrivialCoord{3,T}("y", grid.y_min, grid.y_max, grid.y_nodes)
end

inner_chart = Chart(u_inner_coord, xcoord, ycoord)
outer_charts = [Chart(u_outer_coords[i], xcoord, ycoord)
Expand Down Expand Up @@ -78,7 +86,7 @@ struct System{GT,Cu,Cx,Cy,TDu,TDx,TDy,TI,TF,TDKOx,TDKOy}
end

function System(gridtype::GT, ucoord::GaussLobattoCoord,
xcoord::CartesianCoord, ycoord::CartesianCoord, ord::Int,
xcoord::AbstractCoord, ycoord::AbstractCoord, ord::Int,
filter_gamma::T, sigma_diss::T) where {GT<:GridType,T<:Real}
KO_order = ord + 1

Expand Down Expand Up @@ -148,8 +156,16 @@ function SystemPartition(grid::SpecCartGrid3D{T}) where {T}
grid.u_outer_min + i*delta_udom, grid.u_outer_nodes)
for i in 1:N_outer_sys]

xcoord = Cartesian{2}("x", grid.x_min, grid.x_max, grid.x_nodes, endpoint=false)
ycoord = Cartesian{3}("y", grid.y_min, grid.y_max, grid.y_nodes, endpoint=false)
if grid.x_nodes > 1
xcoord = Cartesian{2}("x", grid.x_min, grid.x_max, grid.x_nodes, endpoint=false)
else
xcoord = TrivialCoord{2,T}("x", grid.x_min, grid.x_max, grid.x_nodes)
end
if grid.y_nodes > 1
ycoord = Cartesian{3}("y", grid.y_min, grid.y_max, grid.y_nodes, endpoint=false)
else
ycoord = TrivialCoord{3,T}("y", grid.y_min, grid.y_max, grid.y_nodes)
end

inner_system = System(Inner(), u_inner_coord, xcoord, ycoord, grid.fd_order,
grid.filter_γ, grid.sigma_diss)
Expand Down
2 changes: 1 addition & 1 deletion src/Jecco.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include("utils.jl")

export AbstractPartition, FlattenedVector

export AbstractCoord, CartesianCoord, GaussLobattoCoord
export AbstractCoord, CartesianCoord, GaussLobattoCoord, TrivialCoord
export Chart, Atlas
export Cartesian, GaussLobatto

Expand Down
22 changes: 22 additions & 0 deletions src/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ abstract type AbstractCoord{N,T} end
coord_axis(A::AbstractCoord{N,T}) where{N,T} = N
coord_eltype(A::AbstractCoord{N,T}) where{N,T} = T

struct TrivialCoord{N,T<:Real} <: AbstractCoord{N,T}
name :: String
min :: T
max :: T
nodes :: Int

function TrivialCoord{N,T}(name, min, max, nodes) where {N,T<:Real}
@assert min == max
@assert nodes == 1
new{N,T}(name, min, max, nodes)
end
end

struct CartesianCoord{N,T<:Real} <: AbstractCoord{N,T}
name :: String
min :: T
Expand All @@ -18,6 +31,7 @@ struct GaussLobattoCoord{N,T<:Real} <: AbstractCoord{N,T}
nodes :: Int
end

coord_type(coord::TrivialCoord) = "Trivial"
coord_type(coord::CartesianCoord) = "Cartesian"
coord_type(coord::GaussLobattoCoord) = "GaussLobatto"

Expand Down Expand Up @@ -48,6 +62,8 @@ function Coord{N}(coord_type::String, name::String, min::T, max::T, nodes::Int)
return CartesianCoord{N,T}(name, min, max, nodes)
elseif coord_type == "GaussLobatto"
return GaussLobattoCoord{N,T}(name, min, max, nodes)
elseif coord_type == "Trivial"
return TrivialCoord{N,T}(name, min, max, nodes)
else
error("Unknown coord type")
end
Expand All @@ -62,6 +78,10 @@ end
# return "missing", not define the method, or just have it return NaN, as now.
@inline delta(coord::GaussLobattoCoord) = NaN

# also, for the trivial coordinate system, we only have one point, so the
# spacing is not defined
@inline delta(coord::TrivialCoord) = NaN

@inline function Base.getindex(coord::CartesianCoord, i::Union{Int, UnitRange})
h = delta(coord)
coord.min .+ (i .- 1) * h
Expand All @@ -76,6 +96,8 @@ end
0.5 * (xmax .+ xmin .+ (xmax - xmin) * xj)
end

@inline Base.getindex(coord::TrivialCoord, i::Union{Int, UnitRange}) = coord.min

@inline Base.firstindex(coord::AbstractCoord) = 1
@inline Base.lastindex(coord::AbstractCoord) = coord.nodes
@inline Base.length(coord::AbstractCoord) = coord.nodes
Expand Down
1 change: 1 addition & 0 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function setup_openpmd_file(out::Output, fid::HDF5.File)
end

openpmd_geometry(coord::CartesianCoord) = "cartesian"
openpmd_geometry(coord::TrivialCoord) = "cartesian"
openpmd_geometry(coord::GaussLobattoCoord) = "other"

function openpmd_geometry(chart::Chart)
Expand Down

0 comments on commit af89257

Please sign in to comment.