Skip to content

Commit

Permalink
Merge branch 'modernize-fortran' of github.com:mdolab/adflow into mod…
Browse files Browse the repository at this point in the history
…ernize-fortran
  • Loading branch information
eirikurj committed Oct 7, 2022
2 parents 986a5ec + 1a8fc3a commit f091a0d
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 98 deletions.
3 changes: 2 additions & 1 deletion config/defaults/config.LINUX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native -O3 -ffast-math
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
FFXX_OPT_FLAGS = -O3 -ffast-math
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
Expand Down
3 changes: 2 additions & 1 deletion config/defaults/config.LINUX_INTEL.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -r8 -O2
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
FFXX_OPT_FLAGS = -O2
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
Expand Down
3 changes: 2 additions & 1 deletion config/defaults/config.LINUX_INTEL_SAFE.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -r8 -O1
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
FFXX_OPT_FLAGS = -O1
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
Expand Down
3 changes: 2 additions & 1 deletion config/defaults/config.OSX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native -O3 -ffast-math
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
FFXX_OPT_FLAGS = -O3 -ffast-math
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
Expand Down
15 changes: 10 additions & 5 deletions src/NKSolver/NKSolvers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ end subroutine NKStep
subroutine LSCubic(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, lambda)

use constants
use utils, only : EChk, myisnan
use utils, only : EChk
use genericISNAN, only : myisnan
use communication, only : myid
use initializeFlow, only : setUniformFlow
use iteration, only : totalR0
Expand Down Expand Up @@ -3063,7 +3064,8 @@ subroutine physicalityCheckANK(lambdaP)
use blockPointers, only : ndom, il, jl, kl
use flowVarRefState, only : nw, nwf, nt1, nt2
use inputtimespectral, only : nTimeIntervalsSpectral
use utils, only : setPointers, EChk, myisnan
use utils, only : setPointers, EChk
use genericISNAN, only : myisnan
use communication, only : ADflow_comm_world
implicit none

Expand Down Expand Up @@ -3260,7 +3262,8 @@ subroutine physicalityCheckANKTurb(lambdaP)
use blockPointers, only : ndom, il, jl, kl
use flowVarRefState, only : nw, nwf, nt1,nt2
use inputtimespectral, only : nTimeIntervalsSpectral
use utils, only : setPointers, EChk, myisnan
use utils, only : setPointers, EChk
use genericISNAN, only : myisnan
use communication, only : ADflow_comm_world
implicit none

Expand Down Expand Up @@ -3389,7 +3392,8 @@ subroutine ANKTurbSolveKSP
use inputTimeSpectral, only : nTimeIntervalsSpectral
use inputDiscretization, only : approxSA, orderturb
use iteration, only : approxTotalIts, totalR0, totalR, currentLevel
use utils, only : EChk, setPointers, myisnan
use utils, only : EChk, setPointers
use genericISNAN, only : myisnan
use solverUtils, only : computeUTau
use NKSolver, only : getEwTol
use BCRoutines, only : applyAllBC, applyAllBC_block
Expand Down Expand Up @@ -3670,7 +3674,8 @@ subroutine ANKStep(firstCall)
use inputTimeSpectral, only : nTimeIntervalsSpectral
use inputDiscretization, only : lumpedDiss, approxSA, orderturb
use iteration, only : approxTotalIts, totalR0, totalR, stepMonitor, linResMonitor, currentLevel, iterType
use utils, only : EChk, setPointers, myisnan
use utils, only : EChk, setPointers
use genericISNAN, only : myisnan
use turbAPI, only : turbSolveDDADI
use solverUtils, only : computeUTau
use adjointUtils, only : referenceShockSensor
Expand Down
2 changes: 1 addition & 1 deletion src/adjoint/adjointUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ subroutine setBlock(blk)
! Sets a block at irow, icol, if useTranspose is False
! Sets a block at icol, irow with transpose of blk if useTranspose is True

use utils, only : myisnan
use genericISNAN, only : myisnan
implicit none
real(kind=realType), dimension(nState, nState) :: blk

Expand Down
2 changes: 1 addition & 1 deletion src/adjoint/outputForward/flowutils_d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ subroutine computegamma(t, gamma, mm)
use cpcurvefits
use inputphysics, only : cpmodel, gammaconstant
implicit none
integer(kind=inttype), intent(in) :: mm
!
! subroutine arguments.
!
integer(kind=inttype), intent(in) :: mm
real(kind=realtype), dimension(mm), intent(in) :: t
real(kind=realtype), dimension(mm), intent(out) :: gamma
!
Expand Down
2 changes: 1 addition & 1 deletion src/adjoint/outputReverse/flowutils_b.f90
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ subroutine computegamma(t, gamma, mm)
use cpcurvefits
use inputphysics, only : cpmodel, gammaconstant
implicit none
integer(kind=inttype), intent(in) :: mm
!
! subroutine arguments.
!
integer(kind=inttype), intent(in) :: mm
real(kind=realtype), dimension(mm), intent(in) :: t
real(kind=realtype), dimension(mm), intent(out) :: gamma
!
Expand Down
2 changes: 1 addition & 1 deletion src/adjoint/outputReverseFast/flowutils_fast_b.f90
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ subroutine computegamma(t, gamma, mm)
use cpcurvefits
use inputphysics, only : cpmodel, gammaconstant
implicit none
integer(kind=inttype), intent(in) :: mm
!
! subroutine arguments.
!
integer(kind=inttype), intent(in) :: mm
real(kind=realtype), dimension(mm), intent(in) :: t
real(kind=realtype), dimension(mm), intent(out) :: gamma
!
Expand Down
27 changes: 20 additions & 7 deletions src/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
include ../../config/config.mk

# Group all the fortran, C and compiler flags together.
FF90_ALL_FLAGS = $(FF90_FLAGS) $(CGNS_INCLUDE_FLAGS) -I. \
FF90_ALL_FLAGS_NO_OPT = $(FF90_FLAGS) $(CGNS_INCLUDE_FLAGS) -I. \
$(PETSC_CC_INCLUDES) $(FF90_PRECISION_FLAGS)

FF77_ALL_FLAGS = $(FF77_FLAGS) $(CGNS_INCLUDE_FLAGS) -I. \
FF90_ALL_FLAGS = $(FF90_ALL_FLAGS_NO_OPT) $(FFXX_OPT_FLAGS)

FF77_ALL_FLAGS_NO_OPT = $(FF77_FLAGS) $(CGNS_INCLUDE_FLAGS) -I. \
$(PETSC_CC_INCLUDES) $(FF90_PRECISION_FLAGS)

FF77_ALL_FLAGS = $(FF77_ALL_FLAGS_NO_OPT) $(FFXX_OPT_FLAGS)

CC_ALL_FLAGS = $(C_FLAGS) -I../c_defines -I../metis-4.0 $(PETSC_CC_INCLUDES) \
$(CC_PRECISION_FLAGS)

Expand All @@ -28,46 +32,55 @@ dirs:=$(addprefix ../,$(dirs))
VPATH:=$(dirs)

# Need to add the ../ to each of the file lists:
fortranFilesNoOpt:=$(addprefix ../,$(fortranFilesNoOpt))
fortranFiles:=$(addprefix ../,$(fortranFiles))
cFiles:=$(addprefix ../,$(cFiles))
f77Files:=$(addprefix ../,$(f77Files))

# Now strip off the directory part. This is because fort_depend gives
# us targets that are like <filename.o>.
fortranFilesNoOptNoDir=$(notdir $(fortranFilesNoOpt))
fortranFilesNoDir=$(notdir $(fortranFiles))
cFilesNoDir=$(notdir $(cFiles))
f77FilesNoDir=$(notdir $(f77Files))

# Generate two separate list of .F90 and .f90 files using the filter command
f90FilesNoOpt=$(filter %.f90,$(fortranFilesNoOptNoDir))
F90FilesNoOpt=$(filter %.F90,$(fortranFilesNoOptNoDir))
f90Files=$(filter %.f90,$(fortranFilesNoDir))
F90Files=$(filter %.F90,$(fortranFilesNoDir))

# Finally convert all source files to .o
OFILES_NO_OPT=$(f90FilesNoOpt:%.f90=%.o) $(F90FilesNoOpt:%.F90=%.o)
OFILES=$(f90Files:%.f90=%.o) $(F90Files:%.F90=%.o) $(cFilesNoDir:%.c=%.o) $(f77FilesNoDir:%.f=%.o)

# Define the file name for the auto-generated dependency file.
DEP_FILE=adflow_project.dep

# Not real targets are "phony"
.PHONY: sources lib
.PHONY: sourcesNoOpt sources lib

default: all

# This rule will build source files (and their depenedencies) without any optimization flags
sourcesNoOpt: FF90_ALL_FLAGS=$(FF90_ALL_FLAGS_NO_OPT)
sourcesNoOpt: $(OFILES_NO_OPT) $(DEP_FILE)

# The 'source's makes all the .o files. It also depends on the dependence file "DEP_FILE".
sources: $(OFILES) $(DEP_FILE)

# The .dep file depends on the source files, so it automatically gets updated
# when you change your source
$(DEP_FILE): $(fortranFiles)
$(DEP_FILE): $(fortranFilesNoOpt) $(fortranFiles)
@echo "Making dependencies!\n"
$(PYTHON) fort_depend.py -w -o $(DEP_FILE) -f $(fortranFiles)
$(PYTHON) fort_depend.py -w -o $(DEP_FILE) -f $(fortranFilesNoOpt) $(fortranFiles)

# Include the automatically generated file.
include $(DEP_FILE)

# The 'lib' target builds the static archive. It depends on "sources".
lib: sources
$(AR) $(AR_FLAGS) libadflow.a $(OFILES)
lib: sourcesNoOpt sources
$(AR) $(AR_FLAGS) libadflow.a $(OFILES_NO_OPT) $(OFILES)

# These are the extra python objects for the python library
PYTHON_OBJECTS = fortranobject.o\
Expand Down
4 changes: 3 additions & 1 deletion src/build/fileList
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fortranFilesNoOpt= modules/precision.F90\
utils/genericISNAN.F90\

fortranFiles= ADT/adtUtils.F90\
ADT/adtBuild.F90\
ADT/adtLocalSearch.F90\
Expand All @@ -18,7 +21,6 @@ fortranFiles= ADT/adtUtils.F90\
\
inputParam/inputParamRoutines.F90\
\
modules/precision.F90\
modules/su_cgns.F90\
modules/constants.F90\
modules/killSignals.f90\
Expand Down
1 change: 0 additions & 1 deletion src/build/rules
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@echo " --- Compiled $*.c successfully ---"
@echo


%.o: %.f
$(FF90) $(FF77_ALL_FLAGS) -c $< -o $*.o
@echo
Expand Down
4 changes: 2 additions & 2 deletions src/solver/solvers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,8 @@ subroutine convergenceInfo
use killSignals, only : routineFailed, fromPython
use iteration, only : rhoRes, rhoResStart, totalR, totalRStart, totalR0
use oversetData, only: oversetPresent
use utils, only : setPointers, myisnan, returnFail, maxHDiffMach, maxEddyv, &
sumResiduals, sumAllResiduals
use utils, only : setPointers, returnFail, maxHDiffMach, maxEddyv, sumResiduals, sumAllResiduals
use genericISNAN, only : myisnan
use surfaceIntegrations, only : integrateSurfaces
use zipperIntegrations, only : integrateZippers
use surfaceFamilies, only : fullFamLIst
Expand Down
47 changes: 47 additions & 0 deletions src/utils/genericISNAN.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module genericISNAN
implicit none
interface myIsNAN
module procedure myIsNAN_r
module procedure myIsNAN_c
end interface

contains

logical function myIsNAN_r(val)
!
! myIsNAN_r determines whether or not the given real value is a NAN or INF and
! returns the according logical.
!
use precision
use, intrinsic :: ieee_arithmetic, only : ieee_is_nan, ieee_is_finite
implicit none
!
! Function arguments.
!
real(kind=alwaysRealType), intent(in) :: val

! Check if NAN or INF
myIsNAN_r = ieee_is_nan(val) .or. .not. ieee_is_finite(val)

end function myIsNAN_r

logical function myIsNAN_c(val)
!
! myIsNAN_c determines whether or not the given complex value contains NAN of INF and
! returns the according logical.
!
use precision
use, intrinsic :: ieee_arithmetic, only : ieee_is_nan, ieee_is_finite
implicit none
!
! Function arguments.
!
complex(kind=realType), intent(in) :: val

! Check if either real or imag part is NAN or INF
myIsNAN_c = ieee_is_nan(real(val)) .or. .not. ieee_is_finite(real(val))
myIsNAN_c = myIsNAN_c .or. ieee_is_nan(aimag(val)) .or. .not. ieee_is_finite(aimag(val))

end function myIsNAN_c

end module genericISNAN
43 changes: 0 additions & 43 deletions src/utils/utils.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module utils
implicit none
interface myIsNAN
module procedure myIsNAN_r
module procedure myIsNAN_c
end interface

contains

Expand Down Expand Up @@ -2557,44 +2553,6 @@ function delta(val1,val2)

end function delta


logical function myIsNAN_r(val)
!
! myIsNAN_r determines whether or not the given real value is a NAN or INF and
! returns the according logical.
!
use constants
use, intrinsic :: ieee_arithmetic, only : ieee_is_nan, ieee_is_finite
implicit none
!
! Function arguments.
!
real(kind=alwaysRealType), intent(in) :: val

! Check if NAN or INF
myIsNAN_r = ieee_is_nan(val) .or. .not. ieee_is_finite(val)

end function myIsNAN_r

logical function myIsNAN_c(val)
!
! myIsNAN_c determines whether or not the given complex value contains NAN of INF and
! returns the according logical.
!
use constants
use, intrinsic :: ieee_arithmetic, only : ieee_is_nan, ieee_is_finite
implicit none
!
! Function arguments.
!
complex(kind=realType), intent(in) :: val

! Check if either real or imag part is NAN or INF
myIsNAN_c = ieee_is_nan(real(val)) .or. .not. ieee_is_finite(real(val))
myIsNAN_c = myIsNAN_c .or. ieee_is_nan(aimag(val)) .or. .not. ieee_is_finite(aimag(val))

end function myIsNAN_c

subroutine nullifyCGNSDomPointers(nn)
!
! nullifyCGNSDomPointers nullifies all the pointers of the
Expand Down Expand Up @@ -6611,7 +6569,6 @@ subroutine getCellCGNSBlockIDs(level, n, cellID)
end do
end subroutine getCellCGNSBlockIDs


subroutine getNCGNSZones(nZones)
use cgnsGrid
implicit none
Expand Down
Loading

0 comments on commit f091a0d

Please sign in to comment.