Energy balance
Local variables to be added
The following local variables need to be defined for the examples in this section:
integer iel , ifac , ivar
integer iel1 , iel2 , ieltsm
integer iortho
integer inc , iccocg
integer nswrgp , imligp , iwarnp
integer ipcvst , iflmas , iflmab , ipccp, ipcvsl
integer iscal
integer ncesmp
integer ilelt , nlelt
double precision xrtpa , xrtp
double precision xbilan , xbilvl , xbilpa , xbilpt
double precision xbilsy , xbilen , xbilso , xbildv
double precision xbilmi , xbilma
double precision epsrgp , climgp , extrap
double precision xfluxf , xgamma
double precision diipbx, diipby, diipbz, distbr
double precision visct, flumab , xcp , xvsl, ctb1, ctb2
integer, allocatable, dimension(:) :: lstelt
double precision, dimension(:), pointer :: coefap, coefbp, cofafp, cofbfp
double precision, allocatable, dimension(:,:) :: grad
double precision, allocatable, dimension(:) :: treco
double precision, dimension(:), pointer :: imasfl, bmasfl
double precision, dimension(:), pointer :: crom
Initialization and finalization
The following initialization block needs to be added for the following examples:
Ad the end of the subroutine, it is recommended to deallocate the work array:
In theory Fortran 95 deallocates locally-allocated arrays automatically, but deallocating arrays in a symmetric manner to their allocation is good practice, and it avoids using a different logic for C and Fortran.
Body
This example computes energy balance relative to temperature We assume that we want to compute balances (convective and diffusive) at the boundaries of the calculation domain represented below (with boundaries marked by colors).
The scalar considered if the temperature. We will also use the specific heat (to obtain balances in Joules)
Domain and associated boundary colors:
- 2, 4, 7 : adiabatic walls
- 6 : wall with fixed temperature
- 3 : inlet
- 5 : outlet
- 1 : symmetry
To ensure calculations have physical meaning, it is best to use a spatially uniform time step (idtvar = 0 or 1). In addition, when restarting a calculation, the balance is incorrect if inpdt0 = 1 (visct not initialized and t(n-1) not known)
Temperature variable
- ivar = isca(iscalt) (use rtp(iel, ivar))
Boundary coefficients coefap/coefbp are those of ivarfl(ivar)
The balance at time step n is equal to:
The first term is negative if the amount of energy in the volume Here is the list of examples dedicated to different physics: has decreased (it is 0 in a steady regime).
The other terms (convection, diffusion) are positive if the amount of energy in the volume has increased due to boundary conditions.
In a steady regime, a positive balance thus indicates an energy gain.
With
(rom
) calculated using the density law from the usphyv subroutine, for example:
where
is rr
and
is tkelv
.
and
may vary.
Here is the corresponding code:
xbilvl = 0.d0
xbildv = 0.d0
xbilpa = 0.d0
xbilpt = 0.d0
xbilsy = 0.d0
xbilen = 0.d0
xbilso = 0.d0
xbilmi = 0.d0
xbilma = 0.d0
xbilan = 0.d0
else
ipccp = 0
endif
else
ipcvsl = 0
endif
if (ipccp.gt.0) then
endif
endif
iortho = 0
if (iortho.eq.0) then
inc = 1
iccocg = 1
(
ivarfl(ivar), 0,
imrgra, inc, iccocg, nswrgp, iwarnp, imligp, &
epsrgp, climgp, extrap, grad)
treco(ifac) = rtp(iel,ivar) &
+ diipbx*grad(1,iel) &
+ diipby*grad(2,iel) &
+ diipbz*grad(3,iel)
enddo
deallocate(grad)
else
treco(ifac) = rtp(iel,ivar)
enddo
endif
if (ipccp.gt.0) then
xrtpa = rtpa(iel,ivar)
xrtp = rtp(iel,ivar)
xbilvl = xbilvl &
+
volume(iel) * propce(iel,ipccp) * crom(iel) &
* (xrtpa - xrtp)
enddo
else
xrtpa = rtpa(iel,ivar)
xrtp = rtp(iel,ivar)
xbilvl = xbilvl &
+
volume(iel) *
cp0 * crom(iel) * (xrtpa - xrtp)
enddo
endif
if (ipccp.gt.0) then
ctb1 = imasfl(ifac)*propce(iel1,ipccp)*rtp(iel1,ivar)
else
ctb1 = 0d0
endif
ctb2 = imasfl(ifac)*propce(iel2,ipccp)*rtp(iel2,ivar)
else
ctb2 = 0d0
endif
xbildv = xbildv + (dt(iel1)*ctb1 - dt(iel2)*ctb2)
enddo
xbildv = xbildv + dt(iel) * propce(iel,ipccp) &
* bmasfl(ifac) &
* rtp(iel,ivar)
enddo
else
ctb1 = imasfl(ifac)*
cp0*rtp(iel1,ivar)
else
ctb1 = 0d0
endif
ctb2 = imasfl(ifac)*
cp0*rtp(iel2,ivar)
else
ctb2 = 0d0
endif
xbildv = xbildv + (dt(iel1) + dt(iel2))*0.5d0*(ctb1 - ctb2)
enddo
xbildv = xbildv + dt(iel) *
cp0 &
* bmasfl(ifac) &
* rtp(iel,ivar)
enddo
endif
if (ncesmp.gt.0) then
do ieltsm = 1, ncesmp
xrtp = rtp(iel,ivar)
if (ipccp.gt.0) then
xbildv = xbildv &
-
volume(iel) * propce(iel,ipccp) * dt(iel) &
* xgamma * xrtp
else
xbildv = xbildv &
-
volume(iel) *
cp0 * dt(iel) * xgamma * xrtp
endif
enddo
endif
call
getfbr(
'2 or 4 or 7', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
visct = propce(iel,ipcvst)
flumab = bmasfl(ifac)
if (ipccp.gt.0) then
xcp = propce(iel,ipccp)
else
endif
if (ipcvsl.gt.0) then
xvsl = propce(iel,ipcvsl)
else
endif
xfluxf = -
surfbn(ifac) * dt(iel) * xcp &
* (cofafp(ifac) + cofbfp(ifac)*treco(ifac)) &
- flumab * dt(iel) * xcp &
* (coefap(ifac) + coefbp(ifac)*treco(ifac))
xbilpa = xbilpa + xfluxf
enddo
call
getfbr(
'6', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
visct = propce(iel,ipcvst)
flumab = bmasfl(ifac)
if (ipccp.gt.0) then
xcp = propce(iel,ipccp)
else
endif
if (ipcvsl.gt.0) then
xvsl = propce(iel,ipcvsl)
else
endif
xfluxf = -
surfbn(ifac) * dt(iel) * xcp &
* (cofafp(ifac) + cofbfp(ifac)*treco(ifac)) &
- flumab * dt(iel) * xcp &
* (coefap(ifac) + coefbp(ifac)*treco(ifac))
xbilpt = xbilpt + xfluxf
enddo
call
getfbr(
'1', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
visct = propce(iel,ipcvst)
flumab = bmasfl(ifac)
if (ipccp.gt.0) then
xcp = propce(iel,ipccp)
else
endif
if (ipcvsl.gt.0) then
xvsl = propce(iel,ipcvsl)
else
endif
xfluxf = -
surfbn(ifac) * dt(iel) * xcp &
* (cofafp(ifac) + cofbfp(ifac)*treco(ifac)) &
- flumab * dt(iel) * xcp &
* (coefap(ifac) + coefbp(ifac)*treco(ifac))
xbilsy = xbilsy + xfluxf
enddo
call
getfbr(
'3', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
visct = propce(iel,ipcvst)
flumab = bmasfl(ifac)
if (ipccp.gt.0) then
xcp = propce(iel,ipccp)
else
endif
if (ipcvsl.gt.0) then
xvsl = propce(iel,ipcvsl)
else
endif
xfluxf = -
surfbn(ifac) * dt(iel) * xcp &
* (cofafp(ifac) + cofbfp(ifac)*treco(ifac)) &
- flumab * dt(iel) * xcp &
* (coefap(ifac) + coefbp(ifac)*treco(ifac))
xbilen = xbilen + xfluxf
enddo
call
getfbr(
'5', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
visct = propce(iel,ipcvst)
flumab = bmasfl(ifac)
if (ipccp.gt.0) then
xcp = propce(iel,ipccp)
else
endif
if (ipcvsl.gt.0) then
xvsl = propce(iel,ipcvsl)
else
endif
xfluxf = -
surfbn(ifac) * dt(iel) * xcp &
* (cofafp(ifac) + cofbfp(ifac)*treco(ifac)) &
- flumab * dt(iel) * xcp &
* (coefap(ifac) + coefbp(ifac)*treco(ifac))
xbilso = xbilso + xfluxf
enddo
deallocate(treco)
if (ncesmp.gt.0) then
do ieltsm = 1, ncesmp
if (
itypsm(ieltsm,ivar).eq.0 .or. xgamma.lt.0.d0)
then
xrtp = rtp(iel,ivar)
else
endif
if (ipccp.gt.0) then
if (xgamma.lt.0.d0) then
xbilma = xbilma &
+
volume(iel) * propce(iel,ipccp) * dt(iel) * xgamma * xrtp
else
xbilmi = xbilmi &
+
volume(iel) * propce(iel,ipccp) * dt(iel) * xgamma * xrtp
endif
else
if (xgamma.lt.0.d0) then
xbilma = xbilma &
+
volume(iel) *
cp0 * dt(iel) * xgamma * xrtp
else
xbilmi = xbilmi &
+
volume(iel) *
cp0 * dt(iel) * xgamma * xrtp
endif
endif
enddo
endif
endif
xbilan = xbilvl + xbildv + xbilpa + xbilpt + xbilsy + xbilen &
+ xbilso + xbilmi + xbilma
ntcabs, xbilvl, xbildv, xbilpa, xbilpt, xbilsy, xbilen, xbilso, &
xbilmi, xbilma, xbilan
2000 format &
(/, &
3x,'** Thermal balance **', /, &
3x,' ---------------', /, &
'---', '------', &
'------------------------------------------------------------', /, &
'bt ',' Iter', &
' Volume Divergence Adia Wall Fixed_T Wall Symmetry', &
' Inlet Outlet Inj. Mass. Suc. Mass. Total', /, &
'bt ', i6, 10e12.4, /, &
'---','------', &
'------------------------------------------------------------')
endif