4242
4343This converts the indices to purely 2D indices if the array `phase` is 2D
4444"""
45- function flatten_index_dimensions (Phase, ind_vec:: Array{Bool, 3} )
46- if length ( size (Phase)) == 2
45+ function flatten_index_dimensions (Phase:: AbstractArray{T, N} , ind_vec:: Array{Bool, 3} ) where {T,N}
46+ if N == 2
4747 ind2D = Vector {CartesianIndex{2}} (undef,length (ind_vec))
4848 for (num, ind) in enumerate (ind_vec)
4949 ind2D[num] = CartesianIndex (ind[1 ], ind[3 ])
@@ -1985,41 +1985,44 @@ add_fault!(Phase, Temp, Grid;
19851985 )
19861986```
19871987"""
1988- function add_fault! (Phase, Temp, Grid:: AbstractGeneralGrid ;
1989- Start= (20 ,100 ), End= (10 ,80 ),
1988+ function add_fault! (
1989+ Phase,
1990+ Temp,
1991+ Grid:: AbstractGeneralGrid ;
1992+ Start= (20 ,100 ),
1993+ End= (10 ,80 ),
19901994 Fault_thickness= 10.0 ,
19911995 Depth_extent= nothing ,
19921996 DipAngle= 0e0 ,
19931997 phase= ConstantPhase (1 ),
19941998 T= nothing ,
1995- cell= false )
1999+ cell= false
2000+ )
19962001
19972002 # Extract the coordinates
19982003 X, Y, Z = coordinate_grids (Grid, cell= cell)
19992004
20002005 # Calculate the direction vector from Start to End
20012006 direction = (End[1 ] - Start[1 ], End[2 ] - Start[2 ])
20022007 length = sqrt (direction[1 ]^ 2 + direction[2 ]^ 2 )
2003- unit_direction = (direction[1 ] / length , direction[2 ] / length)
2008+ unit_direction = (direction[1 ], direction[2 ]) . / length
20042009
20052010 # Calculate the fault region based on fault thickness and length
2006- fault_half_thickness = Fault_thickness / 2.0
2011+ fault_half_thickness = Fault_thickness / 2
20072012
20082013 # Create a mask for the fault region
20092014 fault_mask = falses (size (X))
20102015
2011- for i in 1 : size (X, 1 )
2012- for j in 1 : size (Y, 2 )
2013- for k in 1 : size (Z, 3 )
2016+ for k in 1 : size (Z, 3 ), j in 1 : size (Y, 2 ), i in 1 : size (X, 1 )
20142017 # Rotate the point using the dip angle
20152018 x_rot, y_rot, z_rot = Rot3D (X[i, j, k], Y[i, j, k], Z[i, j, k], 1.0 , 0.0 , cosd (DipAngle), sind (DipAngle))
20162019
20172020 # Calculate the projection of the rotated point onto the fault line
20182021 projection_length = (x_rot - Start[1 ]) * unit_direction[1 ] + (y_rot - Start[2 ]) * unit_direction[2 ]
2019- if projection_length >= 0 && projection_length <= length
2022+ if 0 ≤ projection_length ≤ length
20202023 # Calculate the perpendicular distance to the fault line
20212024 perpendicular_distance = abs ((x_rot - Start[1 ]) * unit_direction[2 ] - (y_rot - Start[2 ]) * unit_direction[1 ])
2022- if perpendicular_distance <= fault_half_thickness
2025+ if perpendicular_distance ≤ fault_half_thickness
20232026 fault_mask[i, j, k] = true
20242027 end
20252028 end
@@ -2031,7 +2034,7 @@ function add_fault!(Phase, Temp, Grid::AbstractGeneralGrid;
20312034
20322035 # Apply depth extent if provided
20332036 if ! isnothing (Depth_extent)
2034- ind = ind[Z[ind] .>= Depth_extent[1 ] .&& Z[ind] .<= Depth_extent[2 ]]
2037+ ind = ind[Z[ind] .≥ Depth_extent[1 ] .&& Z[ind] .≤ Depth_extent[2 ]]
20352038 end
20362039
20372040 ind_flat = flatten_index_dimensions (Phase, ind)
0 commit comments