@@ -8,7 +8,7 @@ module MethodCellTernaryModule
8
8
use CellDefnModule
9
9
use SubcellTriModule, only: SubcellTriType, create_subcell_tri
10
10
use ParticleModule
11
- use GeomUtilModule, only: area
11
+ use GeomUtilModule, only: area, transform
12
12
use ConstantsModule, only: DZERO, DONE, DTWO, DSIX
13
13
use GeomUtilModule, only: point_in_polygon
14
14
implicit none
@@ -158,6 +158,8 @@ subroutine apply_mct(this, particle, tmax)
158
158
real (DP), intent (in ) :: tmax
159
159
! local
160
160
integer (I4B) :: i
161
+ real (DP) :: x, y, z, xO, yO
162
+ real (DP), allocatable :: xs(:), ys(:)
161
163
162
164
! (Re)allocate type-bound arrays
163
165
select type (cell = > this% cell)
@@ -194,10 +196,24 @@ subroutine apply_mct(this, particle, tmax)
194
196
allocate (this% xvertnext(this% nverts))
195
197
allocate (this% yvertnext(this% nverts))
196
198
199
+ ! New origin is the corner of the cell's
200
+ ! bounding box closest to the old origin
201
+ allocate (xs(this% nverts))
202
+ allocate (ys(this% nverts))
203
+ xs = cell% defn% polyvert(1 , :)
204
+ ys = cell% defn% polyvert(2 , :)
205
+ xO = xs(minloc (abs (xs), dim= 1 ))
206
+ yO = ys(minloc (abs (ys), dim= 1 ))
207
+ deallocate (xs)
208
+ deallocate (ys)
209
+
197
210
! Cell vertices
198
211
do i = 1 , this% nverts
199
- this% xvert(i) = cell% defn% polyvert(1 , i)
200
- this% yvert(i) = cell% defn% polyvert(2 , i)
212
+ x = cell% defn% polyvert(1 , i)
213
+ y = cell% defn% polyvert(2 , i)
214
+ call transform(x, y, DZERO, x, y, z, xO, yO)
215
+ this% xvert(i) = x
216
+ this% yvert(i) = y
201
217
end do
202
218
203
219
! Top, bottom, and thickness
@@ -212,13 +228,21 @@ subroutine apply_mct(this, particle, tmax)
212
228
this% iprev = cshift (this% iprev, - 1 )
213
229
this% xvertnext = cshift (this% xvert, 1 )
214
230
this% yvertnext = cshift (this% yvert, 1 )
215
- end select
216
231
217
- ! Calculate vertex velocities.
218
- call this% vertvelo()
232
+ ! Calculate vertex velocities.
233
+ call this% vertvelo()
234
+
235
+ ! Transform particle coordinates
236
+ call particle% transform(xO, yO)
237
+
238
+ ! Track the particle across the cell.
239
+ call this% track(particle, 2 , tmax)
219
240
220
- ! Track the particle across the cell.
221
- call this% track(particle, 2 , tmax)
241
+ ! Transform particle coordinates back
242
+ call particle% transform(xO, yO, invert= .true. )
243
+ call particle% reset_transform()
244
+
245
+ end select
222
246
223
247
end subroutine apply_mct
224
248
@@ -403,16 +427,11 @@ subroutine vertvelo(this)
403
427
sixa = areacell * DSIX
404
428
wk1 = - (this% xvert * this% yvertnext - this% xvertnext * this% yvert)
405
429
nvert = size (this% xvert)
406
- if (nvert == 3 ) then
407
- this% xctr = sum (this% xvert) / 3.0_DP
408
- this% yctr = sum (this% yvert) / 3.0_DP
409
- else
410
- this% xctr = sum ((this% xvert + this% xvertnext) * wk1) / sixa
411
- this% yctr = sum ((this% yvert + this% yvertnext) * wk1) / sixa
412
- end if
430
+ this% xctr = sum ((this% xvert + this% xvertnext) * wk1) / sixa
431
+ this% yctr = sum ((this% yvert + this% yvertnext) * wk1) / sixa
413
432
414
- ! TODO: do we need to check if center is in polygon?
415
- ! only if using the centroid method which misbehaves
433
+ ! TODO: can we use some of the terms of the centroid calculation
434
+ ! to do a cheap point in polygon check?
416
435
!
417
436
! allocate(poly(2, nvert))
418
437
! poly(1,:) = this%xvert
0 commit comments