336
337 class(MethodCellTernaryType), intent(inout) :: this
338
339 real(DP) :: term
340 integer(I4B) :: i
341 real(DP) :: perturb
342 real(DP), allocatable, dimension(:) :: xvals
343 real(DP), allocatable, dimension(:) :: yvals
344 real(DP) :: sixa
345 real(DP) :: vm0i0
346 real(DP) :: vm0ival
347 real(DP) :: hcsum0
348 real(DP) :: hcsum
349 real(DP) :: jac
350 real(DP), allocatable, dimension(:) :: wk1
351 real(DP), allocatable, dimension(:) :: wk2
352 real(DP), allocatable, dimension(:) :: unextxnext
353 real(DP), allocatable, dimension(:) :: unextynext
354 real(DP), allocatable, dimension(:) :: le
355 real(DP), allocatable, dimension(:) :: unextx
356 real(DP), allocatable, dimension(:) :: unexty
357 real(DP) :: areacell
358 real(DP), allocatable, dimension(:) :: areasub
359 real(DP) :: divcell
360 real(DP), allocatable, dimension(:) :: li
361 real(DP), allocatable, dimension(:) :: unintx
362 real(DP), allocatable, dimension(:) :: uninty
363 real(DP), allocatable, dimension(:) :: xmid
364 real(DP), allocatable, dimension(:) :: ymid
365 real(DP), allocatable, dimension(:) :: lm
366 real(DP), allocatable, dimension(:) :: umx
367 real(DP), allocatable, dimension(:) :: umy
368 real(DP), allocatable, dimension(:) :: kappax
369 real(DP), allocatable, dimension(:) :: kappay
370 real(DP), allocatable, dimension(:) :: vm0x
371 real(DP), allocatable, dimension(:) :: vm0y
372 real(DP), allocatable, dimension(:) :: vm1x
373 real(DP), allocatable, dimension(:) :: vm1y
374
375 integer(I4B) :: nvert
376
377 select type (cell => this%cell)
378 type is (cellpolytype)
379
380
381 allocate (le(this%nverts))
382 allocate (unextx(this%nverts))
383 allocate (unexty(this%nverts))
384 allocate (areasub(this%nverts))
385 allocate (li(this%nverts))
386 allocate (unintx(this%nverts))
387 allocate (uninty(this%nverts))
388 allocate (xmid(this%nverts))
389 allocate (ymid(this%nverts))
390 allocate (lm(this%nverts))
391 allocate (umx(this%nverts))
392 allocate (umy(this%nverts))
393 allocate (kappax(this%nverts))
394 allocate (kappay(this%nverts))
395 allocate (vm0x(this%nverts))
396 allocate (vm0y(this%nverts))
397 allocate (vm1x(this%nverts))
398 allocate (vm1y(this%nverts))
399 allocate (unextxnext(this%nverts))
400 allocate (unextynext(this%nverts))
401 allocate (wk1(this%nverts))
402 allocate (wk2(this%nverts))
403 allocate (xvals(3))
404 allocate (yvals(3))
405
406
407 wk1 = this%xvertnext - this%xvert
408 wk2 = this%yvertnext - this%yvert
409 le = dsqrt(wk1 * wk1 + wk2 * wk2)
410 unextx = -wk2 / le
411 unexty = wk1 / le
412
413
414 areacell = area(this%xvert, this%yvert)
415 sixa = areacell *
dsix
416 wk1 = -(this%xvert * this%yvertnext - this%xvertnext * this%yvert)
417 nvert = size(this%xvert)
418 this%xctr = sum((this%xvert + this%xvertnext) * wk1) / sixa
419 this%yctr = sum((this%yvert + this%yvertnext) * wk1) / sixa
420
421
422
423
424
425 do i = 1, this%nverts
426 xvals(1) = this%xvert(i)
427 xvals(2) = this%xvertnext(i)
428 xvals(3) = this%xctr
429 yvals(1) = this%yvert(i)
430 yvals(2) = this%yvertnext(i)
431 yvals(3) = this%yctr
432 areasub(i) = area(xvals, yvals)
433 end do
434
435
436 term =
done / (cell%defn%porosity * cell%defn%retfactor * this%dz)
437 do i = 1, this%nverts
438 this%vne(i) = -cell%defn%faceflow(i) * term / le(i)
439 end do
440
441
442 divcell = sum(le * this%vne) / areacell
443
444
445 wk1 = this%xvert - this%xctr
446 wk2 = this%yvert - this%yctr
447 li = dsqrt(wk1 * wk1 + wk2 * wk2)
448 unintx = wk2 / li
449 uninty = -wk1 / li
450
451 unextxnext = cshift(unintx, 1)
452 unextynext = cshift(uninty, 1)
453
454
455 xmid = 5.d-1 * (this%xvert + this%xctr)
456 ymid = 5.d-1 * (this%yvert + this%yctr)
457
458
459 wk1 = cshift(xmid, 1) - xmid
460 wk2 = cshift(ymid, 1) - ymid
461 lm = dsqrt(wk1 * wk1 + wk2 * wk2)
462 umx = wk1 / lm
463 umy = wk2 / lm
464
465
466
467
468
469
470 kappax = umx
471 kappay = umy
472
473
474
475 perturb = 1.d-2
476
477 vm0i0 = 0.d0
478 call this%calc_thru_hcsum(vm0i0, divcell, le, li, lm, areasub, areacell, &
479 unintx, uninty, unextx, unexty, &
480 unextxnext, unextynext, &
481 kappax, kappay, vm0x, vm0y, vm1x, vm1y, hcsum0)
482
483 vm0ival = vm0i0 + perturb
484 call this%calc_thru_hcsum(vm0ival, divcell, le, li, lm, areasub, areacell, &
485 unintx, uninty, unextx, unexty, &
486 unextxnext, unextynext, &
487 kappax, kappay, vm0x, vm0y, vm1x, vm1y, hcsum)
488
489 jac = (hcsum - hcsum0) / perturb
490 vm0ival = vm0i0 - hcsum0 / jac
491 call this%calc_thru_hcsum(vm0ival, divcell, le, li, lm, areasub, areacell, &
492 unintx, uninty, unextx, unexty, &
493 unextxnext, unextynext, &
494 kappax, kappay, vm0x, vm0y, vm1x, vm1y, hcsum)
495
496
497
498
499 this%vv0x = 2.d0 * vm0x - this%vctrx
500 this%vv0y = 2.d0 * vm0y - this%vctry
501 this%vv1x = 2.d0 * vm1x - this%vctrx
502 this%vv1y = 2.d0 * vm1y - this%vctry
503
504
505 term =
done / (cell%defn%retfactor * cell%defn%porosity * areacell)
506 this%vzbot = cell%defn%faceflow(this%nverts + 2) * term
507 this%vztop = -cell%defn%faceflow(this%nverts + 3) * term
508
509
510 deallocate (le)
511 deallocate (unextx)
512 deallocate (unexty)
513 deallocate (areasub)
514 deallocate (li)
515 deallocate (unintx)
516 deallocate (uninty)
517 deallocate (xmid)
518 deallocate (ymid)
519 deallocate (lm)
520 deallocate (umx)
521 deallocate (umy)
522 deallocate (kappax)
523 deallocate (kappay)
524 deallocate (vm0x)
525 deallocate (vm0y)
526 deallocate (vm1x)
527 deallocate (vm1y)
528 deallocate (unextxnext)
529 deallocate (unextynext)
530 deallocate (wk1)
531 deallocate (wk2)
532 deallocate (xvals)
533 deallocate (yvals)
534
535 end select
real(dp), parameter dsix
real constant 6