Top Banner
M.Pilotti: Classwork of Environmental Hydraulics Classwork 9 Solving the Energy Balance Equation for the vertical thermal profile of a deep lake The meteorological lake diagnostic station that is managed by the Group of Hydraulics of the University of Brescia in lake Iseo. The station measures in real time the lake T(z,t) profile. In this classwork we present a simplified approach to compute this type of information starting from the thermal balance of the lake
16

Classwork 9 Solving the Energy Balance Equation for the ...

May 20, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

Classwork 9

Solving the Energy Balance Equation for the vertical thermal profile of a deep lake

The meteorological lake diagnostic station that is managed by the Group of Hydraulics of the

University of Brescia in lake Iseo. The station measures in real time the lake T(z,t) profile. In this classwork we present a simplified approach to compute this type of information

starting from the thermal balance of the lake

Page 2: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

Why classwork 9 ? The purpose of this classwork is twofold. On one side, we deal with a very important problem, the thermal stratification in a lake, that strongly controls all the dynamics, biological and chemical processes that happen in a deep lake like the most important italian prealpine lakes. We do that starting from a simplified 1D model that has been introduced during our theoretical classes. This type of approach is not devoid of strong limitations and they will be evident at the end of the classwork. However, it provides a very interesting starting point to appreciate the relevance of the single terms that make up the energy balance of a lake. This has been the original starting point from which more complex models developed and students are strongly suggested to read the paper by Dake and Harleman that can be downloaded by the website. The second reason that gives interest to this classwork is that in place of solving the original parabolic diffusion-convective PDE, that could be done with a Finite Difference approach as done in previous classworks, we shall solve numerically the problem by working on the original integral equation. This will allow us to introduce the idea of Finite Volume numerical methods (FVM), appreciating the simplicity of the idea behind and the greater physical meaning of the corresponding numerical algorithm. The content of classwork 9 In this classwork we solve the energy balance equation

∫∫∫∫ +

∇−∇−=

∂∂

Wi pSi pSi pWi

dWC

hTdS

CTdS

CTdW

t ρρλ

ρλ

21

(eq.1)

for a cylindrical lake with unit surface S that has been discretized along the vertical with an adaptive step dz within the PROCEDURE inizializza_spessore_cella; the final result is a set dz[i] so that the volume of each cell is given by volume[j] := S*dz[j], where S:= 1;

i is chosen growing from surface to bottom and it is associated to the cell center. As in the picture on the left, the spacing may vary from cell to cell in order to capture variables gradient where they are presumibly stronger, i.e., close to the surface. In the following we shall concentrate our attention on the thermal balance of cell i and we shall consider the fluxes with the cell i-1 and I+1. Note that in the algorithm a particular case will be that of the first cell, where the boundary condition on the flux with atmosphere above must be applied, and of the last cell, where we shall suppose that the flux is zero, so that, being,

0/ =∂∂ zT , it must be T(last cell):= T(last cell-1). All the properties are associated to the center of the cell. The problem is an evolutive one, that requires the computation of the source term as a function of the day during the year and of the time during the day. Accordingly the structure of the program is devised as in the following table, where the core of the algorithm is contained within the cell with the yellow background

Page 3: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

BEGIN Reading Of Initial Conditions And Initialization Of Variables

Advance in time

FOR giorno := 1 TO n_giorni DO BEGIN

FOR ora := 1 TO 24 step dt DO BEGIN

Compute energy entering from the Lake Surface as a function of giorno and ora solve the energy equation for all the n elements into which the water column has been subdivided FOR i := 1 TO n DO BEGIN

// calcolo i termini di flusso alla Fourier A2_up := calcola_A2_up(i); A2_down := calcola_A2_down(i); // calcolo il termine sorgente A3 := calcola_A3(i); // tengo separato il vettore al tempo t+1 da quello al tempo t T[i] := T_acqua[i] -A2_up +A2_down +A3;

END; END;

Save data in a disk for the current day END;

Close files

END. Accordingly the algorithm works on cell i, being n the total number of cells into which the column has been subdivided, updating the temperature of the cell on the basis of the flux terms and of the source term. The integrals are evaluated in this way

i

ni

ni

Wi

Wt

TTTdW

t ∆−

≅∂∂ +

∫1

ip

i

Wi p

WC

hdW

C

h

ρρ≅∫

in the case of the source term, it is provided by Beer’s equation, that is an exponential ( ) zez ηφβφ −−= 01)(

that can be integrated analitically. Accordingly an exact proxy is

( ) ( )SeeC

dWC

h zz

pWi p

2101 ηη

ηρφβ

ρ−− −

−=∫

The evaluation of the fluxes through Si1 and Si2 requires more care. There are two problems with it: the first is the evaluation of the gradient

Page 4: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

dSdzdzTT

CdS

z

T

CTdS

C ii

ii

Si pSi pSi p

+−

≅∂∂=∇

−∫∫∫

2

)(

1

1

111 ρλ

ρλ

ρλ

dSdzdzTT

CdS

z

T

CTdS

C ii

ii

Si pSi pSi p

+−

≅∂∂=∇

+

+∫∫∫

2

)(

1

1

222 ρλ

ρλ

ρλ

The second is connected to the evaluation of the conductivity value to be used in case this is a function of z. Actually, this variation can usually be neglected but the problem is a more general one, connected to similar situations in environmental hydraulics (e.g., saturated Darcy flow in a porous medium with variables permeability). Accordingly we shall consider it in detail. Let us suppose that λ varies between cell 1 and 2

Let us evaluate the heat flux across the boundary between cell 1 and 2. There are three equivalent way to do it. The first one, by introducing the temperature at the interface, that is unknown

)2()(

)1(;)(

2

22

1

11 L

TT

L

TT −=

−= λφλφ

In an alternative way, we could compute the flux without introducing the unknown T at the boundary, by introducing an

effective, average, thermal conductivity.

)3()(

21

12

LL

TTeq +

−= λφ .

Let us obtain T at the interface from (1) and let us substitute it into (2):

)4(

)(

1

1

2

2

12

2

11

12

211

1

+

−=→

−−=→+=

λλ

φλφ

λφλφ

LL

TT

L

LTT

LTT

Equating (4) to (3), we get

→+−

=

+

−=

21

12

1

1

2

2

12 )(

LL

TT

LL

TTeqλ

λλ

φ ( ) )5(1221

2121 LL

LLeq λλ

λλλ++

=

(5) is the armonic average that should be used in such cases. This average takes into account that if either λ1

or λ2 are zero, the overal flux must be zero. Accordingly, the flux terms can be computed as

SdzdzTT

CTdS

C ii

ii

p

iieq

Si p

+−

≅∇−

−−∫

2

)(

1

1,1_

1 ρλ

ρλ

SdzdzTT

CTdS

C ii

ii

p

iieq

Si p

+−

≅∇+

++∫

2

)(

1

11,_

2 ρλ

ρλ

Accordingly, the FV equation that approximates the integral equation (eq.1) is:

Page 5: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

( ) ( )SeeC

Sdzdz

TT

CS

dzdzTT

CW

t

TT zz

pii

ni

ni

p

iieq

ii

ni

ni

p

iieqi

ni

ni 210

1

11,_

1

1,1_1 1

2

)(

2

)( ηη

ηρφβ

ρλ

ρλ −−

+

++

−−+

−−

+

+−

+

+−

−=∆−

in the yellow cell of the metacode above, the terms are called as below

( ) ( )i

zz

pii

ni

ni

ip

iieq

ii

ni

ni

ip

iieqni

ni W

tSee

CtS

dzdzTT

WCtS

dzdzTT

WCTT

∆−−

+∆

+−

+∆

+−

−= −−

+

++

−−+ 210

1

11,_

1

1,1_1 1

2

)(

2

)( ηη

ηρφβ

ρλ

ρλ

A2_up A2_down A3 Note that the code reads as an input file the initial T profile. For instance, you can copy in your working directory the ASCII file T_0_di_z.in with the following format (T z) as 0.0 6 260.0 6 The forcings within the code are limited to the radiative one, SW and LW. They are computed at each hour in determina_irraggiamento(giorno,TRUNC(ora*dt/3600)); determina_potenza_persa_dalla_superficie(giorno); A final observation regards the boundary condition at the top of the water column, where the A2_up term must be computed as the energy flux with the atmosphere above. This is accomplished in the instruction IF i = 1 THEN derivata := -1/(ro_w*Cp*alfa(i,i-1))*(beta*phi_0 -phi_l) ELSE derivata := (T_acqua[i] -T_acqua[i-1])/(dz[i]/2 +dz[i-1]/2); that deals the upper boundary of the first cell as a particular case.

In order to complete this classwork the students are asked:

• After studying the listing of the following code, to write the FUNCTIONS A2_down and A3. • Write a MATLAB code to read and visualize the third output file produced by the code. • Starting from a lake with a uniform T=6.3 °C (end of winter), simulate for 90 days the heating process

of the lake with the default values in the CONST declaration part of the code (fattore_amplificazione_lambda=1). Observe the T at the surface of the lake. Now repeat the simulation with fattore_amplificazione_lambda=50. Observe the new value of the T at the surface and the thickness of the layer that has been heated. You will see that in this case the temperature are reasonable and the thickness much larger. This is due to the fact that here we suppose that heat migrates toward the bottom only under the action of molecular diffusion, an extraordinary slow process. In reality the heating process in a lake is dominated by several turbulent mixing process. The practical effect of these processes is that of greatly enhancing the heat transfer within the metalimnion. In order to take into account these effects, the simplest way is to amplify the thermal diffusivity of some order of magnitude. A more refined approach would be to simulate these processes but this would demand a much more complex model.

• With fattore_amplificazione_lambda=50 simulate starting from the beginning of the year (giorno_iniziale = 0) for n_giorni = 360.Print the T profile on the third output file only every 30 days (intervallo_stampa_dati = 30). Observe the variation over the year of the T profile. You will see that at a give time it will start cooling at the surface. Is the resulting T profile still reasonable ? Discuss this point on the basis of your knowledge of the properties of the density of water.

• Test the effect of variations of the value of the SW extinction coefficient on the T(z) profile.

Page 6: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

• Implement a function to add the contribution of latent heat Final targets of Classwork 9

• Solving a pretty complicate PDE, in a very simple way. • Getting a better insight of the heating and cooling process in a lake.

Additional and suggested readings To get acquainted with the physical problem, the student is invited to read the following papers that are available on the hydraulics group web page

• J. M. K. Dake and Donald R. F. Harleman, Thermal Stratification in Lakes: Analytical and Laboratory Studies’, Water Resour. Res.,.

• Chen, C. W., G. T. Orlob, and M. B. Sonnen (1969), Comments on ‘Thermal Stratification in Lakes: Analytical and Laboratory Studies’ by J. M. K. Dake and Donald R. F. Harleman, Water Resour. Res., 5(6), 1433–1435

• Dake, J. M. K. and D. R. F. Harleman (1969), Reply to “Comments on ‘Thermal Stratification in Lakes: Analytical and Laboratory Studies’ by J. M. K. Dake and Donald R. F. Harleman”.

An interesting abridged version (with some errors…) can be found in the excellent book

• Eagleson, Peter S., Dynamic hydrology, New York : McGraw-Hill, [1970].

A fundamental reading for understanding more about the physics of these processes is

• Fischer, H.B., List, E.J., Koh, R. C. Y., Imberger, J., and Brooks, N.H.: Mixing in Inland and. Coastal Waters. Academic Press, New York 1979.

Finally, to appreciate the environmental implications of water temperature on the biology and chemistry of the lake, a very instructive reading is

• S. Chapra, Surface Water Quality Modeling, Mc Graw Hill, 1997 The code

program T_lake_profile; // risolve il bilancio di energia per una colonna liquida di un lago soggetta solo ad ingressi // radiativi // MP 4/1/2010 {$R *.RES} Const // dati generali sigma = 5.67*1e-08; // costante di Stefan Boltzmann g = 9.8065; // dati relativi alla radiazione ShortWave Imax = 600; // max teorico con albedo 0; watt/mq Imin = 50; // min teorico con albedo 0; watt/mq --> CONTROLLARE!!! // dati relativi alla colonna d'acqua

Page 7: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

z_max = 245; // profondità colonna d'acqua in metri Cp = 4182; // calore specifico dell'acqua: J/(kg*K) emissivita = 0.9; ro_w = 998.2; albedo = 0.06; // albedo dell'acqua beta = 0.45; // fattore di attenuazione superficiale della radiazione solare; // porzione di phi_0 assorbito alla superficie eta = 0.4; // coefficiente di assorbimento (1/m) che dipende dalla trasparenza dell'acqua // tanto è maggiore tanto più rapido è l'assorbimento lambda_acqua = 0.604; // conduttività. acqua: W/(mK) fattore_amplificazione_lambda = 50; // T_iniziale_lago = 6.4; // temperatura iniziale della colonna termica n_giorni = 90; // durata_simulazione in giorni giorno_iniziale = 0; // giorno iniziale durante l'anno, tra 0 e 365. Serve per determinare la radiazione SW dt = 36; // sec fattore_progressione_dz = 1; //fattore di incremento del passo spaziale dz //della griglia verticale eps = 1e-06; max_dim_A = 1000; max_n_elementi = 10000; // massimo numero di discretizzazioni verticali max_n_passi_temporali = 1000; // massimo numero di vettori soluzioni da salvare intervallo_stampa_dati = 30; // ogni quanti giorni stampare il risultato sul file nameout3 // INPUT-OUTPUT nameout1 = 'logfile1.out'; // inizializzazioni della simulazione nameout2 = 'out2.out'; // risults every time step nameout3 = 'out3.out'; // results every "intervallo_stampa_dati" time step name_T_iniziale = 'T_0_di_z.in'; // profilo iniziale T(z); attenzione: almeno 2 valori e l'ultimo valore deve essere // relativo ad una z > z_max TYPE IntArrayNPbyNP = ARRAY [1..max_dim_A,1..max_dim_A] OF integer; realArrayNPbyNP = ARRAY [1..max_n_elementi+1,1..max_n_passi_temporali] OF real; realArrayNPby4 = ARRAY [1..max_dim_A,1..7] OF real; realArrayNP = ARRAY [1..max_dim_A] OF real; IntegerArrayNP = ARRAY [1..max_dim_A] OF integer; tabella_z = ARRAY [1..max_n_elementi,1..2] OF real; VAR ro_z,T_z,microS_z : tabella_z; ro,ro_iniziale, T,T_acqua,dz,lambda,profondita,S,volume, T_acqua_iniziale, contenuto_di_calore,stabilita : ARRAY [1..max_n_elementi] OF real; soluzione : realArrayNPbyNP; ora, n_discretizzazioni_24_ore, n_discretizzazioni,giorno, i,j,k : INTEGER; dummyR,spessore_cumulato, A1,A2_up,A2_down,A3, Boltzmann, dist1,dist2,dist, phi_sun,phi_0,k_l,phi_l, I_t, t_stampa,T_media_giornaliera, energia_termica_immagazzinata, energia_radiativa_netta_immessa_MJ,ptu, c,t_dummy,T_cielo : real;

Page 8: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

arch1,arch2,arch3 : TEXT; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////// PROPRIETA' FISICHE //////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION densita_acqua_UNESCO(T,S,P:real):extended; {UNESCO International Equation of State (IES 80) as described in Fofonoff (1985). T : °C S : salinity (psu) pressure : (bar) to check with a standard ocean (by convention an ocean at 0 deg C and 35 psu): rho=1027.67547 at 35 PPT, 5 degC and 0 dbar see also: http://www2.sese.uwa.edu.au/~hollings/pilot/denscalc.html The equation of state of water is a complicated curve fit to very precise measurements. The relationship between the Practical Salinity Scale and older measures of salinity (typically measured in parts per thousand) is nearly, but not quite 1:1. Although the actual equation of state is quite complex there is a simple rule of thumb to remember that can be quite helpful: density increases by roughly 1 part per 1000 when the temperature decreases by 5 deg C, the salinity increases by 1 psu or the pressure increases by 200 dbar (about 200 m depth). Range of Validity: The underlying equations are valid for temperatures from -2 to 35 deg C, pressures from 0 to 10,000 dbar, and practical salinity from 0 to 42. Author: Marco Pilotti, 1/2010 } VAR A,B,C,D,dens0,T2,T3,T4,E,F,G,H,I,J,M,N,K : extended; BEGIN // Compute density (kg/m3) at the surface from salinity (psu) and temperature (degC) A := 1.001685e-04 + T * ( -1.120083e-06 + T * 6.536332e-09 ); A := 999.842594 + T * ( 6.793952e-02 + T * ( -9.095290e-03 + T * A ) ); B := 7.6438e-05 + T * ( -8.2467e-07 + T * 5.3875e-09 ); B := 0.824493 + T * ( -4.0899e-03 + T * B ); C := -5.72466e-03 + T * ( 1.0227e-04 - T * 1.6546e-06 ); D := 4.8314e-04; dens0 := A + s *( B + C *sqrt(s) + D * s ); // Compute density (kg/m3) from salinity (psu), temperature (degC) and pressure (dbar) T2 := T*T; T3 := T2*T; T4 := T3*T; E := 19652.21 + 148.4206 * T - 2.327105 * T2 + 1.360477e-2 * T3 - 5.155288e-5 * T4; F := 54.6746 - 0.603459 * T + 1.09987e-2 * T2 - 6.1670e-5 * T3; G := 7.944e-2 + 1.6483e-2 * T - 5.3009e-4 * T2; H := 3.239908 + 1.43713e-3 * T + 1.16092e-4 * T2 - 5.77905e-7 * T3; I := 2.2838e-3 - 1.0981e-5 * T - 1.6078e-6 * T2; J := 1.91075e-4; M := 8.50935e-5 - 6.12293e-6 * T + 5.2787e-8 * T2; N := -9.9348e-7 + 2.0816e-8 * T + 9.1697e-10 * T2; K := (E + F*s + G*s*sqrt(s)) + (H + I*s + J*s*sqrt(s))*P + (M + N*s)*P*P; densita_acqua_UNESCO := dens0 / (1 - P/K); END; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Page 9: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

//////////////////////////////////////////// CALCOLO FORZANTI TERMICHE //////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION calcola_radiazione_incidente(ora,giorno:real):real; // determino la potenza entrante dal sole in W/mq // ora è 1,2...24 // giorno 1... 365 CONST omega = 7.27221E-05*3600; fase = -1.570796327; inizio_primavera = 80; VAR I0,flusso_radiante : real; BEGIN // variante sinusoidale I0 := Imin +(Imax-Imin)*sin(0.008607103*giorno); // modulazione oraria flusso_radiante :=I0*sin(omega*ora +fase); IF flusso_radiante < 0 THEN flusso_radiante := 0; calcola_radiazione_incidente := flusso_radiante; END; PROCEDURE determina_irraggiamento(giorno,ora: integer); // dati relativi all'irraggiamento BEGIN // radiazione solare totale per unità d'area: Watt/mq phi_sun := calcola_radiazione_incidente(ora,giorno+giorno_iniziale); // radiazione solare totale per unità d'area non riflessa dall'acqua // la parte beta di phi_0 rimane nello strato superficiale mentre la // parte (1-beta) penetra all'interno dell'acqua phi_0 := (1-albedo)*phi_sun; END; FUNCTION Atmospheric_LW(T_air,air_vapor_pressure:real):real; // air_vapor_pressure in mm/Hg // T_air in °C CONST sigma = 5.67*1e-08; water_emissivity = 0.97; reflection_coefficient = 1-water_emissivity; A = 0.6; BEGIN Atmospheric_LW := (1-reflection_coefficient)*sigma*(A +0.031*sqrt(air_vapor_pressure))*sqr(T_air+273.16)*sqr(T_air+273.16); END; FUNCTION calcola_potenza_persa(giorno:integer):real; // determino la potenza uscente dalla superficie del lago in W/mq // giorno 1... 365 CONST t0_L = 182.5; t_0 = 135; // giorno di massimo della radizione incidente, a partire dal 21 marzo LWoutmax = 100; sigma = 5.67*1e-08; water_emissivity = 0.97; BEGIN // radiazione persa secondo la relazione di Dake and Harleman calcola_potenza_persa:= water_emissivity*sigma*sqr(T_acqua[1]+273.16)*sqr(T_acqua[1]+273.16) -Atmospheric_LW(7,20);

Page 10: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

END; PROCEDURE determina_potenza_persa_dalla_superficie(giorno:integer); // dati relativi all'irraggiamento BEGIN // radiazione solare totale per unità d'area: Watt/mq giorno := giorno+giorno_iniziale; phi_l := calcola_potenza_persa(giorno); END; PROCEDURE aggiorna_energia_radiante_immessa; // dati relativi alla energia immessa per irraggiamento BEGIN // radiazione immessa in MJ energia_radiativa_netta_immessa_MJ := energia_radiativa_netta_immessa_MJ +(phi_0 -phi_l)*dt*S[1]/1e06; END; PROCEDURE calcola_contenuto_di_calore_della_colonna; // calcola il contenuto di calore della colonna rispetto allo stato iniziale di temperatura uniforme // in MJoule BEGIN energia_termica_immagazzinata := 0; FOR j := 1 TO n_discretizzazioni DO BEGIN contenuto_di_calore[j] := ro_w*Cp*volume[j]*(T_acqua[j] -T_iniziale_lago); energia_termica_immagazzinata := energia_termica_immagazzinata +contenuto_di_calore[j]/1e06; END; END; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////// INIZIALIZZAZIONI //////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// PROCEDURE leggi_profili_iniziali; BEGIN // legge il profilo osservato di T nel lago. Attenzione: l'ultimo valore // deve essere relativo ad una z > z_max ASSIGN(arch3,name_T_iniziale); RESET(arch3); i := 0; WHILE NOT EOF(arch3) DO BEGIN i := i+1; readln(arch3,T_z[i,1],T_z[i,2]); END; CLOSE(arch3); END; PROCEDURE inizializza_profilo_T; // inizializzo la temperatura nella colonna liquida di calcolo BEGIN FOR j := 1 TO n_discretizzazioni DO T_acqua[j] :=T_iniziale_lago END; PROCEDURE inizializza_profilo_densita; // inizializzo la densita nella colonna liquida VAR

Page 11: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

densita_superficiale,pressure,psu : real; BEGIN // ai fini del calcolo della pressione uso la densità superficiale densita_superficiale := densita_acqua_UNESCO(T_acqua[1],S[1],0); FOR j := 1 TO n_discretizzazioni DO BEGIN // pressione in bar pressure := g*densita_superficiale*profondita[j]/1e05; ro[j] := densita_acqua_UNESCO(T_acqua[j],0,pressure); ro_iniziale[j] := ro[j]; END; END; PROCEDURE inizializza_profilo_lambda; // inizializzo la conducibilità nella colonna liquida // conduttività. acqua: W/(mK) BEGIN FOR j := 1 TO n_discretizzazioni DO lambda[j] := fattore_amplificazione_lambda*lambda_acqua; END; PROCEDURE inizializza_volume; // inizializzo il valore del volume della cella alla profondità z BEGIN FOR j := 1 TO n_discretizzazioni DO BEGIN // for semplicity's sake here I consider an unitary surface S[j] := 1; volume[j] := S[j]*dz[j]; END; END; PROCEDURE inizializza_spessore_cella; {procedura per il calcolo dello spessore delle celle della colonna liquida alla progressiva i. Il primo strato è spesso un metro e così anche l'ultimo. Poi lo spessore delle celle è calcolato in modo adattativo, considerando il profilo di T medio annuo per il lago d'iseo 0 14.36 1 14.36 3 14.36 5 14.24 10 13.37 20 9.49 30 7.91 50 6.98 75 6.78 100 6.65 150 6.53 200 6.47 245 6.47 dove il termoclinio è attorno a 20 m } CONST // si veda il file excell analisi_griglia_adattativa per vedere come si // comporta con griglia variabile nello spazio. Non sembra male con lo schema // sotto deltaz1 = 0.1; deltaz2 = fattore_progressione_dz*deltaz1; deltaz3 = fattore_progressione_dz*deltaz2; deltaz4 = fattore_progressione_dz*deltaz3; deltaz5 = fattore_progressione_dz*deltaz4;

Page 12: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

BEGIN // la mesh è raffittita vicino alla superficie del concio j := 1; dz[j] := deltaz1; // lo spessore cumulato è la profondità del fondo della cella spessore_cumulato := dz[j]; // la profondità è riferita al centro della cella profondita[j] := dz[j]/2; WHILE profondita[j] <= z_max DO BEGIN j := j +1; // discretizzazione verticale del lago IF spessore_cumulato < 5 THEN dz[j] := deltaz1 ELSE IF spessore_cumulato < 10 THEN dz[j] := deltaz2 ELSE IF spessore_cumulato < 60 THEN dz[j] := deltaz3 ELSE IF spessore_cumulato < 100 THEN dz[j] := deltaz4 ELSE dz[j] := deltaz5; spessore_cumulato := spessore_cumulato +dz[j]; profondita[j] := profondita[j-1] +(dz[j-1]/2 +dz[j]/2); writeln(profondita[j]:6:2); END; n_discretizzazioni := j-1; writeln('numero di discretizzazioni verticali: ',n_discretizzazioni:5); IF n_discretizzazioni > max_n_elementi THEN BEGIN writeln('Superato il massimo numero di discretizzazioni verticali. Interrompere l''esecuzione'); readln; END; END; PROCEDURE inizializza_parametri_controllo; BEGIN t_stampa := 1; ASSIGN(arch1,nameout1); REWRITE(arch1); ASSIGN(arch2,nameout2); REWRITE(arch2); ASSIGN(arch3,nameout3); REWRITE(arch3); energia_radiativa_netta_immessa_MJ := 0; END; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////// CALCOLI /////////////// //////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION lambda_armonica(i,j:integer):real; // calcola la conducibilità come media armonica tra le due celle in serie BEGIN // tratto come caso particolare la prima cella e il fondo dell'ultima

Page 13: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

IF ((j = 0) OR (j = n_discretizzazioni+1)) THEN lambda_armonica := lambda[i] ELSE lambda_armonica := lambda[i]*lambda[j]*(dz[i] +dz[j])/(lambda[i]*dz[j] +lambda[j]*dz[i]); END; FUNCTION alfa(i,j:integer):real; // calcola la diffusività termica molecolare dell'acqua // 0.00000014 [mq/s] BEGIN alfa := lambda_armonica(i,j)/(ro_w*Cp); END; FUNCTION calcola_A2_up(i:integer):real; // calcola i termini di flusso alla Fourier dalla cella corrente verso la cella in alto VAR deltaz,C,derivata : real; BEGIN deltaz := volume[i]/S[i]; C := alfa(i,i-1)*dt/deltaz; // qua si impone la condizione al contorno sulla superficie libera. Si noti // che il segno riportato da Eagleson è sbagliato IF i = 1 THEN derivata := -1/(ro_w*Cp*alfa(i,i-1))*(beta*phi_0 -phi_l) ELSE derivata := (T_acqua[i] -T_acqua[i-1])/(dz[i]/2 +dz[i-1]/2); calcola_A2_up := C*derivata; END; FUNCTION calcola_A2_down(i:integer):real; // calcola i termini di flusso alla Fourier dalla cella corrente verso la cella in basso BEGIN END; FUNCTION calcola_A3(i:integer):extended; // calcola il termine sorgente BEGIN END; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////// EDITING E FORMATTAZIONE //////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// PROCEDURE salva_su_file_condizione_iniziale; BEGIN writeln(arch1,'Colonna suddivisa in ',n_discretizzazioni:3,' celle'); writeln(arch1,' i dz zmax T(0) lambda arm_(i,i-1) arm_(i,i+1) Superficie volume termine_sorgente'); FOR j := 1 TO n_discretizzazioni DO BEGIN writeln(arch1,j:2,' ',dz[j]:6:2,' ',profondita[j]:6:2,' ',T_acqua[j]:6:2,' ',lambda[j]:6:2,' ',lambda_armonica(j,j-1):6:2,' ',lambda_armonica(j,j+1):6:2,' ',S[j]:6:2,' ',volume[j]:6:2,' ',calcola_A3(j):12:9); END; END;

Page 14: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

PROCEDURE stampa_risultati; VAR k,j,lag_dati : integer; BEGIN // stampa sul file 2 che contiene le soluzioni a tutti i giorni write(arch2,' '); FOR j := 1 TO n_giorni DO write(arch2,soluzione[1,j]:6:2,' '); writeln(arch2); FOR k := 1 TO n_discretizzazioni DO BEGIN write(arch2,' ',profondita[k]:6:2,' '); FOR j := 1 TO n_giorni DO write(arch2,soluzione[k+1,j]:6:2,' '); writeln(arch2); END; // stampa sul file 3 che contiene le soluzioni solo agli istanti selezionati lag_dati := 1; write(arch3,' '); FOR j := 1 TO n_giorni DO BEGIN IF lag_dati > intervallo_stampa_dati-1 THEN BEGIN write(arch3,soluzione[1,j]:6:2,' '); lag_dati := 0; END; lag_dati := lag_dati+1; END; writeln(arch3); FOR k := 1 TO n_discretizzazioni DO BEGIN lag_dati := 1; write(arch3,' ',profondita[k]:6:2,' '); FOR j := 1 TO n_giorni DO BEGIN IF lag_dati > intervallo_stampa_dati-1 THEN BEGIN write(arch3,soluzione[k+1,j]:6:2,' '); lag_dati := 0; END; lag_dati := lag_dati+1; END; writeln(arch3); END; END; PROCEDURE trascrivi_risultati; BEGIN IF giorno > max_n_passi_temporali THEN BEGIN writeln('Vettore soluzione sottodiemnsionato: cambiare max_n_passi_temporali'); readln; END; // la prima riga è il passo temporale soluzione[1,giorno] := giorno +giorno_iniziale; // poi ciascuna colonna contiene il vettore soluzione corrente FOR j := 1 TO n_discretizzazioni DO soluzione[j+1,giorno] := T_acqua[j]; END;

Page 15: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

PROCEDURE chiudi_programma; BEGIN writeln('programma terminato'); readln; CLOSE(arch1); CLOSE(arch2); CLOSE(arch3); END; BEGIN leggi_profili_iniziali; inizializza_parametri_controllo; // inizializzo lo spessore e la temperatura nella colonna d'acqua inizializza_spessore_cella; inizializza_volume; inizializza_profilo_T; inizializza_profilo_lambda; salva_su_file_condizione_iniziale; n_discretizzazioni_24_ore := round(86400/dt); // inizio della simulazione // giorno parte sempre da 1 FOR giorno := 1 TO n_giorni DO BEGIN // Simulo un giorno intero; il passo elementare della simulazione è dt FOR ora := 1 TO n_discretizzazioni_24_ore DO BEGIN // determino la radiazione ad onde corte entrante al tempo t e l'energia // persa dalla superficie del lago determina_irraggiamento(giorno,TRUNC(ora*dt/3600)); determina_potenza_persa_dalla_superficie(giorno); aggiorna_energia_radiante_immessa; FOR k := 1 TO n_discretizzazioni DO BEGIN // calcolo i termini di flusso alla Fourier A2_up := calcola_A2_up(k); A2_down := calcola_A2_down(k); // calcolo il termine sorgente A3 := calcola_A3(k); // tengo separato il vettore al tempo t+1 da quello al tempo t T[k] := T_acqua[k] +A1 -A2_up +A2_down +A3; END; // aggiorno il vettore che ora conterrà la soluzione al tempo t+1 FOR k := 1 TO n_discretizzazioni DO T_acqua[k] := T[k]; END; // calore accumulato nella colonna a partire dallo stato iniziale calcola_contenuto_di_calore_della_colonna;

Page 16: Classwork 9 Solving the Energy Balance Equation for the ...

M.Pilotti: Classwork of Environmental Hydraulics

writeln(giorno:4,' energia immagazzinata -immessa (GJ):',energia_termica_immagazzinata-energia_radiativa_netta_immessa_MJ:10:7); trascrivi_risultati; END; Stampa_risultati; chiudi_programma; END.