Skip to content

Commit 592d903

Browse files
committed
added the possibility to create a CartGrid with dimensional values & non-dimensionalise it
1 parent b7fb368 commit 592d903

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

src/data_types.jl

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,28 +962,45 @@ end
962962

963963
"""
964964
965-
Creates a 1D, 2D or 3D cartesian grid of given size. Grid can be created by defining the size and either the `extent` (length) of the grid in all directions, or by defining start & end points
965+
Grid = CreateCartGrid(; size=(), x = nothing, z = nothing, y = nothing, extent = nothing, CharDim = nothing)
966966
967-
Spacing is assumed to be constant
967+
Creates a 1D, 2D or 3D cartesian grid of given size. Grid can be created by defining the size and either the `extent` (length) of the grid in all directions, or by defining start & end points (`x`,`y`,`z`).
968+
If you specify `CharDim` (a structure with characteristic dimensions created with `GeoParams.jl`), we will nondimensionalize the grd before creating the struct.
969+
970+
Spacing is assumed to be constant in a given direction
971+
972+
This can also be used for staggered grids, as we also create 1D vectors for the central points. The points you indicate in `size` are the corner points.
973+
974+
Note: since this is mostly for solid Earth geoscience applications, the second dimension is called z (vertical)
968975
969-
Note: since this is mostly for Solid Earth geoscience applications, the second dimension is called z (vertical)
970976
971977
# Examples
972978
====
973979
980+
A basic case with non-dimensional units:
974981
```julia
975-
Grid = CreateCartGrid(size=(10,20),x=(0.,10), z=(2.,10))
982+
julia> Grid = CreateCartGrid(size=(10,20),x=(0.,10), z=(2.,10))
976983
Grid{Float64, 2}
977984
size: (10, 20)
978985
length: (10.0, 8.0)
979986
domain: x ∈ [0.0, 10.0], z ∈ [2.0, 10.0]
980987
grid spacing Δ: (1.1111111111111112, 0.42105263157894735)
981988
```
989+
990+
An example with dimensional units:
991+
```julia
992+
julia> CharDim = GEO_units()
993+
julia> Grid = CreateCartGrid(size=(10,20),x=(0.0km, 10km), z=(-20km, 10km), CharDim=CharDim)
994+
995+
```
996+
997+
982998
"""
983999
function CreateCartGrid(;
9841000
size=(),
9851001
x = nothing, z = nothing, y = nothing,
986-
extent = nothing
1002+
extent = nothing,
1003+
CharDim = nothing
9871004
)
9881005

9891006
if isa(size, Number)
@@ -1023,6 +1040,18 @@ function CreateCartGrid(;
10231040
end
10241041
Xₙ = X₁ .+ L
10251042
Δ = L ./ (N .- 1)
1043+
1044+
# nondimensionalize
1045+
if !isnothing(CharDim)
1046+
X₁, Xₙ, Δ, L = GeoUnit.(X₁), GeoUnit.(Xₙ), GeoUnit.(Δ), GeoUnit.(L)
1047+
1048+
X₁ = ntuple( i -> nondimensionalize(X₁[i], CharDim), dim)
1049+
Xₙ = ntuple( i -> nondimensionalize(Xₙ[i], CharDim), dim)
1050+
Δ = ntuple( i -> nondimensionalize(Δ[i], CharDim), dim)
1051+
L = ntuple( i -> nondimensionalize(L[i], CharDim), dim)
1052+
1053+
X₁, Xₙ, Δ, L = NumValue.(X₁), NumValue.(Xₙ), NumValue.(Δ), NumValue.(L)
1054+
end
10261055

10271056
# Generate 1D coordinate arrays of vertexes in all directions
10281057
coord1D=()
@@ -1041,6 +1070,8 @@ function CreateCartGrid(;
10411070

10421071
end
10431072

1073+
1074+
10441075
# view grid object
10451076
function show(io::IO, g::CartGrid{FT, DIM}) where {FT, DIM}
10461077

test/test_data_types.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Data = Z
151151
Data_setC = CartData(X,Y,Z, (FakeData=Data,Data2=Data.+1.))
152152
@test sum(abs.(Value(Data_setC.x))) 2310.0km
153153

154+
155+
156+
157+
154158
# Convert from CartData -> UTMData
155159
Data_set4 = Convert2UTMzone(Data_setC, proj)
156160

test/test_setup_geometry.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Phases = Compute_Phase(Phases, Temp, Grid, LP);
7979

8080
# test AboveSurface with the Grid object
8181
Grid = CreateCartGrid(size=(10,20,30),x=(0.,10), y=(0.,10), z=(-10.,2.))
82+
@test Grid.Δ[2] 0.5263157894736842
83+
8284
Temp = ones(Float64, Grid.N...)*1350;
8385
Phases = zeros(Int32, Grid.N...);
8486

@@ -89,3 +91,8 @@ ind = AboveSurface(Grid, Topo_cart);
8991

9092
ind = BelowSurface(Grid, Topo_cart);
9193
@test sum(ind[1,1,:]) == 25
94+
95+
# Create Grid & nondimensionalize it
96+
CharDim = GEO_units();
97+
Grid = CreateCartGrid(size=(10,20,30),x=(0.0km,10km), y=(0.0km, 10km), z=(-10.0km, 2.0km), CharDim=CharDim)
98+
@test Grid.Δ[2] 0.0005263157894736842

0 commit comments

Comments
 (0)