Skip to content

Commit 566971c

Browse files
Merge pull request #295 from loganoz/293-acoustics-save-lamb-vector-from-flow-simulations-and-read-it-from-acoustics-solver
293 acoustics save lamb vector from flow simulations and read it from acoustics solver
2 parents f0ef368 + c001189 commit 566971c

9 files changed

Lines changed: 405 additions & 33 deletions

File tree

Solver/src/NavierStokesSolver/main.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PROGRAM HORSES3DMainNS
3434
TYPE( FTValueDictionary) :: controlVariables
3535
TYPE( DGSem ) :: sem
3636
TYPE( TimeIntegrator_t ) :: timeIntegrator
37-
LOGICAL :: success, saveGradients, saveSensor, saveLES, saveSource
37+
LOGICAL :: success, saveGradients, saveSensor, saveLES, saveSource, saveLambVector
3838
logical :: generateMonitor = .TRUE.
3939
logical :: optimizePartitionLevel=.FALSE.
4040
logical :: isMLRK=.FALSE.
@@ -204,7 +204,8 @@ PROGRAM HORSES3DMainNS
204204
saveSensor = controlVariables % logicalValueForKey(saveSensorToSolutionKey)
205205
saveLES = controlVariables % logicalValueForKey(saveLESToSolutionKey)
206206
saveSource = controlVariables % logicalValueForKey(saveSourceToSolutionKey)
207-
CALL sem % mesh % SaveSolution(sem % numberOfTimeSteps, timeIntegrator % time, solutionFileName, saveGradients, saveSensor, saveLES, saveSource)
207+
saveLambVector = controlVariables % logicalValueForKey(saveLambVectorToSolutionKey)
208+
CALL sem % mesh % SaveSolution(sem % numberOfTimeSteps, timeIntegrator % time, solutionFileName, saveGradients, saveSensor, saveLES, saveSource, saveLambVector)
208209
if ( sem % particles % active ) then
209210
call sem % particles % ExportToVTK ( sem % numberOfTimeSteps, sem % monitors % solution_file )
210211
end if

Solver/src/libs/foundation/Setup.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Module mainKeywordsModule
1010
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: restartFileNameKey = "restart file name"
1111
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: solutionFileNameKey = "solution file name"
1212
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: saveGradientsToSolutionKey = "save gradients with solution"
13+
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: saveLambVectorToSolutionKey = "save lamb vector"
1314
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: saveSensorToSolutionKey = "save sensor with solution"
1415
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: saveLESToSolutionKey = "save les with solution"
1516
CHARACTER(LEN=KEYWORD_LENGTH), PARAMETER :: saveSourceToSolutionKey = "save source with solution"

Solver/src/libs/mesh/HexMesh.f90

Lines changed: 285 additions & 11 deletions
Large diffs are not rendered by default.

Solver/src/libs/mesh/MappedGeometry.f90

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Module MappedGeometryClass
99
private
1010
public MappedGeometry, MappedGeometryFace
1111
public SetMappingsToCrossProduct
12-
public vDot, vCross
12+
public vDot, vCross, ComputeVorticity
1313
!
1414
! ---------
1515
! Constants
@@ -860,5 +860,19 @@ end subroutine SetMappingsToCrossProduct
860860
!
861861
!///////////////////////////////////////////////////////////////////////////////
862862
!
863+
pure subroutine ComputeVorticity(U_x, U_y, U_z, vorticity)
863864

865+
real(kind=RP), intent(in) :: U_x(3)
866+
real(kind=RP), intent(in) :: U_y(3)
867+
real(kind=RP), intent(in) :: U_z(3)
868+
real(kind=RP), intent(out) :: vorticity(3)
869+
870+
vorticity(1) = U_y(3) - U_z(2)
871+
vorticity(2) = U_z(1) - U_x(3)
872+
vorticity(3) = U_x(2) - U_y(1)
873+
874+
end subroutine ComputeVorticity
875+
!
876+
!///////////////////////////////////////////////////////////////////////////////
877+
!
864878
END Module MappedGeometryClass

Solver/src/libs/mesh/StorageClass.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module StorageClass
9494
#endif
9595
#ifdef ACOUSTIC
9696
real(kind=RP), allocatable :: Qbase(:,:,:,:) ! Base flow State vector
97+
real(kind=RP), allocatable :: Lambbase(:,:,:,:) ! Lamb vector base
98+
real(kind=RP), allocatable :: Lamb_NS(:,:,:,:) ! Lamb vector from NS
9799
#endif
98100
#ifdef CAHNHILLIARD
99101
real(kind=RP), dimension(:,:,:,:), allocatable :: c ! CHE concentration
@@ -195,6 +197,8 @@ module StorageClass
195197
real(kind=RP), dimension(:,:), allocatable :: wallNodeDistance ! for BC walls, distance to the first fluid node
196198
#ifdef ACOUSTIC
197199
real(kind=RP), dimension(:,:,:), allocatable :: Qbase ! Base flow State vector
200+
real(kind=RP), dimension(:,:,:), allocatable :: Lambbase ! Lamb vector base
201+
real(kind=RP), dimension(:,:,:), allocatable :: Lamb_NS ! Lamb vector
198202
#endif
199203
#ifdef MULTIPHASE
200204
real(kind=RP), dimension(:,:), allocatable :: invMa2
@@ -813,6 +817,8 @@ elemental subroutine ElementStorage_Construct(self, Nx, Ny, Nz, computeGradients
813817
#endif
814818
#if defined (ACOUSTIC)
815819
ALLOCATE( self % Qbase (NCONSB,0:Nx,0:Ny,0:Nz) )
820+
ALLOCATE( self % Lambbase (NDIM,0:Nx,0:Ny,0:Nz) )
821+
ALLOCATE( self % Lamb_NS (NDIM,0:Nx,0:Ny,0:Nz) )
816822
#endif
817823
if (computeGradients) then
818824
ALLOCATE( self % U_xNS (NGRAD,0:Nx,0:Ny,0:Nz) )
@@ -893,6 +899,8 @@ elemental subroutine ElementStorage_Construct(self, Nx, Ny, Nz, computeGradients
893899
#endif
894900
#if defined (ACOUSTIC)
895901
self % Qbase = 0.0_RP
902+
self % Lambbase = 0.0_RP
903+
self % Lamb_NS = 0.0_RP
896904
#endif
897905
if (computeGradients) then
898906
self % U_xNS = 0.0_RP
@@ -1002,6 +1010,8 @@ elemental subroutine ElementStorage_Assign(to, from)
10021010
#endif
10031011
#if defined (ACOUSTIC)
10041012
to % Qbase = from % Qbase
1013+
to % Lambbase = from % Lambbase
1014+
to % Lamb_NS = from % Lamb_NS
10051015
#endif
10061016

10071017
#ifndef ACOUSTIC
@@ -1098,6 +1108,8 @@ elemental subroutine ElementStorage_Destruct(self)
10981108
#endif
10991109
#if defined (ACOUSTIC)
11001110
safedeallocate(self % Qbase)
1111+
safedeallocate(self % Lambbase)
1112+
safedeallocate(self % Lamb_NS)
11011113
#endif
11021114

11031115
if (self % computeGradients) then
@@ -1407,6 +1419,8 @@ pure subroutine FaceStorage_Construct(self, NDIM, Nf, Nel, computeGradients, ana
14071419
end if
14081420
#if defined (ACOUSTIC)
14091421
ALLOCATE( self % Qbase (NCONSB,0:Nf(1),0:Nf(2)) )
1422+
ALLOCATE( self % Lambbase (NDIM,0:Nf(1),0:Nf(2)) )
1423+
ALLOCATE( self % Lamb_NS (NDIM,0:Nf(1),0:Nf(2)) )
14101424
#endif
14111425
! Biggest Interface flux memory size is u\vec{n}
14121426
! ----------------------------------------------
@@ -1470,6 +1484,8 @@ pure subroutine FaceStorage_Construct(self, NDIM, Nf, Nel, computeGradients, ana
14701484
end if
14711485
#if defined (ACOUSTIC)
14721486
self % Qbase = 0.0_RP
1487+
self % Lambbase = 0.0_RP
1488+
self % Lamb_NS = 0.0_RP
14731489
#endif
14741490

14751491
self % rho = 0.0_RP
@@ -1568,6 +1584,8 @@ elemental subroutine FaceStorage_Destruct(self)
15681584
safedeallocate(self % rho )
15691585
#if defined (ACOUSTIC)
15701586
safedeallocate(self % Qbase )
1587+
safedeallocate(self % Lambbase )
1588+
safedeallocate(self % Lamb_NS )
15711589
#endif
15721590

15731591
self % anJacobian = .FALSE.
@@ -1732,6 +1750,8 @@ elemental subroutine FaceStorage_Assign(to, from)
17321750
to % QNS = from % QNS
17331751
#if defined (ACOUSTIC)
17341752
to % Qbase = from % Qbase
1753+
to % Lambbase = from % Lambbase
1754+
to % Lamb_NS = from % Lamb_NS
17351755
#endif
17361756
if (to % computeGradients) then
17371757
to % U_xNS = from % U_xNS

Solver/src/libs/monitors/Monitors.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ subroutine Monitors_Construct( Monitors, mesh, controlVariables )
8484
character(len=STR_LEN_MONITORS) :: line
8585
character(len=STR_LEN_MONITORS) :: solution_file
8686
logical, save :: FirstCall = .TRUE.
87-
logical :: saveGradients
87+
logical :: saveGradients, saveLambVector
8888
logical :: monitorMem =.FALSE.
8989
!
9090
! Setup the buffer
@@ -147,7 +147,8 @@ subroutine Monitors_Construct( Monitors, mesh, controlVariables )
147147

148148
#if defined(NAVIERSTOKES) || defined(INCNS)
149149
saveGradients = controlVariables % logicalValueForKey(saveGradientsToSolutionKey)
150-
call Monitors % stats % Construct(mesh, saveGradients)
150+
saveLambVector = controlVariables % logicalValueForKey(saveLambVectorToSolutionKey)
151+
call Monitors % stats % Construct(mesh, saveGradients, saveLambVector)
151152

152153

153154
allocate ( Monitors % surfaceMonitors ( Monitors % no_of_surfaceMonitors ) )

Solver/src/libs/monitors/StatisticsMonitor.f90

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module StatisticsMonitor
5151
real(kind=RP) :: starting_time
5252
integer :: no_of_samples
5353
logical :: saveGradients
54+
logical :: saveLambVector
5455
contains
5556
procedure :: Construct => StatisticsMonitor_Construct
5657
procedure :: Update => StatisticsMonitor_Update
@@ -67,23 +68,23 @@ module StatisticsMonitor
6768
!
6869
!//////////////////////////////////////////////////////////////////////////////////
6970
!
70-
subroutine StatisticsMonitor_Construct(self, mesh, saveGradients)
71+
subroutine StatisticsMonitor_Construct(self, mesh, saveGradients, saveLambVector)
7172
use ParamfileRegions
7273
use PhysicsStorage, only: NCONS, NGRAD
73-
use HexMeshClass, only: no_of_stats_variables
7474
implicit none
7575
class(StatisticsMonitor_t) :: self
7676
class(HexMesh) :: mesh
77-
logical, intent(in) :: saveGradients
77+
logical, intent(in) :: saveGradients, saveLambVector
7878
integer, allocatable :: Nsample, i0, Ndump, Nreset
7979
real(kind=RP), allocatable :: t0
8080
integer :: eID
8181
character(len=LINE_LENGTH) :: paramFile
8282

8383
NO_OF_VARIABLES = NO_OF_VARIABLES_Sij + NCONS
8484
self % saveGradients = saveGradients
85+
self % saveLambVector = saveLambVector
8586
if (saveGradients) NO_OF_VARIABLES = NO_OF_VARIABLES + NGRAD * NDIM
86-
no_of_stats_variables = NO_OF_VARIABLES
87+
if (saveLambVector) NO_OF_VARIABLES = NO_OF_VARIABLES + NDIM
8788
!
8889
! Search for the parameters in the case file
8990
! ------------------------------------------
@@ -168,7 +169,11 @@ subroutine StatisticsMonitor_WriteFile(self, mesh, iter, t, solution_file)
168169
character(len=LINE_LENGTH) :: fileName
169170

170171
write(fileName,'(A,A)') trim(solution_file),'.stats.hsol'
171-
if ( self % state .ne. OFF) call mesh % SaveStatistics(iter, t, trim(fileName), self % saveGradients)
172+
if ( self % state .ne. OFF) then
173+
call mesh % SaveStatistics(iter, t, trim(fileName), self % saveGradients)
174+
write(fileName,'(A,A)') trim(solution_file),'.Lamb.stats.hsol'
175+
if (self % saveLambVector) call mesh % SaveLambVectorStatistics(iter, t, trim(fileName), self % saveGradients)
176+
end if
172177

173178
end subroutine StatisticsMonitor_WriteFile
174179

@@ -225,6 +230,7 @@ end subroutine StatisticsMonitor_Update
225230

226231
subroutine StatisticsMonitor_UpdateValues(self, mesh)
227232
use PhysicsStorage
233+
use MappedGeometryClass, only: vCross, ComputeVorticity
228234
implicit none
229235
class(StatisticsMonitor_t) :: self
230236
class(HexMesh) :: mesh
@@ -237,16 +243,23 @@ subroutine StatisticsMonitor_UpdateValues(self, mesh)
237243
integer :: i, j, k
238244
real(RP) :: ratio, inv_nsamples_plus_1
239245
real(RP) :: rfactor1, rfactor2
240-
integer, dimension(5) :: limits
246+
integer, dimension(6) :: limits
247+
real(kind=RP), dimension(NDIM) :: vorticity, velocity, LambVector
248+
real(kind=RP), pointer, contiguous :: U_x(:), U_y(:), U_z(:)
241249

242250

243251
#ifdef NAVIERSTOKES
244252
! if gradients are not saved, limits(2) is equal to limits(5), the latter wont be used
245253
limits(1) = NO_OF_VARIABLES_Sij + IRHO
246254
limits(2) = NO_OF_VARIABLES_Sij + NCONS
247-
limits(3) = NO_OF_VARIABLES_Sij + NCONS + NGRAD
248-
limits(4) = NO_OF_VARIABLES_Sij + NCONS + 2*NGRAD
249-
limits(5) = NO_OF_VARIABLES
255+
limits(3:6) = limits(2)
256+
if (self % saveGradients) then
257+
limits(3) = NO_OF_VARIABLES_Sij + NCONS + NGRAD ! U_x
258+
limits(4) = NO_OF_VARIABLES_Sij + NCONS + 2*NGRAD ! U_y
259+
limits(5) = NO_OF_VARIABLES_Sij + NCONS + NDIM * NGRAD ! U_z
260+
limits(6) = limits(5)
261+
end if
262+
if (self % saveLambVector) limits(6) = limits(5) + NDIM
250263

251264
inv_nsamples_plus_1 = 1.0_RP / (self % no_of_samples + 1)
252265
ratio = self % no_of_samples * inv_nsamples_plus_1
@@ -272,7 +285,18 @@ subroutine StatisticsMonitor_UpdateValues(self, mesh)
272285
data(limits(2)+1:limits(3),i,j,k) = data(limits(2)+1:limits(3),i,j,k) * ratio + e % storage % U_x(:,i,j,k) * inv_nsamples_plus_1
273286
data(limits(3)+1:limits(4),i,j,k) = data(limits(3)+1:limits(4),i,j,k) * ratio + e % storage % U_y(:,i,j,k) * inv_nsamples_plus_1
274287
data(limits(4)+1:limits(5),i,j,k) = data(limits(4)+1:limits(5),i,j,k) * ratio + e % storage % U_z(:,i,j,k) * inv_nsamples_plus_1
275-
end if
288+
end if
289+
! Save Lamb vector: u x w
290+
if (self % saveLambVector) then
291+
! Attention: qm in APE is -(w x u)'
292+
U_x => e % storage % U_x(:,i,j,k)
293+
U_y => e % storage % U_y(:,i,j,k)
294+
U_z => e % storage % U_z(:,i,j,k)
295+
call ComputeVorticity(U_x, U_y, U_z, vorticity)
296+
velocity = e % storage % Q(IRHOU:IRHOW,i,j,k) / e % storage % Q(IRHO,i,j,k)
297+
call vCross(velocity, vorticity, LambVector)
298+
data(limits(5)+1:limits(6),i,j,k) = data(limits(5)+1:limits(6),i,j,k) * ratio + LambVector * inv_nsamples_plus_1
299+
end if
276300
end do ; end do ; end do
277301

278302
end associate
@@ -283,9 +307,14 @@ subroutine StatisticsMonitor_UpdateValues(self, mesh)
283307
! if gradients are not saved, limits(2) is equal to limits(5), the latter wont be used
284308
limits(1) = NO_OF_VARIABLES_Sij + INSRHO
285309
limits(2) = NO_OF_VARIABLES_Sij + NCONS
286-
limits(3) = NO_OF_VARIABLES_Sij + NCONS + NGRAD
287-
limits(4) = NO_OF_VARIABLES_Sij + NCONS + 2*NGRAD
288-
limits(5) = NO_OF_VARIABLES
310+
limits(3:6) = limits(2)
311+
if (self % saveGradients) then
312+
limits(3) = NO_OF_VARIABLES_Sij + NCONS + NGRAD ! U_x
313+
limits(4) = NO_OF_VARIABLES_Sij + NCONS + 2*NGRAD ! U_y
314+
limits(5) = NO_OF_VARIABLES_Sij + NCONS + NDIM * NGRAD ! U_z
315+
limits(6) = limits(5)
316+
end if
317+
if (self % saveLambVector) limits(6) = limits(5) + NDIM
289318

290319
inv_nsamples_plus_1 = 1.0_RP / (self % no_of_samples + 1)
291320
ratio = self % no_of_samples * inv_nsamples_plus_1
@@ -312,6 +341,17 @@ subroutine StatisticsMonitor_UpdateValues(self, mesh)
312341
data(limits(3)+1:limits(4),i,j,k) = data(limits(3)+1:limits(4),i,j,k) * ratio + e % storage % U_y(:,i,j,k) * inv_nsamples_plus_1
313342
data(limits(4)+1:limits(5),i,j,k) = data(limits(4)+1:limits(5),i,j,k) * ratio + e % storage % U_z(:,i,j,k) * inv_nsamples_plus_1
314343
end if
344+
! Save Lamb vector: u x w
345+
if (self % saveLambVector) then
346+
! Attention: qm in APE is -(w x u)'
347+
U_x => e % storage % U_x(:,i,j,k)
348+
U_y => e % storage % U_y(:,i,j,k)
349+
U_z => e % storage % U_z(:,i,j,k)
350+
call ComputeVorticity(U_x, U_y, U_z, vorticity)
351+
velocity = e % storage % Q(INSRHOU:INSRHOW,i,j,k) / e % storage % Q(INSRHO,i,j,k)
352+
call vCross(velocity, vorticity, LambVector)
353+
data(limits(5)+1:limits(6),i,j,k) = data(limits(5)+1:limits(6),i,j,k) * ratio + LambVector * inv_nsamples_plus_1
354+
end if
315355
end do ; end do ; end do
316356

317357
end associate

Solver/src/libs/physics/navierstokes/PhysicsStorage_NS.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ MODULE PhysicsStorage_NS
145145
SUBROUTINE ConstructPhysicsStorage_NS( controlVariables, Lref, timeref, success )
146146
USE FTValueDictionaryClass
147147
USE Physics_NSKeywordsModule
148+
use mainKeywordsModule, only: saveLambVectorToSolutionKey
148149
use Utilities, only: toLower, almostEqual
149150
!
150151
! ---------
@@ -273,6 +274,14 @@ SUBROUTINE ConstructPhysicsStorage_NS( controlVariables, Lref, timeref, success
273274
end if
274275
end if
275276

277+
! If Lamb vector is requested, computeGradient should be enabled
278+
if (controlVariables % logicalValueForKey(saveLambVectorToSolutionKey)) then
279+
if (.not. computeGradients) then
280+
print *, trim(COMPUTE_GRADIENTS_KEY), " should be enabled to compute the Lamb vector."
281+
error stop
282+
end if
283+
end if
284+
276285
dimensionless_ % gammaM2 = thermodynamics_ % gamma * POW2( dimensionless_ % Mach )
277286
!
278287
! ********************

0 commit comments

Comments
 (0)