From 668a2755f7c680c5e14910d80f5ba933a0abe89a Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Fri, 9 Dec 2022 11:40:27 -0600 Subject: [PATCH 01/13] IBM variable preparation. --- CMakeLists.txt | 2 + include/ImmersedBoundaryPatch.f90 | 86 +++++++++++++ include/SimulationFlags.f90 | 3 +- include/State.f90 | 36 ++++-- src/ImmersedBoundaryImpl.f90 | 200 ++++++++++++++++++++++++++++++ src/RegionImpl.f90 | 9 +- src/SimulationFlagsImpl.f90 | 15 +++ src/StateImpl.f90 | 21 ++++ 8 files changed, 361 insertions(+), 11 deletions(-) create mode 100644 include/ImmersedBoundaryPatch.f90 create mode 100644 src/ImmersedBoundaryImpl.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 013da1b8..d58ba959 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,8 @@ 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 # C source files. ${PROJECT_SOURCE_DIR}/src/PLOT3DFormat.c diff --git a/include/ImmersedBoundaryPatch.f90 b/include/ImmersedBoundaryPatch.f90 new file mode 100644 index 00000000..8a5a3356 --- /dev/null +++ b/include/ImmersedBoundaryPatch.f90 @@ -0,0 +1,86 @@ +#include "config.h" + +module ImmersedBoundaryPatch_mod + + use Patch_mod, only : t_Patch + + implicit none + + type, extends(t_Patch), public :: t_ImmersedBoundaryPatch + real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal, levelsetCurvature, & + indicatorFunction, primitiveGridNorm + real(SCALAR_KIND) :: globalVolumeFraction + contains + procedure, pass :: setup => setupImmersedBoundaryPatch + procedure, pass :: cleanup => cleanupImmersedBoundaryPatch + procedure, pass :: verifyUsage => verifyImmersedBoundaryPatchUsage + procedure, pass :: updateRhs => addImmersedBoundaryPenalty + procedure, pass :: updateLevelset => addImmersedBoundaryLevelset + end type t_ImmersedBoundaryPatch + + interface + subroutine setupImmersedBoundaryPatch(this, index, comm, patchDescriptor, & + grid, simulationFlags, solverOptions) + use Grid_mod, only : t_Grid + use SolverOptions_mod, only : t_SolverOptions + use PatchDescriptor_mod, only : t_PatchDescriptor + use SimulationFlags_mod, only : t_SimulationFlags + + import :: t_ImmersedBoundaryPatch + + class(t_ImmersedBoundaryPatch) :: this + integer, intent(in) :: index, comm + type(t_PatchDescriptor), intent(in) :: patchDescriptor + class(t_Grid), intent(in) :: grid + type(t_SimulationFlags), intent(in) :: simulationFlags + type(t_SolverOptions), intent(in) :: solverOptions + end subroutine setupImmersedBoundaryPatch + end interface + + interface + subroutine cleanupImmersedBoundaryPatch(this) + import :: t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this + end subroutine cleanupImmersedBoundaryPatch + end interface + + interface + function verifyImmersedBoundaryPatchUsage(this, patchDescriptor, gridSize, normalDirection, & + extent, simulationFlags, success, message) result(isPatchUsed) + use PatchDescriptor_mod, only : t_PatchDescriptor + use SimulationFlags_mod, only : t_SimulationFlags + import :: t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this + type(t_PatchDescriptor), intent(in) :: patchDescriptor + integer, intent(in) :: gridSize(:), normalDirection, extent(6) + type(t_SimulationFlags), intent(in) :: simulationFlags + logical, intent(out) :: success + character(len = STRING_LENGTH), intent(out) :: message + logical :: isPatchUsed + end function verifyImmersedBoundaryPatchUsage + end interface + + interface + subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions, grid, state) + use Grid_mod, only : t_Grid + use State_mod, only : t_State + use SolverOptions_mod, only : t_SolverOptions + use SimulationFlags_mod, only : t_SimulationFlags + import :: t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this + integer, intent(in) :: mode + type(t_SimulationFlags), intent(in) :: simulationFlags + type(t_SolverOptions), intent(in) :: solverOptions + class(t_Grid), intent(in) :: grid + class(t_State) :: state + end subroutine addImmersedBoundaryPenalty + end interface + + interface + subroutine addImmersedBoundaryLevelset(this) + import :: t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this + end subroutine addImmersedBoundaryLevelset + end interface + +end module ImmersedBoundaryPatch_mod diff --git a/include/SimulationFlags.f90 b/include/SimulationFlags.f90 index 366b26ab..dde3eefe 100644 --- a/include/SimulationFlags.f90 +++ b/include/SimulationFlags.f90 @@ -26,7 +26,8 @@ module SimulationFlags_mod computeTimeAverage = .false., & enableBodyForce = .false., & checkConservation = .false., & - IsInitialized = .false. + IsInitialized = .false., & + enableIBM = .false. contains diff --git a/include/State.f90 b/include/State.f90 index 02aaf442..89abe28a 100644 --- a/include/State.f90 +++ b/include/State.f90 @@ -50,18 +50,23 @@ end function getNumberOfScalars type, public :: t_State - type(t_AcousticSource), allocatable :: acousticSources(:) + type(t_AcousticSource), allocatable :: acousticSources(:) - integer :: nSpecies - real(wp) :: time, timeProgressive, adjointForcingFactor = 1.0_wp - SCALAR_TYPE :: plot3dAuxiliaryData(4) = 0.0_wp + integer :: nSpecies + real(wp) :: time, timeProgressive, adjointForcingFactor = 1.0_wp + SCALAR_TYPE :: plot3dAuxiliaryData(4) = 0.0_wp - SCALAR_TYPE, dimension(:,:), allocatable :: rightHandSide, conservedVariables, & - specificVolume, velocity, velocityGradient, stressTensor, pressure, temperature, & - heatFlux, dynamicViscosity, secondCoefficientOfViscosity, thermalDiffusivity, & - targetState, adjointVariables, timeAverage + SCALAR_TYPE, dimension(:,:), allocatable :: rightHandSide, conservedVariables, & + specificVolume, velocity, velocityGradient, stressTensor, pressure, temperature, & + heatFlux, dynamicViscosity, secondCoefficientOfViscosity, thermalDiffusivity, & + targetState, adjointVariables, timeAverage - SCALAR_TYPE, dimension(:,:), pointer :: dummyFunction => null() + ! Variables for immersed boundary method. + real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal!, indicatorFunction, & + !primitiveGridNorm, levelsetCurvature + real(SCALAR_KIND), dimension(:,:), allocatable :: ibmDissipation, nDotGradRho, uDotGradRho + + SCALAR_TYPE, dimension(:,:), pointer :: dummyFunction => null() contains @@ -74,6 +79,7 @@ end function getNumberOfScalars procedure, pass :: computeCfl => computeStateCfl procedure, pass :: computeTimeStepSize => computeStateTimeStepSize procedure, pass :: addSources + procedure, pass :: updateIBMVariables end type t_State @@ -253,4 +259,16 @@ end subroutine addSources end interface + interface + subroutine updateIBMVariables(this, mode, grid, simulationFlags) + use Grid_mod, only : t_Grid + use SimulationFlags_mod, only : t_SimulationFlags + import :: t_State + class(t_State) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grid + type(t_SimulationFlags), intent(in) :: simulationFlags + end subroutine updateIBMVariables + end interface + end module State_mod diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 new file mode 100644 index 00000000..1fe5b950 --- /dev/null +++ b/src/ImmersedBoundaryImpl.f90 @@ -0,0 +1,200 @@ +#include "config.h" + +subroutine setupImmersedBoundaryPatch(this, index, comm, patchDescriptor, & + grid, simulationFlags, solverOptions) + ! <<< External modules >>> + use MPI + use iso_fortran_env, only : output_unit + + ! <<< Derived types >>> + use Grid_mod, only : t_Grid + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + use SolverOptions_mod, only : t_SolverOptions + use PatchDescriptor_mod, only : t_PatchDescriptor + use SimulationFlags_mod, only : t_SimulationFlags + + ! <<< Internal modules >>> + use InputHelper, only : getOption, getRequiredOption + use ErrorHandler, only : writeAndFlush, gracefulExit + + implicit none + + ! <<< Arguments >>> + class(t_ImmersedBoundaryPatch) :: this + integer, intent(in) :: index, comm + type(t_PatchDescriptor), intent(in) :: patchDescriptor + class(t_Grid), intent(in) :: grid + type(t_SimulationFlags), intent(in) :: simulationFlags + type(t_SolverOptions), intent(in) :: solverOptions + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + character(len = STRING_LENGTH) :: message + + call this%cleanup() + call this%setupBase(index, comm, patchDescriptor, grid, simulationFlags, solverOptions) + + if (simulationFlags%enableAdjoint) then + write(message, '(A)') "ImmersedBoundaryPatch does not support adjoint mode!" + call gracefulExit(this%comm, message) + end if + + ! ! Store the unmodified grid norm + ! allocate(this%primitiveGridNorm(this%nPatchPoints, 1)) + ! call this%collect(grid%norm, this%primitiveGridNorm) +end subroutine setupImmersedBoundaryPatch + +subroutine cleanupImmersedBoundaryPatch(this) + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + + implicit none + + ! <<< Arguments >>> + class(t_ImmersedBoundaryPatch) :: this + + call this%cleanupBase() +end subroutine cleanupImmersedBoundaryPatch + +function verifyImmersedBoundaryPatchUsage(this, patchDescriptor, gridSize, normalDirection, & + extent, simulationFlags, success, message) result(isPatchUsed) + + ! <<< Derived types >>> + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + use PatchDescriptor_mod, only : t_PatchDescriptor + use SimulationFlags_mod, only : t_SimulationFlags + + implicit none + + ! <<< Arguments >>> + class(t_ImmersedBoundaryPatch) :: this + type(t_PatchDescriptor), intent(in) :: patchDescriptor + integer, intent(in) :: gridSize(:), normalDirection, extent(6) + type(t_SimulationFlags), intent(in) :: simulationFlags + logical, intent(out) :: success + character(len = STRING_LENGTH), intent(out) :: message + + ! <<< Result >>> + logical :: isPatchUsed + + ! <<< Local variables >>> + integer :: i + + isPatchUsed = .false. + + success = .false. + + do i = 1, size(gridSize) + if (extent((i-1)*2+1) < 0 .or. extent((i-1)*2+2) > gridSize(i) .or. & + extent((i-1)*2+1) > extent((i-1)*2+2)) then + write(message, '(A)') "Invalid extent!" + return + end if + end do + + success = .true. + +end function verifyImmersedBoundaryPatchUsage + +subroutine addImmersedBoundaryPenalty(this) + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this +end subroutine addImmersedBoundaryPenalty + +subroutine addImmersedBoundaryLevelset(this) + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + class(t_ImmersedBoundaryPatch) :: this +end subroutine addImmersedBoundaryLevelset + +! t_State method +subroutine updateIBMVariables(this, mode, grid, simulationFlags) + + ! <<< Derived types >>> + use Grid_mod, only : t_Grid + use State_mod, only : t_State + use SimulationFlags_mod, only : t_SimulationFlags + + ! <<< Enumerations >>> + use Region_enum, only : FORWARD + + ! <<< Internal modules >>> + use MPITimingsHelper, only : startTiming, endTiming + + implicit none + + ! <<< Arguments >>> + class(t_State) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grid + type(t_SimulationFlags), intent(in) :: simulationFlags + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + integer :: i, j, n, nUnknowns + real(wp) :: buf + real(wp), dimension(:, :), allocatable :: densityGradient, dissipationTerm + real(wp), dimension(:), allocatable :: objectVelocity + + call startTiming("updateIBMVariables") + + if (mode .ne. FORWARD) then + return + end if + + assert(size(this%levelset, 1) == size(this%conservedVariables, 1)) + assert(size(this%levelset, 2) == 1) + + nUnknowns = size(this%conservedVariables, 2) + + allocate(densityGradient(grid%nGridPoints, grid%nDimensions)) + allocate(dissipationTerm(grid%nGridPoints, nUnknowns)) + allocate(objectVelocity(grid%nDimensions)) + + !TODO: compute levelset. + this%levelset(:, 1) = grid%coordinates(:, 2) - 0.0_wp + + ! compute levelset normal. + call grid%computeGradient(this%levelset(:, 1), this%levelsetNormal) + + do i = 1, grid%nGridPoints + ! Make the levelset normal a unit norm + buf = sqrt(sum(this%levelsetNormal(i,:) ** 2)) + if (buf .gt. 0.0_wp) this%levelsetNormal(i,:) = this%levelsetNormal(i,:) / buf + + ! ! Compute indicator function + ! if (levelset(i, 1) .le. 0.0_wp) then + ! indicatorFunction(i, 1) = 0.0_wp + ! else + ! indicatorFunction(i, 1) = 1.0_wp + ! end if + ! + ! ! Update the grid norm + ! gridNorm(i, 1) = primitiveGridNorm(i, 1) * indicatorFunction(i, 1) + end do + + !TODO: object velocity. + objectVelocity = 0.0_wp + + this%nDotGradRho = 0.0_wp + this%uDotGradRho = 0.0_wp + this%ibmDissipation = 0.0_wp + call grid%computeGradient(this%conservedVariables(:,1), densityGradient) + do n = 1, grid%nDimensions + this%nDotGradRho(:, 1) = this%nDotGradRho(:, 1) + this%levelsetNormal(:, n) * densityGradient(:, n) + this%uDotGradRho(:, 1) = this%uDotGradRho(:, 1) + objectVelocity(n) * densityGradient(:, n) + + ! Dissipation term. + dissipationTerm = this%conservedVariables + call grid%dissipation(n)%apply(dissipationTerm, grid%localSize) + if (.not. simulationFlags%compositeDissipation) then + do j = 1, nUnknowns + dissipationTerm(:,j) = - grid%arcLengths(:,n) * dissipationTerm(:,j) + end do + call grid%dissipationTranspose(n)%apply(dissipationTerm, grid%localSize) + call grid%firstDerivative(n)%applyNormInverse(dissipationTerm, grid%localSize) + end if + this%ibmDissipation = this%ibmDissipation + dissipationTerm + end do + + call endTiming("updateIBMVariables") + +end subroutine updateIBMVariables diff --git a/src/RegionImpl.f90 b/src/RegionImpl.f90 index 5ee2f33a..84933e0f 100644 --- a/src/RegionImpl.f90 +++ b/src/RegionImpl.f90 @@ -1745,6 +1745,13 @@ subroutine computeRhs(this, mode, timeStep, stage) end do end do + ! Update immersed boundary variables. + if (this%simulationFlags%enableIBM) then + do i = 1, size(this%states) + call this%states(i)%updateIBMVariables(mode, this%grids(i), this%simulationFlags) + end do + end if + ! Add patch penalties. if (allocated(this%patchFactories)) then do i = 1, size(this%patchFactories) @@ -1758,7 +1765,7 @@ subroutine computeRhs(this, mode, timeStep, stage) end do end if - ! Source terms. + ! Acoustic source terms. do i = 1, size(this%states) call this%states(i)%addSources(mode, this%grids(i)) end do diff --git a/src/SimulationFlagsImpl.f90 b/src/SimulationFlagsImpl.f90 index ae9f0e33..49ee02b5 100644 --- a/src/SimulationFlagsImpl.f90 +++ b/src/SimulationFlagsImpl.f90 @@ -2,17 +2,25 @@ subroutine initializeSimulationFlags(this) + ! <<< External modules >>> + use MPI + ! <<< Derived types >>> use SimulationFlags_mod, only : t_SimulationFlags ! <<< Internal modules >>> use InputHelper, only : getOption + use ErrorHandler, only : gracefulExit implicit none ! <<< Arguments >>> class(t_SimulationFlags) :: this + ! <<< Local variables >>> + integer :: comm_ + character(len = STRING_LENGTH) :: message + this%viscosityOn = getOption("include_viscous_terms", .false.) this%enableController = getOption("enable_controller", .false.) this%enableFunctional = getOption("enable_functional", .false.) @@ -32,6 +40,7 @@ subroutine initializeSimulationFlags(this) this%compositeDissipation = getOption("composite_dissipation", .true.) this%enableBodyForce = getOption("enable_body_force", .false.) this%checkConservation = getOption("check_conservation", .false.) + this%enableIBM = getOption("enable_immersed_boundary", .false.) this%computeTimeAverage = .false. if (.not. this%useConstantCfl) & @@ -42,6 +51,12 @@ subroutine initializeSimulationFlags(this) this%enableFunctional = .true. end if + if (this%enableAdjoint .and. this%enableIBM) then + comm_ = MPI_COMM_WORLD + write(message, '(A)') "Adjoint mode for immersed boundary method is not implemented!" + call gracefulExit(comm_, message) + end if + this%IsInitialized = .true. end subroutine initializeSimulationFlags diff --git a/src/StateImpl.f90 b/src/StateImpl.f90 index 4af5012e..4c683bde 100644 --- a/src/StateImpl.f90 +++ b/src/StateImpl.f90 @@ -54,6 +54,17 @@ subroutine allocateData(this, simulationFlags, solverOptions, nGridPoints, nDime allocate(this%adjointVariables(nGridPoints, solverOptions%nUnknowns)) end if + if (simulationFlags%enableIBM) then + ! Allocate levelset arrays + allocate(this%levelset(nGridPoints, 1)) + allocate(this%levelsetNormal(nGridPoints, nDimensions)) + ! allocate(this%levelsetCurvature(grid%nGridPoints, 1)) + ! allocate(this%indicatorFunction(grid%nGridPoints, 1)) + allocate(this%ibmDissipation(nGridPoints, solverOptions%nUnknowns)) + allocate(this%nDotGradRho(nGridPoints, 1)) + allocate(this%uDotGradRho(nGridPoints, 1)) + end if + end subroutine allocateData end module StateImpl @@ -168,6 +179,16 @@ subroutine cleanupState(this) SAFE_DEALLOCATE(this%heatFlux) SAFE_DEALLOCATE(this%timeAverage) + ! deallocate levelset arrays + SAFE_DEALLOCATE(this%levelset) + SAFE_DEALLOCATE(this%levelsetNormal) + ! SAFE_DEALLOCATE(this%levelsetCurvature) + ! SAFE_DEALLOCATE(this%indicatorFunction) + ! SAFE_DEALLOCATE(this%primitiveGridNorm) + SAFE_DEALLOCATE(this%ibmDissipation) + SAFE_DEALLOCATE(this%nDotGradRho) + SAFE_DEALLOCATE(this%uDotGradRho) + this%adjointForcingFactor = 1.0_wp end subroutine cleanupState From ff749c8f6a2557c6992854c784c30f7b2bddacd7 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Fri, 9 Dec 2022 13:08:50 -0600 Subject: [PATCH 02/13] IBM isothermal wall volume penalization. --- include/ImmersedBoundaryPatch.f90 | 7 +- src/ImmersedBoundaryImpl.f90 | 168 +++++++++++++++++++++++++++++- 2 files changed, 171 insertions(+), 4 deletions(-) diff --git a/include/ImmersedBoundaryPatch.f90 b/include/ImmersedBoundaryPatch.f90 index 8a5a3356..9cfa3153 100644 --- a/include/ImmersedBoundaryPatch.f90 +++ b/include/ImmersedBoundaryPatch.f90 @@ -7,9 +7,10 @@ module ImmersedBoundaryPatch_mod implicit none type, extends(t_Patch), public :: t_ImmersedBoundaryPatch - real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal, levelsetCurvature, & - indicatorFunction, primitiveGridNorm - real(SCALAR_KIND) :: globalVolumeFraction + ! real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal, levelsetCurvature, & + ! indicatorFunction, primitiveGridNorm + real(SCALAR_KIND) :: ratioOfSpecificHeats, ibmTemperature + real(SCALAR_KIND) :: dti, maxSpeed, dissipationAmount, ibmEpsilon contains procedure, pass :: setup => setupImmersedBoundaryPatch procedure, pass :: cleanup => cleanupImmersedBoundaryPatch diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index 1fe5b950..3a269636 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -1,5 +1,39 @@ #include "config.h" +module ImmersedBoundaryImpl + + implicit none + public + +contains + + ! Regularized a Heaviside function + ! phi: signed-distance (levelset) + ! eps: regularization parameters (length) + ! --------------------------------------- + function regularizeHeaviside(phi, eps) result(H) + + implicit none + + ! Arguments + integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) + real(wp), intent(in) :: phi, eps + real(wp) :: H + + if (phi .le. -eps) then + H = 0.0_wp + else if (abs(phi) .lt. eps) then + H = 0.5_wp * (1.0_wp + phi / eps + 1.0_wp / pi * sin(phi * pi / eps)) + else + H = 1.0_wp + end if + + return + end function regularizeHeaviside + +end module ImmersedBoundaryImpl + subroutine setupImmersedBoundaryPatch(this, index, comm, patchDescriptor, & grid, simulationFlags, solverOptions) ! <<< External modules >>> @@ -39,6 +73,25 @@ subroutine setupImmersedBoundaryPatch(this, index, comm, patchDescriptor, call gracefulExit(this%comm, message) end if + ! Set the max speed based on the reference sound speed + this%maxSpeed = 1.0_wp + + ! Store inverse timestep size + this%dti = 1.0_wp / solverOptions%timeStepSize + + ! Set the diffusion amount based on the stability limit + call getRequiredOption("immersed_boundary/dissipation_amount", this%dissipationAmount, this%comm) + ! dissipationAmount = 0.05_WP * minGridSpacing**2 * dti / real(nDimensions, WP) + + this%ibmEpsilon = getOption("immersed_boundary/regularization_parameter", 0.0_wp) + + ! Import specific heat ratio + this%ratioOfSpecificHeats = solverOptions%ratioOfSpecificHeats + + ! Set wall temperature + this%ibmTemperature = getOption("immersed_boundary/wall_temperature", & + 1.0_wp / (solverOptions%ratioOfSpecificHeats - 1.0_wp)) + ! ! Store the unmodified grid norm ! allocate(this%primitiveGridNorm(this%nPatchPoints, 1)) ! call this%collect(grid%norm, this%primitiveGridNorm) @@ -95,9 +148,118 @@ function verifyImmersedBoundaryPatchUsage(this, patchDescriptor, gridSize, norma end function verifyImmersedBoundaryPatchUsage -subroutine addImmersedBoundaryPenalty(this) +subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions, grid, state) + ! <<< Derived types >>> + use Grid_mod, only : t_Grid + use State_mod, only : t_State + use SolverOptions_mod, only : t_SolverOptions + use SimulationFlags_mod, only : t_SimulationFlags use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch + + ! <<< Enumerations >>> + use Region_enum, only : FORWARD, ADJOINT, LINEARIZED + + ! <<< Internal module >>> + use ImmersedBoundaryImpl, only : regularizeHeaviside + + implicit none + + ! <<< Arguments >>> class(t_ImmersedBoundaryPatch) :: this + integer, intent(in) :: mode + type(t_SimulationFlags), intent(in) :: simulationFlags + type(t_SolverOptions), intent(in) :: solverOptions + class(t_Grid), intent(in) :: grid + class(t_State) :: state + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + integer :: nUnknowns, nDimensions + integer :: i, j, k, n, gridIndex, patchIndex + real(wp) :: localDensity, localVelocity(grid%nDimensions), localVelocitySquared, & + localnDotGradRho, localuDotGradRho, localIbmDissipation(size(state%conservedVariables, 2)) + real(wp) :: objectVelocity(grid%nDimensions), source_(size(state%conservedVariables, 2)), velocityPenalty(grid%nDimensions) + real(wp) :: buf, weight + + !TODO: implement adjoint. + assert_key(mode, (FORWARD)) + assert(this%gridIndex == grid%index) + assert(all(grid%offset == this%gridOffset)) + assert(all(grid%localSize == this%gridLocalSize)) + + nUnknowns = size(state%conservedVariables, 2) + nDimensions = grid%nDimensions + + ! Collect IBM variables. + !TODO: collect object velocity. + objectVelocity = 0.0_wp + + ! Update the source terms and IBM forcing + do k = this%offset(3) + 1, this%offset(3) + this%localSize(3) + do j = this%offset(2) + 1, this%offset(2) + this%localSize(2) + do i = this%offset(1) + 1, this%offset(1) + this%localSize(1) + gridIndex = i - this%gridOffset(1) + this%gridLocalSize(1) * & + (j - 1 - this%gridOffset(2) + this%gridLocalSize(2) * & + (k - 1 - this%gridOffset(3))) + if (grid%iblank(gridIndex) == 0) cycle + patchIndex = i - this%offset(1) + this%localSize(1) * & + (j - 1 - this%offset(2) + this%localSize(2) * & + (k - 1 - this%offset(3))) + + localDensity = state%conservedVariables(gridIndex, 1) + localVelocity = state%velocity(gridIndex, :) + localVelocitySquared = sum(localVelocity ** 2) + localnDotGradRho = state%nDotGradRho(gridIndex, 1) + localuDotGradRho = state%uDotGradRho(gridIndex, 1) + localIbmDissipation = state%ibmDissipation(gridIndex, :) + ! ! Get velocity of associated object + ! if (ibm_move) then + ! n = objectIndex(i) + ! objectVelocity = object(n)%velocity(1:nDimensions) + ! ibmVelocity(i,:) = objectVelocity + ! else + ! objectVelocity = 0.0_WP + ! end if + + ! Compute the velocity penalty + velocityPenalty = objectVelocity - localVelocity + + ! Zero-out the local source terms + source_ = 0.0_WP + + ! Density treatment + source_(1) = this%maxSpeed * localnDotGradRho - localuDotGradRho & + + this%dissipationAmount * localIbmDissipation(1) + + ! Momentum treatment + do n = 1, nDimensions + source_(n+1) = localDensity * velocityPenalty(n) * this%dti + & + localVelocity(n) * (this%maxSpeed * localnDotGradRho - localuDotGradRho) + & + this%dissipationAmount * localIbmDissipation(n+1) + end do + + ! Energy treatment + source_(nDimensions+2) = 0.5_wp * localVelocitySquared * (this%maxSpeed * localnDotGradRho - & + localuDotGradRho) + this%dissipationAmount * localIbmDissipation(nDimensions+2) + & + sum(state%conservedVariables(gridIndex, 2:nDimensions+1) * velocityPenalty(1:nDimensions)) * this%dti + + ! Isothermal + source_(nDimensions+2) = source_(nDimensions+2) + & + localDensity * (this%ibmTemperature - state%temperature(gridIndex,1)) / this%ratioOfSpecificHeats * this%dti + + ! Add the IBM contribution + buf = 0.0_wp + ! buf = ibmEpsilon * sqrt(sum((levelsetNormal(i,:) * gridSpacing(i, :))**2)) + weight = 1.0_wp - regularizeHeaviside(state%levelset(gridIndex, 1), buf) + if (state%levelset(gridIndex, 1) .le. 0.0_wp) then + state%rightHandSide(gridIndex,:) = source_ * weight + else + state%rightHandSide(gridIndex,:) = state%rightHandSide(gridIndex,:) & + + source_ * weight + end if + end do !... i = this%offset(1) + 1, this%offset(1) + this%localSize(1) + end do !... j = this%offset(2) + 1, this%offset(2) + this%localSize(2) + end do !... k = this%offset(3) + 1, this%offset(3) + this%localSize(3) end subroutine addImmersedBoundaryPenalty subroutine addImmersedBoundaryLevelset(this) @@ -195,6 +357,10 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) this%ibmDissipation = this%ibmDissipation + dissipationTerm end do + SAFE_DEALLOCATE(densityGradient) + SAFE_DEALLOCATE(dissipationTerm) + SAFE_DEALLOCATE(objectVelocity) + call endTiming("updateIBMVariables") end subroutine updateIBMVariables From 2a7b40f70587acf61775483a3a4f92f4940d165f Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Mon, 12 Dec 2022 20:33:04 -0600 Subject: [PATCH 03/13] utils/rhs: save individual patch rhs. --- utils/rhs.f90 | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/utils/rhs.f90 b/utils/rhs.f90 index 6567d97a..fdc4e766 100644 --- a/utils/rhs.f90 +++ b/utils/rhs.f90 @@ -105,9 +105,9 @@ end subroutine saveRhs ! Save RHS i = len_trim(filename) if (filename(i-1:i) == ".q") then - filename = filename(:i-2) // ".rhs.q" + filename = filename(:i-2) else - filename = PROJECT_NAME // ".rhs.q" + filename = PROJECT_NAME end if call saveRhs(region, filename) @@ -124,7 +124,7 @@ end subroutine saveRhs write(filename, '(2A,I8.8,A)') trim(outputPrefix), "-", i, ".q" call region%loadData(QOI_FORWARD_STATE, filename) - write(filename, '(2A,I8.8,A)') trim(outputPrefix), "-", i, ".rhs.q" + write(filename, '(2A,I8.8)') trim(outputPrefix), "-", i call saveRhs(region, filename) end do @@ -144,11 +144,15 @@ subroutine saveRhs(region, filename) ! <<< Derived types >>> use Region_mod, only : t_Region + use Patch_mod, only : t_Patch ! <<< Enumerations >>> use State_enum, only : QOI_DUMMY_FUNCTION use Region_enum, only : FORWARD + ! <<< External modules >>> + use InputHelper, only : getOption + implicit none ! <<< Arguments >>> @@ -156,12 +160,15 @@ subroutine saveRhs(region, filename) character(len = *), intent(in) :: filename ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + integer, save :: nDimensions = 0 + integer :: i, j + character(len = STRING_LENGTH) :: patchFile type :: t_RhsInternal SCALAR_TYPE, pointer :: buffer(:,:) => null() end type t_RhsInternal type(t_RhsInternal), allocatable, save :: data_(:) - integer, save :: nDimensions = 0 - integer :: i + class(t_Patch), pointer :: patch => null() assert(allocated(region%grids)) assert(allocated(region%states)) @@ -190,13 +197,39 @@ subroutine saveRhs(region, filename) end do end if - call region%computeRhs(FORWARD) + call region%computeRhs(FORWARD, region%timestep, 1) do i = 1, size(region%states) data_(i)%buffer = region%states(i)%rightHandSide region%states(i)%dummyFunction => data_(i)%buffer end do - call region%saveData(QOI_DUMMY_FUNCTION, filename) + call region%saveData(QOI_DUMMY_FUNCTION, trim(filename) // ".rhs.f") + + if (getOption("rhs/save_patch_rhs", .false.) .and. (allocated(region%patchFactories))) then + ! Add patch penalties. + do i = 1, size(region%patchFactories) + ! Zero out the right-hand side. + do j = 1, size(region%states) + region%states(j)%rightHandSide = 0.0_wp + end do + + call region%patchFactories(i)%connect(patch) + if (.not. associated(patch)) cycle + do j = 1, size(region%states) + if (patch%gridIndex /= region%grids(j)%index) cycle + call patch%updateRhs(FORWARD, region%simulationFlags, region%solverOptions, & + region%grids(j), region%states(j)) + end do + + do j = 1, size(region%states) + data_(j)%buffer = region%states(j)%rightHandSide + region%states(j)%dummyFunction => data_(j)%buffer + end do + + write(patchFile, '(3A)') trim(filename) // ".", trim(patch%name), ".f" + call region%saveData(QOI_DUMMY_FUNCTION, patchFile) + end do + end if end subroutine saveRhs From b96a375f292c65405ad417acdcd17c75c81ec469 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Tue, 13 Dec 2022 20:21:40 -0600 Subject: [PATCH 04/13] DeformingWall2D: initial laminar boundary layer setup. --- examples/DeformingWall2D/.gitignore | 2 + examples/DeformingWall2D/bc.dat | 10 +++ examples/DeformingWall2D/config.py | 126 ++++++++++++++++++++++++++++ examples/DeformingWall2D/magudi.inp | 76 +++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 examples/DeformingWall2D/.gitignore create mode 100644 examples/DeformingWall2D/bc.dat create mode 100644 examples/DeformingWall2D/config.py create mode 100644 examples/DeformingWall2D/magudi.inp diff --git a/examples/DeformingWall2D/.gitignore b/examples/DeformingWall2D/.gitignore new file mode 100644 index 00000000..eaceb320 --- /dev/null +++ b/examples/DeformingWall2D/.gitignore @@ -0,0 +1,2 @@ +*.q +*.f diff --git a/examples/DeformingWall2D/bc.dat b/examples/DeformingWall2D/bc.dat new file mode 100644 index 00000000..bfa6f551 --- /dev/null +++ b/examples/DeformingWall2D/bc.dat @@ -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 + flatPlate.S SAT_ISOTHERMAL_WALL 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 +# sponge.N SPONGE 1 -2 1 -1 -12 -1 1 -1 +# sponge.W SPONGE 1 1 1 25 1 -1 1 -1 +# sponge.E SPONGE 1 -1 1 -25 1 -1 1 -1 +# targetRegion COST_TARGET 1 2 1 -1 1 1 1 -1 diff --git a/examples/DeformingWall2D/config.py b/examples/DeformingWall2D/config.py new file mode 100644 index 00000000..6ee916ce --- /dev/null +++ b/examples/DeformingWall2D/config.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +import numpy as np +import scipy.sparse as sps +import plot3dnasa as p3d + +def mapping_function(x, sigma): + return np.sinh(sigma * x) / np.sinh(sigma) + +def grid(size, mapping_type='sinh'): + from scipy.optimize import fsolve + x_min = -10. + x_max = 100. + y_min = 0. + y_max = 25. + z_min = -40. + z_max = 40. + dy_min = 0.016 + num_uniform = 7 + g = p3d.Grid().set_size(size, True) + x = np.linspace(x_min, x_max, g.size[0,0] + 1)[:-1] + if mapping_type == 'sinh': + sigma = fsolve(lambda x: ( + (y_max - y_min - num_uniform * dy_min) * mapping_function( + 1. / (g.size[0,1] - 1.), x) - dy_min) ** 2, 2.) + y = np.append(np.linspace(y_min, y_min + dy_min * num_uniform, + num_uniform + 1), y_min + dy_min * + num_uniform + (y_max - y_min - num_uniform * dy_min) * + mapping_function(np.linspace(0., 1., g.size[0,1] - + num_uniform), sigma)[1:]) + else: + sigma = fsolve(lambda x: (y_max - y_min) / dy_min - num_uniform + 1 - + (x ** (g.size[0,1] - num_uniform) - 1.) / + (x - 1.), 1.02) + print 100. * (sigma - 1.) + y = np.append([0.], np.cumsum( + [dy_min if r < num_uniform - 1 + else dy_min * sigma ** (r - num_uniform + 1) + for r in range(g.size[0,1] - 1)])) + # z = np.linspace(z_min, z_max, g.size[0,2] + 1)[:-1] + for i in range(x.size): + g.xyz[0][i,:,:,0] = x[i] + for j in range(y.size): + g.xyz[0][:,j,:,1] = y[j] + # for k in range(z.size): + # g.xyz[0][:,:,k,2] = z[k] + return g + +def solve_blasius(eta_max, Ng = 1001): + eta = np.linspace(0., eta_max, Ng) + dx = eta_max / Ng + f = np.zeros(Ng,) + + # Shooting method + fv0 = np.zeros(3,) + dfv0 = np.array([0., 0., 1.]) + fvHist = np.zeros([Ng, 3]) + def stateRhs(fv, dfv): + rhs = np.array([fv[1], fv[2], -0.5 * fv[2] * fv[0]]) + J = sps.csr_matrix([[0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [-0.5 * fv[2], 0.0, -0.5 * fv[0]]]) + return rhs, J.dot(dfv) + + Niter = 100 + threshold = 1e-15 + for iter in range(Niter): + fv = np.copy(fv0) + dfv = np.copy(dfv0) + fvHist[0] = np.copy(fv0) + for n in range(1, Ng): + k1, dk1 = stateRhs(fv, dfv) + k2, dk2 = stateRhs(fv + 0.5 * dx * k1, dfv + 0.5 * dx * dk1) + k3, dk3 = stateRhs(fv + 0.5 * dx * k2, dfv + 0.5 * dx * dk2) + k4, dk4 = stateRhs(fv + dx * k3, dfv + dx * dk3) + fv += dx / 6. * (k1 + 2. * k2 + 2. * k3 + k4) + dfv += dx / 6. * (dk1 + 2. * dk2 + 2. * dk3 + dk4) + fvHist[n] = np.copy(fv) + res = fv[1] - 1.0 + if (abs(res) < threshold): + print(iter, abs(res)) + break + else: + fv0[-1] -= res / dfv[1] + f = fvHist[:, 0] + + temp = np.append(eta[:,np.newaxis].T, fvHist.T, axis=0).T + # np.savetxt("blasius.txt", temp) + return temp + +def cubicSplineInterp(x, y): + from scipy.interpolate import splrep, BSpline + t, c, k = splrep(x, y, k = 3) + return BSpline(t, c, k) + +def initial_condition(g, mach_number=1.0 / 343.0, gamma=1.4, Re = 1.16e6): + x = g.xyz[0][:,:,:,0] + y = g.xyz[0][:,:,:,1] + + xmin = np.amin(x) + delta = np.sqrt((x - xmin) / Re / mach_number + 1.0) + eta = y / delta + print(eta[0, 10, -1], eta[-1, 10, -1]) + blasiusTable = solve_blasius(1.5 * np.amax(eta)) + uTable = mach_number * blasiusTable[:, 2] + vtTable = 0.5 * (blasiusTable[:, 0] * blasiusTable[:, 2] - blasiusTable[:, 1]) + uFunc = cubicSplineInterp(blasiusTable[:, 0], uTable) + vtFunc = cubicSplineInterp(blasiusTable[:, 0], vtTable) + + u0 = uFunc(eta) + v0 = vtFunc(eta) / Re / delta + p = 1.0 / gamma + + s = p3d.Solution().copy_from(g).quiescent(gamma) + s.q[0][:,:,:,0] = 1.0 + s.q[0][:,:,:,1:4] = 0.0 + s.q[0][:,:,:,1] = u0 + s.q[0][:,:,:,2] = v0 + s.q[0][:,:,:,4] = p + return s.fromprimitive() + +if __name__ == '__main__': + g = grid([301, 201], mapping_type='geom') + g.save('DeformingWall2D.xyz') + s = initial_condition(g, Re = 23175.7) + s.save('DeformingWall2D.ic.q') + s.save('DeformingWall2D.target.q') diff --git a/examples/DeformingWall2D/magudi.inp b/examples/DeformingWall2D/magudi.inp new file mode 100644 index 00000000..31b6bb11 --- /dev/null +++ b/examples/DeformingWall2D/magudi.inp @@ -0,0 +1,76 @@ +# magudi.inp +# Input file to magudi for simulation of a two-dimensional channel flow with a deforming wall +# Written by "Kevin" Seung Whan Chung + +# Filenames, etc. +output_prefix = "DeformingWall2D" +grid_file = "DeformingWall2D.xyz" +initial_condition_file = "DeformingWall2D.ic.q" +target_state_file = "DeformingWall2D.target.q" +boundary_condition_file = "bc.dat" + +# Simulation flags +include_viscous_terms = true +use_constant_CFL_mode = false +use_target_state = true +curvilinear_domain = false + +# Controller flags +enable_controller = false +controller_switch = false + +# Functional flags +enable_functional = false +cost_functional_type = "DRAG" + +# Adjoint optimization flags +enable_adjoint_solver = false +baseline_prediction_available = true +use_continuous_adjoint = false +controller_buffer_size = 100 + +# Gradient accuracy options +check_gradient_accuracy = false + +# Physical constants +Reynolds_number = 23175.7 +Prandtl_number = 0.7 +viscosity_power_law_exponent = 0.0 + +# Discretization scheme +defaults/discretization_scheme = "SBP 3-6" + +# Time stepping options +time_step_size = 1.2e-2 +number_of_timesteps = 4000 +report_interval = 10 +save_interval = 200 + +# Artificial dissipation +add_dissipation = false +dissipation_amount = 0.0002 +composite_dissipation = false + +# Solution limits +enable_solution_limits = true +minimum_density = 0.1 +minimum_temperature = 0.05 +maximum_density = 5. +maximum_temperature = 4. + +## Periodicity +#grid001/dir1/periodicity_type = 'PLANE' +#grid001/dir1/periodic_length = 5.0 + +# Penalty parameters +#defaults/viscous_penalty_amount = 0. +# This is based on actual Reynolds_number +#patches/flatPlate.N/viscous_penalty_amount1 = 2. +#patches/flatPlate.S/viscous_penalty_amount1 = 2. + +# Body force parameters +enable_body_force = false +body_force/initial_momentum = 0.00194363459 + +# utils/rhs +rhs/save_patch_rhs = true From e330150cbbb622e1038a2965614ae0881cbd2dbb Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Wed, 14 Dec 2022 17:15:33 -0600 Subject: [PATCH 05/13] SimulationFlags: assign all attributes. --- src/SimulationFlagsImpl.f90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SimulationFlagsImpl.f90 b/src/SimulationFlagsImpl.f90 index 49ee02b5..4e130e5f 100644 --- a/src/SimulationFlagsImpl.f90 +++ b/src/SimulationFlagsImpl.f90 @@ -92,6 +92,7 @@ subroutine assignSimulationFlags(this, simulationFlags) this%enableController = simulationFlags%enableController this%enableFunctional = simulationFlags%enableFunctional this%enableAdjoint = simulationFlags%enableAdjoint + this%adjointForcingSwitch = simulationFlags%adjointForcingSwitch this%repeatFirstDerivative = simulationFlags%repeatFirstDerivative this%useTargetState = simulationFlags%useTargetState this%dissipationOn = simulationFlags%dissipationOn @@ -104,6 +105,9 @@ subroutine assignSimulationFlags(this, simulationFlags) this%isBaselineAvailable = simulationFlags%isBaselineAvailable this%useContinuousAdjoint = simulationFlags%useContinuousAdjoint this%compositeDissipation = simulationFlags%compositeDissipation + this%enableBodyForce = simulationFlags%enableBodyForce + this%checkConservation = simulationFlags%checkConservation + this%enableIBM = simulationFlags%enableIBM this%computeTimeAverage = simulationFlags%computeTimeAverage From e5236d621005df2a4a8807c7a51dbb2e397524f4 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Wed, 14 Dec 2022 17:17:21 -0600 Subject: [PATCH 06/13] DeformingWall2D: laminar stationary boundary layer with immersed boundary. --- examples/DeformingWall2D/bc.dat | 2 +- examples/DeformingWall2D/config.py | 55 ++++++++++++++++++++++++----- examples/DeformingWall2D/magudi.inp | 5 +++ src/ImmersedBoundaryImpl.f90 | 20 ++++++----- src/PatchFactoryImpl.f90 | 4 +++ 5 files changed, 68 insertions(+), 18 deletions(-) diff --git a/examples/DeformingWall2D/bc.dat b/examples/DeformingWall2D/bc.dat index bfa6f551..56d79938 100644 --- a/examples/DeformingWall2D/bc.dat +++ b/examples/DeformingWall2D/bc.dat @@ -1,9 +1,9 @@ # Name Type Grid normDir iMin iMax jMin jMax kMin kMax # ==================== ===================== ==== ======= ==== ==== ==== ==== ==== ==== farField.N SAT_FAR_FIELD 1 -2 1 -1 -1 -1 1 -1 - flatPlate.S SAT_ISOTHERMAL_WALL 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 -12 -1 1 -1 # sponge.W SPONGE 1 1 1 25 1 -1 1 -1 # sponge.E SPONGE 1 -1 1 -25 1 -1 1 -1 diff --git a/examples/DeformingWall2D/config.py b/examples/DeformingWall2D/config.py index 6ee916ce..006bac86 100644 --- a/examples/DeformingWall2D/config.py +++ b/examples/DeformingWall2D/config.py @@ -6,7 +6,7 @@ def mapping_function(x, sigma): return np.sinh(sigma * x) / np.sinh(sigma) -def grid(size, mapping_type='sinh'): +def grid(size, dip_range, mapping_type='sinh'): from scipy.optimize import fsolve x_min = -10. x_max = 100. @@ -16,26 +16,38 @@ def grid(size, mapping_type='sinh'): z_max = 40. dy_min = 0.016 num_uniform = 7 - g = p3d.Grid().set_size(size, True) - x = np.linspace(x_min, x_max, g.size[0,0] + 1)[:-1] + + x = np.linspace(x_min, x_max, size[0] + 1)[:-1] if mapping_type == 'sinh': sigma = fsolve(lambda x: ( (y_max - y_min - num_uniform * dy_min) * mapping_function( - 1. / (g.size[0,1] - 1.), x) - dy_min) ** 2, 2.) + 1. / (size[1] - 1.), x) - dy_min) ** 2, 2.) y = np.append(np.linspace(y_min, y_min + dy_min * num_uniform, num_uniform + 1), y_min + dy_min * num_uniform + (y_max - y_min - num_uniform * dy_min) * - mapping_function(np.linspace(0., 1., g.size[0,1] - + mapping_function(np.linspace(0., 1., size[1] - num_uniform), sigma)[1:]) else: sigma = fsolve(lambda x: (y_max - y_min) / dy_min - num_uniform + 1 - - (x ** (g.size[0,1] - num_uniform) - 1.) / + (x ** (size[1] - num_uniform) - 1.) / (x - 1.), 1.02) print 100. * (sigma - 1.) y = np.append([0.], np.cumsum( [dy_min if r < num_uniform - 1 else dy_min * sigma ** (r - num_uniform + 1) - for r in range(g.size[0,1] - 1)])) + for r in range(size[1] - 1)])) + + # leftIdx, rightIdx = p3d.find_extents(x, dip_range[0], dip_range[1]) + dummy, depthIdx = p3d.find_extents(y, 0.0, dip_range[2]) + # assert(leftIdx >= 1) + # assert(rightIdx <= size[0]) + assert(depthIdx <= size[1]) + size[1] += depthIdx - 1 + y = np.append(-y[(depthIdx-1):0:-1], y) + + # sizes = [size, [rightIdx - leftIdx + 1, depthIdx]] + # print(sizes) + g = p3d.Grid().set_size(size, True) # z = np.linspace(z_min, z_max, g.size[0,2] + 1)[:-1] for i in range(x.size): g.xyz[0][i,:,:,0] = x[i] @@ -43,6 +55,28 @@ def grid(size, mapping_type='sinh'): g.xyz[0][:,j,:,1] = y[j] # for k in range(z.size): # g.xyz[0][:,:,k,2] = z[k] + + # for i in range(rightIdx - leftIdx + 1): + # g.xyz[1][i,:,:,0] = x[i + leftIdx - 1] + # for j in range(depthIdx): + # g.xyz[1][:,-1-j,:,1] = -y[j] + + patchRange = int(1.5 * depthIdx) + formatStr = ' {:<20} {:<21} {:>4d} {:>7d}' + 6 * ' {:>4d}' + print(formatStr.format('immersed1', 'IMMERSED_BOUNDARY', + 1, 0, 1, -1, 1, patchRange, 1, -1)) + # print(formatStr.format('interface.S1', 'SAT_BLOCK_INTERFACE', + # 1, 2, leftIdx, rightIdx, 1, 1, 1, -1)) + # print(formatStr.format('interface.N2', 'SAT_BLOCK_INTERFACE', + # 2, -2, 1, -1, -1, -1, 1, -1)) + # print(formatStr.format('immersed1', 'IMMERSED_BOUNDARY', + # 1, 0, leftIdx, rightIdx, 1, depthIdx, 1, -1)) + # print(formatStr.format('immersed2', 'IMMERSED_BOUNDARY', + # 2, 0, 1, -1, 1, -1, 1, -1)) + # print(formatStr.format('flatPlate.S1', 'SAT_ISOTHERMAL_WALL', + # 1, 2, 1, leftIdx - 1, 1, 1, 1, -1)) + # print(formatStr.format('flatPlate.N1', 'SAT_ISOTHERMAL_WALL', + # 1, 2, rightIdx + 1, -1, 1, 1, 1, -1)) return g def solve_blasius(eta_max, Ng = 1001): @@ -110,6 +144,10 @@ def initial_condition(g, mach_number=1.0 / 343.0, gamma=1.4, Re = 1.16e6): v0 = vtFunc(eta) / Re / delta p = 1.0 / gamma + mask = (eta < 0.0) + u0[mask] = 0.0 + v0[mask] = 0.0 + s = p3d.Solution().copy_from(g).quiescent(gamma) s.q[0][:,:,:,0] = 1.0 s.q[0][:,:,:,1:4] = 0.0 @@ -119,7 +157,8 @@ def initial_condition(g, mach_number=1.0 / 343.0, gamma=1.4, Re = 1.16e6): return s.fromprimitive() if __name__ == '__main__': - g = grid([301, 201], mapping_type='geom') + dip_range = [0.0, 15.0, 5.0] + g = grid([301, 201], dip_range, mapping_type='geom') g.save('DeformingWall2D.xyz') s = initial_condition(g, Re = 23175.7) s.save('DeformingWall2D.ic.q') diff --git a/examples/DeformingWall2D/magudi.inp b/examples/DeformingWall2D/magudi.inp index 31b6bb11..90bfbdef 100644 --- a/examples/DeformingWall2D/magudi.inp +++ b/examples/DeformingWall2D/magudi.inp @@ -72,5 +72,10 @@ maximum_temperature = 4. enable_body_force = false body_force/initial_momentum = 0.00194363459 +# Immersed boundary parameters +enable_immersed_boundary = true +immersed_boundary/dissipation_amount = 0.0 +immersed_boundary/regularization_parameter = 0.0 + # utils/rhs rhs/save_patch_rhs = true diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index 3a269636..27ee205b 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -145,6 +145,7 @@ function verifyImmersedBoundaryPatchUsage(this, patchDescriptor, gridSize, norma end do success = .true. + isPatchUsed = .true. end function verifyImmersedBoundaryPatchUsage @@ -345,15 +346,16 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) this%uDotGradRho(:, 1) = this%uDotGradRho(:, 1) + objectVelocity(n) * densityGradient(:, n) ! Dissipation term. - dissipationTerm = this%conservedVariables - call grid%dissipation(n)%apply(dissipationTerm, grid%localSize) - if (.not. simulationFlags%compositeDissipation) then - do j = 1, nUnknowns - dissipationTerm(:,j) = - grid%arcLengths(:,n) * dissipationTerm(:,j) - end do - call grid%dissipationTranspose(n)%apply(dissipationTerm, grid%localSize) - call grid%firstDerivative(n)%applyNormInverse(dissipationTerm, grid%localSize) - end if + dissipationTerm = 0.0_wp + ! dissipationTerm = this%conservedVariables + ! call grid%dissipation(n)%apply(dissipationTerm, grid%localSize) + ! if (.not. simulationFlags%compositeDissipation) then + ! do j = 1, nUnknowns + ! dissipationTerm(:,j) = - grid%arcLengths(:,n) * dissipationTerm(:,j) + ! end do + ! call grid%dissipationTranspose(n)%apply(dissipationTerm, grid%localSize) + ! call grid%firstDerivative(n)%applyNormInverse(dissipationTerm, grid%localSize) + ! end if this%ibmDissipation = this%ibmDissipation + dissipationTerm end do diff --git a/src/PatchFactoryImpl.f90 b/src/PatchFactoryImpl.f90 index c25293d3..342c6ac1 100644 --- a/src/PatchFactoryImpl.f90 +++ b/src/PatchFactoryImpl.f90 @@ -17,6 +17,7 @@ subroutine connectPatch(this, patchTarget, patchType, createNew) use BlockInterfacePatch_mod, only : t_BlockInterfacePatch use SolenoidalExcitationPatch_mod, only : t_SolenoidalExcitationPatch use KolmogorovForcingPatch_mod, only : t_KolmogorovForcingPatch + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch implicit none @@ -76,6 +77,9 @@ subroutine connectPatch(this, patchTarget, patchType, createNew) case ('KOLMOGOROV_FORCING') allocate(t_KolmogorovForcingPatch :: this%patch) + + case ('IMMERSED_BOUNDARY') + allocate(t_ImmersedBoundaryPatch :: this%patch) case default this%patchType = "" From 15d7f4e0852827e1913a13e01557cfebca601267 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 11:20:48 -0600 Subject: [PATCH 07/13] Grid: gridSpacing used for immersed boundary. --- include/Grid.f90 | 3 ++- src/GridImpl.f90 | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/Grid.f90 b/include/Grid.f90 index 9a3ec83e..a7b1c009 100644 --- a/include/Grid.f90 +++ b/include/Grid.f90 @@ -35,7 +35,8 @@ module Grid_mod integer, dimension(:), allocatable :: iblank SCALAR_TYPE, dimension(:,:), allocatable :: coordinates, jacobian, metrics, norm, & - controlMollifier, targetMollifier, arcLengths + controlMollifier, targetMollifier, arcLengths, gridSpacing + SCALAR_TYPE :: minGridSpacing #ifdef SCALAR_TYPE_IS_binary128_IEEE754 real(SCALAR_KIND), allocatable :: mpiReduceBuffer(:) #endif diff --git a/src/GridImpl.f90 b/src/GridImpl.f90 index de8b97fc..3f66805a 100644 --- a/src/GridImpl.f90 +++ b/src/GridImpl.f90 @@ -41,6 +41,7 @@ subroutine allocateData(this, simulationFlags) allocate(this%coordinates(this%nGridPoints, this%nDimensions)) allocate(this%jacobian(this%nGridPoints, 1)) allocate(this%metrics(this%nGridPoints, this%nDimensions ** 2)) + allocate(this%gridSpacing(this%nGridPoints, this%nDimensions)) allocate(this%norm(this%nGridPoints, 1)) this%norm = 1.0_wp @@ -351,6 +352,7 @@ subroutine cleanupGrid(this) SAFE_DEALLOCATE(this%coordinates) SAFE_DEALLOCATE(this%jacobian) SAFE_DEALLOCATE(this%metrics) + SAFE_DEALLOCATE(this%gridSpacing) SAFE_DEALLOCATE(this%norm) SAFE_DEALLOCATE(this%targetMollifier) @@ -796,6 +798,7 @@ subroutine updateGrid(this, hasNegativeJacobian, errorMessage) case (1) this%jacobian(:,1) = jacobianMatrixInverse(:,1) this%metrics(:,1) = 1.0_wp + this%gridSpacing(:,1) = abs(jacobianMatrixInverse(:,1)) if (allocated(this%arcLengths)) this%arcLengths(:,1) = abs(this%metrics(:,1)) case (2) @@ -807,6 +810,8 @@ subroutine updateGrid(this, hasNegativeJacobian, errorMessage) this%metrics(:,2) = - jacobianMatrixInverse(:,3) this%metrics(:,3) = - jacobianMatrixInverse(:,2) this%metrics(:,4) = jacobianMatrixInverse(:,1) + this%gridSpacing(:,1) = abs(jacobianMatrixInverse(:,1) + jacobianMatrixInverse(:,3)) + this%gridSpacing(:,2) = abs(jacobianMatrixInverse(:,2) + jacobianMatrixInverse(:,4)) if (allocated(this%arcLengths)) then this%arcLengths(:,1) = sqrt(this%metrics(:,1) ** 2 + this%metrics(:,2) ** 2) this%arcLengths(:,2) = sqrt(this%metrics(:,3) ** 2 + this%metrics(:,4) ** 2) @@ -817,6 +822,8 @@ subroutine updateGrid(this, hasNegativeJacobian, errorMessage) this%metrics(:,2) = 0.0_wp this%metrics(:,3) = 0.0_wp this%metrics(:,4) = jacobianMatrixInverse(:,1) + this%gridSpacing(:,1) = abs(jacobianMatrixInverse(:,1)) + this%gridSpacing(:,2) = abs(jacobianMatrixInverse(:,4)) if (allocated(this%arcLengths)) then this%arcLengths(:,1) = abs(this%metrics(:,1)) this%arcLengths(:,2) = abs(this%metrics(:,4)) @@ -836,13 +843,22 @@ subroutine updateGrid(this, hasNegativeJacobian, errorMessage) jacobianMatrixInverse(:,7) * & (jacobianMatrixInverse(:,2) * jacobianMatrixInverse(:,6) - & jacobianMatrixInverse(:,5) * jacobianMatrixInverse(:,3)) + this%gridSpacing(:,1) = abs(jacobianMatrixInverse(:,1) + jacobianMatrixInverse(:,4) + & + jacobianMatrixInverse(:,7)) + this%gridSpacing(:,2) = abs(jacobianMatrixInverse(:,2) + jacobianMatrixInverse(:,5) + & + jacobianMatrixInverse(:,8)) + this%gridSpacing(:,3) = abs(jacobianMatrixInverse(:,3) + jacobianMatrixInverse(:,6) + & + jacobianMatrixInverse(:,9)) else this%jacobian(:,1) = jacobianMatrixInverse(:,1) * & jacobianMatrixInverse(:,5) * jacobianMatrixInverse(:,9) + this%gridSpacing(:,1) = abs(jacobianMatrixInverse(:,1)) + this%gridSpacing(:,2) = abs(jacobianMatrixInverse(:,5)) + this%gridSpacing(:,3) = abs(jacobianMatrixInverse(:,9)) end if if (any(this%periodicityType == PLANE)) then - + !TODO: gridSpacing is not determined for periodic domain. if (this%isCurvilinear) then this%metrics(:,1) = jacobianMatrixInverse(:,5) * jacobianMatrixInverse(:,9) - & jacobianMatrixInverse(:,8) * jacobianMatrixInverse(:,6) From 82b5f29fc676e21e62aa3a6b3191853711f33e16 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 11:23:58 -0600 Subject: [PATCH 08/13] ImmersedBoundary: routines for temporally changing wall. --- include/State.f90 | 23 ++++++ src/ImmersedBoundaryImpl.f90 | 149 +++++++++++++++++++++++++++-------- src/SolverImpl.f90 | 40 +++++++++- src/StateImpl.f90 | 4 + 4 files changed, 182 insertions(+), 34 deletions(-) diff --git a/include/State.f90 b/include/State.f90 index 89abe28a..be766936 100644 --- a/include/State.f90 +++ b/include/State.f90 @@ -64,6 +64,8 @@ end function getNumberOfScalars ! Variables for immersed boundary method. real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal!, indicatorFunction, & !primitiveGridNorm, levelsetCurvature + real(SCALAR_KIND), dimension(:), allocatable :: wallShape, objectSpeed + real(SCALAR_KIND) :: levelsetLoc, levelsetWidth, levelsetAmp, levelsetPeriod real(SCALAR_KIND), dimension(:,:), allocatable :: ibmDissipation, nDotGradRho, uDotGradRho SCALAR_TYPE, dimension(:,:), pointer :: dummyFunction => null() @@ -80,6 +82,8 @@ end function getNumberOfScalars procedure, pass :: computeTimeStepSize => computeStateTimeStepSize procedure, pass :: addSources procedure, pass :: updateIBMVariables + procedure, pass :: setupLevelset + procedure, pass :: updateLevelset end type t_State @@ -271,4 +275,23 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) end subroutine updateIBMVariables end interface + interface + subroutine setupLevelset(this, grid) + use Grid_mod, only : t_Grid + import :: t_State + class(t_State) :: this + class(t_Grid), intent(in) :: grid + end subroutine setupLevelset + end interface + + interface + subroutine updateLevelset(this, mode, grid) + use Grid_mod, only : t_Grid + import :: t_State + class(t_State) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grid + end subroutine updateLevelset + end interface + end module State_mod diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index 27ee205b..181c83dc 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -80,10 +80,11 @@ subroutine setupImmersedBoundaryPatch(this, index, comm, patchDescriptor, this%dti = 1.0_wp / solverOptions%timeStepSize ! Set the diffusion amount based on the stability limit - call getRequiredOption("immersed_boundary/dissipation_amount", this%dissipationAmount, this%comm) - ! dissipationAmount = 0.05_WP * minGridSpacing**2 * dti / real(nDimensions, WP) + this%dissipationAmount = getOption("immersed_boundary/dissipation_amount", 0.05_wp) + ! this%dissipationAmount = this%dissipationAmount * grid%minGridSpacing * this%dti / real(grid%nDimensions, wp) + ! this%dissipationAmount = this%dissipationAmount * grid%minGridSpacing**2 * this%dti / real(grid%nDimensions, wp) - this%ibmEpsilon = getOption("immersed_boundary/regularization_parameter", 0.0_wp) + this%ibmEpsilon = getOption("immersed_boundary/regularization_parameter", 1.0_wp) ! Import specific heat ratio this%ratioOfSpecificHeats = solverOptions%ratioOfSpecificHeats @@ -178,7 +179,8 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions integer :: nUnknowns, nDimensions integer :: i, j, k, n, gridIndex, patchIndex real(wp) :: localDensity, localVelocity(grid%nDimensions), localVelocitySquared, & - localnDotGradRho, localuDotGradRho, localIbmDissipation(size(state%conservedVariables, 2)) + localnDotGradRho, localuDotGradRho, localIbmDissipation(size(state%conservedVariables, 2)), & + localLevelsetNormal(grid%nDimensions) real(wp) :: objectVelocity(grid%nDimensions), source_(size(state%conservedVariables, 2)), velocityPenalty(grid%nDimensions) real(wp) :: buf, weight @@ -191,8 +193,6 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions nUnknowns = size(state%conservedVariables, 2) nDimensions = grid%nDimensions - ! Collect IBM variables. - !TODO: collect object velocity. objectVelocity = 0.0_wp ! Update the source terms and IBM forcing @@ -213,7 +213,11 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions localnDotGradRho = state%nDotGradRho(gridIndex, 1) localuDotGradRho = state%uDotGradRho(gridIndex, 1) localIbmDissipation = state%ibmDissipation(gridIndex, :) - ! ! Get velocity of associated object + localLevelsetNormal = state%levelsetNormal(gridIndex, :) + + ! Get velocity of associated object + !TODO: include tangential component of the object velocity. + objectVelocity = state%objectSpeed(gridIndex) * localLevelsetNormal ! if (ibm_move) then ! n = objectIndex(i) ! objectVelocity = object(n)%velocity(1:nDimensions) @@ -249,8 +253,7 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions localDensity * (this%ibmTemperature - state%temperature(gridIndex,1)) / this%ratioOfSpecificHeats * this%dti ! Add the IBM contribution - buf = 0.0_wp - ! buf = ibmEpsilon * sqrt(sum((levelsetNormal(i,:) * gridSpacing(i, :))**2)) + buf = this%ibmEpsilon * sqrt(sum((localLevelsetNormal * grid%gridSpacing(gridIndex, :))**2)) weight = 1.0_wp - regularizeHeaviside(state%levelset(gridIndex, 1), buf) if (state%levelset(gridIndex, 1) .le. 0.0_wp) then state%rightHandSide(gridIndex,:) = source_ * weight @@ -292,10 +295,10 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) integer :: i, j, n, nUnknowns - real(wp) :: buf + real(wp) :: buf, timeDerivativeFactor, objectVelocity(grid%nDimensions) real(wp), dimension(:, :), allocatable :: densityGradient, dissipationTerm - real(wp), dimension(:), allocatable :: objectVelocity call startTiming("updateIBMVariables") @@ -310,17 +313,23 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) allocate(densityGradient(grid%nGridPoints, grid%nDimensions)) allocate(dissipationTerm(grid%nGridPoints, nUnknowns)) - allocate(objectVelocity(grid%nDimensions)) - !TODO: compute levelset. - this%levelset(:, 1) = grid%coordinates(:, 2) - 0.0_wp + ! compute levelset. + call this%updateLevelset(mode, grid) + timeDerivativeFactor = 2.0_wp * pi / this%levelsetPeriod * cos(2.0_wp * pi * this%time / this%levelsetPeriod) ! compute levelset normal. call grid%computeGradient(this%levelset(:, 1), this%levelsetNormal) do i = 1, grid%nGridPoints - ! Make the levelset normal a unit norm + ! levelset normal magnitude buf = sqrt(sum(this%levelsetNormal(i,:) ** 2)) + + !TODO: include tangential component of the object velocity. + ! d/dt levelset = - wallShape * d/dt timeFactor + this%objectSpeed(i) = timeDerivativeFactor * this%wallShape(i) / buf + + ! Make the levelset normal a unit norm if (buf .gt. 0.0_wp) this%levelsetNormal(i,:) = this%levelsetNormal(i,:) / buf ! ! Compute indicator function @@ -334,35 +343,111 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) ! gridNorm(i, 1) = primitiveGridNorm(i, 1) * indicatorFunction(i, 1) end do - !TODO: object velocity. - objectVelocity = 0.0_wp - this%nDotGradRho = 0.0_wp this%uDotGradRho = 0.0_wp this%ibmDissipation = 0.0_wp call grid%computeGradient(this%conservedVariables(:,1), densityGradient) - do n = 1, grid%nDimensions - this%nDotGradRho(:, 1) = this%nDotGradRho(:, 1) + this%levelsetNormal(:, n) * densityGradient(:, n) - this%uDotGradRho(:, 1) = this%uDotGradRho(:, 1) + objectVelocity(n) * densityGradient(:, n) + do i = 1, grid%nGridPoints + objectVelocity = this%objectSpeed(i) * this%levelsetNormal(i, :) + + this%nDotGradRho(i, 1) = this%nDotGradRho(i, 1) + sum(this%levelsetNormal(i, :) * densityGradient(i, :)) + this%uDotGradRho(i, 1) = this%uDotGradRho(i, 1) + sum(objectVelocity * densityGradient(i, :)) + end do + + do n = 1, grid%nDimensions ! Dissipation term. - dissipationTerm = 0.0_wp - ! dissipationTerm = this%conservedVariables - ! call grid%dissipation(n)%apply(dissipationTerm, grid%localSize) - ! if (.not. simulationFlags%compositeDissipation) then - ! do j = 1, nUnknowns - ! dissipationTerm(:,j) = - grid%arcLengths(:,n) * dissipationTerm(:,j) - ! end do - ! call grid%dissipationTranspose(n)%apply(dissipationTerm, grid%localSize) - ! call grid%firstDerivative(n)%applyNormInverse(dissipationTerm, grid%localSize) - ! end if + dissipationTerm = this%conservedVariables + call grid%dissipation(n)%apply(dissipationTerm, grid%localSize) + if (.not. simulationFlags%compositeDissipation) then + do j = 1, nUnknowns + dissipationTerm(:,j) = grid%arcLengths(:,n) * dissipationTerm(:,j) + end do + call grid%dissipationTranspose(n)%apply(dissipationTerm, grid%localSize) + call grid%firstDerivative(n)%applyNormInverse(dissipationTerm, grid%localSize) + end if this%ibmDissipation = this%ibmDissipation + dissipationTerm end do SAFE_DEALLOCATE(densityGradient) SAFE_DEALLOCATE(dissipationTerm) - SAFE_DEALLOCATE(objectVelocity) call endTiming("updateIBMVariables") end subroutine updateIBMVariables + +subroutine setupLevelset(this, grid) + + ! <<< Derived types >>> + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + ! <<< Internal modules >>> + use InputHelper, only : getRequiredOption + + implicit none + + ! <<< Arguments >>> + class(t_State) :: this + class(t_Grid) :: grid + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) + integer :: i, n + + call getRequiredOption("immersed_boundary/location", this%levelsetLoc, grid%comm) + call getRequiredOption("immersed_boundary/width", this%levelsetWidth, grid%comm) + call getRequiredOption("immersed_boundary/amplitude", this%levelsetAmp, grid%comm) + call getRequiredOption("immersed_boundary/period", this%levelsetPeriod, grid%comm) + + this%wallShape = 0.0_wp + do i = 1, grid%nGridPoints + if ((grid%coordinates(i, 1) < (this%levelsetLoc - 0.5_wp * this%levelsetWidth)) .or. & + (grid%coordinates(i, 1) > (this%levelsetLoc + 0.5_wp * this%levelsetWidth))) cycle + this%wallShape(i) = 0.5_wp + 0.5_wp * cos(2.0_wp * pi * (grid%coordinates(i, 1) - this%levelsetLoc) / this%levelsetWidth) + end do + + this%wallShape = this%wallShape * this%levelsetAmp + +end subroutine setupLevelset + +subroutine updateLevelset(this, mode, grid) + + ! <<< Derived types >>> + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + ! <<< Enumerations >>> + use Region_enum, only : FORWARD + + ! <<< Internal modules >>> + use MPITimingsHelper, only : startTiming, endTiming + + implicit none + + ! <<< Arguments >>> + class(t_State) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grid + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) + real(wp) :: timeFactor + + call startTiming("updateLevelset") + + if (mode .ne. FORWARD) then + return + end if + + assert(size(this%levelset, 1) == size(this%conservedVariables, 1)) + assert(size(this%levelset, 2) == 1) + + timeFactor = sin(2.0_wp * pi * this%time / this%levelsetPeriod) + this%levelset(:, 1) = grid%coordinates(:, 2) - this%wallShape * timeFactor + + call endTiming("updateLevelset") + +end subroutine updateLevelset diff --git a/src/SolverImpl.f90 b/src/SolverImpl.f90 index adb1f025..de12c949 100644 --- a/src/SolverImpl.f90 +++ b/src/SolverImpl.f90 @@ -405,6 +405,9 @@ end module SolverImpl subroutine setupSolver(this, region, restartFilename, outputPrefix) + ! <<< External modules >>> + use MPI + ! <<< Derived types >>> use Region_mod, only : t_Region use Solver_mod, only : t_Solver @@ -421,6 +424,7 @@ subroutine setupSolver(this, region, restartFilename, outputPrefix) ! <<< Internal modules >>> use InputHelper, only : getOption, getRequiredOption + use ErrorHandler, only : gracefulExit use Patch_factory, only : computeSpongeStrengths, updatePatchFactories use InterfaceHelper, only : checkFunctionContinuityAtInterfaces, exchangeInterfaceData @@ -433,8 +437,9 @@ subroutine setupSolver(this, region, restartFilename, outputPrefix) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - character(len = STRING_LENGTH) :: filename - integer :: i, j + real(wp) :: minGridSpacing + character(len = STRING_LENGTH) :: filename, message + integer :: i, j, ierror class(t_Patch), pointer :: patch => null() class(t_Controller), pointer :: controller => null() class(t_Functional), pointer :: functional => null() @@ -576,6 +581,37 @@ subroutine setupSolver(this, region, restartFilename, outputPrefix) end if + if (region%simulationFlags%enableIBM) then + if (.not. region%simulationFlags%dissipationOn) then + write(message, '(A)') "Immersed boundary requires artificial dissipation!" + call gracefulExit(region%comm, message) + end if + + do i = 1, size(region%states) + call region%states(i)%setupLevelset(region%grids(i)) + end do + + ! Determine minimum grid spacing (avoid holes) + do i = 1, size(region%grids) + minGridSpacing = huge(1.0_wp) + do j = 1, region%grids(i)%nGridPoints + minGridSpacing = min(minGridSpacing, & + minval(region%grids(i)%gridSpacing(j,1:region%grids(i)%nDimensions))) + end do + call MPI_Allreduce(MPI_IN_PLACE, minGridSpacing, 1, REAL_TYPE_MPI, & + MPI_MIN, region%grids(i)%comm, ierror) + end do + + if (region%commGridMasters /= MPI_COMM_NULL) & + call MPI_Allreduce(MPI_IN_PLACE, minGridSpacing, 1, REAL_TYPE_MPI, & + MPI_MIN, region%commGridMasters, ierror) + + do i = 1, size(region%grids) + call MPI_Bcast(minGridSpacing, 1, REAL_TYPE_MPI, 0, region%grids(i)%comm, ierror) + region%grids(i)%minGridSpacing = minGridSpacing + end do + end if + end subroutine setupSolver subroutine cleanupSolver(this) diff --git a/src/StateImpl.f90 b/src/StateImpl.f90 index 4c683bde..a0e0e7ac 100644 --- a/src/StateImpl.f90 +++ b/src/StateImpl.f90 @@ -63,6 +63,8 @@ subroutine allocateData(this, simulationFlags, solverOptions, nGridPoints, nDime allocate(this%ibmDissipation(nGridPoints, solverOptions%nUnknowns)) allocate(this%nDotGradRho(nGridPoints, 1)) allocate(this%uDotGradRho(nGridPoints, 1)) + allocate(this%wallShape(nGridPoints)) + allocate(this%objectSpeed(nGridPoints)) end if end subroutine allocateData @@ -188,6 +190,8 @@ subroutine cleanupState(this) SAFE_DEALLOCATE(this%ibmDissipation) SAFE_DEALLOCATE(this%nDotGradRho) SAFE_DEALLOCATE(this%uDotGradRho) + SAFE_DEALLOCATE(this%wallShape) + SAFE_DEALLOCATE(this%objectSpeed) this%adjointForcingFactor = 1.0_wp From 0b596005cbb30826f4fd781d6e95813731f8e2dd Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 11:24:39 -0600 Subject: [PATCH 09/13] utils/rhs: generate functions for immersed boundary. --- utils/rhs.f90 | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/utils/rhs.f90 b/utils/rhs.f90 index fdc4e766..78430f5e 100644 --- a/utils/rhs.f90 +++ b/utils/rhs.f90 @@ -8,6 +8,7 @@ program rhs use State_enum, only : QOI_FORWARD_STATE use Region_mod, only : t_Region + use Solver_mod, only : t_Solver use InputHelper, only : parseInputFile, getOption, getRequiredOption use ErrorHandler, only : writeAndFlush, gracefulExit @@ -22,6 +23,7 @@ program rhs character(len = STRING_LENGTH) :: filename, outputPrefix logical :: success type(t_Region) :: region + type(t_Solver) :: solver integer, allocatable :: globalGridSizes(:,:) interface @@ -71,30 +73,8 @@ end subroutine saveRhs ! Write out some useful information. call region%reportGridDiagnostics() - ! Setup boundary conditions. - call getRequiredOption("boundary_condition_file", filename) - call region%setupBoundaryConditions(filename) - - ! Compute damping strength on sponge patches. - do i = 1, size(region%grids) - call computeSpongeStrengths(region%patchFactories, region%grids(i)) - end do - - ! Check continuity at block interfaces. - if (getOption("check_interface_continuity", .false.)) & - call checkFunctionContinuityAtInterfaces(region, epsilon(0.0_wp)) - - ! Update patches. - do i = 1, size(region%grids) - call updatePatchFactories(region%patchFactories, region%simulationFlags, & - region%solverOptions, region%grids(i), region%states(i)) - end do - - ! Compute normalized metrics, norm matrix and Jacobian. - do i = 1, size(region%grids) - call region%grids(i)%update() - end do - call MPI_Barrier(MPI_COMM_WORLD, ierror) + ! Initialize the solver. + call solver%setup(region, outputPrefix = outputPrefix) if (command_argument_count() >= 1) then !... only one solution file to process. @@ -232,4 +212,23 @@ subroutine saveRhs(region, filename) end do end if + if (getOption("enable_immersed_boundary", .false.)) then + ! resize the data buffer. + do i = 1, size(data_) + deallocate(data_(i)%buffer) + allocate(data_(i)%buffer(region%grids(i)%nGridPoints, region%grids(i)%nDimensions + 3)) + end do + + do j = 1, size(region%states) + data_(j)%buffer(:, 1) = region%states(j)%levelset(:, 1) + data_(j)%buffer(:, 2) = region%states(j)%objectSpeed + data_(j)%buffer(:, 3) = region%states(j)%wallShape + data_(j)%buffer(:, 4:region%grids(j)%nDimensions + 3) = region%states(j)%levelsetNormal + region%states(j)%dummyFunction => data_(j)%buffer + end do + + write(patchFile, '(A)') trim(filename) // ".levelset.f" + call region%saveData(QOI_DUMMY_FUNCTION, patchFile) + end if + end subroutine saveRhs From 25278280af772d8500f7119643421a30e6ccdc97 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 11:26:35 -0600 Subject: [PATCH 10/13] DeformingWall2D: laminar boundary layer with a sinusoidally oscillating wall. --- examples/DeformingWall2D/bc.dat | 6 +++--- examples/DeformingWall2D/magudi.inp | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/DeformingWall2D/bc.dat b/examples/DeformingWall2D/bc.dat index 56d79938..d49d9bfe 100644 --- a/examples/DeformingWall2D/bc.dat +++ b/examples/DeformingWall2D/bc.dat @@ -4,7 +4,7 @@ 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 -12 -1 1 -1 -# sponge.W SPONGE 1 1 1 25 1 -1 1 -1 -# sponge.E SPONGE 1 -1 1 -25 1 -1 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 diff --git a/examples/DeformingWall2D/magudi.inp b/examples/DeformingWall2D/magudi.inp index 90bfbdef..bf1abc39 100644 --- a/examples/DeformingWall2D/magudi.inp +++ b/examples/DeformingWall2D/magudi.inp @@ -47,10 +47,13 @@ report_interval = 10 save_interval = 200 # Artificial dissipation -add_dissipation = false -dissipation_amount = 0.0002 +add_dissipation = true +dissipation_amount = 1e-3 composite_dissipation = false +# Sponge options +defaults/sponge_amount = 0.2 + # Solution limits enable_solution_limits = true minimum_density = 0.1 @@ -68,14 +71,15 @@ maximum_temperature = 4. #patches/flatPlate.N/viscous_penalty_amount1 = 2. #patches/flatPlate.S/viscous_penalty_amount1 = 2. -# Body force parameters -enable_body_force = false -body_force/initial_momentum = 0.00194363459 - # Immersed boundary parameters enable_immersed_boundary = true -immersed_boundary/dissipation_amount = 0.0 -immersed_boundary/regularization_parameter = 0.0 +immersed_boundary/dissipation_amount = 1e-3 +immersed_boundary/regularization_parameter = 3.0 +immersed_boundary/period = 48.0 +immersed_boundary/location = 10.0 +immersed_boundary/width = 20.0 +immersed_boundary/amplitude = 1.0 + # utils/rhs rhs/save_patch_rhs = true From ee7bcdc02d68e04d5436e5e87f4acf5417633409 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 13:10:18 -0600 Subject: [PATCH 11/13] LevelsetFactory: abstract interface for various levelsets. --- CMakeLists.txt | 3 + include/ImmersedBoundaryPatch.f90 | 8 -- include/LevelsetFactory.f90 | 64 ++++++++++++++ include/Region.f90 | 16 ++++ include/SinusoidalWallLevelset.f90 | 73 ++++++++++++++++ include/State.f90 | 23 +---- src/ImmersedBoundaryImpl.f90 | 112 ++---------------------- src/RegionImpl.f90 | 40 +++++++++ src/SinusoidalWallLevelsetImpl.f90 | 133 +++++++++++++++++++++++++++++ src/SolverImpl.f90 | 6 +- src/StateImpl.f90 | 6 +- utils/rhs.f90 | 7 +- 12 files changed, 344 insertions(+), 147 deletions(-) create mode 100644 include/LevelsetFactory.f90 create mode 100644 include/SinusoidalWallLevelset.f90 create mode 100644 src/SinusoidalWallLevelsetImpl.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index d58ba959..37b29068 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -213,6 +214,8 @@ set(magudiObj_SOURCES ${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 diff --git a/include/ImmersedBoundaryPatch.f90 b/include/ImmersedBoundaryPatch.f90 index 9cfa3153..38cd0c31 100644 --- a/include/ImmersedBoundaryPatch.f90 +++ b/include/ImmersedBoundaryPatch.f90 @@ -16,7 +16,6 @@ module ImmersedBoundaryPatch_mod procedure, pass :: cleanup => cleanupImmersedBoundaryPatch procedure, pass :: verifyUsage => verifyImmersedBoundaryPatchUsage procedure, pass :: updateRhs => addImmersedBoundaryPenalty - procedure, pass :: updateLevelset => addImmersedBoundaryLevelset end type t_ImmersedBoundaryPatch interface @@ -77,11 +76,4 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions end subroutine addImmersedBoundaryPenalty end interface - interface - subroutine addImmersedBoundaryLevelset(this) - import :: t_ImmersedBoundaryPatch - class(t_ImmersedBoundaryPatch) :: this - end subroutine addImmersedBoundaryLevelset - end interface - end module ImmersedBoundaryPatch_mod diff --git a/include/LevelsetFactory.f90 b/include/LevelsetFactory.f90 new file mode 100644 index 00000000..4365f79c --- /dev/null +++ b/include/LevelsetFactory.f90 @@ -0,0 +1,64 @@ +#include "config.h" + +module LevelsetFactory_mod + + implicit none + + type, abstract, public :: t_LevelsetFactory + + contains + + procedure(setup), pass, deferred :: setup + procedure(cleanup), pass, deferred :: cleanup + procedure(updateLevelset), pass, deferred :: updateLevelset + + end type t_LevelsetFactory + + abstract interface + + subroutine setup(this, grids, states) + + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + import :: t_LevelsetFactory + + class(t_LevelsetFactory) :: this + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + end subroutine setup + + end interface + + abstract interface + + subroutine cleanup(this) + + import :: t_LevelsetFactory + + class(t_LevelsetFactory) :: this + + end subroutine cleanup + + end interface + + abstract interface + + subroutine updateLevelset(this, mode, grids, states) + + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + import :: t_LevelsetFactory + + class(t_LevelsetFactory) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + end subroutine updateLevelset + + end interface + +end module LevelsetFactory_mod diff --git a/include/Region.f90 b/include/Region.f90 index 0093dfc2..7010b3cb 100644 --- a/include/Region.f90 +++ b/include/Region.f90 @@ -22,6 +22,7 @@ module Region_mod use SolverOptions_mod, only : t_SolverOptions use PatchDescriptor_mod, only : t_PatchDescriptor use SimulationFlags_mod, only : t_SimulationFlags + use LevelsetFactory_mod, only : t_LevelsetFactory implicit none @@ -33,6 +34,7 @@ module Region_mod type(t_SolverOptions) :: solverOptions type(t_SimulationFlags) :: simulationFlags type(t_PatchDescriptor), allocatable :: patchData(:) + class(t_LevelsetFactory), pointer :: levelsetFactory => null() integer :: comm = MPI_COMM_NULL, commGridMasters = MPI_COMM_NULL, timestep = 0 integer, allocatable :: globalGridSizes(:,:), processDistributions(:,:), & gridCommunicators(:), patchCommunicators(:), patchInterfaces(:), & @@ -40,6 +42,7 @@ module Region_mod logical :: outputOn = .true. SCALAR_TYPE :: initialXmomentum, oneOverVolume, momentumLossPerVolume, & adjointMomentumLossPerVolume + character(len=STRING_LENGTH) :: levelsetType contains @@ -55,6 +58,7 @@ module Region_mod procedure, pass :: saveSpongeStrength procedure, pass :: resetProbes procedure, pass :: saveProbeData + procedure, pass :: connectLevelsetFactory end type t_Region @@ -227,4 +231,16 @@ end subroutine saveProbeData end interface + interface + + subroutine connectLevelsetFactory(this) + + import :: t_Region + + class(t_Region) :: this + + end subroutine connectLevelsetFactory + + end interface + end module Region_mod diff --git a/include/SinusoidalWallLevelset.f90 b/include/SinusoidalWallLevelset.f90 new file mode 100644 index 00000000..9002810b --- /dev/null +++ b/include/SinusoidalWallLevelset.f90 @@ -0,0 +1,73 @@ +#include "config.h" + +module SinusoidalWallLevelset_mod + + use LevelsetFactory_mod, only : t_LevelsetFactory + + implicit none + + type, private :: t_SWInternal + SCALAR_TYPE, allocatable :: buffer(:) + end type t_SWInternal + + type, extends(t_LevelsetFactory), public :: t_SinusoidalWallLevelset + + type(t_SWInternal), dimension(:), allocatable :: wallShapes + real(SCALAR_KIND) :: levelsetLoc, levelsetWidth, levelsetAmp, levelsetPeriod + + contains + + procedure, pass :: setup => setupSinusoidalWallLevelset + procedure, pass :: cleanup => cleanupSinusoidalWallLevelset + procedure, pass :: updateLevelset => updateSinusoidalWallLevelset + + end type t_SinusoidalWallLevelset + + interface + + subroutine setupSinusoidalWallLevelset(this, grids, states) + + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + import :: t_SinusoidalWallLevelset + + class(t_SinusoidalWallLevelset) :: this + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + end subroutine setupSinusoidalWallLevelset + + end interface + + interface + + subroutine cleanupSinusoidalWallLevelset(this) + + import :: t_SinusoidalWallLevelset + + class(t_SinusoidalWallLevelset) :: this + + end subroutine cleanupSinusoidalWallLevelset + + end interface + + interface + + subroutine updateSinusoidalWallLevelset(this, mode, grids, states) + + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + import :: t_SinusoidalWallLevelset + + class(t_SinusoidalWallLevelset) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + end subroutine updateSinusoidalWallLevelset + + end interface + +end module SinusoidalWallLevelset_mod diff --git a/include/State.f90 b/include/State.f90 index be766936..db0873e5 100644 --- a/include/State.f90 +++ b/include/State.f90 @@ -64,7 +64,7 @@ end function getNumberOfScalars ! Variables for immersed boundary method. real(SCALAR_KIND), dimension(:,:), allocatable :: levelset, levelsetNormal!, indicatorFunction, & !primitiveGridNorm, levelsetCurvature - real(SCALAR_KIND), dimension(:), allocatable :: wallShape, objectSpeed + real(SCALAR_KIND), dimension(:,:), allocatable :: objectVelocity real(SCALAR_KIND) :: levelsetLoc, levelsetWidth, levelsetAmp, levelsetPeriod real(SCALAR_KIND), dimension(:,:), allocatable :: ibmDissipation, nDotGradRho, uDotGradRho @@ -82,8 +82,6 @@ end function getNumberOfScalars procedure, pass :: computeTimeStepSize => computeStateTimeStepSize procedure, pass :: addSources procedure, pass :: updateIBMVariables - procedure, pass :: setupLevelset - procedure, pass :: updateLevelset end type t_State @@ -275,23 +273,4 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) end subroutine updateIBMVariables end interface - interface - subroutine setupLevelset(this, grid) - use Grid_mod, only : t_Grid - import :: t_State - class(t_State) :: this - class(t_Grid), intent(in) :: grid - end subroutine setupLevelset - end interface - - interface - subroutine updateLevelset(this, mode, grid) - use Grid_mod, only : t_Grid - import :: t_State - class(t_State) :: this - integer, intent(in) :: mode - class(t_Grid), intent(in) :: grid - end subroutine updateLevelset - end interface - end module State_mod diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index 181c83dc..dd15d4af 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -216,8 +216,7 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions localLevelsetNormal = state%levelsetNormal(gridIndex, :) ! Get velocity of associated object - !TODO: include tangential component of the object velocity. - objectVelocity = state%objectSpeed(gridIndex) * localLevelsetNormal + objectVelocity = state%objectVelocity(gridIndex, :) ! if (ibm_move) then ! n = objectIndex(i) ! objectVelocity = object(n)%velocity(1:nDimensions) @@ -266,11 +265,6 @@ subroutine addImmersedBoundaryPenalty(this, mode, simulationFlags, solverOptions end do !... k = this%offset(3) + 1, this%offset(3) + this%localSize(3) end subroutine addImmersedBoundaryPenalty -subroutine addImmersedBoundaryLevelset(this) - use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch - class(t_ImmersedBoundaryPatch) :: this -end subroutine addImmersedBoundaryLevelset - ! t_State method subroutine updateIBMVariables(this, mode, grid, simulationFlags) @@ -297,7 +291,7 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) integer, parameter :: wp = SCALAR_KIND real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) integer :: i, j, n, nUnknowns - real(wp) :: buf, timeDerivativeFactor, objectVelocity(grid%nDimensions) + real(wp) :: buf real(wp), dimension(:, :), allocatable :: densityGradient, dissipationTerm call startTiming("updateIBMVariables") @@ -314,24 +308,8 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) allocate(densityGradient(grid%nGridPoints, grid%nDimensions)) allocate(dissipationTerm(grid%nGridPoints, nUnknowns)) - ! compute levelset. - call this%updateLevelset(mode, grid) - timeDerivativeFactor = 2.0_wp * pi / this%levelsetPeriod * cos(2.0_wp * pi * this%time / this%levelsetPeriod) - - ! compute levelset normal. - call grid%computeGradient(this%levelset(:, 1), this%levelsetNormal) - - do i = 1, grid%nGridPoints - ! levelset normal magnitude - buf = sqrt(sum(this%levelsetNormal(i,:) ** 2)) - - !TODO: include tangential component of the object velocity. - ! d/dt levelset = - wallShape * d/dt timeFactor - this%objectSpeed(i) = timeDerivativeFactor * this%wallShape(i) / buf - - ! Make the levelset normal a unit norm - if (buf .gt. 0.0_wp) this%levelsetNormal(i,:) = this%levelsetNormal(i,:) / buf - + !NOTE: remnant from jcode. + ! do i = 1, grid%nGridPoints ! ! Compute indicator function ! if (levelset(i, 1) .le. 0.0_wp) then ! indicatorFunction(i, 1) = 0.0_wp @@ -341,7 +319,7 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) ! ! ! Update the grid norm ! gridNorm(i, 1) = primitiveGridNorm(i, 1) * indicatorFunction(i, 1) - end do + ! end do this%nDotGradRho = 0.0_wp this%uDotGradRho = 0.0_wp @@ -349,10 +327,8 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) call grid%computeGradient(this%conservedVariables(:,1), densityGradient) do i = 1, grid%nGridPoints - objectVelocity = this%objectSpeed(i) * this%levelsetNormal(i, :) - this%nDotGradRho(i, 1) = this%nDotGradRho(i, 1) + sum(this%levelsetNormal(i, :) * densityGradient(i, :)) - this%uDotGradRho(i, 1) = this%uDotGradRho(i, 1) + sum(objectVelocity * densityGradient(i, :)) + this%uDotGradRho(i, 1) = this%uDotGradRho(i, 1) + sum(this%objectVelocity(i, :) * densityGradient(i, :)) end do do n = 1, grid%nDimensions @@ -375,79 +351,3 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) call endTiming("updateIBMVariables") end subroutine updateIBMVariables - -subroutine setupLevelset(this, grid) - - ! <<< Derived types >>> - use Grid_mod, only : t_Grid - use State_mod, only : t_State - - ! <<< Internal modules >>> - use InputHelper, only : getRequiredOption - - implicit none - - ! <<< Arguments >>> - class(t_State) :: this - class(t_Grid) :: grid - - ! <<< Local variables >>> - integer, parameter :: wp = SCALAR_KIND - real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) - integer :: i, n - - call getRequiredOption("immersed_boundary/location", this%levelsetLoc, grid%comm) - call getRequiredOption("immersed_boundary/width", this%levelsetWidth, grid%comm) - call getRequiredOption("immersed_boundary/amplitude", this%levelsetAmp, grid%comm) - call getRequiredOption("immersed_boundary/period", this%levelsetPeriod, grid%comm) - - this%wallShape = 0.0_wp - do i = 1, grid%nGridPoints - if ((grid%coordinates(i, 1) < (this%levelsetLoc - 0.5_wp * this%levelsetWidth)) .or. & - (grid%coordinates(i, 1) > (this%levelsetLoc + 0.5_wp * this%levelsetWidth))) cycle - this%wallShape(i) = 0.5_wp + 0.5_wp * cos(2.0_wp * pi * (grid%coordinates(i, 1) - this%levelsetLoc) / this%levelsetWidth) - end do - - this%wallShape = this%wallShape * this%levelsetAmp - -end subroutine setupLevelset - -subroutine updateLevelset(this, mode, grid) - - ! <<< Derived types >>> - use Grid_mod, only : t_Grid - use State_mod, only : t_State - - ! <<< Enumerations >>> - use Region_enum, only : FORWARD - - ! <<< Internal modules >>> - use MPITimingsHelper, only : startTiming, endTiming - - implicit none - - ! <<< Arguments >>> - class(t_State) :: this - integer, intent(in) :: mode - class(t_Grid), intent(in) :: grid - - ! <<< Local variables >>> - integer, parameter :: wp = SCALAR_KIND - real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) - real(wp) :: timeFactor - - call startTiming("updateLevelset") - - if (mode .ne. FORWARD) then - return - end if - - assert(size(this%levelset, 1) == size(this%conservedVariables, 1)) - assert(size(this%levelset, 2) == 1) - - timeFactor = sin(2.0_wp * pi * this%time / this%levelsetPeriod) - this%levelset(:, 1) = grid%coordinates(:, 2) - this%wallShape * timeFactor - - call endTiming("updateLevelset") - -end subroutine updateLevelset diff --git a/src/RegionImpl.f90 b/src/RegionImpl.f90 index 84933e0f..2f7f322d 100644 --- a/src/RegionImpl.f90 +++ b/src/RegionImpl.f90 @@ -1148,6 +1148,11 @@ subroutine cleanupRegion(this) end if SAFE_DEALLOCATE(this%states) + if (this%simulationFlags%enableIBM) then + call this%levelsetFactory%cleanup() + nullify(this%levelsetFactory) + end if + if (allocated(this%patchFactories)) then do i = 1, size(this%patchFactories) call this%patchFactories(i)%connect(patch) @@ -1747,6 +1752,7 @@ subroutine computeRhs(this, mode, timeStep, stage) ! Update immersed boundary variables. if (this%simulationFlags%enableIBM) then + call this%levelsetFactory%updateLevelset(mode, this%grids, this%states) do i = 1, size(this%states) call this%states(i)%updateIBMVariables(mode, this%grids(i), this%simulationFlags) end do @@ -2040,3 +2046,37 @@ subroutine saveProbeData(this, mode, finish) end do end subroutine saveProbeData + +subroutine connectLevelsetFactory(this) + + ! <<< Derived types >>> + use Region_mod, only : t_Region + use LevelsetFactory_mod, only : t_LevelsetFactory + use SinusoidalWallLevelset_mod, only : t_SinusoidalWallLevelset + + ! <<< Internal modules >>> + use InputHelper, only : getRequiredOption + + implicit none + + ! <<< Arguments >>> + class(t_Region) :: this + + ! <<< Local variables >>> + character(len = STRING_LENGTH) :: levelsetType + + call getRequiredOption("immersed_boundary/levelset_type", levelsetType, this%comm) + + this%levelsetType = levelsetType + + select case (trim(levelsetType)) + + case ('sinusoidal_wall') + allocate(t_SinusoidalWallLevelset :: this%levelsetFactory) + + case default + this%levelsetType = "" + + end select + +end subroutine connectLevelsetFactory diff --git a/src/SinusoidalWallLevelsetImpl.f90 b/src/SinusoidalWallLevelsetImpl.f90 new file mode 100644 index 00000000..66d37730 --- /dev/null +++ b/src/SinusoidalWallLevelsetImpl.f90 @@ -0,0 +1,133 @@ +#include "config.h" + +subroutine setupSinusoidalWallLevelset(this, grids, states) + + ! <<< Derived types >>> + use SinusoidalWallLevelset_mod, only : t_SinusoidalWallLevelset + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + ! <<< Internal modules >>> + use InputHelper, only : getRequiredOption + + implicit none + + ! <<< Arguments >>> + class(t_SinusoidalWallLevelset) :: this + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) + integer :: i, n + + call this%cleanup() + + assert(size(states) == size(grids)) + allocate(this%wallShapes(size(grids))) + do i = 1, size(grids) + allocate(this%wallShapes(i)%buffer(grids(i)%nGridPoints)) + end do + + call getRequiredOption("immersed_boundary/location", this%levelsetLoc, grids(1)%comm) + call getRequiredOption("immersed_boundary/width", this%levelsetWidth, grids(1)%comm) + call getRequiredOption("immersed_boundary/amplitude", this%levelsetAmp, grids(1)%comm) + call getRequiredOption("immersed_boundary/period", this%levelsetPeriod, grids(1)%comm) + + do n = 1, size(grids) + this%wallShapes(n)%buffer = 0.0_wp + do i = 1, grids(n)%nGridPoints + if ((grids(n)%coordinates(i, 1) < (this%levelsetLoc - 0.5_wp * this%levelsetWidth)) .or. & + (grids(n)%coordinates(i, 1) > (this%levelsetLoc + 0.5_wp * this%levelsetWidth))) cycle + this%wallShapes(n)%buffer(i) = 0.5_wp + 0.5_wp * cos(2.0_wp * pi * (grids(n)%coordinates(i, 1) - this%levelsetLoc) / this%levelsetWidth) + end do + this%wallShapes(n)%buffer = this%wallShapes(n)%buffer * this%levelsetAmp + end do + +end subroutine setupSinusoidalWallLevelset + +subroutine cleanupSinusoidalWallLevelset(this) + + ! <<< Derived types >>> + use SinusoidalWallLevelset_mod, only : t_SinusoidalWallLevelset + + ! <<< Arguments >>> + class(t_SinusoidalWallLevelset) :: this + + ! <<< Local variables >>> + integer :: i + + if (allocated(this%wallShapes)) then + do i = 1, size(this%wallShapes) + SAFE_DEALLOCATE(this%wallShapes(i)%buffer) + end do + SAFE_DEALLOCATE(this%wallShapes) + end if + +end subroutine cleanupSinusoidalWallLevelset + +subroutine updateSinusoidalWallLevelset(this, mode, grids, states) + + ! <<< Derived types >>> + use SinusoidalWallLevelset_mod, only : t_SinusoidalWallLevelset + use Grid_mod, only : t_Grid + use State_mod, only : t_State + + ! <<< Enumerations >>> + use Region_enum, only : FORWARD + + ! <<< Internal modules >>> + use MPITimingsHelper, only : startTiming, endTiming + + implicit none + + ! <<< Arguments >>> + class(t_SinusoidalWallLevelset) :: this + integer, intent(in) :: mode + class(t_Grid), intent(in) :: grids(:) + class(t_State) :: states(:) + + ! <<< Local variables >>> + integer, parameter :: wp = SCALAR_KIND + real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) + real(wp) :: timeFactor, timeDerivativeFactor, buf, objectSpeed + integer :: i, j + + call startTiming("updateSinusoidalWallLevelset") + + if (mode .ne. FORWARD) then + return + end if + + timeFactor = sin(2.0_wp * pi * states(1)%time / this%levelsetPeriod) + timeDerivativeFactor = 2.0_wp * pi / this%levelsetPeriod * cos(2.0_wp * pi * states(1)%time / this%levelsetPeriod) + + do i = 1, size(states) + assert(size(states(i)%levelset, 1) == size(states(i)%conservedVariables, 1)) + assert(size(states(i)%levelset, 2) == 1) + assert(size(states(i)%levelset, 1) == size(this%wallShapes(i)%buffer)) + + states(i)%levelset(:, 1) = grids(i)%coordinates(:, 2) & + - this%wallShapes(i)%buffer * timeFactor + + ! compute levelset normal. + call grids(i)%computeGradient(states(i)%levelset(:, 1), states(i)%levelsetNormal) + + do j = 1, grids(i)%nGridPoints + ! levelset normal magnitude + buf = sqrt(sum(states(i)%levelsetNormal(j,:) ** 2)) + + ! d/dt levelset = - wallShape * d/dt timeFactor + objectSpeed = timeDerivativeFactor * this%wallShapes(i)%buffer(j) / buf + + ! Make the levelset normal a unit norm + if (buf .gt. 0.0_wp) states(i)%levelsetNormal(j,:) = states(i)%levelsetNormal(j,:) / buf + + states(i)%objectVelocity(j,:) = objectSpeed * states(i)%levelsetNormal(j,:) + end do + end do + + call endTiming("updateSinusoidalWallLevelset") + +end subroutine updateSinusoidalWallLevelset diff --git a/src/SolverImpl.f90 b/src/SolverImpl.f90 index de12c949..ae70cb17 100644 --- a/src/SolverImpl.f90 +++ b/src/SolverImpl.f90 @@ -587,9 +587,9 @@ subroutine setupSolver(this, region, restartFilename, outputPrefix) call gracefulExit(region%comm, message) end if - do i = 1, size(region%states) - call region%states(i)%setupLevelset(region%grids(i)) - end do + call region%connectLevelsetFactory() + + call region%levelsetFactory%setup(region%grids, region%states) ! Determine minimum grid spacing (avoid holes) do i = 1, size(region%grids) diff --git a/src/StateImpl.f90 b/src/StateImpl.f90 index a0e0e7ac..79e00ef3 100644 --- a/src/StateImpl.f90 +++ b/src/StateImpl.f90 @@ -63,8 +63,7 @@ subroutine allocateData(this, simulationFlags, solverOptions, nGridPoints, nDime allocate(this%ibmDissipation(nGridPoints, solverOptions%nUnknowns)) allocate(this%nDotGradRho(nGridPoints, 1)) allocate(this%uDotGradRho(nGridPoints, 1)) - allocate(this%wallShape(nGridPoints)) - allocate(this%objectSpeed(nGridPoints)) + allocate(this%objectVelocity(nGridPoints, nDimensions)) end if end subroutine allocateData @@ -190,8 +189,7 @@ subroutine cleanupState(this) SAFE_DEALLOCATE(this%ibmDissipation) SAFE_DEALLOCATE(this%nDotGradRho) SAFE_DEALLOCATE(this%uDotGradRho) - SAFE_DEALLOCATE(this%wallShape) - SAFE_DEALLOCATE(this%objectSpeed) + SAFE_DEALLOCATE(this%objectVelocity) this%adjointForcingFactor = 1.0_wp diff --git a/utils/rhs.f90 b/utils/rhs.f90 index 78430f5e..8b6a9506 100644 --- a/utils/rhs.f90 +++ b/utils/rhs.f90 @@ -216,14 +216,13 @@ subroutine saveRhs(region, filename) ! resize the data buffer. do i = 1, size(data_) deallocate(data_(i)%buffer) - allocate(data_(i)%buffer(region%grids(i)%nGridPoints, region%grids(i)%nDimensions + 3)) + allocate(data_(i)%buffer(region%grids(i)%nGridPoints, 1 + 2 * region%grids(i)%nDimensions)) end do do j = 1, size(region%states) data_(j)%buffer(:, 1) = region%states(j)%levelset(:, 1) - data_(j)%buffer(:, 2) = region%states(j)%objectSpeed - data_(j)%buffer(:, 3) = region%states(j)%wallShape - data_(j)%buffer(:, 4:region%grids(j)%nDimensions + 3) = region%states(j)%levelsetNormal + data_(j)%buffer(:, 2:region%grids(j)%nDimensions + 1) = region%states(j)%levelsetNormal + data_(j)%buffer(:, region%grids(j)%nDimensions + 2 : 2 * region%grids(j)%nDimensions + 1) = region%states(j)%objectVelocity region%states(j)%dummyFunction => data_(j)%buffer end do From ab7865f4745e839dc4b79987f240242caa8216d9 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 14:36:08 -0600 Subject: [PATCH 12/13] cleaned up unused variables. --- bin/Adjoint.f90 | 1 - bin/CheckGradientAccuracy.f90 | 1 - bin/Forward.f90 | 1 - bin/Linearized_Forward.f90 | 6 +- bin/control_space_norm.f90 | 10 +- bin/paste_control_forcing.f90 | 168 +++++++++--------- bin/patchup_qfile.f90 | 8 +- bin/qfile_zaxpy.f90 | 3 +- bin/slice_control_forcing.f90 | 5 +- bin/spatial_inner_product.f90 | 1 - bin/terminal_objective.f90 | 11 +- bin/zXdotY.f90 | 2 +- examples/DeformingWall2D/magudi.inp | 1 + src/AcousticNoiseImpl.f90 | 7 +- src/ActuatorPatchImpl.f90 | 2 +- src/ControlSpaceAdvancerImpl.f90 | 11 +- src/DensityGradientImpl.f90 | 10 +- src/ErrorHandlerImpl.f90 | 2 +- src/GenericActuatorImpl.f90 | 4 +- src/ImmersedBoundaryImpl.f90 | 1 - src/IsothermalWallImpl.f90 | 5 +- src/JamesonRK3IntegratorImpl.f90 | 2 - src/KolmogorovForcingPatchImpl.f90 | 3 +- src/LighthillSourceImpl.f90 | 9 +- src/LighthillTensorComponentImpl.f90 | 19 +- src/MomentumActuatorImpl.f90 | 2 +- src/SolverImpl.f90 | 20 +-- src/ThermalActuatorImpl.f90 | 12 -- test/adjoint_relation/SAT_block_interface.f90 | 14 +- test/adjoint_relation/SAT_farfield.f90 | 4 +- test/adjoint_relation/SAT_isothermal.f90 | 4 +- .../artificial_dissipation.f90 | 4 +- test/adjoint_relation/body_force.f90 | 9 +- test/adjoint_relation/control_functional.f90 | 11 +- test/adjoint_relation/full_rhs.f90 | 14 +- test/adjoint_relation/initial_condition.f90 | 11 +- test/adjoint_relation/inviscid_flux.f90 | 6 +- test/adjoint_relation/sponge.f90 | 4 +- test/adjoint_relation/time_integrator.f90 | 9 +- test/adjoint_relation/viscous_flux.f90 | 6 +- test/block_interface_sign.f90 | 20 +-- .../SAT_block_interface_linearized.f90 | 11 +- .../SAT_farfield_linearized.f90 | 4 +- .../SAT_isothermal_linearized.f90 | 4 +- .../artificial_dissipation_linearized.f90 | 3 +- .../body_force_linearized.f90 | 9 +- .../full_rhs_linearized.f90 | 14 +- .../inviscid_flux_linearized.f90 | 6 +- .../linearized_relation/sponge_linearized.f90 | 4 +- test/linearized_relation/viscous_flux_C.f90 | 5 +- .../viscous_flux_linearized.f90 | 5 +- test/stencil_coefficients.f90 | 1 - test/testZAXPY.f90 | 4 +- utils/append_gradient.f90 | 1 - utils/control_mollifier_factor.f90 | 4 +- utils/extend_control_forcing.f90 | 7 +- utils/probe_from_qfile.f90 | 5 +- utils/saveGridNorm.f90 | 7 +- utils/shear_layer.f90 | 6 +- utils/zxdoty_in_time.f90 | 6 +- 60 files changed, 219 insertions(+), 330 deletions(-) diff --git a/bin/Adjoint.f90 b/bin/Adjoint.f90 index 77a93513..4236cd0a 100644 --- a/bin/Adjoint.f90 +++ b/bin/Adjoint.f90 @@ -33,7 +33,6 @@ program adjoint type(t_Solver) :: solver ! << output variables >> - integer :: inputNumber, simulationNumber SCALAR_TYPE :: dummyValue = 0.0_wp ! Initialize MPI. diff --git a/bin/CheckGradientAccuracy.f90 b/bin/CheckGradientAccuracy.f90 index 13f06472..a743c73c 100644 --- a/bin/CheckGradientAccuracy.f90 +++ b/bin/CheckGradientAccuracy.f90 @@ -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) diff --git a/bin/Forward.f90 b/bin/Forward.f90 index 0bba5deb..36e80314 100644 --- a/bin/Forward.f90 +++ b/bin/Forward.f90 @@ -32,7 +32,6 @@ program forward type(t_Solver) :: solver ! << output variables >> - integer :: inputNumber, simulationNumber SCALAR_TYPE :: dummyValue = 0.0_wp ! Initialize MPI. diff --git a/bin/Linearized_Forward.f90 b/bin/Linearized_Forward.f90 index 23ab2433..258f0c19 100644 --- a/bin/Linearized_Forward.f90 +++ b/bin/Linearized_Forward.f90 @@ -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. diff --git a/bin/control_space_norm.f90 b/bin/control_space_norm.f90 index f50c0264..16ec1c3f 100644 --- a/bin/control_space_norm.f90 +++ b/bin/control_space_norm.f90 @@ -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) @@ -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 diff --git a/bin/paste_control_forcing.f90 b/bin/paste_control_forcing.f90 index 5ec126e6..cd6d3581 100644 --- a/bin/paste_control_forcing.f90 +++ b/bin/paste_control_forcing.f90 @@ -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) @@ -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>> + ! 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> - integer :: inputNumber, simulationNumber - SCALAR_TYPE :: A - ! Initialize MPI. call MPI_Init(ierror) call MPI_Comm_rank(MPI_COMM_WORLD, procRank, ierror) diff --git a/bin/qfile_zaxpy.f90 b/bin/qfile_zaxpy.f90 index 315ba53c..3279e416 100644 --- a/bin/qfile_zaxpy.f90 +++ b/bin/qfile_zaxpy.f90 @@ -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. @@ -35,7 +35,6 @@ program qfile_zaxpy type(t_VectorInternal), allocatable :: X(:), Y(:) ! << output variables >> - integer :: inputNumber, simulationNumber SCALAR_TYPE :: A ! Initialize MPI. diff --git a/bin/slice_control_forcing.f90 b/bin/slice_control_forcing.f90 index 3ac957db..8e8d05fb 100644 --- a/bin/slice_control_forcing.f90 +++ b/bin/slice_control_forcing.f90 @@ -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) diff --git a/bin/spatial_inner_product.f90 b/bin/spatial_inner_product.f90 index 40dd864b..25178ae6 100644 --- a/bin/spatial_inner_product.f90 +++ b/bin/spatial_inner_product.f90 @@ -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. diff --git a/bin/terminal_objective.f90 b/bin/terminal_objective.f90 index 3e49bf37..3471db08 100644 --- a/bin/terminal_objective.f90 +++ b/bin/terminal_objective.f90 @@ -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. @@ -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") diff --git a/bin/zXdotY.f90 b/bin/zXdotY.f90 index f5631d3f..5edaf4d5 100644 --- a/bin/zXdotY.f90 +++ b/bin/zXdotY.f90 @@ -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 diff --git a/examples/DeformingWall2D/magudi.inp b/examples/DeformingWall2D/magudi.inp index bf1abc39..1924fbab 100644 --- a/examples/DeformingWall2D/magudi.inp +++ b/examples/DeformingWall2D/magudi.inp @@ -73,6 +73,7 @@ maximum_temperature = 4. # Immersed boundary parameters enable_immersed_boundary = true +immersed_boundary/levelset_type = "sinusoidal_wall" immersed_boundary/dissipation_amount = 1e-3 immersed_boundary/regularization_parameter = 3.0 immersed_boundary/period = 48.0 diff --git a/src/AcousticNoiseImpl.f90 b/src/AcousticNoiseImpl.f90 index 6e9921d0..ae00e847 100644 --- a/src/AcousticNoiseImpl.f90 +++ b/src/AcousticNoiseImpl.f90 @@ -26,7 +26,7 @@ subroutine setupAcousticNoise(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, ierror - character(len = STRING_LENGTH) :: filename, outputPrefix, message + character(len = STRING_LENGTH) :: filename assert(allocated(region%states)) assert(size(region%states) > 0) @@ -147,10 +147,9 @@ function computeAcousticNoise(this, region) result(instantaneousFunctional) integer, parameter :: wp = SCALAR_KIND integer :: i, j, ierror SCALAR_TYPE, allocatable :: F(:,:) - SCALAR_TYPE :: ideal_mean_pressure !SeungWhan: constant mean pressure + ! SCALAR_TYPE :: ideal_mean_pressure !SeungWhan: constant mean pressure ! <<< SeungWhan: message, timeRampFactor >> - character(len=STRING_LENGTH) :: message real(wp) :: timeRampFactor assert(allocated(region%grids)) @@ -231,7 +230,7 @@ subroutine computeAcousticNoiseAdjointForcing(this, simulationFlags, solverOptio integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, nDimensions, gridIndex, patchIndex SCALAR_TYPE, allocatable :: meanPressure(:) - SCALAR_TYPE :: F, ideal_mean_pressure !SeungWhan: constant mean pressure + SCALAR_TYPE :: F!, ideal_mean_pressure !SeungWhan: constant mean pressure ! <<< SeungWhan: message, timeRampFactor >> real(wp) :: timeRampFactor diff --git a/src/ActuatorPatchImpl.f90 b/src/ActuatorPatchImpl.f90 index 1f652e08..165ad4a9 100644 --- a/src/ActuatorPatchImpl.f90 +++ b/src/ActuatorPatchImpl.f90 @@ -30,7 +30,7 @@ subroutine setupActuatorPatch(this, index, comm, patchDescriptor, ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - character(len = STRING_LENGTH) :: outputPrefix, message, & + character(len = STRING_LENGTH) :: outputPrefix, & gradientFilename, gradientDirectory, & controlForcingFilename, controlForcingDirectory diff --git a/src/ControlSpaceAdvancerImpl.f90 b/src/ControlSpaceAdvancerImpl.f90 index 555de50f..18a6774f 100644 --- a/src/ControlSpaceAdvancerImpl.f90 +++ b/src/ControlSpaceAdvancerImpl.f90 @@ -20,15 +20,14 @@ subroutine ZAXPY(comm,ZFilename,A,XFilename,YFilename) integer, parameter :: wp = SCALAR_KIND integer :: i, procRank, numProcs, ierror, mpiFileHandle character(len = STRING_LENGTH) :: message - logical :: XFileExists, YFileExists, success - integer(kind = MPI_OFFSET_KIND) :: XFileSize, YFileSize, ZFileSize, fileOffset + logical :: XFileExists, YFileExists + integer(kind = MPI_OFFSET_KIND) :: XFileSize, YFileSize, fileOffset integer(kind = MPI_OFFSET_KIND) :: globalSize, bufferSize, sendcnt, indexQuotient integer(kind = MPI_OFFSET_KIND) :: globalBufferSize, globalOffset integer(kind = MPI_OFFSET_KIND), parameter :: bufferSizeLimit = FILE_LENGTH integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc SCALAR_TYPE, dimension(:), allocatable :: XBuffer, YBuffer, ZBuffer - SCALAR_TYPE :: dummyValue ! Initialize MPI. call MPI_Comm_rank(comm, procRank, ierror) @@ -213,7 +212,7 @@ function zWXMWY(comm,WFilename,XFilename,YFilename, normFilename) result(z) integer, parameter :: wp = SCALAR_KIND integer :: i, procRank, numProcs, ierror, mpiFileHandle character(len = STRING_LENGTH) :: message - logical :: WFileExists, XFileExists, YFileExists, normFileExists, success + logical :: WFileExists, XFileExists, YFileExists, normFileExists integer(kind = MPI_OFFSET_KIND) :: WFileSize, XFileSize, YFileSize, normFileSize, fileOffset integer(kind = MPI_OFFSET_KIND) :: globalSize, bufferSize, sendcnt, indexQuotient @@ -442,9 +441,9 @@ function zXdotY(comm,XFilename,YFilename,normFilename) result(z) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, procRank, numProcs, ierror, mpiFileHandle + integer :: i, procRank, numProcs, ierror, mpiFileHandle character(len = STRING_LENGTH) :: message - logical :: XFileExists, YFileExists, normFileExists, success + logical :: XFileExists, YFileExists, normFileExists integer(kind = MPI_OFFSET_KIND) :: XFileSize, YFileSize, normFileSize, fileOffset integer(kind = MPI_OFFSET_KIND) :: globalSize, bufferSize, sendcnt, indexQuotient diff --git a/src/DensityGradientImpl.f90 b/src/DensityGradientImpl.f90 index 9d5df4ae..24095dae 100644 --- a/src/DensityGradientImpl.f90 +++ b/src/DensityGradientImpl.f90 @@ -26,7 +26,6 @@ subroutine setupDensityGradient(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, nDimensions, ierror - character(len = STRING_LENGTH) :: filename, outputPrefix, message assert(allocated(region%states)) assert(size(region%states) > 0) @@ -111,7 +110,7 @@ subroutine computeDensityGradientSpatialDistribution(this, grid, state, F) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: k, nDimensions, nUnknowns assert(size(F, 1) == grid%nGridPoints) assert(size(F, 2) == 1) @@ -156,10 +155,9 @@ function computeDensityGradient(this, region) result(instantaneousFunctional) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: i, ierror SCALAR_TYPE, allocatable :: F(:,:) - character(len=STRING_LENGTH) :: message real(wp) :: timeRampFactor assert(allocated(region%grids)) @@ -226,9 +224,9 @@ subroutine computeDensityGradientAdjointForcing(this, simulationFlags, solverOpt ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, l, nDimensions, nUnknowns, gridIndex, patchIndex + integer :: i, j, k, nDimensions, nUnknowns, gridIndex, patchIndex SCALAR_TYPE, allocatable :: adjointVector(:) - real(wp) :: temp, timeRampFactor + real(wp) :: timeRampFactor nDimensions = grid%nDimensions assert_key(nDimensions, (1, 2, 3)) diff --git a/src/ErrorHandlerImpl.f90 b/src/ErrorHandlerImpl.f90 index dcf7daf9..a63e87f5 100644 --- a/src/ErrorHandlerImpl.f90 +++ b/src/ErrorHandlerImpl.f90 @@ -78,7 +78,7 @@ subroutine assertImpl(condition, conditionString, filename, lineNo) integer, intent(in) :: lineNo ! <<< Local variables >>> - integer :: i, j, one = 1, flag = 0, procRank, ierror + integer :: i, j, flag = 0, procRank, ierror character(len = len_trim(conditionString)) :: str1 character(len = len_trim(filename)) :: str2 diff --git a/src/GenericActuatorImpl.f90 b/src/GenericActuatorImpl.f90 index 0617d54d..776facbd 100644 --- a/src/GenericActuatorImpl.f90 +++ b/src/GenericActuatorImpl.f90 @@ -167,7 +167,7 @@ subroutine updateGenericActuatorForcing(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, nDimensions, nActuatorComponents + integer :: i, j, nDimensions class(t_Patch), pointer :: patch => null() if (.not. allocated(region%patchFactories)) return @@ -222,7 +222,7 @@ subroutine updateGenericActuatorDeltaForcing(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, nDimensions, nActuatorComponents + integer :: i, j, nDimensions class(t_Patch), pointer :: patch => null() if (.not. allocated(region%patchFactories)) return diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index dd15d4af..adc83dd9 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -291,7 +291,6 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) integer, parameter :: wp = SCALAR_KIND real(wp), parameter :: pi = 4.0_wp * atan(1.0_wp) integer :: i, j, n, nUnknowns - real(wp) :: buf real(wp), dimension(:, :), allocatable :: densityGradient, dissipationTerm call startTiming("updateIBMVariables") diff --git a/src/IsothermalWallImpl.f90 b/src/IsothermalWallImpl.f90 index 633fea03..cb7c0282 100644 --- a/src/IsothermalWallImpl.f90 +++ b/src/IsothermalWallImpl.f90 @@ -129,8 +129,9 @@ subroutine addIsothermalWallPenalty(this, mode, simulationFlags, solverOptions, ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, nDimensions, nUnknowns, direction, gridIndex, patchIndex - SCALAR_TYPE, allocatable :: metricsAlongNormalDirection(:), velocity(:,:), temperature(:), & - metrics(:,:), penaltyAtBoundary(:), penaltyNearBoundary(:,:), temp(:,:), & + SCALAR_TYPE, allocatable :: metricsAlongNormalDirection(:), & + ! metrics(:,:), penaltyNearBoundary(:,:), & + penaltyAtBoundary(:), temp(:,:), & localVelocity(:), localFluxJacobian(:,:), adjointPenalties(:,:) assert_key(mode, (FORWARD, ADJOINT, LINEARIZED)) diff --git a/src/JamesonRK3IntegratorImpl.f90 b/src/JamesonRK3IntegratorImpl.f90 index 1a549192..a72f2138 100644 --- a/src/JamesonRK3IntegratorImpl.f90 +++ b/src/JamesonRK3IntegratorImpl.f90 @@ -189,7 +189,5 @@ subroutine substepLinearizedJamesonRK3(this, region, time, timeStepSize, timeste ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer, save :: stageLastCall = 0 - integer :: i end subroutine substepLinearizedJamesonRK3 diff --git a/src/KolmogorovForcingPatchImpl.f90 b/src/KolmogorovForcingPatchImpl.f90 index c6b10463..a6b16a24 100644 --- a/src/KolmogorovForcingPatchImpl.f90 +++ b/src/KolmogorovForcingPatchImpl.f90 @@ -31,7 +31,7 @@ subroutine setupKolmogorovForcingPatch(this, index, comm, patchDescriptor, integer, parameter :: wp = SCALAR_KIND real(real64), parameter :: pi = 4.0_real64 * atan(1.0_real64) character(len = STRING_LENGTH) :: key - integer :: i, j, k, gridIndex, patchIndex, nDimensions, ierror + integer :: i, j, k, gridIndex, patchIndex, nDimensions nDimensions = grid%nDimensions assert_key(nDimensions, (2, 3)) @@ -119,7 +119,6 @@ subroutine addKolmogorovForcing(this, mode, simulationFlags, solverOptions, grid ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, nDimensions, gridIndex, patchIndex - real(SCALAR_KIND) :: time, excitationAmount real(SCALAR_KIND), allocatable :: temporalFunctions(:,:) SCALAR_TYPE, allocatable :: temp(:,:,:) SCALAR_TYPE :: localForcing diff --git a/src/LighthillSourceImpl.f90 b/src/LighthillSourceImpl.f90 index fac5c9d7..a045243d 100644 --- a/src/LighthillSourceImpl.f90 +++ b/src/LighthillSourceImpl.f90 @@ -26,7 +26,6 @@ subroutine setupLighthillSource(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, l, nDimensions, ierror - character(len = STRING_LENGTH) :: filename, outputPrefix, message SCALAR_TYPE, allocatable :: temp1(:,:), temp2(:,:) assert(allocated(region%states)) @@ -96,9 +95,6 @@ subroutine cleanupLighthillSource(this) ! <<< Arguments >>> class(t_LighthillSource) :: this - ! <<< Local variables >>> - integer :: i - call this%cleanupBase() end subroutine cleanupLighthillSource @@ -124,7 +120,7 @@ subroutine computeLighthillSourceSpatialDistribution(this, grid, state, F) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: j, k, nDimensions, nUnknowns logical :: computeViscousFlux = .false. SCALAR_TYPE, allocatable :: fluxes1(:,:,:), fluxes2(:,:,:), F1(:,:,:), F2(:,:,:) @@ -230,10 +226,9 @@ function computeLighthillSource(this, region) result(instantaneousFunctional) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: i, ierror SCALAR_TYPE, allocatable :: F(:,:) - character(len=STRING_LENGTH) :: message real(wp) :: timeRampFactor assert(allocated(region%grids)) diff --git a/src/LighthillTensorComponentImpl.f90 b/src/LighthillTensorComponentImpl.f90 index 515dcc92..5494d631 100644 --- a/src/LighthillTensorComponentImpl.f90 +++ b/src/LighthillTensorComponentImpl.f90 @@ -25,8 +25,8 @@ subroutine setupLighthillTensorComponent(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, nDimensions, ierror - character(len = STRING_LENGTH) :: filename, outputPrefix, message + integer :: nDimensions + character(len = STRING_LENGTH) :: message assert(allocated(region%states)) assert(size(region%states) > 0) @@ -84,9 +84,6 @@ subroutine cleanupLighthillTensorComponent(this) ! <<< Arguments >>> class(t_LighthillTensorComponent) :: this - ! <<< Local variables >>> - integer :: i - call this%cleanupBase() end subroutine cleanupLighthillTensorComponent @@ -112,7 +109,7 @@ subroutine computeLighthillTensorComponentSpatialDistribution(this, grid, state, ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: i, k, nDimensions, nUnknowns logical :: computeViscousFlux = .false. SCALAR_TYPE, allocatable :: fluxes1(:,:,:), fluxes2(:,:,:) @@ -199,10 +196,9 @@ function computeLighthillTensorComponent(this, region) result(instantaneousFunct ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, j, k, nDimensions, nUnknowns, ierror + integer :: i, ierror SCALAR_TYPE, allocatable :: F(:,:) - character(len=STRING_LENGTH) :: message real(wp) :: timeRampFactor assert(allocated(region%grids)) @@ -270,10 +266,9 @@ subroutine computeLighthillTensorComponentAdjointForcing(this, simulationFlags, ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND integer :: i, j, k, l, nDimensions, nUnknowns, gridIndex, patchIndex - SCALAR_TYPE, allocatable :: temp1(:,:,:), temp2(:,:,:), localMetricsAlongDirection1(:), & - localFluxJacobian1(:,:), localFluxJacobian2(:,:), localConservedVariables(:), & - localVelocity(:), unitVector1(:), unitVector2(:), & - localStressTensor(:), localHeatFlux(:), localAdjointDiffusion(:,:) + SCALAR_TYPE, allocatable :: localMetricsAlongDirection1(:), & + localFluxJacobian1(:,:), localConservedVariables(:), & + localVelocity(:), unitVector2(:) SCALAR_TYPE, allocatable :: F(:) real(wp) :: timeRampFactor, const1 diff --git a/src/MomentumActuatorImpl.f90 b/src/MomentumActuatorImpl.f90 index 5b59f6f0..33d4a68e 100644 --- a/src/MomentumActuatorImpl.f90 +++ b/src/MomentumActuatorImpl.f90 @@ -19,7 +19,7 @@ subroutine setupMomentumActuator(this, region) ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer :: i, nDimensions, nActuatorComponents + integer :: i, nDimensions class(t_Patch), pointer :: patch => null() call this%cleanup() diff --git a/src/SolverImpl.f90 b/src/SolverImpl.f90 index ae70cb17..c5d30019 100644 --- a/src/SolverImpl.f90 +++ b/src/SolverImpl.f90 @@ -681,7 +681,7 @@ function runForward(this, region, restartFilename) result(costFunctional) integer :: i, j, timestep, startTimestep real(wp) :: time, startTime, timeStepSize SCALAR_TYPE :: instantaneousCostFunctional - logical :: controllerSwitch = .false., solutionCrashes = .false. + logical :: controllerSwitch = .false. call startTiming("runForward") @@ -1184,7 +1184,7 @@ function runLinearized(this, region) result(costFunctional) integer :: i, j, timestep, startTimestep real(wp) :: time, startTime, timeStepSize SCALAR_TYPE :: instantaneousCostFunctional - logical :: controllerSwitch = .false., solutionCrashes = .false. + logical :: controllerSwitch = .false. call startTiming("runLinearized") @@ -1380,14 +1380,14 @@ subroutine checkGradientAccuracy(this, region) class(t_Region) :: region ! <<< Local variables >>> - integer, parameter :: wp = SCALAR_KIND - integer :: i, j, nIterations, restartIteration, fileUnit, iostat, procRank, ierror - integer :: numberOfActuatorPatches - class(t_Patch), pointer :: patch => null() - character(len = STRING_LENGTH) :: filename, message - character(len = STRING_LENGTH) :: gradientFilename, controlForcingFilename - real(wp) :: actuationAmount, baselineCostFunctional, costFunctional, costSensitivity, & - initialActuationAmount, geometricGrowthFactor, gradientError, dummyValue + character(len = STRING_LENGTH) :: message + ! integer :: i, j, nIterations, restartIteration, fileUnit, iostat, procRank, ierror + ! integer :: numberOfActuatorPatches + ! class(t_Patch), pointer :: patch => null() + ! character(len = STRING_LENGTH) :: filename, message + ! character(len = STRING_LENGTH) :: gradientFilename, controlForcingFilename + ! real(wp) :: actuationAmount, baselineCostFunctional, costFunctional, costSensitivity, & + ! initialActuationAmount, geometricGrowthFactor, gradientError, dummyValue write(message, '(A)') "Subroutine checkGradientAccuracy is obsolete. Use utils/python/checkGradientAccuracy.py." call gracefulExit(region%comm, message) diff --git a/src/ThermalActuatorImpl.f90 b/src/ThermalActuatorImpl.f90 index 4f813a79..0e9f3c86 100644 --- a/src/ThermalActuatorImpl.f90 +++ b/src/ThermalActuatorImpl.f90 @@ -111,9 +111,6 @@ function computeThermalActuatorSensitivity(this, region) result(instantaneousSen SCALAR_TYPE, allocatable :: F(:,:) real(SCALAR_KIND) :: timeRampFactor - ! <<< SeungWhan: variable for time_ramp printing >>> - character(len = STRING_LENGTH) :: message - assert(allocated(region%grids)) assert(allocated(region%states)) assert(size(region%grids) == size(region%states)) @@ -189,9 +186,6 @@ subroutine updateThermalActuatorForcing(this, region) class(t_Patch), pointer :: patch => null() SCALAR_TYPE, allocatable :: temp(:,:) - ! <<< SeungWhan: variable for time_ramp printing >>> - character(len = STRING_LENGTH) :: message - if (.not. allocated(region%patchFactories)) return nDimensions = size(region%globalGridSizes, 1) @@ -266,9 +260,6 @@ subroutine updateThermalActuatorDeltaForcing(this, region) class(t_Patch), pointer :: patch => null() SCALAR_TYPE, allocatable :: temp(:,:) - ! <<< SeungWhan: variable for time_ramp printing >>> - character(len = STRING_LENGTH) :: message - if (.not. allocated(region%patchFactories)) return nDimensions = size(region%globalGridSizes, 1) @@ -341,9 +332,6 @@ subroutine migrateToThermalActuatorForcing(this, region, startTimeStep, endTimeS class(t_Patch), pointer :: patch => null() SCALAR_TYPE, allocatable :: temp(:,:) - ! <<< SeungWhan: variable for time_ramp printing >>> - character(len = STRING_LENGTH) :: message - if (.not. allocated(region%patchFactories)) return nDimensions = size(region%globalGridSizes, 1) diff --git a/test/adjoint_relation/SAT_block_interface.f90 b/test/adjoint_relation/SAT_block_interface.f90 index c5fd6877..12b15ac5 100644 --- a/test/adjoint_relation/SAT_block_interface.f90 +++ b/test/adjoint_relation/SAT_block_interface.f90 @@ -11,7 +11,7 @@ program SAT_block_interface implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -236,8 +236,6 @@ end subroutine sort type(t_Region) :: region type(t_Grid) :: grid(2) type(t_State) :: state0(2), state1(2), deltaState(2) - type(t_PatchDescriptor) :: patchDescriptor - type(t_PatchFactory), allocatable :: patchFactories(:) class(t_Patch), pointer :: patch => null() ! type(t_FarFieldPatch) :: patch @@ -246,14 +244,12 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, hx, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 2), gridIndex, & - nUnknowns, direction_, errorCode, extent(6), ierror - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & - deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& - targetViscousFluxes(:,:,:) + nUnknowns, ierror + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & + deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:) SCALAR_TYPE :: inviscidPenaltyAmount, viscousPenaltyAmount SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation - character(len = STRING_LENGTH) :: errorMessage - character(len = STRING_LENGTH) :: filename, outputPrefix, message, resultFilename + character(len = STRING_LENGTH) :: filename tolerance_ = 1.0E-11 if( present(tolerance) ) tolerance_ = tolerance diff --git a/test/adjoint_relation/SAT_farfield.f90 b/test/adjoint_relation/SAT_farfield.f90 index a809d367..285ea2e6 100644 --- a/test/adjoint_relation/SAT_farfield.f90 +++ b/test/adjoint_relation/SAT_farfield.f90 @@ -11,7 +11,7 @@ program SAT_farfield implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -242,7 +242,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & adjointRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:), targetViscousFluxes(:,:,:) diff --git a/test/adjoint_relation/SAT_isothermal.f90 b/test/adjoint_relation/SAT_isothermal.f90 index 067850d5..d06827c0 100644 --- a/test/adjoint_relation/SAT_isothermal.f90 +++ b/test/adjoint_relation/SAT_isothermal.f90 @@ -11,7 +11,7 @@ program SAT_isothermal implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -230,7 +230,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & adjointRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:), targetViscousFluxes(:,:,:) diff --git a/test/adjoint_relation/artificial_dissipation.f90 b/test/adjoint_relation/artificial_dissipation.f90 index f09575be..2d6c7e03 100644 --- a/test/adjoint_relation/artificial_dissipation.f90 +++ b/test/adjoint_relation/artificial_dissipation.f90 @@ -11,7 +11,7 @@ program artificial_dissipation implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -222,7 +222,6 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian real(wp) :: scalar1, scalar2, tolerance_, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns @@ -231,7 +230,6 @@ end subroutine sort deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:) SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation - character(len = STRING_LENGTH) :: errorMessage tolerance_ = 1.0E-12 if( present(tolerance) ) tolerance_ = tolerance diff --git a/test/adjoint_relation/body_force.f90 b/test/adjoint_relation/body_force.f90 index ea4361a7..98b6bca7 100644 --- a/test/adjoint_relation/body_force.f90 +++ b/test/adjoint_relation/body_force.f90 @@ -11,7 +11,7 @@ program body_force implicit none logical :: success, success1, success2, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -238,17 +238,14 @@ end subroutine sort type(t_SolverOptions) :: solverOptions type(t_Grid) :: grid type(t_State) :: state0, state1 - type(t_PatchDescriptor) :: patchDescriptor - type(t_PatchFactory), allocatable :: patchFactories(:) - class(t_Patch), pointer :: patch => null() ! type(t_SpongePatch) :: patch ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) - integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns + real(SCALAR_KIND), allocatable :: F(:,:), & adjointRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:) diff --git a/test/adjoint_relation/control_functional.f90 b/test/adjoint_relation/control_functional.f90 index 5f797dc1..00f4ceea 100644 --- a/test/adjoint_relation/control_functional.f90 +++ b/test/adjoint_relation/control_functional.f90 @@ -11,7 +11,7 @@ program control_functional implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror, stat + integer :: i, j, nDimensions, ierror, stat integer :: procRank character(len = STRING_LENGTH) :: costType character(len = STRING_LENGTH) :: controllerTypes(3) @@ -168,17 +168,16 @@ end subroutine sort real(wp) :: scalar1, sensitivity, scalar2, tolerance_, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer, allocatable :: gridSize(:,:) - integer :: i, j, k, l, nUnknowns, nTimesteps, saveInterval, & + integer :: i, j, k, l, nTimesteps, saveInterval, & timestep, startTimestep, timemarchDirection real(wp) :: timeStepSize, time, startTime, velMin, velMax - real(SCALAR_KIND), allocatable :: forwardState(:,:), adjointState(:,:), & - controlForcing(:,:), adjointForcing(:,:), deltaState(:,:),& - forwardRhs(:) - character(len = STRING_LENGTH) :: filename, errorMessage + character(len = STRING_LENGTH) :: filename character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) success = .true. + tolerance_ = 1.0E-13 + if (present(tolerance)) tolerance_ = tolerance ! set up simulation flags call simulationFlags%initialize() diff --git a/test/adjoint_relation/full_rhs.f90 b/test/adjoint_relation/full_rhs.f90 index f3cef336..4a8e5c6f 100644 --- a/test/adjoint_relation/full_rhs.f90 +++ b/test/adjoint_relation/full_rhs.f90 @@ -20,8 +20,8 @@ program full_rhs 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 @@ -43,10 +43,6 @@ end subroutine testAdjointRelation end interface - ! << 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) @@ -266,12 +262,10 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer(kind = MPI_OFFSET_KIND) :: offset - real(wp) :: scalar1, scalar2, tolerance_,& + real(wp) :: scalar1, scalar2,& stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, ierror, procRank - integer :: nDimensions, nUnknowns, stage - logical :: success_ + integer :: nDimensions, stage character(len=STRING_LENGTH) :: filename real(SCALAR_KIND), allocatable :: F(:,:), deltaPrimitiveVariables(:,:) diff --git a/test/adjoint_relation/initial_condition.f90 b/test/adjoint_relation/initial_condition.f90 index d7636e3e..11a6683c 100644 --- a/test/adjoint_relation/initial_condition.f90 +++ b/test/adjoint_relation/initial_condition.f90 @@ -11,7 +11,7 @@ program initial_condition implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror, stat + integer :: i, j, nDimensions, ierror, stat integer :: procRank character(len = STRING_LENGTH) :: costType @@ -163,17 +163,16 @@ end subroutine sort real(wp) :: scalar1, sensitivity, scalar2, tolerance_, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer, allocatable :: gridSize(:,:) - integer :: i, j, k, l, nUnknowns, nTimesteps, saveInterval, & + integer :: i, j, k, l, nTimesteps, saveInterval, & timestep, startTimestep, timemarchDirection real(wp) :: timeStepSize, time, startTime, velMin, velMax - real(SCALAR_KIND), allocatable :: forwardState(:,:), & - controlForcing(:,:), adjointForcing(:,:), deltaState(:,:),& - forwardRhs(:) - character(len = STRING_LENGTH) :: filename, errorMessage + character(len = STRING_LENGTH) :: filename character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) success = .true. + tolerance_ = 1.0E-13 + if( present(tolerance) ) tolerance_ = tolerance ! set up simulation flags call simulationFlags%initialize() diff --git a/test/adjoint_relation/inviscid_flux.f90 b/test/adjoint_relation/inviscid_flux.f90 index aa23f1f6..5d638223 100644 --- a/test/adjoint_relation/inviscid_flux.f90 +++ b/test/adjoint_relation/inviscid_flux.f90 @@ -11,7 +11,7 @@ program inviscid_flux implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -221,8 +221,7 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_,& + real(wp) :: scalar1, scalar2,& stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & @@ -232,7 +231,6 @@ end subroutine sort adjointRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:) SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation - character(len = STRING_LENGTH) :: errorMessage success = .true. diff --git a/test/adjoint_relation/sponge.f90 b/test/adjoint_relation/sponge.f90 index ac24f18a..5b228829 100644 --- a/test/adjoint_relation/sponge.f90 +++ b/test/adjoint_relation/sponge.f90 @@ -11,7 +11,7 @@ program sponge implicit none logical :: success, success1, success2, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -246,7 +246,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & adjointRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:) diff --git a/test/adjoint_relation/time_integrator.f90 b/test/adjoint_relation/time_integrator.f90 index 389838a5..f6433ff8 100644 --- a/test/adjoint_relation/time_integrator.f90 +++ b/test/adjoint_relation/time_integrator.f90 @@ -11,7 +11,7 @@ program time_integrator implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -122,15 +122,12 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_,& - stepSizes(32), errorHistory(32), convergenceHistory(31) + real(wp) :: scalar1, scalar2, tolerance_ integer, allocatable :: gridSize(:,:) - integer :: i, j, k, nUnknowns, nTimesteps, timestep, startTimestep, timemarchDirection + integer :: i, nTimesteps, timestep, startTimestep, timemarchDirection real(wp) :: timeStepSize, time, error real(SCALAR_KIND), allocatable :: forwardState(:), adjointState(:), & forwardRhs(:), adjointRhs(:) - character(len = STRING_LENGTH) :: errorMessage tolerance_ = 100*epsilon(0.0_wp) if( present(tolerance) ) tolerance_ = tolerance diff --git a/test/adjoint_relation/viscous_flux.f90 b/test/adjoint_relation/viscous_flux.f90 index fa684e80..82473a86 100644 --- a/test/adjoint_relation/viscous_flux.f90 +++ b/test/adjoint_relation/viscous_flux.f90 @@ -11,7 +11,7 @@ program viscous_flux implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -221,8 +221,7 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_,& + real(wp) :: scalar1, scalar2,& stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & @@ -236,7 +235,6 @@ end subroutine sort localHeatFlux(:), localAdjointDiffusion(:,:), & temp2(:,:) SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation - character(len = STRING_LENGTH) :: errorMessage success = .true. diff --git a/test/block_interface_sign.f90 b/test/block_interface_sign.f90 index 63172217..6c523565 100644 --- a/test/block_interface_sign.f90 +++ b/test/block_interface_sign.f90 @@ -11,7 +11,7 @@ program block_interface_sign use State_enum use InputHelper, only : parseInputFile, getFreeUnit, getOption, getRequiredOption - use InputHelperImpl, only: dict, find + use InputHelperImpl, only: find use ErrorHandler use PLOT3DHelper, only : plot3dDetectFormat, plot3dErrorMessage use MPITimingsHelper, only : startTiming, endTiming, reportTimings, cleanupTimers @@ -24,8 +24,8 @@ program block_interface_sign implicit none integer, parameter :: wp = SCALAR_KIND - integer :: i, j, stat, fileUnit, dictIndex, procRank, numProcs, ierror, STATUS - character(len = STRING_LENGTH) :: filename, resultFilename, outputPrefix, message + integer :: i, j, procRank, numProcs, ierror + character(len = STRING_LENGTH) :: filename, outputPrefix, message logical :: success integer, dimension(:,:), allocatable :: globalGridSizes type(t_Region) :: region @@ -45,10 +45,6 @@ end subroutine testInterfaceRelation end interface - ! << 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) @@ -305,15 +301,11 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer(kind = MPI_OFFSET_KIND) :: offset - real(wp) :: scalar1, scalar2, tolerance_, randomArray(10), & - stepSizes(32), errorHistory(32), convergenceHistory(31) + real(wp) :: randomArray(10) integer :: i, j, k, l, ierror, procRank - integer :: nDimensions, nUnknowns, stage, direction, gridIndex - logical :: success_ + integer :: nDimensions, direction, gridIndex character(len=STRING_LENGTH) :: filename, grid0Patch, outputPrefix - real(SCALAR_KIND), allocatable :: F(:,:), deltaPrimitiveVariables(:,:), & - localMetricsAlongNormalDirection(:), & + real(SCALAR_KIND), allocatable :: localMetricsAlongNormalDirection(:), & fluxes2(:,:,:) integer, allocatable :: patch0Index(:) real(wp), parameter :: PI = 4.0_wp * ATAN(1.0_wp) diff --git a/test/linearized_relation/SAT_block_interface_linearized.f90 b/test/linearized_relation/SAT_block_interface_linearized.f90 index 7b298535..6b5e11c3 100644 --- a/test/linearized_relation/SAT_block_interface_linearized.f90 +++ b/test/linearized_relation/SAT_block_interface_linearized.f90 @@ -11,7 +11,7 @@ program SAT_block_interface_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -238,8 +238,6 @@ end subroutine sort type(t_Region) :: region type(t_Grid) :: grid(2) type(t_State) :: state0(2), state1(2), deltaState(2) - type(t_PatchDescriptor) :: patchDescriptor - type(t_PatchFactory), allocatable :: patchFactories(:) class(t_Patch), pointer :: patch => null() ! type(t_FarFieldPatch) :: patch @@ -248,10 +246,9 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, hx, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, l, gridSize(nDimensions, 2), gridIndex, & - nUnknowns, direction_, errorCode, extent(6), ierror, normalDirection - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + nUnknowns, ierror, normalDirection + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& - targetViscousFluxes(:,:,:), & temp1(:,:,:), localFluxJacobian1(:,:), & localConservedVariables(:), localVelocity(:), & localMetricsAlongDirection1(:), & @@ -262,7 +259,7 @@ end subroutine sort SCALAR_TYPE :: inviscidPenaltyAmount, viscousPenaltyAmount SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation character(len = STRING_LENGTH) :: errorMessage - character(len = STRING_LENGTH) :: filename, outputPrefix, message, resultFilename + character(len = STRING_LENGTH) :: filename tolerance_ = 1.0E-11 if( present(tolerance) ) tolerance_ = tolerance diff --git a/test/linearized_relation/SAT_farfield_linearized.f90 b/test/linearized_relation/SAT_farfield_linearized.f90 index 7b7ef03d..50dc5706 100644 --- a/test/linearized_relation/SAT_farfield_linearized.f90 +++ b/test/linearized_relation/SAT_farfield_linearized.f90 @@ -11,7 +11,7 @@ program SAT_farfield_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -230,7 +230,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & temp1(:,:,:), localFluxJacobian1(:,:), & localConservedVariables(:), localVelocity(:), & localMetricsAlongDirection1(:), & diff --git a/test/linearized_relation/SAT_isothermal_linearized.f90 b/test/linearized_relation/SAT_isothermal_linearized.f90 index 1b8c1413..58876d64 100644 --- a/test/linearized_relation/SAT_isothermal_linearized.f90 +++ b/test/linearized_relation/SAT_isothermal_linearized.f90 @@ -11,7 +11,7 @@ program SAT_isothermal_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -230,7 +230,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & linearizedRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:), targetViscousFluxes(:,:,:) diff --git a/test/linearized_relation/artificial_dissipation_linearized.f90 b/test/linearized_relation/artificial_dissipation_linearized.f90 index 002748e7..d4163c35 100644 --- a/test/linearized_relation/artificial_dissipation_linearized.f90 +++ b/test/linearized_relation/artificial_dissipation_linearized.f90 @@ -11,7 +11,7 @@ program artificial_dissipation_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -224,7 +224,6 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns diff --git a/test/linearized_relation/body_force_linearized.f90 b/test/linearized_relation/body_force_linearized.f90 index 82274679..a2238155 100644 --- a/test/linearized_relation/body_force_linearized.f90 +++ b/test/linearized_relation/body_force_linearized.f90 @@ -11,7 +11,7 @@ program body_force_linearized implicit none logical :: success, success1, success2, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -238,17 +238,14 @@ end subroutine sort type(t_SolverOptions) :: solverOptions type(t_Grid) :: grid type(t_State) :: state0, state1 - type(t_PatchDescriptor) :: patchDescriptor - type(t_PatchFactory), allocatable :: patchFactories(:) - class(t_Patch), pointer :: patch => null() ! type(t_SpongePatch) :: patch ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) - integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns + real(SCALAR_KIND), allocatable :: F(:,:), & linearizedRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:) diff --git a/test/linearized_relation/full_rhs_linearized.f90 b/test/linearized_relation/full_rhs_linearized.f90 index d6f6bb25..2ddce19c 100644 --- a/test/linearized_relation/full_rhs_linearized.f90 +++ b/test/linearized_relation/full_rhs_linearized.f90 @@ -20,8 +20,8 @@ program full_rhs_linearized 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 @@ -43,10 +43,6 @@ end subroutine testLinearizedRelation end interface - ! << 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) @@ -266,12 +262,10 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - integer(kind = MPI_OFFSET_KIND) :: offset - real(wp) :: scalar1, scalar2, tolerance_,& + real(wp) :: scalar1, scalar2,& stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, ierror, procRank, clock - integer :: nDimensions, nUnknowns, stage - logical :: success_ + integer :: nDimensions, stage character(len=STRING_LENGTH) :: filename real(SCALAR_KIND), allocatable :: F(:,:), deltaPrimitiveVariables(:,:) integer, allocatable :: seed(:) diff --git a/test/linearized_relation/inviscid_flux_linearized.f90 b/test/linearized_relation/inviscid_flux_linearized.f90 index 994e9769..a054135b 100644 --- a/test/linearized_relation/inviscid_flux_linearized.f90 +++ b/test/linearized_relation/inviscid_flux_linearized.f90 @@ -11,7 +11,7 @@ program inviscid_flux_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -223,8 +223,7 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_,& + real(wp) :: scalar1, scalar2,& stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & @@ -234,7 +233,6 @@ end subroutine sort linearizedRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:) SCALAR_TYPE, dimension(nDimensions) :: h, gridPerturbation - character(len = STRING_LENGTH) :: errorMessage success = .true. diff --git a/test/linearized_relation/sponge_linearized.f90 b/test/linearized_relation/sponge_linearized.f90 index 585427bd..c90c5efd 100644 --- a/test/linearized_relation/sponge_linearized.f90 +++ b/test/linearized_relation/sponge_linearized.f90 @@ -11,7 +11,7 @@ program sponge_linearized implicit none logical :: success, success1, success2, success_, isPeriodic - integer :: i, j, k, nDimensions, direction, ierror + integer :: i, j, nDimensions, direction, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -248,7 +248,7 @@ end subroutine sort real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns, direction_, errorCode, extent(6) - real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & + real(SCALAR_KIND), allocatable :: F(:,:), fluxes2(:,:,:), & linearizedRightHandSide(:,:), & deltaConservedVariables(:,:), deltaPrimitiveVariables(:,:),& temp2(:,:) diff --git a/test/linearized_relation/viscous_flux_C.f90 b/test/linearized_relation/viscous_flux_C.f90 index 24539f27..7c29db52 100644 --- a/test/linearized_relation/viscous_flux_C.f90 +++ b/test/linearized_relation/viscous_flux_C.f90 @@ -11,7 +11,7 @@ program viscous_flux_C implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -226,8 +226,7 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & + real(wp) :: scalar1, scalar2, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns real(SCALAR_KIND), allocatable :: F(:,:), temp2(:,:), & diff --git a/test/linearized_relation/viscous_flux_linearized.f90 b/test/linearized_relation/viscous_flux_linearized.f90 index 8e03aa83..3109d333 100644 --- a/test/linearized_relation/viscous_flux_linearized.f90 +++ b/test/linearized_relation/viscous_flux_linearized.f90 @@ -11,7 +11,7 @@ program viscous_flux_linearized implicit none logical :: success, success_, isPeriodic - integer :: i, j, k, nDimensions, ierror + integer :: i, j, nDimensions, ierror integer :: procRank character(len = STRING_LENGTH), parameter :: discretizationTypes(4) = & (/ "SBP 1-2", "SBP 2-4", "SBP 3-6", "SBP 4-8" /) @@ -223,8 +223,7 @@ end subroutine sort ! <<< Local variables >>> integer, parameter :: wp = SCALAR_KIND - logical :: isPeriodic_(3), hasNegativeJacobian - real(wp) :: scalar1, scalar2, tolerance_, scalarHistory(32), & + real(wp) :: scalar1, scalar2, scalarHistory(32), & stepSizes(32), errorHistory(32), convergenceHistory(31) integer :: i, j, k, gridSize(nDimensions, 1), nUnknowns real(SCALAR_KIND), allocatable :: F(:,:), fluxes1(:,:,:), fluxes2(:,:,:), & diff --git a/test/stencil_coefficients.f90 b/test/stencil_coefficients.f90 index 73f47f9e..605ec909 100644 --- a/test/stencil_coefficients.f90 +++ b/test/stencil_coefficients.f90 @@ -16,7 +16,6 @@ program stencil_coefficients integer, parameter :: wp = SCALAR_KIND type(t_StencilOperator) :: A logical :: success - integer :: i interface diff --git a/test/testZAXPY.f90 b/test/testZAXPY.f90 index ba48262c..c6b320ba 100644 --- a/test/testZAXPY.f90 +++ b/test/testZAXPY.f90 @@ -13,8 +13,8 @@ program testZAXPY implicit none - character(len = STRING_LENGTH) :: ZFilename, Astr, XFilename, YFilename, message - integer :: i, stat, fileUnit, procRank, numProcs, ierror, mpiFileHandle, errorCode = 0 + character(len = STRING_LENGTH) :: ZFilename, XFilename, YFilename + integer :: stat, fileUnit, procRank, numProcs, ierror, errorCode = 0 SCALAR_TYPE, dimension(17) :: X, Y, Z, Zoutput SCALAR_TYPE :: A diff --git a/utils/append_gradient.f90 b/utils/append_gradient.f90 index f293587d..60aca5fa 100644 --- a/utils/append_gradient.f90 +++ b/utils/append_gradient.f90 @@ -39,7 +39,6 @@ program append_gradient integer, dimension(:,:), allocatable :: globalGridSizes type(t_Region) :: region type(t_Solver) :: solver - SCALAR_TYPE :: dummyValue ! Initialize MPI. call MPI_Init(ierror) diff --git a/utils/control_mollifier_factor.f90 b/utils/control_mollifier_factor.f90 index 3cbeb4b7..ecb702e8 100644 --- a/utils/control_mollifier_factor.f90 +++ b/utils/control_mollifier_factor.f90 @@ -25,7 +25,7 @@ program control_mollifier_factor integer :: kthArgument, numberOfArguments logical :: lookForInput = .false., lookForOutput = .false., & inputFlag = .false., outputFlag = .false. - character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename, restartFilename + character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename character(len = STRING_LENGTH) :: filename, outputPrefix, message logical :: fileExists, success integer, dimension(:,:), allocatable :: globalGridSizes @@ -35,7 +35,7 @@ program control_mollifier_factor type(t_Solver) :: solver ! << output variables >> - integer :: inputNumber, simulationNumber, intValue = 0 + integer :: intValue = 0 SCALAR_TYPE :: dummyValue = 0.0_wp, maxValue = 0.0_wp ! Initialize MPI. diff --git a/utils/extend_control_forcing.f90 b/utils/extend_control_forcing.f90 index e390dc52..c862443c 100644 --- a/utils/extend_control_forcing.f90 +++ b/utils/extend_control_forcing.f90 @@ -13,7 +13,7 @@ program extend_control_forcing character(len = STRING_LENGTH) :: ZFilename, XFilename, message, & durationStr, totalTimestepStr integer :: ierror - integer :: startTimestep, duration, totalTimestep + integer :: duration, totalTimestep ! Initialize MPI. call MPI_Init(ierror) @@ -69,13 +69,12 @@ subroutine extendControlForcing(comm,ZFilename,XFilename,XFileTimestep,extension 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, extensionOffset + logical :: XFileExists + integer(kind = MPI_OFFSET_KIND) :: XFileSize, offset, extensionOffset integer(kind = MPI_OFFSET_KIND) :: XArraySize, patchSize, extensionSize, bufferSize, sendcnt, indexQuotient integer(kind = MPI_OFFSET_KIND), dimension(:), allocatable :: recvcnt, displc SCALAR_TYPE, dimension(:), allocatable :: XBuffer, extensionBuffer - SCALAR_TYPE :: dummyValue ! Initialize MPI. call MPI_Comm_rank(comm, procRank, ierror) diff --git a/utils/probe_from_qfile.f90 b/utils/probe_from_qfile.f90 index c37d93dd..b5d1aeb0 100644 --- a/utils/probe_from_qfile.f90 +++ b/utils/probe_from_qfile.f90 @@ -24,14 +24,11 @@ program probe_from_qfile implicit none integer, parameter :: wp = SCALAR_KIND - integer :: i, j, startTimestep, endTimestep, saveInterval, ierror + integer :: i, startTimestep, endTimestep, saveInterval, ierror character(len = STRING_LENGTH) :: filename, outputPrefix logical :: success type(t_Region) :: region integer, allocatable :: globalGridSizes(:,:) - type(t_FunctionalFactory) :: functionalFactory - class(t_Functional), pointer :: functional => null() - SCALAR_TYPE :: instantaneousFunctional character(len = STRING_LENGTH) :: message !SeungWhan: for debugging ! Initialize MPI. diff --git a/utils/saveGridNorm.f90 b/utils/saveGridNorm.f90 index 1e815340..c5ab79d9 100644 --- a/utils/saveGridNorm.f90 +++ b/utils/saveGridNorm.f90 @@ -18,19 +18,16 @@ program savegridnorm implicit none integer, parameter :: wp = SCALAR_KIND - integer :: i, stat, fileUnit, procRank, numProcs, ierror + integer :: i, procRank, numProcs, ierror integer :: kthArgument, numberOfArguments logical :: lookForInput = .false., lookForOutput = .false., saveMetricsFlag = .false., & inputFlag = .false., outputFlag = .false. - character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename, restartFilename + character(len = STRING_LENGTH) :: argument, inputFilename, outputFilename character(len = STRING_LENGTH) :: filename, outputPrefix, message logical :: fileExists, success integer, dimension(:,:), allocatable :: globalGridSizes type(t_Region) :: region - ! << output variables >> - integer :: inputNumber, simulationNumber - ! Initialize MPI. call MPI_Init(ierror) call MPI_Comm_rank(MPI_COMM_WORLD, procRank, ierror) diff --git a/utils/shear_layer.f90 b/utils/shear_layer.f90 index 9960e234..0f39fc9d 100644 --- a/utils/shear_layer.f90 +++ b/utils/shear_layer.f90 @@ -12,7 +12,7 @@ program shear_layer use InputHelper, only : parseInputFile, getOption, getRequiredOption use ErrorHandler, only : writeAndFlush, gracefulExit - use PLOT3DHelper, only : plot3dDetectFormat, plot3dErrorMessage + use PLOT3DHelper, only : plot3dDetectFormat !> Generates the initial condition and target state for a shear layer. @@ -20,9 +20,7 @@ program shear_layer integer :: i, ierror character(len = STRING_LENGTH) :: filename - logical :: success type(t_Region) :: region - integer, allocatable :: globalGridSizes(:,:) ! Initialize MPI. call MPI_Init(ierror) @@ -294,7 +292,7 @@ subroutine shearLayerInitialCondition(state, grid) type(t_State) :: state ! Local variables - integer :: i, j, k, ierror, procRank + integer :: i, j, ierror, procRank integer, parameter :: nkx = 10, nkz = 5 integer, parameter :: wp = SCALAR_KIND real(SCALAR_KIND), parameter :: pi = 4.0_wp * atan(1.0_wp) diff --git a/utils/zxdoty_in_time.f90 b/utils/zxdoty_in_time.f90 index 1bbd0a16..574ca640 100644 --- a/utils/zxdoty_in_time.f90 +++ b/utils/zxdoty_in_time.f90 @@ -15,7 +15,7 @@ program run_zXdotY integer, parameter :: wp = SCALAR_KIND character(len = STRING_LENGTH) :: zFilename, XFilename, YFilename, normFilename, message character(len = STRING_LENGTH) :: nTimesteps_str, argument - integer :: nTimesteps, reportInterval = 1, stat, fileUnit, procRank, ierror + integer :: nTimesteps, reportInterval = 1, ierror integer :: kthArgument, numberOfArguments logical :: lookForReportInterval = .false. @@ -91,7 +91,7 @@ subroutine zXdotYinTime(comm,zFilename,XFilename,YFilename,normFilename,nTimeste integer, parameter :: wp = SCALAR_KIND integer :: i, procRank, numProcs, ierror, mpiFileHandle, timestep, stage character(len = STRING_LENGTH) :: message - logical :: XFileExists, YFileExists, normFileExists, success, append + logical :: XFileExists, YFileExists, normFileExists, append integer(kind = MPI_OFFSET_KIND) :: XFileSize, YFileSize, normFileSize, offset, timeOffset integer(kind = MPI_OFFSET_KIND) :: globalSize, patchSize, bufferSize, sendcnt, indexQuotient @@ -275,7 +275,7 @@ subroutine zXdotYinTime(comm,zFilename,XFilename,YFilename,normFilename,nTimeste deallocate(XBuffer) deallocate(YBuffer) - deallocate(normBuffer) + deallocate(normBuffer) end subroutine From 34211d85ff829812c8134fbade2c1349257fa348 Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Thu, 15 Dec 2022 23:45:12 -0600 Subject: [PATCH 13/13] t_State: ibmPatchExists flag. --- include/State.f90 | 1 + src/ImmersedBoundaryImpl.f90 | 2 ++ src/RegionImpl.f90 | 26 ++++++++++++++++++++++++++ src/SinusoidalWallLevelsetImpl.f90 | 2 ++ 4 files changed, 31 insertions(+) diff --git a/include/State.f90 b/include/State.f90 index db0873e5..38c90765 100644 --- a/include/State.f90 +++ b/include/State.f90 @@ -67,6 +67,7 @@ end function getNumberOfScalars real(SCALAR_KIND), dimension(:,:), allocatable :: objectVelocity real(SCALAR_KIND) :: levelsetLoc, levelsetWidth, levelsetAmp, levelsetPeriod real(SCALAR_KIND), dimension(:,:), allocatable :: ibmDissipation, nDotGradRho, uDotGradRho + logical :: ibmPatchExists = .false. SCALAR_TYPE, dimension(:,:), pointer :: dummyFunction => null() diff --git a/src/ImmersedBoundaryImpl.f90 b/src/ImmersedBoundaryImpl.f90 index adc83dd9..e6c8bf22 100644 --- a/src/ImmersedBoundaryImpl.f90 +++ b/src/ImmersedBoundaryImpl.f90 @@ -299,6 +299,8 @@ subroutine updateIBMVariables(this, mode, grid, simulationFlags) return end if + if (.not. this%ibmPatchExists) return + assert(size(this%levelset, 1) == size(this%conservedVariables, 1)) assert(size(this%levelset, 2) == 1) diff --git a/src/RegionImpl.f90 b/src/RegionImpl.f90 index 2f7f322d..49edd07a 100644 --- a/src/RegionImpl.f90 +++ b/src/RegionImpl.f90 @@ -2051,6 +2051,8 @@ subroutine connectLevelsetFactory(this) ! <<< Derived types >>> use Region_mod, only : t_Region + use Patch_mod, only : t_Patch + use ImmersedBoundaryPatch_mod, only : t_ImmersedBoundaryPatch use LevelsetFactory_mod, only : t_LevelsetFactory use SinusoidalWallLevelset_mod, only : t_SinusoidalWallLevelset @@ -2064,7 +2066,31 @@ subroutine connectLevelsetFactory(this) ! <<< Local variables >>> character(len = STRING_LENGTH) :: levelsetType + integer :: i, j + class(t_Patch), pointer :: patch => null() + + ! Determine whether IBM is actually used in each state. + do i = 1, size(this%states) + this%states(i)%ibmPatchExists = .false. + end do + + if (allocated(this%patchFactories)) then + do i = 1, size(this%states) + do j = 1, size(this%patchFactories) + call this%patchFactories(j)%connect(patch) + if (.not. associated(patch)) cycle + if (patch%gridIndex /= this%grids(i)%index) cycle + + select type (patch) + class is (t_ImmersedBoundaryPatch) + this%states(i)%ibmPatchExists = .true. + exit + end select + end do ! j = 1, size(this%patchFactories) + end do ! i = 1, size(this%states) + end if + ! Determine levelset type. call getRequiredOption("immersed_boundary/levelset_type", levelsetType, this%comm) this%levelsetType = levelsetType diff --git a/src/SinusoidalWallLevelsetImpl.f90 b/src/SinusoidalWallLevelsetImpl.f90 index 66d37730..727e165f 100644 --- a/src/SinusoidalWallLevelsetImpl.f90 +++ b/src/SinusoidalWallLevelsetImpl.f90 @@ -104,6 +104,8 @@ subroutine updateSinusoidalWallLevelset(this, mode, grids, states) timeDerivativeFactor = 2.0_wp * pi / this%levelsetPeriod * cos(2.0_wp * pi * states(1)%time / this%levelsetPeriod) do i = 1, size(states) + if (.not. states(i)%ibmPatchExists) cycle + assert(size(states(i)%levelset, 1) == size(states(i)%conservedVariables, 1)) assert(size(states(i)%levelset, 2) == 1) assert(size(states(i)%levelset, 1) == size(this%wallShapes(i)%buffer))