Skip to content

Commit 59550cd

Browse files
committed
add StaticArrays for Rot3D
1 parent 1320014 commit 59550cd

File tree

2 files changed

+18
-46
lines changed

2 files changed

+18
-46
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
2424
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2525
ScatteredInterpolation = "3f865c0f-6dca-5f4d-999b-29fe1e7e3c92"
2626
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
27+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2728
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2829
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2930
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
@@ -53,8 +54,9 @@ JLD2 = "0.4"
5354
MeshIO = "0.1 - 0.4"
5455
NearestNeighbors = "0.2 - 0.4"
5556
Parameters = "0.9 - 0.12"
56-
SpecialFunctions = "1.0, 2"
5757
ScatteredInterpolation = "0.3"
58+
SpecialFunctions = "1.0, 2"
59+
StaticArrays = "1"
5860
WriteVTK = "1"
5961
julia = "1.9"
6062

src/Setup_geometry.jl

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ using Printf
33
using Parameters # helps setting default parameters in structures
44
using SpecialFunctions: erfc
55
using GeoParams
6-
using ScatteredInterpolation
6+
using ScatteredInterpolation
7+
using StaticArrays
78

89
# Setup_geometry
910
#
@@ -561,21 +562,6 @@ end
561562
# Internal function that rotates the coordinates
562563
function Rot3D!(X,Y,Z, StrikeAngle, DipAngle)
563564

564-
#=
565-
# rotation matrixes
566-
roty = [cosd(-DipAngle) 0 sind(-DipAngle) ; 0 1 0 ; -sind(-DipAngle) 0 cosd(-DipAngle)];
567-
rotz = [cosd(StrikeAngle) -sind(StrikeAngle) 0 ; sind(StrikeAngle) cosd(StrikeAngle) 0 ; 0 0 1]
568-
569-
for i in eachindex(X)
570-
CoordVec = [X[i], Y[i], Z[i]]
571-
CoordRot = rotz*CoordVec;
572-
CoordRot = roty*CoordRot;
573-
X[i] = CoordRot[1];
574-
Y[i] = CoordRot[2];
575-
Z[i] = CoordRot[3];
576-
end
577-
=#
578-
579565
# precompute trigonometric functions (expensive!)
580566
sindStrikeAngle, cosStrikeAngle = sincosd(StrikeAngle)
581567
sinDipAngle, cosDipAngle = sincosd(-DipAngle) # note the minus here to be consistent with the earlier version of the code
@@ -591,14 +577,14 @@ end
591577
592578
Perform rotation for a point in 3D space
593579
"""
594-
function Rot3D(X::Number,Y::Number,Z::Number, cosStrikeAngle, sindStrikeAngle, cosDipAngle, sinDipAngle)
580+
function Rot3D(X::_T,Y::_T,Z::_T, cosStrikeAngle::_T, sindStrikeAngle::_T, cosDipAngle::_T, sinDipAngle::_T) where _T<:Number
595581

596582
# rotation matrixes
597583
#roty = [cosd(-DipAngle) 0 sind(-DipAngle) ; 0 1 0 ; -sind(-DipAngle) 0 cosd(-DipAngle)];
598-
roty = [cosDipAngle 0 sinDipAngle ; 0 1 0 ; -sinDipAngle 0 cosDipAngle]; # note that dip-angle is changed from before!
599-
rotz = [cosStrikeAngle -sindStrikeAngle 0 ; sindStrikeAngle cosStrikeAngle 0 ; 0 0 1]
584+
roty = @SMatrix [cosDipAngle 0 sinDipAngle ; 0 1 0 ; -sinDipAngle 0 cosDipAngle]; # note that dip-angle is changed from before!
585+
rotz = @SMatrix [cosStrikeAngle -sindStrikeAngle 0 ; sindStrikeAngle cosStrikeAngle 0 ; 0 0 1]
600586

601-
CoordVec = [X, Y, Z]
587+
CoordVec = @SVector [X, Y, Z]
602588
CoordRot = rotz*CoordVec;
603589
CoordRot = roty*CoordRot;
604590

@@ -1506,12 +1492,13 @@ end
15061492
=#
15071493

15081494
"""
1509-
find_slab!(ls, d, X,Y,Z, Start, End, Top, Bottom, seg_slab, D0, L0)
1495+
find_slab_distance!(ls, d, X,Y,Z, trench::Trench)
15101496
15111497
Function that finds the perpendicular distance to the top and bottom of the slab `d`, and the current length of the slab `l`.
15121498
15131499
"""
1514-
function find_slab!(ls, d, X,Y,Z, Start, End,Top,Bottom,seg_slab,D0,L0,direction)
1500+
function find_slab_distance!(ls, d, X,Y,Z, Top, Bottom, trench::Trench)
1501+
@unpack D0, L0, n_seg, Start, End, direction = trench;
15151502

15161503
# Perform rotation of 3D coordinates along the angle from Start -> End:
15171504
Xrot = X .- Start[1];
@@ -1521,20 +1508,18 @@ function find_slab!(ls, d, X,Y,Z, Start, End,Top,Bottom,seg_slab,D0,L0,direction
15211508

15221509
xb = Rot3D(End[1]-Start[1],End[2]-Start[2], 0.0, cosd(StrikeAngle), sind(StrikeAngle), 1.0, 0.0)
15231510

1524-
#xb1 = transform_coordinate!(X,Y,Z,Xrot,Yrot,Start,End,direction);
1525-
15261511
# dl
1527-
dl = L0/seg_slab;
1512+
dl = L0/n_seg;
15281513

15291514
l = 0 # length at the trench position
15301515

15311516
# Construct the slab
1532-
for i = 1:(seg_slab-1)
1517+
for i = 1:(n_seg-1)
15331518

15341519
ln = l+dl;
15351520

1536-
pa = (Top[i,1],Top[i,2]); # D = 0 | L = l
1537-
pb = (Bottom[i,1],Bottom[i,2]); # D = -D0 | L=l
1521+
pa = (Top[i,1], Top[i,2]); # D = 0 | L = l
1522+
pb = (Bottom[i,1], Bottom[i,2]); # D = -D0 | L=l
15381523

15391524
pc = (Bottom[i+1,1],Bottom[i+1,2]); # D = -D0 |L=L+dl
15401525
pd = (Top[i+1,1],Top[i+1,2]) # D = 0| L = L+dl
@@ -1554,7 +1539,6 @@ function find_slab!(ls, d, X,Y,Z, Start, End,Top,Bottom,seg_slab,D0,L0,direction
15541539

15551540
# Find the particles
15561541
yp = Yrot[ind_s];
1557-
15581542
zp = Z[ind_s];
15591543

15601544
# Initialize the ind that are going to be used by inpoly
@@ -1595,20 +1579,6 @@ function find_slab!(ls, d, X,Y,Z, Start, End,Top,Bottom,seg_slab,D0,L0,direction
15951579
end
15961580

15971581

1598-
"""
1599-
1600-
Internal routine which finds distance perpendicular (`d`) and along (`ls`) the slab, as specified in `trench`.
1601-
"""
1602-
function find_slab_distance!(ls, d, trench, Top, Bottom, X,Y,Z)
1603-
@unpack D0, L0, n_seg, Start, End, direction = trench;
1604-
1605-
# Finds the distance to the slab
1606-
GeophysicalModelGenerator.find_slab!(ls, d, X,Y,Z, Start,End, Top,Bottom,n_seg,D0,L0,direction);
1607-
1608-
return nothing
1609-
end
1610-
1611-
16121582

16131583
"""
16141584
addSlab!(Phase, Temp, Grid::AbstractGeneralGrid, trench::Trench; phase = ConstantPhase(1), T = nothing)
@@ -1657,10 +1627,10 @@ function addSlab!(Phase, Temp, Grid::AbstractGeneralGrid, trench::Trench;
16571627
Top,Bottom = compute_slab_surface(trench);
16581628

16591629
# Find the distance to the slab (along & perpendicular)
1660-
find_slab_distance!(ls, d, trench, Top, Bottom, X,Y,Z );
1630+
find_slab_distance!(ls, d, X,Y,Z, Top, Bottom, trench);
16611631

16621632
# Function to fill up the temperature and the phase.
1663-
ind = findall((-trench.D0 .<= d .<= 0.0));
1633+
ind = findall((-trench.D0 .<= d .<= 0.0));Grid
16641634

16651635
if isa(T, LinearWeightedTemperature)
16661636
l_decouplingind = findall(Top[:,2].<=-trench.d_decoupling);

0 commit comments

Comments
 (0)