Skip to content

Commit

Permalink
Add Polygon structure
Browse files Browse the repository at this point in the history
  • Loading branch information
TatjanaWeiler committed Feb 29, 2024
1 parent 148be67 commit e35424c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/Setup_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using GeoParams
# These are routines that help to create input geometries, such as slabs with a given angle
#

export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!,
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, AddPolygon!,
makeVolcTopo,
ConstantTemp, LinearTemp, HalfspaceCoolingTemp, SpreadingRateTemp, LithosphericTemp,
ConstantPhase, LithosphericPhases,
Expand Down Expand Up @@ -450,6 +450,65 @@ function AddCylinder!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
return nothing
end

function inPoly(PolyX, PolyY, x, y)
inside = false
iSteps = collect(eachindex(PolyX))
jSteps = [length(PolyX); collect(1:length(PolyX)-1)]

Check warning on line 456 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L453-L456

Added lines #L453 - L456 were not covered by tests

for (i,j) in zip(iSteps, jSteps)
xi = PolyX[i]
yi = PolyY[i]
xj = PolyX[j]
yj = PolyY[j]

Check warning on line 462 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L458-L462

Added lines #L458 - L462 were not covered by tests

if ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi + eps()) + xi)

Check warning on line 464 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L464

Added line #L464 was not covered by tests

inside = !inside

Check warning on line 466 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L466

Added line #L466 was not covered by tests
end
end

Check warning on line 468 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L468

Added line #L468 was not covered by tests

return inside

Check warning on line 470 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L470

Added line #L470 was not covered by tests
end


function AddPolygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input

Check warning on line 474 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L474

Added line #L474 was not covered by tests
xlim=Tuple{}, ylim=Tuple{2}, zlim=Tuple{}, # limits of the box
Origin=nothing, StrikeAngle=0, DipAngle=0, # origin & dip/strike
phase = ConstantPhase(1), # Sets the phase number(s) in the box
T=nothing ) # Sets the thermal structure (various functions are available)

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

Check warning on line 481 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L481

Added line #L481 was not covered by tests


indx = zeros(length(X))

Check warning on line 484 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L484

Added line #L484 was not covered by tests

# find points of the total script within the polygone, only in 2D due to the symetric structures and index of y

Check warning on line 486 in src/Setup_geometry.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"polygone" should be "polygon".

Check warning on line 486 in src/Setup_geometry.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"symetric" should be "symmetric".
for i = 1:length(X)#(indy)

Check warning on line 487 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L487

Added line #L487 was not covered by tests

# working but not the fastest
if Y[i] >= ylim[1] && Y[i]<=ylim[2]
indx[i] = inPoly(xlim,zlim, X[i], Z[i])

Check warning on line 491 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L490-L491

Added lines #L490 - L491 were not covered by tests
end
end

Check warning on line 493 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L493

Added line #L493 was not covered by tests

# get all indices which are in the polygone separated

Check warning on line 495 in src/Setup_geometry.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"polygone" should be "polygon".
ind = findall(x->x>0,indx)

Check warning on line 496 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L496

Added line #L496 was not covered by tests


# Compute thermal structure accordingly. See routines below for different options
if T != nothing
Temp[ind] = Compute_ThermalStructure(Temp[ind], X[ind], Y[ind], Z[ind], T)

Check warning on line 501 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L500-L501

Added lines #L500 - L501 were not covered by tests
end

# Set the phase. Different routines are available for that - see below.
Phase[ind] = Compute_Phase(Phase[ind], Temp[ind], X[ind], Y[ind], Z[ind], phase)

Check warning on line 505 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L505

Added line #L505 was not covered by tests

return nothing

Check warning on line 507 in src/Setup_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/Setup_geometry.jl#L507

Added line #L507 was not covered by tests
end



# Internal function that rotates the coordinates
function Rot3D!(X,Y,Z, StrikeAngle, DipAngle)

Expand Down
46 changes: 46 additions & 0 deletions tutorials/Tutorial_polygon_geometry
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using GeophysicalModelGenerator


# number of cells in every direction
nx = 100
ny = 100
nz = 200

# define domain size
x = LinRange(0.0,800.0,nx)
y = LinRange(0.0,800.0,ny)
z = LinRange(-660,50,nz)
X,Y,Z = XYZGrid(x, y, z);
Cart = CartData(X,Y,Z, (Data=Z,))

# initialize phase and temperature matrix
Phase = ones(Int32,size(X))
Temp = ones(Float64,size(X))*1350

# add different phases: crust->2, Mantle Lithosphere->3 Mantle->1
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)



# xlim: x-coordiates of the points, same ordering as zlim

Check warning on line 25 in tutorials/Tutorial_polygon_geometry

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"coordiates" should be "coordinates".
# zlim: z-coordinates of the points, same ordering as xlim
# ylim: limits the object within the two ylim values
# unlimited number of points possible to create the polygon
# add sediment basin # depending on resolution show and angle if it the edge is visible in paraview
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))

# add thinning of the continental crust attached to the slab and its thickness
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))

# add accretionary prism
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))


# add air phase 0
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))

# # Save data to paraview:
Data_Final = CartData(X,Y,Z,(Phase=Phase,Temp=Temp))
Write_Paraview(Data_Final, "Sedimentary_basin")


0 comments on commit e35424c

Please sign in to comment.