Skip to content

Commit 2312b64

Browse files
authored
Merge branch 'main' into ap_new_bending
2 parents ad306d7 + d7af5a0 commit 2312b64

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

docs/src/man/geodynamic_setups.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ GeophysicalModelGenerator.AddLayer!
1414
GeophysicalModelGenerator.AddSphere!
1515
GeophysicalModelGenerator.AddEllipsoid!
1616
GeophysicalModelGenerator.AddCylinder!
17+
GeophysicalModelGenerator.addStripes!
1718
GeophysicalModelGenerator.makeVolcTopo
1819
GeophysicalModelGenerator.ConstantTemp
1920
GeophysicalModelGenerator.LinearTemp

src/Setup_geometry.jl

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,121 @@ using ScatteredInterpolation
1010
# These are routines that help to create input geometries, such as slabs with a given angle
1111
#
1212

13-
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, addSlab!,
13+
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, addSlab!, addStripes!,
1414
makeVolcTopo,
1515
ConstantTemp, LinearTemp, HalfspaceCoolingTemp, SpreadingRateTemp, LithosphericTemp,
1616
ConstantPhase, LithosphericPhases,
1717
Compute_ThermalStructure, Compute_Phase,
1818
McKenzie_subducting_slab, LinearWeightedTemperature, Trench
1919

2020

21+
22+
"""
23+
addStripes!(Phase, Grid::AbstractGeneralGrid;
24+
stripAxes = (1,1,0),
25+
stripeWidth = 0.2,
26+
stripeSpacing = 1,
27+
Origin = nothing,
28+
StrikeAngle = 0,
29+
DipAngle = 10,
30+
phase = ConstantPhase(3),
31+
stripePhase = ConstantPhase(4))
32+
33+
Adds stripes to a pre-defined phase (e.g. added using AddBox!)
34+
35+
36+
Parameters
37+
====
38+
- Phase - Phase array (consistent with Grid)
39+
- Grid - grid structure (usually obtained with ReadLaMEM_InputFile, but can also be other grid types)
40+
- stripAxes - sets the axis for which we want the stripes. Default is (1,1,0) i.e. X, Y and not Z
41+
- stripeWidth - width of the stripe
42+
- stripeSpacing - space between two stripes
43+
- Origin - the origin, used to rotate the box around. Default is the left-front-top corner
44+
- StrikeAngle - strike angle
45+
- DipAngle - dip angle
46+
- phase - specifies the phase we want to apply stripes to
47+
- stripePhase - specifies the stripe phase
48+
49+
50+
Example
51+
========
52+
53+
Example: Box with striped phase and constant temperature & a dip angle of 10 degrees:
54+
```julia
55+
julia> Grid = ReadLaMEM_InputFile("test_files/SaltModels.dat")
56+
LaMEM Grid:
57+
nel : (32, 32, 32)
58+
marker/cell : (3, 3, 3)
59+
markers : (96, 96, 96)
60+
x ϵ [-3.0 : 3.0]
61+
y ϵ [-2.0 : 2.0]
62+
z ϵ [-2.0 : 0.0]
63+
julia> Phases = zeros(Int32, size(Grid.X));
64+
julia> Temp = zeros(Float64, size(Grid.X));
65+
julia> AddBox!(Phases,Temp,Grid, xlim=(0,500), zlim=(-50,0), phase=ConstantPhase(3), DipAngle=10, T=ConstantTemp(1000))
66+
julia> addStripes!(Phases, Grid, stripAxes=(1,1,1), stripeWidth=0.2, stripeSpacing=1, Origin=nothing, StrikeAngle=0, DipAngle=10, phase=ConstantPhase(3), stripePhase=ConstantPhase(4))
67+
julia> Model3D = ParaviewData(Grid, (Phases=Phases,Temp=Temp)); # Create Cartesian model
68+
julia> Write_Paraview(Model3D,"LaMEM_ModelSetup") # Save model to paraview
69+
1-element Vector{String}:
70+
"LaMEM_ModelSetup.vts"
71+
```
72+
"""
73+
function addStripes!(Phase, Grid::AbstractGeneralGrid; # required input
74+
stripAxes = (1,1,0), # activate stripes along dimensions x, y and z when set to 1
75+
stripeWidth = 0.2, # full width of a stripe
76+
stripeSpacing = 1, # spacing between two stripes centers
77+
Origin = nothing, # origin
78+
StrikeAngle = 0, # strike
79+
DipAngle = 0, # dip angle
80+
phase = ConstantPhase(3), # phase to be striped
81+
stripePhase = ConstantPhase(4)) # stripe phase
82+
83+
# warnings
84+
if stripeWidth >= stripeSpacing/2.0
85+
print("WARNING: stripeWidth should be strictly < stripeSpacing/2.0, otherwise phase is overwritten by the stripePhase\n")
86+
elseif sum(stripAxes .== 0) == 3
87+
print("WARNING: at least one axis should be set to 1 e.g. stripAxes = (1,0,0), otherwise no stripes will be added\n")
88+
end
89+
90+
# Retrieve 3D data arrays for the grid
91+
X,Y,Z = coordinate_grids(Grid)
92+
93+
# sets origin
94+
if isnothing(Origin)
95+
Origin = (maximum(X), maximum(Y), maximum(Z)) # upper-left corner
96+
end
97+
98+
# Perform rotation of 3D coordinates:
99+
Xrot = X .- Origin[1];
100+
Yrot = Y .- Origin[2];
101+
Zrot = Z .- Origin[3];
102+
103+
Rot3D!(Xrot,Yrot,Zrot, StrikeAngle, DipAngle)
104+
105+
ph_ind = findall(Phase .== phase.phase);
106+
107+
ind = Int64[]
108+
if stripAxes[1] == 1
109+
indX = findall( abs.(Xrot[ph_ind] .% stripeSpacing) .<= stripeWidth/2.0);
110+
ind = vcat(ind,indX);
111+
end
112+
if stripAxes[2] == 1
113+
indY = findall( abs.(Yrot[ph_ind] .% stripeSpacing) .<= stripeWidth/2.0);
114+
ind = vcat(ind,indY);
115+
end
116+
if stripAxes[3] == 1
117+
indZ = findall( abs.(Zrot[ph_ind] .% stripeSpacing) .<= stripeWidth/2.0);
118+
ind = vcat(ind,indZ);
119+
end
120+
121+
Phase[ph_ind[ind]] .= stripePhase.phase;
122+
123+
return nothing
124+
end
125+
126+
127+
21128
"""
22129
AddBox!(Phase, Temp, Grid::AbstractGeneralGrid; xlim=Tuple{2}, [ylim=Tuple{2}], zlim=Tuple{2},
23130
Origin=nothing, StrikeAngle=0, DipAngle=0,

test/test_setup_geometry.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ Temp = ones(Float64, Grid.N...)*1350;
3333
Phases = zeros(Int32, Grid.N...);
3434

3535
AddBox!(Phases,Temp,Grid, xlim=(2,4), zlim=(4,8), phase=ConstantPhase(3), DipAngle=10, T=LinearTemp(Tbot=1350, Ttop=200))
36-
3736
@test maximum(Phases) == 3
3837

38+
addStripes!(Phases, Grid,stripAxes=(1,1,1),stripeWidth=0.2,stripeSpacing=1,Origin=nothing, StrikeAngle=0, DipAngle=10,phase = ConstantPhase(3),stripePhase = ConstantPhase(4))
39+
@test maximum(Phases) == 4
40+
3941
# Create a CartData structure from it
4042
Data = CartData(Grid, (T=Temp, Phases=Phases))
4143

0 commit comments

Comments
 (0)