Skip to content

Commit

Permalink
vars on separate lines in ternarysolvetrack and method types, draft f…
Browse files Browse the repository at this point in the history
…ortran style check script
  • Loading branch information
wpbonelli committed Feb 10, 2024
1 parent c340d91 commit 133e313
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 189 deletions.
115 changes: 115 additions & 0 deletions .github/common/fortran_style_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import argparse
from pathlib import Path
from contextlib import nullcontext
from warnings import warn


def separate_lines(path, overwrite=False):
"""Variables defined on separate lines"""
lines = open(path, "r").read().splitlines()
with (open(path, "w") if overwrite else nullcontext()) as f :
for line in lines:
rprt = line.rpartition("::")
if len(rprt[0]) == 0 and len(rprt[1]) == 0:
if overwrite:
f.write(line + "\n")
else:
print(line)
continue
if "(" in rprt[2] or ")" in rprt[2]:
if overwrite:
f.write(line + "\n")
else:
print(line)
continue
typ = rprt[0].split(",")[0].strip()
spl = rprt[2].split(",")
if len(spl) == 1:
if overwrite:
f.write(line + "\n")
else:
print(line)
continue
prev = ""
for s in spl:
l = typ + " :: " + s.strip()
prev += l if "(" in s else ""
if prev:
prev += ","
continue
if overwrite:
f.write(prev + l + "\n")
else:
print(prev + l)
prev = ""


def no_return_statements(path, overwrite=False):
"""Remove return statements at the end of routines"""
# todo
pass


def no_empty_comments(path, overwrite=False):
"""Remove comments on lines with only whitespace"""
# todo
pass


if __name__ == "__main__":
parser = argparse.ArgumentParser(
"MODFLOW 6 fortran format source code style checks"
)
parser.add_argument(
"-i",
"--input",
help="path to input file" # todo: or directory
)
parser.add_argument(
"-f",
"--force",
action="store_true",
default=False,
required=False,
help="overwrite/reformat files",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
required=False,
help="show verbose output",
)
parser.add_argument(
"--sep-lines",
action="store_true",
default=True,
required=False,
help="define variables on separate lines",
)
parser.add_argument(
"--no-return",
action="store_true",
default=False,
required=False,
help="no return statements at the end of routines",
)
parser.add_argument(
"--no-emptyc",
action="store_true",
default=False,
required=False,
help="no empty comments"
)
args = parser.parse_args()
input_path = Path(args.input).expanduser().absolute()
if args.sep_lines:
separate_lines(input_path, overwrite=args.force)
if args.no_return:
no_return_statements(input_path, overwrite=args.force)
warn("--no-return not implemented yet")
if args.no_emptyc:
no_empty_comments(input_path, overwrite=args.force)
warn("--no-emptyc not implemented yet")

47 changes: 38 additions & 9 deletions src/Solution/ParticleTracker/MethodCellTernary.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ module MethodCellTernaryModule
private
real(DP), allocatable :: x_vert(:), y_vert(:) !< cell vertex coordinates
real(DP), allocatable :: vx_vert_polygon(:), vy_vert_polygon(:) !< cell vertex velocities
real(DP) :: xctr, yctr !< cell center coordinates
real(DP) :: vxctr, vyctr !< cell center velocities
real(DP) :: ztop, zbot !< cell top and bottom elevations
real(DP) :: xctr
real(DP) :: yctr !< cell center coordinates
real(DP) :: vxctr
real(DP) :: vyctr !< cell center velocities
real(DP) :: ztop
real(DP) :: zbot !< cell top and bottom elevations
real(DP) :: dz !< cell thickness
real(DP) :: vztop, vzbot !< cell top and bottom velocities
real(DP) :: vztop
real(DP) :: vzbot !< cell top and bottom velocities
integer(I4B), public, pointer :: zeromethod
contains
procedure, public :: apply => apply_mct
Expand Down Expand Up @@ -87,7 +91,10 @@ subroutine pass_mct(this, particle)
class(MethodCellTernaryType), intent(inout) :: this
type(ParticleType), pointer, intent(inout) :: particle
! local
integer(I4B) :: isc, exitFace, inface, npolyverts
integer(I4B) :: isc
integer(I4B) :: exitFace
integer(I4B) :: inface
integer(I4B) :: npolyverts

exitFace = particle%iboundary(3)
isc = particle%idomain(3)
Expand Down Expand Up @@ -275,11 +282,33 @@ subroutine load_subcell(this, particle, subcell)
type(ParticleType), pointer, intent(inout) :: particle
class(SubcellTriType), intent(inout) :: subcell
! -- local
integer(I4B) :: ic, isc, npolyverts
integer(I4B) :: iv0, iv1, ipv0, ipv1
integer(I4B) :: ic
integer(I4B) :: isc
integer(I4B) :: npolyverts
integer(I4B) :: iv0
integer(I4B) :: iv1
integer(I4B) :: ipv0
integer(I4B) :: ipv1
integer(I4B) :: iv
real(DP) :: x0, y0, x1, y1, x2, y2, x1rel, y1rel, x2rel, y2rel, xi, yi
real(DP) :: di2, d02, d12, di1, d01, alphai, betai
real(DP) :: x0
real(DP) :: y0
real(DP) :: x1
real(DP) :: y1
real(DP) :: x2
real(DP) :: y2
real(DP) :: x1rel
real(DP) :: y1rel
real(DP) :: x2rel
real(DP) :: y2rel
real(DP) :: xi
real(DP) :: yi
real(DP) :: di2
real(DP) :: d02
real(DP) :: d12
real(DP) :: di1
real(DP) :: d01
real(DP) :: alphai
real(DP) :: betai
real(DP) :: betatol

select type (cell => this%cell)
Expand Down
58 changes: 47 additions & 11 deletions src/Solution/ParticleTracker/MethodDis.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module MethodDisModule
procedure, public :: apply => apply_dis ! apply the method
procedure, public :: destroy !< destructor for the method
procedure, public :: load => load_dis ! load the method
procedure, public :: load_cell_defn !< load cell definition from the grid,
procedure :: load_cell_defn !< load cell definition from the grid
procedure, public :: pass => pass_dis !< pass the particle to the next domain
procedure, private :: get_top ! get cell top elevation
procedure, private :: load_nbrs_to_defn ! load face neighbors
Expand Down Expand Up @@ -62,11 +62,19 @@ subroutine load_dis(this, particle, next_level, submethod)
integer(I4B), intent(in) :: next_level
class(MethodType), pointer, intent(inout) :: submethod
! -- local
integer(I4B) :: ic, icu
integer(I4B) :: irow, jcol, klay
real(DP) :: areax, areay, areaz
real(DP) :: dx, dy, dz
real(DP) :: factor, term
integer(I4B) :: ic
integer(I4B) :: icu
integer(I4B) :: irow
integer(I4B) :: jcol
integer(I4B) :: klay
real(DP) :: areax
real(DP) :: areay
real(DP) :: areaz
real(DP) :: dx
real(DP) :: dy
real(DP) :: dz
real(DP) :: factor
real(DP) :: term

select type (cell => this%cell)
type is (CellRectType)
Expand Down Expand Up @@ -134,8 +142,22 @@ subroutine pass_dis(this, particle)
class(MethodDisType), intent(inout) :: this
type(ParticleType), pointer, intent(inout) :: particle
! -- local
integer(I4B) :: inface, ipos, ic, icu, inbr, idiag, ilay, irow, icol
real(DP) :: z, zrel, topfrom, botfrom, top, bot, sat
integer(I4B) :: inface
integer(I4B) :: ipos
integer(I4B) :: ic
integer(I4B) :: icu
integer(I4B) :: inbr
integer(I4B) :: idiag
integer(I4B) :: ilay
integer(I4B) :: irow
integer(I4B) :: icol
real(DP) :: z
real(DP) :: zrel
real(DP) :: topfrom
real(DP) :: botfrom
real(DP) :: top
real(DP) :: bot
real(DP) :: sat

inface = particle%iboundary(2)
z = particle%z
Expand Down Expand Up @@ -278,8 +300,19 @@ subroutine load_nbrs_to_defn(this, defn)
class(MethodDisType), intent(inout) :: this
type(CellDefnType), pointer, intent(inout) :: defn
! -- local
integer(I4B) :: ic1, ic2, icu1, icu2, j1, iloc, ipos
integer(I4B) :: irow1, irow2, jcol1, jcol2, klay1, klay2
integer(I4B) :: ic1
integer(I4B) :: ic2
integer(I4B) :: icu1
integer(I4B) :: icu2
integer(I4B) :: j1
integer(I4B) :: iloc
integer(I4B) :: ipos
integer(I4B) :: irow1
integer(I4B) :: irow2
integer(I4B) :: jcol1
integer(I4B) :: jcol2
integer(I4B) :: klay1
integer(I4B) :: klay2
integer(I4B) :: iedgeface

! -- Allocate facenbr array
Expand Down Expand Up @@ -339,7 +372,10 @@ subroutine load_flows_to_defn(this, defn)
class(MethodDisType), intent(inout) :: this
type(CellDefnType), intent(inout) :: defn
! -- local
integer(I4B) :: ic, m, n, npolyverts
integer(I4B) :: ic
integer(I4B) :: m
integer(I4B) :: n
integer(I4B) :: npolyverts

ic = defn%icell
npolyverts = defn%npolyverts
Expand Down
Loading

0 comments on commit 133e313

Please sign in to comment.