Skip to content

Commit

Permalink
Merge pull request #21 from dreamer2368/ibm
Browse files Browse the repository at this point in the history
Immersed boundary method
  • Loading branch information
dreamer2368 authored Dec 16, 2022
2 parents 90e35e1 + 34211d8 commit 3f9aa79
Show file tree
Hide file tree
Showing 78 changed files with 1,478 additions and 375 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set(magudiObj_SOURCES
${PROJECT_SOURCE_DIR}/include/ReverseMigrator.f90
${PROJECT_SOURCE_DIR}/src/ReverseMigratorImpl.f90
${PROJECT_SOURCE_DIR}/include/MappingFunction.f90
${PROJECT_SOURCE_DIR}/include/LevelsetFactory.f90

# Extended types.
${PROJECT_SOURCE_DIR}/include/RK4Integrator.f90
Expand Down Expand Up @@ -211,6 +212,10 @@ set(magudiObj_SOURCES
${PROJECT_SOURCE_DIR}/src/ProbePatchImpl.f90
${PROJECT_SOURCE_DIR}/include/KolmogorovForcingPatch.f90
${PROJECT_SOURCE_DIR}/src/KolmogorovForcingPatchImpl.f90
${PROJECT_SOURCE_DIR}/include/ImmersedBoundaryPatch.f90
${PROJECT_SOURCE_DIR}/src/ImmersedBoundaryImpl.f90
${PROJECT_SOURCE_DIR}/include/SinusoidalWallLevelset.f90
${PROJECT_SOURCE_DIR}/src/SinusoidalWallLevelsetImpl.f90

# C source files.
${PROJECT_SOURCE_DIR}/src/PLOT3DFormat.c
Expand Down
1 change: 0 additions & 1 deletion bin/Adjoint.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ program adjoint
type(t_Solver) :: solver

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
Expand Down
1 change: 0 additions & 1 deletion bin/CheckGradientAccuracy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ program gradient_accuracy
integer, dimension(:,:), allocatable :: globalGridSizes
type(t_Region) :: region
type(t_Solver) :: solver
SCALAR_TYPE :: dummyValue

! Initialize MPI.
call MPI_Init(ierror)
Expand Down
1 change: 0 additions & 1 deletion bin/Forward.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ program forward
type(t_Solver) :: solver

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
Expand Down
6 changes: 2 additions & 4 deletions bin/Linearized_Forward.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ program linearized_forward
inputFlag = .false., outputFlag = .false., saveMetricsFlag = .false.
character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename
character(len = STRING_LENGTH) :: filename, outputPrefix, message
logical :: adjointRestart, fileExists, success
integer :: accumulatedNTimesteps
logical :: fileExists, success
integer, dimension(:,:), allocatable :: globalGridSizes
type(t_Region) :: region, lineariedRegion
type(t_Region) :: region
type(t_Solver) :: solver

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
Expand Down
10 changes: 2 additions & 8 deletions bin/control_space_norm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ program control_space_norm
implicit none

integer, parameter :: wp = SCALAR_KIND
integer :: i, stat, fileUnit, dictIndex, procRank, numProcs, ierror, STATUS
character(len = STRING_LENGTH) :: filename, resultFilename, outputPrefix, message
integer :: i, dictIndex, procRank, numProcs, ierror
character(len = STRING_LENGTH) :: filename, outputPrefix, message
logical :: success
integer, dimension(:,:), allocatable :: globalGridSizes
type(t_Region) :: region
type(t_Solver) :: solver

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
call MPI_Init(ierror)
call MPI_Comm_rank(MPI_COMM_WORLD, procRank, ierror)
Expand Down Expand Up @@ -169,8 +165,6 @@ subroutine collectControlSpaceNorm(this, region)
class(t_TimeIntegrator), pointer :: timeIntegrator => null()
class(t_Controller), pointer :: controller => null()
class(t_Functional), pointer :: functional => null()
type(t_ReverseMigratorFactory) :: reverseMigratorFactory
class(t_ReverseMigrator), pointer :: reverseMigrator => null()
integer :: i, j, timestep, startTimestep, timemarchDirection
real(SCALAR_KIND) :: time, startTime, timeStepSize

Expand Down
168 changes: 83 additions & 85 deletions bin/paste_control_forcing.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ subroutine pasteControlForcing(comm,ZFilename,XFilename,totalTimestep,startTimes
integer, parameter :: wp = SCALAR_KIND
integer :: i, procRank, numProcs, ierror, mpiFileHandle
character(len = STRING_LENGTH) :: message
logical :: XFileExists, ZFileExists, success
integer(kind = MPI_OFFSET_KIND) :: XFileSize, ZFileSize, offset, globalOffset
logical :: XFileExists, ZFileExists
integer(kind = MPI_OFFSET_KIND) :: XFileSize, offset, globalOffset

integer(kind = MPI_OFFSET_KIND) :: globalSize, patchSize, sliceSize, bufferSize, sendcnt, indexQuotient
integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc
SCALAR_TYPE, dimension(:), allocatable :: XBuffer, ZBuffer
SCALAR_TYPE :: dummyValue

! Initialize MPI.
call MPI_Comm_rank(comm, procRank, ierror)
Expand Down Expand Up @@ -230,87 +229,86 @@ subroutine pasteControlForcing(comm,ZFilename,XFilename,totalTimestep,startTimes

end subroutine

subroutine createZeroControlForcing(comm,ZFilename,globalSize)

use MPI
use, intrinsic :: iso_fortran_env, only : output_unit

use InputHelper, only : parseInputFile, getOption, getRequiredOption
use ErrorHandler
use MPITimingsHelper, only : startTiming, endTiming, reportTimings, cleanupTimers

implicit none

! <<< Arguments >>>
integer, intent(in) :: comm
integer(kind = MPI_OFFSET_KIND), intent(in) :: globalSize
character(len = *), intent(in) :: ZFilename

! <<< Local variables >>>
integer, parameter :: wp = SCALAR_KIND
integer :: i, procRank, numProcs, ierror, mpiFileHandle
character(len = STRING_LENGTH) :: message
logical :: XFileExists, success
integer(kind = MPI_OFFSET_KIND) :: ZFileSize, offset, globalOffset

integer(kind = MPI_OFFSET_KIND) :: patchSize, sliceSize, bufferSize, sendcnt, indexQuotient
integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc
SCALAR_TYPE, dimension(:), allocatable :: ZBuffer
SCALAR_TYPE :: dummyValue

! Initialize MPI.
call MPI_Comm_rank(comm, procRank, ierror)
call MPI_Comm_size(comm, numProcs, ierror)

call startTiming("File name and size check")

write(message,'(3A)') "Creating zero ", trim(ZFilename), "... "
call writeAndFlush(comm, output_unit, message, advance = 'no')

call endTiming("File name and size check")
call startTiming("Buffer setup")

indexQuotient = MOD(globalSize,int(numProcs,MPI_OFFSET_KIND))
bufferSize = globalSize/int(numProcs,MPI_OFFSET_KIND)
allocate(recvcnt(0:numProcs-1))
allocate(displc(0:numProcs-1))
recvcnt(0:indexQuotient-1) = bufferSize+1
recvcnt(indexQuotient:numProcs-1) = bufferSize
displc = 0
do i=1,numProcs-1
displc(i) = SUM(recvcnt(0:i-1))
end do
offset = displc(procRank)*SIZEOF_SCALAR

if( procRank<indexQuotient ) then
sendcnt = bufferSize+1
else
sendcnt = bufferSize
end if
allocate(ZBuffer(sendcnt))
ZBuffer = 0.0_wp

call endTiming("Buffer setup")
call startTiming("Write file")

call MPI_Barrier(comm, ierror)

call MPI_File_open(comm, trim(ZFilename), &
MPI_MODE_WRONLY + MPI_MODE_CREATE, MPI_INFO_NULL, &
mpiFileHandle, ierror)
call MPI_FILE_SET_VIEW(mpiFileHandle,offset,MPI_DOUBLE,MPI_DOUBLE, &
'native',MPI_INFO_NULL,ierror)
call MPI_File_write_all(mpiFileHandle, ZBuffer, int(sendcnt), &
SCALAR_TYPE_MPI, MPI_STATUS_IGNORE, ierror)
call MPI_File_close(mpiFileHandle, ierror)

call MPI_Barrier(comm, ierror)

call endTiming("Write file")

write(message, '(A)') " done!"
call writeAndFlush(comm, output_unit, message)

end subroutine
!NOTE: this subroutine is unused and thus commented out. Should be working.
! subroutine createZeroControlForcing(comm,ZFilename,globalSize)
!
! use MPI
! use, intrinsic :: iso_fortran_env, only : output_unit
!
! use InputHelper, only : parseInputFile, getOption, getRequiredOption
! use ErrorHandler
! use MPITimingsHelper, only : startTiming, endTiming, reportTimings, cleanupTimers
!
! implicit none
!
! ! <<< Arguments >>>
! integer, intent(in) :: comm
! integer(kind = MPI_OFFSET_KIND), intent(in) :: globalSize
! character(len = *), intent(in) :: ZFilename
!
! ! <<< Local variables >>>
! integer, parameter :: wp = SCALAR_KIND
! integer :: i, procRank, numProcs, ierror, mpiFileHandle
! character(len = STRING_LENGTH) :: message
! integer(kind = MPI_OFFSET_KIND) :: offset
!
! integer(kind = MPI_OFFSET_KIND) :: bufferSize, sendcnt, indexQuotient
! integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc
! SCALAR_TYPE, dimension(:), allocatable :: ZBuffer
!
! ! Initialize MPI.
! call MPI_Comm_rank(comm, procRank, ierror)
! call MPI_Comm_size(comm, numProcs, ierror)
!
! call startTiming("File name and size check")
!
! write(message,'(3A)') "Creating zero ", trim(ZFilename), "... "
! call writeAndFlush(comm, output_unit, message, advance = 'no')
!
! call endTiming("File name and size check")
! call startTiming("Buffer setup")
!
! indexQuotient = MOD(globalSize,int(numProcs,MPI_OFFSET_KIND))
! bufferSize = globalSize/int(numProcs,MPI_OFFSET_KIND)
! allocate(recvcnt(0:numProcs-1))
! allocate(displc(0:numProcs-1))
! recvcnt(0:indexQuotient-1) = bufferSize+1
! recvcnt(indexQuotient:numProcs-1) = bufferSize
! displc = 0
! do i=1,numProcs-1
! displc(i) = SUM(recvcnt(0:i-1))
! end do
! offset = displc(procRank)*SIZEOF_SCALAR
!
! if( procRank<indexQuotient ) then
! sendcnt = bufferSize+1
! else
! sendcnt = bufferSize
! end if
! allocate(ZBuffer(sendcnt))
! ZBuffer = 0.0_wp
!
! call endTiming("Buffer setup")
! call startTiming("Write file")
!
! call MPI_Barrier(comm, ierror)
!
! call MPI_File_open(comm, trim(ZFilename), &
! MPI_MODE_WRONLY + MPI_MODE_CREATE, MPI_INFO_NULL, &
! mpiFileHandle, ierror)
! call MPI_FILE_SET_VIEW(mpiFileHandle,offset,MPI_DOUBLE,MPI_DOUBLE, &
! 'native',MPI_INFO_NULL,ierror)
! call MPI_File_write_all(mpiFileHandle, ZBuffer, int(sendcnt), &
! SCALAR_TYPE_MPI, MPI_STATUS_IGNORE, ierror)
! call MPI_File_close(mpiFileHandle, ierror)
!
! call MPI_Barrier(comm, ierror)
!
! call endTiming("Write file")
!
! write(message, '(A)') " done!"
! call writeAndFlush(comm, output_unit, message)
!
! end subroutine

end program paste_control_forcing
8 changes: 2 additions & 6 deletions bin/patchup_qfile.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ program patchup_qfile
end type t_VectorInternal

integer, parameter :: wp = SCALAR_KIND
integer :: i, j, stat, fileUnit, procRank, numProcs, ierror
integer :: i, j, procRank, numProcs, ierror
integer :: kthArgument, numberOfArguments
logical :: lookForInput = .false., inputFlag = .false.
character(len = STRING_LENGTH) :: argument, inputFilename, mollifierFilename
character(len = STRING_LENGTH) :: filename, outputPrefix, message, &
Zfilename, Astr, Xfilename, Yfilename
Zfilename, Xfilename, Yfilename
logical :: fileExists, zeroYfile = .false., success
integer, dimension(:,:), allocatable :: globalGridSizes
type(t_Region) :: region
type(t_VectorInternal), allocatable :: X(:), Y(:), antiW(:)

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: A

! Initialize MPI.
call MPI_Init(ierror)
call MPI_Comm_rank(MPI_COMM_WORLD, procRank, ierror)
Expand Down
3 changes: 1 addition & 2 deletions bin/qfile_zaxpy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program qfile_zaxpy
end type t_VectorInternal

integer, parameter :: wp = SCALAR_KIND
integer :: i, j, stat, fileUnit, procRank, numProcs, ierror
integer :: i, j, procRank, numProcs, ierror
integer :: kthArgument, numberOfArguments
logical :: lookForInput = .false., lookForMollifier = .false., &
inputFlag = .false., mollifierFlag = .false.
Expand All @@ -35,7 +35,6 @@ program qfile_zaxpy
type(t_VectorInternal), allocatable :: X(:), Y(:)

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: A

! Initialize MPI.
Expand Down
5 changes: 2 additions & 3 deletions bin/slice_control_forcing.f90
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ subroutine sliceControlForcing(comm,ZFilename,XFilename,totalTimestep,startTimes
integer, parameter :: wp = SCALAR_KIND
integer :: i, procRank, numProcs, ierror, mpiFileHandle
character(len = STRING_LENGTH) :: message
logical :: XFileExists, success
integer(kind = MPI_OFFSET_KIND) :: XFileSize, ZFileSize, offset, globalOffset
logical :: XFileExists
integer(kind = MPI_OFFSET_KIND) :: XFileSize, offset, globalOffset

integer(kind = MPI_OFFSET_KIND) :: globalSize, patchSize, sliceSize, bufferSize, sendcnt, indexQuotient
integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc
SCALAR_TYPE, dimension(:), allocatable :: XBuffer
SCALAR_TYPE :: dummyValue

! Initialize MPI.
call MPI_Comm_rank(comm, procRank, ierror)
Expand Down
1 change: 0 additions & 1 deletion bin/spatial_inner_product.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ program spatial_inner_product
type(t_VectorInternal), allocatable :: temp(:)

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
Expand Down
11 changes: 4 additions & 7 deletions bin/terminal_objective.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ program terminal_objective
integer :: mode
character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename
character(len = STRING_LENGTH) :: filename, outputPrefix, message
logical :: adjointRestart, fileExists, success
integer :: accumulatedNTimesteps
logical :: fileExists, success
integer, dimension(:,:), allocatable :: globalGridSizes
type(t_Region) :: region
type(t_Solver) :: solver

! << output variables >>
integer :: inputNumber, simulationNumber
SCALAR_TYPE :: dummyValue = 0.0_wp

! Initialize MPI.
Expand Down Expand Up @@ -221,10 +219,9 @@ function runTerminalObjective(this, region, mode) result(instantaneousCostFuncti
character(len = STRING_LENGTH) :: filename, message
class(t_Functional), pointer :: functional => null()
class(t_Patch), pointer :: patch => null()
integer :: i, j, timestep, startTimestep
real(wp) :: time, startTime, timeStepSize
logical :: controllerSwitch = .false., solutionCrashes = .false., &
nonzeroAdjointInitialCondition = .false.
integer :: i, j, startTimestep
real(wp) :: startTime
logical :: nonzeroAdjointInitialCondition = .false.

call startTiming("runTerminalObjective")

Expand Down
2 changes: 1 addition & 1 deletion bin/zXdotY.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program run_zXdotY
implicit none

integer, parameter :: wp = SCALAR_KIND
character(len = STRING_LENGTH) :: zFilename, WFilename, XFilename, YFilename, normFilename, message
character(len = STRING_LENGTH) :: zFilename, XFilename, YFilename, normFilename, message
SCALAR_TYPE :: z
integer :: stat, fileUnit, procRank, ierror

Expand Down
2 changes: 2 additions & 0 deletions examples/DeformingWall2D/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.q
*.f
10 changes: 10 additions & 0 deletions examples/DeformingWall2D/bc.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Name Type Grid normDir iMin iMax jMin jMax kMin kMax
# ==================== ===================== ==== ======= ==== ==== ==== ==== ==== ====
farField.N SAT_FAR_FIELD 1 -2 1 -1 -1 -1 1 -1
inflow.W SAT_FAR_FIELD 1 1 1 1 1 -1 1 -1
outflow.E SAT_FAR_FIELD 1 -1 -1 -1 1 -1 1 -1
immersed1 IMMERSED_BOUNDARY 1 0 1 -1 1 171 1 -1
sponge.N SPONGE 1 -2 1 -1 -15 -1 1 -1
sponge.W SPONGE 1 1 1 15 1 -1 1 -1
sponge.E SPONGE 1 -1 -15 -1 1 -1 1 -1
# targetRegion COST_TARGET 1 2 1 -1 1 1 1 -1
Loading

0 comments on commit 3f9aa79

Please sign in to comment.