Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor force implementation #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions source/bc/mus_bc_fluid_turbulent_module.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
!! in [[tem_bc_module]].
!!
module mus_bc_fluid_turbulent_module
use iso_c_binding, only: c_f_pointer

! include treelm modules
use env_module, only: rk, long_k
use tem_param_module, only: cs2inv, cs2, rho0, rho0Inv, cs4inv, &
Expand Down
2 changes: 0 additions & 2 deletions source/compute/mus_compute_Poisson_module.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
!! $$G = -\frac{-2 c_{\infty} N_A z e}{\epsilon_r \epsilon_0}
!! sinh(\frac{z e }{k_b T}\phi) $$
module mus_compute_Poisson_module
use iso_c_binding, only: c_f_pointer

! include treelm modules
use env_module, only: rk
use tem_varSys_module, only: tem_varSys_type
Expand Down
68 changes: 40 additions & 28 deletions source/compute/mus_compute_d2q9_module.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ subroutine bgk_Regularized_d2q9 ( fieldProp, inState, outState, auxField, &
! indeces
integer :: iElem, iDir
! temporary distribution variables
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3)
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3), force(3)
real(kind=rk) :: rho, u_x, u_y, a12xx, a12xy, a12yy
real(kind=rk) :: omega, cmpl_o, feq(QQ), f1(QQ)
integer :: denspos, velpos(3), elemOff, nScalars
Expand All @@ -1068,6 +1068,9 @@ subroutine bgk_Regularized_d2q9 ( fieldProp, inState, outState, auxField, &

nScalars = varSys%nScalars

! convert force from physical to lattice
force = fieldProp(1)%fluid%force_phy / params%physics%fac(level)%body_force

!$omp do schedule(static)
!NEC$ ivdep
!DIR$ NOVECTOR
Expand All @@ -1086,11 +1089,11 @@ subroutine bgk_Regularized_d2q9 ( fieldProp, inState, outState, auxField, &
u_y = auxField(elemOff + velpos(2))

! non equilibrium second-order moments
! SOM_neq = SOM - SOM_eq
! SOM_neq = SOM - SOM_eq + 0.5Fcc
SOM = secondMom_2D(layout%fStencil%cxcx, f, layout%fStencil%QQ)
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x))
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y))
SOM_neq(3) = SOM(3) - rho * u_x * u_y
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x)) + u_x * force(1)
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y)) + u_y * force(2)
SOM_neq(3) = SOM(3) - rho * u_x * u_y + div1_2 * (u_y * force(1) + u_x * force(2))

! Hermitian coefficients
omega = fieldProp(1)%fluid%viscKine%omLvl(level)%val(iElem)
Expand Down Expand Up @@ -1149,7 +1152,7 @@ subroutine bgk_RecursiveRegularized_d2q9 ( fieldProp, inState, outState, auxFiel
! indeces
integer :: iElem, iDir
! temporary distribution variables
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3)
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3), force(3)
real(kind=rk) :: rho, u_x, u_y, a12xx, a12xy, a12yy
real(kind=rk) :: omega, cmpl_o, feq(QQ), f1(QQ)
integer :: denspos, velpos(3), elemOff, nScalars
Expand All @@ -1166,6 +1169,9 @@ subroutine bgk_RecursiveRegularized_d2q9 ( fieldProp, inState, outState, auxFiel

nScalars = varSys%nScalars

! convert force from physical to lattice
force = fieldProp(1)%fluid%force_phy / params%physics%fac(level)%body_force

!$omp do schedule(static)
!NEC$ ivdep
!DIR$ NOVECTOR
Expand All @@ -1184,11 +1190,11 @@ subroutine bgk_RecursiveRegularized_d2q9 ( fieldProp, inState, outState, auxFiel
u_y = auxField(elemOff + velpos(2))

! non equilibrium second-order moments
! SOM_neq = SOM - SOM_eq
! SOM_neq = SOM - SOM_eq + 0.5Fcc
SOM = secondMom_2D(layout%fStencil%cxcx, f, layout%fStencil%QQ)
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x))
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y))
SOM_neq(3) = SOM(3) - rho * u_x * u_y
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x)) + u_x * force(1)
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y)) + u_y * force(2)
SOM_neq(3) = SOM(3) - rho * u_x * u_y + div1_2 * (u_y * force(1) + u_x * force(2))

! Hermitian coefficients
omega = fieldProp(1)%fluid%viscKine%omLvl(level)%val(iElem)
Expand Down Expand Up @@ -1384,7 +1390,7 @@ subroutine bgk_HybridRecursiveRegularized_d2q9( fieldProp, inState, outState, &
! Self-describing variables, loop indices, etc.
integer :: iElem, iDir
! Temporary distribution variables
real(kind=rk) :: pdfTmp(QQ)
real(kind=rk) :: pdfTmp(QQ), force(3)
!symmetric strain rate tensor (SR) and it's trace (tr)
real(kind=rk) :: SR(3)!TODO::, tr_SR
! Velocity gradient
Expand Down Expand Up @@ -1427,6 +1433,9 @@ subroutine bgk_HybridRecursiveRegularized_d2q9( fieldProp, inState, outState, &
! Sigma value
sigma = fieldProp(1)%fluid%HRR_sigma

! convert force from physical to lattice
force = fieldProp(1)%fluid%force_phy / params%physics%fac(level)%body_force

!$omp do schedule(static)
!NEC$ ivdep
!DIR$ NOVECTOR
Expand Down Expand Up @@ -1468,13 +1477,11 @@ subroutine bgk_HybridRecursiveRegularized_d2q9( fieldProp, inState, outState, &
SR(3) = gradU(1, 2, 1) + gradU(2, 1, 1) !S_XY

! Determine the non-equilibrium second-order moments via
! SOM_neq = SOM - SOM_eq
! First, get the second-order moments
! SOM_neq = SOM - SOM_eq + 0.5Fcc
SOM = secondMom_2D(layout%fStencil%cxcx, pdfTmp, layout%fStencil%QQ)
! Second, subtract it's equilibrium: SOM_eq = rho*(cs²+u²)
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x))
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y))
SOM_neq(3) = SOM(3) - rho * u_x * u_y
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x)) + u_x * force(1)
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y)) + u_y * force(2)
SOM_neq(3) = SOM(3) - rho * u_x * u_y + div1_2 * (u_y * force(1) + u_x * force(2))

! Hermitian coefficients
! Relaxation parameter
Expand Down Expand Up @@ -1553,7 +1560,7 @@ subroutine bgk_HybridRecursiveRegularizedCorr_d2q9( fieldProp, inState, outState
! Self-describing variables, loop indices, etc.
integer :: iElem, iDir
! Temporary distribution variables
real(kind=rk) :: pdfTmp(QQ)
real(kind=rk) :: pdfTmp(QQ), force(3)
!symmetric strain rate tensor (SR) and it's trace (tr)
real(kind=rk) :: SR(3)!TODO::, tr_SR
! Velocity gradient
Expand Down Expand Up @@ -1597,6 +1604,9 @@ subroutine bgk_HybridRecursiveRegularizedCorr_d2q9( fieldProp, inState, outState
! standard value is 0.98
sigma = fieldProp(1)%fluid%HRR_sigma

! convert force from physical to lattice
force = fieldProp(1)%fluid%force_phy / params%physics%fac(level)%body_force

! allocate internalSource element array
do iSrc = 1, scheme%field(1)%internalSource%varDict%nVals
if ( trim(scheme%field(1)%internalSource%varDict%val(iSrc)%key) == 'hrr_correction' ) exit
Expand Down Expand Up @@ -1652,7 +1662,6 @@ subroutine bgk_HybridRecursiveRegularizedCorr_d2q9( fieldProp, inState, outState
& weight = layout%weight(:), &
& gradRHOU3 = gradRHOU3(:, 1), &
& phi = S_corr(:), &
& dens = HRR_Corr%dens(iElem), &
& vel = HRR_Corr%vel(iElem,:) )

! Calculate symmetric strain rate tensor (SR) and it's trace (tr)
Expand All @@ -1664,15 +1673,15 @@ subroutine bgk_HybridRecursiveRegularizedCorr_d2q9( fieldProp, inState, outState
SR(3) = gradU(1, 2, 1) + gradU(2, 1, 1) !S_XY

! Determine the non-equilibrium second-order moments via
! SOM_neq = SOM - SOM_eq
! SOM_neq = SOM - SOM_eq + 0.5Fcc
! Apply correction
pdfTmp(:) = pdfTmp(:) + 0.5_rk * S_corr(:)
! First, get the second-order moments
SOM = secondMom_2D(layout%fStencil%cxcx, pdfTmp, layout%fStencil%QQ)
! Second, subtract it's equilibrium: SOM_eq = rho*(cs²+u²)
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x))
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y))
SOM_neq(3) = SOM(3) - rho * u_x * u_y
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x)) + u_x * force(1)
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y)) + u_y * force(2)
SOM_neq(3) = SOM(3) - rho * u_x * u_y + div1_2 * (u_y * force(1) + u_x * force(2))

! Hermitian coefficients
! Relaxation parameter
Expand Down Expand Up @@ -1740,7 +1749,7 @@ end subroutine bgk_HybridRecursiveRegularizedCorr_d2q9
! indeces
integer :: iElem, iDir
! temporary distribution variables
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3)
real(kind=rk) :: f( QQ ), SOM(3), SOM_neq(3), force(3)
real(kind=rk) :: rho, u_x, u_y, a12xx, a12xy, a12yy
real(kind=rk) :: omega, tau, tauN, CoefTauNTau
real(kind=rk) :: feq(QQ), f1(QQ), f_temp
Expand All @@ -1760,6 +1769,9 @@ end subroutine bgk_HybridRecursiveRegularizedCorr_d2q9
nScalars = varSys%nScalars

tauN = fieldProp(1)%fluid%DRT_tauN

! convert force from physical to lattice
force = fieldProp(1)%fluid%force_phy / params%physics%fac(level)%body_force

!$omp do schedule(static)
!NEC$ ivdep
Expand All @@ -1778,11 +1790,11 @@ end subroutine bgk_HybridRecursiveRegularizedCorr_d2q9
u_y = auxField(elemOff + velpos(2))

! non equilibrium second-order moments
! SOM_neq = SOM - SOM_eq
! SOM_neq = SOM - SOM_eq + 0.5Fcc
SOM = secondMom_2D(layout%fStencil%cxcx, f, layout%fStencil%QQ)
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x))
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y))
SOM_neq(3) = SOM(3) - rho * u_x * u_y
SOM_neq(1) = SOM(1) - rho * (cs2 + (u_x * u_x)) + u_x * force(1)
SOM_neq(2) = SOM(2) - rho * (cs2 + (u_y * u_y)) + u_y * force(2)
SOM_neq(3) = SOM(3) - rho * u_x * u_y + div1_2 * (u_y * force(1) + u_x * force(2))

!Relaxation coefficients
! remains constant on uniform mesh. Does loop over elements include voxels off different size?
Expand Down
Loading