Skip to content

Commit 4a8d48f

Browse files
committed
use static arrays
1 parent 577227e commit 4a8d48f

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/Setup_geometry.jl

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,9 +1510,7 @@ function find_slab_distance!(ls, d, X,Y,Z, Top, Bottom, trench::Trench)
15101510

15111511
# dl
15121512
dl = L0/n_seg;
1513-
15141513
l = 0 # length at the trench position
1515-
15161514
D = @SVector [0.0, -D0,-D0,0.0]
15171515

15181516
# Construct the slab
@@ -1527,8 +1525,8 @@ function find_slab_distance!(ls, d, X,Y,Z, Top, Bottom, trench::Trench)
15271525
pd = (Top[i+1,1],Top[i+1,2]) # D = 0| L = L+dl
15281526

15291527
# Create the polygon
1530-
poly_y = [pa[1],pb[1],pc[1],pd[1]];
1531-
poly_z = [pa[2],pb[2],pc[2],pd[2]];
1528+
poly_y = @SVector [pa[1],pb[1],pc[1],pd[1]];
1529+
poly_z = @SVector [pa[2],pb[2],pc[2],pd[2]];
15321530

15331531
# find a sub set of particles
15341532
ymin,ymax = extrema(poly_y);
@@ -1542,33 +1540,25 @@ function find_slab_distance!(ls, d, X,Y,Z, Top, Bottom, trench::Trench)
15421540

15431541
# Initialize the ind that are going to be used by inpoly
15441542
ind = zeros(Bool,size(zp));
1545-
1546-
# inPoly! [Written by Arne Spang, must be updated with the new version]
1547-
inPolygon!(ind,poly_y,poly_z,yp,zp);
1543+
inPolygon!(ind,poly_y,poly_z,yp,zp); # determine whether points are inside the polygon or not
15481544

15491545
# indexes of the segment
15501546
ind_seg = ind_s[ind]
15511547

15521548
# Prepare the variable to interpolate {I put here because to allow also a variation of thickness of the slab}
1553-
15541549
L = @SVector [l,l,ln,ln];
15551550

15561551
# Interpolations
1557-
points = [pa[1] pa[2];pb[1] pb[2];pc[1] pc[2];pd[1] pd[2]]'
1552+
points = @SMatrix [pa[1] pb[1] pc[1] pd[1]; pa[2] pb[2] pc[2] pd[2]]
15581553

15591554
itp1 = ScatteredInterpolation.interpolate(Shepard(), points, D);
1560-
15611555
itp2 = ScatteredInterpolation.interpolate(Shepard(), points, L);
15621556

15631557
# Loop over the chosen particles and interpolate the current value of L and D.
1564-
particle_n = length(ind_seg)
1565-
1566-
for ip = 1:particle_n
1567-
1568-
point_ = [Yrot[ind_seg[ip]],Z[ind_seg[ip]]];
1569-
1570-
d[ind_seg[ip]] = ScatteredInterpolation.evaluate(itp1,point_)[1];
1571-
ls[ind_seg[ip]] = ScatteredInterpolation.evaluate(itp2,point_)[1];
1558+
for ip in ind_seg
1559+
point_ = [Yrot[ip], Z[ip]];
1560+
d[ip] = ScatteredInterpolation.evaluate(itp1,point_)[1];
1561+
ls[ip] = ScatteredInterpolation.evaluate(itp2,point_)[1];
15721562
end
15731563

15741564
#Update l

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ end
16711671
Same as above but `inside`, `X` and `Y` and are vectors.
16721672
16731673
"""
1674-
function inPolygon!(inside::Vector{Bool}, PolyX::Vector{T}, PolyY::Vector{T}, x::Vector{T}, y::Vector{T}; fast=false) where T <: Real
1674+
function inPolygon!(inside::Vector{Bool}, PolyX::AbstractVector{T}, PolyY::AbstractVector{T}, x::Vector{T}, y::Vector{T}; fast=false) where T <: Real
16751675
if fast
16761676
for i = eachindex(x)
16771677
inside[i] = inPolyPointF(PolyX, PolyY, x[i], y[i])
@@ -1689,7 +1689,7 @@ end
16891689
Checks if a point given by x and y is in or on (both cases return true) a polygon given by PolyX and PolyY, iSteps and jSteps provide the connectivity between the polygon edges. This function should be used through inPolygon!().
16901690
16911691
"""
1692-
function inPolyPoint(PolyX::Vector{T}, PolyY::Vector{T}, x::T, y::T) where T <: Real
1692+
function inPolyPoint(PolyX::AbstractVector{T}, PolyY::AbstractVector{T}, x::T, y::T) where T <: Real
16931693
inside1, inside2, inside3, inside4 = false, false, false, false
16941694
n = length(PolyX)
16951695
for i in eachindex(PolyX)

0 commit comments

Comments
 (0)