Skip to content

Commit dc372e4

Browse files
committed
Polygon function compatible with new inPolygon
1 parent 04cc8a8 commit dc372e4

File tree

5 files changed

+73
-77
lines changed

5 files changed

+73
-77
lines changed

docs/make.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,26 @@ makedocs(;
8282
"Home" => "index.md",
8383
"Tutorials" => Any[
8484
"Overview" => "man/tutorials.md",
85-
"1 - 3D seismic tomography from ASCII" => "man/tutorial_load3DSeismicData.md",
86-
"2 - 3D seismic tomography from netCDF" => "man/tutorial_loadregular3DSeismicData_netCDF.md",
87-
"3 - Visualize Moho topography" => "man/tutorial_MohoTopo.md",
88-
"4 - Create GMT-based topography" => "man/tutorial_GMT_Topography.md",
89-
"5 - Coastlines" => "man/tutorial_Coastlines.md",
90-
"6 - Import screenshots" => "man/tutorial_Screenshot_To_Paraview.md",
91-
"7 - Interpolate irregular 3D seismic tomography" => "man/tutorial_loadirregular3DSeismicData.md",
92-
"8 - ETOPO1 Topography and geological maps" => "man/tutorial_GMT_Topography_GeologicalMap.md",
93-
"9 - ISC earthquake data" => "man/tutorial_ISC_data.md",
94-
"10 - Plot GPS vectors" => "man/tutorial_GPS.md",
95-
"11 - Read UTM data" => "man/tutorial_UTM.md",
96-
"12 - VoteMaps" => "man/Tutorial_Votemaps.md",
97-
"13 - Campi Flegrei" => "man/tutorial_local_Flegrei.md",
98-
"14 - La Palma volcano Model" => "man/Tutorial_LaPalma.md",
99-
"15 - Create movies" => "man/tutorial_time_Seismicity.md",
100-
"16 - Fault Density Map" => "man/tutorial_Fault_Map.md",
101-
"17 - Jura tutorial" => "man/Tutorial_Jura.md",
102-
"18 - Geometry setup " => "man/tutorial_Polygon_structures.md"
85+
"1 - Getting started" => "man/Tutorial_Basic.md",
86+
"2 - 3D seismic tomography from ASCII" => "man/tutorial_load3DSeismicData.md",
87+
"3 - 3D seismic tomography from netCDF" => "man/tutorial_loadregular3DSeismicData_netCDF.md",
88+
"4 - Visualize Moho topography" => "man/Tutorial_MohoTopo_Spada.md",
89+
"5 - Create GMT-based topography" => "man/tutorial_GMT_Topography.md",
90+
"6 - Coastlines" => "man/tutorial_Coastlines.md",
91+
"7 - Import screenshots" => "man/tutorial_Screenshot_To_Paraview.md",
92+
"8 - Interpolate irregular 3D seismic tomography" => "man/tutorial_loadirregular3DSeismicData.md",
93+
"9 - ETOPO1 Topography and geological maps" => "man/tutorial_GMT_Topography_GeologicalMap.md",
94+
"10 - ISC earthquake data" => "man/tutorial_ISC_data.md",
95+
"11 - Plot GPS vectors" => "man/tutorial_GPS.md",
96+
"12 - Read UTM data" => "man/tutorial_UTM.md",
97+
"13 - VoteMaps" => "man/Tutorial_Votemaps.md",
98+
"14 - Campi Flegrei" => "man/tutorial_local_Flegrei.md",
99+
"15 - La Palma volcano Model" => "man/Tutorial_LaPalma.md",
100+
"16 - Create movies" => "man/tutorial_time_Seismicity.md",
101+
"17 - Fault Density Map" => "man/Tutorial_FaultDensity.md",
102+
"18 - Alpine data integration" => "man/Tutorial_AlpineData.md",
103+
"19 - Jura tutorial" => "man/Tutorial_Jura.md",
104+
"20 - Build geometry setup with polygon.md" => "man/tutorial_Polygon_structures.md"
103105
],
104106
"User Guide" => Any[
105107
"Installation" => "man/installation.md",

docs/src/man/tutorial_Polygon_structures.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This tutorial visualizes simplified geological as it is done here for a passive
88
## Steps
99

1010
#### 1. Set up your simplified background model
11-
Before adding specific geological features, a general simplified model setup is necessary. The construction is made by using the AddBox function. For the model the discontinuities are in 15, 45, 145, and 945 km depth.
11+
Before adding specific geological features, a general simplified model setup is necessary. The construction is made by using the addBox function. For the model the discontinuities are in 15, 45, 145, and 945 km depth.
1212

1313
```julia
1414
using GeophysicalModelGenerator
@@ -33,12 +33,14 @@ Temp = ones(Float64,size(X))*1350
3333
# add different phases: crust->2, Mantle Lithosphere->3 Mantle->1
3434
AddBox!(Phase, Temp, Cart; xlim=(0.0,800.0),ylim=(0.0,800.0), zlim=(-800.0,0.0), phase = LithosphericPhases(Layers=[15 30 100 800], Phases=[2 3 1 5], Tlab=1300 ), T=LinearTemp(Ttop=20, Tbot=1600))
3535

36+
37+
# add air phase 0
3638
AddBox!(Phase, Temp, Cart; xlim=(0.0,800.0),ylim=(0.0,800.0), zlim=(0.0,50.0), phase = ConstantPhase(0), T=ConstantTemp(20.0))
3739

3840
```
3941

4042

41-
#### 2. Add polygone sturture
43+
#### 2. Add polygon struture
4244
For including the geological structures of a passive margin into the model via the polygon function, depths down to 150 km are focused on. With the polygon function, it is possible to create different shapes. In the example, the sediment basin shows a more trapezial (2D in x-/z-direction) shape, while the thinning of the plate is a more triangular (2D in x-/z-direction). More complex structures are possible to build in the background model due to the non-limitation number of points in the x- and z-direction. In y-direction only the length can be varied and is set by two values. The shape is not changeable. The x- and z-values of the points need to be in the same order for selecting the correct point (P1(1/3), P2(2/2) --> xlim(1,2), ylim(3,2)).
4345

4446

@@ -48,18 +50,18 @@ For including the geological structures of a passive margin into the model via t
4850
# ylim: limits the object within the two ylim values
4951
# unlimited number of points possible to create the polygon
5052

51-
# add sediment basin # depending on resolution show and angle if it the edge is visible in paraview
52-
addPolygon!(Phase, Temp, Cart; xlim=(0.0,0.0, 160.0, 200.0),ylim=(100.0,300.0), zlim=(0.0,-10.0,-20.0,0.0), phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
53+
# add sediment basin
54+
addPolygon!(Phase, Temp, Cart; xlim=[0.0,0.0, 160.0, 200.0],ylim=[100.0,300.0], zlim=[0.0,-10.0,-20.0,0.0], phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
5355

5456
# add thinning of the continental crust attached to the slab and its thickness
55-
addPolygon!(Phase, Temp, Cart; xlim=(0.0, 200.0, 0.0),ylim=(500.0,800.0), zlim=(-100.0,-150.0,-150.0), phase = ConstantPhase(5), T=LinearTemp(Ttop=1000, Tbot=1100))
57+
addPolygon!(Phase, Temp, Cart; xlim=[0.0, 200.0, 0.0],ylim=[500.0,800.0], zlim=[-100.0,-150.0,-150.0], phase = ConstantPhase(5), T=LinearTemp(Ttop=1000, Tbot=1100))
5658

5759
# add accretionary prism
58-
addPolygon!(Phase, Temp, Cart; xlim=(800.1, 600.0, 800.1),ylim=(100.0,800.0), zlim=(0.0,0.0,-60.0), phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
60+
addPolygon!(Phase, Temp, Cart; xlim=[800.0, 600.0, 800.0],ylim=[100.0,800.0], zlim=[0.0,0.0,-60.0], phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
5961

6062
```
6163

62-
#### 3. Export the final model setup to a paraview file
64+
#### 3. Export final model setup to a paraview file
6365
For visualisation and comparison to actual measured data, the mode setup is saved to a paraview file.
6466

6567
```julia

src/Setup_geometry.jl

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using GeoParams
99
# These are routines that help to create input geometries, such as slabs with a given angle
1010
#
1111

12-
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, addPolygon!
12+
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, addPolygon!,
1313
makeVolcTopo,
1414
ConstantTemp, LinearTemp, HalfspaceCoolingTemp, SpreadingRateTemp, LithosphericTemp,
1515
ConstantPhase, LithosphericPhases,
@@ -472,33 +472,11 @@ end
472472

473473

474474

475-
476-
function inPoly(PolyX, PolyY, x, y)
477-
inside = false
478-
iSteps = collect(eachindex(PolyX))
479-
jSteps = [length(PolyX); collect(1:length(PolyX)-1)]
480-
481-
for (i,j) in zip(iSteps, jSteps)
482-
xi = PolyX[i]
483-
yi = PolyY[i]
484-
xj = PolyX[j]
485-
yj = PolyY[j]
486-
487-
if ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi + eps()) + xi)
488-
489-
inside = !inside
490-
end
491-
end
492-
493-
return inside
494-
end
495-
496-
497475
"""
498-
addPolygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
499-
xlim=Tuple{}, ylim=Tuple{2}, zlim=Tuple{}, # limits of the box
500-
phase = ConstantPhase(1), # Sets the phase number(s) in the box
501-
T=nothing )
476+
function addPolygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
477+
xlim=Vector(), ylim=Vector(2), zlim=Vector(), # limits of the box
478+
phase = ConstantPhase(1), # Sets the phase number(s) in the box
479+
T=nothing )
502480
Adds a polygon with phase & temperature structure to a 3D model setup. This simplifies creating model geometries in geodynamic models
503481
504482
@@ -510,7 +488,7 @@ Parameters
510488
- xlim - x-cooridnate of the polygon points, same ordering as zlim, number of points unlimited
511489
- ylim - y-cooridnate, limition in length possible (two values (start and stop))
512490
- zlim - z-cooridnate of the polygon points, same ordering as xlim, number of points unlimited
513-
- phase - specifies the phase of the box. See `ConstantPhase()`,`LithosphericPhases()`
491+
- phase - specifies the phase of the box. See `ConstantPhase()`
514492
- T - specifies the temperature of the box. See `ConstantTemp()`,`LinearTemp()`,`HalfspaceCoolingTemp()`,`SpreadingRateTemp()`
515493
516494
@@ -540,29 +518,28 @@ julia> Write_Paraview(Model3D,"LaMEM_ModelSetup") # Save model to para
540518
"""
541519

542520

543-
function addPolygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
544-
xlim=Tuple{}, ylim=Tuple{2}, zlim=Tuple{}, # limits of the box
545-
phase = ConstantPhase(1), # Sets the phase number(s) in the box
546-
T=nothing ) # Sets the thermal structure (various functions are available)
521+
function addPolygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
522+
xlim=Vector(), ylim=Vector(2), zlim=Vector(), # limits of the box
523+
phase = ConstantPhase(1), # Sets the phase number(s) in the box
524+
T=nothing ) # Sets the thermal structure (various functions are available)
547525

548526
# Retrieve 3D data arrays for the grid
549527
X,Y,Z = coordinate_grids(Grid)
550528

529+
ind = zeros(Bool,size(X))
530+
ind_slice = zeros(Bool,size(X[:,1,:]))
551531

552-
indx = zeros(length(X))
532+
# find points within the polygon, only in 2D
533+
for i = 1:size(Y)[2]
553534

554-
# find points of the total script within the polygone, only in 2D due to the symetric structures and index of y
555-
for i = 1:length(X)#(indy)
556-
557-
# working but not the fastest
558-
if Y[i] >= ylim[1] && Y[i]<=ylim[2]
559-
indx[i] = inPoly(xlim,zlim, X[i], Z[i])
535+
if Y[1,i,1] >= ylim[1] && Y[1,i,1]<=ylim[2]
536+
inPolygon!(ind_slice, xlim,zlim, X[:,i,:], Z[:,i,:])
537+
ind[:,i,:] = ind_slice
538+
else
539+
ind[:,i,:] = zeros(size(X[:,1,:]))
560540
end
561541
end
562542

563-
# get all indices which are in the polygone separated
564-
ind = findall(x->x>0,indx)
565-
566543

567544
# Compute thermal structure accordingly. See routines below for different options
568545
if T != nothing

test/test_setup_geometry.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ AddBox!(Phases,Temp,Grid, xlim=(2,4), zlim=(4,8), phase=ConstantPhase(3), DipAng
3939

4040
@test maximum(Phases) == 3
4141

42-
# add accretionary prism
43-
addPolygon!(Phase, Temp, Cart; xlim=(1, 2, 1),ylim=(0.0,1.0), zlim=(2.0,3.0,3.0), phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
44-
@test maximum(Phases) == 8
4542

4643
# Create a CartData structure from it
4744
Data = CartData(Grid, (T=Temp, Phases=Phases))
@@ -217,3 +214,22 @@ AddBox!(Phase, Temp, Cart; xlim=(0.0,600.0),ylim=(0.0,600.0), zlim=(-80.0, 0.0),
217214

218215

219216
Data_Final = AddField(Cart,"Temp",Temp)
217+
218+
# test polygon structure
219+
220+
x = LinRange(0.0,1200.0,64);
221+
y = LinRange(0.0,1200.0,64);
222+
z = LinRange(-660,50,64);
223+
Cart = CartData(XYZGrid(x, y, z));
224+
225+
# initialize phase and temperature matrix
226+
Phase = ones(Int32,(length(x),length(y),length(z)));
227+
Temp = ones(Float64,(length(x),length(y),length(z)))*1350;
228+
229+
AddBox!(Phase, Temp, Cart; xlim=(0.0,600.0),ylim=(0.0,600.0), zlim=(-80.0, 0.0), phase = ConstantPhase(5), T=T=ConstantTemp(120.0));
230+
231+
# add accretionary prism
232+
addPolygon!(Phase, Temp, Cart; xlim=[500.0, 200.0, 500.0],ylim=[100.0,400.0], zlim=[0.0,0.0,-60.0], phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
233+
234+
@test maximum(Phase) == 8
235+
@test minimum(Temp) == 21.40845070422536

tutorials/Tutorial_polygon_geometry.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@ Temp = ones(Float64,size(X))*1350
2121
AddBox!(Phase, Temp, Cart; xlim=(0.0,800.0),ylim=(0.0,800.0), zlim=(-800.0,0.0), phase = LithosphericPhases(Layers=[15 30 100 800], Phases=[2 3 1 5], Tlab=1300 ), T=LinearTemp(Ttop=20, Tbot=1600) )#T=HalfspaceCoolingTemp(Tsurface=20.0, Tmantle=1350, Age=120, Adiabat=0.4)
2222

2323

24-
25-
# xlim: x-coordinates of the points, same ordering as zlim
24+
# xlim: x-coordiates of the points, same ordering as zlim
2625
# zlim: z-coordinates of the points, same ordering as xlim
2726
# ylim: limits the object within the two ylim values
2827
# unlimited number of points possible to create the polygon
29-
# add sediment basin # depending on resolution show and angle if it the edge is visible in paraview
30-
addPolygon!(Phase, Temp, Cart; xlim=(0.0,0.0, 160.0, 200.0),ylim=(100.0,300.0), zlim=(0.0,-10.0,-20.0,0.0), phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
28+
# add sediment basin # depending on the resolution and angle if it the edge is visible in paraview
29+
addPolygon!(Phase, Temp, Cart; xlim=[0.0,0.0, 160.0, 200.0],ylim=[100.0,300.0], zlim=[0.0,-10.0,-20.0,0.0], phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
3130

3231
# add thinning of the continental crust attached to the slab and its thickness
33-
addPolygon!(Phase, Temp, Cart; xlim=(0.0, 200.0, 0.0),ylim=(500.0,800.0), zlim=(-100.0,-150.0,-150.0), phase = ConstantPhase(5), T=LinearTemp(Ttop=1000, Tbot=1100))
32+
addPolygon!(Phase, Temp, Cart; xlim=[0.0, 200.0, 0.0],ylim=[500.0,800.0], zlim=[-100.0,-150.0,-150.0], phase = ConstantPhase(5), T=LinearTemp(Ttop=1000, Tbot=1100))
3433

3534
# add accretionary prism
36-
addPolygon!(Phase, Temp, Cart; xlim=(800.1, 600.0, 800.1),ylim=(100.0,800.0), zlim=(0.0,0.0,-60.0), phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
35+
addPolygon!(Phase, Temp, Cart; xlim=[800.0, 600.0, 800.0],ylim=[100.0,800.0], zlim=[0.0,0.0,-60.0], phase = ConstantPhase(8), T=LinearTemp(Ttop=20, Tbot=30))
3736

3837

3938
# add air phase 0
40-
addBox!(Phase, Temp, Cart; xlim=(0.0,800.0),ylim=(0.0,800.0), zlim=(0.0,50.0), phase = ConstantPhase(0), T=ConstantTemp(20.0))
39+
AddBox!(Phase, Temp, Cart; xlim=(0.0,800.0),ylim=(0.0,800.0), zlim=(0.0,50.0), phase = ConstantPhase(0), T=ConstantTemp(20.0))
4140

4241
# # Save data to paraview:
4342
Data_Final = CartData(X,Y,Z,(Phase=Phase,Temp=Temp))

0 commit comments

Comments
 (0)