Skip to content

Commit d7af5a0

Browse files
authored
Merge pull request #95 from NicolasRiel/main
Function to add stripes on shapes
2 parents 4b99288 + d07b203 commit d7af5a0

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
@@ -9,14 +9,121 @@ 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!,
12+
export AddBox!, AddSphere!, AddEllipsoid!, AddCylinder!, AddLayer!, addStripes!,
1313
makeVolcTopo,
1414
ConstantTemp, LinearTemp, HalfspaceCoolingTemp, SpreadingRateTemp, LithosphericTemp,
1515
ConstantPhase, LithosphericPhases,
1616
Compute_ThermalStructure, Compute_Phase,
1717
McKenzie_subducting_slab, LinearWeightedTemperature
1818

1919

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

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

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

0 commit comments

Comments
 (0)