💻 Fortran Source Code Library

We currently offer 172 open-source, production-grade Fortran codes for offline testing. Run calculations locally on your own machine, view code structure, read technical explanations, and download compilation packages including sample input files.

Free Convection in Enclosures

Core Numerical Engine in Fortran 90 • 33 total downloads

enclosure_convection.f90
! =========================================================================
! Source File: enclosure_convection.f90
! =========================================================================

program enclosure_convection
  implicit none
  integer :: etype,ftype,i
  double precision :: Lg,Hh,Ww,Di,Do,Thot,Tcold
  double precision :: rho,mu,kf,Pr,cp,beta
  double precision :: Tf,dT,nu_v,alp,Ra,Nu,h_eff,Q,keff,Lc,HL,g
  double precision :: dTs,Ras,Nus,Qs
  double precision, parameter :: pi=3.14159265358979d0
  g=9.80665d0
  read(*,*) etype; read(*,*) Lg; read(*,*) Hh; read(*,*) Ww
  read(*,*) Di; read(*,*) Do
  read(*,*) Thot; read(*,*) Tcold
  read(*,*) ftype; read(*,*) rho; read(*,*) mu
  read(*,*) kf; read(*,*) Pr; read(*,*) cp; read(*,*) beta
  Tf=(Thot+Tcold)/2d0; dT=abs(Thot-Tcold)
  if(ftype==1) then
    rho=1.177d0;mu=1.85d-5;kf=0.0263d0;Pr=0.71d0;cp=1007d0;beta=1d0/(Tf+273.15d0)
  elseif(ftype==2) then
    rho=997d0;mu=8.9d-4;kf=0.613d0;Pr=6.13d0;cp=4180d0;beta=2.1d-4
  elseif(ftype==3) then
    rho=870d0;mu=0.05d0;kf=0.14d0;Pr=500d0;cp=2000d0;beta=7d-4
  endif
  nu_v=mu/rho; alp=kf/(rho*cp)
  Ra=g*beta*dT*Lg**3/(nu_v*alp)
  Nu=1d0; Q=0d0; keff=kf; Lc=Lg; HL=1d0
  select case(etype)
  case(1)
    HL=Hh/max(Lg,1d-6)
    if(HL<=2d0) then
      Nu=0.18d0*(Pr*Ra/(0.2d0+Pr))**0.29d0
    elseif(HL<=10d0) then
      Nu=0.22d0*(Pr*Ra/(0.2d0+Pr))**0.28d0*(HL)**(-0.25d0)
    else
      Nu=0.42d0*Ra**0.25d0*Pr**0.012d0*(HL)**(-0.3d0)
    endif
    if(Nu<1d0) Nu=1d0
    h_eff=Nu*kf/Lg; Q=h_eff*Hh*Ww*dT
  case(2)
    Nu=0.069d0*Ra**(1d0/3d0)*Pr**0.074d0
    if(Nu<1d0) Nu=1d0
    h_eff=Nu*kf/Lg; Q=h_eff*Hh*Ww*dT
  case(3)
    Nu=1d0; h_eff=kf/Lg; Q=h_eff*Hh*Ww*dT
  case(4)
    Lc=(Do-Di)/2d0
    Ra=g*beta*dT*Lc**3/(nu_v*alp)
    keff=0.386d0*kf*(Pr/(0.861d0+Pr))**0.25d0*Ra**0.25d0
    if(keff<kf) keff=kf
    Q=2d0*pi*keff*dT/log(Do/max(Di,1d-6))
    Nu=keff/kf; h_eff=Nu*kf/Lc
  case default
    Lc=(Do-Di)/2d0
    Ra=g*beta*dT*Lc**3/(nu_v*alp)
    keff=0.74d0*kf*(Pr/(0.861d0+Pr))**0.25d0*Ra**0.25d0
    if(keff<kf) keff=kf
    Q=pi*Di*Do*keff*dT/Lc
    Nu=keff/kf; h_eff=Nu*kf/Lc
  end select
  write(*,'(A)') '============================================'
  write(*,'(A)') '  FREE CONVECTION IN ENCLOSURES'
  write(*,'(A)') '============================================'
  write(*,'(A)') ''
  write(*,'(A)') '--- INPUTS ---'
  write(*,'(A,I4)') '  Enclosure Type          = ',etype
  write(*,'(A,F10.4,A)') '  Gap L                   = ',Lg,' m'
  write(*,'(A,F10.4,A)') '  Height H                = ',Hh,' m'
  write(*,'(A,F10.4,A)') '  Width W                 = ',Ww,' m'
  write(*,'(A,F10.2,A)') '  T_hot                   = ',Thot,' C'
  write(*,'(A,F10.2,A)') '  T_cold                  = ',Tcold,' C'
  write(*,'(A,F10.2,A)') '  Delta T                 = ',dT,' C'
  write(*,'(A)') ''
  write(*,'(A)') '--- FLUID ---'
  write(*,'(A,F10.4,A)') '  rho                     = ',rho,' kg/m3'
  write(*,'(A,ES12.4,A)') '  mu                      = ',mu,' Pa.s'
  write(*,'(A,F10.6,A)') '  k                       = ',kf,' W/mK'
  write(*,'(A,F10.4)') '  Pr                      = ',Pr
  write(*,'(A,ES12.4,A)') '  beta                    = ',beta,' 1/K'
  write(*,'(A)') ''
  write(*,'(A)') '--- RESULTS ---'
  write(*,'(A,ES14.4)') '  Rayleigh Number Ra      = ',Ra
  write(*,'(A,F12.4)') '  Nusselt Number Nu       = ',Nu
  write(*,'(A,F12.4,A)') '  Effective h             = ',h_eff,' W/m2K'
  write(*,'(A,F12.4,A)') '  k_effective             = ',keff,' W/mK'
  write(*,'(A,F12.4,A)') '  Heat Transfer Q         = ',Q,' W (or W/m)'
  if(etype<=3) write(*,'(A,F8.2)') '  Aspect H/L              = ',HL
  write(*,'(A)') ''
  write(*,'(A)') '--- DELTA-T SWEEP ---'
  write(*,'(A)') '  dT[C]      Ra           Nu        Q[W]'
  write(*,'(A)') '  ---------------------------------------------------'
  do i=1,25
    dTs=1d0+(dT*3d0-1d0)*dble(i-1)/24d0
    if(etype<=3) then; Ras=g*beta*dTs*Lg**3/(nu_v*alp)
    else; Ras=g*beta*dTs*Lc**3/(nu_v*alp); endif
    select case(etype)
    case(1)
      if(HL<=2d0) then; Nus=0.18d0*(Pr*Ras/(0.2d0+Pr))**0.29d0
      elseif(HL<=10d0) then; Nus=0.22d0*(Pr*Ras/(0.2d0+Pr))**0.28d0*HL**(-0.25d0)
      else; Nus=0.42d0*Ras**0.25d0*Pr**0.012d0*HL**(-0.3d0); endif
      if(Nus<1d0) Nus=1d0; Qs=Nus*kf/Lg*Hh*Ww*dTs
    case(2)
      Nus=0.069d0*Ras**(1d0/3d0)*Pr**0.074d0
      if(Nus<1d0) Nus=1d0; Qs=Nus*kf/Lg*Hh*Ww*dTs
    case(3); Nus=1d0; Qs=kf/Lg*Hh*Ww*dTs
    case(4)
      keff=0.386d0*kf*(Pr/(0.861d0+Pr))**0.25d0*Ras**0.25d0
      if(keff<kf) keff=kf; Nus=keff/kf
      Qs=2d0*pi*keff*dTs/log(Do/max(Di,1d-6))
    case default
      keff=0.74d0*kf*(Pr/(0.861d0+Pr))**0.25d0*Ras**0.25d0
      if(keff<kf) keff=kf; Nus=keff/kf
      Qs=pi*Di*Do*keff*dTs/Lc
    end select
    write(*,'(2X,F8.2,2X,ES10.3,2X,F9.3,2X,F12.4)') dTs,Ras,Nus,Qs
  enddo
  write(*,'(A)') ''
  write(*,'(A)') '--- CORRELATIONS ---'
  write(*,'(A)') '  Vertical rect: Catton (1978) correlations'
  write(*,'(A)') '  Horizontal hot bottom: Globe-Dropkin Nu=0.069*Ra^(1/3)*Pr^0.074'
  write(*,'(A)') '  Concentric cyl: k_eff/k=0.386(Pr/(0.861+Pr))^0.25*Ra^0.25'
  write(*,'(A)') '  Concentric sph: k_eff/k=0.74(Pr/(0.861+Pr))^0.25*Ra^0.25'
  write(*,'(A)') '  Ref: Incropera Ch.9 Sec.9.8, Kothandaraman Ch.10'
end program enclosure_convection


Solver Description

Models natural convection within enclosed cavities including vertical and horizontal rectangular gaps, concentric cylinders, and concentric spheres. Computes effective thermal conductivity ($k_{eff}$) and convection heat transfer rate using Catton and Globe-Dropkin correlations.

Key Numerical Methods & Architecture

  • Input Redirection: Reads parameters sequentially from standard input (`stdin`) using Fortran sequential read (`read(*,*)`), ensuring modular integration.
  • Modular Design: Formulated using pure mathematical routines, separation of equations from output formatting, and precise numerical solvers (e.g. bisection, Newton-Raphson).
  • Standard Compliant: Written in clean, standards-compliant Fortran 90 to ensure cross-compiler compatibility.

🛠️ Local Compilation

To test this code on your machine, compile the source code file(s) using a standard Fortran compiler (e.g., `gfortran`).

Compilation Command:

gfortran -O3 enclosure_convection.f90 -o enclosure_convection

Execution Command:

Execute the program by feeding the sample input file into the program using stdin redirection:

enclosure_convection < input.txt

📥 Downloads & Local Files

Preview of the required input file (input.txt):

! Enclosure type (1=Vert Rect, 2=Horiz hot bottom, 3=Horiz hot top, 4=Concentric Cyl, 5=Concentric Sph)
1
! Gap size L [m]
0.02
! Height H [m]
0.5
! Width W [m]
1.0
! Inner/First diameter Di [m]
0.0
! Outer/Second diameter Do [m]
0.0
! Hot surface temperature T_hot [C]
60.0
! Cold surface temperature T_cold [C]
20.0
! Fluid type (1=Air, 2=Water, 3=Oil)
1
! Custom thermal expansion coefficient beta [1/K] (0=auto)
0.0