42
42
43
43
This converts the indices to purely 2D indices if the array `phase` is 2D
44
44
"""
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
47
47
ind2D = Vector {CartesianIndex{2}} (undef,length (ind_vec))
48
48
for (num, ind) in enumerate (ind_vec)
49
49
ind2D[num] = CartesianIndex (ind[1 ], ind[3 ])
@@ -1985,41 +1985,44 @@ add_fault!(Phase, Temp, Grid;
1985
1985
)
1986
1986
```
1987
1987
"""
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 ),
1990
1994
Fault_thickness= 10.0 ,
1991
1995
Depth_extent= nothing ,
1992
1996
DipAngle= 0e0 ,
1993
1997
phase= ConstantPhase (1 ),
1994
1998
T= nothing ,
1995
- cell= false )
1999
+ cell= false
2000
+ )
1996
2001
1997
2002
# Extract the coordinates
1998
2003
X, Y, Z = coordinate_grids (Grid, cell= cell)
1999
2004
2000
2005
# Calculate the direction vector from Start to End
2001
2006
direction = (End[1 ] - Start[1 ], End[2 ] - Start[2 ])
2002
2007
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
2004
2009
2005
2010
# 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
2007
2012
2008
2013
# Create a mask for the fault region
2009
2014
fault_mask = falses (size (X))
2010
2015
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 )
2014
2017
# Rotate the point using the dip angle
2015
2018
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))
2016
2019
2017
2020
# Calculate the projection of the rotated point onto the fault line
2018
2021
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
2020
2023
# Calculate the perpendicular distance to the fault line
2021
2024
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
2023
2026
fault_mask[i, j, k] = true
2024
2027
end
2025
2028
end
@@ -2031,7 +2034,7 @@ function add_fault!(Phase, Temp, Grid::AbstractGeneralGrid;
2031
2034
2032
2035
# Apply depth extent if provided
2033
2036
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 ]]
2035
2038
end
2036
2039
2037
2040
ind_flat = flatten_index_dimensions (Phase, ind)
0 commit comments