Hi everyone. I am new to Julia. Just started a week ago.
I am trying to do a Monte Carlo kind of code and these functions are a part of it.
function GetTime(ray0, F_Sp)
Snodes=zeros(size(ray0,1),1); #iniciate variable
#Loop to evaluate slowness
for ri=1:size(ray0,1)
Snodes[ri]=F_Sp(ray0[ri,1],ray0[ri,2],ray0[ri,3]);
end
#mean slowness in every path
B=(Snodes[1:end-1].+Snodes[2:end]).*0.5;
#Distance between nodes
C=((diff(ray0[:,1]).*diff(ray0[:,1]))+(diff(ray0[:,2]).*diff(ray0[:,2]))+(diff(ray0[:,3]).*diff(ray0[:,3]))).^(1/2);
#traveltime
T=sum(B.*C);
return T
end
function RayBender(ray0,dz,dray,zmax,dr,F_Sp)
T0=GetTime(ray0, F_Sp);
movedz=dz*dray;
NCC=0;
while NCC<dr-2
NCC=0;
for p=2:dr-1
#Bend a point of the ray up and down
#Also get the travel time of each test
rayz1=[ray0[1:p-1,3] ; ray0[p,3]+movedz; ray0[p+1:end,3]];
#rayz1[rayz1.>zmax] .= zmax;
T1=GetTime([collect(ray0[:,1]) collect(ray0[:,2]) collect(rayz1)],F_Sp);
rayz2=[ray0[1:p-1,3] ; ray0[p,3]-movedz; ray0[p+1:end,3]];
T2=GetTime([collect(ray0[:,1]) collect(ray0[:,2]) collect(rayz2)],F_Sp);
if T1<T0 && T1<T2 # If RAY 1 is the solution
ray0=[collect(ray0[:,1]) collect(ray0[:,2]) collect(rayz1)];
T0=T1;
#println("T1")
elseif T2<T0 && T2<T1 # If RAY 2 is the solution
ray0=[collect(ray0[:,1]) collect(ray0[:,2]) collect(rayz2)];
T0=T2;
#println("T2")
else
NCC=NCC+1; # Keep Count of NO CHANGES
end
end
end
return T0,ray0
end
I have a path (ray) that crosses a box of velocity. F_Sp is the interpolated 3D slowness function at any point.
I need to call them like 2e14 times so i need it to be VERY FAST.
Can any one give me some tips?
The first one just calculates the travel time and the second one bends an initially linear ray into the real one.