320
321 class(DisuType) :: this
322
323 integer(I4B) :: n, m
324 integer(I4B) :: ipos, jpos, kpos
325 integer(I4B) :: ihc
326 integer(I4B) :: nsym, ndir, nvrt, nwarn
327 logical :: found
328 real(DP) :: dz
329 real(DP) :: angn, angm, dang
330 real(DP) :: dx, dy, dist, cosang, angc
331 real(DP) :: xnorm, ynorm, angv
332 real(DP) :: angn_sym, angm_sym
333 real(DP) :: angn_dir, angc_dir
334 real(DP) :: angn_vrt, angv_vrt
335 real(DP) :: angn_warn, angc_warn
336 integer(I4B) :: n_sym, m_sym
337 integer(I4B) :: n_dir, m_dir
338 integer(I4B) :: n_vrt, m_vrt
339 integer(I4B) :: n_warn, m_warn
340 character(len=LENBIGLINE) :: bigmsg
341 real(DP), parameter :: angtol = 0.01_dp
342 real(DP), parameter :: angvtol = 1.0_dp
343 real(DP), parameter :: cos45 = 0.70710678118654752_dp
344
345 character(len=*), parameter :: fmtidm = &
346 &"('Invalid idomain value ', i0, ' specified for node ', i0)"
347 character(len=*), parameter :: fmtangsym = &
348 "('ANGLDEGX values for ', i0, ' cell faces associated with &
349 &horizontal connections in the DISU Package are inconsistent with &
350 &the values for the reverse connections (for example, ANGLDEGX = ', &
351 &f0.3, ' for the connection from cell ', i0, ' to cell ', i0, &
352 &' and ANGLDEGX = ', f0.3, ' for the connection from cell ', i0, &
353 &' to cell ', i0, '). The two values must differ by 180 degrees &
354 &(within 0.01 degrees) because they are the outward normals of the &
355 &two sides of the same cell face. Only the value for the connection &
356 &from the lower to the higher cell number is used.')"
357 character(len=*), parameter :: fmtangdir = &
358 "('ANGLDEGX values for ', i0, ' cell faces associated with &
359 &horizontal connections in the DISU Package point away from the &
360 &connected cell (for example, ANGLDEGX = ', f0.3, ' for the &
361 &connection from cell ', i0, ' to cell ', i0, ', but the direction &
362 &from the center of cell ', i0, ' to the center of cell ', i0, &
363 &' is ', f0.3, ' degrees). The centers of two connected cells must &
364 &lie on opposite sides of their shared face, so ANGLDEGX, the &
365 &outward normal of the face, must be within 90 degrees of the &
366 &direction from the cell center to the center of the connected &
367 &cell, in the coordinate system of the VERTICES.')"
368 character(len=*), parameter :: fmtangvrt = &
369 "('ANGLDEGX values for ', i0, ' cell faces associated with &
370 &horizontal connections in the DISU Package differ by more than 1 &
371 °ree from the outward normal of the face computed from the two &
372 &VERTICES shared by the connected cells (for example, ANGLDEGX = ', &
373 &f0.3, ' for the connection from cell ', i0, ' to cell ', i0, &
374 &', but the normal computed from the vertices is ', f0.3, &
375 &' degrees). ANGLDEGX must be expressed in the coordinate system of &
376 &the VERTICES.')"
377 character(len=*), parameter :: fmtangwarn = &
378 "('ANGLDEGX values for ', i0, ' cell faces associated with &
379 &horizontal connections in the DISU Package deviate by more than 45 &
380 °rees from the direction between the centers of the connected &
381 &cells (for example, ANGLDEGX = ', f0.3, ' for the connection from &
382 &cell ', i0, ' to cell ', i0, ', but the direction between the cell &
383 ¢ers is ', f0.3, ' degrees). This is not necessarily an error, &
384 &but such connections depart substantially from the assumptions of &
385 &the control-volume finite-difference method and may warrant a &
386 &closer look at the grid.')"
387 character(len=*), parameter :: fmtdz = &
388 &"('Cell ', i0, ' with thickness <= 0. Top, bot: ', 2(1pg24.15))"
389 character(len=*), parameter :: fmtarea = &
390 &"('Cell ', i0, ' with area <= 0. Area: ', 1(1pg24.15))"
391 character(len=*), parameter :: fmtjan = &
392 &"('Cell ', i0, ' must have its first connection be itself. Found: ', i0)"
393 character(len=*), parameter :: fmtjam = &
394 &"('Cell ', i0, ' has invalid connection in JA. Found: ', i0)"
395 character(len=*), parameter :: fmterrmsg = &
396 "('Top elevation (', 1pg15.6, ') for cell ', i0, ' is above bottom &
397 &elevation (', 1pg15.6, ') for cell ', i0, '. Based on node numbering &
398 &rules cell ', i0, ' must be below cell ', i0, '.')"
399
400
401 do n = 1, this%nodesuser
402
403
404
405 ipos = this%iainp(n)
406 m = this%jainp(ipos)
407 if (m < 0) then
408 m = abs(m)
409 this%jainp(ipos) = m
410 end if
411 if (n /= m) then
412 write (errmsg, fmtjan) n, m
413 call store_error(errmsg)
414 end if
415
416
417 do ipos = this%iainp(n) + 1, this%iainp(n + 1) - 1
418 m = this%jainp(ipos)
419 if (m < 0 .or. m > this%nodesuser) then
420
421 write (errmsg, fmtjam) n, m
422 call store_error(errmsg)
423 end if
424 end do
425 end do
426
427
428 if (count_errors() > 0) then
429 if (this%inunit > 0) then
430 call store_error_filename(this%input_fname)
431 end if
432 end if
433
434
435 do n = 1, this%nodesuser
436 if (this%idomain(n) < 0) then
437 write (errmsg, fmtidm) this%idomain(n), n
438 call store_error(errmsg)
439 end if
440 end do
441
442
443
444 do n = 1, this%nodesuser
445 if (this%idomain(n) > 0) then
446 dz = this%top1d(n) - this%bot1d(n)
447 if (dz <= dzero) then
448 write (errmsg, fmt=fmtdz) n, this%top1d(n), this%bot1d(n)
449 call store_error(errmsg)
450 end if
451 if (this%area1d(n) <= dzero) then
452 write (errmsg, fmt=fmtarea) n, this%area1d(n)
453 call store_error(errmsg)
454 end if
455 end if
456 end do
457
458
459 if (this%voffsettol < dzero) then
460 write (errmsg, '(a, 1pg15.6)') &
461 'Vertical offset tolerance must be greater than zero. Found ', &
462 this%voffsettol
463 call store_error(errmsg)
464 if (this%inunit > 0) then
465 call store_error_filename(this%input_fname)
466 end if
467 end if
468
469
470
471 do n = 1, this%nodesuser
472 do ipos = this%iainp(n) + 1, this%iainp(n + 1) - 1
473 m = this%jainp(ipos)
474 ihc = this%ihcinp(ipos)
475 if (ihc == 0 .and. m > n) then
476 dz = this%top1d(m) - this%bot1d(n)
477 if (dz > this%voffsettol) then
478 write (errmsg, fmterrmsg) this%top1d(m), m, this%bot1d(n), n, m, n
479 call store_error(errmsg)
480 end if
481 end if
482 end do
483 end do
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500 if (this%iangledegx == 1) then
501 nsym = 0
502 ndir = 0
503 nvrt = 0
504 nwarn = 0
505 n_sym = 0
506 m_sym = 0
507 n_dir = 0
508 m_dir = 0
509 n_vrt = 0
510 m_vrt = 0
511 n_warn = 0
512 m_warn = 0
513 angn_sym = dzero
514 angm_sym = dzero
515 angn_dir = dzero
516 angc_dir = dzero
517 angn_vrt = dzero
518 angv_vrt = dzero
519 angn_warn = dzero
520 angc_warn = dzero
521 do n = 1, this%nodesuser
522 if (this%idomain(n) == 0) cycle
523 do ipos = this%iainp(n) + 1, this%iainp(n + 1) - 1
524 m = this%jainp(ipos)
525 if (m < 1 .or. m > this%nodesuser) cycle
526 if (this%ihcinp(ipos) == 0) cycle
527 if (this%idomain(m) == 0) cycle
528 angn = this%angldegxinp(ipos)
529
530
531
532 if (m > n) then
533 jpos = 0
534 do kpos = this%iainp(m) + 1, this%iainp(m + 1) - 1
535 if (this%jainp(kpos) == n) then
536 jpos = kpos
537 exit
538 end if
539 end do
540 if (jpos > 0) then
541 angm = this%angldegxinp(jpos)
542 dang = modulo(angm - angn, 360.0_dp)
543 if (abs(dang - 180.0_dp) > angtol) then
544 nsym = nsym + 1
545 if (nsym == 1) then
546 n_sym = n
547 m_sym = m
548 angn_sym = angn
549 angm_sym = angm
550 end if
551 end if
552 end if
553 end if
554
555
556 if (this%nvert > 0) then
557 dx = this%cellxy(1, m) - this%cellxy(1, n)
558 dy = this%cellxy(2, m) - this%cellxy(2, n)
559 dist = sqrt(dx * dx + dy * dy)
560 if (dist > dzero) then
561 cosang = (cos(angn * dpio180) * dx + &
562 sin(angn * dpio180) * dy) / dist
563 angc = modulo(atan2(dy, dx) / dpio180, 360.0_dp)
564 if (cosang <= dzero) then
565 ndir = ndir + 1
566 if (ndir == 1) then
567 n_dir = n
568 m_dir = m
569 angn_dir = angn
570 angc_dir = angc
571 end if
572 else if (cosang < cos45) then
573 nwarn = nwarn + 1
574 if (nwarn == 1) then
575 angn_warn = angn
576 angc_warn = angc
577 n_warn = n
578 m_warn = m
579 end if
580 end if
581 end if
582
583
584
585
586 if (m > n) then
587 call this%disu_face_normal(n, m, found, xnorm, ynorm)
588 if (found) then
589 angv = modulo(atan2(ynorm, xnorm) / dpio180, 360.0_dp)
590 dang = abs(modulo(angn - angv + 180.0_dp, 360.0_dp) - 180.0_dp)
591 if (dang > angvtol) then
592 nvrt = nvrt + 1
593 if (nvrt == 1) then
594 n_vrt = n
595 m_vrt = m
596 angn_vrt = angn
597 angv_vrt = angv
598 end if
599 end if
600 end if
601 end if
602 end if
603 end do
604 end do
605 this%nangldegxerr = nsym + ndir + nvrt
606
607
608
609
610 if (nsym > 0) then
611 write (bigmsg, fmtangsym) nsym, angn_sym, n_sym, m_sym, &
612 angm_sym, m_sym, n_sym
613 call store_warning(bigmsg)
614 call this%disu_write_warning(bigmsg)
615 end if
616 if (ndir > 0) then
617 write (bigmsg, fmtangdir) ndir, angn_dir, n_dir, m_dir, &
618 n_dir, m_dir, angc_dir
619 call store_warning(bigmsg)
620 call this%disu_write_warning(bigmsg)
621 end if
622 if (nvrt > 0) then
623 write (bigmsg, fmtangvrt) nvrt, angn_vrt, n_vrt, m_vrt, angv_vrt
624 call store_warning(bigmsg)
625 call this%disu_write_warning(bigmsg)
626 end if
627 if (nwarn > 0) then
628 write (bigmsg, fmtangwarn) nwarn, angn_warn, n_warn, m_warn, angc_warn
629 call store_warning(bigmsg)
630 call this%disu_write_warning(bigmsg)
631 end if
632 end if
633
634
635 if (count_errors() > 0) then
636 if (this%inunit > 0) then
637 call store_error_filename(this%input_fname)
638 end if
639 end if
640