-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,892 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module ConfigLoader_h | ||
!! Header module for ConfigLoader | ||
|
||
!! @note This is a header module: it contains subroutine interface definitions only. | ||
!! Subroutine implementation (code) is found in the corresponding submodule file (with no '_h'). @endnote | ||
|
||
use, intrinsic :: iso_fortran_env, sp=>real32, dp=>real64 | ||
implicit none | ||
|
||
integer, parameter :: MAXSTR = 500 | ||
!! Maximum string length | ||
integer, parameter :: array_fixed = 1 | ||
!! arrayMode: Fixed size, all values must be specified in input | ||
integer, parameter :: array_pad = 2 | ||
!! arrayMode: Padded array, pad unspecified values with last specified value | ||
integer, parameter :: array_fill = 3 | ||
!! arrayMode: Fill in array, pad unspecified values from default array | ||
|
||
character(len=1) :: configCommentChar = '#' | ||
!! Character indicating comment line | ||
|
||
character(len=1) :: configKVDelim = '=' | ||
!! Character delimiting key from value | ||
|
||
interface addConfigParameter | ||
module subroutine addScalarParameter(keyString,targetVar,defaultVal,enumStrings) | ||
!! Generic interface for registering scalar parameters | ||
character(*), intent(in) :: keyString | ||
!! Parameter key | ||
class(*), target, intent(inout) :: targetVar | ||
!! Variable to store parameter once read | ||
class(*), optional, intent(in) :: defaultVal | ||
!! Default value of optional parameter, omit for mandatory parameters | ||
character(*), optional, intent(in) :: enumStrings(:) | ||
!! Array of strings for enumeration parameters (for integer parameters only) | ||
end subroutine addScalarParameter | ||
|
||
module subroutine addArrayParameter(keyString,targetVar,arrayMode,defaultVal) | ||
!! Generic interface for registering array parameters | ||
character(*), intent(in) :: keyString | ||
!! Parameter key | ||
class(*), target, intent(inout) :: targetVar(:) | ||
!! Variable to store parameter once read | ||
integer, intent(in) :: arrayMode | ||
!! Determine how to pad array: [[ConfigLoader_h:array_fixed]], [[ConfigLoader_h:array_pad]], [[ConfigLoader_h:array_fill]] | ||
class(*), optional, intent(in) :: defaultVal(:) | ||
!! Default value of optional parameter, omit for mandatory parameters | ||
end subroutine addArrayParameter | ||
end interface | ||
|
||
interface | ||
module subroutine parseConfigFile(filename) | ||
!! Open and parse a configuration file for registered parameters | ||
character(*), intent(in) :: filename | ||
!! File path of config file to parse | ||
end subroutine parseConfigFile | ||
end interface | ||
|
||
end module ConfigLoader_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# --- Compile flags --- | ||
# Compiler | ||
PLATFORM ?= gnu | ||
BUILD ?= release | ||
ifeq ($(PLATFORM), gnu) | ||
FC=gfortran | ||
AR=gcc-ar | ||
FFLAGS += -std=f2008 -fimplicit-none -J$(MODDIR) #-fopenmp | ||
FFLAGS_LEGACY = -fimplicit-none -J$(MODDIR) | ||
|
||
else ifeq ($(PLATFORM), intel) | ||
FC=ifort | ||
FFLAGS += -stand:f08 -module:$(MODDIR) | ||
FFLAGS_LEGACY = $(FFLAGS) | ||
|
||
else | ||
$(error unrecognized platform.) | ||
endif | ||
|
||
ifeq ($(PLATFORM)-$(BUILD), gnu-debug) | ||
FFLAGS += -g -Og -C -Wall -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow | ||
|
||
else ifeq ($(PLATFORM)-$(BUILD), gnu-release) | ||
FFLAGS += -O3 | ||
#-flto | ||
|
||
else ifeq ($(PLATFORM)-$(BUILD), intel-debug) | ||
FFLAGS += -g -O0 -check all -debug all -traceback -fpe0 | ||
|
||
else ifeq ($(PLATFORM)-$(BUILD), intel-release) | ||
FFLAGS += -fast | ||
|
||
else | ||
$(error unrecognized build target.) | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# --- Source directories --- | ||
vpath %.f90 external/ConfigLoader | ||
vpath %.f90 src | ||
vpath %.cl src | ||
|
||
# --- Source names --- | ||
# Headers - built first, contain subroutine interface definitions | ||
# Modules - built second, contain subroutine collections | ||
# Programs - built and linked last, contain main program(s) | ||
# Kernels - contain OpenCL kernel code, linked into executable as binary resource | ||
HEADERMODULES = ConfigLoader_h | ||
MODULES = TecplotOutput UserInput TestCases ConfigLoader | ||
PROGS = lbmocl | ||
KERNELS = kernels.cl | ||
|
||
# --- Output Directories --- | ||
FOCAL_DIR ?= ./external/focal | ||
OPENCL_DIR ?= /usr/lib/ | ||
BINDIR = ./bin/ | ||
OBJDIR = ./obj/ | ||
MODDIR = ./mod/ | ||
|
||
# --- Targets --- | ||
PROGOBJS =$(addprefix $(OBJDIR), $(addsuffix .o, $(PROGS))) | ||
MODOBJS = $(addprefix $(OBJDIR), $(addsuffix .o, $(MODULES))) | ||
HEADEROBJS = $(addprefix $(OBJDIR), $(addsuffix .o, $(HEADERMODULES))) | ||
EXEC = $(addprefix $(BINDIR), $(PROGS)) | ||
DIRS = $(MODDIR) $(BINDIR) $(OBJDIR) | ||
|
||
# --- Compiler Flags --- | ||
include make.compiler | ||
|
||
# --- Link Flags --- | ||
ifeq ($(BUILD), release) | ||
FOCAL_LFLAGS ?= -L$(FOCAL_DIR)/lib -lfocal | ||
else ifeq ($(BUILD), debug) | ||
FOCAL_LFLAGS ?= -L$(FOCAL_DIR)/lib -lfocaldbg | ||
else | ||
$(error unrecognized build.) | ||
endif | ||
OPENCL_LFLAGS ?= -g -L$(OPENCL_DIR) -lOpenCL | ||
LFLAGS = $(FOCAL_LFLAGS) $(OPENCL_LFLAGS) | ||
|
||
# --- Main build target --- | ||
all: $(DIRS) $(EXEC) | ||
|
||
include $(FOCAL_DIR)/make.include | ||
|
||
# --- Cleanup (reset) --- | ||
clean: focal_clean | ||
rm -f $(OBJDIR)*.o | ||
rm -f $(MODDIR)*.mod | ||
rm -f $(MODDIR)*.smod | ||
rm -f $(BINDIR)* | ||
|
||
# Programs depend on modules | ||
$(PROGOBJS): $(MODOBJS) | ||
|
||
$(EXEC): $(FOCAL_LIB_OBJS) | ||
|
||
# Modules depend on any header modules | ||
$(MODOBJS): $(HEADEROBJS) | ||
|
||
# Recipe to link executables | ||
$(BINDIR)%: $(addprefix $(OBJDIR), %.o fclKernels.o) $(MODOBJS) $(HEADEROBJS) | ||
$(FC) $^ $(LFLAGS) -o $@ | ||
|
||
# Recipe to compile fortran objects | ||
$(OBJDIR)%.o: %.f90 | ||
$(FC) $(FFLAGS) -c $< -o $@ | ||
|
||
# Recipe to 'compile' kernel source into a binary object | ||
$(OBJDIR)%.o: %.cl | ||
ld -r -b binary fclKernels.cl -o $@ | ||
nm $@ | ||
|
||
# Recipe to concatenate kernel files | ||
fclKernels.cl: $(KERNELS) | ||
cat $^ > fclKernels.cl | ||
|
||
# Recipe to create output directories | ||
$(DIRS): | ||
mkdir $@ | ||
|
||
.SECONDARY: $(addprefix $(OBJDIR), fclKernels.o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
module LBM_Tecplot_Output | ||
!! Contains routines for writing macroscopic variables to tecplot files | ||
! | ||
! | ||
use iso_fortran_env, only: sp=> real32 | ||
implicit none | ||
|
||
contains | ||
|
||
subroutine writePltTxt(filename,ni,nj,nSave,dtSave,dx,rho,u,v) | ||
!! Write macroscopic variable data to tecplot ascii format | ||
! | ||
! | ||
character(*), intent(in) :: filename | ||
integer, intent(in) :: ni, nj, nSave | ||
real(sp), intent(in) :: dtSave ! Time interval between saved solutions | ||
real(sp), intent(in) :: dx ! Lattice spacing | ||
real(sp), intent(in), dimension(ni*nj,nSave) :: rho, u, v | ||
|
||
integer, parameter :: nperline = 100 | ||
|
||
integer :: fh, n, i, j | ||
|
||
open(newunit=fh,file=filename,status='unknown') | ||
|
||
write(fh,*) 'TITLE = "LBM Solution"' | ||
write(fh,*) 'VARIABLES = "X" "Y" "rho" "u" "v"' | ||
|
||
do n=1,nSave | ||
|
||
write(fh,'(A,I8,A,I8,A,F10.4,A)',advance='no') 'ZONE T="Solution" DATAPACKING=BLOCK I=',nj,' J=',ni, & | ||
' STRANDID=1 SOLUTIONTIME=',n*dtSave, 'VARLOCATION=([1-5]=NODAL)' | ||
|
||
if (n==1) then | ||
! Write grid data | ||
write(fh,*) '' | ||
do i=1,ni | ||
do j=1,nj | ||
write(fh,*) (i-1)*dx | ||
end do | ||
end do | ||
|
||
do i=1,ni | ||
do j=1,nj | ||
write(fh,*) (j-1)*dx | ||
end do | ||
end do | ||
|
||
else | ||
! Use grid data from zone 1 | ||
write(fh,*) 'VARSHARELIST=([1,2]=1)' | ||
|
||
end if | ||
|
||
write(fh,*) ( rho(i:min(i+nperline-1,ni*nj),n),NEW_LINE('A') , i=1,ni*nj,nperline ) | ||
write(fh,*) ( u(i:min(i+nperline-1,ni*nj),n),NEW_LINE('A') , i=1,ni*nj,nperline ) | ||
write(fh,*) ( v(i:min(i+nperline-1,ni*nj),n),NEW_LINE('A') , i=1,ni*nj,nperline ) | ||
|
||
end do | ||
|
||
close(fh) | ||
|
||
end subroutine writePltTxt | ||
! ----------------------------------------------------------------------------- | ||
|
||
|
||
subroutine writePltBin(filename,ni,nj,nSave,dtSave,dx,rho,u,v) | ||
!! Write macroscopic variable data to tecplot binary format | ||
! | ||
! | ||
use iso_c_binding, only: int32=>c_int32_t, float32=>c_float, float64=>c_double | ||
|
||
character(*), intent(in) :: filename | ||
integer, intent(in) :: ni, nj, nSave | ||
real(sp), intent(in) :: dtSave ! Time interval between saved solutions | ||
real(sp), intent(in) :: dx ! Lattice spacing | ||
real(sp), intent(in), dimension(ni*nj,nSave) :: rho, u, v | ||
|
||
integer, parameter :: nVar = 5 | ||
character(*), parameter :: pltTitle = 'LBM Solution' | ||
character(*), parameter :: zoneName = 'Solution' | ||
character(*), parameter :: v1Name = 'rho' | ||
character(*), parameter :: v2Name = 'u' | ||
character(*), parameter :: v3Name = 'v' | ||
|
||
integer :: fh, n, i, j | ||
|
||
! Open file for binary access | ||
open(newunit=fh,file=filename,status='unknown',access='stream') | ||
|
||
! File header | ||
write(fh) '#!TDV112' | ||
write(fh) int(1,int32) ! byte order | ||
write(fh) int(0,int32) ! file type: full | ||
write(fh) (ichar(pltTitle(i:i),int32),i=1,len(pltTitle)),0 ! Title | ||
|
||
write(fh) int(nVar,int32) ! no. of vars | ||
|
||
! Variable names | ||
write(fh) ichar('x',int32),0,ichar('y',int32),0 | ||
write(fh) (ichar(v1Name(i:i),int32),i=1,len(v1Name)),0 | ||
write(fh) (ichar(v2Name(i:i),int32),i=1,len(v2Name)),0 | ||
write(fh) (ichar(v3Name(i:i),int32),i=1,len(v3Name)),0 | ||
|
||
! Zone header info | ||
do n=1,nSave | ||
write(fh) real(299.0,float32) ! Zone start | ||
write(fh) (ichar(zoneName(i:i),int32),i=1,len(zoneName)),0 | ||
write(fh) int(-1,int32) ! no parent zones | ||
write(fh) int(0,int32) !static strand id | ||
write(fh) real(n*dtSave,float64) ! Zone time | ||
write(fh) int(-1,int32) ! Not used by tecplot | ||
write(fh) int(0,int32) ! ordered zone | ||
write(fh) int(0,int32) ! data packing block | ||
write(fh) int(0,int32) ! don't specify var loc | ||
write(fh) int(0,int32) ! no neighbours | ||
write(fh) nj,ni,1 ! Imax, Jmax, Kmax | ||
write(fh) int(0,int32) ! no aux data | ||
end do | ||
write(fh) real(357.0,float32) ! end of header | ||
|
||
! Data section | ||
do n=1, nSave | ||
write(fh) real(299.0,float32) ! zone start | ||
write(fh) (int(1,int32),i=1,nVar) ! Variable type (float) | ||
write(fh) int(0,int32) ! no passive vars | ||
if (n==1) then | ||
write(fh) int(0,int32) ! no variable sharing | ||
write(fh) -1 ! no connectivity sharing | ||
write(fh) real(0.0,float64) ! Zone variable bounds | ||
write(fh) real(ni*dx,float64) | ||
write(fh) real(0.0,float64) | ||
write(fh) real(nj*dx,float64) | ||
write(fh) real(minval(rho(:,n)),float64) | ||
write(fh) real(maxval(rho(:,n)),float64) | ||
write(fh) real(minval(u(:,n)),float64) | ||
write(fh) real(maxval(u(:,n)),float64) | ||
write(fh) real(minval(v(:,n)),float64) | ||
write(fh) real(maxval(v(:,n)),float64) | ||
|
||
do i=1,ni ! Write grid data out (block format) | ||
do j=1,nj | ||
write(fh) real((i-1)*dx,float32) | ||
end do | ||
end do | ||
|
||
do i=1,ni | ||
do j=1,nj | ||
write(fh) real((j-1)*dx,float32) | ||
end do | ||
end do | ||
|
||
write(fh) real(rho(:,n),float32) ! Write variable data out (block format) | ||
write(fh) real(u(:,n),float32) | ||
write(fh) real(v(:,n),float32) | ||
else | ||
write(fh) int(1,int32) ! variable sharing enabled | ||
write(fh) int([0,0,-1,-1,-1],int32) ! Use x,y from first zone | ||
write(fh) -1 ! no connectivity sharing | ||
write(fh) real(minval(rho(:,n)),float64) | ||
write(fh) real(maxval(rho(:,n)),float64) | ||
write(fh) real(minval(u(:,n)),float64) | ||
write(fh) real(maxval(u(:,n)),float64) | ||
write(fh) real(minval(v(:,n)),float64) | ||
write(fh) real(maxval(v(:,n)),float64) | ||
|
||
write(fh) real(rho(:,n),float32) ! Write variable data out (block format) | ||
write(fh) real(u(:,n),float32) | ||
write(fh) real(v(:,n),float32) | ||
end if | ||
end do | ||
|
||
close(fh) | ||
|
||
end subroutine writePltBin | ||
! ----------------------------------------------------------------------------- | ||
|
||
|
||
|
||
end module LBM_Tecplot_output |
Oops, something went wrong.