The only requirement is julia, preferably 1.9.
- Clone this repo
- Start a Julia REPL in the root directory of the repo
julia --project=.
- Press
]
to enter Pkg mode. The REPL prompt should look like so
(Simulation) pkg>
- Instantiate the package. This step will download dependencies and take some time. Most of the heavier dependencies come from the two SciML packages. Note that solvers from this package were only used for testing the model, not for the calculating solution used for the plots.
(Simulation) pkg> instantiate
- Precompile the package. Again, this should take 5-ish minutes. Play a match of Blitz Chess maybe.
using Simulation
- Hit backspace to return to the regular REPL, run the tests and, generate plots
julia> include("test/runtests.jl")
We make the following assumptions and simplifications
- Flat plate collector with parallel riser tubes
- Temperature variations along the width of the solar collector (i.e. perpendicular to fluid flow direction) are not modelled, assume uniform mean temperature along with.
- Single phase regime -- the fluid does not undergo phase change
- Changes in specific heat capacity with temperature are negligible for all materials in the operating range
- Fixed ambient temperature, wind speed (i.e. fixed convection heat transfer coefficients), sky temperature, and solar irradiation
- Working fluid is incompressible, mass flow rate is constant throughout the system
- Heat exchanges occur only at the collector and storage tank, no heat transfer at pipes or pump
- The work done by the pump is completely balanced by e.g. the changes in potential energy in the storage tank and riser tubes, so it does not appear in the balance equations
- Radial temperature of the fluid is not modelled - assume an overall mean temperature across the cross section
@kwdef struct SWHSModel{T}
Ns::Int= 10 # stratifications count for tank
Nc::Int= 100 # number of points in the discretized mesh of collector
ρp::T = 8.0e3 # density of plate
ρf::T = 1.0e3 # working fluid density
ρe::T = 1.5e3 # effective density (tank + wokring fluid)
δ::T = 0.1 # plate thickness
W::T = 1.0 # plate width
L::T = 2.0 # plate length
H::T = 10.0 # height of tank
ΔH::T = H/Ns # height of each stratified layer
Δy::T = L/Nc
dt::T = 5.0 # tank diameter
dr::T = 0.1 # riser pipe diameter
dd::T = dr # down comer pipe diameter
kp::T = 50.0 # thermal conductivity of plate
Cpp::T = 450.0 # specific heat capacity of plate
Cpf::T = 4.2e3 # specific heat capacity of working fluid
Cpe::T = 5000.0 # effective specific heat of tank + working fluid
S::T = 800.0 # radiation flux
hpf::T = 1000.0 # heat transfer coefficient (plate and working fluid)
hpa::T = 100.0 # heat transfer coefficient (plate and atmosphere)
hra::T = 100.0 # heat transfer coefficient (riser pipe and ambient)
hda::T = hra # heat transfer coefficient (down pipe and ambient)
hta::T = 500.0 # loss coefficient (storage tank)
Ta::T = 300.0 # ambient temperature
T∞::T = 295.0 # sky temperature
α::T = 5.5e-8 # radiation coefficient
Af::T = W*L*0.2 # transverse cross section area pipes in collector
mdot::T = 0.5 * Af * ρf # mass flow rate (assuming 0.5m per s in collector pipes
A::T = π*dt*ΔH # ambient contact area per stratified layer
V::T = ΔH*π*(dt^2)/4 # tank volume per stratified layer
ρCl::T = 1.0e3
mCr::T = 1.0e3
mCd::T = mCr
...
end
We consider a flat plate collector with parallel riser tubes modelled as an absorber plate transfering heat to the fluid in the risers. This model is based on the work of [4]. Heat transfer between plate and fluid modelled as convection using Newton's law of cooling [1].
We have the following processes
- Solar radiation,
$\propto T_p^4 - T_{\text{sky}}^4$ (Stefan-Boltzmann law) - Convective transfer to fluid,
$\propto T_p - T_f$ (Newton's law of cooling) - Convective loss to atmosphere,
$\propto T_p - T_a$ (Newton's law of cooling)
where
Note that we only need the width factor to get the source term for the 1D advection equation used for simulating the working fluid in the collector.
We use Neumann boundary conditions:
We model heat transfer through and by the fluid using a 1D advection equation with the source term being the plate-fluid convective transfer term.
where
We use a stratified, well-mixed tank model as presented in [3,7].
for
where
We assume that the temperature drop across the connecting pipes is small and model them as single nodes between the collector and the tank, similar to as done in (TODO: cite). Denote
where
Consider first
Where the prime
We need the second derivative for the conductive term as well.
Where we estimated the second derivative at the boundaries using the Neumann conditions.
and similarly for
Denote this matrix as
Putting everything together, we get the following system of ODEs for the discretized plate subsystem.
We can take
Again, compact notation
So that
The implementation can found here in the source.
We set ourselves up for contiguous memory accesses.
If we use an array/tensor programming language/library with GPU support (JuliaGPU, Halide, ArrayFire, TensorFlow etc), GPU acceleration should be simple to incorporate).
Once we have the final system of equations, we should be able to plug it into ODE and even steady-state solvers of our choice. We implement a simple fourth order explicit Runge-Kutta method.
function runge_kutta_4(f!, tspan, dt, prob::SWHSProblem)
@unpack u, du = prob
@unpack cache = prob
T = eltype(u)
k1 = zeros(T, length(u))
k2 = zeros(T, length(u))
k3 = zeros(T, length(u))
k4 = zeros(T, length(u))
t = first(tspan)
while t < last(tspan)
f!(k1, u, cache)
f!(k2, u .+ dt .* k1 ./ 2, cache)
f!(k3, u .+ dt .* k2 ./ 2, cache)
f!(k4, u .+ dt .* k3, cache)
@. u += dt/6 * (k1 + 2k2 + 2k3 + k4)
t += dt
end
u
end
- [1] Incropera, Frank P., et al. Fundamentals of heat and mass transfer. Vol. 6. New York: Wiley, 1996.
- [2] Zeghib, I., & Chaker, A. (2011). Simulation of a solar domestic water heating system. Energy Procedia, 6, 292-301.
- [3] Kalita, K. (2020). Solar Energy Engineering and Technology [MOOC]. NPTEL. https://onlinecourses.nptel.ac.in/noc20_ph14/preview
- [4] Al-Tabbakh, A. A. (2022). Numerical transient modeling of a flat plate solar collector. Results in Engineering, 15, 100580
- [5] Rosales, R. R. (2022) Notes: von Neumann Stability Analysis. [Course Notes] https://math.mit.edu/classes/18.300/Notes/Notes_vNSA.pdf
- [6] Rowell, D., & Wormley, D. N. (1997). System dynamics: an introduction (Vol. 635). Upper Saddle River: Prentice Hall.
- [7] Hussein, H. M. S. "Transient investigation of a two phase closed thermosyphon flat plate solar water heater." Energy Conversion and Management 43.18 (2002): 2479-2492.
- Automatic Differentiation (AD): The implementation in code of the final implementation cannot be used AD for Jacobian calculations at this point. I verified this by trying to use some implicit solvers from SciML that use AD. It should be possible to come up with a differentiable implementation, which would allow solving this model using more advanced implicit solvers. As a first step, we would have to ensure that the function is generic enough to be able to accept dual numbers as arguments.
- Parameter sweeps/ Sensitivity Analysis: Ideally I would have liked to perform sensitivity analysis for some of the important parameters. This has been left out due to time constraints.
-
A less complex model(?): For starters I probably should have tried harder for something like a lumped element model, if that is possible for thermal systems. Some model design strategies exist, such as modeling a "thermal circuit" with temperature
$\equiv$ voltage and heat flux$\equiv$ electric current. This treatment is presented in [6]. - A more complex model(?): Both solar collectors and storage tanks have been modelled with a fair amount of complexity [2,4,7].