Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Polygon structure in pseudo3D #73

Merged
merged 26 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e35424c
Add Polygon structure
TatjanaWeiler Feb 29, 2024
d69e6e6
Merge branch 'main' into pr/73
boriskaus Mar 2, 2024
ce4a3f5
fix typos; change name to addPolygon
boriskaus Mar 2, 2024
acc2136
Add Polygon structure -- added files
TatjanaWeiler Mar 4, 2024
7e66f8d
Merge branch 'main' of https://github.com/TatjanaWeiler/GeophysicalMo…
TatjanaWeiler Mar 4, 2024
dd50004
Create Setup_geometry.jl
TatjanaWeiler Mar 4, 2024
a580ea8
Update Setup_geometry.jl
TatjanaWeiler Mar 4, 2024
c93b36c
Merge branch 'main' into main
boriskaus Mar 4, 2024
a91df89
Poly_tutorial
TatjanaWeiler Mar 4, 2024
c747e9f
Merge branch 'main' of https://github.com/TatjanaWeiler/GeophysicalMo…
TatjanaWeiler Mar 4, 2024
4dfe524
Merge remote-tracking branch 'upstream/main'
TatjanaWeiler Mar 8, 2024
04cc8a8
Merge branch 'main' into main
boriskaus Mar 8, 2024
dc372e4
Polygon function compatible with new inPolygon
TatjanaWeiler Mar 11, 2024
d5dd2e1
Polygon again
TatjanaWeiler Mar 11, 2024
de5f329
Merge branch 'main' into main
boriskaus Mar 11, 2024
b0d5107
Merge branch 'main' into main
boriskaus Mar 11, 2024
f67f9cf
Update make.jl
boriskaus Mar 11, 2024
99b495c
Update make.jl
boriskaus Mar 11, 2024
937bbd2
Update make.jl
boriskaus Mar 11, 2024
428fb96
Update tutorial_Polygon_structures.md
boriskaus Mar 11, 2024
8aa10f1
Update Setup_geometry.jl
boriskaus Mar 11, 2024
6530a9f
Additional test polygon
TatjanaWeiler Mar 12, 2024
7a94ab9
Merge branch 'main' of https://github.com/TatjanaWeiler/GeophysicalMo…
TatjanaWeiler Mar 12, 2024
32adc3c
Test polygon
TatjanaWeiler Mar 13, 2024
edad91d
Test polygon_3
TatjanaWeiler Mar 13, 2024
9ad2943
Merge branch 'main' into main
boriskaus Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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 @@
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 polygon, only in 2D due to the symmetric structures and index of y
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 polygon separated
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.jl
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-coordinates of the points, same ordering as zlim
# 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")


Loading