Skip to content

Commit ef2a286

Browse files
committed
Define behavior of get_cell_t! for GridSurface2D; fix bug in tangent calc
1 parent df89161 commit ef2a286

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/GeometricTools_grid.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,15 @@ function get_cell_t!(out, self::Grid, coor_in, lin, ndivscells)
214214
c2::Int = length(coor_in) >= 2 ? coor_in[2]==0 && ndivscells[2]==0 ? 1 : coor_in[2] : -1
215215
c3::Int = length(coor_in) >= 3 ? coor_in[3]==0 && ndivscells[3]==0 ? 1 : coor_in[3] : -1
216216

217+
# Catch case of 2D quasi dimensional space
218+
if c3==-1 && length(coor_in)<3 && length(ndivscells)<3
219+
c3 -= c3 - 1
220+
end
221+
217222
# ERROR CASE: Coordinates out of bounds
218223
if (c1 > ndivscells[1] && !(c1==1 && ndivscells[1]==0)) ||
219224
(c2 > ndivscells[2] && !(c2==1 && ndivscells[2]==0)) ||
220-
(c3 > ndivscells[3] && !(c3==1 && ndivscells[3]==0)) ||
225+
(length(coor_in)>=3 && c3 > ndivscells[3] && !(c3==1 && ndivscells[3]==0)) ||
221226
c1<=0 || c2<=0 || c3<=0
222227
error("Requested cell $(coor_in) but max cell is $(ndivscells). $((c1, c2, c3))")
223228
end
@@ -308,7 +313,7 @@ function get_cell_t!(out, self::Grid, coor_in, lin, ndivscells)
308313
return out
309314

310315
else
311-
error("Definition of $(self.ndims)-dimensional cells not implemented yet!")
316+
error("Definition of $(self.dims)-dimensional cells not implemented yet!")
312317
end
313318

314319
# end

src/GeometricTools_gridspecials2D.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# AUTHORSHIP
55
* Author : Eduardo J Alvarez
66
7-
* Created : Jan 2024
7+
* Created : Jan 2025
88
* License : MIT License
99
=###############################################################################
1010

@@ -61,27 +61,36 @@ end
6161

6262
get_node(self::GridSurface2D, args...; optargs...) = get_node(self.orggrid, args...; optargs...)
6363
get_cell(self::GridSurface2D, args...; optargs...) = get_cell(self.orggrid, args...; optargs...)
64-
get_cell_t!(self::GridSurface2D, args...; optargs...) = get_cell_t!(self.orggrid, args...; optargs...)
65-
generate_getcellt_args!(self::GridSurface2D, args...; optargs...) = get_cell(self.orggrid, args...; optargs...)
64+
get_cell_t!(out, self::GridSurface2D, args...; optargs...) = get_cell_t!(out, self.orggrid, args...; optargs...)
6665
lintransform!(self::GridSurface2D, args...; optargs...) = lintransform!(self.orggrid, args...; optargs...)
6766

67+
function generate_getcellt_args!(self::GridSurface2D)
68+
69+
# Pre-allocate memory for panel calculation
70+
lin = LinearIndices(self._ndivsnodes)
71+
ndivscells = vcat(self._ndivscells...)
72+
cin = CartesianIndices(Tuple(collect( 1:(d != 0 ? d : 1) for d in self._ndivscells)))
73+
coor = zeros(Int, 2)
74+
out = zeros(Int, 2)
75+
76+
return out, coor, lin, ndivscells, cin
77+
end
78+
79+
6880
get_area(self::GridSurface2D, i) = get_area2D(self._nodes, get_cell(self, i))
6981
function _get_area2D(nodes, panel)
7082
p1, p2 = panel
7183
return sqrt( (nodes[1, p2] - nodes[1, p1])^2 + (nodes[2, p2] - nodes[2, p1])^2 )
7284
end
7385

7486
##### INTERNAL FUNCTIONS ######################################################
75-
_calc_t1_2D(args...) = _calc_t1(args...) / _calc_tnorm_2D(args...)
76-
_calc_t2_2D(args...) = _calc_t2(args...) / _calc_tnorm_2D(args...)
77-
_calc_tnorm_2D(nodes::AbstractMatrix, panel) = sqrt(
78-
(nodes[1, panel[2]] - nodes[1, panel[1]])^2
79-
+ (nodes[2, panel[2]] - nodes[2, panel[1]])^2
80-
)
87+
_calc_t1_2D(nodes::AbstractMatrix, panel) = (nodes[1, panel[2]] - nodes[1, panel[1]]) / _calc_tnorm_2D(nodes, panel)
88+
_calc_t2_2D(nodes::AbstractMatrix, panel) = (nodes[2, panel[2]] - nodes[2, panel[1]]) / _calc_tnorm_2D(nodes, panel)
89+
_calc_tnorm_2D(nodes::AbstractMatrix, panel) = sqrt( (nodes[1, panel[2]] - nodes[1, panel[1]])^2 + (nodes[2, panel[2]] - nodes[2, panel[1]])^2 )
8190

8291
_calc_n1aux_2D(nodes::AbstractMatrix, panel) = -(nodes[2, panel[2]] - nodes[2, panel[1]])
8392
_calc_n2aux_2D(nodes::AbstractMatrix, panel) = nodes[1, panel[2]] - nodes[1, panel[1]]
84-
_calc_nnorm_2D(args...) = sqrt(_calc_n1aux_2D(args...)^2 + _calc_n2aux_2D(args...)^2)
93+
_calc_nnorm_2D(args...) = sqrt( _calc_n1aux_2D(args...)^2 + _calc_n2aux_2D(args...)^2 )
8594
_calc_n1_2D(args...) = _calc_n1aux_2D(args...) / _calc_nnorm_2D(args...)
8695
_calc_n2_2D(args...) = _calc_n2aux_2D(args...) / _calc_nnorm_2D(args...)
8796

0 commit comments

Comments
 (0)