diff --git a/src/+equations/Root_properties.m b/src/+equations/Root_properties.m new file mode 100644 index 00000000..f512993e --- /dev/null +++ b/src/+equations/Root_properties.m @@ -0,0 +1,16 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Subfunction - Root - Properties % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%REFERENCES +function[Rl]=Root_properties(Rl,rroot,frac,BR) +%%% INPUTS +% BR = 10:1:650; %% [gC /m^2 PFT] +% rroot = 0.5*1e-3 ; % 3.3*1e-4 ;%% [0.5-6 *10^-3] [m] root radius +%%% OUTPUTS +root_den = 250*1000; %% [gDM / m^3] Root density Jackson et al., 1997 +R_C = 0.488; %% [gC/gDM] Ratio Carbon-Dry Matter in root Jackson et al., 1997 +Delta_Rltot = BR/R_C/root_den/(pi*(rroot^2)); %% %% root length index [m root / m^2 PFT] +Delta_Rl = Delta_Rltot*frac; +Rl = Rl + Delta_Rl; +end \ No newline at end of file diff --git a/src/+equations/calc_rssrbs.m b/src/+equations/calc_rssrbs.m index 288d070f..496c8570 100644 --- a/src/+equations/calc_rssrbs.m +++ b/src/+equations/calc_rssrbs.m @@ -6,8 +6,7 @@ %elseif rss<30, %rss=30; %end -rss =11.2*exp(0.3563*100.0*(0.38-SMC)); -%rss = exp(7.9-1.6*(SMC-0.0008)/(0.38-0.0008)); +rss = exp(7.6-1.5*(SMC-0.0875)/(0.25-0.0875)); %if rss<70, % rss=70; %end diff --git a/src/+equations/fixedp_brent_ari.m b/src/+equations/fixedp_brent_ari.m index 8f7891bb..d3333941 100644 --- a/src/+equations/fixedp_brent_ari.m +++ b/src/+equations/fixedp_brent_ari.m @@ -328,7 +328,7 @@ %fprintf('Laggards: %d\n', sum(err_outside_tol)); counter = counter + 1; if (counter > iter_limit) - error('iteration limit exceeded'); + return%error('iteration limit exceeded'); end %----------------- % Now reorganize a, b, c so b is in best diff --git a/src/+equations/soil_respiration.m b/src/+equations/soil_respiration.m index 4dc759cc..39fba361 100644 --- a/src/+equations/soil_respiration.m +++ b/src/+equations/soil_respiration.m @@ -1,2 +1,2 @@ function [R] = soil_respiration(Ts) -R = 0.5+0.14375*Ts; %umol m-2 s-1 \ No newline at end of file +R = 2.5 + 0.054375*Ts; %umol m-2 s-1 \ No newline at end of file diff --git a/src/+io/bin_to_csv.m b/src/+io/bin_to_csv.m new file mode 100644 index 00000000..beb51185 --- /dev/null +++ b/src/+io/bin_to_csv.m @@ -0,0 +1,160 @@ +function bin_to_csv(fnames, V, vmax, n_col, ns, options, Ztot) +%% flu +flu_names = {'simulation_number','nu_iterations','year','DoY',... + 'Rntot','lEtot','Htot', ... + 'Rnctot','lEctot','Hctot','Actot', ... + 'Rnstot','lEstot','Hstot','Gtot','Resp', ... + 'aPAR','aPAR_Cab','aPAR/rad.PAR','aPAR_Wm2','PAR','rad.Eoutf','rad.Eoutf./fluxes.aPAR_Wm2','Trap','Evap','ET'}; +flu_units = {'','','','', ... + 'W m-2','W m-2','W m-2',... + 'W m-2','W m-2','W m-2','umol m-2 s-1',... + 'W m-2',' W m-2','W m-2','W m-2','umol m-2 s-1',... + 'umol m-2 s-1',' umol m-2 s-1','umol m-2 s-1','W m-2','umol m-2 s-1','W m-2','W m-2','cm s-1','cm s-1','cm s-1'}; +write_output(flu_names, flu_units, fnames.flu_file, n_col.flu, ns) + +%% surftemp +surftemp_names = {'simulation_number','year','DoY',... + 'Ta','Ts(1)','Ts(2)','Tcave','Tsave'}; +surftemp_units = {'','','', ... + 'C','C','C','C','C'}; +write_output(surftemp_names, surftemp_units, fnames.surftemp_file, n_col.surftemp, ns) + +%% aerodyn +aerodyn_names = {'simulation_number','year','DoY',... + 'raa','rawc','raws','ustar','rac','ras'}; +aerodyn_units = {'','','', ... + 's m-1','s m-1','s m-1', 'm s-1','s m-1','s m-1'}; +write_output(aerodyn_names, aerodyn_units, fnames.aerodyn_file, n_col.aerodyn, ns) + +%% radiation +radiation_names = {'simulation_number','year','DoY',... + 'Rin','Rli','HemisOutShort','HemisOutLong','HemisOutTot','Netshort','Netlong','Rntot'}; +radiation_units = {'','','', ... + 'W m-2','W m-2','W m-2', 'W m-2','W m-2','W m-2','W m-2','W m-2'}; +write_output(radiation_names, radiation_units, fnames.radiation_file, n_col.radiation, ns) +%% Soil temperature and moisture +Sim_Theta_names = num2str(Ztot'); +Sim_Theta_names=cellstr(Sim_Theta_names); +Sim_Theta_units ={'m-3 m-3'}; +write_output(Sim_Theta_names, Sim_Theta_units, ... +fnames.Sim_Theta_file, n_col.Sim_Theta, ns, true) +Sim_Temp_names = num2str(Ztot'); +Sim_Temp_names=cellstr(Sim_Temp_names); +Sim_Temp_units ={'oC'}; +write_output(Sim_Temp_names, Sim_Temp_units, ... +fnames.Sim_Temp_file, n_col.Sim_Temp, ns, true) +%% spectrum (added on 19 September 2008) + +spectrum_hemis_optical_names = {'hemispherically integrated radiation spectrum'}; +spectrum_hemis_optical_units = {'W m-2 um-1'}; +write_output(spectrum_hemis_optical_names, spectrum_hemis_optical_units, fnames.spectrum_hemis_optical_file, n_col.spectrum_hemis_optical, ns, true) + +spectrum_obsdir_optical_names = {'radiance spectrum in observation direction'}; +spectrum_obsdir_optical_units = {'W m-2 sr-1 um-1'}; +write_output(spectrum_obsdir_optical_names, spectrum_obsdir_optical_units, fnames.spectrum_obsdir_optical_file, n_col.spectrum_obsdir_optical, ns, true) + +if options.calc_ebal + write_output({'thermal BlackBody emission spectrum in observation direction'}, {'W m-2 sr-1 um-1'}, ... + fnames.spectrum_obsdir_BlackBody_file, n_col.spectrum_obsdir_BlackBody, ns, true) + if options.calc_planck + write_output({'thermal emission spectrum in hemispherical direction'}, {'W m-2 sr-1 um-1'}, ... + fnames.spectrum_hemis_thermal_file, n_col.spectrum_hemis_thermal, ns, true) + write_output({'thermal emission spectrum in observation direction'}, {'W m-2 sr-1 um-1'}, ... + fnames.spectrum_obsdir_thermal_file, n_col.spectrum_obsdir_thermal, ns, true) + end +end + write_output({'irradiance'}, {'W m-2 um-1'}, ... + fnames.irradiance_spectra_file, n_col.irradiance_spectra, ns, true) + write_output({'reflectance'}, {'fraction of radiation in observation direction *pi / irradiance'}, ... + fnames.reflectance_file, n_col.reflectance, ns, true) +%% input and parameter values (added June 2012) +%write_output(fnames.pars_and_input_file, true) +%write_output(fnames.pars_and_input_short_file, true) +%% Optional Output +if options.calc_vert_profiles + write_output({'Fraction leaves in the sun, fraction of observed, fraction of observed&visible per layer'}, {'rows: simulations or time steps, columns: layer numbers'}, ... + fnames.gap_file, n_col.gap, ns, true) + write_output({'aPAR per leaf layer'}, {'umol m-2 s-1'}, ... + fnames.layer_aPAR_file, n_col.layer_aPAR, ns, true) + write_output({'aPAR by Cab per leaf layer'}, {'umol m-2 s-1'}, ... + fnames.layer_aPAR_Cab_file, n_col.layer_aPAR_Cab, ns, true) + if options.calc_ebal + write_output({'leaf temperature of sunlit leaves, shaded leaves, and weighted average leaf temperature per layer'}, {'^oC ^oC ^oC'}, ... + fnames.leaftemp_file, n_col.leaftemp, ns, true) + write_output({'sensible heat flux per layer'}, {'W m-2'}, ... + fnames.layer_H_file, n_col.layer_H, ns, true) + write_output({'latent heat flux per layer'}, {'W m-2'}, ... + fnames.layer_LE_file, n_col.layer_LE, ns, true) + write_output({'photosynthesis per layer'}, {'umol m-2 s-1'}, ... + fnames.layer_A_file, n_col.layer_A, ns, true) + write_output({'average NPQ = 1-(fm-fo)/(fm0-fo0), per layer'}, {''}, ... + fnames.layer_NPQ_file, n_col.layer_NPQ, ns, true) + write_output({'net radiation per leaf layer'}, {'W m-2'}, ... + fnames.layer_Rn_file, n_col.layer_Rn, ns, true) + end +if options.calc_fluor +fluorescence_names = {'supward fluorescence per layer'}; +fluorescence_units = {'W m-2'}; +write_output(fluorescence_names, fluorescence_units, fnames.layer_fluorescence_file, n_col.layer_fluorescence, ns, true) +end +end +if options.calc_fluor + write_output({'fluorescence per simulation for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescence_file, n_col.fluorescence, ns, true) + if options.calc_PSI + write_output({'fluorescence per simulation for wavelengths of 640 to 850 nm, with 1 nm resolution, for PSI only'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescencePSI_file, n_col.fluorescencePSI, ns, true) + write_output({'fluorescence per simulation for wavelengths of 640 to 850 nm, with 1 nm resolution, for PSII only'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescencePSII_file, n_col.fluorescencePSII, ns, true) + end + write_output({'hemispherically integrated fluorescence per simulation for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1'}, ... + fnames.fluorescence_hemis_file, n_col.fluorescence_hemis, ns, true) + write_output({'total emitted fluorescence by all leaves for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1'}, ... + fnames.fluorescence_emitted_by_all_leaves_file, n_col.fluorescence_emitted_by_all_leaves, ns, true) + write_output({'total emitted fluorescence by all photosystems for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1'}, ... + fnames.fluorescence_emitted_by_all_photosystems_file, n_col.fluorescence_emitted_by_all_photosystems, ns, true) + write_output({'TOC fluorescence contribution from sunlit leaves for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescence_sunlit_file, n_col.fluorescence_sunlit, ns, true) + write_output({'TOC fluorescence contribution from shaded leaves for wavelengths of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescence_shaded_file, n_col.fluorescence_shaded, ns, true) + write_output({'TOC fluorescence contribution from from leaves and soil after scattering for wavelenghts of 640 to 850 nm, with 1 nm resolution'}, {'W m-2 um-1 sr-1'}, ... + fnames.fluorescence_scattered_file, n_col.fluorescence_scattered, ns, true) +end +write_output({'Bottom of canopy irradiance in the shaded fraction, and average BOC irradiance'}, {'First 2162 columns: shaded fraction. Last 2162 columns: average BOC irradiance. Unit: Wm-2 um-1'}, ... +fnames.BOC_irradiance_file, n_col.BOC_irradiance, ns, true) + +fclose('all'); + +%% deleting .bin +structfun(@delete, fnames) +end + +function write_output(header, units, bin_path, f_n_col, ns, not_header) + if nargin == 5 + not_header = false; + end + n_csv = strrep(bin_path, '.bin', '.csv'); + + f_csv = fopen(n_csv, 'w'); + header_str = [strjoin(header, ','), '\n']; + if not_header + header_str = ['#' header_str]; + else + % it is a header => each column must have one + assert(length(header) == f_n_col, 'Less headers than lines `%s` or n_col is wrong', bin_path) + end + fprintf(f_csv, header_str); + fprintf(f_csv, ['#' strjoin(units, ','), '\n']); + + f_bin = fopen(bin_path, 'r'); + out = fread(f_bin, 'double'); +% fclose(f_bin); % + some useconds to execution + + out_2d = reshape(out, f_n_col, ns)'; +% dlmwrite(n_csv, out_2d, '-append', 'precision', '%d'); % SLOW! + for k=1:ns + fprintf(f_csv, '%d,', out_2d(k, 1:end-1)); + fprintf(f_csv, '%d\n', out_2d(k, end)); % saves from extra comma + end +% fclose(f_csv); +end diff --git a/src/+io/create_output_files.m b/src/+io/create_output_files.m index f0b3b004..45d1182d 100644 --- a/src/+io/create_output_files.m +++ b/src/+io/create_output_files.m @@ -33,7 +33,7 @@ %% Log File for i = 1:length(parameter_file) - copyfile(['../' parameter_file{i}],[Output_dir,'Parameters/', parameter_file{i}],'f') + copyfile(['../input/' parameter_file{i}],[Output_dir,'Parameters/', parameter_file{i}],'f') end fidpath = fopen([Output_dir,'Parameters/SCOPEversion.txt'],'w'); % complete path of the SCOPE code fprintf(fidpath,'%s', path_of_code); diff --git a/src/+io/create_output_files_binary.m b/src/+io/create_output_files_binary.m new file mode 100644 index 00000000..afe4a89f --- /dev/null +++ b/src/+io/create_output_files_binary.m @@ -0,0 +1,114 @@ +function [Output_dir, f, fnames] = create_output_files_binary(parameter_file, sitename, path_of_code, input_path, spectral, options) +%% Create Output dir +string = clock; +simulation_name = char(sitename); +outdir_name = sprintf('%s_%4.0f-%02.0f-%02.0f-%02.0f%02.0f', simulation_name, string(1:5)); +Output_dir = [fullfile('../output/', outdir_name) filesep]; + +warning('off','MATLAB:DELETE:FileNotFound') +if any(~exist(Output_dir,'dir')) + mkdir(Output_dir) + mkdir([Output_dir,'Parameters' filesep]) +end + +%% Log File +for i = 1:length(parameter_file) + copy_name = [strrep(parameter_file{i}, '.csv', '') '_' outdir_name '.csv']; + copyfile([input_path parameter_file{i}],[Output_dir,'Parameters/', copy_name],'f') +end +fidpath = fopen([Output_dir,'Parameters/SCOPEversion.txt'],'w'); % complete path of the SCOPE code +fprintf(fidpath,'%s', path_of_code); + +%% Filenames, will become .csv if options is on +fnames.flu_file = fullfile(Output_dir,'fluxes.bin'); +fnames.surftemp_file = fullfile(Output_dir,'surftemp.bin'); +fnames.aerodyn_file = fullfile(Output_dir,'aerodyn.bin'); +fnames.radiation_file = fullfile(Output_dir,'radiation.bin'); +fnames.fluorescence_file = fullfile(Output_dir,'fluorescence.bin'); +fnames.wl_file = fullfile(Output_dir,'wl.bin'); % wavelength +fnames.irradiance_spectra_file = fullfile(Output_dir,'irradiance_spectra.bin'); % Fluorescence +fnames.spectrum_hemis_optical_file = fullfile(Output_dir,'spectrum_hemis.bin'); +fnames.spectrum_obsdir_optical_file = fullfile(Output_dir,'spectrum_obsdir.bin'); +fnames.reflectance_file = fullfile(Output_dir,'reflectance.bin'); % reflectance spectrum +fnames.BOC_irradiance_file = fullfile(Output_dir,'BOC_irradiance.bin'); % reflectance spectrum +fnames.Sim_Theta_file = fullfile(Output_dir,'Sim_Theta.bin'); % soil moisture +fnames.Sim_Temp_file = fullfile(Output_dir,'Sim_Temp.bin'); % soil temperature +if options.calc_ebal + fnames.spectrum_obsdir_BlackBody_file = fullfile(Output_dir,'spectrum_obsdir_BlackBody.bin'); % spectrum observation direction +end + +%if ~(options.simulation==1) +fnames.pars_and_input_file = fullfile(Output_dir,'pars_and_input.bin'); % wavelength + +%for j = 1:length(V) + % fprintf(fidv,'%s\t',V(j).Name); +%end +%fprintf(fidv,'\r'); +%end + +%if ~(options.simulation==1) +fnames.pars_and_input_short_file = fullfile(Output_dir,'pars_and_input_short.bin'); % wavelength +%for j = find(vmax>1) + % fprintf(fidvs,'%s\t',V(vmax>1).Name); +%end +%fprintf(fidvs,' \r'); +% +%% Optional Output +if options.calc_vert_profiles + fnames.gap_file = fullfile(Output_dir,'gap.bin'); % gap + fnames.leaftemp_file = fullfile(Output_dir,'leaftemp.bin'); % leaftemp + fnames.layer_H_file = fullfile(Output_dir,'layer_H.bin'); % vertical profile + fnames.layer_LE_file = fullfile(Output_dir,'layer_lE.bin'); % latent heat + fnames.layer_A_file = fullfile(Output_dir,'layer_A.bin'); % + fnames.layer_aPAR_file = fullfile(Output_dir,'layer_aPAR.bin'); % + fnames.layer_aPAR_Cab_file = fullfile(Output_dir,'layer_aPAR_Cab.bin'); % + fnames.layer_Rn_file = fullfile(Output_dir,'layer_Rn.bin'); % + if options.calc_fluor + fnames.layer_fluorescence_file = fullfile(Output_dir,'layer_fluorescence.bin'); % + fnames.layer_fluorescenceEm_file = fullfile(Output_dir,'layer_fluorescenceEm.bin'); % + fnames.layer_NPQ_file = fullfile(Output_dir,'layer_NPQ.bin'); % + end + +else + delete([Output_dir,'../output/leaftemp.bin']) + delete([Output_dir,'../output/layer_H.bin']) + delete([Output_dir,'../output/layer_lE.bin']) + delete([Output_dir,'../output/layer_A.bin']) + delete([Output_dir,'../output/layer_aPAR.bin']) + delete([Output_dir,'../output/layer_Rn.bin']) +end + +if options.calc_fluor + fnames.fluorescence_file = fullfile(Output_dir,'fluorescence.bin'); % Fluorescence + if options.calc_PSI + fnames.fluorescencePSI_file = fullfile(Output_dir,'fluorescencePSI.bin'); % Fluorescence + fnames.fluorescencePSII_file = fullfile(Output_dir,'fluorescencePSII.bin'); % Fluorescence + end + fnames.fluorescence_hemis_file = fullfile(Output_dir,'fluorescence_hemis.bin'); % Fluorescence + fnames.fluorescence_emitted_by_all_leaves_file = fullfile(Output_dir,'fluorescence_emitted_by_all_leaves.bin'); + fnames.fluorescence_emitted_by_all_photosystems_file = fullfile(Output_dir,'fluorescence_emitted_by_all_photosystems.bin'); + fnames.fluorescence_sunlit_file = fullfile(Output_dir,'fluorescence_sunlit.bin'); % Fluorescence + fnames.fluorescence_shaded_file = fullfile(Output_dir,'fluorescence_shaded.bin'); % Fluorescence + fnames.fluorescence_scattered_file = fullfile(Output_dir,'fluorescence_scattered.bin'); % Fluorescence +else + delete([Output_dir,'fluorescence.bin']) +end + +if options.calc_directional + delete([Output_dir,'BRDF/*.bin']) +end + +if options.calc_planck && options.calc_ebal + fnames.spectrum_obsdir_thermal_file = fullfile(Output_dir,'spectrum_obsdir_thermal.bin'); % spectrum observation direction + fnames.spectrum_hemis_thermal_file = fullfile(Output_dir,'spectrum_hemis_thermal.bin'); % spectrum hemispherically integrated +end +%% Open files for writing +f = structfun(@(x) fopen(x, 'w'), fnames, 'UniformOutput',false); + +%% write wl +wlS = spectral.wlS; %#ok<*NASGU> +wlF = spectral.wlF; + +save([Output_dir 'wlS.txt'], 'wlS', '-ascii'); +save([Output_dir 'wlF.txt'], 'wlF', '-ascii'); +end diff --git a/src/+io/initialize_output_structures.m b/src/+io/initialize_output_structures.m index 6b0c495c..8000f696 100644 --- a/src/+io/initialize_output_structures.m +++ b/src/+io/initialize_output_structures.m @@ -1,7 +1,6 @@ function [rad,thermal,fluxes] = initialize_output_structures(spectral) -[iter.counter ,... - fluxes.Rntot, fluxes.lEtot, fluxes.Htot, fluxes.Atot ,... +[ fluxes.Rntot, fluxes.lEtot, fluxes.Htot, fluxes.Atot ,... fluxes.Rnctot, fluxes.lEctot, fluxes.Hctot, fluxes.Actot ,... fluxes.Rnstot, fluxes.lEstot, fluxes.Hstot, fluxes.Gtot, fluxes.Resp ,... thermal.Tcave, thermal.Tsave ,... diff --git a/src/+io/load_timeseries.m b/src/+io/load_timeseries.m index a9251d94..212adda4 100644 --- a/src/+io/load_timeseries.m +++ b/src/+io/load_timeseries.m @@ -1,6 +1,6 @@ function [V,xyt,canopy] = load_timeseries(V,leafbio,soil,canopy,meteo,constants,F,xyt,path_input,options) -Dataset_dir = ['dataset ' char(F(5).FileName)]; +Dataset_dir = ''; t_file = char(F(6).FileName); year_file = char(F(7).FileName); Rin_file = char(F(8).FileName); @@ -78,7 +78,7 @@ end if ~isempty(LAI_file) LAItable = load([path_input,Dataset_dir,'/',LAI_file]); - V(22).Val = interp1(LAItable(:,1),LAItable(:,2),t_); + V(22).Val = LAItable(:,2); else V(22).Val = canopy.LAI*ones(size(time_)); end diff --git a/src/+io/output_data.m b/src/+io/output_data.m index 003cdf5f..817a45ef 100644 --- a/src/+io/output_data.m +++ b/src/+io/output_data.m @@ -17,206 +17,13 @@ function output_data(Output_dir, options, k, iter, xyt, fluxes, rad, thermal, ga fidf = fopen([Output_dir,'fluxes.dat'],'a'); fprintf(fidf,'%9.0f %9.0f %9.0f %9.4f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f',... [k iter.counter xyt.year(k) xyt.t(k) fluxes.Rntot fluxes.lEtot fluxes.Htot fluxes.Rnctot fluxes.lEctot, ... - fluxes.Hctot fluxes.Actot fluxes.Rnstot fluxes.lEstot fluxes.Hstot fluxes.Gtot fluxes.Resp 1E6*fluxes.aPAR 1E6*fluxes.aPAR_Cab fluxes.aPAR/rad.PAR fluxes.aPAR_Wm2 1E6*rad.PAR]); + fluxes.Hctot fluxes.Actot fluxes.Rnstot fluxes.lEstot fluxes.Hstot fluxes.Gtot fluxes.Resp 1E6*fluxes.aPAR,... + 1E6*fluxes.aPAR_Cab fluxes.aPAR/rad.PAR fluxes.aPAR_Wm2 1E6*rad.PAR]); if options.calc_fluor fprintf(fidf,'%9.4f %9.6f', rad.Eoutf, rad.Eoutf./fluxes.aPAR_Wm2); end fprintf(fidf,'\r'); -% surftemp -fidt = fopen([Output_dir,'surftemp.dat'],'a'); -fprintf(fidt,'%9.0f %9.0f %9.4f % 9.2f %9.2f %9.2f %9.2f %9.2f',... - [k xyt.year(k) xyt.t(k) thermal.Ta thermal.Ts(1) thermal.Ts(2) thermal.Tcave thermal.Tsave]); -fprintf(fidt,'\r'); - -% aerodyn -fidra = fopen([Output_dir,'aerodyn.dat'],'a'); -fprintf(fidra,'%15.4f %15.4f %15.4f %15.4f',[thermal.raa, thermal.rawc, thermal.raws, thermal.ustar]); -fprintf(fidra,'\r'); - -% radiation -fidr = fopen([Output_dir,'radiation.dat'],'a'); -fprintf(fidr,'%9.0f %9.0f %9.4f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f',[k xyt.year(k) xyt.t(k) meteo.Rin meteo.Rli rad.Eouto rad.Eoutt + rad.Eoutte rad.Eouto+rad.Eoutt + rad.Eoutte fluxes.Rntot]); -fprintf(fidr,'\r'); - -% spectrum (added on 19 September 2008) -fidfho = fopen([Output_dir,'spectrum_hemis_optical.dat'],'a'); -fprintf(fidfho,'%9.5f ',rad.Eout_'); -fprintf(fidfho,'\r'); - -fidfoo = fopen([Output_dir,'spectrum_obsdir_optical.dat'],'a'); -fprintf(fidfoo,'%9.5f ',rad.Lo_'); -fprintf(fidfoo,'\r'); - -if options.calc_ebal - fidto = fopen([Output_dir,'spectrum_obsdir_BlackBody.dat'],'a'); - fprintf(fidto,'%9.2f', rad.LotBB_'); - fprintf(fidto,'\r'); - - if options.calc_planck - fidplanckh = fopen([Output_dir,'spectrum_hemis_thermal.dat'],'a'); - fprintf(fidplanckh,'%9.2f', rad.Eoutte_'); - fprintf(fidplanckh,'\r'); - - fidplancko = fopen([Output_dir,'spectrum_obsdir_thermal.dat'],'a'); - fprintf(fidplancko,'%9.2f', rad.Lot_'); - fprintf(fidplancko,'\r'); - end -end - -fidsi = fopen([Output_dir,'irradiance_spectra.dat'],'a'); -fprintf(fidsi,'%10.2f',meteo.Rin*(rad.fEsuno+rad.fEskyo)'); -fprintf(fidsi,'\r'); - -fidref = fopen([Output_dir,'reflectance.dat'],'a'); -reflectance = pi*rad.Lo_./(rad.Esun_+rad.Esky_); -reflectance(spectral.wlS>3000) = NaN; -fprintf(fidref,'%9.5f',reflectance'); -fprintf(fidref,'\r'); - -% input and parameter values (added June 2012) -fidv = fopen([Output_dir,'pars_and_input.dat'],'a'); -for i = 1:length(V) - fprintf(fidv,'%12.3f',V(i).Val(vi(i))); -end -fprintf(fidv,'\r'); - -fidvs = fopen([Output_dir,'pars_and_input_short.dat'],'a'); -k2 = find(vmax>1); -for i = 1:length(k2) - fprintf(fidvs,'%9.5f ',V(k2(i)).Val(vi(k2(i)))); -end -fprintf(fidvs,' \r'); - -%% Optional Output - -if options.calc_vert_profiles - - % gap - fidgp = fopen([Output_dir,'gap.dat'],'a'); - fprintf(fidgp,'%9.2f %9.2f %9.2f',[gap.Ps gap.Po gap.Pso]); - fprintf(fidgp,'\r'); - - fidpl = fopen([Output_dir,'layer_aPAR.dat'],'a'); - fprintf(fidpl,'%9.2f',[1E6*profiles.Pn1d' 0]); - fprintf(fidpl,'\r'); - - fidplC = fopen([Output_dir,'layer_aPAR_Cab.dat'],'a'); - fprintf(fidplC,'%9.2f',[1E6*profiles.Pn1d_Cab' 0]); - fprintf(fidplC,'\r'); - - if options.calc_ebal - - % leaftemp - fidtc = fopen([Output_dir,'leaftemp.dat'],'a'); - fprintf(fidtc,'%9.2f',[profiles.Tcu1d' profiles.Tch' profiles.Tc1d']); - fprintf(fidtc,'\r'); - - fidhl = fopen([Output_dir,'layer_h.dat'],'a'); - fprintf(fidhl,'%9.2f',[profiles.Hc1d' fluxes.Hstot]); - fprintf(fidhl,'\r'); - - fidlel = fopen([Output_dir,'layer_le.dat'],'a'); - fprintf(fidlel,'%9.2f',[profiles.lEc1d' fluxes.lEstot]); - fprintf(fidlel,'\r'); - - fidal = fopen([Output_dir,'layer_a.dat'],'a'); - fprintf(fidal,'%9.2f',[profiles.A1d' fluxes.Resp]); - fprintf(fidal,'\r'); - - fidNPQ = fopen([Output_dir,'layer_NPQ.dat'],'a'); - fprintf(fidNPQ,'%9.2f',[profiles.qE' 0]); - fprintf(fidNPQ,'\r'); - - fidrn = fopen([Output_dir,'layer_rn.dat'],'a'); - fprintf(fidrn,'%9.2f',[profiles.Rn1d' fluxes.Rnstot]); - fprintf(fidrn,'\r'); - end - if options.calc_fluor - fidfll = fopen([Output_dir,'layer_fluorescence.dat'],'a'); - fprintf(fidfll,'%9.2f',profiles.fluorescence'); - fprintf(fidfll,'\r'); - end -end - -if options.calc_fluor% && options.calc_ebal - fidfl = fopen([Output_dir,'fluorescence.dat'],'a'); - if options.calc_PSI - fidfl1 = fopen([Output_dir,'fluorescencePSI.dat'],'a'); - fidfl2 = fopen([Output_dir,'fluorescencePSII.dat'],'a'); - end - fidflh = fopen([Output_dir,'fluorescence_hemis.dat'],'a'); - fidfle = fopen([Output_dir,'fluorescence_emitted_by_all_leaves.dat'],'a'); - fidfrc = fopen([Output_dir,'fluorescence_emitted_by_all_photosystems.dat'],'a'); - fidflsu = fopen([Output_dir,'fluorescence_sunlit.dat'],'a'); - fidflsh = fopen([Output_dir,'fluorescence_shaded.dat'],'a'); - fidflsc = fopen([Output_dir,'fluorescence_scattered.dat'],'a'); - - for j=1:size(spectral.wlF,1) - fprintf(fidfl,'%10.4f ',rad.LoF_); - if options.calc_PSI - fprintf(fidfl1,'%10.4f ',rad.LoF1_); - fprintf(fidfl2,'%10.4f ',rad.LoF2_); - end - fprintf(fidflh,'%10.4f ',rad.Fhem_); - fprintf(fidfle,'%10.4f ',rad.Fem_); - fprintf(fidfrc,'%10.4f ',rad.Femtot); - fprintf(fidflsu,'%10.4f ',sum(rad.LoF_sunlit,2)); - fprintf(fidflsh,'%10.4f ',sum(rad.LoF_shaded,2)); - fprintf(fidflsc,'%10.4f ',sum(rad.LoF_scattered,2)+sum(rad.LoF_soil,2)); - end - fprintf(fidfl,' \r'); - if options.calc_PSI - fprintf(fidfl1,' \r'); - fprintf(fidfl2,' \r'); - end - fprintf(fidflh,' \r'); - fprintf(fidfle,' \r'); - fprintf(fidfrc,' \r'); - fprintf(fidflsu,' \r'); - fprintf(fidflsh,' \r'); - fprintf(fidflsc,' \r'); -end - -fidp = fopen([Output_dir,'BOC_irradiance.dat'],'a'); -fprintf(fidp,'%9.0f %9.0f', rad.Emin_(61,:),rad.Emin_(61,:)+(rad.Esun_*gap.Ps(61)')'); -fprintf(fidp,'\r'); - -%% -if options.calc_directional && options.calc_ebal - Output_angle = [directional.tto'; directional.psi'; angles.tts*ones(size(directional.psi'))]; - Output_brdf = [spectral.wlS' directional.brdf_]; - if options.calc_planck - Output_temp = [spectral.wlT' directional.Lot_]; - else - Output_temp = [directional.BrightnessT]; - end - if options.calc_fluor - Output_fluor = [spectral.wlF' directional.LoF_]; - end - - save([Output_dir,'Directional/',sprintf('BRDF (SunAngle %2.2f degrees).dat',angles.tts)],'Output_brdf' ,'-ASCII','-TABS') - save([Output_dir,'Directional/',sprintf('Angles (SunAngle %2.2f degrees).dat',angles.tts)],'Output_angle','-ASCII','-TABS') - save([Output_dir,'Directional/',sprintf('Temperatures (SunAngle %2.2f degrees).dat',angles.tts)],'Output_temp','-ASCII','-TABS') - - if options.calc_fluor - save([Output_dir,'Directional/',sprintf('Fluorescence (SunAngle %2.2f degrees).dat',angles.tts)],'Output_fluor','-ASCII','-TABS') - end - - fiddirtir = fopen([Output_dir,'Directional/','read me.txt'],'w'); - fprintf(fiddirtir,'The Directional data is written in three files: \r\n'); - fprintf(fiddirtir,'\r\n- Angles: contains the directions. \r\n'); - fprintf(fiddirtir,' * The 1st row gives the observation zenith angles\r\n'); - fprintf(fiddirtir,' * The 2nd row gives the observation azimuth angles\r\n'); - fprintf(fiddirtir,' * The 3rd row gives the solar zenith angles\r\n'); - fprintf(fiddirtir,'\r\n- Temperatures: contains the directional brightness temperature. \r\n'); - fprintf(fiddirtir,' * The 1st column gives the wl values corresponding to the brightness temperature values (except for broadband)\r\n'); - fprintf(fiddirtir,' * The 2nd column gives the Tb values corresponding to the directions given by first column in the Angles file\r\n'); - fprintf(fiddirtir,'\r\n- BRDF: contains the bidirectional distribution functions values. \r\n'); - fprintf(fiddirtir,' * The 1st column gives the wl values corresponding to the BRDF values\r\n'); - fprintf(fiddirtir,' * The 2nd column gives the BRDF values corresponding to the directions given by first column in the Angles file\r\n'); - fclose(fiddirtir); -end %% fclose all; diff --git a/src/+io/output_data_binary.m b/src/+io/output_data_binary.m new file mode 100644 index 00000000..9c68e5cc --- /dev/null +++ b/src/+io/output_data_binary.m @@ -0,0 +1,226 @@ +function n_col = output_data_binary(f, k, xyt, rad, canopy, V, vi, vmax, options, fluxes, meteo, iter, thermal,spectral, gap, profiles, Sim_Theta_U, Sim_Temp, Trap, Evap) +%% OUTPUT DATA +% author C. Van der Tol +% date: 30 Nov 2019 + +%% +if isdatetime(xyt.t) + get_doy = @(x) juliandate(x) - juliandate(datetime(year(x), 1, 0)); + V(46).Val = get_doy(timestamp2datetime(xyt.startDOY)); + V(47).Val = get_doy(timestamp2datetime(xyt.endDOY)); + xyt.t = get_doy(xyt.t); +end + +%% Fluxes product +flu_out = [k iter.counter xyt.year(k) xyt.t(k) fluxes.Rntot fluxes.lEtot fluxes.Htot fluxes.Rnctot fluxes.lEctot, ... + fluxes.Hctot fluxes.Actot fluxes.Rnstot fluxes.lEstot fluxes.Hstot fluxes.Gtot fluxes.Resp 1E6*fluxes.aPAR, ... + 1E6*fluxes.aPAR_Cab fluxes.aPAR/rad.PAR fluxes.aPAR_Wm2 1E6*rad.PAR rad.Eoutf rad.Eoutf./fluxes.aPAR_Wm2 Trap(k)*10 Evap(k)*10 Trap(k)*10+Evap(k)*10]; +n_col.flu = length(flu_out); +fwrite(f.flu_file,flu_out,'double'); + +%% surftemp +surftemp_out = [k xyt.year(k) xyt.t(k) thermal.Ta thermal.Ts(1) thermal.Ts(2) thermal.Tcave thermal.Tsave]; +n_col.surftemp = length(surftemp_out); +fwrite(f.surftemp_file,surftemp_out,'double'); + +%% aerodyn +aerodyn_out = [k xyt.year(k) xyt.t(k) thermal.raa, thermal.rawc, thermal.raws, thermal.ustar, thermal.raa+thermal.rawc, thermal.raa+thermal.raws]; +n_col.aerodyn = length(aerodyn_out); +fwrite(f.aerodyn_file,aerodyn_out,'double'); + +%% radiation +radiation_out = [k xyt.year(k) xyt.t(k) meteo.Rin meteo.Rli rad.Eouto rad.Eoutt + rad.Eoutte rad.Eouto+rad.Eoutt + rad.Eoutte meteo.Rin-rad.Eouto meteo.Rli-rad.Eoutt-rad.Eoutte fluxes.Rntot]; +n_col.radiation = length(radiation_out); +fwrite(f.radiation_file,radiation_out,'double'); + +%% Soil temperature +Sim_Theta_out = [Sim_Theta_U(k,:)]; +n_col.Sim_Theta = length(Sim_Theta_out); +fwrite(f.Sim_Theta_file,Sim_Theta_out,'double'); +Sim_Temp_out = [Sim_Temp(k,:)]; +n_col.Sim_Temp = length(Sim_Temp_out); +fwrite(f.Sim_Temp_file,Sim_Temp_out,'double'); +%% spectrum (added on 19 September 2008) +spectrum_hemis_optical_out = rad.Eout_; +n_col.spectrum_hemis_optical = length(spectrum_hemis_optical_out); +fwrite(f.spectrum_hemis_optical_file,spectrum_hemis_optical_out,'double'); + +spectrum_obsdir_optical_out = [rad.Lo_']; +n_col.spectrum_obsdir_optical = length(spectrum_obsdir_optical_out); +fwrite(f.spectrum_obsdir_optical_file,spectrum_obsdir_optical_out,'double'); + +if options.calc_ebal + + spectrum_obsdir_BlackBody_out = [rad.LotBB_']; + n_col.spectrum_obsdir_BlackBody = length(spectrum_obsdir_BlackBody_out); + fwrite(f.spectrum_obsdir_BlackBody_file,spectrum_obsdir_BlackBody_out,'double'); + + if options.calc_planck + + spectrum_hemis_thermal_out = [rad.Eoutte_']; + n_col.spectrum_hemis_thermal = length(spectrum_hemis_thermal_out); + fwrite(f.spectrum_hemis_thermal_file,spectrum_hemis_thermal_out,'double'); + + spectrum_obsdir_thermal_out = [rad.Lot_']; + n_col.spectrum_obsdir_thermal = length(spectrum_obsdir_thermal_out); + fwrite(f.spectrum_obsdir_thermal_file,spectrum_obsdir_thermal_out,'double'); + + end +end + + irradiance_spectra_out = [meteo.Rin*(rad.fEsuno+rad.fEskyo)']; + n_col.irradiance_spectra = length(irradiance_spectra_out); + fwrite(f.irradiance_spectra_file,irradiance_spectra_out,'double'); + + reflectance = pi*rad.Lo_./(rad.Esun_+rad.Esky_); + reflectance(spectral.wlS>3000) = NaN; + reflectance_out = [reflectance']; + n_col.reflectance = length(reflectance_out); + fwrite(f.reflectance_file,reflectance_out,'double'); +%% input and parameter values (added June 2012) + +for i = 1:length(V) +pars_and_input_out = [V(i).Val(vi(i))]; +fwrite(f.pars_and_input_file,pars_and_input_out,'double'); +end + +k2 = find(vmax>1); +for i = 1:length(k2) +pars_and_input_short_out = [V(k2(i)).Val(vi(k2(i)))]; +fwrite(f.pars_and_input_short_file,pars_and_input_short_out,'double'); +end + +%% Optional Output + +if options.calc_vert_profiles + + % gap + gap_out = [gap.Ps gap.Po gap.Pso]; + n_col.gap = numel(gap_out(:)); + fwrite(f.gap_file,gap_out,'double'); + + layer_aPAR_out = [1E6*profiles.Pn1d' 0]; + n_col.layer_aPAR = length(layer_aPAR_out); + fwrite(f.layer_aPAR_file,layer_aPAR_out,'double'); + + layer_aPAR_Cab_out = [1E6*profiles.Pn1d_Cab' 0]; + n_col.layer_aPAR_Cab = length(layer_aPAR_Cab_out); + fwrite(f.layer_aPAR_Cab_file,layer_aPAR_Cab_out,'double'); + + if options.calc_ebal + + % leaftemp + leaftemp_out = [profiles.Tcu1d' profiles.Tch' profiles.Tc1d']; + n_col.leaftemp = length(leaftemp_out); + fwrite(f.leaftemp_file,leaftemp_out,'double'); + + layer_H_out = [profiles.Hc1d' fluxes.Hstot]; + n_col.layer_H = length(layer_H_out); + fwrite(f.layer_H_file,layer_H_out,'double'); + + layer_LE_out = [profiles.lEc1d' fluxes.lEstot]; + n_col.layer_LE = length(layer_LE_out); + fwrite(f.layer_LE_file,layer_LE_out,'double'); + + layer_A_out = [profiles.A1d' fluxes.Resp]; + n_col.layer_A = length(layer_A_out); + fwrite(f.layer_A_file,layer_A_out,'double'); + + layer_NPQ_out = [profiles.qE' 0]; + n_col.layer_NPQ = length(layer_NPQ_out); + fwrite(f.layer_NPQ_file,layer_NPQ_out,'double'); + + layer_Rn_out = [profiles.Rn1d' fluxes.Rnstot]; + n_col.layer_Rn = length(layer_Rn_out); + fwrite(f.layer_Rn_file,layer_Rn_out,'double'); + + end + if options.calc_fluor + layer_fluorescence_out = [profiles.fluorescence']; + n_col.layer_fluorescence = length(layer_fluorescence_out); + fwrite(f.layer_fluorescence_file,layer_fluorescence_out,'double'); + end +end + +if options.calc_fluor% && options.calc_ebal + for j=1:size(spectral.wlF,1) + fluorescence_out = [rad.LoF_]; + n_col.fluorescence = length(fluorescence_out); + fwrite(f.fluorescence_file,fluorescence_out,'double'); + + if options.calc_PSI + fluorescencePSI_out = [rad.LoF1_]; + n_col.fluorescencePSI = length(fluorescencePSI_out); + fwrite(f.fluorescencePSI_file,fluorescencePSI_out,'double'); + + fluorescencePSII_out = [rad.LoF2_]; + n_col.fluorescencePSII = length(fluorescencePSII_out); + fwrite(f.fluorescencePSII_file,fluorescencePSII_out,'double'); + end + + fluorescence_hemis_out = [rad.Fhem_]; + n_col.fluorescence_hemis = length(fluorescence_hemis_out); + fwrite(f.fluorescence_hemis_file,fluorescence_hemis_out,'double'); + + fluorescence_emitted_by_all_leaves_out = [rad.Fem_]; + n_col.fluorescence_emitted_by_all_leaves = length(fluorescence_emitted_by_all_leaves_out); + fwrite(f.fluorescence_emitted_by_all_leaves_file,fluorescence_emitted_by_all_leaves_out,'double'); + + fluorescence_emitted_by_all_photosystems_out = [rad.Femtot]; + n_col.fluorescence_emitted_by_all_photosystems = length(fluorescence_emitted_by_all_photosystems_out); + fwrite(f.fluorescence_emitted_by_all_photosystems_file,fluorescence_emitted_by_all_photosystems_out,'double'); + + fluorescence_sunlit_out = [sum(rad.LoF_sunlit,2)]; + n_col.fluorescence_sunlit = length(fluorescence_sunlit_out); + fwrite(f.fluorescence_sunlit_file,fluorescence_sunlit_out,'double'); + + fluorescence_shaded_out = [sum(rad.LoF_shaded,2)]; + n_col.fluorescence_shaded = length(fluorescence_shaded_out); + fwrite(f.fluorescence_shaded_file,fluorescence_shaded_out,'double'); + + fluorescence_scattered_out = [sum(rad.LoF_scattered,2)+sum(rad.LoF_soil,2)]; + n_col.fluorescence_scattered = length(fluorescence_scattered_out); + fwrite(f.fluorescence_scattered_file,fluorescence_scattered_out,'double'); + + end +end + BOC_irradiance_out = [rad.Emin_(61,:),rad.Emin_(61,:)+(rad.Esun_*gap.Ps(61)')']; + n_col.BOC_irradiance = length(BOC_irradiance_out); + fwrite(f.BOC_irradiance_file,BOC_irradiance_out,'double'); + +%% +if options.calc_directional && options.calc_ebal + Output_angle = [directional.tto'; directional.psi'; angles.tts*ones(size(directional.psi'))]; + Output_brdf = [spectral.wlS' directional.brdf_]; + if options.calc_planck + Output_temp = [spectral.wlT' directional.Lot_]; + else + Output_temp = [directional.BrightnessT]; + end + if options.calc_fluor + Output_fluor = [spectral.wlF' directional.LoF_]; + end + + save([Output_dir,'Directional/',sprintf('BRDF (SunAngle %2.2f degrees).dat',angles.tts)],'Output_brdf' ,'-ASCII','-TABS') + save([Output_dir,'Directional/',sprintf('Angles (SunAngle %2.2f degrees).dat',angles.tts)],'Output_angle','-ASCII','-TABS') + save([Output_dir,'Directional/',sprintf('Temperatures (SunAngle %2.2f degrees).dat',angles.tts)],'Output_temp','-ASCII','-TABS') + + if options.calc_fluor + save([Output_dir,'Directional/',sprintf('Fluorescence (SunAngle %2.2f degrees).dat',angles.tts)],'Output_fluor','-ASCII','-TABS') + end + + fiddirtir = fopen([Output_dir,'Directional/','read me.txt'],'w'); + fprintf(fiddirtir,'The Directional data is written in three files: \r\n'); + fprintf(fiddirtir,'\r\n- Angles: contains the directions. \r\n'); + fprintf(fiddirtir,' * The 1st row gives the observation zenith angles\r\n'); + fprintf(fiddirtir,' * The 2nd row gives the observation azimuth angles\r\n'); + fprintf(fiddirtir,' * The 3rd row gives the solar zenith angles\r\n'); + fprintf(fiddirtir,'\r\n- Temperatures: contains the directional brightness temperature. \r\n'); + fprintf(fiddirtir,' * The 1st column gives the wl values corresponding to the brightness temperature values (except for broadband)\r\n'); + fprintf(fiddirtir,' * The 2nd column gives the Tb values corresponding to the directions given by first column in the Angles file\r\n'); + fprintf(fiddirtir,'\r\n- BRDF: contains the bidirectional distribution functions values. \r\n'); + fprintf(fiddirtir,' * The 1st column gives the wl values corresponding to the BRDF values\r\n'); + fprintf(fiddirtir,' * The 2nd column gives the BRDF values corresponding to the directions given by first column in the Angles file\r\n'); + fclose(fiddirtir); +end +end diff --git a/src/+io/output_verification_csv.m b/src/+io/output_verification_csv.m new file mode 100644 index 00000000..82040ef1 --- /dev/null +++ b/src/+io/output_verification_csv.m @@ -0,0 +1,102 @@ +function output_verification_csv(Output_dir, verification_dir) +% Date: 07 August 2012 +% Author: Christiaan van der Tol (tol@itc.nl) +% output_verification.m (script) checks if the output of the latest run +% with SCOPE_v1.51 matches with a 'standard' output located in a directory +% called 'verificationdata'. If it does not, warnings will appear in the +% Matlab command window. +% The following is tested: +% - does the number of output files match? +% - does the size of the files match (number of bytes)? +% - are all files that are in the verification dataset present with the +% same file names? +% - is the content of the files exactly the same? +% If the output is different, for example because different parameter +% values have been used in the simulations, then the variables that are +% different will be plotted: the verification data in blue, and the latest +% run in red. In this way the differences can be visually inspected. + +% clc, close all +% +% directories = dir(['..' filesep 'output' filesep '*']); +% [time_value_s,I] = sort([directories(3:end).datenum]); +% Directory = directories(2+I(end)).name; +% +% Directory = Output_dir + +%% load verification data +path0_ = ['output' filesep verification_dir filesep]; +path1_ = [Output_dir filesep]; + +info0 = dir([path0_ filesep '*.csv']); %'standard' validation data (to compare with) +info1 = dir([path1_ filesep '*.csv']); %the most recent output + +[differentsize,differentcontent,differentnumberoffiles] = deal(0); + +if ~(length(info0)==length(info1)) + fprintf(['\nWarning: in the output file, ' num2str(length(info1)) ' files were stored, \r']) + fprintf(['whereas there should be ' num2str(length(info0)) ' files in this directory \r ']) + fprintf('check the simulation options that are specified the options tab of the input spreadsheet \r') + differentnumberoffiles = 1; +end + +L = length(info0); +for i = 1:L + s0 = info0(i).bytes; + n0 = info0(i).name; + for j = 1:length(info1) + k = strcmp(info1(j).name, n0); + if k, break, end + end + if k + s1 = info1(j).bytes; + if ~(s0==s1) + fprintf(['\n Warning: the file size of ' info0(i).name ' is different from the verification output \r']) + fprintf(['(' num2str(s1) ' instead of ' num2str(s0) ' bytes) \r']) + differentsize = 1; + else + if (~strcmp(info0(i).name,'pars_and_input.csv') && ~strcmp(info0(i).name,'pars_and_input_short.csv')) + D0 = dlmread([path0_ info0(i).name],',',2,0); + D1 = dlmread([path1_ info1(j).name],',',2,0); + elseif strcmp(info0(i).name,'pars_and_input_short.csv') + continue + else + D0 = dlmread([path0_ info0(i).name],',',1,0); + D1 = dlmread([path1_ info1(j).name],',',1,0); + end + if length(D0) ~= length(D1), keyboard, end + if (sum(sum(D0-D1).^2))>1E-9 + fprintf(['\nWarning: data in the output file ' info0(i).name ' are different from the verification output \r ']) + h0 = textread([path0_ info0(i).name],'%s','bufsize', 1E9); %#ok + spn = ceil(sqrt(size(D0,2))); + figure(i) + if spn>7 + nr = min(size(D1, 1), size(D0, 1)); + for z = 1:nr + plot(D0(z,:)','k'), hold on, plot(D1(z,:)','r') + end + title(info0(i).name, 'interpreter', 'none') + else + h0 = strsplit(h0{1}, ','); + for m = 1:size(D0,2) + subplot(spn,spn,m) + plot(D0(:,m),'k'), hold on, plot(D1(:,m),'r') + title([info0(i).name h0(m)], 'interpreter', 'none') + end + end + differentcontent = 1; + end + end + else + fprintf(['\nWarning: the file ' info0(i).name ' was not found in the output\r']) + end +end +if differentsize + fprintf('\nWarning The size of some of the output files is different from the verification data \r') + fprintf('Check if the startdate and enddate in the spreadsheet\r') + fprintf('and the verification data in are specified in "Dataset_Dir" in the Filenames tab of the input data spreadsheet \r') +end +if ~(differentsize || differentcontent || differentnumberoffiles) + fprintf('All right, the output is the same as in the verification data set \r') +end +end \ No newline at end of file diff --git a/src/+io/select_input.m b/src/+io/select_input.m index 689ce7f6..e2ae397b 100644 --- a/src/+io/select_input.m +++ b/src/+io/select_input.m @@ -1,5 +1,5 @@ function [soil,leafbio,canopy,meteo,angles,xyt] = select_input(V,vi,canopy,options,xyt,soil) -global Theta_LL +global Theta_LL latitude longitude soil.spectrum = V(16).Val(vi(16)); soil.rss = V(17).Val(vi(17)); soil.rs_thermal = V(18).Val(vi(18)); @@ -8,7 +8,7 @@ soil.CSSOIL = V(43).Val(vi(43)); soil.lambdas = V(21).Val(vi(21)); soil.rbs = V(44).Val(vi(44)); -soil.SMC = Theta_LL(45,1); %%%%%%% soil.SMC = flip£¨Theta_LL£©£¨:,1£© +soil.SMC = Theta_LL(54,1); %%%%%%% soil.SMC = flip£¨Theta_LL£©£¨:,1£© soil.BSMBrightness = V(61).Val(vi(61)); soil.BSMlat = V(62).Val(vi(62)); soil.BSMlon = V(63).Val(vi(63)); diff --git a/src/+io/timestamp2datetime.m b/src/+io/timestamp2datetime.m new file mode 100644 index 00000000..c01503a0 --- /dev/null +++ b/src/+io/timestamp2datetime.m @@ -0,0 +1,32 @@ +function dt = timestamp2datetime(ts) + % ts : char or char array like ['20190101'; '20190102'] + % int or int array [20190101; 20190102] + % dt : datetime or datetime array + + if isnumeric(ts) + ts = num2str(ts); + % char or char array like ['20190101'; '20190102'] + end + + switch size(ts, 2) + case 18 % SS.SSS +% error('milliseconds timestamp is not implemented due to ambiguity of reading: incomplete ts silently become NaNs') + format = 'yyyyMMddHHmmss.SSS'; + case 14 % SS + format = 'yyyyMMddHHmmss'; + case 12 % HH, HR + format = 'yyyyMMddHHmm'; + case 10 % HH (not standard) + format = 'yyyyMMddHH'; + case 8 % DD + % in this case HH == 0, MM == 0, SS == 0 + format = 'yyyyMMdd'; + case 6 % MM, WW + error('weekly and monthly timestamps are not implemented') + case 4 % YY + error('yearly timestamp is not implemented') + otherwise + error('format of timestamp is not any truncation of `yyyyMMddHHmm`') + end + dt = datetime(ts, 'InputFormat', format); +end \ No newline at end of file diff --git a/src/+plot/plots.m b/src/+plot/plots.m index a2b564e8..942aa68e 100644 --- a/src/+plot/plots.m +++ b/src/+plot/plots.m @@ -8,44 +8,30 @@ function plots(Output_dir) % Directory = directories(2+I(end)).name; %% load verification data -path1_ = ['..\output\' Output_dir ,'\']; -info1 = dir([path1_ '\*.dat']); %the most recent output +path1_ = [Output_dir]; +info1 = dir([path1_ '\*.csv']); %the most recent output L = length(info1); -wl = dlmread([path1_ 'wl.dat'],'',2,0); - -for i = 1:L-1 - s1 = info1(1).bytes; - n1 = info1(1).name; - if (strcmp(info1(i).name,'pars_and_input.dat') || ... - strcmp(info1(i).name,'pars_and_input_short.dat')) - differentcontent = 1; - continue - end - D1 = dlmread([path1_ info1(i).name],'',2,0); +%wl = dlmread([path1_ 'wl.csv'],'',2,0); +for i = 12 + %s1 = info1(1).bytes; + %n1 = info1(1).name; + %if (strcmp(info1(i).name,'pars_and_input.csv') || ... + % strcmp(info1(i).name,'pars_and_input_short.csv')) + % differentcontent = 1; + % continue + %end + %D1 = dlmread([path1_ info1(i).name],'',2,0); + D1=xlsread([path1_ info1(i).name]); spn = ceil(sqrt(size(D1,2))); - h1 = textread([path1_ info1(i).name],'%s'); + h1 = textread([path1_ info1(i).name],'%s','delimiter',','); figure(i) - if spn>7 - nl = length(D1); - for z = 1:min(47,nl) - if size(D1,1)-1==length(wl) - plot(wl,D1(z,1:end-1)'), hold on - set(gca,'xlim',[.4 2.5]) - else - if z. -%% -% try % for Compiler .exe -% clc -% clear all - -%% 0. globals -global constants -global RWU -global HR U Precip G Rn LAI Ta1 Ts1 h_v rl_min HR_a Ts Ta Tss Taa Tcc bbx RWUtot Rls frac Tsss sfactortot sfactor -run Constants -Mdata=xlsread('E:\grassland\SCOPE-master\SCOPE_v1.73\src\Meterology data','sheet1','B5:AD17572'); -Ta1=Mdata(:,1); % air temperature -HR=Mdata(:,2)./100; % relative humidity -U=Mdata(:,3); % wind speed at 2m -Precip=Mdata(:,4)./10; % precipitation -Ts1=Mdata(:,5); % soil temperature at 20cm -Ts2=Mdata(:,6); % soil temperature at 40cm -Ts3=Mdata(:,7); % soil temperature at 60cm -SMC1=Mdata(:,8); % soil moisture content at 20cm -SMC2=Mdata(:,9); % soil moisture content at 40cm -SMC3=Mdata(:,10); % soil moisture content at 60cm -G1=Mdata(:,11:13); % soil heat flux -Rn=Mdata(:,14); % net rediation -LAI=Mdata(:,26); % leaf area index -h_v=Mdata(:,27); % canopy height -rl_min=Mdata(:,28); % minimum soil resistance -%Precip=Precipi./18000; -G=ones(17568,1); -G=nanmean(G1')'; -Tsss=Mdata(:,29); -HR_a=HR; -Ta=Ta1; -Ts=Ts1; -%P_Va(KT)=0.611*exp(17.27*Ta(KT)/(Ta(KT)+237.3))*HR_a(KT); -%% 1. define constants -[constants] = io.define_constants(); - -%% 2. simulation options -path_of_code = cd; -run ../set_parameter_filenames; -% parameter_file = {'input_data.xlsx'}; % for Compiler .exe - -if length(parameter_file)>1, useXLSX = 0; else useXLSX = 1; end - -if ~useXLSX - run(['../' parameter_file{1}]) - - options.calc_ebal = N(1); % calculate the energy balance (default). If 0, then only SAIL is executed! - options.calc_vert_profiles = N(2); % calculate vertical profiles of fluxes - options.calc_fluor = N(3); % calculate chlorophyll fluorescence in observation direction - options.calc_planck = N(4); % calculate spectrum of thermal radiation - options.calc_directional = N(5); % calculate BRDF and directional temperature - options.calc_xanthophyllabs = N(6); % include simulation of reflectance dependence on de-epoxydation state - options.calc_PSI = N(7); % 0: optipar 2017 file with only one fluorescence spectrum vs 1: Franck et al spectra for PSI and PSII - options.rt_thermal = N(8); % 1: use given values under 10 (default). 2: use values from fluspect and soil at 2400 nm for the TIR range - options.calc_zo = N(9); - options.soilspectrum = N(10); %0: use soil spectrum from a file, 1: simulate soil spectrum with the BSM model - options.soil_heat_method = N(11); % 0: calculated from specific heat and conductivity (default), 1: empiricaly calibrated, 2: G as constant fraction of soil net radiation - options.Fluorescence_model = N(12); %0: empirical, with sustained NPQ (fit to Flexas' data); 1: empirical, with sigmoid for Kn; 2: Magnani 2012 model - options.calc_rss_rbs = N(13); % 0: calculated from specific heat and conductivity (default), 1: empiricaly calibrated, 2: G as constant fraction of soil net radiation - options.apply_T_corr = N(14); % correct Vcmax and rate constants for temperature in biochemical.m - options.verify = N(15); - options.save_headers = N(16); % write headers in output files - options.makeplots = N(17); - options.simulation = N(18); % 0: individual runs (specify all input in a this file) - % 1: time series (uses text files with meteo input as time series) - % 2: Lookup-Table (specify the values to be included) - % 3: Lookup-Table with random input (specify the ranges of values) -else - options = io.readStructFromExcel(['../' char(parameter_file)], 'options', 3, 1); -end - -if options.simulation>2 || options.simulation<0, fprintf('\n simulation option should be between 0 and 2 \r'); return, end - -%% 3. file names -if ~useXLSX - run(['../' parameter_file{2}]) -else - [dummy,X] = xlsread(['../' char(parameter_file)],'filenames'); - j = find(~strcmp(X(:,2),{''})); - X = X(j,(1:end)); -end - -F = struct('FileID',{'Simulation_Name','soil_file','leaf_file','atmos_file'... - 'Dataset_dir','t_file','year_file','Rin_file','Rli_file'... - ,'p_file','Ta_file','ea_file','u_file','CO2_file','z_file','tts_file'... - ,'LAI_file','hc_file','SMC_file','Vcmax_file','Cab_file','LIDF_file'}); -for i = 1:length(F) - k = find(strcmp(F(i).FileID,strtok(X(:,1)))); - if ~isempty(k) - F(i).FileName = strtok(X(k,2)); - %if i==4, F(i).FileName = strtok(X(k,2:end)); end - end -end - -%% 4. input data - -if ~useXLSX - X = textread(['../' parameter_file{3}],'%s'); %#ok - N = str2double(X); -else - [N,X] = xlsread(['../' char(parameter_file)],'inputdata', ''); - X = X(9:end,1); -end -V = io.assignvarnames(); -options.Cca_function_of_Cab = 0; - -for i = 1:length(V) - j = find(strcmp(strtok(X(:,1)),V(i).Name)); - if ~useXLSX, cond = isnan(N(j+1)); else cond = sum(~isnan(N(j,:)))<1; end - if isempty(j) || cond - if i==2 - fprintf(1,'%s %s %s \n','warning: input "', V(i).Name, '" not provided in input spreadsheet...'); - fprintf(1,'%s %s %s\n', 'I will use 0.25*Cab instead'); - options.Cca_function_of_Cab = 1; - else - - if ~(options.simulation==1) && (i==30 || i==32) - fprintf(1,'%s %s %s \n','warning: input "', V(i).Name, '" not provided in input spreadsheet...'); - fprintf(1,'%s %s %s\n', 'I will use the MODTRAN spectrum as it is'); - else - if (options.simulation == 1 || (options.simulation~=1 && (i<46 || i>50))) - fprintf(1,'%s %s %s \n','warning: input "', V(i).Name, '" not provided in input spreadsheet'); - if (options.simulation ==1 && (i==1 ||i==9||i==22||i==23||i==54 || (i>29 && i<37))) - fprintf(1,'%s %s %s\n', 'I will look for the values in Dataset Directory "',char(F(5).FileName),'"'); - else - if (i== 24 || i==25) - fprintf(1,'%s %s %s\n', 'will estimate it from LAI, CR, CD1, Psicor, and CSSOIL'); - options.calc_zo = 1; - else - if (i>38 && i<44) - fprintf(1,'%s %s %s\n', 'will use the provided zo and d'); - options.calc_zo = 0; - else - if ~(options.simulation ==1 && (i==30 ||i==32)) - fprintf(1,'%s \n', 'this input is required: SCOPE ends'); - return - else - fprintf(1,'%s %s %s\n', '... no problem, I will find it in Dataset Directory "',char(F(5).FileName), '"'); - end - end - end - end - end - end - end - end - - if ~useXLSX - j2 = []; j1 = j+1; - while 1 - if isnan(N(j1)), break, end - j2 = [j2; j1]; %#ok - j1 = j1+1; - end - if isempty(j2) - V(i).Val = -999; - else - V(i).Val = N(j2); - end - - - else - if sum(~isnan(N(j,:)))<1 - V(i).Val = -999; - else - V(i).Val = N(j,~isnan(N(j,:))); - end - end -end - -%% 5. Declare paths -path_input = '../../data/input/'; % path of all inputs - -%% 6. Numerical parameters (iteration stops etc) -iter.maxit = 600; % maximum number of iterations -iter.maxEBer = 1; %[W m-2] maximum accepted error in energy bal. -iter.Wc = 1; % Weight coefficient for iterative calculation of Tc - -%% 7. Load spectral data for leaf and soil -%opticoef = xlsread([path_input,'fluspect_parameters/',char(F(3).FileName)]); % file with leaf spectral parameters -%xlsread([path_input,'fluspect_parameters/',char(F(3).FileName)]); % file with leaf spectral parameters -load([path_input,'fluspect_parameters/',char(F(3).FileName)]); -rsfile = load([path_input,'soil_spectrum/',char(F(2).FileName)]); % file with soil reflectance spectra -% Optical coefficient data used by fluspect -% optipar.nr = opticoef(:,2); -% optipar.Kab = opticoef(:,3); -% optipar.Kca = opticoef(:,4); -% optipar.Ks = opticoef(:,5); -% optipar.Kw = opticoef(:,6); -% optipar.Kdm = opticoef(:,7); -% optipar.nw = opticoef(:,8); -% optipar.phiI = opticoef(:,9); -% optipar.phiII = opticoef(:,10); -% optipar.GSV1 = opticoef(:,11); -% optipar.GSV2 = opticoef(:,12); -% optipar.GSV3 = opticoef(:,13); -% optipar.KcaV = opticoef(:,14); -% optipar.KcaZ = opticoef(:,15); - -%% 8. Load directional data from a file -directional = struct; -if options.calc_directional - anglesfile = load([path_input,'directional/brdf_angles2.dat']); % Multiple observation angles in case of BRDF calculation - directional.tto = anglesfile(:,1); % [deg] Observation zenith Angles for calcbrdf - directional.psi = anglesfile(:,2); % [deg] Observation zenith Angles for calcbrdf - directional.noa = length(directional.tto); % Number of Observation Angles -end - -%% 9. Define canopy structure -canopy.nlayers = 60; -nl = canopy.nlayers; -canopy.x = (-1/nl : -1/nl : -1)'; % a column vector -canopy.xl = [0; canopy.x]; % add top level -canopy.nlincl = 13; -canopy.nlazi = 36; -canopy.litab = [ 5:10:75 81:2:89 ]'; % a column, never change the angles unless 'ladgen' is also adapted -canopy.lazitab = ( 5:10:355 ); % a row - -%% 10. Define spectral regions -[spectral] = io.define_bands(); - -wlS = spectral.wlS; % SCOPE 1.40 definition -wlP = spectral.wlP; % PROSPECT (fluspect) range -wlT = spectral.wlT; % Thermal range -wlF = spectral.wlF; % Fluorescence range - -I01 = find(wlSmax(wlF)); -N01 = length(I01); -N02 = length(I02); - -nwlP = length(wlP); -nwlT = length(wlT); - -nwlS = length(wlS); - -spectral.IwlP = 1 : nwlP; -spectral.IwlT = nwlP+1 : nwlP+nwlT; -spectral.IwlF = (640:850)-399; - -[rho,tau,rs] = deal(zeros(nwlP + nwlT,1)); - -%% 11. load time series data -if options.simulation == 1 - vi = ones(length(V),1); - [soil,leafbio,canopy,meteo,angles,xyt] = io.select_input(V,vi,canopy,options); - [V,xyt,canopy] = io.load_timeseries(V,leafbio,soil,canopy,meteo,constants,F,xyt,path_input,options); -else - soil = struct; -end - -%% 12. preparations -if options.simulation==1 - diff_tmin = abs(xyt.t-xyt.startDOY); - diff_tmax = abs(xyt.t-xyt.endDOY); - I_tmin = find(min(diff_tmin)==diff_tmin); - I_tmax = find(min(diff_tmax)==diff_tmax); - if options.soil_heat_method<2 - if (isempty(meteo.Ta) || meteo.Ta<-273), meteo.Ta = 20; end - soil.Tsold = meteo.Ta*ones(12,2); - end -end - -nvars = length(V); -vmax = ones(nvars,1); -for i = 1:nvars - vmax(i) = length(V(i).Val); -end -vmax([14,27],1) = 1; % these are Tparam and LIDFb -vi = ones(nvars,1); -switch options.simulation - case 0, telmax = max(vmax); [xyt.t,xyt.year]= deal(zeros(telmax,1)); - case 1, telmax = size(xyt.t,1); - case 2, telmax = prod(double(vmax)); [xyt.t,xyt.year]= deal(zeros(telmax,1)); -end -[rad,thermal,fluxes] = io.initialize_output_structures(spectral); -atmfile = [path_input 'radiationdata/' char(F(4).FileName(1))]; -atmo.M = helpers.aggreg(atmfile,spectral.SCOPEspec); - -%% 13. create output files -Output_dir = io.create_output_files(parameter_file, F, path_of_code, options, V, vmax, spectral); -%15 function MainLoop -global KT Delt_t TEND TIME MN NN NL ML ND hOLD TOLD h hh T TT P_gOLD P_g P_gg Delt_t0 -global KIT NIT TimeStep Processing -global SUMTIME hhh TTT P_ggg Theta_LLL DSTOR Thmrlefc CHK Theta_LL Theta_L -global NBCh AVAIL Evap DSTOR0 EXCESS QMT RS BCh hN hSAVE NBChh DSTMAX Soilairefc Trap sumTRAP_dir sumEVAP_dir -global TSAVE IRPT1 IRPT2 AVAIL0 TIMEOLD TIMELAST SRT ALPHA BX alpha_h bx Srt L -global QL QL_h QL_T QV Qa KL_h Chh ChT Khh KhT -global D_Vg Theta_g Sa V_A k_g MU_a DeltZ Alpha_Lg -global J Beta_g KaT_Switch Theta_s -global D_V D_A fc Eta nD POR Se -global ThmrlCondCap ZETA XK DVT_Switch -global m g MU_W Ks RHOL -global Lambda1 Lambda2 Lambda3 c_unsat Lambda_eff RHO_bulk -global RHODA RHOV c_a c_V c_L -global ETCON EHCAP -global Xaa XaT Xah RDA Rv KL_T -global DRHOVT DRHOVh DRHODAt DRHODAz -global hThmrl Tr COR IS Hystrs XWRE -global Theta_V DTheta_LLh IH -global W WW D_Ta SSUR -global W_Chg -global KLT_Switch Theta_r Alpha n CKTN trap Evapo SMC lEstot lEctot Ztot Rl -%%%%%%%%%%%%%%%%%%%%%%% Main Processing part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -run StartInit; % Initialize Temperature, Matric potential and soil air pressure. - - -%% 14. Run the model -fprintf('\n The calculations start now \r') -calculate = 1; - -for k = 1:telmax - %SMC=Theta_LL(:,1); - TIMEOLD=0; - TIMELAST=0; - KT=KT+1 % Counting Number of timesteps - if KT>1 && Delt_t>(TEND-TIME) - Delt_t=TEND-TIME; % If Delt_t is changed due to excessive change of state variables, the judgement of the last time step is excuted. - end - TIME=TIME+Delt_t; % The time elapsed since start of simulation - TimeStep(KT,1)=Delt_t; - SUMTIME(KT,1)=TIME; - Processing=TIME/TEND - %%i%%%% Updating the state variables. %%%%%%%%%%%%%%%%%%%%%%%%%%%% - if Precip(KT)>0.0005 - %7-13 9-10 p=52mm - NBChh=1; - else - NBChh=2; - end - if IRPT1==0 && IRPT2==0 - for MN=1:NN - hOLD(MN)=h(MN); - h(MN)=hh(MN); - hhh(MN,KT)=hh(MN); -% KL_h(MN,KT)=KL_h(MN,2); -% Chh(MN,KT)=Chh(MN,2); -% ChT(MN,KT)=ChT(MN,2); -% Khh(MN,KT)=Khh(MN,2); -% KhT(MN,KT)=KhT(MN,2); - - if Thmrlefc==1 - TOLD(MN)=T(MN); - T(MN)=TT(MN); - TTT(MN,KT)=TT(MN); - end - if Soilairefc==1 - P_gOLD(MN)=P_g(MN); - P_g(MN)=P_gg(MN); - P_ggg(MN,KT)=P_gg(MN); - end - if rwuef==1 - SRT(MN,KT)=Srt(MN,1); - ALPHA(MN,KT)=alpha_h(MN,1); - BX(MN,KT)=bx(MN,1); - end - end - DSTOR0=DSTOR; - if KT>1 - run SOIL1 - end - end - if options.simulation == 1, vi(vmax>1) = k; end - if options.simulation == 0, vi(vmax==telmax) = k; end - [soil,leafbio,canopy,meteo,angles,xyt] = io.select_input(V,vi,canopy,options,xyt,soil); - if options.simulation ~=1 - fprintf('simulation %i ', k ); - fprintf('of %i \n', telmax); - else - calculate = 0; - if k>=I_tmin && k<=I_tmax - quality_is_ok = ~isnan(meteo.p*meteo.Ta*meteo.ea*meteo.u.*meteo.Rin.*meteo.Rli); - fprintf('time = %4.2f \n', xyt.t(k)); - if quality_is_ok - calculate = 1; - end - end - end - - if calculate - - iter.counter = 0; - - LIDF_file = char(F(22).FileName); - if ~isempty(LIDF_file) - canopy.lidf = dlmread([path_input,'leafangles/',LIDF_file],'',3,0); - else - canopy.lidf = equations.leafangles(canopy.LIDFa,canopy.LIDFb); % This is 'ladgen' in the original SAIL model, - end - - if options.calc_PSI - fversion = @fluspect_B_CX; - else - fversion = @fluspect_B_CX_PSI_PSII_combined; - end - leafbio.V2Z = 0; - leafopt = fversion(spectral,leafbio,optipar); - leafbio.V2Z = 1; - leafoptZ = fversion(spectral,leafbio,optipar); - - IwlP = spectral.IwlP; - IwlT = spectral.IwlT; - - rho(IwlP) = leafopt.refl; - tau(IwlP) = leafopt.tran; - rlast = rho(nwlP); - tlast = tau(nwlP); - - if options.soilspectrum == 0 - rs(IwlP) = rsfile(:,soil.spectrum+1); - else - soilemp.SMC = 25; % empirical parameter (fixed) - soilemp.film = 0.015; % empirical parameter (fixed) - rs(IwlP) = BSM(soil,optipar,soilemp); - end - rslast = rs(nwlP); - - switch options.rt_thermal - case 0 - rho(IwlT) = ones(nwlT,1) * leafbio.rho_thermal; - tau(IwlT) = ones(nwlT,1) * leafbio.tau_thermal; - rs(IwlT) = ones(nwlT,1) * soil.rs_thermal; - case 1 - rho(IwlT) = ones(nwlT,1) * rlast; - tau(IwlT) = ones(nwlT,1) * tlast; - rs(IwlT) = ones(nwlT,1) * rslast; - end - leafopt.refl = rho; % extended wavelength ranges are stored in structures - leafopt.tran = tau; - - reflZ = leafopt.refl; - tranZ = leafopt.tran; - reflZ(1:300) = leafoptZ.refl(1:300); - tranZ(1:300) = leafoptZ.tran(1:300); - leafopt.reflZ = reflZ; - leafopt.tranZ = tranZ; - - soil.refl = rs; - - soil.Ts = meteo.Ta * ones(2,1); % initial soil surface temperature - - if length(F(4).FileName)>1 && options.simulation==0 - atmfile = [path_input 'radiationdata/' char(F(4).FileName(k))]; - atmo.M = helpers.aggreg(atmfile,spectral.SCOPEspec); - end - atmo.Ta = meteo.Ta; - - [rad,gap,profiles] = RTMo(spectral,atmo,soil,leafopt,canopy,angles,meteo,rad,options); - - switch options.calc_ebal - case 1 - [iter,fluxes,rad,thermal,profiles,soil,RWU,frac] ... - = ebal(iter,options,spectral,rad,gap, ... - leafopt,angles,meteo,soil,canopy,leafbio,xyt,k,profiles,LR); - - if options.calc_fluor - if options.calc_vert_profiles - [rad,profiles] = RTMf(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); - else - [rad] = RTMf(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); - end - end - if options.calc_xanthophyllabs - [rad] = RTMz(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); - end - - if options.calc_planck - rad = RTMt_planck(spectral,rad,soil,leafopt,canopy,gap,angles,thermal.Tcu,thermal.Tch,thermal.Ts(2),thermal.Ts(1),1); - end - - if options.calc_directional - directional = calc_brdf(options,directional,spectral,angles,rad,atmo,soil,leafopt,canopy,meteo,profiles,thermal); - end - - otherwise - Fc = (1-gap.Ps(1:end-1))'/nl; % Matrix containing values for Ps of canopy - fluxes.aPAR = canopy.LAI*(Fc*rad.Pnh + equations.meanleaf(canopy,rad.Pnu , 'angles_and_layers',gap.Ps));% net PAR leaves - fluxes.aPAR_Cab = canopy.LAI*(Fc*rad.Pnh_Cab + equations.meanleaf(canopy,rad.Pnu_Cab, 'angles_and_layers',gap.Ps));% net PAR leaves - [fluxes.aPAR_Wm2,fluxes.aPAR_Cab_eta] = deal(canopy.LAI*(Fc*rad.Rnh_PAR + equations.meanleaf(canopy,rad.Rnu_PAR, 'angles_and_layers',gap.Ps)));% net PAR leaves - if options.calc_fluor - profiles.etah = ones(60,1); - profiles.etau = ones(13,36,60); - if options.calc_vert_profiles - [rad,profiles] = RTMf(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); - else - [rad] = RTMf(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); - end - end - end - if options.calc_fluor % total emitted fluorescence irradiance (excluding leaf and canopy re-absorption and scattering) - if options.calc_PSI - rad.Femtot = 1E3*(leafbio.fqe(2)* optipar.phiII(spectral.IwlF) * fluxes.aPAR_Cab_eta +leafbio.fqe(1)* optipar.phiI(spectral.IwlF) * fluxes.aPAR_Cab); - else - rad.Femtot = 1E3*leafbio.fqe* optipar.phi(spectral.IwlF) * fluxes.aPAR_Cab_eta; - end - end - io.output_data(Output_dir, options, k, iter, xyt, fluxes, rad, thermal, gap, meteo, spectral, V, vi, vmax, profiles, directional, angles) - end - if options.simulation==2 && telmax>1, vi = helpers.count(nvars,vi,vmax,1); end - Ac=fluxes.Actot; - lEstot =fluxes.lEstot; - lEctot =fluxes.lEctot; - % if KT>=1933 && KT<=1991 - % Taa=20; - % Tss=20; - % else - Tss=thermal.Tsave; - Tcc=thermal.Ts(1); - Taa=thermal.Ta; - % end - - %if KT<2880 - [Rl]=Root_properties(Rl,Ac,rroot,frac,bbx,KT); - % else - %Rl=Rl; - %end - Ts(KT)=Ta1(KT); - if Delt_t~=Delt_t0 - for MN=1:NN - hh(MN)=h(MN)+(h(MN)-hOLD(MN))*Delt_t/Delt_t0; - TT(MN)=T(MN)+(T(MN)-TOLD(MN))*Delt_t/Delt_t0; - end - end - hSAVE=hh(NN); - TSAVE=TT(NN); - if NBCh==1 - hN=BCh; - hh(NN)=hN; - hSAVE=hN; - elseif NBCh==2 - if NBChh~=2 - if BCh<0 - hN=DSTOR0; - hh(NN)=hN; - hSAVE=hN; - else - hN=-1e6; - hh(NN)=hN; - hSAVE=hN; - end - end - else - if NBChh~=2 - hN=DSTOR0; - hh(NN)=hN; - hSAVE=hN; - end - end - % run Forcing_PARM -%Ts(KT)=Ts1(KT); - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - for KIT=1:NIT % Start the iteration procedure in a time step. - [hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J); - [KL_T]=CondL_T(NL); - [RHOV,DRHOVh,DRHOVT]=Density_V(TT,hh,g,Rv,NN); - [W,WW,MU_W,D_Ta]=CondL_Tdisp(POR,Theta_LL,Theta_L,SSUR,RHO_bulk,RHOL,TT,Theta_s,h,hh,W_Chg,NL,nD,J,Delt_t,Theta_g,KLT_Switch); - [L]=Latent(TT,NN); - [Xaa,XaT,Xah,DRHODAt,DRHODAz,RHODA]=Density_DA(T,RDA,P_g,Rv,DeltZ,h,hh,TT,P_gg,Delt_t,NL,NN,DRHOVT,DRHOVh,RHOV); - [c_unsat,Lambda_eff]=CondT_coeff(Theta_LL,Lambda1,Lambda2,Lambda3,RHO_bulk,Theta_g,RHODA,RHOV,c_a,c_V,c_L,NL,nD,ThmrlCondCap,ETCON,EHCAP); - [k_g]=Condg_k_g(POR,NL,J,m,Theta_g,g,MU_W,Ks,RHOL); - [D_V,Eta,D_A]=CondV_DE(Theta_LL,TT,fc,Theta_s,NL,nD,J,Theta_g,POR,ThmrlCondCap,ZETA,XK,DVT_Switch); - [D_Vg,V_A,Beta_g]=CondV_DVg(P_gg,Theta_g,Sa,V_A,k_g,MU_a,DeltZ,Alpha_Lg,KaT_Switch,Theta_s,Se,NL,J); - run h_sub; - - if NBCh==1 - DSTOR=0; - RS=0; - elseif NBCh==2 - AVAIL=-BCh; - EXCESS=(AVAIL+QMT(KT))*Delt_t; - if abs(EXCESS/Delt_t)<=1e-10,EXCESS=0;end - DSTOR=min(EXCESS,DSTMAX); - RS=(EXCESS-DSTOR)/Delt_t; - else - AVAIL=AVAIL0-Evap(KT); - EXCESS=(AVAIL+QMT(KT))*Delt_t; - if abs(EXCESS/Delt_t)<=1e-10,EXCESS=0;end - DSTOR=0; - RS=0; - end - - if Soilairefc==1 - run Air_sub; - end - - if Thmrlefc==1 - run Enrgy_sub; - end - - if max(CHK)<0.001 - break - end - hSAVE=hh(NN); - TSAVE=TT(NN); - %max(CHK) - end - TIMEOLD=KT; - %sum(sum(CHK)) - KIT - KIT=0; - [hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J); - - if IRPT1==0 && IRPT2==0 - if KT % In case last time step is not convergent and needs to be repeated. - MN=0; - - for ML=1:NL - for ND=1:2 - MN=ML+ND-1; - Theta_LLL(ML,ND,KT)=Theta_LL(ML,ND); - Theta_L(ML,ND)=Theta_LL(ML,ND); - - end - end - - %SMC = Theta_LL(:,1); - run ObservationPoints - end - if (TEND-TIME)<1E-3 - for MN=1:NN - hOLD(MN)=h(MN); - h(MN)=hh(MN); - hhh(MN,KT)=hh(MN); - if Thmrlefc==1 - TOLD(MN)=T(MN); - T(MN)=TT(MN); - TTT(MN,KT)=TT(MN); - end - if Soilairefc==1 - P_gOLD(MN)=P_g(MN); - P_g(MN)=P_gg(MN); - P_ggg(MN,KT)=P_gg(MN); - end - end - break - end - end - for MN=1:NN - QL(MN,KT)=QL(MN); - QL_h(MN,KT)=QL_h(MN); - QL_T(MN,KT)=QL_T(MN); - Qa(MN,KT)=Qa(MN); - QV(MN,KT)=QV(MN); - end - RWUtot(:,KT)=RWU; - Rls(:,KT)=Rl; - sfactortot(KT)=sfactor; - -end -% run PlotResults -%%%%%%%%%%%%%%%%%%%% postprocessing part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% plot the figures of simulation output soil moisture/temperature, -%%%% soil evaporation, plant transpiration simulated with two different -%%%% ET method (indirect ET method & direct ET method) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if Evaptranp_Cal==1 % save the variables for ETind scenario - Sim_Theta_ind=Sim_Theta; - Sim_Temp_ind=Sim_Temp; - TRAP=36000.*trap; - TRAP_ind=TRAP'; - EVAP=36000.*Evapo; - EVAP_ind=EVAP'; - disp ('Convergence Achieved for ETind scenario. Please switch to ETdir scenario and run again.') -else - TRAP=18000.*trap; - TRAP_dir=TRAP'; - EVAP=18000.*Evapo; - EVAP_dir=EVAP'; - for i=1:KT/48 - sumTRAP_ind(i)=0; %#ok<*SAGROW> - sumEVAP_ind(i)=0; - sumTRAP_dir(i)=0; - sumEVAP_dir(i)=0; - for j=(i-1)*48+1:i*48 - sumTRAP_ind(i)=TRAP_ind(j)+sumTRAP_ind(i); - sumEVAP_ind(i)=EVAP_ind(j)+sumEVAP_ind(i); - sumTRAP_dir(i)=TRAP(j)+sumTRAP_dir(i); - sumEVAP_dir(i)=EVAP(j)+sumEVAP_dir(i); - end - end -end -if options.verify - io.output_verification(Output_dir) -end - -if options.makeplots - plot.plots(Output_dir) -end - -%% for Compiler -% catch ME -% disp(['ERROR: ' ME.message]) -% end -% fprintf('\nThe run is finished. Press any key to close the window') -% fprintf('\nIf no error message was produced navigate to ./SCOPE_v1.70/output to see the results') -% pause diff --git a/src/AirPARM.m b/src/AirPARM.m index ed5b8109..a5d4e5b9 100644 --- a/src/AirPARM.m +++ b/src/AirPARM.m @@ -1,22 +1,27 @@ -function [Cah,CaT,Caa,Kah,KaT,Kaa,Vah,VaT,Vaa,Cag,QL,QL_h,QL_T,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR]=AirPARM(NL,hh,TT,Theta_LL,DeltZ,DTheta_LLh,DTheta_LLT,POR,RHOL,V_A,KL_h,D_Ta,KL_T,D_V,D_Vg,P_gg,Beta_g,J,Gamma_w,KLa_Switch,Xah,XaT,Xaa,RHODA,Hc,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR) +function [Cah,CaT,Caa,Kah,KaT,Kaa,Vah,VaT,Vaa,Cag,QL,QL_h,QL_T,QL_a,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR,DRHOVZ]=AirPARM(NL,hh,hh_frez,TT,Theta_LL,DeltZ,DTheta_LLh,DTheta_LLT,POR,RHOL,RHOV,V_A,KfL_h,D_Ta,KL_T,D_V,D_Vg,P_gg,Beta_g,Gamma_w,KLa_Switch,Xah,XaT,Xaa,RHODA,Hc,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR,DRHOVZ) for ML=1:NL - KLhBAR(ML)=(KL_h(ML,1)+KL_h(ML,2))/2; + KLhBAR(ML)=(KfL_h(ML,1)+KfL_h(ML,2))/2; KLTBAR(ML)=(KL_T(ML,1)+KL_T(ML,2))/2; - DhDZ(ML)=(hh(ML+1)-hh(ML))/DeltZ(ML); + DDhDZ(ML)=(hh(ML+1)-hh(ML))/DeltZ(ML); + DhDZ(ML)=(hh(ML+1)+hh_frez(ML+1)-hh(ML)-hh_frez(ML))/DeltZ(ML); + DTDZ(ML)=(TT(ML+1)-TT(ML))/DeltZ(ML); DPgDZ(ML)=(P_gg(ML+1)-P_gg(ML))/DeltZ(ML); DTDBAR(ML)=(D_Ta(ML,1)+D_Ta(ML,2))/2; + DRHOVZ(ML)=(RHOV(ML+1)-RHOV(ML))/DeltZ(ML); end MN=0; for ML=1:NL + J=ML; for ND=1:2 MN=ML+ND-1; if KLa_Switch==1 QL(ML)=-(KLhBAR(ML)*(DhDZ(ML)+DPgDZ(ML)/Gamma_w)+(KLTBAR(ML)+DTDBAR(ML))*DTDZ(ML)+KLhBAR(ML)); QL_h(ML)=-(KLhBAR(ML)*(DhDZ(ML)+DPgDZ(ML)/Gamma_w)+KLhBAR(ML)); + QL_a(ML)=-(KLhBAR(ML)*(DPgDZ(ML)/Gamma_w)); QL_T(ML)=-((KLTBAR(ML)+DTDBAR(ML))*DTDZ(ML)); else QL(ML)=-(KLhBAR(ML)*DhDZ(ML)+(KLTBAR(ML)+DTDBAR(ML))*DTDZ(ML)+KLhBAR(ML)); @@ -29,11 +34,11 @@ CaT(ML,ND)=XaT(MN)*(POR(J)+(Hc-1)*Theta_LL(ML,ND))+(Hc-1)*RHODA(MN)*DTheta_LLT(ML,ND); Caa(ML,ND)=Xaa(MN)*(POR(J)+(Hc-1)*Theta_LL(ML,ND)); - Kah(ML,ND)=Xah(MN)*(D_V(ML,ND)+D_Vg(ML))+Hc*RHODA(MN)*KL_h(ML,ND); + Kah(ML,ND)=Xah(MN)*(D_V(ML,ND)+D_Vg(ML))+Hc*RHODA(MN)*KfL_h(ML,ND); KaT(ML,ND)=XaT(MN)*(D_V(ML,ND)+D_Vg(ML))+Hc*RHODA(MN)*(KL_T(ML,ND)+D_Ta(ML,ND)); - Kaa(ML,ND)=Xaa(MN)*(D_V(ML,ND)+D_Vg(ML))+RHODA(MN)*(Beta_g(ML,ND)+Hc*KL_h(ML,ND)/Gamma_w);% + Kaa(ML,ND)=Xaa(MN)*(D_V(ML,ND)+D_Vg(ML))+RHODA(MN)*(Beta_g(ML,ND)+Hc*KfL_h(ML,ND)/Gamma_w);% - Cag(ML,ND)=Hc*RHODA(MN)*KL_h(ML,ND); + Cag(ML,ND)=Hc*RHODA(MN)*KfL_h(ML,ND); Vah(ML,ND)=-(V_A(ML)+Hc*QL(ML)/RHOL)*Xah(MN); %0;% VaT(ML,ND)=-(V_A(ML)+Hc*QL(ML)/RHOL)*XaT(MN); %0;% diff --git a/src/Air_Solve.m b/src/Air_Solve.m index a6ce4c9e..2e859381 100644 --- a/src/Air_Solve.m +++ b/src/Air_Solve.m @@ -1,6 +1,5 @@ function [C6,P_gg,RHS]=Air_Solve(C6,NN,NL,C6_a,RHS) - RHS(1)=RHS(1)/C6(1,1); for ML=2:NN diff --git a/src/Air_sub.m b/src/Air_sub.m index 79b01f32..1a993cca 100644 --- a/src/Air_sub.m +++ b/src/Air_sub.m @@ -1,16 +1,16 @@ function Air_sub global Cah CaT Caa Kah KaT Kaa Vah VaT Vaa Cag Xah XaT Xaa RHODA Hc -global POR D_V D_Ta D_Vg KL_T KL_h Gamma_w V_A RHOL +global POR D_V D_Ta D_Vg KL_T Gamma_w V_A RHOL global QL Theta_LL hh TT DeltZ DTheta_LLT QL_h QL_T -global NL DTheta_LLh P_gg Beta_g J +global NL DTheta_LLh P_gg Beta_g global KLhBAR KLTBAR DhDZ DTDZ DPgDZ DTDBAR KLa_Switch global C1 C2 C3 C4 C5 C6 C7 C4_a C5_a C6_a NN global Delt_t RHS T h P_g SAVE Thmrlefc global BtmPg TopPg KT -global NBCPB BCPB NBCP BCP +global NBCPB BCPB NBCP BCP QL_a DRHOVZ hh_frez RHOV KfL_h -[Cah,CaT,Caa,Kah,KaT,Kaa,Vah,VaT,Vaa,Cag,QL,QL_h,QL_T,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR]=AirPARM(NL,hh,TT,Theta_LL,DeltZ,DTheta_LLh,DTheta_LLT,POR,RHOL,V_A,KL_h,D_Ta,KL_T,D_V,D_Vg,P_gg,Beta_g,J,Gamma_w,KLa_Switch,Xah,XaT,Xaa,RHODA,Hc,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR); +[Cah,CaT,Caa,Kah,KaT,Kaa,Vah,VaT,Vaa,Cag,QL,QL_h,QL_T,QL_a,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR,DRHOVZ]=AirPARM(NL,hh,hh_frez,TT,Theta_LL,DeltZ,DTheta_LLh,DTheta_LLT,POR,RHOL,RHOV,V_A,KfL_h,D_Ta,KL_T,D_V,D_Vg,P_gg,Beta_g,Gamma_w,KLa_Switch,Xah,XaT,Xaa,RHODA,Hc,KLhBAR,KLTBAR,DhDZ,DTDZ,DPgDZ,DTDBAR,DRHOVZ); [C1,C2,C3,C4,C4_a,C5,C5_a,C6,C6_a,C7]=Air_MAT(Cah,CaT,Caa,Kah,KaT,Kaa,Vah,VaT,Vaa,Cag,DeltZ,NL,NN); diff --git a/src/CnvrgnCHK.m b/src/CnvrgnCHK.m index 483a9f65..111be060 100644 --- a/src/CnvrgnCHK.m +++ b/src/CnvrgnCHK.m @@ -1,6 +1,10 @@ -function [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS) - +%%%%%%%%inputs %%%%%%%%%%%% +%xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR +%%%%%%%% outputs %%%%%%%%%% +%KT,TIME,Delt_t,IRPT1,IRPT2,tS +function [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR) global Delt_t0 +global ISFT TT_CRIT T_CRIT T0 EPCT IRPT1=0; DxMAX=0; for ML=1:NL @@ -14,6 +18,18 @@ end end end +DuMAX=0; +for ML=1:NL + for ND=1:2 + if NBCh==1 && ML==NL && ND==2 + continue + elseif NBChB==1 && ML==1 && ND==1 + continue + else + DuMAX=max(abs(Theta_UU(ML,ND)-Theta_U(ML,ND)),DuMAX); + end + end +end DhMAX=0; for MN=1:NN @@ -25,7 +41,6 @@ DhMAX=max(abs(hh(MN)-h(MN)),DhMAX); end end - if Thmrlefc==1 DTMAX=0; for MN=1:NN @@ -41,13 +56,15 @@ IRPT2=0; -FAC1=min(xERR/DxMAX,hERR/DhMAX); +FAC1=min(xERR/DxMAX,uERR/DuMAX); + FAC2=hERR/DhMAX; +FAC1=min(FAC1,FAC2); if Thmrlefc==1 FAC=min(FAC1, TERR/DTMAX);% else FAC=FAC1; end - +ISFT=0; if FAC>6 FAC=6; Delt_t0=Delt_t; @@ -55,7 +72,7 @@ if Delt_t>1800 %original 1800s Delt_t=1800; end - return +return elseif FAC<0.25 IRPT2=1; % IRPT2=2, means the time step will be decreased; % The time step number. Repeat last time step due to excessive change of state. @@ -71,12 +88,30 @@ else Delt_t0=Delt_t; Delt_t=Delt_t*FAC; + ISFT=0; if Delt_t>1800 Delt_t=1800; end return end + ISFT=0; + + for MN=1:NN + if (TT(NN)-(TT_CRIT(NN)-T0))*(T(NN)-(T_CRIT(NN)-T0))<0 + KT=KT-1; + TIME=TIME-Delt_t; + Delt_t=Delt_t*0.25;tS=tS+1; + ISFT=1; %ISFT=0 indicator of soil thawing start; + break + elseif (TT(MN)-(TT_CRIT(MN)-T0))*(T(MN)-(T_CRIT(MN)-T0))==0 + ISFT=0; %ISFT=1 indicator of soil freezing start; + EPCT(MN)=1; + else + ISFT=0; % both soil temperatures are below zero, soil is freezing,ISFT=2 + EPCT(NN)=1; + end + end diff --git a/src/CondL_Tdisp.m b/src/CondL_Tdisp.m index a574340f..fed4ed49 100644 --- a/src/CondL_Tdisp.m +++ b/src/CondL_Tdisp.m @@ -1,12 +1,13 @@ -function [W,WW,MU_W,D_Ta]=CondL_Tdisp(POR,Theta_LL,Theta_L,SSUR,RHO_bulk,RHOL,TT,Theta_s,h,hh,W_Chg,NL,nD,J,Delt_t,Theta_g,KLT_Switch) +function [W,WW,MU_W,D_Ta]=CondL_Tdisp(POR,Theta_LL,Theta_L,SSUR,RHO_bulk,RHOL,TT,Theta_s,h,hh,W_Chg,NL,nD,Delt_t,Theta_g,KLT_Switch) MU_W0=2.4152*10^(-4); %(g.cm^-1.s^-1) MU1=4742.8; %(J.mol^-1) b=4*10^(-6); %(cm) W0=10^3; %(J.g^-1) - +%% MN=0; for ML=1:NL + J=ML; for ND=1:nD MN=ML+ND-1; if W_Chg==0 @@ -18,13 +19,26 @@ WW(ML,ND)=W0*exp(-WARG); end else - W(ML,ND)=-0.2932*h(MN)/1000;%0;% %%% J.g^-1---Original J.Kg^-1, now is divided by 1000. - WW(ML,ND)=-0.2932*hh(MN)/1000;%0;% + W(ML,ND)=-0.2932*(h(MN))/1000;%0;% +h_frez(MN) %%% J.g^-1---Original J.Kg^-1, now is divided by 1000. + WW(ML,ND)=-0.2932*(hh(MN))/1000;%0;%+hh_frez(MN) + if W(ML,ND)>=2932 + W(ML,ND)=2932; + end + if WW(ML,ND)>=2932 + WW(ML,ND)=2932; + end end f0(ML,ND)=Theta_g(ML,ND)^(7/3)/Theta_s(J)^2; %Theta_g(ML,ND)^0.67; H_W(ML,ND)=RHOL*WW(ML,ND)*(Theta_LL(ML,ND)-Theta_L(ML,ND))/((SSUR/RHO_bulk)*Delt_t); %1e3; % 1e-4J cm-2---> g s-2 ; SSUR and RHO_bulk could also be set as an array to consider more than one soil type; - MU_W(ML,ND)=MU_W0*exp(MU1/(8.31441*(TT(MN)+133.3))); - L_WT(ML,ND)=f0(ML,ND)*1e7*1.5550e-13*POR(J)*H_W(ML,ND)/(b*MU_W(ML,ND)); % kg¡¤m^-1¡¤s^-1 --> 10 g.cm^-1.s^-1; J.cm^-2---> kg.m^2.s^-2.cm^-2--> 1e7g.cm^2.s^-2.cm^-2 + if TT(MN)<-20 + MU_W(ML,ND)=3.71e-2; %L_WT(ML,ND)=0; + elseif TT(MN)>150 + MU_W(ML,ND)=1.81e-3; + else + MU_W(ML,ND)=MU_W0*exp(MU1/(8.31441*(TT(MN)+133.3))); + end + L_WT(ML,ND)=f0(ML,ND)*1e7*1.5550e-13*POR(J)*H_W(ML,ND)/(b*MU_W(ML,ND)); % kg��m^-1��s^-1 --> 10 g.cm^-1.s^-1; J.cm^-2---> kg.m^2.s^-2.cm^-2--> 1e7g.cm^2.s^-2.cm^-2 + if KLT_Switch==1 D_Ta(ML,ND)=L_WT(ML,ND)/(RHOL*(TT(MN)+273.15));%0; %0;%0; % else @@ -35,6 +49,6 @@ %% Tortuosity Factor is a reverse of the tortuosity. In "L_WT", tortuosity should be used. That is why "f0" is in the numerator.%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NOTICE: f0 in L_WT has been changed as 1.5 %%%%%%%%%%% %%%%%% kg.m^2.s^-2.cm^-2.kg.m^-3 --> 1e7g.cm^2.s^-2.cm^-2.g.cm^-3 -%%%%%% Unit of L_WT IS (kg¡¤m^-1¡¤s^-1)=-------------------------- cm^2=;(1.5548e-013 cm^2); Converting meter to centimeter here by multipling UnitC +%%%%%% Unit of L_WT IS (kg��m^-1��s^-1)=-------------------------- cm^2=;(1.5548e-013 cm^2); Converting meter to centimeter here by multipling UnitC %%%%%% m. kg.m^-1.s^-1 --> cm. g.cm^-1.s^-1 %%%%%% Please note that the Rv in MU_W should be 8.31441 J/mol.K. %%%%%%%% \ No newline at end of file diff --git a/src/CondL_h.m b/src/CondL_h.m index b56e6948..ee52c410 100644 --- a/src/CondL_h.m +++ b/src/CondL_h.m @@ -1,51 +1,360 @@ -function [Theta_LL,Se,KL_h,DTheta_LLh,J,hh]=CondL_h(Theta_r,Theta_s,Alpha,hh,n,m,Ks,NL,Theta_L,h,IS,KIT,TT,Thmrlefc,CKTN,POR,J) - -% PRN The lowest suction head (The maximum value of matric head,considering -% the negative sign before them. The absolute value of which is smallest) at which soil remains saturated. - -% PRN=-1e-6; - - MN=0; - for ML=1:NL - J=IS(ML); - for ND=1:2 - MN=ML+ND-1; - - if hh(MN)>=-1e-6 - Theta_LL(ML,ND)=Theta_s(J); - hh(MN)=-1e-6; - DTheta_LLh(ML,ND)=0; - Se(ML,ND)=1; - elseif hh(MN)<=-1e5 - Theta_LL(ML,ND)=Theta_r(J); - hh(MN)=-1e5; +function [Theta_LL,Se,KfL_h,KfL_T,DTheta_LLh,hh,hh_frez,Theta_UU,DTheta_UUh,Theta_II,KL_h]=CondL_h(Theta_r,Theta_s,Alpha,hh,hh_frez,h_frez,n,m,Ks,NL,Theta_L,h,KIT,TT,Thmrlefc,POR,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,Theta_II,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se) +global hd hm Theta_m Gama_hh +SFCC=1; +MN=0; +for ML=1:NL + % J=IS(ML); + J=ML;%hd=-1e7;hm=-9899; + for ND=1:2 + MN=ML+ND-1;%SAVEKfL_h(ML,ND)=KfL_h(ML,ND); + if SWCC==1 + if SFCC==1 + if abs(hh(MN))>=abs(hd) + Gama_hh(MN)=0; + elseif abs(hh(MN))>=abs(hm) + Gama_hh(MN)=log(abs(hd)/abs(hh(MN)))/log(abs(hd)/abs(hm)); + else + Gama_hh(MN)=1; + end + Theta_m(ML)=Gama_hh(MN)*Theta_r(J)+(Theta_s(J)-Gama_hh(MN)*Theta_r(J))*(1+abs(Alpha(J)*(-1))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + if Theta_m(ML)>=POR(J) + Theta_m(ML)=POR(J); + elseif Theta_m(ML)<=Theta_s(J) + Theta_m(ML)=Theta_s(J); + end + + if hh(MN)>=-1 + Theta_UU(ML,ND)=Theta_s(J); + DTheta_LLh(ML,ND)=0;%hh_frez(MN)=h_frez(MN); + if (hh_frez(MN))>=0 + Theta_LL(ML,ND)=Theta_s(J); + DTheta_UUh(ML,ND)=0;%Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + Se(ML,ND)=1; + else + if Thmrlefc + if (hh(MN)+hh_frez(MN))<=hd + Theta_LL(ML,ND)=0; + DTheta_UUh(ML,ND)=0;%(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=0; + else + Theta_LL(ML,ND)=Gama_hh(MN)*Theta_r(J)+(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + DTheta_UUh(ML,ND)=(-Theta_r(J))/(abs((hh(MN)+hh_frez(MN)))*log(abs(hd/hm)))*(1-(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)))-Alpha(J)*n(J)*m(J)*(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))*((1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1))*(abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)); %(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + end + + else + if abs(hh(MN)-h(MN))<1e-3 + DTheta_UUh(ML,ND)=(Theta_m(ML)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); + else + DTheta_UUh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))/(hh(MN)+hh_frez(MN)-h(MN)-h_frez(MN)); + end + end + end + else + if Thmrlefc + if Gama_hh(MN)==0 + Theta_UU(ML,ND)=0; + DTheta_LLh(ML,ND)=0;%(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + if (hh(MN)+hh_frez(MN))<=hd + Theta_LL(ML,ND)=0; + DTheta_UUh(ML,ND)=0;%(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=0; + else + Theta_LL(ML,ND)=Gama_hh(MN)*Theta_r(J)+(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + DTheta_UUh(ML,ND)=(-Theta_r(J))/(abs((hh(MN)+hh_frez(MN)))*log(abs(hd/hm)))*(1-(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)))-Alpha(J)*n(J)*m(J)*(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))*((1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1))*(abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)); %(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + end + else + Theta_UU(ML,ND)=Gama_hh(MN)*Theta_r(J)+(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))/(1+abs(Alpha(J)*hh(MN))^n(J))^m(J); + DTheta_LLh(ML,ND)=(-Theta_r(J))/(abs(hh(MN))*log(abs(hd/hm)))*(1-(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)))-Alpha(J)*n(J)*m(J)*(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))*((1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1))*(abs(Alpha(J)*hh(MN))^(n(J)-1)); %(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + if (hh(MN)+hh_frez(MN))<=hd + Theta_LL(ML,ND)=0; + DTheta_UUh(ML,ND)=0;%(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=0; + else + Theta_LL(ML,ND)=Gama_hh(MN)*Theta_r(J)+(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + DTheta_UUh(ML,ND)=(-Theta_r(J))/(abs((hh(MN)+hh_frez(MN)))*log(abs(hd/hm)))*(1-(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)))-Alpha(J)*n(J)*m(J)*(Theta_m(ML)-Gama_hh(MN)*Theta_r(J))*((1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1))*(abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)); %(Theta_s(J)-Gama_hh(MN)*Theta_a(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + end + end + else + if abs(hh(MN)-h(MN))<1e-3 + DTheta_LLh(ML,ND)=(Theta_m(ML)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)))^n(J))^(-m(J)-1); + else + DTheta_LLh(ML,ND)=(Theta_UU(ML,ND)-Theta_U(ML,ND))/(hh(MN)-h(MN)); + end + end + end + %%%%%%%%%%%%%%%%%%%% Sin function for ice calculation %%%%%%%%%%%%%%%%%%%%% + else + Tf1=273.15+1;Tf2=273.15-3;%XCAP(J)=0.23; + if hh(MN)>=-1e-6 + Theta_UU(ML,ND)=Theta_s(J); + hh(MN)=-1e-6; + DTheta_UUh(ML,ND)=0; + if TT(MN)+273.15>Tf1 + Theta_II(ML,ND)=0; + Theta_LL(ML,ND)=Theta_s(J); + + elseif TT(MN)+273.15>=Tf2 + Theta_II(ML,ND)=0.5*(1-sin(pi()*(TT(MN)+273.15-0.5*Tf1-0.5*Tf2)/(Tf1-Tf2)))*XCAP(J); + Theta_LL(ML,ND)=Theta_UU(ML,ND)-Theta_II(ML,ND)*RHOI/RHOL; + + else + Theta_II(ML,ND)=XCAP(J); + Theta_LL(ML,ND)=Theta_UU(ML,ND)-Theta_II(ML,ND)*RHOI/RHOL; + + end + if Theta_LL(ML,ND)<=0.06; + Theta_LL(ML,ND)=0.06; + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=0; + else + Theta_LL(ML,ND)=Theta_LL(ML,ND); + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + DTheta_LLh(ML,ND)=DTheta_UUh(ML,ND); + end + elseif hh(MN)<=-1e7 + Theta_UU(ML,ND)=Theta_r(J); + hh(MN)=-1e7; + DTheta_UUh(ML,ND)=0; + Theta_II(ML,ND)=0; + Theta_LL(ML,ND)=Theta_r(J); + Se(ML,ND)=0; + DTheta_LLh(ML,ND)=0; + else + Theta_UU(ML,ND)=Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*hh(MN))^n(J))^m(J); + + if Thmrlefc + DTheta_UUh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + else + if abs(hh(MN)-h(MN))<1e-3 + DTheta_UUh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + else + DTheta_UUh(ML,ND)=(Theta_UU(ML,ND)-Theta_U(ML,ND))/(hh(MN)-h(MN)); + end + end + if TT(MN)+273.15>Tf1 + Theta_II(ML,ND)=0; + Theta_LL(ML,ND)=Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + + elseif TT(MN)+273.15>=Tf2 + Theta_II(ML,ND)=0.5*(1-sin(pi()*(TT(MN)+273.15-0.5*Tf1-0.5*Tf2)/(Tf1-Tf2)))*XCAP(J); + Theta_LL(ML,ND)=Theta_UU(ML,ND)-Theta_II(ML,ND)*RHOI/RHOL;%Theta_UU(ML,ND) + + else + Theta_II(ML,ND)=XCAP(J); + Theta_LL(ML,ND)=Theta_UU(ML,ND)-Theta_II(ML,ND)*RHOI/RHOL;%Theta_UU(ML,ND) + + end + if Theta_LL(ML,ND)<=0.06; + Theta_LL(ML,ND)=0.06; + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=0; + else + Theta_LL(ML,ND)=Theta_LL(ML,ND); + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + DTheta_LLh(ML,ND)=DTheta_UUh(ML,ND); + end + + end + end + else + if hh(MN)>=Phi_s(J) + Theta_UU(ML,ND)=Theta_s(J); + hh(MN)=Phi_s(J); + DTheta_UUh(ML,ND)=0; + if hh(MN)+hh_frez(MN)<=-1e7 + Theta_LL(ML,ND)=Theta_r(J); + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=0; + elseif hh(MN)+hh_frez(MN)>=Phi_s(J) + Theta_LL(ML,ND)=Theta_s(J); + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=1; + else + Theta_LL(ML,ND)=Theta_s(J)*((hh(MN)+hh_frez(MN))/Phi_s(J))^(-1*Lamda(J));%Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + if Thmrlefc + DTheta_LLh(ML,ND)=Theta_s(J)/Phi_s(J)*((hh(MN)+hh_frez(MN))/Phi_s(J))^(-1*Lamda(J)-1);%(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); + else + if abs(hh(MN)-h(MN))<1e-3 + DTheta_LLh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); + else + DTheta_LLh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))/(hh(MN)+hh_frez(MN)-h(MN)-h_frez(MN)); + end + end + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + end + elseif hh(MN)<=-1e7 + Theta_LL(ML,ND)=Theta_r(J); + Theta_UU(ML,ND)=Theta_r(J); + Theta_II(ML,ND)=0; + hh(MN)=-1e7; + hh_frez(MN)=-1e-6; + DTheta_UUh(ML,ND)=0; DTheta_LLh(ML,ND)=0; Se(ML,ND)=0; else - Theta_LL(ML,ND)=Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*hh(MN))^n(J))^m(J); - + Theta_UU(ML,ND)=Theta_s(J)*((hh(MN))/Phi_s(J))^(-1*Lamda(J));%Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU if Thmrlefc - DTheta_LLh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + DTheta_UUh(ML,ND)=Theta_s(J)/Phi_s(J)*((hh(MN))/Phi_s(J))^(-1*Lamda(J)-1);%(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); else if abs(hh(MN)-h(MN))<1e-3 - DThehta_LL(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*hh(MN))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*hh(MN))^n(J))^(-m(J)-1); + DTheta_UUh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)))^n(J))^(-m(J)-1); else - DTheta_LLh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))/(hh(MN)-h(MN)); + DTheta_UUh(ML,ND)=(Theta_UU(ML,ND)-Theta_U(ML,ND))/(hh(MN)-h(MN)); end end - Se(ML,ND)=Theta_LL(ML,ND)/POR(J); - end + if hh(MN)+hh_frez(MN)<=-1e7 + Theta_LL(ML,ND)=Theta_r(J); + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=0; + elseif hh(MN)+hh_frez(MN)>=Phi_s(J) + Theta_LL(ML,ND)=Theta_s(J); + DTheta_LLh(ML,ND)=0; + Se(ML,ND)=1; + else + Theta_LL(ML,ND)=Theta_s(J)*((hh(MN)+hh_frez(MN))/Phi_s(J))^(-1*Lamda(J));%Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^m(J); %Theta_UU==>Theta_LL Theta_LL==>Theta_UU + if Thmrlefc + DTheta_LLh(ML,ND)=Theta_s(J)/Phi_s(J)*((hh(MN)+hh_frez(MN))/Phi_s(J))^(-1*Lamda(J)-1);%(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); + else + if abs(hh(MN)-h(MN))<1e-3 + DTheta_LLh(ML,ND)=(Theta_s(J)-Theta_r(J))*Alpha(J)*n(J)*abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^(n(J)-1)*(-m(J))*(1+abs(Alpha(J)*(hh(MN)+hh_frez(MN)))^n(J))^(-m(J)-1); + else + DTheta_LLh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))/(hh(MN)+hh_frez(MN)-h(MN)-h_frez(MN)); + end + end + Se(ML,ND)=Theta_LL(ML,ND)/POR(J); + + end + end + end + if Se(ML,ND)>=1 + Se(ML,ND)=1; + elseif Se(ML,ND)<=0 + Se(ML,ND)=0; + end + if isnan(Se(ML,ND))==1 + keyboard + end + Theta_II(ML,ND)=(Theta_UU(ML,ND)-Theta_LL(ML,ND))*RHOL/RHOI; % ice water content + if Theta_UU(ML,ND)~=0 + Ratio_ice(ML,ND)=RHOI*Theta_II(ML,ND)/(RHOL*Theta_UU(ML,ND)); % ice ratio + else + Ratio_ice(ML,ND)=0; + end -% if KIT - CKT(MN)=CKTN/(50+2.575*TT(MN)); + if KIT + MU_W0=2.4152*10^(-4); %(g.cm^-1.s^-1) + MU1=4742.8; %(J.mol^-1) + MU_WN=MU_W0*exp(MU1/(8.31441*(20+133.3))); + if TT(MN)<-20 + MU_W(ML,ND)=3.71e-2; %CKT(MN)=0.2688; + elseif TT(MN)>150 + MU_W(ML,ND)=1.81e-3; + %CKT(MN)=5.5151; % kg��m^-1��s^-1 --> 10 g.cm^-1.s^-1; J.cm^-2---> kg.m^2.s^-2.cm^-2--> 1e7g.cm^2.s^-2.cm^-2 + else + MU_W(ML,ND)=MU_W0*exp(MU1/(8.31441*(TT(MN)+133.3))); + + end + % CKT(MN)=CKTN/(50+2.575*TT(MN)); + CKT(MN)=MU_WN/MU_W(ML,ND); + if Se(ML,ND)==0 + KL_h(ML,ND)=0; + else KL_h(ML,ND)=CKT(MN)*Ks(J)*(Se(ML,ND)^(0.5))*(1-(1-Se(ML,ND)^(1/m(J)))^m(J))^2; -% else -% KL_h(ML,ND)=0; -% end + end + + CORF=1; + FILM=1; % indicator for film flow parameterization; =1, Zhang (2010); =2, Lebeau and Konrad (2010) + if FILM==1 + % %%%%%%%%% see Zhang (2010) + AGR(J)=0.00035; + + % % %%%%%%%%% see Zeng (2011) and Zhang (2010) + RHOW0=1e3;GVA=9.81; + uw0=2.4152e-5; % Pa s + u1=4.7428; % kJ mol-1 + R=8.314472; % J mol-1 K-1 + e=78.54; + e0=8.85e-12; + B_sig=235.8E-3; + Tc=647.15; + e_sig=1.256; + c_sig=-0.625; + kb=1.381e-23; %Boltzmann constant + Bi=1;Ba=1.602e-19*Bi; + uw=uw0*exp(u1/R/(TT(MN)+133.3)); + sigma=B_sig*((Tc-(TT(MN)+273.15))/Tc)^e_sig*(1+c_sig*(Tc-(TT(MN)+273.15))/Tc); + B(J)=2^0.5*pi()^2*RHOW0*GVA/uw*(e*e0/2/sigma)^1.5*(kb*(TT(MN)+273.15)/(Bi*Ba))^3; + + + Coef_f=0.0373*(2*AGR(J))^3.109; + Ks_flm(ML,ND)=B(J)*(1-POR(J))*(2*AGR(J))^0.5; %m2 + if hh(MN)<-1 + Kr(ML,ND)=Coef_f*(1+2*AGR(J)*RHOW0*GVA*abs(hh(MN)/100)/2/sigma)^(-1.5); + else + Kr(ML,ND)=1; + end + KL_h_flm(ML,ND)=Ks_flm(ML,ND)*Kr(ML,ND)*1e4; %m2 --> cm2 + else + %%%%%%%%% see sutraset --> perfilm.f based on Lebeau and Konrad (2010) + % EFFECTIVE DIAMETER + ASVL=-6e-20; + GVA=9.8; + PERMVAC=8.854e-12; %(VAC)CUM (PERM)EABILITY [PERMFS] [C2J-1M-1 OR F/M OR S4A2/KG/M3] + ELECTRC=1.602e-19; + BOTZC=1.381e-23; + RHOW0=1000; + PSICM=1000; + SWM=0.1; %THE SATURATION WHEN SURFACE ROUGHNESS OF THE SOLID GRAIN BECOMES NEGNIGIBLE (-) IT IS EQUIVALENT TO + % SATURATION BEEN 1000M FROM TULLER AND OR (2005) + RELPW=78.54; + % SWG=1; + ED=6.0*(1-POR(J))*(-ASVL/(6.0*pi()*RHOW0*GVA*PSICM))^(1.0/3.0)/POR(J)/SWM; + % FILM THICKNESS (WARNING) THIS IS NOT THE FULL PART + DEL=(RELPW*PERMVAC/(2*RHOW0*GVA))^0.50*(pi()*BOTZC*298.15/ELECTRC); + Ks_flm(ML,ND)=CORF*4.0*(1-POR(J))*DEL^3.0/pi()/ED; + if hh(MN)<=-1 + Kr(ML,ND)=(1-Se(ML,ND))*abs(hh(MN)/100)^(-1.50); + else + Kr(ML,ND)=1; + end + KL_h_flm(ML,ND)=Ks_flm(ML,ND)*Kr(ML,ND)*1e4; %m2 --> cm2 + end + if KL_h_flm(ML,ND)<=0 + KL_h_flm(ML,ND)=0; + elseif KL_h_flm(ML,ND)>=1e-6 + KL_h_flm(ML,ND)=1e-6; + end + if KL_h(ML,ND)<=1E-20 + KL_h(ML,ND)=1E-20; + end + if Gama_hh(MN)~=1 + KfL_h(ML,ND)=KL_h(ML,ND)*10^(-1*Imped(MN)*Ratio_ice(ML,ND));%+KL_h_flm(ML,ND); % hydraulic conductivity for freezing soil +% KL_h(ML,ND)=KL_h(ML,ND)+KL_h_flm(ML,ND); + else + KfL_h(ML,ND)=KL_h(ML,ND)*10^(-1*Imped(MN)*Ratio_ice(ML,ND)); % hydraulic conductivity for freezing soil + end + if isnan(KL_h(ML,ND))==1 + KL_h(ML,ND)=0; + keyboard + end + if ~isreal(KL_h(ML,ND)) + keyboard + end + KfL_T(ML,ND)=heaviside(TT_CRIT(MN)-(TT(MN)+T0))*L_f*1e4/(g*(T0)); % thermal consider for freezing soil + else + KL_h(ML,ND)=0; + KfL_h(ML,ND)=0; + KfL_T(ML,ND)=0; end end +end + + %%%%%%%%% Unit of KL_h is determined by Ks, which would be given at the%%%% %%%%%%%%% beginning.Import thing is to keep the unit of matric head hh(MN) diff --git a/src/CondT_coeff.m b/src/CondT_coeff.m index 60987bfe..148bb297 100644 --- a/src/CondT_coeff.m +++ b/src/CondT_coeff.m @@ -1,15 +1,29 @@ -function [c_unsat,Lambda_eff]=CondT_coeff(Theta_LL,Lambda1,Lambda2,Lambda3,RHO_bulk,Theta_g,RHODA,RHOV,c_a,c_V,c_L,NL,nD,ThmrlCondCap,~,~) - -global HCAP TCON SF TCA GA1 GA2 GB1 GB2 HCD -global ZETA0 CON0 PS1 PS2 ETCON EHCAP ZETA XWILT XK TT -global MN ML ND IS J POR DRHOVT L D_A Theta_V +function [c_unsat,Lambda_eff,ZETA,ETCON,EHCAP,TETCON,EfTCON]=CondT_coeff(Theta_LL,Lambda1,Lambda2,Lambda3,RHO_bulk,Theta_g,RHODA,RHOV,c_a,c_V,c_L,NL,nD,ThmrlCondCap,ThermCond,HCAP,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,POR,DRHOVT,L,D_A,Theta_V,Theta_II,TCON_dry,Theta_s,XSOC,TPS1,TPS2,TCON0,TCON_s,FEHCAP,RHOI,RHOL,c_unsat,Lambda_eff,ETCON,EHCAP,TETCON,EfTCON,ZETA) if ThmrlCondCap==1 - - [ETCON,EHCAP,ZETA,J]=EfeCapCond(HCAP,TCON,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,NL,IS,J,POR,Theta_LL,DRHOVT,L,D_A,RHOV,Theta_V); +% run EfeCapCond; + [ETCON,EHCAP,TETCON,EfTCON,ZETA]=EfeCapCond(HCAP,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,NL,POR,Theta_LL,DRHOVT,L,D_A,RHOV,Theta_V,Theta_II,TCON_dry,Theta_s,XSOC,ThermCond,TPS1,TPS2,TCON0,TCON_s,FEHCAP,RHOI,RHOL,ETCON,EHCAP,TETCON,EfTCON,ZETA); for ML=1:NL - for ND=1:nD - Lambda_eff(ML,ND)=ETCON(ML,ND); + for ND=1:nD + + if ThermCond==1 + Lambda_eff(ML,ND)=ETCON(ML,ND); + elseif ThermCond==2 + Lambda_eff(ML,ND)=EfTCON(ML,ND)/100; + elseif ThermCond==3 + Lambda_eff(ML,ND)=TETCON(ML,ND); + elseif ThermCond==4 + Lambda_eff(ML,ND)=EfTCON(ML,ND)/100; + end + + + if Lambda_eff(ML,ND)<=0 + Lambda_eff(ML,ND)=0.0008; + elseif Lambda_eff(ML,ND)>=0.02 + Lambda_eff(ML,ND)=0.02; + else + Lambda_eff(ML,ND)=Lambda_eff(ML,ND); + end c_unsat(ML,ND)=EHCAP(ML,ND); end end diff --git a/src/CondV_DE.m b/src/CondV_DE.m index 5d17c30c..667c73da 100644 --- a/src/CondV_DE.m +++ b/src/CondV_DE.m @@ -1,19 +1,22 @@ -function [D_V,Eta,D_A]=CondV_DE(Theta_LL,TT,fc,Theta_s,NL,nD,J,Theta_g,POR,ThmrlCondCap,ZETA,XK,DVT_Switch) +function [D_V,Eta,D_A]=CondV_DE(Theta_LL,TT,fc,Theta_s,NL,nD,Theta_g,POR,ThmrlCondCap,ZETA,XK,DVT_Switch,Theta_UU) MN=0; for ML=1:NL + J=ML; for ND=1:nD MN=ML+ND-1; if ThmrlCondCap - if Theta_LL(ML,ND) AVAIL Maximum rate at which water can be supplied to the soil from above during the current time step; %> %> -global alpha_h bx Srt rwuef Ts_msr - +global alpha_h bx Srt rwuef Ts_msr Tb_msr Theta_U Theta_UU Theta_I Theta_II KfL_h RHOI KfL_T Tbtm r_a_SOIL Rn_SOIL EVAP XCAP SAVEKfL_h +global Ta_msr RH_msr Rn_msr WS_msr G_msr Pg_msr HourInput Rns_msr SH_msr LE_msr DRHOVZ DTDZ DhDZ Precip_msr LAI_msr DTheta_LLh SAVETheta_UU DTheta_UUh EVAPO %SAVEDTheta_UUh alpha_h=zeros(mL,nD); %root water uptake -bx=zeros(NL,1); -bbx=zeros(NL,1); -Srt=zeros(mL,nD); - -DTheta_LLh=zeros(mL,nD); -KL_h=zeros(mL,nD); % The hydraulic conductivity(m¡¤s^-1); -KL_T=zeros(mL,nD); % The conductivity controlled by thermal gradient(m^2¡¤Cels^-1¡¤s^-1); -D_Ta=zeros(mL,nD); % The thermal dispersivity for soil water (m^2¡¤Cels^-1¡¤s^-1); +bx=zeros(mL,nD);SAVEKfL_h=zeros(mL,nD); +Srt=zeros(mL,nD);DhDZ=zeros(mL,1);DTDZ=zeros(mL,1);DRHOVZ=zeros(mL,1); DTheta_LLh=zeros(mL,nD);DTheta_UUh=zeros(mL,nD);SAVETheta_UU=zeros(mL,nD);SAVEDTheta_UUh=zeros(mL,nD);SAVEDTheta_LLh=zeros(mL,nD);SAVEDTheta_LLT=zeros(mL,nD); +Ratio_ice=zeros(mL,nD); +KL_h=zeros(mL,nD); % The hydraulic conductivity(m��s^-1); +KfL_h=zeros(mL,nD); % The hydraulic conductivity considering ice blockking effect(m��s^-1); +KfL_T=zeros(mL,nD); % The depression temperature controlled by ice(m^2��Cels^-1��s^-1); +KL_T=zeros(mL,nD); % The conductivity controlled by thermal gradient(m^2��Cels^-1��s^-1); +D_Ta=zeros(mL,nD); % The thermal dispersivity for soil water (m^2��Cels^-1��s^-1); Theta_L=zeros(mL,nD); % The soil moisture at the start of current time step; Theta_LL=zeros(mL,nD); % The soil moisture at the end of current time step; +Theta_U=zeros(mL,nD); % The total soil moisture(water+ice) at the start of current time step; +Theta_UU=zeros(mL,nD); % The total soil moisture at the end of current time step; +Theta_I=zeros(mL,nD); % The soil ice water content at the start of current time step; +Theta_II=zeros(mL,nD); % The soil ice water content at the end of current time step; Se=zeros(mL,nD); % The saturation degree of soil moisture; h=zeros(mN,1); % The matric head at the start of current time step; hh=zeros(mN,1); % The matric head at the end of current time step; +h_frez=zeros(mN,1); % The freeze depression head at the start of current time step; +hh_frez=zeros(mN,1); % The freeze depression head at the end of current time step; +XCAP=zeros(mN,1); T=zeros(mN,1); % The soil temperature at the start of current time step; TT=zeros(mN,1); % The soil temperature at the end of current time step; +T_CRIT=zeros(mN,1); % The soil ice critical temperature at the start of current time step; +TT_CRIT=zeros(mN,1); % The soil ice critical temperature at the start of current time step; +EPCT=zeros(mN,1); Theta_V=zeros(mL,nD); % Volumetric gas content; -W=zeros(mL,nD); % Differential heat of wetting at the start of current time step(J¡¤kg^-1); -WW=zeros(mL,nD); % Differential heat of wetting at the end of current time step(J¡¤kg^-1); - % Integral heat of wetting in individual time step(J¡¤m^-2); %%%%%%%%%%%%%%% Notice: the formulation of this in 'CondL_Tdisp' is not a sure. %%%%%%%%%%%%%% -MU_W=zeros(mL,nD); % Visocity of water(kg¡¤m^?6?1¡¤s^?6?1); +W=zeros(mL,nD); % Differential heat of wetting at the start of current time step(J��kg^-1); +WW=zeros(mL,nD); % Differential heat of wetting at the end of current time step(J��kg^-1); + % Integral heat of wetting in individual time step(J��m^-2); %%%%%%%%%%%%%%% Notice: the formulation of this in 'CondL_Tdisp' is not a sure. %%%%%%%%%%%%%% +MU_W=zeros(mL,nD); % Visocity of water(kg��m^?6?1��s^?6?1); f0=zeros(mL,nD); % Tortusity factor [Millington and Quirk (1961)]; kg.m^2.s^-2.m^-2.kg.m^-3 -L_WT=zeros(mL,nD); % Liquid dispersion factor in Thermal dispersivity(kg¡¤m^-1¡¤s^-1)=-------------------------- m^2 (1.5548e-013 m^2); +L_WT=zeros(mL,nD); % Liquid dispersion factor in Thermal dispersivity(kg��m^-1��s^-1)=-------------------------- m^2 (1.5548e-013 m^2); DhT=zeros(mN,1); % Difference of matric head with respect to temperature; m. kg.m^-1.s^-1 RHS=zeros(mN,1); % The right hand side part of equations in '*_EQ' subroutine; EHCAP=zeros(mL,nD); % Effective heat capacity; @@ -200,29 +212,29 @@ C6=zeros(mL,nD); % Conductivity term coefficients related to soil air pressure; C7=zeros(mN,1); % Gravity term coefficients; C9=zeros(mN,1); % root water uptake coefficients; -QL=zeros(mL,nD); % Soil moisture mass flux (kg¡¤m^-2¡¤s^-1); -QL_D=zeros(mL,nD); % Convective moisturemass flux (kg¡¤m^-2¡¤s^-1); -QL_disp=zeros(mL,nD); % Dispersive moisture mass flux (kg¡¤m^-2¡¤s^-1); -QL_h=zeros(mL,nD); % potential driven moisture mass flux (kg¡¤m^-2¡¤s^-1); -QL_T=zeros(mL,nD); % temperature driven moisture mass flux (kg¡¤m^-2¡¤s^-1); +QL=zeros(mL,nD); % Soil moisture mass flux (kg��m^-2��s^-1); +QL_D=zeros(mL,nD); % Convective moisturemass flux (kg��m^-2��s^-1); +QL_disp=zeros(mL,nD); % Dispersive moisture mass flux (kg��m^-2��s^-1); +QL_h=zeros(mL,nD); % potential driven moisture mass flux (kg��m^-2��s^-1); +QL_T=zeros(mL,nD); % temperature driven moisture mass flux (kg��m^-2��s^-1); HR=zeros(mN,1); % The relative humidity in soil pores, used for calculatin the vapor density; -RHOV_s=zeros(mN,1); % Saturated vapor density in soil pores (kg¡¤m^-3); -RHOV=zeros(mN,1); % Vapor density in soil pores (kg¡¤m^-3); +RHOV_s=zeros(mN,1); % Saturated vapor density in soil pores (kg��m^-3); +RHOV=zeros(mN,1); % Vapor density in soil pores (kg��m^-3); DRHOV_sT=zeros(mN,1); % Derivative of saturated vapor density with respect to temperature; DRHOVh=zeros(mN,1); % Derivative of vapor density with respect to matric head; DRHOVT=zeros(mN,1); % Derivative of vapor density with respect to temperature; -RHODA=zeros(mN,1); % Dry air density in soil pores(kg¡¤m^-3); -DRHODAz=zeros(mN,1); % Derivative of dry air density with respect to distance; +RHODA=zeros(mN,1); % Dry air density in soil pores(kg��m^-3); DRHODAt=zeros(mN,1); % Derivative of dry air density with respect to time; +DRHODAz=zeros(mN,1); % Derivative of dry air density with respect to distance; Xaa=zeros(mN,1); % Coefficients of derivative of dry air density with respect to temperature and matric head; XaT=zeros(mN,1); % Coefficients of derivative of dry air density with respect to temperature and matric head; Xah=zeros(mN,1); % Coefficients of derivative of dry air density with respect to temperature and matric head; -D_Vg=zeros(mL,1); % Gas phase longitudinal dispersion coefficient (m^2¡¤s^-1); -D_V=zeros(mL,nD); % Molecular diffusivity of water vapor in soil(m^2¡¤s^-1); -D_A=zeros(mN,1); % Diffusivity of water vapor in air (m^2¡¤s^-1); +D_Vg=zeros(mL,1); % Gas phase longitudinal dispersion coefficient (m^2��s^-1); +D_V=zeros(mL,nD); % Molecular diffusivity of water vapor in soil(m^2��s^-1); +D_A=zeros(mN,1); % Diffusivity of water vapor in air (m^2��s^-1); k_g=zeros(mL,nD); % Intrinsic air permeability (m^2); Sa=zeros(mL,nD); % Saturation degree of gas in soil pores; -V_A=zeros(mL,nD); % Soil air velocity (m¡¤s^-1); +V_A=zeros(mL,nD); % Soil air velocity (m��s^-1); Alpha_Lg=zeros(mL,nD); % Longitudinal dispersivity in gas phase (m); POR_C=zeros(mL,nD); % The threshold air-filled porosity; Eta=zeros(mL,nD); % Enhancement factor for thermal vapor transport in soil. @@ -242,6 +254,12 @@ Cag=zeros(mL,nD); % Gravity coefficients in dry air mass conservation equation; Lambda_eff=zeros(mL,nD); % Effective heat conductivity; c_unsat=zeros(mL,nD); % Effective heat capacity; +CTT_PH=zeros(mL,nD); % Storage coefficient in energy conservation equation related to phase change; +CTT_Lg=zeros(mL,nD); % Storage coefficient in energy conservation equation related to liquid and gas; +CTT_g=zeros(mL,nD); % Storage coefficient in energy conservation equation related to air; +CTT_LT=zeros(mL,nD); % Storage coefficient in energy conservation equation related to liquid and temperature; +EfTCON=zeros(mL,nD); % Effective heat conductivity Johansen method; +TETCON=zeros(mL,nD); % Effective heat conductivity Johansen method; L=zeros(mN,1); % The latent heat of vaporization at the beginning of the time step; LL=zeros(mN,1); % The latent heat of vaporization at the end of the time step; CTh=zeros(mL,nD); % Storage coefficient in energy conservation equation related to matric head; @@ -270,14 +288,20 @@ Ts=zeros(Nmsrmn,1); % Surface temperature; U=zeros(Nmsrmn,1); % Wind speed (m.s^-1); HR_a=zeros(Nmsrmn,1); % Air relative humidity; -Rns=zeros(Nmsrmn,1); % Net shortwave radiation(W¡¤m^-2); -Rnl=zeros(Nmsrmn,1); % Net longwave radiation(W¡¤m^-2); +Rns=zeros(Nmsrmn,1); % Net shortwave radiation(W��m^-2); +Rnl=zeros(Nmsrmn,1); % Net longwave radiation(W��m^-2); Rn=zeros(Nmsrmn,1); h_SUR=zeros(Nmsrmn,1); % Observed matric potential at surface; -SH=zeros(Nmsrmn,1); % Sensible heat (W¡¤m^-2); +SH=zeros(Nmsrmn,1); % Sensible heat (W��m^-2); MO=zeros(Nmsrmn,1); % Monin-Obukhov's stability parameter (MO Length); Zeta_MO=zeros(Nmsrmn,1); % Atmospheric stability parameter; TopPg=zeros(Nmsrmn,1); % Atmospheric pressure above the surface as the boundary condition (Pa); +Tp_t=zeros(Nmsrmn/10,1); +Evap=zeros(Nmsrmn/10,1); +Tbtm=zeros(Nmsrmn/10,1); +r_a_SOIL=zeros(Nmsrmn/10,1); +Rn_SOIL=zeros(Nmsrmn/10,1); +EVAP=zeros(Nmsrmn/10,1); QL_Dts=zeros(mL,1); % Convective moisture mass flux in one time step; QL_dispts=zeros(mL,1); % Dispersive moisture mass flux in one time step; QLts=zeros(mL,1); % Total moisture mass flux in one time step; @@ -298,60 +322,90 @@ hOLD=zeros(mN,1); % Array used to get the matric head at the end of last time step and extraplot the matric head at the start of current time step; TOLD=zeros(mN,1); % The same meanings of hOLD,but for temperature; P_gOLD=zeros(mN,1); % The same meanins of TOLD,but for soil air pressure; +% QV=zeros(mL,1); % Diffusive vapor mass flux; +DRHOVhDz=zeros(mL,1); +% DhDZ=zeros(mL,1); +EtaBAR=zeros(mL,1); +% D_Vg=zeros(mL,1); +DRHOVTDz=zeros(mL,1); +% DTDZ=zeros(mL,1); +KLhBAR=zeros(mL,1); +DEhBAR=zeros(mL,1); +KLTBAR=zeros(mL,1); +DTDBAR=zeros(mL,1); +QLH=zeros(mL,1); +QLT=zeros(mL,1); +DVH=zeros(mL,1); +DVT=zeros(mL,1); +QVH=zeros(mL,1); +QVT=zeros(mL,1); +QV=zeros(mL,1);QVa=zeros(mL,1);Qa=zeros(mL,1);DPgDZ=zeros(mL,1); +QL_a=zeros(mL,1); Ksoil=zeros(ML,1); -Rl=ones(ML,1)*150; +%Rl=zeros(ML,1); SMC=zeros(ML,1); -DeltZ_R=zeros(ML,1); -Theta_o=ones(ML,1); +bbx=zeros(ML,1); +%DeltZ_R=zeros(ML,1); +%Theta_o=ones(ML,1); +%Theta_s=ones(ML,1); +%Theta_r=ones(ML,1); frac=zeros(ML,1); wfrac=zeros(ML,1); -RWUtot=zeros(ML,17568); -Rls=zeros(ML,17568); -Tatot=zeros(17568,1); +RWUtot=zeros(ML,Nmsrmn/10); +RWUtott=zeros(1,Nmsrmn/10); +RWUtottt=zeros(1,Nmsrmn/10); +EVAPO=zeros(1,Nmsrmn/10); +Rls=zeros(ML,Nmsrmn/10); +Tatot=zeros(Nmsrmn/10,1); LR=0; -PSItot=zeros(17568,1); -sfactortot=zeros(17568,1); +PSItot=zeros(Nmsrmn/10,1); +sfactortot=zeros(Nmsrmn/10,1); +Tsur=zeros(Nmsrmn/10,1); +Ztot=zeros(ML,1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%% The indicators needs to be set before the running of this program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% J=1; % Indicator denotes the index of soil type for choosing soil physical parameters; % -rwuef=0; -Evaptranp_Cal=2; % Indicator denotes the method of estimating evapotranspiration; +rwuef=1; +HourInput=1; +SWCC=1; % indicator for choose the soil water characteristic curve, =0, Clapp and Hornberger; =1, Van Gen; +Evaptranp_Cal=3; % Indicator denotes the method of estimating evapotranspiration; % Value of 1 means the ETind method, otherwise, ETdir method; UseTs_msrmn=1; % Value of 1 means the measurement Ts would be used; Otherwise, 0; % Msrmn_Fitting=1; % Value of 1 means the measurement data is used to fit the simulations; -Hystrs=1; % If the value of Hystrs is 1, then the hysteresis is considered, otherwise 0; % +Hystrs=0; % If the value of Hystrs is 1, then the hysteresis is considered, otherwise 0; % Thmrlefc=1; % Consider the isothermal water flow if the value is 0, otherwise 1; % -Soilairefc=1; % The dry air transport is considered with the value of 1,otherwise 0; % +Soilairefc=0; % The dry air transport is considered with the value of 1,otherwise 0; % hThmrl=1; % Value of 1, the special calculation of water capacity is used, otherwise 0; % h_TE=0; % Value of 1 means that the temperature dependence % % of matric head would be considered.Otherwise,0; % W_Chg=1; % Value of 0 means that the heat of wetting would % - % be calculated by Milly's method£¬Otherwise,1. The % + % be calculated by Milly's method��Otherwise,1. The % % method of Lyle Prunty would be used; % ThmrlCondCap=1; %1; % The indicator for choosing Milly's effective thermal capacity and conductivity % % formulation to verify the vapor and heat transport in extremly dry soil. % +% ThmrlCond=1; % The indicator for choosing effective thermal conductivity methods, 1= de vries method;2= Jonhansen methods +ThermCond=1; % The indicator for choosing effective thermal conductivity methods, 1= de vries method;2= Jonhansen methods;3= Simplified de vries method(Tian 2016);4= Farouki methods +% SWCC=1; % indicator for choose the soil water characteristic curve, =0, Clapp and Hornberger; =1, Van Gen; +CHST=0; % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use +ISOC=1; % Indicator of considering soil organic matter effect or not. ISOC=1, yes; ISOC=0 no %%%%% 172 27%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -SaturatedK=[12/(3600*24) 68/(3600*24)]; % Saturation hydraulic conductivity (cm.s^-1); -SaturatedMC=[0.38 0.43]; % Saturated water content; -ResidualMC=[0.0008 0.045]; % The residual water content of soil; -Coefficient_n=[1.5 2.68]; % Coefficient in VG model; -Coefficient_Alpha=[0.00166 0.145]; % Coefficient in VG model; -porosity=[0.50 0.45]; % Soil porosity; +run soilpropertyread %load soil property CKTN=(50+2.575*20); % Constant used in calculating viscosity factor for hydraulic conductivity l=0.5; % Coefficient in VG model; g=981; % Gravity acceleration (cm.s^-2); RHOL=1; % Water density (g.cm^-3); +RHOI=0.92; % Ice density (g.cm^-3); SSUR=10^5; % Surface area for loam,for sand 10^2 (cm^-1); Rv=461.5*1e4; % (cm^2.s^-2.Cels^-1)Gas constant for vapor (original J.kg^-1.Cels^-1); RDA=287.1*1e4; % (cm^2.s^-2.Cels^-1)Gas constant for dry air (original J.kg^-1.Cels^-1); -RHO_bulk=1.4; % Bulk density of sand (g.cm^-3); -fc=0.036; % The fraction of clay,for loam,0.036; for sand,0.02; +RHO_bulk=1.25; % Bulk density of sand (g.cm^-3); +fc=0.022; % The fraction of clay,for loam,0.036; for sand,0.02; Unit_C=1; % Change the mH2O into (kg.m^-1.s^-2) %101325/10.3; UnitC=100; % Change of meter into centimeter; Hc=0.02; % Henry's constant; GWT=7; % The gain factor(dimensionless),which assesses the temperature -rroot=1.5*1e-3; % dependence of the soil water retention curve is set as 7 for + % dependence of the soil water retention curve is set as 7 for % sand (Noborio et al, 1996); MU_a=1.846*10^(-4); % (g.cm^-1.s^-1)Viscosity of air (original 1.846*10^(-5)kg.m^-1.s^-1); Gamma0=71.89; % The surface tension of soil water at 25 Cels degree. (g.s^-2); @@ -365,55 +419,72 @@ W0=1.001*10^3; % Coefficient for calculating differential heat of wetting by Milly's method L0=597.3*4.182; Tr=20; % Reference temperature -c_L=4.186; % Specific heat capacity of liquid water (J¡¤g^-1¡¤Cels^-1) %%%%%%%%% Notice the original unit is 4186kg^-1 -c_V=1.870; % Specific heat capacity of vapor (J¡¤g^-1¡¤Cels^-1) -c_a=1.255e-3; -%c_a=1.005; % 0.0003*4.186; %Specific heat capacity of dry air (J¡¤g^-1¡¤Cels^-1) -Gsc=1360; % The solar constant (1360 W¡¤m^-2) -Sigma_E=4.90*10^(-9); % The stefan-Boltzman constant.(=4.90*10^(-9) MJ¡¤m^-2¡¤Cels^-4¡¤d^-1) -P_g0=951978.50; % The mean atmospheric pressure (Should be given in new simulation period subroutine.) - +c_L=4.186; % Specific heat capacity of liquid water (J��g^-1��Cels^-1) %%%%%%%%% Notice the original unit is 4186kg^-1 +c_V=1.870; % Specific heat capacity of vapor (J��g^-1��Cels^-1) +c_a=1.005; +%c_a=1.005; % 0.0003*4.186; %Specific heat capacity of dry air (J��g^-1��Cels^-1) +c_i=2.0455; % Specific heat capacity of ice (J��g^-1��Cels^-1) +Gsc=1360; % The solar constant (1360 W��m^-2) +Sigma_E=4.90*10^(-9); % The stefan-Boltzman constant.(=4.90*10^(-9) MJ��m^-2��Cels^-4��d^-1) +P_g0=95197.850;%951978.50; % The mean atmospheric pressure (Should be given in new simulation period subroutine.) +rroot=1.5*1e-3; +RTB=1000; %initial root total biomass (g) +Precipp=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Input for producing initial soil moisture and soil temperature profile %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -InitND1=20; % Unit of it is cm. These variables are used to indicated the depth corresponding to the measurement. -InitND2=40; +Mdata=textread('../input/Mdata.txt'); +Ta_msr=Mdata(:,2)'; +RH_msr=Mdata(:,3)'; +WS_msr=Mdata(:,4)'; +Pg_msr=Mdata(:,5)'; +Rn_msr=Mdata(:,7)'; +Rns_msr=Mdata(:,7)'; +VPD_msr=Mdata(:,9)'; +LAI_msr=Mdata(:,10)'; +G_msr=Mdata(:,7)'*0.15; +Ts_msr=Mdata(:,2)'; +Precip_msr=Mdata(:,6)'*10*DELT; +Tmin=min(Ts_msr); +InitND1=5; % Unit of it is cm. These variables are used to indicated the depth corresponding to the measurement. +InitND2=30; InitND3=60; -InitND4=200; -InitND5=300; -% Measured temperature at InitND1 depth at the start of simulation period -InitT0= 9.89; -InitT1= 10.76714; -InitT2= 11.82195; -InitT3= 11.9841; -InitT4= 12.0; -InitT5= 12.6841; -BtmT=16.6; -InitX0= 0.2181060; -InitX1= 0.2227298; % Measured soil moisture content -InitX2= 0.2131723; -InitX3= 0.1987298; -InitX4= 0.1727298; -InitX5= 0.16; -BtmX=0.16;%0.05; % The initial moisture content at the bottom of the column. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% The measured soil moisture and tempeature data here -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if Msrmn_Fitting -%20, 40, 60, 80, 100cm -Xdata=xlsread('E:\grassland\SCOPE-master\SCOPE_v1.73\src\INPUT_2013_YM_HOUR','sheet1','a3:s2450'); -Xdata=Xdata'; -Msr_Mois=0.01.*[Xdata(13,:);Xdata(14,:);Xdata(15,:);Xdata(16,:);Xdata(17,:)]; -%20, 40, 60, 80, 100cm -Msr_Temp=[Xdata(4,:);Xdata(5,:);Xdata(6,:);Xdata(7,:);Xdata(8,:)]; -Msr_Time=3600.*Xdata(1,:); -Ts_msr=Xdata(3,:); -ETdata=xlsread('E:\grassland\SCOPE-master\SCOPE_v1.73\src\ET','sheet1','A2:E2449'); -ET_H=ETdata(:,1)'; -ET_D=ETdata(:,3)'; -E_D=ETdata(:,4)'; +InitND4=100; +InitND5=200; +InitND6=300; +if SWCC==0 +InitT0= -1.762; %-1.75estimated soil surface temperature-1.762 +InitT1= -0.662; +InitT2= 0.264; +InitT3= 0.905; +InitT4= 4.29; +InitT5= 3.657;%; +InitT6= 6.033; +BtmT=6.62; %9 8.1 +InitX0= 0.088; +InitX1= 0.095; % Measured soil liquid moisture content +InitX2= 0.180; %0.169 +InitX3= 0.213; %0.205 +InitX4= 0.184; %0.114 +InitX5= 0.0845; +InitX6= 0.078; +BtmX=0.078;%0.078 0.05; % The initial moisture content at the bottom of the column. +else +InitT0= -0.32554812042345; %-1.75estimated soil surface temperature-1.762 +InitT1= 1.47214795327483; +InitT2= 2.31236451432981; +InitT3= 2.89208940206501; +InitT4= 3.73006346689778; +InitT5= 4.07350351072157;%; +InitT6= 4.033; +BtmT=mean(Ts_msr); %9 8.1 +InitX0= 0.077503746503950; %0.0793 +InitX1= 0.092141294540442; % Measured soil liquid moisture content +InitX2= 0.139618635508642; %0.182 +InitX3= 0.156812295825425; +InitX4= 0.169971216306663; %0.14335 +InitX5= 0.19354781823877; +InitX6= 0.1896; +BtmX=fieldMC(6);%0.05; % The initial moisture content at the bottom of the column. end - - diff --git a/src/Density_V.m b/src/Density_V.m index 43f8ec09..0ffd5ff2 100644 --- a/src/Density_V.m +++ b/src/Density_V.m @@ -2,11 +2,20 @@ for MN=1:NN HR(MN)=exp(hh(MN)*g/(Rv*(TT(MN)+273.15))); - + if HR(MN)<=0.041 + HR(MN)=0.041; + elseif HR(MN)>=1 + HR(MN)=1; + end RHOV_s(MN)=1e-6*exp(31.3716-6014.79/(TT(MN)+273.15)-7.92495*0.001*(TT(MN)+273.15))/(TT(MN)+273.15); - DRHOV_sT(MN)=RHOV_s(MN)*(6014.79/(TT(MN)+273.15)^2-7.92495*0.001)-RHOV_s(MN)/(TT(MN)+273.15); - + if TT(MN)<-20 + RHOV_s(MN)=1e-6*exp(31.3716-6014.79/(-20+273.15)-7.92495*0.001*(-20+273.15))/(-20+273.15); + DRHOV_sT(MN)=RHOV_s(MN)*(6014.79/(-20+273.15)^2-7.92495*0.001)-RHOV_s(MN)/(-20+273.15); + elseif TT(MN)>=150 + RHOV_s(MN)=1e-6*exp(31.3716-6014.79/(150+273.15)-7.92495*0.001*(150+273.15))/(150+273.15); + DRHOV_sT(MN)=RHOV_s(MN)*(6014.79/(150+273.15)^2-7.92495*0.001)-RHOV_s(MN)/(150+273.15); + end RHOV(MN)=RHOV_s(MN)*HR(MN); DRHOVh(MN)=RHOV_s(MN)*HR(MN)*g/(Rv*(TT(MN)+273.15)); diff --git a/src/Dtrmn_Z.m b/src/Dtrmn_Z.m index 16d4feb1..941bfab9 100644 --- a/src/Dtrmn_Z.m +++ b/src/Dtrmn_Z.m @@ -1,72 +1,44 @@ function Dtrmn_Z % The determination of the element length -global Elmn_Lnth ML DeltZ NL Tot_Depth DeltZ_R MML Ztot +global Elmn_Lnth ML DeltZ NL Tot_Depth DeltZ_R MML Elmn_Lnth=0; -for ML=1:2 - DeltZ_R(ML)=0.25; +for ML=1:3 + DeltZ_R(ML)=1;%4 end - DeltZ_R(3)=0.5; - -for ML=4:12 - DeltZ_R(ML)=1; + DeltZ_R(4)=2;%4 +for ML=5:14 + DeltZ_R(ML)=2;%5 end - -for ML=13:17 - DeltZ_R(ML)=2; +for ML=15:18 + DeltZ_R(ML)=2.5;%5 end - -for ML=18:23 +for ML=19:23 DeltZ_R(ML)=5; end +for ML=24:31 + DeltZ_R(ML)=10; +end +for ML=32:40 + DeltZ_R(ML)=10; +end +for ML=41:42 + DeltZ_R(ML)=15;%5 +end % Sum of element lengths and compared to the total lenght, so that judge % can be made to determine the length of rest elements. -for ML=1:23 +for ML=1:42 Elmn_Lnth=Elmn_Lnth+DeltZ_R(ML); end % If the total sum of element lenth is over the predefined depth, stop the % for loop, make the ML, at which the element lenth sumtion is over defined % depth, to be new NL. -for ML=24:28 - DeltZ_R(ML)=10; - Elmn_Lnth=Elmn_Lnth+DeltZ_R(ML); - if Elmn_Lnth>Tot_Depth - DeltZ_R(ML)=Tot_Depth-Elmn_Lnth+DeltZ_R(ML); - NL=ML; - - for ML=1:NL - MML=NL-ML+1; - DeltZ(ML)=DeltZ_R(MML); - end - return - elseif Elmn_LnthTot_Depth - DeltZ_R(ML)=Tot_Depth-Elmn_Lnth+DeltZ_R(ML); - NL=ML; - - for ML=1:NL - MML=NL-ML+1; - DeltZ(ML)=DeltZ_R(MML); - end - return - elseif Elmn_Lnth=Tot_Depth DeltZ_R(ML)=Tot_Depth-Elmn_Lnth+DeltZ_R(ML); NL=ML; @@ -77,14 +49,4 @@ end return end - Ztot=DeltZ'; - Ztot=flip(Ztot); - Ztot=cumsum(Ztot,1); - Ztot=flip(Ztot); -end - - - - - - \ No newline at end of file +end \ No newline at end of file diff --git a/src/EfeCapCond.m b/src/EfeCapCond.m index 8d19edc8..6d893044 100644 --- a/src/EfeCapCond.m +++ b/src/EfeCapCond.m @@ -1,11 +1,12 @@ -function [ETCON,EHCAP,ZETA,J]=EfeCapCond(HCAP,TCON,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,NL,IS,J,POR,Theta_LL,DRHOVT,L,D_A,RHOV,Theta_V) - -MN=0; +function [ETCON,EHCAP,TETCON,EfTCON,ZETA]=EfeCapCond(HCAP,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,NL,POR,Theta_LL,DRHOVT,L,D_A,RHOV,Theta_V,Theta_II,TCON_dry,Theta_s,XSOC,ThermCond,TPS1,TPS2,TCON0,TCON_s,FEHCAP,RHOI,RHOL,ETCON,EHCAP,TETCON,EfTCON,ZETA) +global TCON +MN=0;TCON(1)=1.37e-3*4.182; for ML=1:NL for ND=1:2 MN=ML+ND-1; - J=IS(ML); + J=ML;%J=IS(ML); XXX=Theta_LL(ML,ND); + XII=Theta_II(ML,ND)*RHOI/RHOL; %MODIFIED 201905 if Theta_LL(ML,ND) < XK(J) XXX=XK(J); end @@ -17,25 +18,93 @@ end D_A(MN)=0.229*(1+TT(MN)/273)^1.75; TCON(2)=TCA+D_A(MN)*L(MN)*DRHOVT(MN); %TCA+D_A(MN)*L(MN)*DRHOVT(MN); % Revised from ""(D_V(ML,ND)*Eta(ML,ND)+D_Vg(ML))*L(MN)*DRHOVT(MN) - - TARG=TCON(2)/TCON(1)-1; - GRAT=0.667/(1+TARG*SF(2))+0.333/(1+TARG*(1-2*SF(2))); - ETCON(ML,ND)=(PS1(J)+XXX*TCON(1)+(POR(J)-XXX)*GRAT*TCON(2))/(PS2(J)+XXX+(POR(J)-XXX)*GRAT); - ZETA(ML,ND)=GRAT/(GRAT*(POR(J)-XXX)+XXX+PS2(J)); - + TCON(6)=5.2e-3*4.182; % ice thermal conductivity + SF(6)=0.125; + TARG(2)=TCON(2)/TCON(1)-1; + TARG(6)=TCON(6)/TCON(1)-1; + GRAT(2)=0.667/(1+TARG(2)*SF(2))+0.333/(1+TARG(2)*(1-2*SF(2))); + GRAT(6)=0.667/(1+TARG(6)*SF(6))+0.333/(1+TARG(6)*(1-2*SF(6))); + ETCON(ML,ND)=(PS1(J)+XXX*TCON(1)+(POR(J)-XXX-XII)*GRAT(2)*TCON(2)+XII*GRAT(6)*TCON(6))/(PS2(J)+XXX+(POR(J)-XXX-XII)*GRAT(2)+XII*GRAT(6)); + ZETA(ML,ND)=GRAT(2)/(GRAT(2)*(POR(J)-XXX)+XXX+PS2(J)); % ita_T enhancement factor + ZETA(ML,ND)=GRAT(2)/(GRAT(2)*(POR(J)-XXX-XII)+XXX+PS2(J)+XII*GRAT(6)); if Theta_LL(ML,ND)==XXX EHCAP(ML,ND)=HCD(J)+HCAP(1)*Theta_LL(ML,ND); - EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND); % The Calorie should be converted as J + EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND)+HCAP(6)*XII; % The Calorie should be converted as J else ZETA(ML,ND)=ZETA0(J)+(ZETA(ML,ND)-ZETA0(J))*Theta_LL(ML,ND)/XXX; ETCON(ML,ND)=CON0(J)+(ETCON(ML,ND)-CON0(J))*Theta_LL(ML,ND)/XXX; EHCAP(ML,ND)=HCD(J)+HCAP(1)*Theta_LL(ML,ND); - EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND); % The Calorie should be converted as J - end + EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND)+HCAP(6)*XII; % The Calorie should be converted as J + end + %%%%%%simpliefied Vries method by Tian 2016 + TSF(2)=0.333*(1-(POR(J)-XXX-XII)/POR(J)); + TSF(6)=0.333*(1-XII/POR(J)); + TSF(7)=0.5; % shape factor for organic matter + D_A(MN)=0.229*(1+TT(MN)/273)^1.75; + TCON(2)=TCA+D_A(MN)*L(MN)*DRHOVT(MN); %TCA+D_A(MN)*L(MN)*DRHOVT(MN); % Revised from ""(D_V(ML,ND)*Eta(ML,ND)+D_Vg(ML))*L(MN)*DRHOVT(MN) + TCON(6)=5.2e-3*4.182; % ice conductivity + TCON(7)=0.25e-2; % soil organic matter conductivity + TARG(2)=TCON(2)/TCON(1)-1; + TARG(6)=TCON(6)/TCON(1)-1; + TARG(7)=TCON(7)/TCON(1)-1; + TTGRAT(2)=0.667/(1+TARG(2)*TSF(2))+0.333/(1+TARG(2)*(1-2*TSF(2))); + TTGRAT(6)=0.667/(1+TARG(6)*TSF(6))+0.333/(1+TARG(6)*(1-2*TSF(6))); + TTGRAT(7)=0.667/(1+TARG(7)*TSF(7))+0.333/(1+TARG(7)*(1-2*TSF(7))); + if XSOC(J)==0 + TETCON(ML,ND)=(TPS1(J)+XXX*TCON(1)+(POR(J)-XXX-XII)*TTGRAT(2)*TCON(2)+XII*TTGRAT(6)*TCON(6))/(TPS2(J)+XXX+(POR(J)-XXX-XII)*TTGRAT(2)+XII*TTGRAT(6)); + else + TETCON(ML,ND)=(TPS1(J)+XXX*TCON(1)+(POR(J)-XXX-XII)*TTGRAT(2)*TCON(2)+XII*TTGRAT(6)*TCON(6)+XSOC(J)*TTGRAT(7)*TCON(7))/(TPS2(J)+XXX+(POR(J)-XXX-XII)*TTGRAT(2)+XII*TTGRAT(6)+XSOC(J)*TTGRAT(7)); + end + TZETA(ML,ND)=TTGRAT(2)/(TTGRAT(2)*(POR(J)-XXX)+XXX+TPS2(J)); % ita_T enhancement factor + if Theta_LL(ML,ND)==XXX + EHCAP(ML,ND)=HCD(J)+HCAP(1)*Theta_LL(ML,ND); + EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND)+HCAP(6)*XII; % The Calorie should be converted as J + else + ZETA(ML,ND)=ZETA0(J)+(ZETA(ML,ND)-ZETA0(J))*Theta_LL(ML,ND)/XXX; + TETCON(ML,ND)=TCON0(J)+(TETCON(ML,ND)-TCON0(J))*Theta_LL(ML,ND)/XXX; + EHCAP(ML,ND)=HCD(J)+HCAP(1)*Theta_LL(ML,ND); + EHCAP(ML,ND)=EHCAP(ML,ND)+(0.448*RHOV(MN)*4.182+HCAP(2))*Theta_V(ML,ND)+HCAP(6)*XII; % The Calorie should be converted as J + end + %%%%%%%%%%%%%%%%%% Farouki thermal parameter method %%%%%%%%%%% +%%%%%%%%%%%%%%%%%change 21 July 2017 switch of thermal conductivity%%%%%% + if ThermCond==4 %|| ThermCond==2 + % FEHCAP(ML,ND)=(2.128*Theta_sa(J)+2.385*Theta_cl(J))/(Theta_sa(J)+Theta_cl(J))*1e6; %J m-3 K-1 +% TCON_s(J)=(8.8*Theta_sa(J)+2.92*Theta_cl(J))/(Theta_sa(J)+Theta_cl(J)); % W m-1 K-1 + FFEHCAP(ML,ND)=(FEHCAP(J)*(1-POR(J))+1000*4217.7*Theta_LL(ML,ND)+917*2117.27*XII)*1e-6; % The Calorie should be converted as J + EHCAP(ML,ND)=FFEHCAP(ML,ND); + end + %%%%%%%%%%%%%%%%%% Johansen thermal conductivity method %%%%%%%%%%% + TCON_qtz=7.7;TCON_o=2.0;TCON_L=0.57;%Theta_qtz(J)=0.47; % thermal conductivities of soil quartz, other soil particles and water; unit W m-1 K-1 + if ThermCond==2 + TCON_s(J)=TCON_qtz^(Theta_qtz(J))*TCON_o^(1-Theta_qtz(J)); % solid soil thermal conductivity Unit W m-1 K-1 + end + TCON_i(J)=2.2; + %%%%% Peters-Lidard et al. 1998 frozen soil thermal conductivity method %%%%%%% + Satr(ML,ND)=(Theta_LL(ML,ND)+XII)/Theta_s(J); + if Theta_II(ML,ND)<=0 + if Theta_LL(ML,ND)/POR(J)>0.1 + K_e(ML,ND)=log10(Theta_LL(ML,ND)/POR(J))+1; % Kersten coefficient, weighting dry and wet thermal conductivity + elseif Theta_LL(ML,ND)/POR(J)>0.05 + K_e(ML,ND)=0.7*log10(Theta_LL(ML,ND)/POR(J))+1; % Kersten coefficient, weighting dry and wet thermal conductivity + else + K_e(ML,ND)=0; + end + Coef_k=1.9;%[4.6 3.55 1.9; 1.7 0.95 0.85]; + K_e1(ML,ND)=Coef_k*(Theta_LL(ML,ND)/POR(J))/(1+(Coef_k-1)*(Theta_LL(ML,ND)/POR(J))); % Kersten coefficient, weighting dry and wet thermal conductivity + ALPHA=0.9;%[1.05,0.9,0.58]; + K_e2(ML,ND)=exp(ALPHA*(1-(Theta_LL(ML,ND)/POR(J))^(ALPHA-1.33))); %Lu and Ren 2007; ALPHA=1.05,0.9,0.58 + TCON_sat(ML,ND)=TCON_s(J)^(1-Theta_s(J))*TCON_L^(Theta_s(J)); % saturated soil thermal conductivity Unit W m-1 K-1 + EfTCON(ML,ND)=K_e(ML,ND)*(TCON_sat(ML,ND)-TCON_dry(J))+TCON_dry(J); + else + K_e(ML,ND)=(Theta_LL(ML,ND)+Theta_II(ML,ND))/POR(J);%+Theta_II(ML,ND) + TCON_sat(ML,ND)=TCON_s(J)^(1-Theta_s(J))*TCON_i(J)^(Theta_s(J)-Theta_LL(ML,ND))*TCON_L^(Theta_LL(ML,ND)); % saturated soil thermal conductivity Unit W m-1 K-1 + EfTCON(ML,ND)=K_e(ML,ND)*(TCON_sat(ML,ND)-TCON_dry(J))+TCON_dry(J); + end end end - - + + + diff --git a/src/EnrgyPARM.m b/src/EnrgyPARM.m index f27bfbdf..ec39a801 100644 --- a/src/EnrgyPARM.m +++ b/src/EnrgyPARM.m @@ -1,11 +1,12 @@ -function [CTh,CTT,CTa,KTh,KTT,KTa,VTT,VTh,VTa,CTg,QL,QV,Qa,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,RHOVBAR,EtaBAR]=EnrgyPARM(NL,hh,TT,DeltZ,P_gg,Kaa,Vvh,VvT,Vaa,c_a,c_L,DTheta_LLh,RHOV,Hc,RHODA,DRHODAz,L,WW,RHOL,Theta_V,DRHOVh,DRHOVT,KL_h,D_Ta,KL_T,D_V,D_Vg,DVa_Switch,Theta_g,QL,V_A,Lambda_eff,c_unsat,Eta,Xah,XaT,Xaa,DTheta_LLT,Soilairefc,Khh,KhT,Kha,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,QV,Qa,RHOVBAR,EtaBAR) +function [CTh,CTT,CTa,KTh,KTT,KTa,VTT,VTh,VTa,CTg,QL,QLT,QLH,QV,QVH,QVT,QVa,Qa,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,RHOVBAR,EtaBAR]=EnrgyPARM(NL,hh,TT,DeltZ,P_gg,Kaa,Vvh,VvT,Vaa,c_a,c_L,DTheta_LLh,RHOV,Hc,RHODA,DRHODAz,L,WW,RHOL,Theta_V,DRHOVh,DRHOVT,KfL_h,D_Ta,KL_T,D_V,D_Vg,DVa_Switch,Theta_g,QL,V_A,Lambda_eff,c_unsat,Eta,Xah,XaT,Xaa,DTheta_LLT,Soilairefc,Khh,KhT,Kha,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,QV,Qa,RHOVBAR,EtaBAR,h_frez,hh_frez,SFCC,Srt,DTheta_UUh,TT_CRIT,T0,EPCT,L_f,RHOI,g,c_i,QLT,QLH,SAVEDTheta_LLh,SAVEDTheta_UUh,Kcah,KcaT,Kcaa,Kcva,Ccah,CcaT,Ccaa,QVa,CTT) for ML=1:NL if ~Soilairefc - KLhBAR(ML)=(KL_h(ML,1)+KL_h(ML,2))/2; + KLhBAR(ML)=(KfL_h(ML,1)+KfL_h(ML,2))/2; KLTBAR(ML)=(KL_T(ML,1)+KL_T(ML,2))/2; DETBAR(ML)=(D_V(ML,1)*Eta(ML,1)+D_V(ML,2)*Eta(ML,2))/2; - DhDZ(ML)=(hh(ML+1)-hh(ML))/DeltZ(ML); + DDhDZ(ML)=(hh(ML+1)-hh(ML))/DeltZ(ML); + DhDZ(ML)=(hh(ML+1)+hh_frez(ML+1)-hh(ML)-hh_frez(ML))/DeltZ(ML); DTDZ(ML)=(TT(ML+1)-TT(ML))/DeltZ(ML); DPgDZ(ML)=(P_gg(ML+1)-P_gg(ML))/DeltZ(ML); end @@ -17,26 +18,33 @@ EtaBAR(ML)=(Eta(ML,1)+Eta(ML,2))/2; end -%%%%%% NOTE: The soil air gas in soil-pore is considered with Xah and XaT terms.(0.0003,volumetric heat capacity)%%%%%% +%%%%%% NOTE: The soil air gas in soil-pore is considered with Xah and XaT terms.(0.0003,volumetric heat capacity)%%%%%% MN=0; for ML=1:NL for ND=1:2 MN=ML+ND-1; if ~Soilairefc QL(ML)=-(KLhBAR(ML)*DhDZ(ML)+(KLTBAR(ML)+DTDBAR(ML))*DTDZ(ML)+KLhBAR(ML)); + QLT(ML)=-((KLTBAR(ML)+DTDBAR(ML))*DTDZ(ML)); + QLH(ML)=-(KLhBAR(ML)*DhDZ(ML)+KLhBAR(ML)); Qa(ML)=0; else Qa(ML)=-((DEhBAR(ML)+D_Vg(ML))*DRHODAz(ML)-RHODA(ML)*(V_A(ML)+Hc*QL(ML)/RHOL)); end if DVa_Switch==1 - QV(ML)=-(DEhBAR(ML)+D_Vg(ML))*DRHOVhDz(ML)*DhDZ(ML)-(DEhBAR(ML)*EtaBAR(ML)+D_Vg(ML))*DRHOVTDz(ML)*DTDZ(ML)+RHOVBAR(ML)*V_A(ML); + QV(ML)=-(DEhBAR(ML)+D_Vg(ML))*DRHOVhDz(ML)*DDhDZ(ML)-(DEhBAR(ML)*EtaBAR(ML)+D_Vg(ML))*DRHOVTDz(ML)*DTDZ(ML)+RHOVBAR(ML)*V_A(ML); + QVa(ML)=RHOVBAR(ML)*V_A(ML); + else - QV(ML)=-(DEhBAR(ML)+D_Vg(ML))*DRHOVhDz(ML)*DhDZ(ML)-(DEhBAR(ML)*EtaBAR(ML)+D_Vg(ML))*DRHOVTDz(ML)*DTDZ(ML); + QV(ML)=-(DEhBAR(ML)+D_Vg(ML))*DRHOVhDz(ML)*DDhDZ(ML)-(DEhBAR(ML)*EtaBAR(ML)+D_Vg(ML))*DRHOVTDz(ML)*DTDZ(ML); end - - if Soilairefc==1 - Kcah(ML,ND)=c_a*TT(MN)*((D_V(ML,ND)+D_Vg(ML))*Xah(MN)+Hc*RHODA(MN)*KL_h(ML,ND)); + DVH(ML)=(DEhBAR(ML))*DRHOVhDz(ML); + DVT(ML)=(DEhBAR(ML)*EtaBAR(ML))*DRHOVTDz(ML); + QVH(ML)=-(DEhBAR(ML)+D_Vg(ML))*DRHOVhDz(ML)*DDhDZ(ML); + QVT(ML)=-(DEhBAR(ML)*EtaBAR(ML)+D_Vg(ML))*DRHOVTDz(ML)*DTDZ(ML); + if Soilairefc==1 + Kcah(ML,ND)=c_a*TT(MN)*((D_V(ML,ND)+D_Vg(ML))*Xah(MN)+Hc*RHODA(MN)*KfL_h(ML,ND)); KcaT(ML,ND)=c_a*TT(MN)*((D_V(ML,ND)+D_Vg(ML))*XaT(MN)+Hc*RHODA(MN)*(KL_T(ML,ND)+D_Ta(ML,ND))); % Kcaa(ML,ND)=c_a*TT(MN)*Kaa(ML,ND); %((D_V(ML,ND)+D_Vg(ML))*Xaa(MN)+RHODA(MN)*(Beta_g(ML,ND)+Hc*KL_h(ML,ND)/Gamma_w)); % if DVa_Switch==1 @@ -48,27 +56,59 @@ CcaT(ML,ND)=c_a*TT(MN)*(-V_A(ML)-Hc*QL(ML)/RHOL)*XaT(MN); Ccaa(ML,ND)=c_a*TT(MN)*Vaa(ML,ND); %*(-V_A(ML)-Hc*QL(ML)/RHOL)*Xaa(MN); % end + + if abs(SAVEDTheta_LLh(ML,ND)-SAVEDTheta_UUh(ML,ND))~=0 + CTT_PH(ML,ND)=(10*L_f^2*RHOI/(g*(T0+TT(MN))))*DTheta_UUh(ML,ND); + CTT_Lg(ML,ND)=(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVT(MN); + CTT_g(ML,ND)=c_a*TT(MN)*Theta_g(ML,ND)*XaT(MN); +%Modified 20190514 + CTT_LT(ML,ND)=(((c_L*TT(MN)-WW(ML,ND))*RHOL-((c_L*TT(MN)+L(MN))*RHOV(MN)+c_a*RHODA(MN)*TT(MN)))*(1-RHOI/RHOL)-RHOI*c_i*TT(MN))*1e4*L_f/(g*(T0+TT(MN)))*DTheta_UUh(ML,ND);%DTheta_LLh(ML,ND); %DTheta_LLT(ML,ND) + if CTT_PH(ML,ND)<0 + CTT_PH(ML,ND)=0;%-c_i*TT(MN)-c_i*TT(MN) + end + CTT(ML,ND)=c_unsat(ML,ND)+CTT_Lg(ML,ND)+CTT_g(ML,ND)+CTT_LT(ML,ND)+CTT_PH(ML,ND); + CTh(ML,ND)=(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVh(MN)+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN);%;%+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN) + CTa(ML,ND)=TT(MN)*Theta_V(ML,ND)*c_a*Xaa(MN);% There is not this term in Milly's work. + + else % Main coefficients for energy transport is here: - CTh(ML,ND)=((c_L*TT(MN)-WW(ML,ND))*RHOL-(c_L*TT(MN)+L(MN))*RHOV(MN)-c_a*RHODA(MN)*TT(MN))*DTheta_LLh(ML,ND) ... + CTT_Lg(ML,ND)=0;CTT_g(ML,ND)=0;CTT_LT(ML,ND)=0;CTT_PH(ML,ND)=0; + CTh(ML,ND)=((c_L*TT(MN)-WW(ML,ND))*RHOL-(c_L*TT(MN)+L(MN))*RHOV(MN)-c_a*RHODA(MN)*TT(MN))*DTheta_LLh(ML,ND);%DTheta_LLh(ML,ND) ... +(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVh(MN)+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN);%;%+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN) CTT(ML,ND)=c_unsat(ML,ND)+(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVT(MN)+c_a*TT(MN)*Theta_g(ML,ND)*XaT(MN) ... +((c_L*TT(MN)-WW(ML,ND))*RHOL-(c_L*TT(MN)+L(MN))*RHOV(MN)-c_a*RHODA(MN)*TT(MN))*DTheta_LLT(ML,ND); % %+c_a*TT(MN)*Theta_g(ML,ND)*XaT(MN)"+" CTa(ML,ND)=TT(MN)*Theta_V(ML,ND)*c_a*Xaa(MN);% There is not this term in Milly's work. - + end + if SFCC==0 %%%%%% ice calculation use Sin function + if TT(MN)+273.15>Tf1 + CTT_PH(ML,ND)=0; + elseif TT(MN)+273.15>=Tf2%XCAP(MN)* + CTT_PH(ML,ND)=L_f*10^(-3)*0.5*cos(pi()*(TT(MN)+273.15-0.5*Tf1-0.5*Tf2)/(Tf1-Tf2))*pi()/(Tf1-Tf2); + else + CTT_PH(ML,ND)=0; + end + CTT_Lg(ML,ND)=(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVT(MN); + CTT_g(ML,ND)=c_a*TT(MN)*Theta_g(ML,ND)*XaT(MN); + CTT_LT(ML,ND)=((c_L*TT(MN)-c_i*TT(MN)-WW(ML,ND))*RHOL+((c_L*TT(MN)+L(MN))*RHOV(MN)+c_a*RHODA(MN)*TT(MN))*(RHOL/RHOI-1))*1e4*L_f/(g*(T0+TT(MN)))*DTheta_UUh(ML,ND); %DTheta_LLT(ML,ND) + + CTT(ML,ND)=c_unsat(ML,ND)+CTT_Lg(ML,ND)+CTT_g(ML,ND)+CTT_LT(ML,ND)+CTT_PH(ML,ND); + CTh(ML,ND)=(c_L*TT(MN)+L(MN))*Theta_g(ML,ND)*DRHOVh(MN)+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN);%;%+c_a*TT(MN)*Theta_g(ML,ND)*Xah(MN) + CTa(ML,ND)=TT(MN)*Theta_V(ML,ND)*c_a*Xaa(MN);% There is not this term in Milly's work. + end KTh(ML,ND)=L(MN)*(D_V(ML,ND)+D_Vg(ML))*DRHOVh(MN)+c_L*TT(MN)*RHOL*Khh(ML,ND)+Kcah(ML,ND); %; %+Kcah(ML,ND) KTT(ML,ND)=Lambda_eff(ML,ND)+c_L*TT(MN)*RHOL*KhT(ML,ND)+KcaT(ML,ND)+L(MN)*(D_V(ML,ND)*Eta(ML,ND)+D_Vg(ML))*DRHOVT(MN); %;%; % Revised from: "Lambda_eff(ML,ND)+c_L*TT(MN)*RHOL*KhT(ML,ND);" KTa(ML,ND)=Kcva(ML,ND)+Kcaa(ML,ND)+c_L*TT(MN)*RHOL*Kha(ML,ND); % There is not this term in Milly's work. - + if DVa_Switch==1 - VTh(ML,ND)=c_L*TT(MN)*RHOL*Vvh(ML,ND)+Ccah(ML,ND)-L(MN)*V_A(ML)*DRHOVh(MN); - VTT(ML,ND)=c_L*TT(MN)*RHOL*VvT(ML,ND)+CcaT(ML,ND)-L(MN)*V_A(ML)*DRHOVT(MN)-(c_L*(QL(ML)+QV(ML))+c_a*Qa(ML)-2.369*QV(ML)); + VTh(ML,ND)=c_L*TT(MN)*RHOL*Vvh(ML,ND)+Ccah(ML,ND)-L(MN)*V_A(ML)*DRHOVh(MN); + VTT(ML,ND)=c_L*TT(MN)*RHOL*VvT(ML,ND)+CcaT(ML,ND)-L(MN)*V_A(ML)*DRHOVT(MN)-(c_L*(QL(ML)+QV(ML))+c_a*Qa(ML)-2.369*QV(ML)); else - VTh(ML,ND)=c_L*TT(MN)*RHOL*Vvh(ML,ND)+Ccah(ML,ND); - VTT(ML,ND)=c_L*TT(MN)*RHOL*VvT(ML,ND)+CcaT(ML,ND)-(c_L*(QL(ML)+QV(ML))+c_a*Qa(ML)-2.369*QV(ML)); + VTh(ML,ND)=c_L*TT(MN)*RHOL*Vvh(ML,ND)+Ccah(ML,ND); + VTT(ML,ND)=c_L*TT(MN)*RHOL*VvT(ML,ND)+CcaT(ML,ND)-(c_L*(QL(ML)+QV(ML))+c_a*Qa(ML)-2.369*QV(ML)); end VTa(ML,ND)=Ccaa(ML,ND); %c_a*TT(MN)*Vaa(ML,ND); - CTg(ML,ND)=(c_L*RHOL+c_a*Hc*RHODA(MN))*KL_h(ML,ND)*TT(MN); %;;% % Revised from "c_L*T(MN)*KL_h(ML,ND)" + CTg(ML,ND)=(c_L*RHOL+c_a*Hc*RHODA(MN))*KfL_h(ML,ND)*TT(MN)-c_L*Srt(ML,ND)*TT(MN); %;;% % Revised from "c_L*T(MN)*KL_h(ML,ND)" end end diff --git a/src/Enrgy_BC.m b/src/Enrgy_BC.m index adec41a8..4e5372cc 100644 --- a/src/Enrgy_BC.m +++ b/src/Enrgy_BC.m @@ -1,9 +1,10 @@ -function [RHS,C5,C5_a]=Enrgy_BC(RHS,KT,NN,c_L,RHOL,QMB,SH,Precip,L,L_ts,NBCTB,NBCT,BCT,BCTB,DSTOR0,Delt_t,T,Ts,Ta,EVAP,Rn,C5,C5_a) -global Tss Ts1 Taa Tcc Tsss +function [RHS,C5,C5_a]=Enrgy_BC(RHS,KT,NN,c_L,RHOL,QMB,SH,Precip,L,L_ts,NBCTB,NBCT,BCT,BCTB,DSTOR0,Delt_t,T,Ts,Ta,EVAP,C5,C5_a,r_a_SOIL,Resis_a,Tbtm,c_a,Rn_SOIL) +global Tss Tsur Tsss +Tsur(KT)=Tss; %%%%%%%%% Apply the bottom boundary condition called for by NBCTB %%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if NBCTB==1 - RHS(1)=BCTB; + RHS(1)=BCTB;%Tbtm(KT); C5(1,1)=1; RHS(2)=RHS(2)-C5(1,2)*RHS(1); C5(1,2)=0; @@ -17,23 +18,22 @@ %%%%%%%%%% Apply the surface boundary condition called by NBCT %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if NBCT==1 - if ~isnan(Tss) - RHS(NN)=Tss;%BCT;%30; - elseif ~isnan(Tcc) - RHS(NN)=Tcc; - elseif ~isnan(Taa) - RHS(NN)=Taa; + if isreal(Tss) + RHS(NN)=Ta(KT);%BCT;%30; else - RHS(NN)=Tsss(KT); + RHS(NN)=Ta(KT); end C5(NN,1)=1; RHS(NN-1)=RHS(NN-1)-C5(NN-1,2)*RHS(NN); C5(NN-1,2)=0; - C5_a(NN-1)=0; + C5_a(NN-1)=0; + %SHH(KT)=0.1200*c_a*(T(NN)-Ta(KT))/r_a_SOIL(KT);%Resis_a(KT); % J cm-2 s-1 + %SHF(KT)=0.1200*c_a*(T(NN)-Ta(KT))/Resis_a(KT);%Resis_a(KT); % J cm-2 s-1 elseif NBCT==2 RHS(NN)=RHS(NN)-BCT; -else +else L_ts(KT)=L(NN); - RHS(NN)=RHS(NN)+Rn(KT)-RHOL*L_ts(KT)*EVAP(KT)-SH(KT)+RHOL*c_L*(Ta(KT)*Precip(KT)+DSTOR0*T(NN)/Delt_t); + SH(KT)=0.1200*c_a*(T(NN)-Ta(KT))/r_a_SOIL(KT);%Resis_a(KT); % J cm-2 s-1 + RHS(NN)=RHS(NN)+100*Rn_SOIL(KT)/1800-RHOL*L_ts(KT)*EVAP(KT)-SH(KT)+RHOL*c_L*(Ta(KT)*Precip(KT)+DSTOR0*T(NN)/Delt_t); % J cm-2 s-1 end diff --git a/src/Enrgy_Solve.m b/src/Enrgy_Solve.m index cd198fa9..bbefb0c1 100644 --- a/src/Enrgy_Solve.m +++ b/src/Enrgy_Solve.m @@ -12,7 +12,6 @@ end for MN=1:NN - CHK(MN)=abs(RHS(MN)-TT(MN)); - %CHK(MN)=abs((RHS(MN)-TT(MN))/TT(MN)); % + CHK(MN)=abs(RHS(MN)-TT(MN));SAVETT(MN)=TT(MN); %abs((RHS(MN)-TT(MN))/TT(MN)); % TT(MN)=RHS(MN); -end \ No newline at end of file +end diff --git a/src/Enrgy_sub.m b/src/Enrgy_sub.m index bb78759d..2aee2ca3 100644 --- a/src/Enrgy_sub.m +++ b/src/Enrgy_sub.m @@ -1,39 +1,31 @@ function Enrgy_sub -global TT MN NN BCTB +global TT NN BCTB Tmin global NL hh DeltZ P_gg global CTh CTT CTa KTh KTT KTa CTg Vvh VvT Vaa Kaa global c_a c_L RHOL DRHOVT DRHOVh RHOV Hc RHODA DRHODAz L WW global Theta_V Theta_g QL V_A -global KL_h KL_T D_Ta Lambda_eff c_unsat D_V Eta D_Vg Xah XaT Xaa DTheta_LLT Soilairefc +global KL_T D_Ta Lambda_eff c_unsat D_V Eta D_Vg Xah XaT Xaa DTheta_LLT Soilairefc global DTheta_LLh DVa_Switch global Khh KhT Kha KLhBAR KLTBAR DTDBAR DhDZ DTDZ DPgDZ Beta_g DEhBAR DETBAR QV Qa RHOVBAR EtaBAR global C1 C2 C3 C4 C5 C6 C7 C4_a C5_a C6_a VTT VTh VTa global Delt_t RHS T h P_g SAVE Thmrlefc global QMB SH Precip KT -global NBCTB NBCT BCT DSTOR0 Ts Ta L_ts -global EVAP Rn CHK QET QEB - -for MN=1:NN - %if isreal(TT(MN))==0 - TT(MN)=real(TT(MN)); - % end -end - -% EnrgyPARM; -[CTh,CTT,CTa,KTh,KTT,KTa,VTT,VTh,VTa,CTg,QL,QV,Qa,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,RHOVBAR,EtaBAR]=EnrgyPARM(NL,hh,TT,DeltZ,P_gg,Kaa,Vvh,VvT,Vaa,c_a,c_L,DTheta_LLh,RHOV,Hc,RHODA,DRHODAz,L,WW,RHOL,Theta_V,DRHOVh,DRHOVT,KL_h,D_Ta,KL_T,D_V,D_Vg,DVa_Switch,Theta_g,QL,V_A,Lambda_eff,c_unsat,Eta,Xah,XaT,Xaa,DTheta_LLT,Soilairefc,Khh,KhT,Kha,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,QV,Qa,RHOVBAR,EtaBAR); -% Enrgy_MAT; +global NBCTB NBCT BCT DSTOR0 Ts Ta L_ts TOLD +global EVAP CHK QET QEB r_a_SOIL Resis_a Tbtm Rn_SOIL QLT QLH QVH QVT QVa h_frez hh_frez SFCC Srt DTheta_UUh TT_CRIT T0 EPCT L_f RHOI g c_i KfL_h SAVEDTheta_LLh SAVEDTheta_UUh Kcah KcaT Kcaa Kcva Ccah CcaT Ccaa +[CTh,CTT,CTa,KTh,KTT,KTa,VTT,VTh,VTa,CTg,QL,QLT,QLH,QV,QVH,QVT,QVa,Qa,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,RHOVBAR,EtaBAR]=EnrgyPARM(NL,hh,TT,DeltZ,P_gg,Kaa,Vvh,VvT,Vaa,c_a,c_L,DTheta_LLh,RHOV,Hc,RHODA,DRHODAz,L,WW,RHOL,Theta_V,DRHOVh,DRHOVT,KfL_h,D_Ta,KL_T,D_V,D_Vg,DVa_Switch,Theta_g,QL,V_A,Lambda_eff,c_unsat,Eta,Xah,XaT,Xaa,DTheta_LLT,Soilairefc,Khh,KhT,Kha,KLhBAR,KLTBAR,DTDBAR,DhDZ,DTDZ,DPgDZ,Beta_g,DEhBAR,DETBAR,QV,Qa,RHOVBAR,EtaBAR,h_frez,hh_frez,SFCC,Srt,DTheta_UUh,TT_CRIT,T0,EPCT,L_f,RHOI,g,c_i,QLT,QLH,SAVEDTheta_LLh,SAVEDTheta_UUh,Kcah,KcaT,Kcaa,Kcva,Ccah,CcaT,Ccaa,QVa,CTT); [C1,C2,C3,C4,C4_a,C5,C5_a,C6,C6_a,C7]=Enrgy_MAT(CTh,CTT,CTa,KTh,KTT,KTa,CTg,VTT,VTh,VTa,DeltZ,NL,NN,Soilairefc); -% Enrgy_EQ; [RHS,C5,SAVE]=Enrgy_EQ(C1,C2,C3,C4,C4_a,C5,C6_a,C6,C7,NL,NN,Delt_t,T,h,hh,P_g,P_gg,Thmrlefc,Soilairefc); -% Enrgy_BC; -[RHS,C5,C5_a]=Enrgy_BC(RHS,KT,NN,c_L,RHOL,QMB,SH,Precip,L,L_ts,NBCTB,NBCT,BCT,BCTB,DSTOR0,Delt_t,T,Ts,Ta,EVAP,Rn,C5,C5_a); -% Enrgy_Solve; +[RHS,C5,C5_a]=Enrgy_BC(RHS,KT,NN,c_L,RHOL,QMB,SH,Precip,L,L_ts,NBCTB,NBCT,BCT,BCTB,DSTOR0,Delt_t,T,Ts,Ta,EVAP,C5,C5_a,r_a_SOIL,Resis_a,Tbtm,c_a,Rn_SOIL); [TT,CHK,RHS,C5]= Enrgy_Solve(C5,C5_a,TT,NN,NL,RHS); +DeltT=abs(TT-TOLD); +if any(isnan(TT)) || any(TT(1:NN)30) %isnan(TT)==1 + for MN=1:NN + TT(MN)=TOLD(MN); + end +end for MN=1:NN - % if isreal(TT(MN))==0 - TT(MN)=real(TT(MN)); - % end +if TT(MN)<=-272 + TT(MN)=-272; +end end - -% Enrgy_Bndry_Flux; [QET,QEB]=Enrgy_Bndry_Flux(SAVE,TT,NN); \ No newline at end of file diff --git a/src/Evap_Cal.m b/src/Evap_Cal.m index e67b5309..117ae926 100644 --- a/src/Evap_Cal.m +++ b/src/Evap_Cal.m @@ -1,10 +1,16 @@ -%function [Evap,EVAP,Trap,bx,Srt]= Evap_Cal(KT,lEstot,lEctot,PSIs,PSI,rsss,rrr,rxx,rwuef) -function [Evap,EVAP,Trap,bx,Srt]= Evap_Cal(bx,Srt,DeltZ,TIME,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,NN,KT,Evaptranp_Cal,Coefficient_n,Coefficient_Alpha,Theta_r,Theta_s,DURTN,PME,PT_PM_0,hh,rwuef,J,lEstot,lEctot) -global LAI Rn G Ta1 Ts1 h_v rl_min RWU -if (isnan(lEstot) || isnan(lEctot)||lEstot>800) -%HR_a(KT)=HR(KT); -Ta(KT)=Ta1(KT); -Ts(KT)=Ts1(KT); +function [Rn_SOIL,Evap,EVAP,Trap,r_a_SOIL,Resis_a,Srt]= Evap_Cal(DeltZ,TIME,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,NN,KT,hh,rwuef,Theta_UU,Rn,T,TT,Gvc,Rns,Srt) +global LAI rl_min RWU lEstot lEctot Tss RWUtot RWUtott RWUtottt EVAPO + +%%%%%%% LAI and light extinction coefficient calculation %%%%%%%%%%%%%%%%%% +%%%%%%% LAI and light extinction coefficient calculation %%%%%%%%%%%%%%%%%% +Tao=0.56; %light attenual coefficient + +LAI(KT)=Gvc(KT); %0.9; + +if LAI(KT)<=0.01 + LAI(KT)=0.01; +end +% LAI(KT)=1.2; if LAI(KT)<=2 LAI_act(KT)=LAI(KT); elseif LAI(KT)<=4 @@ -12,8 +18,10 @@ else LAI_act(KT)=0.5*LAI(KT); end -Tao=0.56; %light attenual coefficient - % Set constants +% LAI(KT)=0; +Gvc(KT)=1-exp(-1*(Tao*LAI(KT))); + +% Set constants sigma = 4.903e-9; % Stefan Boltzmann constant MJ.m-2.day-1 FAO56 pag 74 lambdav = 2.45; % latent heat of evaporation [MJ.kg-1] FAO56 pag 31 % Gieske 2003 pag 74 Eq33/DKTgman 2002 @@ -24,15 +32,17 @@ R = 0.287; % specific gas [kJ.kg-1.K-1] FAO56 p26 box6 Cp = 1.013E-3; % specific heat at cte pressure [MJ.kg-1.?C-1] FAO56 p26 box6 k = 0.41; % karman's cte [] FAO 56 Eq4 - Z=521; % altitute of the location(m) + Z=3421; % altitute of the location(m) as=0.25; % regression constant, expressKTg the fraction of extraterrestrial radiation FAO56 pag50 bs=0.5; alfa=0.23; % albeo of vegetation set as 0.23 - z_m=2; % observation height of wKTd speed; 10m + z_m=10; % observation height of wKTd speed; 10m Lz=240*pi()/180; % latitude of Beijing time zone west of Greenwich Lm=252*pi()/180; % latitude of Local time, west of Greenwich % albedo of soil calculation; Theta_LL_sur(KT)=Theta_LL(NL,2); + Theta_UU_sur(KT)=Theta_UU(NL,2); + if Theta_LL_sur(KT)<0.1 alfa_s(KT)=0.25; elseif Theta_LL_sur(KT)<0.25 @@ -40,31 +50,21 @@ else alfa_s(KT)=0.1; end - %JN(KT)=fix(TIME/3600/24)+174; % day number - % n=[4.8 0 10.6 2.9 13 12.3 9.3 10.9 2.6 0 4.1 0 11.9 11.4 8.1 0 0 0 4.7 5.4 10.2 0 0 12.1 0 0 5.4 11.1 0 1.5 0.7 0 2.5 8.7 6 3.9 0 1.2 10.5 8.6 7.3 8.8 9.8 10.8 8.6 0 4.6 8.9 3.2 3 9 7.9 4 7.2 6.3 5.1 9.2 8.9 9.7 8.2 4.5 3.1 0 4.9 8.1 0 0 11.6 11.2 7.7 7.2 0 2.9 0 3 9 0 0 8 9.1 4.5 4.7 11 11.2 9.7 8.8 7.3 0 0 0 4.4 0 0 3.6 0 0 8.6 0.8 8.6 0 7.4 3.1]; - % h_v=[0.047333333 0.071 0.094666667 0.118333333 0.142 0.165666667 0.189333333 0.213 0.236666667 0.260333333 0.284 0.307666667 0.331333333 0.355 0.390909091 0.426818182 0.462727273 0.498636364 0.534545455 0.570454545 0.606363636 0.642272727 0.678181818 0.714090909 0.75 0.807142857 0.864285714 0.921428571 0.978571429 1.035714286 1.092857143 1.15 1.21625 1.2825 1.34875 1.415 1.48125 1.5475 1.61375 1.68 1.715 1.75 1.785 1.82 1.855 1.89 1.925 1.96 1.995 2.03 2.065 2.1 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135 2.135]; - % rl_min=[139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 121 121 121 121 121 121 121 121 121 121 121 121 121 121 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 139 239 239 239 239 239 239]; - %DayNum=fix(TIME/3600/24)+1; - % n(KT)=n(DayNum); - % h_v(KT)=h_v(DayNum); - % rl_min(KT)=rl_min(DayNum); - % 6-23 TO 7-31 - % Calculation procedure %% AIR PARAMETERS CALCULATION % compute DELTA - SLOPE OF SATURATION VAPOUR PRESSURE CURVE % [kPa.?C-1] % FAO56 pag 37 Eq13 - DELTA(KT) = 4098*(0.6108*exp(17.27*Ta1(KT)/(Ta1(KT)+237.3)))/(Ta1(KT)+237.3)^2; + DELTA(KT) = 4098*(0.6108*exp(17.27*Ta(KT)/(Ta(KT)+237.3)))/(Ta(KT)+237.3)^2; % ro_a - MEAN AIR DENSITY AT CTE PRESSURE % [kg.m-3] % FAO56 pag26 box6 Pa=101.3*((293-0.0065*Z)/293)^5.26; - ro_a(KT) = Pa/(R*1.01*(Ta1(KT)+273.16)); + ro_a(KT) = Pa/(R*1.01*(Ta(KT)+273.16)); % compute e0_Ta - saturation vapour pressure at actual air temperature % [kPa] % FAO56 pag36 Eq11 - e0_Ta(KT) = 0.6108*exp(17.27*Ta1(KT)/(Ta1(KT)+237.3)); - e0_Ts(KT) = 0.6108*exp(17.27*Ts1(KT)/(Ts1(KT)+237.3)); + e0_Ta(KT) = 0.6108*exp(17.27*Ta(KT)/(Ta(KT)+237.3)); + e0_Ts(KT) = 0.6108*exp(17.27*Ts(KT)/(Ts(KT)+237.3)); % compute e_a - ACTUAL VAPOUR PRESSURE % [kPa] % FAO56 pag74 Eq54 @@ -76,14 +76,16 @@ % FAO56 pag31 eq8 gama = 0.664742*1e-3*Pa; -% Calculation of net radiation - % Rn_SOIL(KT) = Rns_SOIL(KT) - RnL(KT); % net radiation for vegetation - Rn_SOIL(KT) =Rn(KT)*exp(-1*(Tao*LAI(KT))); % net radiation for soil - Rn_vege(KT) =Rn(KT)-Rn_SOIL(KT); % net radiation for vegetation - + hh_v(KT)=0.12; + rl_min(KT)=100; + % Rn(KT) =Rn_msr(KT); + if TIME<=1800*3600 + Rn_SOIL(KT) =Rn(KT)*0.68; % exp(-1*(Tao*LAI(KT)))net radiation for soil + else + Rn_SOIL(KT) =Rn(KT)*0.68; + end %% SURFACE RESISTANCE PARAMETERS CALCULATION R_a=0.81;R_b=0.004*24*11.6;R_c=0.05; - % R_fun(KT)=((R_b*Rns(KT)+R_c)/(R_a*(R_b*Rns(KT)+1))); rl(KT)=rl_min(KT)/((R_b*Rn(KT)+R_c)/(R_a*(R_b*Rn(KT)+1))); % r_s - SURFACE RESISTANCE @@ -92,44 +94,47 @@ r_s_VEG(KT) = rl(KT)/LAI_act(KT); % SOIL: equation 20 of van de Griend and Owe, 1994 - %Theta_LL_sur(KT)=Theta_LL(NL,2); - - r_s_SOIL(KT)=10.0*exp(0.3563*100.0*(0.25-Theta_LL_sur(KT))); % 0.25 set as minmum soil moisture for potential evaporation - %r_s_SOIL(i)=10.0*exp(0.3563*100.0*(fc(i)-por(i))); - % correction wKTdspeed measurement and scalKTg at h+2m - % [m.s-1] - % FAO56 pag56 eq47 + + if KT<=1047 + r_s_SOIL(KT)=10.0*exp(0.3563*100.0*(0.2050-Theta_LL_sur(KT))); % 0.25 set as minmum soil moisture for potential evaporation + elseif KT<=4300 + r_s_SOIL(KT)=10.0*exp(0.3563*100.0*(0.205-Theta_LL_sur(KT))); % 0.25 set as minmum soil moisture for potential evaporation + else + r_s_SOIL(KT)=10.0*exp(0.3563*100.0*(0.205-Theta_LL_sur(KT))); % 0.25 set as minmum soil moisture for potential evaporation + end % r_a - AERODYNAMIC RESISTANCE % [s.m-1] % FAO56 pag20 eq4- (d - zero displacement plane, z_0m - roughness length momentum transfer, z_0h - roughness length heat and vapour transfer, [m], FAO56 pag21 BOX4 - r_a_VEG(KT) = log((2-(2*h_v(KT)/3))/(0.123*h_v(KT)))*log((2-(2*h_v(KT)/3))/(0.0123*h_v(KT)))/((k^2)*U(KT))*100; + r_a_VEG(KT) = log((2-(2*hh_v(KT)/3))/(0.123*hh_v(KT)))*log((2-(2*hh_v(KT)/3))/(0.0123*hh_v(KT)))/((k^2)*U(KT))*100; % s m-1 % r_a of SOIL % Liu www.hydrol-earth-syst-sci.net/11/769/2007/ % equation for neutral conditions (eq. 9) % only function of ws, it is assumed that roughness are the same for any type of soil - RHOV_sur(KT)=RHOV(NN); - Theta_LL_sur(KT)=Theta_LL(NL,2); - P_Va(KT)=0.611*exp(17.27*Ta1(KT)/(Ta1(KT)+237.3))*HR_a(KT); %The aTaospheric vapor pressure (KPa) (1000Pa=1000.1000.g.100^-1.cm^-1.s^-2) + RHOV_sur(KT)=RHOV(NN); + % Theta_LL_sur(KT)=Theta_LL(NL,2); + % + % Theta_UU_sur(KT)=Theta_UU(NL,2); + P_Va(KT)=0.611*exp(17.27*Ta(KT)/(Ta(KT)+237.3))*HR_a(KT); %The atmospheric vapor pressure (KPa) (1000Pa=1000.1000.g.100^-1.cm^-1.s^-2) - RHOV_A(KT)=P_Va(KT)*1e4/(Rv*(Ta1(KT)+273.15)); % g.cm^-3; Rv-cm^2.s^-2.Cels^-1 + RHOV_A(KT)=P_Va(KT)*1e4/(Rv*(Ta(KT)+273.15)); % g.cm^-3; Rv-cm^2.s^-2.Cels^-1 z_ref=200; % cm The reference height of tempearature measurement (usually 2 m) d0_disp=0; % cm The zero-plane displacement (=0 m) - z_srT=0.1; % cm The surface roughness for the heat flux (=0.001m) + z_srT=0.1; % cm The surface roughness for the heat flux (=0.001m) 0.01m VK_Const=0.41; % The von Karman constant (=0.41) - z_srm=0.1; % cm The surface roughness for momentum flux (=0.001m) - U_wind=198.4597; % The mean wKTd speed at reference height.(cm.s^-1) + z_srm=0.1; % cm The surface roughness for momentum flux (=0.001m) 0.01m + U_wind=198.4597; % The mean wind speed at reference height.(cm.s^-1) - MO(KT)=((Ta1(KT)+273.15)*U(KT)^2)/(g*(Ta1(KT)-Ts1(KT))*log(z_ref/z_srm)); % Wind speed should be KT cm.s^-1, MO-cm; + MO(KT)=(Ta(KT)*U(KT)^2)/(g*(Ta(KT)-T(NN))*log(z_ref/z_srm)); % Wind speed should be in cm.s^-1, MO-cm; Zeta_MO(KT)=z_ref/MO(KT); - if abs(Ta1(KT)-Ts1(KT))<=0.01 + if abs(Ta(KT)-T(NN))<=0.01 Stab_m(KT)=0; Stab_T(KT)=0; - elseif Ta1(KT)0.001s.cm^-1 + + r_a_SOIL(KT) = log((2.0)/0.001)*log(2.0/0.001)/((k^2)*U(KT))*100; %(s.m^-1) ORIGINAL Zom=0.0058 + Evapo(KT)=(RHOV_sur(KT)-RHOV_A(KT))/(Resis_s(KT)+r_a_SOIL(KT)/100); + % PT/PE - Penman-Montheith % mm.day-1 % FAO56 pag19 eq3 % VEG - PT_PM_VEG(KT) = (DELTA(KT)*(Rn_vege(KT))+ro_a(KT)*Cp*(e0_Ta(KT)-e_a(KT))/r_a_VEG(KT))/((DELTA(KT) + gama*(1+r_s_VEG(KT)/r_a_VEG(KT))))/1000000/lambdav; % mm s-1 - % reference et ET0 - %PT_PM_0(KT) = (0.408*DELTA(KT)*Rn(KT)+gama*900/(Ta(KT)+273)*(e0_Ta(KT)-e_a(KT))*u_2(KT))/(DELTA(KT) + gama*(1+0.34*u_2(KT))); - %T_act(KT)=PT_PM_0(KT)*Kcb(KT); - % for SOIL - PE_PM_SOIL(KT) = (DELTA(KT)*(Rn_SOIL(KT)-G(KT))+ro_a(KT)*Cp*(e0_Ta(KT)-e_a(KT))/r_a_SOIL(KT))/((DELTA(KT) + gama*(1+r_s_SOIL(KT)/r_a_SOIL(KT))))/1000000/lambdav; % mm s-1 - Evap(KT)=0.1*PE_PM_SOIL(KT); % transfer to second value + PT_PM_VEG(KT) = (DELTA(KT)*(Rn(KT))+3600*ro_a(KT)*Cp*(e0_Ta(KT)-e_a(KT))/r_a_VEG(KT))/(lambdav*(DELTA(KT) + gama*(1+r_s_VEG(KT)/r_a_VEG(KT))))/3600; + + if LAI(KT)==0 || hh_v(KT)==0 + PT_PM_VEG(KT)=0; + end + PE_PM_SOIL(KT) = (DELTA(KT)*(Rn_SOIL(KT))+3600*ro_a(KT)*Cp*(e0_Ta(KT)-e_a(KT))/r_a_SOIL(KT))/(lambdav*(DELTA(KT) + gama*(1+r_s_SOIL(KT)/r_a_SOIL(KT))))/3600; + Evap(KT)=0.1*PE_PM_SOIL(KT); % transfer to second value-G_SOIL(KT) +% Evap(KT)=LE_msr(KT); EVAP(KT,1)=Evap(KT); - Tp_t(KT)=0.1*PT_PM_VEG(KT); % transfer to second value + Tp_t(KT)=0.1*PT_PM_VEG(KT); %transfer to second value TP_t(KT,1)=Tp_t(KT); - % water stress function parameters - H1=-15;H2=-50;H4=-9000;H3L=-900;H3H=-500; - if Tp_t(KT)<0.02/3600 - H3=H3L; - elseif Tp_t(KT)>0.05/3600 - H3=H3H; + +if rwuef==1 + if KT<=3288+1103 + H1=0;H2=-31;H4=-8000;H3L=-600;H3H=-300; + if Tp_t(KT)<0.02/3600 + H3=H3L; + elseif Tp_t(KT)>0.05/3600 + H3=H3H; + else + H3=H3H+(H3L-H3H)/(0.03/3600)*(0.05/3600-Tp_t(KT)); + end else - H3=H3H+(H3L-H3H)/(0.03/3600)*(0.05/3600-Tp_t(KT)); + H1=-1;H2=-5;H4=-16000;H3L=-600;H3H=-300; + if Tp_t(KT)<0.02/3600 + H3=H3L; + elseif Tp_t(KT)>0.05/3600 + H3=H3H; + else + H3=H3H+(H3L-H3H)/(0.03/3600)*(0.05/3600-Tp_t(KT)); + end end - % piecewise linear reduction function MN=0; for ML=1:NL for ND=1:2 MN=ML+ND-1; - if hh(MN) >=H1, + if hh(MN) >=H1 alpha_h(ML,ND) = 0; - elseif hh(MN) >=H2, + elseif hh(MN) >=H2 alpha_h(ML,ND) = (H1-hh(MN))/(H1-H2); - elseif hh(MN) >=H3, + elseif hh(MN) >=H3 alpha_h(ML,ND) = 1; - elseif hh(MN) >=H4, + elseif hh(MN) >=H4 alpha_h(ML,ND) = (hh(MN)-H4)/(H3-H4); else alpha_h(ML,ND) = 0; @@ -192,15 +213,16 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%% Root lenth distribution %%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Lm=50; - RL0=1; - r=9.48915E-07; % root growth rate cm/s - fr(KT)=RL0/(RL0+(Lm-RL0)*exp((-1)*(50))); - LR(KT)=Lm*fr(KT); - RL=300; + + Elmn_Lnth=0; + RL=sum(DeltZ); + Elmn_Lnth(1)=0; + RB=0.9; + LR=log(0.01)/log(RB); + RY=1-RB^(LR); - if LR(KT)<=1 + if LR<=1 for ML=1:NL-1 % ignore the surface root water uptake 1cm for ND=1:2 MN=ML+ND-1; @@ -208,15 +230,26 @@ end end else - for ML=1:NL - Elmn_Lnth=Elmn_Lnth+DeltZ(ML); - if Elmn_Lnth=RL-LR(KT) && Elmn_Lnth=RL-LR(KT) && Elmn_Lnth-300 && lEstot>-300 && any(TT>5)) + lambda1 = (2.501-0.002361*Ta(KT))*1E6; + lambda2 = (2.501-0.002361*Tss)*1E6; + Evap(KT)=lEstot/lambda2*0.1; % transfer to second value unit: cm s-1 + EVAP(KT,1)=Evap(KT); + Tp_t(KT)=lEctot/lambda1*0.1; % transfer to second value + Srt1=RWU*100./DeltZ'; else -Evap(KT)=lEstot/2454000*0.1; % transfer to second value unit: cm s-1 -EVAP(KT,1)=Evap(KT); -Tp_t(KT)=lEctot/2454000*0.1; % transfer to second value -Srt1=RWU*100./DeltZ'; + Evap(KT)=0; % transfer to second value unit: cm s-1 + EVAP(KT,1)=0; + Tp_t(KT)=0; % transfer to second value + Srt1=0./DeltZ'; +end +RWUtot(:,KT)=RWU; +RWUtott=sum(RWUtot); +RWUtottt=RWUtott*3600*1000; +EVAPO(KT)=Evap(KT); for ML=1:NL for ND=1:2 MN=ML+ND-1; @@ -271,6 +323,6 @@ end Trap(KT)=0; Trap(KT)=Tp_t(KT); % root water uptake integration by DeltZ; - end - + +end \ No newline at end of file diff --git a/src/Forcing_PARM.m b/src/Forcing_PARM.m index ffa3984f..b1699ee3 100644 --- a/src/Forcing_PARM.m +++ b/src/Forcing_PARM.m @@ -1,113 +1,28 @@ function Forcing_PARM -global Umax Umin tmax1 DayNum Hrmax Hrmin Tmax Tmin Um Ur DURTN -global Rn TIMEOLD -global Ta Ts U HR_a SH Rns Rnl TIME KT P_Va RHOV_A Rv TopPg h_SUR NBCT -global Ts_msr +global Umax Umin tmax1 DayNum Hrmax Hrmin Tmax Tmin Um Ur DURTN Tsmax Tsmin +global Pg_w Pg_a0 Pg_a Pg_b Rn TIMEOLD DELT +global Ta Ts U HR_a SH Rns Rnl TIME KT P_Va RHOV_A Rv TopPg h_SUR Hsur_w Hsur_a0 Hsur_a Hsur_b NBCT +global Ts_a0 Ts_a Ts_w Ts_b Ts_msr Tbtm Tb_msr Ta_msr RH_msr Rn_msr WS_msr G_msr Pg_msr G_SOIL HourInput Rns_msr SH_msr LET LE_msr SUMTIME NoTime Precip Precip_msr LAI_msr Gvc Tss Tsss - if TIMEOLD==KT - Ta(KT)=0;HR_a(KT)=0;Ts(KT)=0;U(KT)=0;SH(KT)=0;Rns(KT)=0;Rnl(KT)=0;Rn(KT)=0;TopPg(KT)=0;h_SUR(KT)=0; - end - if NBCT==1 && KT==1 - Ts(1)=0; - end - - - Tmax=[31.3 28.3 35.5 32.9 38.1 38.3 37.2 36.1 31.6 28.4 33.2 30.1 36.6 34 35 32.1 29.1 26.7 30.8 31.5 32 28.9 27.3 33.2 29.6 28.5 30.3 31.8 28.4 26.4 28.9 28.8 31 32.8 31.9 32 26.8 32.1 34.6 30.6 32.4 33 35 35.7 35.4 30.8 27.4 30.5 33.1 32.3 32.3 34.3 35.9 36.4 37.5 33.8 34.5 33.6 32.5 33.1 34.1 31.9 31.2 32 31.2 30.4 27 33.4 29.4 27.9 28.7 24.9 26.5 22.8 27.5 28.5 26 25.4 27 31.1 28.9 31.6 31.9 33.8 31.7 34 30.4 28.7 23.6 21.4 25.5 21.6 20.2 23.4 19.5 19.7 25.4 32.7 28.4 23.5 29 24.1]; - Tmin=[21.7 22.2 19.8 26.7 19.3 19 21.1 25.6 26.2 23.2 23.3 22.3 23.2 22 24 24.4 22.6 22.5 20.8 23.9 22.7 24 22.7 18.3 22 21.2 21.3 21.1 23.6 21.1 21.4 23.2 23.7 22.9 24.9 22 21.2 18.2 21.2 19.8 22.4 23.2 24 23.4 23.9 19.8 20.1 18.4 20.5 23.3 21.2 22.1 22.5 23.1 25.2 25.5 21.6 22.4 20.3 21.2 22.5 23.3 22.9 22.9 20.4 22.3 19.1 15.9 18 16.4 18 18.6 18 18.7 16.5 18.4 18.8 17.5 17.2 17.1 18.9 17.1 12.7 15.2 17.1 18.5 20.8 21.6 17.5 18.6 18.5 18.4 13.4 14.7 12.6 12.2 11.7 11.5 13.1 14.2 16.6 13.1]; - - - % Unit of windspeed (cm/s) - Um=100.*[1.121926613 0.822746183 0.822746183 0.822746183 1.570697258 1.79508258 1.421107043 1.645492365 1.047131505 0.972336398 0.747951075 2.169058118 1.570697258 0.89754129 0.972336398 2.169058118 2.169058118 2.842214086 1.047131505 2.169058118 1.271516828 1.271516828 2.169058118 0.747951075 0.673155968 1.645492365 1.19672172 0.747951075 1.19672172 1.570697258 0.747951075 1.121926613 1.346311935 1.346311935 2.169058118 1.720287473 1.047131505 1.121926613 0.822746183 1.121926613 0.89754129 0.89754129 0.822746183 1.047131505 1.121926613 2.991804301 0.89754129 0.972336398 1.047131505 1.271516828 0.822746183 0.822746183 0.59836086 0.747951075 1.346311935 0.673155968 1.047131505 1.49590215 1.047131505 1.19672172 1.271516828 1.421107043 0.89754129 0.972336398 0.89754129 1.047131505 3.290984731 0.89754129 0.972336398 0.822746183 0.972336398 1.121926613 0.822746183 1.645492365 1.19672172 0.822746183 0.822746183 0.822746183 0.822746183 0.972336398 0.822746183 1.49590215 1.49590215 0.89754129 0.972336398 0.59836086 1.421107043 0.673155968 1.346311935 0.448770645 0.59836086 1.271516828 2.767418978 0.89754129 0.59836086 0.747951075 0.972336398 0.822746183 1.19672172 1.121926613 1.19672172 0.972336398]; - Hrmax=0.01.*[82 87 95 73 75 61 61 67 88 96 98 100 95 82 86 72 84 75 87 83 99 94 90 79 100 100 91 99 100 100 100 94 94 98 81 90 96 100 99 100 95 98 96 100 91 98 100 100 100 100 100 98 100 100 79 89 97 74 100 88 91 88 95 85 79 89 93 100 98 85 83 93 100 95 98 98 95 100 96 85 99 100 100 100 78 91 70 97 100 100 100 100 97 100 100 100 100 100 100 95 100 100]; - Hrmin=0.01.*[42 53 29 29 15 21 29 37 50 74 58 69 31 48 46 48 58 57 51 55 51 70 66 41 58 63 45 45 62 73 62 68 60 56 51 50 60 46 41 51 55 56 48 42 43 58 62 54 55 44 54 50 44 42 31 33 35 42 41 44 43 46 49 39 49 57 63 28 32 43 45 59 50 67 42 42 55 55 50 35 47 34 28 24 38 31 44 53 74 76 56 74 79 37 51 50 35 22 35 59 23 40]; - % Unit in cm/s - if TIME=-1e-6 + TT_CRIT(MN)=T0; + else + TT_CRIT(MN)=T0+g*T0*HHH(MN)/L_f/1e4/2; + end + if TT_CRIT(MN)<=T0+Tmin + TT_CRIT(MN)=T0+Tmin; % unit K + elseif TT_CRIT(MN)>=T0 + TT_CRIT(MN)=T0; + else + TT_CRIT(MN)=TT_CRIT(MN); + end + if heaviside(TT_CRIT(MN)-(TT(MN)+T0))>0 + hh_frez(MN)=L_f*1e4*((TT(MN)+T0)-TT_CRIT(MN))/g/T0; + else + hh_frez(MN)=0; + end + if HHH(MN)<=hd + hh_frez(MN)=0; + end + if hh_frez(MN)>=-1e-6 + hh_frez(MN)=0; + elseif hh_frez(MN)<=-1e6 + hh_frez(MN)=-1e6; + end + end \ No newline at end of file diff --git a/src/Initial_root_biomass.m b/src/Initial_root_biomass.m new file mode 100644 index 00000000..2182639f --- /dev/null +++ b/src/Initial_root_biomass.m @@ -0,0 +1,28 @@ +function [Rl] = Initial_root_biomass(RTB,DeltZ_R,rroot,ML) +global Ztot +%rri=zeros(1,45); +root_den = 250*1000; %% [gDM / m^3] Root density Jackson et al., 1997 +R_C = 0.488; %% [gC/gDM] Ratio Carbon-Dry Matter in root Jackson et al., 1997 +beta = 0.993; %% ? is a plant-dependent root distribution parameter adopted from Jackson et al. (1996) +Rltot = RTB/R_C/root_den/(pi*(rroot^2)); %% %% root length index [m root / m^2 PFT] + %Ztot=DeltZ'; + % Ztot=flip(Ztot); + Ztot=cumsum(DeltZ_R',1); + %Ztot=flip(Ztot); +for i=1:ML + if i==1 + ri(i)=(1-beta.^(Ztot(i)/2)); + else + ri(i)=beta.^(Ztot(i-1)-(DeltZ_R(i-1)/2))-beta.^(Ztot(i-1)+(DeltZ_R(i)/2)); + end +end +%for i=1:ML +% if i==1 + % rri(i)=ri(i)./2; + % else + % rri(i)=(ri(i)+ri(i-1))./2; + % end +%end +Rl=(ri.*Rltot./(DeltZ_R./100))'; +Rl=flipud(Rl); +end \ No newline at end of file diff --git a/src/Latent.m b/src/Latent.m index ee511938..8f700b22 100644 --- a/src/Latent.m +++ b/src/Latent.m @@ -1,5 +1,7 @@ +% function Latent +% global TT L MN NN function [L]= Latent(TT,NN) for MN=1:NN - L(MN)=(2.501*10^6-2369.2*TT(MN))/1000; + L(MN)=(2.501*10^6-2369.2*TT(MN))/1000; % J g-1 end diff --git a/src/Max_Rootdepth.m b/src/Max_Rootdepth.m index 2d49f838..7aafd83d 100644 --- a/src/Max_Rootdepth.m +++ b/src/Max_Rootdepth.m @@ -1,43 +1,24 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Subfunction - Root - Depth % +% Subfunction - Root - Depth ¼ÆËãÔú¸ùÉî¶È % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%REFERENCES -function[bbx]=Max_Rootdepth(bbx,NL,KT,Ta) +function[bbx]=Max_Rootdepth(bbx,NL,KT,TT) %%% INPUTS -global DeltZ LR +global DeltZ Tot_Depth R_depth % BR = 10:1:650; %% [gC /m^2 PFT] % rroot = 0.5*1e-3 ; % 3.3*1e-4 ;%% [0.5-6 *10^-3] [m] root radius %%% OUTPUTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%% Root lenth distribution %%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - if Ta>40 - Ta=40; - end - if Ta<10 - Ta=10; - end - % Lm=123; - % RL0=20; - %r=9.48915E-07; % root growth rate cm/s - % fr(KT)=RL0/(RL0+(Lm-RL0)*exp((-1)*(r*TIME))); - % LR(KT)=Lm*fr(KT); - if KT<=1 - LR=35; - else - LR=LR+(Ta-10)*0.0015; - if LR>55 - LR=55; - end - end - RL=500; + R_depth=350;%¸ù³¤ Elmn_Lnth=0; for ML=1:NL Elmn_Lnth=Elmn_Lnth+DeltZ(ML); - if Elmn_Lnth=RL-LR && Elmn_Lnth<=RL-0.1*LR + elseif Elmn_Lnth>=Tot_Depth-R_depth && Elmn_Lnth<=Tot_Depth-5 %&& TT(ML)>0 bbx(ML)=1; else bbx(ML)=0; diff --git a/src/ObservationPoints.m b/src/ObservationPoints.m index 0d5f3bd4..4fad3d31 100644 --- a/src/ObservationPoints.m +++ b/src/ObservationPoints.m @@ -8,16 +8,18 @@ % Sim_Theta(KT,1:5)=Theta_LLL(Moni_Depth_SM,1,KT); % Sim_Temp(KT,1:7)=TTT(Moni_Depth,KT); - - - Moni_Depth=45:-1:1; - Moni_Depth_SM=45:-1:1; - Moni_Depth_RT=45:-1:1; + + NL=54; + Moni_Depth=NL:-1:1; + Moni_Depth_SM=NL:-1:1; + Moni_Depth_RT=NL:-1:1; Sim_Theta(KT,1:length(Moni_Depth_SM))=Theta_LLL(Moni_Depth_SM,1,KT); + Sim_Theta_I(KT,1:length(Moni_Depth_SM))=Theta_III(Moni_Depth_SM,1,KT); + Sim_Theta_U(KT,1:length(Moni_Depth_SM))=Theta_UUU(Moni_Depth_SM,1,KT); Sim_Temp(KT,1:length(Moni_Depth))=TTT(Moni_Depth,KT); if rwuef==1 Sim_SRT(KT,1:length(Moni_Depth))=SRT(Moni_Depth,KT); end - + diff --git a/src/PlotResults1.m b/src/PlotResults1.m index 24bec32b..a647999e 100644 --- a/src/PlotResults1.m +++ b/src/PlotResults1.m @@ -1,34 +1,34 @@ -global RHOV_A Msrmn_Fitting Msr_Mois Msr_Temp Msr_Time QMTT%Trap EVAP_ind TRAP_ind Sim_Theta_ind Sim_Theta EVAP_dir TRAP_dir ET_H E_D ET_D sumTRAP_dir sumEVAP_dir +global RHOV_A Msrmn_Fitting Msr_Mois Msr_Temp Msr_Time %Trap EVAP_ind TRAP_ind Sim_Theta_ind Sim_Theta EVAP_dir TRAP_dir ET_H E_D ET_D sumTRAP_dir sumEVAP_dir disp ('Convergence Achieved.') figure; -subplot(3,3,1); plot (hhh, 'DisplayName','hhh', 'YDataSource', 'hhh'); -subplot(3,3,2); plot(TTT, 'DisplayName','TTT', 'YDataSource', 'TTT'); -subplot(3,3,3); plot(SUMTIME,QMTT); -subplot(3,3,4); plot(SUMTIME,Evapo); -subplot(3,3,5); plot(SUMTIME,trap); -subplot(3,3,6); plot(SUMTIME,Ta(1:KT)); -subplot(3,3,7); plot(SUMTIME,U(1:KT)); -subplot(3,3,8); plot(SUMTIME,HR_a(1:KT)); -subplot(3,3,9); plot(SUMTIME,RHOV_A(1:KT)); +subplot(3,3,1): plot (hhh, 'DisplayName','hhh', 'YDataSource', 'hhh'); +subplot(3,3,2): plot(TTT, 'DisplayName','TTT', 'YDataSource', 'TTT'); +subplot(3,3,3): plot(SUMTIME,QMT); +subplot(3,3,4): plot(SUMTIME,Evap); +subplot(3,3,5): plot(SUMTIME,Trap); +subplot(3,3,6): plot(SUMTIME,Ta(1:KT)); +subplot(3,3,7): plot(SUMTIME,U(1:KT)); +subplot(3,3,8): plot(SUMTIME,HR_a(1:KT)); +subplot(3,3,9): plot(SUMTIME,RHOV_A(1:KT)); if Msrmn_Fitting fig1=figure; - subplot(5,1,1);plot (SUMTIME/3600, Sim_Theta_ind(:,17), 'r-',SUMTIME/3600,Sim_Theta(:,17), 'g-',Msr_Time/3600, Msr_Mois(1,:),'b.','LineWidth',2);title('20cm'); - subplot(5,1,2);plot (SUMTIME/3600, Sim_Theta_ind(:,21), 'r-',SUMTIME/3600,Sim_Theta(:,21), 'g-',Msr_Time/3600, Msr_Mois(2,:),'b.','LineWidth',2);title('40cm'); - subplot(5,1,3);plot (SUMTIME/3600, Sim_Theta_ind(:,24), 'r-',SUMTIME/3600,Sim_Theta(:,24), 'g-',Msr_Time/3600, Msr_Mois(3,:),'b.','LineWidth',2);title('60cm'); + subplot(5,1,1):plot (SUMTIME/3600, Sim_Theta_ind(:,17), 'r-',SUMTIME/3600,Sim_Theta(:,17), 'g-',Msr_Time/3600, Msr_Mois(1,:),'b.','LineWidth',2);title('20cm'); + subplot(5,1,2):plot (SUMTIME/3600, Sim_Theta_ind(:,21), 'r-',SUMTIME/3600,Sim_Theta(:,21), 'g-',Msr_Time/3600, Msr_Mois(2,:),'b.','LineWidth',2);title('40cm'); + subplot(5,1,3):plot (SUMTIME/3600, Sim_Theta_ind(:,24), 'r-',SUMTIME/3600,Sim_Theta(:,24), 'g-',Msr_Time/3600, Msr_Mois(3,:),'b.','LineWidth',2);title('60cm'); ylabel('Soil moisture \theta','Rotation',90) - subplot(5,1,4);plot (SUMTIME/3600, Sim_Theta_ind(:,26), 'r-',SUMTIME/3600,Sim_Theta(:,26), 'g-',Msr_Time/3600, Msr_Mois(4,:),'b.','LineWidth',2);title('80cm'); - subplot(5,1,5);plot (SUMTIME/3600, Sim_Theta_ind(:,28), 'r-',SUMTIME/3600,Sim_Theta(:,28), 'g-',Msr_Time/3600, Msr_Mois(5,:),'b.','LineWidth',2);title('100cm'); + subplot(5,1,4):plot (SUMTIME/3600, Sim_Theta_ind(:,26), 'r-',SUMTIME/3600,Sim_Theta(:,26), 'g-',Msr_Time/3600, Msr_Mois(4,:),'b.','LineWidth',2);title('80cm'); + subplot(5,1,5):plot (SUMTIME/3600, Sim_Theta_ind(:,28), 'r-',SUMTIME/3600,Sim_Theta(:,28), 'g-',Msr_Time/3600, Msr_Mois(5,:),'b.','LineWidth',2);title('100cm'); xlabel('Time(h)'); legend('\thetaind','\thetadir','\thetaobs') fig2=figure; - subplot(5,1,1);plot (SUMTIME/3600, Sim_Temp_ind(:,17), 'r-' ,SUMTIME/3600, Sim_Temp(:,17), 'g-' ,Msr_Time/3600, Msr_Temp(1,:),'b.','LineWidth',2);title('20cm'); - subplot(5,1,2);plot (SUMTIME/3600, Sim_Temp_ind(:,21), 'r-' ,SUMTIME/3600, Sim_Temp(:,21), 'g-' ,Msr_Time/3600, Msr_Temp(2,:),'b.','LineWidth',2);title('40cm'); - subplot(5,1,3);plot (SUMTIME/3600, Sim_Temp_ind(:,24), 'r-' ,SUMTIME/3600, Sim_Temp(:,24), 'g-' ,Msr_Time/3600, Msr_Temp(3,:),'b.','LineWidth',2);title('60cm'); + subplot(5,1,1):plot (SUMTIME/3600, Sim_Temp_ind(:,17), 'r-' ,SUMTIME/3600, Sim_Temp(:,17), 'g-' ,Msr_Time/3600, Msr_Temp(1,:),'b.','LineWidth',2);title('20cm'); + subplot(5,1,2):plot (SUMTIME/3600, Sim_Temp_ind(:,21), 'r-' ,SUMTIME/3600, Sim_Temp(:,21), 'g-' ,Msr_Time/3600, Msr_Temp(2,:),'b.','LineWidth',2);title('40cm'); + subplot(5,1,3):plot (SUMTIME/3600, Sim_Temp_ind(:,24), 'r-' ,SUMTIME/3600, Sim_Temp(:,24), 'g-' ,Msr_Time/3600, Msr_Temp(3,:),'b.','LineWidth',2);title('60cm'); ylabel('Soil temperature T','Rotation',90) - subplot(5,1,4);plot (SUMTIME/3600, Sim_Temp_ind(:,26), 'r-' ,SUMTIME/3600, Sim_Temp(:,26), 'g-' ,Msr_Time/3600, Msr_Temp(4,:),'b.','LineWidth',2);title('80cm'); - subplot(5,1,5);plot (SUMTIME/3600, Sim_Temp_ind(:,28), 'r-' ,SUMTIME/3600, Sim_Temp(:,28), 'g-' ,Msr_Time/3600, Msr_Temp(5,:),'b.','LineWidth',2);title('100cm'); + subplot(5,1,4):plot (SUMTIME/3600, Sim_Temp_ind(:,26), 'r-' ,SUMTIME/3600, Sim_Temp(:,26), 'g-' ,Msr_Time/3600, Msr_Temp(4,:),'b.','LineWidth',2);title('80cm'); + subplot(5,1,5):plot (SUMTIME/3600, Sim_Temp_ind(:,28), 'r-' ,SUMTIME/3600, Sim_Temp(:,28), 'g-' ,Msr_Time/3600, Msr_Temp(5,:),'b.','LineWidth',2);title('100cm'); xlabel('Time(h)'); legend('Tind','Tdir','Tobs') fig3=figure; @@ -37,11 +37,11 @@ ylabel('EvapoTranspiration ET(mm)','Rotation',90); legend('ETind','ETdir','ETobs','Location','best') fig4=figure; - subplot(2,1,1);plot (175:275, sumEVAP_ind+sumTRAP_ind, 'b-' ,175:275, sumEVAP_dir+sumTRAP_dir, 'r-' ,175:275,ET_D(1:101),'ko','LineWidth',2,'MarkerSize',5); + subplot(2,1,1):plot (175:275, sumEVAP_ind+sumTRAP_ind, 'b-' ,175:275, sumEVAP_dir+sumTRAP_dir, 'r-' ,175:275,ET_D(1:101),'ko','LineWidth',2,'MarkerSize',5); xlabel('DOY'); ylabel('EvapoTranspiration ET(mm)','Rotation',90); legend('ETind','ETdir','ETobs','Location','best') - subplot(2,1,2);plot (175:275, sumEVAP_ind, 'b-' ,175:275, sumEVAP_dir, 'r-' ,175:275,E_D(1:101),'ko','LineWidth',2,'MarkerSize',5); + subplot(2,1,2):plot (175:275, sumEVAP_ind, 'b-' ,175:275, sumEVAP_dir, 'r-' ,175:275,E_D(1:101),'ko','LineWidth',2,'MarkerSize',5); xlabel('DOY'); ylabel('Evaporation E(mm)','Rotation',90); legend('Eind','Edir','Eobs','Location','best') diff --git a/src/Root_properties.m b/src/Root_properties.m index 578b15d1..189ec95e 100644 --- a/src/Root_properties.m +++ b/src/Root_properties.m @@ -5,15 +5,23 @@ %%REFERENCES function[Rl]=Root_properties(Rl,Ac,rroot,frac,bbx,KT) %%% INPUTS -global DeltZ LAI +global DeltZ sfactor LAI_msr % BR = 10:1:650; %% [gC /m^2 PFT] % rroot = 0.5*1e-3 ; % 3.3*1e-4 ;%% [0.5-6 *10^-3] [m] root radius %%% OUTPUTS - % if KT<3800 - fr=-0.0296*LAI(KT)+0.30; - % else - % fr=0.001; - % end +if KT<2880 +fr=0.3*3*exp(-0.15*LAI_msr(KT))/(exp(-0.15*LAI_msr(KT))+2*sfactor); + if fr<0.15 + fr=0.15; + end +else + fr=0.001; +end + %if KT<3840 + %fr=-0.091*LAI(KT)+0.40; + % else + % fr=0.001; + %end %elseif KT<3200 % fr=0.05; %else @@ -27,21 +35,24 @@ if (~isnan(Ac))||(Ac>0) Rl=Rl.*DeltZ0; Delta_Rltot = BR/R_C/root_den/(pi*(rroot^2)); %% %% root length index [m root / m^2 PFT] -for i=1:nn - if Rl(i)>2000 - frac(i)=0; - end -end +%for i=1:nn +% if Rl(i)>50000 +% frac(i)=0; +% end +%end +if ~isnan(frac) frac=frac/sum(sum(frac)); -Delta_Rl=Delta_Rltot*frac.*bbx; +else + frac=Rl./sum(sum(Rl)); +end +Delta_Rl=frac.*bbx*Delta_Rltot; Rl=Rl+Delta_Rl; Rl=Rl./DeltZ0; else -Rl=Rl; -end -for i=1:nn - if Rl(i)>2000 - Rl(i)=2000; - end end +%for i=1:nn +% if Rl(i)>50000 +% Rl(i)=50000; +% end +%end end \ No newline at end of file diff --git a/src/SOIL1.m b/src/SOIL1.m index a9a13b32..7df54018 100644 --- a/src/SOIL1.m +++ b/src/SOIL1.m @@ -7,7 +7,8 @@ for ML=1:NL % Soil type index; - J=IS(ML); + J=ML; +% J=IS(ML); % The average moisture content of an element; EX=0.5*(Theta_L(ML,1)+Theta_L(ML,2)); % Has average trend of wetting in the element changed? If the trend is diff --git a/src/SOIL2.m b/src/SOIL2.m index 6f515119..0a2b7e95 100644 --- a/src/SOIL2.m +++ b/src/SOIL2.m @@ -1,8 +1,11 @@ -function [hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J) - +function [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se) + if hThmrl==1 + for MN=1:NN - COR(MN)=exp(0.0068*(TT(MN)-Tr)); + CORh(MN)=0.0068; + COR(MN)=exp(-1*CORh(MN)*(TT(MN)-Tr));%*COR21(MN) + if COR(MN)==0 COR(MN)=1; end @@ -17,8 +20,7 @@ hhU(MN)=COR(MN)*hh(MN); hh(MN)=hhU(MN); end - -[Theta_LL,Se,KL_h,DTheta_LLh,J,hh]=CondL_h(Theta_r,Theta_s,Alpha,hh,n,m,Ks,NL,Theta_L,h,IS,KIT,TT,Thmrlefc,CKTN,POR,J); +[Theta_LL,Se,KfL_h,KfL_T,DTheta_LLh,hh,hh_frez,Theta_UU,DTheta_UUh,Theta_II,KL_h]=CondL_h(Theta_r,Theta_s,Alpha,hh,hh_frez,h_frez,n,m,Ks,NL,Theta_L,h,KIT,TT,Thmrlefc,POR,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,Theta_II,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); for MN=1:NN hhU(MN)=hh(MN); hh(MN)=hhU(MN)/COR(MN); @@ -26,9 +28,10 @@ if Hystrs==0 for ML=1:NL - J=IS(ML); + J=ML; +% J=IS(ML); for ND=1:2 - Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND); + Theta_V(ML,ND)=POR(J)-Theta_UU(ML,ND);%-Theta_II(ML,ND); % Theta_LL==>Theta_UU if Theta_V(ML,ND)<=1e-14 Theta_V(ML,ND)=1e-14; end @@ -37,18 +40,19 @@ end else for ML=1:NL - J=IS(ML); + J=ML; +% J=IS(ML); for ND=1:2 if IH(ML)==2 if XWRE(ML,ND)0 DTheta_LLh(ML,ND)=DTheta_LLh(ML,ND)*(Theta_LL(ML,ND)/XSAVE-XSAVE/Theta_s(J)); end - Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND); + Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND)-Theta_II(ML,ND); end end if IH(ML)==1 @@ -58,15 +62,18 @@ if KIT>0 DTheta_LLh(ML,ND)=2*DTheta_LLh(ML,ND)*(1-XSAVE/Theta_s(J)); end - Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND); + Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND)-Theta_II(ML,ND); else Theta_LL(ML,ND)=Theta_LL(ML,ND)+XWRE(ML,ND)*(1-Theta_LL(ML,ND)/Theta_s(J)); if KIT>0 DTheta_LLh(ML,ND)=DTheta_LLh(ML,ND)*(1-XWRE(ML,ND)/Theta_s(J)); end - Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND); + Theta_V(ML,ND)=POR(J)-Theta_LL(ML,ND)-Theta_II(ML,ND); end - end + end + if Theta_V(ML,ND)<=1e-14 % consider the negative conditions? + Theta_V(ML,ND)=1e-14; + end Theta_g(ML,ND)=Theta_V(ML,ND); end end diff --git a/src/STEMMUS_SCOPE.m b/src/STEMMUS_SCOPE.m index a2fa67b0..52b38d77 100644 --- a/src/STEMMUS_SCOPE.m +++ b/src/STEMMUS_SCOPE.m @@ -1,7 +1,10 @@ -%% STEMMUS-SCOPE.m (script) + %% STEMMUS-SCOPE.m (script) % STEMMUS-SCOPE is a model for Integrated modeling of canopy photosynthesis, fluorescence, -% and the transfer of energy, mass, and momentum in the soil–plant–atmosphere continuum (STEMMUS–SCOPE v1.0.0) +% and the transfer of energy, mass, and momentum in the soil–plant–atmosphere continuum +% +% Version: 1.0.1 +% % Copyright (C) 2021 Yunfei Wang, Lianyu Yu, Yijian Zeng, Christiaan Van der Tol, Bob Su % Contact: y.zeng@utwente.nl % @@ -20,38 +23,45 @@ %% %% 0. globals +run filesread %prepare input files +run Constants %input soil parameters +global i tS KT Delt_t TEND TIME MN NN NL ML ND hOLD TOLD h hh T TT P_gOLD P_g P_gg Delt_t0 g +global KIT NIT TimeStep Processing +global SUMTIME hhh TTT P_ggg Theta_LLL DSTOR Thmrlefc CHK Theta_LL Theta_L Theta_UUU Theta_UU Theta_U Theta_III Theta_II Theta_I +global NBCh AVAIL Evap DSTOR0 EXCESS QMT RS BCh hN hSAVE NBChh DSTMAX Soilairefc Trap sumTRAP_dir sumEVAP_dir +global TSAVE IRPT1 IRPT2 AVAIL0 TIMEOLD TIMELAST SRT ALPHA BX alpha_h bx Srt KfL_hh KL_hh Chhh ChTT Khhh KhTT CTTT CTT_PH CTT_LT CTT_g CTT_Lg CCTT_PH CCTT_LT CCTT_g CCTT_Lg C_unsat c_unsat +global QL QL_h QL_T QV Qa KL_h Chh ChT Khh KhT SAVEDSTOR TRAP_ind TRAP_dir SAVEhh SAVEhhh Resis_a KfL_h KfL_T TTT_CRIT TT_CRIT T_CRIT TOLD_CRIT +global h_frez hh_frez hhh_frez hOLD_frez ISFT L_f T0 CTT EPCT EPCTT DTheta_LLh DTheta_LLT DTheta_UUh CKT CKTT DDTheta_LLh DDTheta_LLT DDTheta_UUh Lambda_Eff Lambda_eff EfTCON TTETCON TETCON NBCTB Tbtms Cor_TIME DDhDZ DhDZ DDTDZ DTDZ DDRHOVZ DRHOVZ +global DDEhBAR DEhBAR DDRHOVhDz DRHOVhDz EEtaBAR EtaBAR DD_Vg D_Vg DDRHOVTDz DRHOVTDz KKLhBAR KLhBAR KKLTBAR KLTBAR DDTDBAR DTDBAR QVV QLL CChh SAVEDTheta_LLT SAVEDTheta_LLh SAVEDTheta_UUh DSAVEDTheta_LLT DSAVEDTheta_LLh DSAVEDTheta_UUh +global QVT QVH QVTT QVHH SSa Sa HRA HR QVAA QVa QLH QLT QLHH QLTT DVH DVHH DVT DVTT SSe Se QAA QAa QL_TT QL_HH QLAA QL_a DPgDZ DDPgDZ k_g kk_g VV_A V_A Theta_r Theta_s m n Alpha SAVETheta_UU Gama_hh Theta_a Gama_h hm hd +global SAVEKfL_h KCHK FCHK TKCHK hCHK TSAVEhh SAVEhh_frez Precip SAVETT INDICATOR thermal +global Theta_g MU_a DeltZ Alpha_Lg +global Beta_g KaT_Switch +global D_V D_A fc Eta nD POR +global ThmrlCondCap ZETA XK DVT_Switch +global MU_W Ks RHOL +global Lambda1 Lambda2 Lambda3 RHO_bulk +global RHODA RHOV c_a c_V c_L +global ETCON EHCAP +global Xaa XaT Xah RDA Rv KL_T +global DRHOVT DRHOVh DRHODAt DRHODAz +global hThmrl Tr COR IS Hystrs XWRE +global Theta_V IH CORh XCAP Phi_s RHOI Lamda +global W WW D_Ta SSUR +global W_Chg SWCC Imped Ratio_ice ThermCond Beta_gBAR Alpha_LgBAR +global KLT_Switch xERR hERR TERR NBChB NBCT uERR +global L TCON_dry TPS1 TPS2 TCON0 XSOC TCON_s +global HCAP SF TCA GA1 GA2 GB1 GB2 HCD ZETA0 CON0 PS1 PS2 XWILT FEHCAP QMTT QMBB Evapo trap RnSOIL PrecipO global constants -global RWU -global HR U Precip G Rn LAI Ta1 Ts1 h_v rl_min HR_a Ts Ta Tss Taa Tcc bbx RWUtot Rls frac Tsss sfactortot sfactor -run Constants -Mdata=xlsread('E:\grassland\SCOPE-master\SCOPE_v1.73\src\Meterology data','sheet1','B5:AD17572'); -Ta1=Mdata(:,1); % air temperature -HR=Mdata(:,2)./100; % relative humidity -U=Mdata(:,3); % wind speed at 2m -Precip=Mdata(:,4)./10; % precipitation -Ts1=Mdata(:,5); % soil temperature at 20cm -Ts2=Mdata(:,6); % soil temperature at 40cm -Ts3=Mdata(:,7); % soil temperature at 60cm -SMC1=Mdata(:,8); % soil moisture content at 20cm -SMC2=Mdata(:,9); % soil moisture content at 40cm -SMC3=Mdata(:,10); % soil moisture content at 60cm -G1=Mdata(:,11:13); % soil heat flux -Rn=Mdata(:,14); % net rediation -LAI=Mdata(:,26); % leaf area index -h_v=Mdata(:,27); % canopy height -rl_min=Mdata(:,28); % minimum soil resistance -G=ones(17568,1); -G=nanmean(G1')'; -Tsss=Mdata(:,29); -HR_a=HR; -Ta=Ta1; -Ts=Ts1; +global RWU EVAP +global HR Precip Precipp Tss frac sfactortot sfactor Tsss fluxes lEstot lEctot NoTime DELT IGBP_veg_long latitude longitude reference_height canopy_height sitename Dur_tot Tmin TT + %% 1. define constants [constants] = io.define_constants(); - +[Rl] = Initial_root_biomass(RTB,DeltZ_R,rroot,ML); %% 2. simulation options path_of_code = cd; -run ../set_parameter_filenames; +run set_parameter_filenames; if length(parameter_file)>1, useXLSX = 0; else useXLSX = 1; end @@ -80,16 +90,16 @@ % 2: Lookup-Table (specify the values to be included) % 3: Lookup-Table with random input (specify the ranges of values) else - options = io.readStructFromExcel(['../' char(parameter_file)], 'options', 3, 1); + options = io.readStructFromExcel(['../input/' char(parameter_file)], 'options', 3, 1); end if options.simulation>2 || options.simulation<0, fprintf('\n simulation option should be between 0 and 2 \r'); return, end %% 3. file names if ~useXLSX - run(['../' parameter_file{2}]) + run(['../input/' parameter_file{2}]) else - [dummy,X] = xlsread(['../' char(parameter_file)],'filenames'); + [dummy,X] = xlsread(['../input/' char(parameter_file)],'filenames'); j = find(~strcmp(X(:,2),{''})); X = X(j,(1:end)); end @@ -108,10 +118,10 @@ %% 4. input data if ~useXLSX - X = textread(['../' parameter_file{3}],'%s'); %#ok + X = textread(['../input/' parameter_file{3}],'%s'); %#ok N = str2double(X); else - [N,X] = xlsread(['../' char(parameter_file)],'inputdata', ''); + [N,X] = xlsread(['../input/' char(parameter_file)],'inputdata', ''); X = X(9:end,1); end V = io.assignvarnames(); @@ -180,35 +190,86 @@ end end end - +V(48).Val=latitude; +V(49).Val=longitude; +V(62).Val=latitude; +V(63).Val=longitude; +V(29).Val=reference_height; +V(23).Val=canopy_height; +V(55).Val=mean(Ta_msr); +%Input T parameters for different vegetation type +if IGBP_veg_long(1:2)== ['P'; 'e'] %['Permanent Wetlands'] + V(14).Val= [0.2 0.3 288 313 328]; +elseif IGBP_veg_long(1:2)== ['E'; 'v'] %['Evergreen Broadleaf'] + V(14).Val= [0.2 0.3 283 311 328]; +elseif IGBP_veg_long(1:2)== ['D'; 'e'] %['Deciduous Broadleaf'] + V(14).Val= [0.2 0.3 283 311 328]; +elseif IGBP_veg_long(1:2)== ['M'; 'i'] %['Mixed Forests'] + V(14).Val= [0.2 0.3 281 307 328]; +elseif IGBP_veg_long(11:12)== ['N'; 'e'] %['Evergreen Needleleaf'] + V(14).Val= [0.2 0.3 278 303 328]; +elseif IGBP_veg_long(1:2)== ['C'; 'r'] %['Croplands'] + V(14).Val= [0.2 0.3 278 303 328]; +elseif IGBP_veg_long(1:2)== ['O'; 'p'] %['Open Shrublands'] + V(14).Val= [0.2 0.3 288 313 328]; +elseif IGBP_veg_long(1:2)== ['C'; 'l'] %['Closed Shrublands'] + V(14).Val= [0.2 0.3 288 313 328]; +elseif IGBP_veg_long(1:2)== ['S'; 'a'] %['Savannas'] + V(14).Val= [0.2 0.3 278 313 328]; +elseif IGBP_veg_long(1:2)== ['W'; 'o'] %['Woody Savannas'] + V(14).Val= [0.2 0.3 278 313 328]; +else %IGBP_veg_long(1)==['Grasslands'] + V(14).Val= [0.2 0.3 288 303 328]; +end +if IGBP_veg_long(1:2)== ['P'; 'e'] %['Permanent Wetlands'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['E'; 'v'] %['Evergreen Broadleaf'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['D'; 'e'] %['Deciduous Broadleaf'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['M'; 'i'] %['Mixed Forests'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(11:12)== ['N'; 'e'] %['Evergreen Needleleaf'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['C'; 'r'] %['Croplands'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['O'; 'p'] %['Open Shrublands'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['C'; 'l'] %['Closed Shrublands'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['S'; 'a'] %['Savannas'] + V(28).Val= [0.05]; +elseif IGBP_veg_long(1:2)== ['W'; 'o'] %['Woody Savannas'] + V(28).Val= [0.05]; +else %IGBP_veg_long(1)==['Grasslands'] + V(28).Val= [0.05]; +end +TZ=fix(longitude/15); +TZZ=mod(longitude,15); +if longitude>0 + if abs(TZZ)>7.5 + V(50).Val= TZ+1; + else + V(50).Val= TZ; + end +else + if abs(TZZ)>7.5 + V(50).Val= TZ-1; + else + V(50).Val= TZ; + end +end %% 5. Declare paths -path_input = '../../data/input/'; % path of all inputs +path_input = '../input/'; % path of all inputs %% 6. Numerical parameters (iteration stops etc) -iter.maxit = 600; % maximum number of iterations -iter.maxEBer = 1; %[W m-2] maximum accepted error in energy bal. +iter.maxit = 400; % maximum number of iterations +iter.maxEBer = 5; %[W m-2] maximum accepted error in energy bal. iter.Wc = 1; % Weight coefficient for iterative calculation of Tc %% 7. Load spectral data for leaf and soil -%opticoef = xlsread([path_input,'fluspect_parameters/',char(F(3).FileName)]); % file with leaf spectral parameters -%xlsread([path_input,'fluspect_parameters/',char(F(3).FileName)]); % file with leaf spectral parameters load([path_input,'fluspect_parameters/',char(F(3).FileName)]); rsfile = load([path_input,'soil_spectrum/',char(F(2).FileName)]); % file with soil reflectance spectra -% Optical coefficient data used by fluspect -% optipar.nr = opticoef(:,2); -% optipar.Kab = opticoef(:,3); -% optipar.Kca = opticoef(:,4); -% optipar.Ks = opticoef(:,5); -% optipar.Kw = opticoef(:,6); -% optipar.Kdm = opticoef(:,7); -% optipar.nw = opticoef(:,8); -% optipar.phiI = opticoef(:,9); -% optipar.phiII = opticoef(:,10); -% optipar.GSV1 = opticoef(:,11); -% optipar.GSV2 = opticoef(:,12); -% optipar.GSV3 = opticoef(:,13); -% optipar.KcaV = opticoef(:,14); -% optipar.KcaZ = opticoef(:,15); %% 8. Load directional data from a file directional = struct; @@ -291,61 +352,68 @@ atmo.M = helpers.aggreg(atmfile,spectral.SCOPEspec); %% 13. create output files -Output_dir = io.create_output_files(parameter_file, F, path_of_code, options, V, vmax, spectral); -%15 function MainLoop -global KT Delt_t TEND TIME MN NN NL ML ND hOLD TOLD h hh T TT P_gOLD P_g P_gg Delt_t0 -global KIT NIT TimeStep Processing -global SUMTIME hhh TTT P_ggg Theta_LLL DSTOR Thmrlefc CHK Theta_LL Theta_L -global NBCh AVAIL Evap DSTOR0 EXCESS QMT RS BCh hN hSAVE NBChh DSTMAX Soilairefc Trap sumTRAP_dir sumEVAP_dir -global TSAVE IRPT1 IRPT2 AVAIL0 TIMEOLD TIMELAST SRT ALPHA BX alpha_h bx Srt L -global QL QL_h QL_T QV Qa KL_h Chh ChT Khh KhT -global D_Vg Theta_g Sa V_A k_g MU_a DeltZ Alpha_Lg -global J Beta_g KaT_Switch Theta_s -global D_V D_A fc Eta nD POR Se -global ThmrlCondCap ZETA XK DVT_Switch -global m g MU_W Ks RHOL -global Lambda1 Lambda2 Lambda3 c_unsat Lambda_eff RHO_bulk -global RHODA RHOV c_a c_V c_L -global ETCON EHCAP -global Xaa XaT Xah RDA Rv KL_T -global DRHOVT DRHOVh DRHODAt DRHODAz -global hThmrl Tr COR IS Hystrs XWRE -global Theta_V DTheta_LLh IH -global W WW D_Ta SSUR -global W_Chg -global KLT_Switch Theta_r Alpha n CKTN trap Evapo SMC lEstot lEctot Ztot Rl -%%%%%%%%%%%%%%%%%%%%%%% Main Processing part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +[Output_dir, f, fnames] = io.create_output_files_binary(parameter_file, sitename, path_of_code, path_input, spectral, options); run StartInit; % Initialize Temperature, Matric potential and soil air pressure. %% 14. Run the model fprintf('\n The calculations start now \r') calculate = 1; - -for k = 1:telmax - %SMC=Theta_LL(:,1); - TIMEOLD=0; - TIMELAST=0; - KT=KT+1 % Counting Number of timesteps +TIMEOLD=0;SAVEhh_frez=zeros(NN+1,1);FCHK=zeros(1,NN);KCHK=zeros(1,NN);hCHK=zeros(1,NN); +TIMELAST=0; +SAVEtS=tS; kk=0; %DELT=Delt_t; +for i = 1:1:Dur_tot-1 + KT=KT+1 % Counting Number of timesteps if KT>1 && Delt_t>(TEND-TIME) Delt_t=TEND-TIME; % If Delt_t is changed due to excessive change of state variables, the judgement of the last time step is excuted. end TIME=TIME+Delt_t; % The time elapsed since start of simulation TimeStep(KT,1)=Delt_t; SUMTIME(KT,1)=TIME; - Processing=TIME/TEND - %%i%%%% Updating the state variables. %%%%%%%%%%%%%%%%%%%%%%%%%%%% - if Precip(KT)>0.0005 - NBChh=1; + Processing=TIME/TEND; + NoTime(KT)=fix(SUMTIME(KT)/DELT); + if NoTime(KT)==0 + k=1; else - NBChh=2; + k=NoTime(KT); end - if IRPT1==0 && IRPT2==0 - for MN=1:NN + %%%%% Updating the state variables. %%%%%%%%%%%%%%%%%%%%%%%%%%%% + + L_f=0; %latent heat of freezing fusion J Kg-1 + T0=273.15; TT_CRIT(MN)=T0;% unit K + if IRPT1==0 && IRPT2==0 && ISFT==0 + for MN=1:NN + hOLD_frez(MN)=h_frez(MN); + h_frez(MN)=hh_frez(MN); + hhh_frez(MN,KT)=hh_frez(MN); + TOLD_CRIT(MN)=T_CRIT(MN); + T_CRIT(MN)=TT_CRIT(MN); + TTT_CRIT(MN,KT)=TT_CRIT(MN); + hOLD(MN)=h(MN); h(MN)=hh(MN); hhh(MN,KT)=hh(MN); - + KfL_hh(MN,KT)=KfL_h(MN,2); + KL_hh(MN,KT)=KL_h(MN,2); + Chhh(MN,KT)=Chh(MN,2); + ChTT(MN,KT)=ChT(MN,2); + Khhh(MN,KT)=Khh(MN,2); + KhTT(MN,KT)=KhT(MN,2); + CTTT(MN,KT)=CTT(MN,2); + EPCTT(MN,KT)=EPCT(MN); + C_unsat(MN,KT)=c_unsat(MN,2); + CCTT_PH(MN,KT)=CTT_PH(MN,2); + CCTT_Lg(MN,KT)=CTT_Lg(MN,2); + CCTT_g(MN,KT)=CTT_g(MN,2); + CCTT_LT(MN,KT)=CTT_LT(MN,2); + Lambda_Eff(MN,KT)=Lambda_eff(MN,2); + EfTCON(MN,KT)=EfTCON(MN,2); + TTETCON(MN,KT)=TETCON(MN,2); + DDhDZ(MN,KT)=DhDZ(MN); + DDTDZ(MN,KT)=DTDZ(MN); + DDTDZ(MN,KT)=DTDZ(MN); + DDRHOVZ(MN,KT)=DRHOVZ(MN); + TKCHK(MN,KT)=KCHK(MN); if Thmrlefc==1 TOLD(MN)=T(MN); T(MN)=TT(MN); @@ -363,10 +431,10 @@ end end DSTOR0=DSTOR; + if KT>1 run SOIL1 end - end if options.simulation == 1, vi(vmax>1) = k; end if options.simulation == 0, vi(vmax==telmax) = k; end [soil,leafbio,canopy,meteo,angles,xyt] = io.select_input(V,vi,canopy,options,xyt,soil); @@ -374,14 +442,7 @@ fprintf('simulation %i ', k ); fprintf('of %i \n', telmax); else - calculate = 0; - if k>=I_tmin && k<=I_tmax - quality_is_ok = ~isnan(meteo.p*meteo.Ta*meteo.ea*meteo.u.*meteo.Rin.*meteo.Rli); - fprintf('time = %4.2f \n', xyt.t(k)); - if quality_is_ok - calculate = 1; - end - end + calculate = 1; end if calculate @@ -458,8 +519,7 @@ case 1 [iter,fluxes,rad,thermal,profiles,soil,RWU,frac] ... = ebal(iter,options,spectral,rad,gap, ... - leafopt,angles,meteo,soil,canopy,leafbio,xyt,k,profiles,LR); - + leafopt,angles,meteo,soil,canopy,leafbio,xyt,k,profiles,Delt_t); if options.calc_fluor if options.calc_vert_profiles [rad,profiles] = RTMf(spectral,rad,soil,leafopt,canopy,gap,angles,profiles); @@ -500,21 +560,81 @@ else rad.Femtot = 1E3*leafbio.fqe* optipar.phi(spectral.IwlF) * fluxes.aPAR_Cab_eta; end - end - io.output_data(Output_dir, options, k, iter, xyt, fluxes, rad, thermal, gap, meteo, spectral, V, vi, vmax, profiles, directional, angles) + end end if options.simulation==2 && telmax>1, vi = helpers.count(nvars,vi,vmax,1); end - Ac=fluxes.Actot; - lEstot =fluxes.lEstot; - lEctot =fluxes.lEctot; - - Tss=thermal.Tsave; - Tcc=thermal.Ts(1); - Taa=thermal.Ta; - - [Rl]=Root_properties(Rl,Ac,rroot,frac,bbx,KT); - - Ts(KT)=Ta1(KT); + if KT==1 + if isreal(fluxes.Actot)&&isreal(thermal.Tsave)&&isreal(fluxes.lEstot)&&isreal(fluxes.lEctot) + Acc=fluxes.Actot; + lEstot =fluxes.lEstot; + lEctot =fluxes.lEctot; + Tsss=Tss; + Tss=thermal.Tsave; + else + Acc=0; + lEstot =0; + lEctot =0; + Tsss=Tss; + Tss=Ta_msr(KT); + end + elseif NoTime(KT)>NoTime(KT-1) + if isreal(fluxes.Actot)&&isreal(thermal.Tsave)&&isreal(fluxes.lEstot)&&isreal(fluxes.lEctot) + Acc=fluxes.Actot; + lEstot =fluxes.lEstot; + lEctot =fluxes.lEctot; + Tsss=Tss; + Tss=thermal.Tsave; + else + Acc=0; + lEstot =0; + lEctot =0; + Tsss=Tss; + Tss=Ta_msr(KT); + end + end + + sfactortot(KT)=sfactor; + + for ML=1:NL + QVV(ML,KT)=QV(ML); + QLL(ML,KT)=QL(ML,1); + DDEhBAR(ML,KT)=DEhBAR(ML); + DDRHOVhDz(ML,KT)=DRHOVhDz(ML); + DDhDZ(ML,KT)=DhDZ(ML); + EEtaBAR(ML,KT)=EtaBAR(ML); + DD_Vg(ML,KT)=D_Vg(ML); + DDRHOVTDz(ML,KT)=DRHOVTDz(ML); + DDTDZ(ML,KT)=DTDZ(ML); + DDPgDZ(ML,KT)=DPgDZ(ML); + KKLhBAR(ML,KT)=KLhBAR(ML); + KKLTBAR(ML,KT)=KLTBAR(ML); + DDTDBAR(ML,KT)=DTDBAR(ML); + QVAA(ML,KT)=QVa(ML); + QAA(ML,KT)=Qa(ML); + if ~Soilairefc + QLHH(ML,KT)=QLH(ML); + QLTT(ML,KT)=QLT(ML); + else + QLHH(ML,KT)=QL_h(ML); + QLTT(ML,KT)=QL_T(ML); + QLAA(ML,KT)=QL_a(ML); + end + DVHH(ML,KT)=DVH(ML); + DVTT(ML,KT)=DVT(ML); + SSe(ML,KT)=Se(ML,1); + SSa(ML,KT)=Sa(ML,1); + DSAVEDTheta_LLh(ML,KT)=SAVEDTheta_LLh(ML,1); + DSAVEDTheta_LLT(ML,KT)=SAVEDTheta_LLT(ML,1); + DSAVEDTheta_UUh(ML,KT)=SAVEDTheta_UUh(ML,1); + + QVHH(ML,KT)=QVH(ML); + QVTT(ML,KT)=QVT(ML); + DDTheta_LLh(ML,KT)=DTheta_LLh(ML,1); + CChh(ML,KT)=Chh(ML,1); + kk_g(ML,KT)=k_g(ML,1); + VV_A(ML,KT)=V_A(ML); + end + end if Delt_t~=Delt_t0 for MN=1:NN hh(MN)=h(MN)+(h(MN)-hOLD(MN))*Delt_t/Delt_t0; @@ -546,21 +666,22 @@ hSAVE=hN; end end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + run Forcing_PARM + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for KIT=1:NIT % Start the iteration procedure in a time step. - [hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J); + [TT_CRIT,hh_frez]=HT_frez(hh,T0,g,L_f,TT,NN,hd,Tmin); + [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); [KL_T]=CondL_T(NL); [RHOV,DRHOVh,DRHOVT]=Density_V(TT,hh,g,Rv,NN); - [W,WW,MU_W,D_Ta]=CondL_Tdisp(POR,Theta_LL,Theta_L,SSUR,RHO_bulk,RHOL,TT,Theta_s,h,hh,W_Chg,NL,nD,J,Delt_t,Theta_g,KLT_Switch); - [L]=Latent(TT,NN); + [W,WW,MU_W,D_Ta]=CondL_Tdisp(POR,Theta_LL,Theta_L,SSUR,RHO_bulk,RHOL,TT,Theta_s,h,hh,W_Chg,NL,nD,Delt_t,Theta_g,KLT_Switch); + [L]= Latent(TT,NN); [Xaa,XaT,Xah,DRHODAt,DRHODAz,RHODA]=Density_DA(T,RDA,P_g,Rv,DeltZ,h,hh,TT,P_gg,Delt_t,NL,NN,DRHOVT,DRHOVh,RHOV); - [c_unsat,Lambda_eff]=CondT_coeff(Theta_LL,Lambda1,Lambda2,Lambda3,RHO_bulk,Theta_g,RHODA,RHOV,c_a,c_V,c_L,NL,nD,ThmrlCondCap,ETCON,EHCAP); - [k_g]=Condg_k_g(POR,NL,J,m,Theta_g,g,MU_W,Ks,RHOL); - [D_V,Eta,D_A]=CondV_DE(Theta_LL,TT,fc,Theta_s,NL,nD,J,Theta_g,POR,ThmrlCondCap,ZETA,XK,DVT_Switch); - [D_Vg,V_A,Beta_g]=CondV_DVg(P_gg,Theta_g,Sa,V_A,k_g,MU_a,DeltZ,Alpha_Lg,KaT_Switch,Theta_s,Se,NL,J); + [c_unsat,Lambda_eff,ZETA,ETCON,EHCAP,TETCON,EfTCON]=CondT_coeff(Theta_LL,Lambda1,Lambda2,Lambda3,RHO_bulk,Theta_g,RHODA,RHOV,c_a,c_V,c_L,NL,nD,ThmrlCondCap,ThermCond,HCAP,SF,TCA,GA1,GA2,GB1,GB2,HCD,ZETA0,CON0,PS1,PS2,XWILT,XK,TT,POR,DRHOVT,L,D_A,Theta_V,Theta_II,TCON_dry,Theta_s,XSOC,TPS1,TPS2,TCON0,TCON_s,FEHCAP,RHOI,RHOL,c_unsat,Lambda_eff,ETCON,EHCAP,TETCON,EfTCON,ZETA); + [k_g]=Condg_k_g(POR,NL,m,Theta_g,g,MU_W,Ks,RHOL,SWCC,Imped,Ratio_ice,Soilairefc,MN); + [D_V,Eta,D_A]=CondV_DE(Theta_LL,TT,fc,Theta_s,NL,nD,Theta_g,POR,ThmrlCondCap,ZETA,XK,DVT_Switch,Theta_UU); + [D_Vg,V_A,Beta_g,DPgDZ,Beta_gBAR,Alpha_LgBAR]=CondV_DVg(P_gg,Theta_g,Sa,V_A,k_g,MU_a,DeltZ,Alpha_Lg,KaT_Switch,Theta_s,Se,NL,DPgDZ,Beta_gBAR,Alpha_LgBAR,Beta_g); run h_sub; - if NBCh==1 DSTOR=0; RS=0; @@ -574,8 +695,8 @@ AVAIL=AVAIL0-Evap(KT); EXCESS=(AVAIL+QMT(KT))*Delt_t; if abs(EXCESS/Delt_t)<=1e-10,EXCESS=0;end - DSTOR=0; - RS=0; + DSTOR=min(EXCESS,DSTMAX); + RS(KT)=(EXCESS-DSTOR)/Delt_t; end if Soilairefc==1 @@ -586,33 +707,36 @@ run Enrgy_sub; end - if max(CHK)<0.001 + if max(CHK)<0.001 %&& max(FCHK)<0.001 %&& max(hCHK)<0.001 %&& min(KCHK)>0.001 break end hSAVE=hh(NN); TSAVE=TT(NN); - end TIMEOLD=KT; - KIT KIT=0; - [hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J); + [TT_CRIT,hh_frez]=HT_frez(hh,T0,g,L_f,TT,NN,hd,Tmin); + [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); + SAVEtS=tS; if IRPT1==0 && IRPT2==0 if KT % In case last time step is not convergent and needs to be repeated. MN=0; - for ML=1:NL for ND=1:2 MN=ML+ND-1; Theta_LLL(ML,ND,KT)=Theta_LL(ML,ND); Theta_L(ML,ND)=Theta_LL(ML,ND); - + Theta_UUU(ML,ND,KT)=Theta_UU(ML,ND); + Theta_U(ML,ND)=Theta_UU(ML,ND); + Theta_III(ML,ND,KT)=Theta_II(ML,ND); + Theta_I(ML,ND)=Theta_II(ML,ND); + DDTheta_LLh(ML,KT)=DTheta_LLh(ML,2); + DDTheta_LLT(ML,KT)=DTheta_LLT(ML,2); + DDTheta_UUh(ML,KT)=DTheta_UUh(ML,2); end end - - run ObservationPoints end if (TEND-TIME)<1E-3 @@ -620,10 +744,17 @@ hOLD(MN)=h(MN); h(MN)=hh(MN); hhh(MN,KT)=hh(MN); + HRA(MN,KT)=HR(MN); if Thmrlefc==1 TOLD(MN)=T(MN); T(MN)=TT(MN); TTT(MN,KT)=TT(MN); + TOLD_CRIT(MN)=T_CRIT(MN); + T_CRIT(MN)=TT_CRIT(MN); + TTT_CRIT(MN,KT)=TT_CRIT(MN); + hOLD_frez(MN)=h_frez(MN); + h_frez(MN)=hh_frez(MN); + hhh_frez(MN,KT)=hh_frez(MN); end if Soilairefc==1 P_gOLD(MN)=P_g(MN); @@ -634,62 +765,24 @@ break end end - for MN=1:NN - QL(MN,KT)=QL(MN); - QL_h(MN,KT)=QL_h(MN); - QL_T(MN,KT)=QL_T(MN); - Qa(MN,KT)=Qa(MN); - QV(MN,KT)=QV(MN); - end - RWUtot(:,KT)=RWU; - Rls(:,KT)=Rl; - sfactortot(KT)=sfactor; - -end - -%%%%%%%%%%%%%%%%%%%% postprocessing part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% plot the figures of simulation output soil moisture/temperature, -%%%% soil evaporation, plant transpiration simulated with two different -%%%% ET method (indirect ET method & direct ET method) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if Evaptranp_Cal==1 % save the variables for ETind scenario - Sim_Theta_ind=Sim_Theta; - Sim_Temp_ind=Sim_Temp; - TRAP=36000.*trap; - TRAP_ind=TRAP'; - EVAP=36000.*Evapo; - EVAP_ind=EVAP'; - disp ('Convergence Achieved for ETind scenario. Please switch to ETdir scenario and run again.') -else - TRAP=18000.*trap; - TRAP_dir=TRAP'; - EVAP=18000.*Evapo; - EVAP_dir=EVAP'; - for i=1:KT/48 - sumTRAP_ind(i)=0; %#ok<*SAGROW> - sumEVAP_ind(i)=0; - sumTRAP_dir(i)=0; - sumEVAP_dir(i)=0; - for j=(i-1)*48+1:i*48 - sumTRAP_ind(i)=TRAP_ind(j)+sumTRAP_ind(i); - sumEVAP_ind(i)=EVAP_ind(j)+sumEVAP_ind(i); - sumTRAP_dir(i)=TRAP(j)+sumTRAP_dir(i); - sumEVAP_dir(i)=EVAP(j)+sumEVAP_dir(i); + if KT>0 + for MN=1:NN + QL(MN,KT)=QL(MN); + QL_HH(MN,KT)=QL_h(MN); + QL_TT(MN,KT)=QL_T(MN); + QV(MN,KT)=QV(MN); + SAVEhhh(MN,KT)=SAVEhh(MN); end + SAVEDSTOR(KT)=DSTOR; end + kk=k; + n_col = io.output_data_binary(f, k, xyt, rad, canopy, V, vi, vmax, options, fluxes, meteo, iter, thermal, spectral, gap, profiles, Sim_Theta_U, Sim_Temp, Trap, Evap); end if options.verify io.output_verification(Output_dir) end - +io.bin_to_csv(fnames, V, vmax, n_col, k, options,Ztot) if options.makeplots plot.plots(Output_dir) end -%% for Compiler -% catch ME -% disp(['ERROR: ' ME.message]) -% end -% fprintf('\nThe run is finished. Press any key to close the window') -% fprintf('\nIf no error message was produced navigate to ./SCOPE_v1.70/output to see the results') -% pause diff --git a/src/StartInit.m b/src/StartInit.m index 7482381c..760ec343 100644 --- a/src/StartInit.m +++ b/src/StartInit.m @@ -1,10 +1,10 @@ function StartInit -global InitND1 InitND2 InitND3 InitND4 InitND5 BtmT BtmX Btmh% Preset the measured depth to get the initial T, h by interpolation method. -global InitT0 InitT1 InitT2 InitT3 InitT4 InitT5 Dmark +global InitND1 InitND2 InitND3 InitND4 InitND5 BtmT BtmX Btmh InitND6% Preset the measured depth to get the initial T, h by interpolation method. +global InitT0 InitT1 InitT2 InitT3 InitT4 InitT5 InitT6 Dmark global T MN ML NL NN DeltZ Elmn_Lnth Tot_Depth InitLnth -global InitX0 InitX1 InitX2 InitX3 InitX4 InitX5 Inith0 Inith1 Inith2 Inith3 Inith4 Inith5 -global h Theta_s Theta_r m n Alpha Theta_L Theta_LL hh TT P_g P_gg Ks +global InitX0 InitX1 InitX2 InitX3 InitX4 InitX5 InitX6 Inith0 Inith1 Inith2 Inith3 Inith4 Inith5 Inith6 +global h Theta_s Theta_r m n Alpha Theta_L Theta_LL hh TT P_g P_gg Ks h_frez hh_frez global XOLD XWRE NS J POR Thmrlefc IH IS Eqlspace FACc global porosity SaturatedMC ResidualMC SaturatedK Coefficient_n Coefficient_Alpha global NBCh NBCT NBCP NBChB NBCTB NBCPB BChB BCTB BCPB BCh BCT BCP BtmPg @@ -12,23 +12,48 @@ global HCAP TCON SF TCA GA1 GA2 GB1 GB2 S1 S2 HCD TARG1 TARG2 GRAT VPER global TERM ZETA0 CON0 PS1 PS2 i KLT_Switch DVT_Switch KaT_Switch global Kaa_Switch DVa_Switch KLa_Switch -global hThmrl Tr COR Hystrs -global Theta_V DTheta_LLh Theta_g KIT Se KL_h CKTN +global KfL_T Theta_II Theta_I Theta_UU Theta_U T_CRIT L_f g T0 TT_CRIT XUOLD XIOLD ISFT TCON_s TCON_dry TCON_L RHo_bulk Imped TPS1 TPS2 FEHCAP TS1 TS2 TCON0 TCON_min Theta_qtz XSOC +global Lamda Phi_s SWCC XCAP ThermCond Gama_hh Theta_a Gama_h hm hd SAVEhh SAVEh +global COR CORh Theta_V Theta_g Se KL_h DTheta_LLh KfL_h DTheta_UUh hThmrl Tr Hystrs KIT RHOI RHOL FOC FOS FOSL MSOC Coef_Lamda fieldMC Theta_f Ta_msr +hd=-1e7;hm=-9899; +% SWCC=0; % indicator for choose the soil water characteristic curve, =0, Clapp and Hornberger; =1, Van Gen; +CHST=0; Elmn_Lnth=0; Dmark=0; - -for J=1:NS - POR(J)=porosity(J); - Theta_s(J)=SaturatedMC(J); - Theta_r(J)=ResidualMC(J); - n(J)=Coefficient_n(J); - Ks(J)=SaturatedK(J); - Alpha(J)=Coefficient_Alpha(J); - m(J)=1-1/n(J); - XK(J)=0.075; %0.11 This is for silt loam; For sand XK=0.025 - XWILT(J)=Theta_r(J)+(Theta_s(J)-Theta_r(J))/(1+abs(Alpha(J)*(-1.5e4))^n(J))^m(J); +Vol_qtz=FOS; +VPERSOC=MSOC.*2700./((MSOC.*2700)+(1-MSOC).*1300); % fraction of soil organic matter +FOSL=1-FOC-FOS-VPERSOC; +Phi_S=[-17 -17 -17 -17 -17 -17]; +Phi_soc=-0.0103;Lamda_soc=2.7;Theta_soc=0.6; +ImpedF=[3 3 3 3 3 3 3]; +for JJ=1:6 + POR(JJ)=porosity(JJ); + Theta_s(JJ)=SaturatedMC(JJ); + Theta_r(JJ)=ResidualMC(JJ); + Theta_f(JJ)=fieldMC(JJ); + n(JJ)=Coefficient_n(JJ); + Ks(JJ)=SaturatedK(JJ); + Alpha(JJ)=Coefficient_Alpha(JJ); + m(JJ)=1-1/n(JJ); +% XK(JJ)=0.09; %0.11 This is for silt loam; For sand XK=0.025 + XK(JJ)=Theta_r(JJ)-0.01; %0.11 This is for silt loam; For sand XK=0.025 + XWILT(JJ)=Theta_r(JJ)+(Theta_s(JJ)-Theta_r(JJ))/(1+abs(Alpha(JJ)*(-1.5e4))^n(JJ))^m(JJ); + XCAP(JJ)=Theta_r(JJ)+(Theta_s(JJ)-Theta_r(JJ))/(1+abs(Alpha(JJ)*(-336))^n(JJ))^m(JJ); + VPERS(JJ)=FOS(JJ)*(1-POR(JJ)); + VPERSL(JJ)=FOSL(JJ)*(1-POR(JJ)); + VPERC(JJ)=FOC(JJ)*(1-POR(JJ)); + if SWCC==0 + if CHST==0 + Phi_s(JJ)=Phi_S(JJ); + Lamda(JJ)=Coef_Lamda(JJ); + end + Theta_s(JJ)=Theta_s_ch(JJ); + end end +Ksh(1:6)=[18/(3600*24) 18/(3600*24) 18/(3600*24) 18/(3600*24) 18/(3600*24) 18/(3600*24)];%[1.45*1e-4 1.45*1e-4 0.94*1e-4 0.94*1e-4 0.68*1e-4 0.68*1e-4]; +BtmKsh=Ksh(6); +Ksh0=Ksh(1); if ~Eqlspace Inith0=-(((Theta_s(J)-Theta_r(J))/(InitX0-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); Inith1=-(((Theta_s(J)-Theta_r(J))/(InitX1-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); @@ -36,66 +61,305 @@ Inith3=-(((Theta_s(J)-Theta_r(J))/(InitX3-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); Inith4=-(((Theta_s(J)-Theta_r(J))/(InitX4-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); Inith5=-(((Theta_s(J)-Theta_r(J))/(InitX5-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); + Inith6=-(((Theta_s(J)-Theta_r(J))/(InitX6-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); Btmh=-(((Theta_s(J)-Theta_r(J))/(BtmX-Theta_r(J)))^(1/m(J))-1)^(1/n(J))/Alpha(J); if Btmh==-inf - Btmh=-1e6; + Btmh=-1e7; end - +%%%%%%%%%%%%%%%%%% considering soil hetero effect modify date: 20170103 %%%% for ML=1:NL Elmn_Lnth=Elmn_Lnth+DeltZ(ML); InitLnth(ML)=Tot_Depth-Elmn_Lnth; if abs(InitLnth(ML)-InitND5)<1e-10 for MN=1:(ML+1) + IS(MN)=6; %%%%%% Index of soil type %%%%%%% + J=IS(MN); + POR(MN)=porosity(J); + Ks(MN)=SaturatedK(J); + Theta_qtz(MN)=Vol_qtz(J); + VPER(MN,1)=VPERS(J); + VPER(MN,2)=VPERSL(J); + VPER(MN,3)=VPERC(J); + XSOC(MN)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN)=0.11; %0.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 % VG soil water retention model + Theta_s(MN)=SaturatedMC(J); + Theta_r(MN)=ResidualMC(J); + Theta_f(MN)=fieldMC(J); + XK(MN)=ResidualMC(J)-0.01; + n(MN)=Coefficient_n(J); + m(MN)=1-1/n(MN); + Alpha(MN)=Coefficient_Alpha(J); + XWILT(MN)=Theta_r(MN)+(Theta_s(MN)-Theta_r(MN))/(1+abs(Alpha(MN)*(-1.5e4))^n(MN))^m(MN); + XCAP(MN)=Theta_r(MN)+(Theta_s(MN)-Theta_r(MN))/(1+abs(Alpha(MN)*(-336))^n(MN))^m(MN); + Inith5=-(((Theta_s(MN)-Theta_r(MN))/(InitX5-Theta_r(MN)))^(1/m(MN))-1)^(1/n(MN))/Alpha(MN); + Btmh=-(((Theta_s(MN)-Theta_r(MN))/(BtmX-Theta_r(MN)))^(1/m(MN))-1)^(1/n(MN))/Alpha(MN); + else + Theta_s(MN)=Theta_s_ch(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN)=Phi_S(J); + Lamda(MN)=Coef_Lamda(J); + Theta_s(MN)=Theta_s_ch(J); + else + Phi_s(MN)=-0.01*10^(1.88-0.0131*VPER(MN,1)/(1-POR(MN))*100); + Lamda(MN)=(2.91+0.159*VPER(MN,3)/(1-POR(MN))*100); + Phi_s(MN)=(Phi_s(MN)*(1-XSOC(MN))+XSOC(MN)*Phi_soc)*100; + Lamda(MN)=1/(Lamda(MN)*(1-XSOC(MN))+XSOC(MN)*Lamda_soc); + Theta_s_min(MN)=0.489-0.00126*VPER(MN,1)/(1-POR(MN))*100; + Theta_s(MN)=Theta_s_min(MN)*(1-XSOC(MN))+XSOC(MN)*Theta_soc; + Theta_s(MN)=Theta_s_min(MN); + + end + Theta_r(MN)=ResidualMC(J); + XWILT(MN)=Theta_s(MN)*((-1.5e4)/Phi_s(MN))^(-1*Lamda(MN)); + Inith5=Phi_s(MN)*(InitX5/Theta_s(MN))^(-1/Lamda(MN)); + Btmh=Phi_s(MN)*(BtmX/Theta_s(MN))^(-1/Lamda(MN)); + end T(MN)=BtmT+(MN-1)*(InitT5-BtmT)/ML; h(MN)=(Btmh+(MN-1)*(Inith5-Btmh)/ML); - IS(MN)=1; %%%%%% Index of soil type %%%%%%% - IH(MN)=2; %%%%%% Index of wetting history of soil which would be assumed as dry at the first with the value of 1 %%%%%%% + IH(MN)=1; %%%%%% Index of wetting history of soil which would be assumed as dry at the first with the value of 1 %%%%%%% end Dmark=ML+2; - end + end if abs(InitLnth(ML)-InitND4)<1e-10 for MN=Dmark:(ML+1) + IS(MN-1)=4;IS(5:8)=5; + J=IS(MN-1); + POR(MN-1)=porosity(J); + Ks(MN-1)=SaturatedK(J); + Theta_qtz(MN-1)=Vol_qtz(J); + VPER(MN-1,1)=VPERS(J); + VPER(MN-1,2)=VPERSL(J); + VPER(MN-1,3)=VPERC(J); + XSOC(MN-1)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN-1)=0.11; %0.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 + Theta_s(MN-1)=SaturatedMC(J); + Theta_r(MN-1)=ResidualMC(J); + Theta_f(MN-1)=fieldMC(J); + XK(MN-1)=ResidualMC(J)-0.01; + n(MN-1)=Coefficient_n(J); + m(MN-1)=1-1/n(MN-1); + Alpha(MN-1)=Coefficient_Alpha(J); + XWILT(MN-1)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-1.5e4))^n(MN-1))^m(MN-1); + Inith4=-(((Theta_s(MN-1)-Theta_r(MN-1))/(InitX4-Theta_r(MN-1)))^(1/m(MN-1))-1)^(1/n(MN-1))/Alpha(MN-1); + else + Theta_s(MN-1)=Theta_s_ch(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN-1)=Phi_S(J); + Lamda(MN-1)=Coef_Lamda(J); + else + Phi_s(MN-1)=-0.01*10^(1.88-0.0131*VPER(MN-1,1)/(1-POR(MN-1))*100); + Lamda(MN-1)=(2.91+0.159*VPER(MN-1,3)/(1-POR(MN-1))*100); + Phi_s(MN-1)=(Phi_s(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Phi_soc)*100; + Lamda(MN-1)=1/(Lamda(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Lamda_soc); + Theta_s_min(MN-1)=0.489-0.00126*VPER(MN-1,1)/(1-POR(MN-1))*100; + Theta_s(MN-1)=Theta_s_min(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Theta_soc; + Theta_s(MN-1)=Theta_s_min(MN-1); + + end + Theta_r(MN-1)=ResidualMC(J); + XWILT(MN-1)=Theta_s(MN-1)*((-1.5e4)/Phi_s(MN-1))^(-1*Lamda(MN-1)); + Inith4=Phi_s(MN-1)*(InitX4/Theta_s(MN-1))^(-1/Lamda(MN-1)); + end T(MN)=InitT5+(MN-Dmark+1)*(InitT4-InitT5)/(ML+2-Dmark); h(MN)=(Inith5+(MN-Dmark+1)*(Inith4-Inith5)/(ML+2-Dmark)); - IS(MN-1)=1; - IH(MN-1)=2; + IH(MN-1)=1; end Dmark=ML+2; end if abs(InitLnth(ML)-InitND3)<1e-10 for MN=Dmark:(ML+1) + IS(MN-1)=4; + J=IS(MN-1); + POR(MN-1)=porosity(J); + Ks(MN-1)=SaturatedK(J); + Theta_qtz(MN-1)=Vol_qtz(J); + VPER(MN-1,1)=VPERS(J); + VPER(MN-1,2)=VPERSL(J); + VPER(MN-1,3)=VPERC(J); + XSOC(MN-1)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN-1)=0.11; %0.0550.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 + Theta_s(MN-1)=SaturatedMC(J); + Theta_r(MN-1)=ResidualMC(J); + Theta_f(MN-1)=fieldMC(J); + XK(MN-1)=ResidualMC(J)-0.01; + n(MN-1)=Coefficient_n(J); + m(MN-1)=1-1/n(MN-1); + Alpha(MN-1)=Coefficient_Alpha(J); + XWILT(MN-1)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-1.5e4))^n(MN-1))^m(MN-1); + XCAP(MN)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-336))^n(MN-1))^m(MN-1); + Inith3=-(((Theta_s(MN-1)-Theta_r(MN-1))/(InitX3-Theta_r(MN-1)))^(1/m(MN-1))-1)^(1/n(MN-1))/Alpha(MN-1); + else + Theta_s(MN-1)=Theta_s_ch(J); + Theta_r(MN-1)=ResidualMC(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN-1)=Phi_S(J); + Lamda(MN-1)=Coef_Lamda(J); + else + Phi_s(MN-1)=-0.01*10^(1.88-0.0131*VPER(MN-1,1)/(1-POR(MN-1))*100); + Lamda(MN-1)=(2.91+0.159*VPER(MN-1,3)/(1-POR(MN-1))*100); + Phi_s(MN-1)=(Phi_s(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Phi_soc)*100; + Lamda(MN-1)=1/(Lamda(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Lamda_soc); + Theta_s_min(MN-1)=0.489-0.00126*VPER(MN-1,1)/(1-POR(MN-1))*100; + Theta_s(MN-1)=Theta_s_min(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Theta_soc; + Theta_s(MN-1)=0.41; + end + XWILT(MN-1)=Theta_s(MN-1)*((-1.5e4)/Phi_s(MN-1))^(-1*Lamda(MN-1)); + Inith3=Phi_s(MN-1)*(InitX3/Theta_s(MN-1))^(-1/Lamda(MN-1)); + end T(MN)=InitT4+(MN-Dmark+1)*(InitT3-InitT4)/(ML+2-Dmark); h(MN)=(Inith4+(MN-Dmark+1)*(Inith3-Inith4)/(ML+2-Dmark)); - IS(MN-1)=1; - IH(MN-1)=2; + IH(MN-1)=1; end Dmark=ML+2; end if abs(InitLnth(ML)-InitND2)<1e-10 for MN=Dmark:(ML+1) - T(MN)=InitT3+(MN-Dmark+1)*(InitT2-InitT3)/(ML+2-Dmark); + IS(MN-1)=3; + J=IS(MN-1); + POR(MN-1)=porosity(J); + Ks(MN-1)=SaturatedK(J); + Theta_qtz(MN-1)=Vol_qtz(J); + VPER(MN-1,1)=VPERS(J); + VPER(MN-1,2)=VPERSL(J); + VPER(MN-1,3)=VPERC(J); + XSOC(MN-1)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN-1)=0.11; %0.0490.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 + Theta_s(MN-1)=SaturatedMC(J); + Theta_r(MN-1)=ResidualMC(J); + Theta_f(MN-1)=fieldMC(J); + XK(MN-1)=ResidualMC(J)-0.01; + n(MN-1)=Coefficient_n(J); + m(MN-1)=1-1/n(MN-1); + Alpha(MN-1)=Coefficient_Alpha(J); + XWILT(MN-1)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-1.5e4))^n(MN-1))^m(MN-1); + XCAP(MN)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-336))^n(MN-1))^m(MN-1); + Inith2=-(((Theta_s(MN-1)-Theta_r(MN-1))/(InitX2-Theta_r(MN-1)))^(1/m(MN-1))-1)^(1/n(MN-1))/Alpha(MN-1); + else + Theta_s(MN-1)=Theta_s_ch(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN-1)=Phi_S(J); + Lamda(MN-1)=Coef_Lamda(J); + else + Phi_s(MN-1)=-0.01*10^(1.88-0.0131*VPER(MN-1,1)/(1-POR(MN-1))*100); + Lamda(MN-1)=(2.91+0.159*VPER(MN-1,3)/(1-POR(MN-1))*100); + Phi_s(MN-1)=(Phi_s(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Phi_soc)*100; + Lamda(MN-1)=1/(Lamda(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Lamda_soc); + Theta_s_min(MN-1)=0.489-0.00126*VPER(MN-1,1)/(1-POR(MN-1))*100; + Theta_s(MN-1)=Theta_s_min(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*0.45; + Theta_s(MN-1)=0.41; + end + Theta_r(MN-1)=ResidualMC(J); + XWILT(MN-1)=Theta_s(MN-1)*((-1.5e4)/Phi_s(MN-1))^(-1*Lamda(MN-1)); + Inith2=Phi_s(MN-1)*(InitX2/Theta_s(MN-1))^(-1/Lamda(MN-1)); + end + T(MN)=InitT3+(MN-Dmark+1)*(InitT2-InitT3)/(ML+2-Dmark); h(MN)=(Inith3+(MN-Dmark+1)*(Inith2-Inith3)/(ML+2-Dmark)); - IS(MN-1)=1; - IH(MN-1)=2; + IH(MN-1)=1; end Dmark=ML+2; - end + end if abs(InitLnth(ML)-InitND1)<1e-10 for MN=Dmark:(ML+1) + IS(MN-1)=2; + J=IS(MN-1); + POR(MN-1)=porosity(J); + Ks(MN-1)=SaturatedK(J); + Theta_qtz(MN-1)=Vol_qtz(J); + VPER(MN-1,1)=VPERS(J); + VPER(MN-1,2)=VPERSL(J); + VPER(MN-1,3)=VPERC(J); + XSOC(MN-1)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN-1)=0.11; %0.0450.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 + Theta_s(MN-1)=SaturatedMC(J); + Theta_r(MN-1)=ResidualMC(J); + Theta_f(MN-1)=fieldMC(J); + XK(MN-1)=ResidualMC(J)-0.01; + n(MN-1)=Coefficient_n(J); + m(MN-1)=1-1/n(MN-1); + Alpha(MN-1)=Coefficient_Alpha(J); + XWILT(MN-1)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-1.5e4))^n(MN-1))^m(MN-1); + XCAP(MN)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-336))^n(MN-1))^m(MN-1); + Inith1=-(((Theta_s(MN-1)-Theta_r(MN-1))/(InitX1-Theta_r(MN-1)))^(1/m(MN-1))-1)^(1/n(MN-1))/Alpha(MN-1); + else + Theta_r(MN-1)=ResidualMC(J); + Theta_s(MN-1)=Theta_s_ch(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN-1)=Phi_S(J); + Lamda(MN-1)=Coef_Lamda(J); + else + Phi_s(MN-1)=-0.01*10^(1.88-0.0131*VPER(MN-1,1)/(1-POR(MN-1))*100); + Lamda(MN-1)=(2.91+0.159*VPER(MN-1,3)/(1-POR(MN-1))*100); + Phi_s(MN-1)=(Phi_s(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Phi_soc)*100; + Lamda(MN-1)=1/(Lamda(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Lamda_soc); + Theta_s_min(MN-1)=0.489-0.00126*VPER(MN-1,1)/(1-POR(MN-1))*100; + Theta_s(MN-1)=Theta_s_min(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*0.6; + + end + XWILT(MN-1)=Theta_s(MN-1)*((-1.5e4)/Phi_s(MN-1))^(-1*Lamda(MN-1)); + Inith1=Phi_s(MN-1)*(InitX1/Theta_s(MN-1))^(-1/Lamda(MN-1)); + end T(MN)=InitT2+(MN-Dmark+1)*(InitT1-InitT2)/(ML+2-Dmark); h(MN)=(Inith2+(MN-Dmark+1)*(Inith1-Inith2)/(ML+2-Dmark)); - IS(MN-1)=1; - IH(MN-1)=2; + IH(MN-1)=1; end Dmark=ML+2; end if abs(InitLnth(ML))<1e-10 for MN=Dmark:(NL+1) + IS(MN-1)=1; + J=IS(MN-1); + POR(MN-1)=porosity(J); + Ks(MN-1)=SaturatedK(J); + Theta_qtz(MN-1)=Vol_qtz(J); + VPER(MN-1,1)=VPERS(J); + VPER(MN-1,2)=VPERSL(J); + VPER(MN-1,3)=VPERC(J); + XSOC(MN-1)=VPERSOC(J); + Imped(MN)=ImpedF(J); + XK(MN-1)=0.11; %0.0450.11 This is for silt loam; For sand XK=0.025 + if SWCC==1 + Theta_s(MN-1)=SaturatedMC(J); + Theta_r(MN-1)=ResidualMC(J); + Theta_f(MN-1)=fieldMC(J); + XK(MN-1)=ResidualMC(J)-0.01; + n(MN-1)=Coefficient_n(J); + m(MN-1)=1-1/n(MN-1); + Alpha(MN-1)=Coefficient_Alpha(J); + XWILT(MN-1)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-1.5e4))^n(MN-1))^m(MN-1); + XCAP(MN)=Theta_r(MN-1)+(Theta_s(MN-1)-Theta_r(MN-1))/(1+abs(Alpha(MN-1)*(-336))^n(MN-1))^m(MN-1); + Inith0=-(((Theta_s(MN-1)-Theta_r(MN-1))/(InitX0-Theta_r(MN-1)))^(1/m(MN-1))-1)^(1/n(MN-1))/Alpha(MN-1); + else + Theta_s(MN-1)=Theta_s_ch(J); + if CHST==0 % Indicator of parameters derivation using soil texture or not. CHST=1, use; CHST=0 not use + Phi_s(MN-1)=Phi_S(J); + Lamda(MN-1)=Coef_Lamda(J); + else + Phi_s(MN-1)=-0.01*10^(1.88-0.0131*VPER(MN-1,1)/(1-POR(MN-1))*100); %unit m + Lamda(MN-1)=(2.91+0.159*VPER(MN-1,3)/(1-POR(MN-1))*100); + Phi_s(MN-1)=(Phi_s(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Phi_soc)*100; + Lamda(MN-1)=1/(Lamda(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*Lamda_soc); + Theta_s_min(MN-1)=0.489-0.00126*VPER(MN-1,1)/(1-POR(MN-1))*100; + Theta_s(MN-1)=Theta_s_min(MN-1)*(1-XSOC(MN-1))+XSOC(MN-1)*0.7; + + end + Theta_r(MN-1)=ResidualMC(J); + XWILT(MN-1)=Theta_s(MN-1)*((-1.5e4)/Phi_s(MN-1))^(-1*Lamda(MN-1)); + Inith0=Phi_s(MN-1)*(InitX0/Theta_s(MN-1))^(-1/Lamda(MN-1)); + end T(MN)=InitT1+(MN-Dmark+1)*(InitT0-InitT1)/(NL+2-Dmark); h(MN)=(Inith1+(MN-Dmark+1)*(Inith0-Inith1)/(ML+2-Dmark)); - IS(MN-1)=1; - IH(MN-1)=2; + IH(MN-1)=1; end end end @@ -105,68 +369,154 @@ T(MN)=22; TT(MN)=T(MN); IS(MN)=1; - IH(MN)=2; + IH(MN)=1; end - end - + end +%%%%%%%%%%%%%%%%%% considering soil hetero effect modify date: 20170103 %%%% +%%%%% Perform initial freezing temperature for each soil type. %%%% +L_f=3.34*1e5; %latent heat of freezing fusion J Kg-1 +T0=273.15; % unit K + ISFT=0; + for MN=1:NN - hh(MN)=h(MN); + if T(MN)<=0 + h_frez(MN)=L_f*1e4*(T(MN))/g/T0; + else + h_frez(MN)=0; + end + if SWCC==1 + if h_frez(MN)<=h(MN)+1e-6 + h_frez(MN)=h(MN)+1e-6; + else + h_frez(MN)=h_frez(MN); + end + else + if h_frez(MN)<=h(MN)-Phi_s(J) + h_frez(MN)=h(MN)-Phi_s(J); + else + h_frez(MN)=h_frez(MN); + end + end + h_frez(MN)=h_frez(MN); + hh_frez(MN)=h_frez(MN); + h(MN)=h(MN)-h_frez(MN); + hh(MN)=h(MN);SAVEh(MN)=h(MN);SAVEhh(MN)=hh(MN); + if abs(hh(MN))>=abs(hd) + Gama_h(MN)=0; + Gama_hh(MN)=Gama_h(MN); + elseif abs(hh(MN))>=abs(hm) + % Gama_h(MN)=1-log(abs(hh(MN)))/log(abs(hm)); + Gama_h(MN)=log(abs(hd)/abs(hh(MN)))/log(abs(hd)/abs(hm)); + Gama_hh(MN)=Gama_h(MN); + else + Gama_h(MN)=1; + Gama_hh(MN)=Gama_h(MN); + end + if Thmrlefc==1 TT(MN)=T(MN); end if Soilairefc==1 - P_g(MN)=94197.850*10; + P_g(MN)=95197.850; P_gg(MN)=P_g(MN); end if MN J g-1 Cels-1; % -TCON(1)=1.37e-3*4.182;TCON(2)=6e-5*4.182;TCON(3)=8.8e-2;TCON(4)=2.9e-2;TCON(5)=2.5e-3;% ZENG origial TCON(3)=2.1e-2*4.182;TCON(4)=7e-3*4.182;TCON(5)=6e-4*4.182; % J cm^-1 s^-1 Cels^-1; % -SF(1)=0;SF(2)=0;SF(3)=0.125;SF(4)=0.125;SF(5)=0.5; % +HCAP(1)=0.998*4.182;HCAP(2)=0.0003*4.182;HCAP(3)=0.46*4.182;HCAP(4)=0.46*4.182;HCAP(5)=0.6*4.182;HCAP(6)=0.45*4.182; %HCAP(3)=2.66;HCAP(4)=2.66;HCAP(5)=1.3;% ZENG origial HCAP(3)=0.46*4.182;HCAP(4)=0.46*4.182;HCAP(5)=0.6*4.182; % J cm^-3 Cels^-1 / g.cm-3---> J g-1 Cels-1; % +TCON(1)=1.37e-3*4.182;TCON(2)=6e-5*4.182;TCON(3)=2.1e-2*4.182;TCON(4)=7e-3*4.182;TCON(5)=6e-4*4.182;TCON(6)=5.2e-3*4.182;%TCON(3)=8.8e-2;TCON(4)=2.9e-2;TCON(5)=2.5e-3;% ZENG origial TCON(3)=2.1e-2*4.182;TCON(4)=7e-3*4.182;TCON(5)=6e-4*4.182; % J cm^-1 s^-1 Cels^-1; % +SF(1)=0;SF(2)=0;SF(3)=0.125;SF(4)=0.125;SF(5)=0.5;SF(6)=0.125; % TCA=6e-5*4.182;GA1=0.035;GA2=0.013; % -VPER(1)=0.41;VPER(2)=0.05;VPER(3)=0.05;% for sand VPER(1)=0.65;VPER(2)=0;VPER(3)=0; % For Silt Loam; % VPER(1)=0.16;VPER(2)=0.33;VPER(3)=0.05; % - % +% VPER(1)=0.25;VPER(2)=0.23;VPER(3)=0.01;% for sand VPER(1)=0.65;VPER(2)=0;VPER(3)=0; % For Silt Loam; % VPER(1)=0.16;VPER(2)=0.33;VPER(3)=0.05; VPER(1)=0.41;VPER(2)=0.06;% + %%%%% Perform initial thermal calculations for each soil type. %%%% % -for J=1:NS %--------------> Sum over all phases of dry porous media to find the dry heat capacity % - S1=POR(J)*TCA; %-------> and the sums in the dry thermal conductivity; % - S2=POR(J); % - HCD(J)=0; % +for J=1:NL %--------------> Sum over all phases of dry porous media to find the dry heat capacity % + S1(J)=POR(J)*TCA; %-------> and the sums in the dry thermal conductivity; % + S2(J)=POR(J); % + HCD(J)=0; + VPERCD(J,1)=VPER(J,1)*(1-XSOC(J)); + VPERCD(J,2)=(VPER(J,2)+VPER(J,3))*(1-XSOC(J)); + VPERCD(J,3)=XSOC(J)*(1-POR(J));% for i=3:5 % TARG1=TCON(i)/TCA-1; % GRAT=0.667/(1+TARG1*SF(i))+0.333/(1+TARG1*(1-2*SF(i))); % - S1=S1+GRAT*TCON(i)*VPER(i-2); % - S2=S2+GRAT*VPER(i-2); % - HCD(J)=HCD(J)+HCAP(i)*VPER(i-2); % + S1(J)=S1(J)+GRAT*TCON(i)*VPERCD(J,i-2); % + S2(J)=S2(J)+GRAT*VPERCD(J,i-2); % + HCD(J)=HCD(J)+HCAP(i)*VPERCD(J,i-2); % end % - ZETA0(J)=1/S2; % - CON0(J)=1.25*S1/S2; % + ZETA0(J)=1/S2(J); % + CON0(J)=1.25*S1(J)/S2(J); % PS1(J)=0; % PS2(J)=0; % for i=3:5 % TARG2=TCON(i)/TCON(1)-1; % GRAT=0.667/(1+TARG2*SF(i))+0.333/(1+TARG2*(1-2*SF(i))); % - TERM=GRAT*VPER(i-2); % + TERM=GRAT*VPERCD(J,i-2); % PS1(J)=PS1(J)+TERM*TCON(i); % PS2(J)=PS2(J)+TERM; % end % GB1(J)=0.298/POR(J); % - GB2(J)=(GA1-GA2)/XWILT(J)+GB1(J); % + GB2(J)=(GA1-GA2)/XWILT(J)+GB1(J); + %%%%%%%% Johansen thermal conductivity method %%%%%%% + RHo_bulk(J)=(1-Theta_s(J))*2.7*1000; % Unit g.cm^-3 + TCON_dry(J)=(0.135*RHo_bulk(J)+64.7)/(2700-0.947*RHo_bulk(J)); % Unit W m-1 K-1 ==> J cm^-1 s^-1 Cels^-1 + %%%%%%%% organic thermal conductivity method %%%%%%% + TCON_Soc=0.05; %RHo_SOC=130; + TCON_dry(J)=TCON_dry(J)*(1-XSOC(J))+XSOC(J)*TCON_Soc; +% %%%%%%%%%%%%%%%% + TCON_qtz=7.7;TCON_o=2.0;TCON_L=0.57;%Theta_qtz(J)=0.47; % thermal conductivities of soil quartz, other soil particles and water; unit W m-1 K-1 + TCON_s(J)=TCON_qtz^(Theta_qtz(J))*TCON_o^(1-Theta_qtz(J)); % Johansen solid soil thermal conductivity Unit W m-1 K-1 + TCON_sa=7.7;Theta_sa(J)=VPER(J,1)/(1-POR(J));TCON_slt=2.74;Theta_slt(J)=VPER(J,2)/(1-POR(J));TCON_cl=1.93;Theta_cl(J)=VPER(J,3)/(1-POR(J)); % thermal conductivities of soil sand, silt and clay, unit W m-1 K-1 + SF_sa=0.182;SF_slt=0.0534;SF_cl=0.00775; + TCON_min(J)=(TCON_sa^(Theta_sa(J))*TCON_slt^(Theta_slt(J))*TCON_cl^(Theta_cl(J)))/100; + SF_min(J)=SF_sa*Theta_sa(J)+SF_slt*Theta_slt(J)+SF_cl*Theta_cl(J); + TS1(J)=POR(J)*TCA; %-------> and the sums in the dry thermal conductivity; % + TS2(J)=POR(J); % % % + TTARG1(J)=TCON_min(J)/TCA-1; % + TGRAT(J)=0.667/(1+TTARG1(J)*SF_min(J))+0.333/(1+TTARG1(J)*(1-2*SF_min(J))); % + TS1(J)=TS1(J)+TGRAT(J)*TCON_min(J)*(1-POR(J)); % + TS2(J)=TS2(J)+TGRAT(J)*(1-POR(J)); % % + TZETA0(J)=1/TS2(J); % + TCON0(J)=1.25*TS1(J)/TS2(J); % dry thermal conductivity % + TPS1(J)=0; % + TPS2(J)=0; % % + TTARG2(J)=TCON_min(J)/TCON(1)-1; % + TGRAT(J)=0.667/(1+TTARG2(J)*SF_min(J))+0.333/(1+TTARG2(J)*(1-2*SF_min(J))); % + TTERM(J)=TGRAT(J)*(1-POR(J)); % + TPS1(J)=TPS1(J)+TTERM(J)*TCON_min(J); % + TPS2(J)=TPS2(J)+TTERM(J); +%%%%%%%%%%%%%%%%%% Farouki thermal parameter method %%%%%%%%%%% + if ThermCond==4 + FEHCAP(J)=(2.128*Theta_sa(J)+2.385*Theta_cl(J))/(Theta_sa(J)+Theta_cl(J))*1e6; %J m-3 K-1 + FEHCAP(J)=FEHCAP(J)*(1-XSOC(J))+XSOC(J)*2.5*1e6; % organic effect J m-3 K-1 + TCON_s(J)=(8.8*Theta_sa(J)+2.92*Theta_cl(J))/(Theta_sa(J)+Theta_cl(J)); % W m-1 K-1 + TCON_s(J)=TCON_s(J)*(1-XSOC(J))+XSOC(J)*0.25; % consider organic effect W m-1 K-1 + end end % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % According to hh value get the Theta_LL % run SOIL2; % For calculating Theta_LL,used in first Balance calculation. -[hh,COR,J,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,IS,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,CKTN,POR,J); - +[hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); +% [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II,Gama_hh]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Gama_hh,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); +% [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h,Theta_UU,Theta_LL,DTheta_LLh,DTheta_UUh,Se); +% [hh,COR,CORh,Theta_V,Theta_g,Se,KL_h,Theta_LL,DTheta_LLh,KfL_h,KfL_T,hh_frez,Theta_UU,DTheta_UUh,Theta_II]=SOIL2(hh,COR,hThmrl,NN,NL,TT,Tr,Hystrs,XWRE,Theta_s,IH,KIT,Theta_r,Alpha,n,m,Ks,Theta_L,h,Thmrlefc,POR,Theta_II,CORh,hh_frez,h_frez,SWCC,Theta_U,XCAP,Phi_s,RHOI,RHOL,Lamda,Imped,L_f,g,T0,TT_CRIT,KfL_h,KfL_T,KL_h); for ML=1:NL Theta_L(ML,1)=Theta_LL(ML,1); Theta_L(ML,2)=Theta_LL(ML,2); XOLD(ML)=(Theta_L(ML,1)+Theta_L(ML,2))/2; + Theta_U(ML,1)=Theta_UU(ML,1); + Theta_U(ML,2)=Theta_UU(ML,2); + XUOLD(ML)=(Theta_U(ML,1)+Theta_U(ML,2))/2; + Theta_I(ML,1)=Theta_II(ML,1); + Theta_I(ML,2)=Theta_II(ML,2); + XIOLD(ML)=(Theta_I(ML,1)+Theta_I(ML,2))/2; end % Using the initial condition to get the initial balance % information---Initial heat storage and initial moisture storage. @@ -184,14 +534,14 @@ IRPT1=0; IRPT2=0; NBCh=3; % Moisture Surface B.C.: 1 --> Specified matric head(BCh); 2 --> Specified flux(BCh); 3 --> Atmospheric forcing; -BCh=-20/1800; -NBChB=2; % Moisture Bottom B.C.: 1 --> Specified matric head (BChB); 2 --> Specified flux(BChB); 3 --> Zero matric head gradient (Gravitiy drainage); -BChB=0; +BCh=-20/3600; +NBChB=3; % Moisture Bottom B.C.: 1 --> Specified matric head (BChB); 2 --> Specified flux(BChB); 3 --> Zero matric head gradient (Gravitiy drainage); +BChB=-9e-10; if Thmrlefc==1 NBCT=1; % Energy Surface B.C.: 1 --> Specified temperature (BCT); 2 --> Specified heat flux (BCT); 3 --> Atmospheric forcing; - BCT=9.89; % surface temperature + BCT=Ta_msr(1); % surface temperature NBCTB=1;% Energy Bottom B.C.: 1 --> Specified temperature (BCTB); 2 --> Specified heat flux (BCTB); 3 --> Zero temperature gradient; - BCTB=16.6; + BCTB=mean(Ta_msr); end if Soilairefc==1 NBCP=2; % Soil air pressure B.C.: 1 --> Ponded infiltration caused a specified pressure value; @@ -207,7 +557,7 @@ end FACc=0; % Used in MeteoDataCHG for check is FAC changed? -BtmPg=94197.850*10; % Atmospheric pressure at the bottom (Pa), set fixed +BtmPg=67197.850; % Atmospheric pressure at the bottom (Pa), set fixed % with the value of mean atmospheric pressure; DSTOR=0; % Depth of depression storage at end of current time step; DSTOR0=DSTOR; % Dept of depression storage at start of current time step; diff --git a/src/TimestepCHK.m b/src/TimestepCHK.m index dad37ec1..6f4d04a6 100644 --- a/src/TimestepCHK.m +++ b/src/TimestepCHK.m @@ -1,23 +1,23 @@ -function [KT,TIME,Delt_t,tS,NBChh,IRPT1,IRPT2]=TimestepCHK(NBCh,BCh,NBChh,DSTOR,DSTOR0,EXCESS,QMT,Precip,Evap,hh,KT,TIME,Delt_t,tS,IRPT1,NN) +function [KT,TIME,Delt_t,tS,NBChh,IRPT1,IRPT2]=TimestepCHK(NBCh,BCh,NBChh,DSTOR,DSTOR0,EXCESS,QMT,Precip,Evap,hh,IRPT1,NN,SAVEhh,TT_CRIT,T0,TT,T,EPCT,h,T_CRIT,xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,KT,TIME,Delt_t,NL,Thmrlefc,NBChB,NBCT,NBCTB,tS,uERR) -global xERR hERR TERR -global Theta_LL Theta_L h TT T -global NL -global Thmrlefc NBChB NBCT NBCTB + if Delt_t<1.0e-10 + keyboard + end if NBCh==1 - [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS); - +% CnvrgnCHK + [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR); elseif NBCh==3 if NBChh==2 %------------------------> NBCh is equal to 3. Which type of BC was used on last time step? - if hh(NN)<= DSTOR %------------------------> NBChh is equal to 2. Check that calculated surface matric head is not unrealistic. - CnvrgnCHK % If it is not, proceed to check the convergence condition.If it is, switch over to NBChh=1. + if SAVEhh(NN)<= DSTOR %hh(NN)------------------------> NBChh is equal to 2. Check that calculated surface matric head is not unrealistic. +% CnvrgnCHK % If it is not, proceed to check the convergence condition.If it is, switch over to NBChh=1. + [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR); else NBChh=1; if IRPT1==1 %------------------------> Since IRPT1=1, we know that simply switching the value of NBChh and re-running the time step IRPT1=0;IRPT2=1; % will not work, since both values of NBChh have been tried. We therefore decrease the length of KT=KT-1;TIME=TIME-Delt_t; % the time step. If the step is sufficiently small, we can always find a value of NBChh that gives - Delt_t=Delt_t*0.25; % consistent results. + Delt_t=Delt_t*0.25; %*0.25 consistent results. tS=tS+1; %-----------------------> tS has passed one, then, whenever it is necessary to repeat a time step, tS should be plused one return % to keep consistant with the number of records of meteorological forcing data. else %-----------------------> Control is transfered here whenever it is found necessary to switch the value of NBChh as a @@ -31,14 +31,14 @@ end % means that Delt_t has not been decreased. elseif EXCESS>=0 %-----------------------> NBChh is equal to 1. As long as a non-negative value for EXCESS was found, the result is OK. % CnvrgnCHK - [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS); + [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR); else if DSTOR0 <= 1e-8 || (-QMT-Precip(KT)+Evap(KT))<=0 NBChh=2; if IRPT1==1 IRPT1=0;IRPT2=1; KT=KT-1;TIME=TIME-Delt_t; - Delt_t=Delt_t*0.25; + Delt_t=Delt_t*0.25;% tS=tS+1; return else @@ -60,13 +60,13 @@ if NBChh==2 %-----------------------> NBChh is equal to 2. This means that the soil was thought to be capable of supporting the sepcified flux, if hh(NN)>=-1e6 && hh(NN)<=DSTOR % BCh. Check to be sure that the resulting matric head does not have a physically unrealistic value. If it % CnvrgnCHK % does not, proceed to find the new Delt_t. If it does, then repeat the time step with NBChh equal to 1. - [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS); + [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR); else NBChh=1; if IRPT1==1 IRPT1=0; IRPT2=1; KT=KT-1; TIME=TIME-Delt_t; - Delt_t=Delt_T*0.25; + Delt_t=Delt_t*0.25;% tS=tS+1; return else @@ -81,13 +81,13 @@ if abs(QMT)<=abs(BCh) %-------------------> NBChh is equal to 1. This means that the potential flux was thought to be excessive, and a specified head % CnvrgnCHK % (saturation or dryness) was applied. Check to be sure that the resulting flux did not exceed the potential value % in magnitude. If it did not, proceed to find new Delt_T. If it did, repeat the step with NBChh equal to 2; - [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS); + [KT,TIME,Delt_t,IRPT1,IRPT2,tS]=CnvrgnCHK(xERR,hERR,TERR,Theta_LL,Theta_L,Theta_UU,Theta_U,hh,h,TT,T,KT,TIME,Delt_t,NL,NN,Thmrlefc,NBCh,NBChB,NBCT,NBCTB,tS,uERR); else NBChh=2; if IRPT1==1 IRPT1=0; IRPT2=1; KT=KT-1; TIME=TIME-Delt_t; - Delt_t=Delt_t*0.25; + Delt_t=Delt_t*0.25;% tS=tS+1; return else @@ -100,6 +100,6 @@ end end end +% end - - +end \ No newline at end of file diff --git a/src/biochemical.m b/src/biochemical.m index 18b3e3cd..953fe411 100644 --- a/src/biochemical.m +++ b/src/biochemical.m @@ -1,9 +1,13 @@ function biochem_out = biochemical(biochem_in,Ci_input) % -global sfactor +global sfactor KT TT if isnan(sfactor) sfactor=1; end +%Tmin=min(min(TT)); +%if Tmin<0 +% sfactor= sfactor*0.3; +%end % Date: 21 Sep 2012 % Update: 20 Feb 2013 % Update: Aug 2013: correction of L171: Ci = Ci*1e6 ./ p .* 1E3; @@ -91,7 +95,12 @@ % qQ % [] photochemical quenching % Vcmax % [umol/m2/s] carboxylation capacity after % ... temperature correction - + A = []; + Ag = []; + Vc = []; + Vs = []; + Ve = []; + CO2_per_electron = []; if nargin < 2 Ci_input = []; end @@ -105,11 +114,24 @@ Cs = NaN; %biochem_in.Ci; end Q = biochem_in.Q; -assert(all(Q(:) >=0), 'Negative light is not allowed!'); +%assert(all(Q(:) >=0), 'Negative light is not allowed!'); +if all(Q(:) >=0) +else + Q= abs(Q); +end + assert(all(isreal(Q(:))), 'Complex-values are not allowed for PAR!'); +%assert(all(Cs(:) >=0), 'Negative CO2 concentration is not allowed!'); +if all(isreal(Cs(:))) +else + Cs=real(Cs); +end -assert(all(Cs(:) >=0), 'Negative CO2 concentration is not allowed!'); -assert(all(isreal(Cs(:))), 'Complex-values are not allowed for CO2 concentration!'); +if all(Cs(:) >=0) +else + Cs=abs(Cs); +end +%assert(all(isreal(Cs(:))), 'Complex-values are not allowed for CO2 concentration!'); T = biochem_in.T + 273.15*(biochem_in.T<200); % convert temperatures to K if not already eb = biochem_in.eb; @@ -320,7 +342,7 @@ % compute Ci using iteration (JAK) % it would be nice to use a built-in root-seeking function but fzero requires scalar inputs and outputs, % Here I use a fully vectorized method based on Brent's method (like fzero) with some optimizations. - tol = 1e-7; % 0.1 ppm more-or-less + tol = 1e-6; % 0.1 ppm more-or-less % Setting the "corner" argument to Gamma may be useful for low Ci cases, but not very useful for atmospheric CO2, so it's ignored. % (fn, x0, corner, tolerance) Ci = equations.fixedp_brent_ari(@(x) Ci_next(x, Cs, RH, minCi), Cs, [], tol); % [] in place of Gamma: it didn't make much difference diff --git a/src/biochemical_MD12.m b/src/biochemical_MD12.m index 5f6c785d..0de1069b 100644 --- a/src/biochemical_MD12.m +++ b/src/biochemical_MD12.m @@ -1,8 +1,4 @@ function biochem_out = biochemical_MD12(biochem_in) -global sfactor -if isnan(sfactor) - sfactor=1; -end %[A,Ci,eta] = biochemical_VCM(Cs,Q,T,eb,O,p,Vcmo,m,Type,Rdparam,stress,Tyear,beta,qLs,NPQs) % Date: 21 Sep 2012 % Update: 28 Jun 2013 Adaptation for use of Farquhar model of C3 photosynthesis (Farquhar et al 1980) @@ -61,7 +57,7 @@ beta=biochem_in.beta; qLs=biochem_in.qLs; NPQs=biochem_in.NPQs; -stress=sfactor; +stress=biochem_in.stressfactor; Cs=biochem_in.Cs; Q=biochem_in.Q; T=biochem_in.T; @@ -301,7 +297,6 @@ %% biochem_out.A = A; -biochem_out.Ag = Ag; biochem_out.Ci = Ci; biochem_out.ps = ps; biochem_out.eta = eta; diff --git a/src/calc_rsoil.m b/src/calc_rsoil.m index 824055c9..b7a9ace1 100644 --- a/src/calc_rsoil.m +++ b/src/calc_rsoil.m @@ -1,36 +1,15 @@ -function [PSIs,rsss,rrr,rxx] = calc_rsoil(Rl,DeltZ,Ztot,Ks,Theta_s,Theta_r,Theta_LL,Theta_o,bbx) -DeltZ=DeltZ'; -n=1.5; -m=1-1/n; +function [PSIs,rsss,rrr,rxx] = calc_rsoil(Rl,DeltZ,Ks,Theta_s,Theta_r,Theta_LL,bbx,m,n,Alpha) +%global SSMM RRll ZZZ KT +DeltZ0=DeltZ'; l=0.5; -a=1.66; -SMC=Theta_LL(:,1); -Se = (SMC-Theta_r*Theta_o)./(Theta_s-Theta_r); -Ksoil=Ks*Se.^l.*(1-(1-Se.^(1./m).^m)).^2; -PSIs=-(Se.^(-1./m)-1).^(1/n)/a.*bbx; -rsss = 1./Ksoil./Rl./DeltZ/2/pi.*log((pi*Rl).^(-0.5)/(0.5*1e-3)).*bbx; % KL_h is the hydraulic conductivity, m s-1;VR is the root length density, m m-3;Ks is saturation conductivty; -rxx = 2*1e12*Ztot/0.5/0.22./Rl/100.*bbx; % Delta_z*j is the depth of the layer -rrr = 1.2*1e11*(Theta_s./SMC)./Rl./(DeltZ/100).*bbx; -%%% RADIAL --> Flow --> Krad*dP*row = [kg/m2 root s] or Krad*dP*row*RAI [kg/m2 ground s] -%Krad = 5*10^-8; %% % [1/s] %% radial conductivity root Amenu and Kumar 2008 -%Krad = 15*1e-8 ;%% [m /Pa s] radial conductivity root -- North, G.B., Peterson, C.A. (2005) in Vascular transport in plants, Water -%%% Krad = 10^-9 - 7*10^-7 ;%% [m /MPa s] radial conductivity root Mendel et a 2002 WRR, Huang and Nobel, 1994 -%Krad = 0.3 - 20 *10^-8 ;%% [m /MPa s] radial conductivity root Steudle and Peterson 1998 -%Krad = 5 - 13 *10^-8 ;%% [m /MPa s] radial conductivity root Bramley et al 2009 -%Krad = 2*10^-11 - 10^-9; %% % [1/s] %% radial conductivity Schneider et al 2010 -%Krad = 2*10^-9; %% % [1/s] %% Javaux et al 2010 -%Krad = 2*10^-7 -- 2*10^-5 [m /Mpa s] %% Draye et al 2010 -%Krad= 0.5--2*10^-7 [m /Mpa s] %% Doussan et al 2006 -%Krad= 10^-9--10^-7 [m /Mpa s] %% Doussan et al 1998 +SMC=Theta_LL(1:54,2); +%SSMM(KT)=sum(SMC.*(DeltZ/100).*bbx)/sum((DeltZ/100).*bbx); +%RRll(KT)=sum(Rl.*bbx.*(DeltZ/100))/sum((DeltZ/100).*bbx); +%ZZZ(KT)=sum((DeltZ/100).*bbx); +Se = (SMC-Theta_r')./(Theta_s'-Theta_r'); +Ksoil=Ks'.*Se.^l.*(1-(1-Se.^(1./m')).^(m')).^2; +PSIs=-((Se.^(-1./m')-1).^(1./n'))./(Alpha*100)'.*bbx; +rsss = 1./Ksoil./Rl./DeltZ0/2/pi.*log((pi*Rl).^(-0.5)/(0.5*1e-3))*100.*bbx; % KL_h is the hydraulic conductivity, m s-1;VR is the root length density, m m-3;Ks is saturation conductivty; +rxx = 1*1e10*DeltZ0/0.5/0.22./Rl/100.*bbx; % Delta_z*j is the depth of the layer +rrr = 4*1e11*(Theta_s'./SMC)./Rl./(DeltZ0/100).*bbx; -%%% AXIAL --> Flow = Kax/dL*dP*row ;; [kg / s] -% Kax/dL*dP*row/(rroot*dL) ;; [kg/m^2 root /s] -% Kax/dL*dP*row/(rroot*dL)*RAI ;; [kg/m^2 ground /s] -%%% Kax = 0.2 ; % mm2/s Root Axial % Amenu and Kumar 2008 -%%% Kax = 5*10^-11 - 4.2*10^-10 ;%% [m4 /MPa s] axial conductivity root Mendel et a 2002 WRR, -%%% Kax = 2-6*10^-9 ;%% [m3 /MPa s] Bramley et al 2009 -%%% Kax = 2*10^-12 - 5*10^-9 ;%% [m4 /MPa s] Pierret et al 2006 -%%% Kax = 1*10^-12 - 1*10^-9 ;%% [m3 / s] Schneider et al 2010 -%%%% Kax =5^10^-13-5*10^-12; %% % [m3 /s] %% Javaux et al 2010 -%Kax= 5*10^-11 -- 5*10^-9 [m4 /Mpa s] %% Draye et al 2010 -%Kax= 5*10^-11 -- 1*10^-8 [m4 /Mpa s] %% Doussan et al 2006 \ No newline at end of file diff --git a/src/calc_sfactor.m b/src/calc_sfactor.m index 1797fd46..e6f4b0d3 100644 --- a/src/calc_sfactor.m +++ b/src/calc_sfactor.m @@ -1,13 +1,7 @@ -function [sfactor] = calc_sfactor(Rl,Theta_s,Theta_r,Theta_LL,bbx,wfrac) -SMC=Theta_LL(:,1); % soil surface moisture -nn=numel(SMC); -for i=1:nn - wfrac(i)=1/(1+exp((-100*Theta_s)*(SMC(i)-(0.24+Theta_r)/2))); - end -wfrac=wfrac.*bbx; - +function [sfactor] = calc_sfactor(Rl,Theta_s,Theta_r,Theta_LL,bbx,Ta,Theta_f) +SMC=Theta_LL(1:54,1); % soil surface moisture ˳ÐòÏà·´ +wfrac=1./(1+exp((-100.*Theta_s').*(SMC-(Theta_f'+Theta_r')/2))).*bbx; %¸÷²ãÍÁÈÀµÄË®·ÖвÆÈϵÊý RL=Rl.*bbx; -RLfrac=RL./(sum(sum(RL))); -sfactor=sum(sum(RLfrac.*wfrac)); +RLfrac=RL./(sum(sum(RL))); %¸÷²ãÍÁÈÀµÄ¸ù³¤ÃܶÈÕ¼±È +sfactor=sum(sum(RLfrac.*wfrac)); %×ÜÌåË®·ÖвÆÈϵÊý end - diff --git a/src/ebal.m b/src/ebal.m index 0cbcdb42..1d680bfa 100644 --- a/src/ebal.m +++ b/src/ebal.m @@ -1,7 +1,8 @@ function [iter,fluxes,rad,thermal,profiles,soil,RWU,frac] ... = ebal(iter,options,spectral,rad,gap,leafopt, ... - angles,meteo,soil,canopy,leafbio,xyt,k,profiles,LR) - global Rl DeltZ Ztot Ks Theta_s Theta_r Theta_LL Theta_o bbx NL KT sfactor wfrac PSItot + angles,meteo,soil,canopy,leafbio,xyt,k,profiles,Delt_t) + global Rl DeltZ Ztot Ks Theta_s Theta_r Theta_LL Theta_o bbx NL KT sfactor wfrac PSItot sfactortot Theta_f + global m n Alpha TT % function ebal.m calculates the energy balance of a vegetated surface % % authors: Christiaan van der Tol (tol@itc.nl) @@ -106,9 +107,9 @@ p = meteo.p; if options.soil_heat_method < 2 && options.simulation ==1 if k>1 - Deltat = (t-xyt.t(k-1))*86400; % Duration of the time interval (s) + Deltat = Delt_t; % Duration of the time interval (s) else - Deltat = 1/48*86400; + Deltat = Delt_t; end x = [1:12;1:12]'*Deltat; Tsold = soil.Tsold; @@ -163,10 +164,10 @@ LAI = canopy.LAI; PSI=0; %[bbx]=Max_Rootdepth(bbx,TIME,NL,KT); -[bbx]=Max_Rootdepth(bbx,NL,KT,Ta); -[PSIs,rsss,rrr,rxx] = calc_rsoil(Rl,DeltZ,Ztot,Ks,Theta_s,Theta_r,Theta_LL,Theta_o,bbx); -[sfactor] = calc_sfactor(Rl,Theta_s,Theta_r,Theta_LL,bbx,wfrac); -PSIss=PSIs(45,1); +[bbx]=Max_Rootdepth(bbx,NL,KT,TT); +[PSIs,rsss,rrr,rxx] = calc_rsoil(Rl,DeltZ,Ks,Theta_s,Theta_r,Theta_LL,bbx,m,n,Alpha); +[sfactor] = calc_sfactor(Rl,Theta_s,Theta_r,Theta_LL,bbx,Ta,Theta_f); +PSIss=PSIs(NL,1); %% 2. Energy balance iteration loop %'Energy balance loop (Energy balance and radiative transfer) @@ -267,8 +268,8 @@ biochem_out = b(biochem_in); - Au = biochem_out.A; - Auu = biochem_out.Ag; + Au = biochem_out.A; % Ag? or A? + Auu = biochem_out.Ag; %GPP calculation. Ciu = biochem_out.Ci; Fu = biochem_out.eta; rcwu = biochem_out.rcw; @@ -292,23 +293,26 @@ [lEcu,Hcu,ecu,Ccu] = heatfluxes((LAI+1)*(raa+rawc),rcwu,Tcu,ea,Ta,e_to_q,PSI,Ca,Ciu); [lEs,Hs] = heatfluxes((LAI+1)*(raa+raws),rss ,Ts ,ea,Ta,e_to_q,PSIss,Ca,Ca); - if any( ~isreal( Cch )) || any( ~isreal( Ccu(:) )) - error('Heatfluxes produced complex values for CO2 concentration!') - end + %if any( ~isreal( Cch )) || any( ~isreal( Ccu(:) )) + % error('Heatfluxes produced complex values for CO2 concentration!') + %end - % if any( Cch < 0 ) || any( Ccu(:) < 0 ) + % if any( Cch < 0 ) || any( Ccu(:) < 0 ) % error('Heatfluxes produced negative values for CO2 concentration!') - % end + % end % integration over the layers and sunlit and shaded fractions Hstot = Fs*Hs; Hctot = LAI*(Fc*Hch + equations.meanleaf(canopy,Hcu,'angles_and_layers',Ps)); Htot = Hstot + Hctot; - %%%%%% Leaf water potential calculate - + %%%%%% Leaf water potential calculate + lambda1 = (2.501-0.002361*Ta)*1E6; lEctot = LAI*(Fc*lEch + equations.meanleaf(canopy,lEcu,'angles_and_layers',Ps)); % latent heat leaves - - Trans = lEctot/2454000/1000; %unit: m s-1 + if (isreal(lEctot) && lEctot<1000 && lEctot>-300) + else + lEctot=0; + end + Trans = lEctot/lambda1/1000; %unit: m s-1 AA1=PSIs./(rsss+rrr+rxx); AA2=1./(rsss+rrr+rxx); BB1=AA1(~isnan(AA1)); @@ -318,7 +322,7 @@ if isnan(PSI1) PSI1 = -1; end - if PSI/PSI1>0.99 + if abs(PSI-PSI1)<0.0001 break end PSI = (PSI + PSI1)/2; @@ -390,7 +394,9 @@ Tsold(2:end,:) = soil.Tsold(1:end-1,:); Tsold(1,:) = Ts(:); if isnan(Ts), Tsold(1,:) = Tsold(2,:); end + if isreal(Ts) soil.Tsold = Tsold; + end end Tbr = (rad.Eoutte/constants.sigmaSB)^0.25; @@ -440,6 +446,7 @@ Rnctot = LAI*(Fc*Rnch + equations.meanleaf(canopy,Rncu,'angles_and_layers',Ps)); % net radiation leaves lEctot = LAI*(Fc*lEch + equations.meanleaf(canopy,lEcu,'angles_and_layers',Ps)); % latent heat leaves Hctot = LAI*(Fc*Hch + equations.meanleaf(canopy,Hcu ,'angles_and_layers',Ps)); % sensible heat leaves +%Actot = LAI*(Fc*Ah + equations.meanleaf(canopy,Au ,'angles_and_layers',Ps)); % photosynthesis leaves Actot = LAI*(Fc*Ahh + equations.meanleaf(canopy,Auu ,'angles_and_layers',Ps)); % photosynthesis leaves Tcave = (Fc*Tch + equations.meanleaf(canopy,Tcu ,'angles_and_layers',Ps)); % mean leaf temperature Pntot = LAI*(Fc*Pinh + equations.meanleaf(canopy,Pinu,'angles_and_layers',Ps)); % net PAR leaves @@ -498,7 +505,7 @@ fluxes.Au = Au; fluxes.Ah = Ah; -RWU =( PSIs - PSI)./(rsss+rrr+rxx).*bbx; +RWU =(PSIs - PSI)./(rsss+rrr+rxx).*bbx; nn=numel(RWU); for i=1:nn if isnan(RWU(i)) @@ -511,13 +518,15 @@ end end frac = RWU./abs(sum(sum(RWU))); -RWU =( PSIs - PSI)./(rsss+rrr+rxx).*bbx; +RWU =(PSIs - PSI)./(rsss+rrr+rxx).*bbx; +RWU =real(RWU); for i=1:nn if isnan(RWU(i)) RWU(i)=0; end end + profiles.Knu = Knu; profiles.Knh = Knh; % function Tnew = update(Told, Wc, innovation) diff --git a/filenames.m b/src/filenames.m similarity index 100% rename from filenames.m rename to src/filenames.m diff --git a/src/filesread.m b/src/filesread.m new file mode 100644 index 00000000..226a034e --- /dev/null +++ b/src/filesread.m @@ -0,0 +1,138 @@ +global DELT IGBP_veg_long latitude longitude reference_height canopy_height sitename +fileFolder=fullfile('../input/'); %read sitename +dirOutput=dir(fullfile(fileFolder,'*.nc')); +%prepare input files +Path ='../input/'; +%File=dir(fullfile(Path,'filename')); +full_path=strcat(Path,dirOutput.name); +sitefullname=dirOutput.name; + sitename=sitefullname(1:6); + startyear=sitefullname(8:11); + endyear=sitefullname(13:16); + startyear=str2double(startyear); + endyear=str2double(endyear); +%ncFilePath='../input/'; +%ncdisp(sitefullname,'/','full'); + +time1=ncread(full_path,'time'); +t1=datenum(startyear,1,1,0,0,0); +DELT=time1(2); +Dur_tot=length(time1); +dt=time1(2)/3600/24; +t2=datenum(endyear,12,31,23,30,0); +T=t1:dt:t2; +TL=length(T); +T=T'; +T=datestr(T,'yyyy-mm-dd HH:MM:SS'); +T0=T(:,1:4); +T01=T0(:,1); +T02=T0(:,2); +T03=T0(:,3); +T04=T0(:,4); +T1=T(:,5:19); +T3=T1(1,:); +T4=T3(ones(TL,1),:); +T5=[T0,T4]; +T6=datenum(T); +T7=datenum(T5); +T8=T6-T7; +time=T8; +T10=year(T); + +RH=ncread(full_path,'RH'); +RHL=length(RH); +RHa=reshape(RH,RHL,1); + +Tair=ncread(full_path,'Tair'); +TairL=length(Tair); +Taira=reshape(Tair,TairL,1)-273.15; + +es= 6.107*10.^(Taira.*7.5./(237.3+Taira)); +ea=es.*RHa./100; + +SWdown=ncread(full_path,'SWdown'); +SWdownL=length(SWdown); +SWdowna=reshape(SWdown,SWdownL,1); + + +LWdown=ncread(full_path,'LWdown'); +LWdownL=length(LWdown); +LWdowna=reshape(LWdown,LWdownL,1); + + +VPD=ncread(full_path,'VPD'); +VPDL=length(VPD); +VPDa=reshape(VPD,VPDL,1); + + +Qair=ncread(full_path,'Qair'); +QairL=length(Qair); +Qaira=reshape(Qair,QairL,1); + + +Psurf=ncread(full_path,'Psurf'); +PsurfL=length(Psurf); +Psurfa=reshape(Psurf,PsurfL,1); +Psurfa=Psurfa./100; + + +Precip=ncread(full_path,'Precip'); +PrecipL=length(Precip); +Precipa=reshape(Precip,PrecipL,1); +Precipa=Precipa./10; + + +Wind=ncread(full_path,'Wind'); +WindL=length(Wind); +Winda=reshape(Wind,WindL,1); + + +CO2air=ncread(full_path,'CO2air'); +CO2airL=length(CO2air); +CO2aira=reshape(CO2air,CO2airL,1); +CO2aira=CO2aira.*44./22.4; + + +latitude=ncread(full_path,'latitude'); +longitude=ncread(full_path,'longitude'); +elevation=ncread(full_path,'elevation'); + +LAI=ncread(full_path,'LAI'); +LAIL=length(LAI); +LAIa=reshape(LAI,LAIL,1); + + +LAI_alternative=ncread(full_path,'LAI_alternative'); +LAI_alternativeL=length(LAI_alternative); +LAI_alternativea=reshape(LAI_alternative,LAI_alternativeL,1); + +IGBP_veg_long=ncread(full_path,'IGBP_veg_long'); +reference_height=ncread(full_path,'reference_height'); +canopy_height=ncread(full_path,'canopy_height'); +% save .dat files for SCOPE +%save ../input/LAI_alternative.dat -ascii LAI_alternative +save ../input/t_.dat -ascii time +save ../input/Ta_.dat -ascii Taira +save ../input/Rin_.dat -ascii SWdowna +save ../input/Rli_.dat -ascii LWdowna +%save ../input/VPDa.dat -ascii VPDa +%save ../input/Qaira.dat -ascii Qaira +save ../input/p_.dat -ascii Psurfa +%save ../input/Precipa.dat -ascii Precipa +save ../input/u_.dat -ascii Winda +%save ../input/RHa.dat -ascii RHa +save ../input/CO2_.dat -ascii CO2aira +%save ../input/latitude.dat -ascii latitude +%save ../input/longitude.dat -ascii longitude +%save ../input/reference_height.dat -ascii reference_height +%save ../input/canopy_height.dat -ascii canopy_height +%save ../input/elevation.dat -ascii elevation +save ../input/ea_.dat -ascii ea +save ../input/year_.dat -ascii T10 +LAI=[time'; LAIa']'; +save ../input/LAI_.dat -ascii LAI %save meteorological data for STEMMUS +Meteodata=[time';Taira';RHa';Winda';Psurfa';Precipa';SWdowna';LWdowna';VPDa';LAIa']'; +save ../input/Mdata.txt -ascii Meteodata %save meteorological data for STEMMUS +%Lacationdata=[latitude;longitude;reference_height;canopy_height;elevation]'; +%save ../input/Lacationdata.txt -ascii Lacationdata +clearvars -except DELT Dur_tot IGBP_veg_long latitude longitude reference_height canopy_height sitename \ No newline at end of file diff --git a/src/hPARM.m b/src/hPARM.m index 1d6aed2a..701f1d08 100644 --- a/src/hPARM.m +++ b/src/hPARM.m @@ -1,6 +1,6 @@ -function [Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DTheta_LLh,DTheta_LLT]=hPARM(NL,hh,... +function [Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DTheta_LLh,DTheta_LLT,DTheta_UUh,SAVEDTheta_UUh,SAVEDTheta_LLh]=hPARM(NL,hh,... h,TT,T,Theta_LL,Theta_L,DTheta_LLh,DTheta_LLT,RHOV,RHOL,Theta_V,V_A,Eta,DRHOVh,... -DRHOVT,KL_h,D_Ta,KL_T,D_V,D_Vg,COR,Beta_g,Gamma0,Gamma_w,KLa_Switch,DVa_Switch,hThmrl,Thmrlefc,nD) +DRHOVT,KfL_h,D_Ta,KL_T,D_V,D_Vg,COR,Beta_g,Gamma0,Gamma_w,KLa_Switch,DVa_Switch,hThmrl,Thmrlefc,nD,TT_CRIT,T0,h_frez,hh_frez,Theta_UU,Theta_U,CORh,DTheta_UUh,Chh,ChT,Khh,KhT) % piecewise linear reduction function parameters of h;(Wesseling % 1991,Veenhof and McBride 1994) @@ -10,14 +10,21 @@ for ND=1:2 MN=ML+ND-1; if hThmrl - DhU=COR(MN)*(hh(MN)-h(MN)+hh(MN)*0.0068*(TT(MN)-T(MN))); - if DhU~=0 && abs(Theta_LL(ML,ND)-Theta_L(ML,ND))>1e-6 - DTheta_LLh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))*COR(MN)/DhU; - end - DTheta_LLT(ML,ND)=DTheta_LLh(ML,ND)*hh(MN)*0.0068; + CORhh=-1*CORh(MN);%-0.0068; + DhUU=COR(MN)*(hh(MN)+hh_frez(MN)-h(MN)-h_frez(MN)+(hh(MN)+hh_frez(MN))*CORhh*(TT(MN)-T(MN))); + DhU=COR(MN)*(hh(MN)-h(MN)+hh(MN)*CORhh*(TT(MN)-T(MN))); + if DhU~=0 && DhUU~=0 && abs(Theta_LL(ML,ND)-Theta_L(ML,ND))>1e-6 && DTheta_UUh(ML,ND)~=0 %&& abs(TT(MN)-T(MN))<1e-4 + DTheta_UUh(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))*COR(MN)/DhUU; + end + if DhU~=0 && DhUU~=0 &&abs(Theta_LL(ML,ND)-Theta_L(ML,ND))>1e-6 && DTheta_LLh(ML,ND)~=0 %&& abs(TT(MN)-T(MN))<1e-4 + DTheta_LLh(ML,ND)=(Theta_UU(ML,ND)-Theta_U(ML,ND))*COR(MN)/DhU; + end +%% + DTheta_LLT(ML,ND)=DTheta_LLh(ML,ND)*(hh(MN)*CORhh); + SAVEDTheta_LLT(ML,ND)=DTheta_LLT(ML,ND);SAVEDTheta_LLh(ML,ND)=DTheta_LLh(ML,ND);SAVEDTheta_UUh(ML,ND)=DTheta_UUh(ML,ND); else - if abs(TT(MN)-T(MN))<1e-6 - DTheta_LLT(ML,ND)=DTheta_LLh(ML,ND)*(hh(MN)/Gamma0)*(-0.1425-4.76*10^(-4)*TT(MN)); + if abs(TT(MN)-T(MN))>1e-6 + DTheta_LLT(ML,ND)=DTheta_LLh(ML,ND)*(hh(MN)/Gamma0)*(0.1425+4.76*10^(-4)*TT(MN)); else DTheta_LLT(ML,ND)=(Theta_LL(ML,ND)-Theta_L(ML,ND))/(TT(MN)-T(MN)); end @@ -29,19 +36,17 @@ for ML=1:NL for ND=1:nD MN=ML+ND-1; - Chh(ML,ND)=(1-RHOV(MN)/RHOL)*DTheta_LLh(ML,ND)+Theta_V(ML,ND)*DRHOVh(MN)/RHOL; - Khh(ML,ND)=(D_V(ML,ND)+D_Vg(ML))*DRHOVh(MN)/RHOL+KL_h(ML,ND); % - Chg(ML,ND)=KL_h(ML,ND); - %root zone water uptake - + Chh(ML,ND)=(1-RHOV(MN)/RHOL)*DTheta_LLh(ML,ND)+Theta_V(ML,ND)*DRHOVh(MN)/RHOL; %DTheta_LLh==>DTheta_UUh + Khh(ML,ND)=(D_V(ML,ND)+D_Vg(ML))*DRHOVh(MN)/RHOL+KfL_h(ML,ND); %KL_h==>KfL_h + Chg(ML,ND)=KfL_h(ML,ND); %KL_h==>KfL_h if Thmrlefc==1 - ChT(ML,ND)=(1-RHOV(MN)/RHOL)*DTheta_LLT(ML,ND)+Theta_V(ML,ND)*DRHOVT(MN)/RHOL; - KhT(ML,ND)=(D_V(ML,ND)*Eta(ML,ND)+D_Vg(ML))*DRHOVT(MN)/RHOL+KL_T(ML,ND)+D_Ta(ML,ND);%();% + ChT(ML,ND)=(1-RHOV(MN)/RHOL)*DTheta_LLT(ML,ND)+Theta_V(ML,ND)*DRHOVT(MN)/RHOL; %-RHOI/RHOL*KfL_T(ML,ND)*DTheta_LLh(ML,ND)/1e4DTheta_LLT==>DTheta_UUT + KhT(ML,ND)=(D_V(ML,ND)*Eta(ML,ND)+D_Vg(ML))*DRHOVT(MN)/RHOL+KL_T(ML,ND)+D_Ta(ML,ND);%-Khh(ML,ND)*1e4*L_f/(g*(T0+TT(MN)))*max(heaviside(TT_CRIT(MN)-(TT(MN)+T0)))considering ice freezing pressure*KfL_T(ML,ND);%;%();% KfL_T considering the ice end if KLa_Switch==1 - Kha(ML,ND)=RHOV(MN)*Beta_g(ML,ND)/RHOL+KL_h(ML,ND)/Gamma_w; + Kha(ML,ND)=RHOV(MN)*Beta_g(ML,ND)/RHOL+KfL_h(ML,ND)/Gamma_w; %KL_h==>KfL_h else Kha(ML,ND)=0; end @@ -53,5 +58,36 @@ Vvh(ML,ND)=0; VvT(ML,ND)=0; end - end -end + if isnan(Chh(ML,ND)) + keyboard + end + if isnan(Khh(ML,ND))==1 + keyboard + end + if isnan(Chg(ML,ND)) + keyboard + end + if isnan(ChT(ML,ND)) + keyboard + end + if isnan(KhT(ML,ND)) + keyboard + end + if ~isreal(Chh(ML,ND)) + keyboard + end + if ~isreal(Khh(ML,ND))==1 + keyboard + end + if ~isreal(Chg(ML,ND)) + keyboard + end + if ~isreal(ChT(ML,ND)) + keyboard + end + if ~isreal(KhT(ML,ND)) + keyboard + end + end +end + diff --git a/src/h_BC.m b/src/h_BC.m index f0184766..c477d7e7 100644 --- a/src/h_BC.m +++ b/src/h_BC.m @@ -1,49 +1,62 @@ -%function [AVAIL0,RHS,C4,C4_a,Evap,EVAP,Trap,Precip,Srt]=h_BC(lEstot,lEctot,PSIs,PSI,rsss,rrr,rxx,Srt,RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,h_SUR,C4,KL_h,Precip,NN,AVAIL0,C4_a,Evap,rwuef) -function [AVAIL0,RHS,C4,C4_a,Evap,EVAP,Trap,Precip,bx,Srt]=h_BC(DeltZ,bx,Srt,RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,Precip,NN,AVAIL0,C4_a,Evap,RHOV,Ta,HR_a,U,Ts,Theta_LL,Rv,g,NL,Evaptranp_Cal,Coefficient_n,Coefficient_Alpha,Theta_r,Theta_s,DURTN,PME,PT_PM_0,hh,rwuef,J,lEstot,lEctot) -%global Precip +function [AVAIL0,RHS,C4,C4_a,Rn_SOIL,Evap,EVAP,Trap,r_a_SOIL,Resis_a,Srt,Precip]=h_BC(RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,NN,C4_a,DeltZ,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,hh,rwuef,Theta_UU,Rn,T,TT,Gvc,Rns,Srt,Precip_msr,SUMTIME) %[AVAIL0,RHS,C4,C4_a,Evap,EVAP,Trap,Precip,bx,r_a_SOIL,Resis_a]=h_BC(DeltZ,bx,RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,Precip,NN,AVAIL0,C4_a,Evap,RHOV,Ta,HR_a,U,Ts,Theta_LL,Rv,g,NL,hh,rwuef,Theta_UU,Rn,T,TT,Gvc,Rns) +global DELT Precipp %%%%%%%%%% Apply the bottom boundary condition called for by NBChB %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if NBChB==1 %-----> Specify matric head at bottom to be ---BChB; - RHS(1)=BChB; + RHS(1)=BChB; C4(1,1)=1; RHS(2)=RHS(2)-C4(1,2)*RHS(1); - C4(1,2)=0; + C4(1,2)=0; C4_a(1)=0; elseif NBChB==2 %-----> Specify flux at bottom to be ---BChB (Positive upwards); RHS(1)=RHS(1)+BChB; elseif NBChB==3 %-----> NBChB=3,Gravity drainage at bottom--specify flux= hydraulic conductivity; - RHS(1)=RHS(1)-KL_h(1,1); + RHS(1)=RHS(1)-KL_h(1,1); end %%%%%%%%%% Apply the surface boundary condition called for by NBCh %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if NBCh==1 %-----> Specified matric head at surface---equal to hN; - RHS(NN)=h_SUR(KT); + RHS(NN)=h_SUR(KT); C4(NN,1)=1; RHS(NN-1)=RHS(NN-1)-C4(NN-1,2)*RHS(NN); - C4(NN-1,2)=0; + C4(NN-1,2)=0; C4_a(NN-1)=0; elseif NBCh==2 if NBChh==1 - RHS(NN)=hN; + RHS(NN)=hN; C4(NN,1)=1; RHS(NN-1)=RHS(NN-1)-C4(NN-1,2)*RHS(NN); - C4(NN-1,2)=0; + C4(NN-1,2)=0; else - RHS(NN)=RHS(NN)-BCh; %> and a specified matric head (saturation or dryness)was applied; - end -else -%[Evap,EVAP,Trap,Srt]= Evap_Cal(KT,lEstot,lEctot,PSIs,PSI,rsss,rrr,rxx,rwuef); - [Evap,EVAP,Trap,bx,Srt]= Evap_Cal(bx,Srt,DeltZ,TIME,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,NN,KT,Evaptranp_Cal,Coefficient_n,Coefficient_Alpha,Theta_r,Theta_s,DURTN,PME,PT_PM_0,hh,rwuef,J,lEstot,lEctot); - AVAIL0=Precip(KT)+DSTOR0/Delt_t; + RHS(NN)=RHS(NN)-BCh; %> and a specified matric head (saturation or dryness)was applied; + end +else + [Rn_SOIL,Evap,EVAP,Trap,r_a_SOIL,Resis_a,Srt]= Evap_Cal(DeltZ,TIME,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,NN,KT,hh,rwuef,Theta_UU,Rn,T,TT,Gvc,Rns,Srt); + + if Ts(KT) >0 + Precip(KT)=Precip_msr(KT)*0.1/DELT; + else + Precip(KT)=Precip_msr(KT)*0.1/DELT; + Precipp=Precipp+Precip(KT); + Precip(KT)=0; + end + + if Ts(KT) >0 + AVAIL0=Precip(KT)+Precipp+DSTOR0/Delt_t; + Precipp=0; + else + AVAIL0=Precip(KT)+DSTOR0/Delt_t; + end + if NBChh==1 - RHS(NN)=hN; + RHS(NN)=hN; C4(NN,1)=1; RHS(NN-1)=RHS(NN-1)-C4(NN-1,2)*RHS(NN); - C4(NN-1,2)=0; + C4(NN-1,2)=0; C4_a(NN-1)=0; else - RHS(NN)=RHS(NN)+AVAIL0-Evap(KT); + RHS(NN)=RHS(NN)+AVAIL0-Evap(KT); end end diff --git a/src/h_MAT.m b/src/h_MAT.m index b46d0fa5..63ea21ac 100644 --- a/src/h_MAT.m +++ b/src/h_MAT.m @@ -46,7 +46,7 @@ C7(ML)=C7(ML)-C7ARG; C7(ML+1)=C7(ML+1)+C7ARG; - %Srt, root water uptake; + % Srt, root water uptake; C9ARG1=(2*Srt(ML,1)+Srt(ML,2))*DeltZ(ML)/6;%sqrt(Chg(ML,1)*Chg(ML,2));% C9ARG2=(Srt(ML,1)+2*Srt(ML,2))*DeltZ(ML)/6; C9(ML)=C9(ML)+C9ARG1; diff --git a/src/h_sub.m b/src/h_sub.m index 369e24f8..c1c97b3f 100644 --- a/src/h_sub.m +++ b/src/h_sub.m @@ -1,3 +1,11 @@ +% function [Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DTheta_LLh,DTheta_LLT,DTheta_UUh,SAVEDTheta_UUh,SAVEDTheta_LLh,C1,C2,C4,C3,C4_a,C5,C6,C7,C5_a,C9,RHS,SAVE,AVAIL0,... +% Rn_SOIL,Evap,EVAP,Trap,r_a_SOIL,Resis_a,Srt,Precip,... +% CHK,hh,SAVEhh,QMT,QMB]= h_sub_SPAT(NL,... +% h,TT,T,Theta_LL,Theta_L,DTheta_LLh,DTheta_LLT,RHOV,RHOL,Theta_V,V_A,Eta,DRHOVh,... +% DRHOVT,KfL_h,D_Ta,KL_T,D_V,D_Vg,COR,Beta_g,Gamma0,Gamma_w,KLa_Switch,DVa_Switch,hThmrl,Thmrlefc,nD,TT_CRIT,T0,h_frez,hh_frez,Theta_UU,Theta_U,CORh,DTheta_UUh,... +% Chh,ChT,Khh,KhT,DeltZ,Delt_t,P_gg,Soilairefc,... +% NBCh,NBChB,BCh,BChB,hN,KT,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,Ta,HR_a,U,Ts,Rv,g,hh,rwuef,Rn,Gvc,Rns,Srt,Precip_msr,SUMTIME) + function h_sub global hh MN NN global C1 C2 C4 C3 C4_a C5 C6 C7 @@ -8,29 +16,35 @@ global Theta_L Theta_LL Theta_V Eta V_A global RHOV DRHOVh DRHOVT KL_h D_Ta KL_T D_V D_Vg global COR hThmrl Beta_g Gamma0 KLa_Switch DVa_Switch -global Precip Evap CHK Evapo EVAP +global Precip Evap CHK EVAP global NBCh NBChB BCh BChB hN KT DSTOR0 NBChh TIME h_SUR AVAIL0 -global QMT QMB QMTT QMBB +global QMT QMB QMTT QMBB Evapo trap RnSOIL PrecipO global Ta U Ts Rv g HR_a Srt C9 % U_wind is the mean wind speed at height z_ref (m¡¤s^-1), U is the wind speed at each time step. -global Evaptranp_Cal Coefficient_n Coefficient_Alpha Theta_r Theta_s DURTN PME PT_PM_0 rwuef J trap Trap lEstot lEctot -%global trap Trap lEstot lEctot PSIs PSI rsss rrr rxx rwuef +global rwuef Trap Rn_SOIL hOLD +global TT_CRIT T0 h_frez hh_frez Theta_UU Theta_U DTheta_UUh KfL_h Rn SAVEhh CORh r_a_SOIL Resis_a Precip_msr SUMTIME Gvc SAVEDTheta_UUh SAVEDTheta_LLh Rns + -[Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DTheta_LLh,DTheta_LLT]=hPARM(NL,hh,... +[Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DTheta_LLh,DTheta_LLT,DTheta_UUh,SAVEDTheta_UUh,SAVEDTheta_LLh]=hPARM(NL,hh,... h,TT,T,Theta_LL,Theta_L,DTheta_LLh,DTheta_LLT,RHOV,RHOL,Theta_V,V_A,Eta,DRHOVh,... -DRHOVT,KL_h,D_Ta,KL_T,D_V,D_Vg,COR,Beta_g,Gamma0,Gamma_w,KLa_Switch,DVa_Switch,hThmrl,Thmrlefc,nD); +DRHOVT,KfL_h,D_Ta,KL_T,D_V,D_Vg,COR,Beta_g,Gamma0,Gamma_w,KLa_Switch,DVa_Switch,hThmrl,Thmrlefc,nD,TT_CRIT,T0,h_frez,hh_frez,Theta_UU,Theta_U,CORh,DTheta_UUh,Chh,ChT,Khh,KhT); [C1,C2,C4,C3,C4_a,C5,C6,C7,C5_a,C9]=h_MAT(Chh,ChT,Khh,KhT,Kha,Vvh,VvT,Chg,DeltZ,NL,NN,Srt); [RHS,C4,SAVE]=h_EQ(C1,C2,C4,C5,C6,C7,C5_a,C9,NL,NN,Delt_t,T,TT,h,P_gg,Thmrlefc,Soilairefc); -[AVAIL0,RHS,C4,C4_a,Evap,EVAP,Trap,Precip,bx,Srt]=h_BC(DeltZ,bx,Srt,RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,Precip,NN,AVAIL0,C4_a,Evap,RHOV,Ta,HR_a,U,Ts,Theta_LL,Rv,g,NL,Evaptranp_Cal,Coefficient_n,Coefficient_Alpha,Theta_r,Theta_s,DURTN,PME,PT_PM_0,hh,rwuef,J,lEstot,lEctot); -[CHK,hh,C4]=hh_Solve(C4,hh,NN,NL,C4_a,RHS); +[AVAIL0,RHS,C4,C4_a,Rn_SOIL,Evap,EVAP,Trap,r_a_SOIL,Resis_a,Srt,Precip]=h_BC(RHS,NBCh,NBChB,BCh,BChB,hN,KT,Delt_t,DSTOR0,NBChh,TIME,h_SUR,C4,KL_h,NN,C4_a,DeltZ,RHOV,Ta,HR_a,U,Theta_LL,Ts,Rv,g,NL,hh,rwuef,Theta_UU,Rn,T,TT,Gvc,Rns,Srt,Precip_msr,SUMTIME);% h_BC; +[CHK,hh,C4,SAVEhh]=hh_Solve(C4,hh,NN,NL,C4_a,RHS); +if any(isnan(hh)) || any(hh(1:NN)<=-1E12) + for MN=1:NN + hh(MN)=hOLD(MN); + end +end for MN=1:NN - if hh(MN)<=-10^(5) - hh(MN)=-10^(5); - elseif hh(MN)>=-1e-6 + if hh(MN)>=-1e-6 hh(MN)=-1e-6; end -end +end [QMT,QMB]=h_Bndry_Flux(SAVE,hh,NN,KT); +PrecipO(KT)=Precip(KT); QMTT(KT)=QMT(KT); QMBB(KT)=QMB(KT); Evapo(KT)=Evap(KT); -trap(KT)=Trap(KT); \ No newline at end of file +trap(KT)=Trap(KT); +RnSOIL(KT)=Rn_SOIL(KT); diff --git a/src/hh_Solve.m b/src/hh_Solve.m index 0abaa1f8..ba42e299 100644 --- a/src/hh_Solve.m +++ b/src/hh_Solve.m @@ -1,6 +1,7 @@ -function [CHK,hh,C4]=hh_Solve(C4,hh,NN,NL,C4_a,RHS) +function [CHK,hh,C4,SAVEhh]=hh_Solve(C4,hh,NN,NL,C4_a,RHS) -RHS(1)=RHS(1)/C4(1,1); +TTheta_UU=zeros(NL+1,2);hdry(1:NN)=-5e5;hwet(1:NN)=-1;DTTheta_UU=zeros(NL+1,2);TGama_hh=zeros(NL+1,1);TTheta_m=zeros(NL,1); +RHS(1)=RHS(1)/C4(1,1);SAVDTheta_LLh=zeros(NL+1,2);INDICATOR=0; for ML=2:NN C4(ML,1)=C4(ML,1)-C4_a(ML-1)*C4(ML-1,2)/C4(ML-1,1); @@ -10,8 +11,14 @@ for ML=NL:-1:1 RHS(ML)=RHS(ML)-C4(ML,2)*RHS(ML+1)/C4(ML,1); end - for MN=1:NN - CHK(MN)=abs(RHS(MN)-hh(MN)); - hh(MN)=RHS(MN); + CHK(MN)=abs(RHS(MN)-hh(MN)); + hh(MN)=RHS(MN);SAVEhh(MN)=hh(MN); +end + +if isnan(SAVEhh)==1 + keyboard end +if ~isreal(SAVEhh) + keyboard +end \ No newline at end of file diff --git a/set_parameter_filenames.m b/src/set_parameter_filenames.m similarity index 100% rename from set_parameter_filenames.m rename to src/set_parameter_filenames.m diff --git a/setoptions.m b/src/setoptions.m similarity index 100% rename from setoptions.m rename to src/setoptions.m diff --git a/src/slprj/sim/_sharedutils/checksummap.mat b/src/slprj/sim/_sharedutils/checksummap.mat new file mode 100644 index 00000000..c6e93ce7 Binary files /dev/null and b/src/slprj/sim/_sharedutils/checksummap.mat differ diff --git a/src/slprj/sim/_sharedutils/shared_file.dmr b/src/slprj/sim/_sharedutils/shared_file.dmr new file mode 100644 index 00000000..f25ccd83 Binary files /dev/null and b/src/slprj/sim/_sharedutils/shared_file.dmr differ diff --git a/src/slprj/sim/dxpcmds_ref1/build_exception.mat b/src/slprj/sim/dxpcmds_ref1/build_exception.mat new file mode 100644 index 00000000..e4c4d0f2 Binary files /dev/null and b/src/slprj/sim/dxpcmds_ref1/build_exception.mat differ diff --git a/src/slprj/sim/dxpcmds_ref1/tmwinternal/minfo_mdlref.mat b/src/slprj/sim/dxpcmds_ref1/tmwinternal/minfo_mdlref.mat new file mode 100644 index 00000000..8d687b8d Binary files /dev/null and b/src/slprj/sim/dxpcmds_ref1/tmwinternal/minfo_mdlref.mat differ diff --git a/src/slprj/sim/dxpcmds_ref2/tmwinternal/minfo_mdlref.mat b/src/slprj/sim/dxpcmds_ref2/tmwinternal/minfo_mdlref.mat new file mode 100644 index 00000000..cadbda3f Binary files /dev/null and b/src/slprj/sim/dxpcmds_ref2/tmwinternal/minfo_mdlref.mat differ diff --git a/src/slprj/sl_proj.tmw b/src/slprj/sl_proj.tmw new file mode 100644 index 00000000..ba8ecba7 --- /dev/null +++ b/src/slprj/sl_proj.tmw @@ -0,0 +1,2 @@ +Simulink Coder project marker file. Please don't change it. +slprjVersion: 9.3_074 \ No newline at end of file diff --git a/src/slprj/slrt/dxpcmds6t/tmwinternal/minfo.mat b/src/slprj/slrt/dxpcmds6t/tmwinternal/minfo.mat new file mode 100644 index 00000000..073c3cd1 Binary files /dev/null and b/src/slprj/slrt/dxpcmds6t/tmwinternal/minfo.mat differ diff --git a/src/soilpropertyread.m b/src/soilpropertyread.m new file mode 100644 index 00000000..07322397 --- /dev/null +++ b/src/soilpropertyread.m @@ -0,0 +1,189 @@ +global SaturatedK SaturatedMC ResidualMC Coefficient_n Coefficient_Alpha porosity FOC FOS FOSL MSOC Coef_Lamda fieldMC latitude longitude +ncFilePath='../SoilProperty'; +dirOutput=dir('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','/','full'); +%ncdisp('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','/','full'); +%ncdisp('../SoilProperty/CLAY1.nc','/','full'); +%% load soil property +lat=ncread('../SoilProperty/CLAY1.nc','lat'); +lon=ncread('../SoilProperty/CLAY1.nc','lon'); +for i=1:16800 + if abs(lat(i)-latitude)<0.0085 + break + end +end + for j=1:43200 + if abs(lon(j)-longitude)<0.0085 + break + end + end +depth1=ncread('../SoilProperty/CLAY1.nc','depth'); +depth2=ncread('../SoilProperty/CLAY2.nc','depth'); +depth3=ncread('../SoilProperty/POR.nc','depth'); +CLAY1=ncread('../SoilProperty/CLAY1.nc','CLAY',[j,i,1],[1,1,4]); +CLAY2=ncread('../SoilProperty/CLAY2.nc','CLAY',[j,i,1],[1,1,4]); +SAND1=ncread('../SoilProperty/SAND1.nc','SAND',[j,i,1],[1,1,4]); +SAND2=ncread('../SoilProperty/SAND2.nc','SAND',[j,i,1],[1,1,4]); +SILT1=ncread('../SoilProperty/SILT1.nc','SILT',[j,i,1],[1,1,4]); +SILT2=ncread('../SoilProperty/SILT2.nc','SILT',[j,i,1],[1,1,4]); +OC1=ncread('../SoilProperty/OC1.nc','OC',[j,i,1],[1,1,4]); +OC2=ncread('../SoilProperty/OC2.nc','OC',[j,i,1],[1,1,4]); + +FOC=[CLAY1(1) CLAY1(3) CLAY2(1) CLAY2(2) CLAY2(3) CLAY2(4)]/100; %fraction of clay +FOS=[SAND1(1) SAND1(3) SAND2(1) SAND2(2) SAND2(3) SAND2(4)]/100; %fraction of sand +%FOSL=1-FOC-FOS; %fraction of silt +MSOC=double([OC1(1) OC1(3) OC2(1) OC2(2) OC2(3) OC2(4)])./10000; %mass fraction of soil organic matter +%% load lamda +lati=ncread('../SoilProperty/lambda/lambda_l1.nc','lat'); +long=ncread('../SoilProperty/lambda/lambda_l1.nc','lon'); +for i=1:21600 + if abs(lati(i)-latitude)<0.0085 + break + end +end + for j=1:43200 + if abs(long(j)-longitude)<0.0085 + break + end + end +lambda1=ncread('../SoilProperty/lambda/lambda_l1.nc','lambda',[j,i],[1,1]); +lambda2=ncread('../SoilProperty/lambda/lambda_l2.nc','lambda',[j,i],[1,1]); +lambda3=ncread('../SoilProperty/lambda/lambda_l3.nc','lambda',[j,i],[1,1]); +lambda4=ncread('../SoilProperty/lambda/lambda_l4.nc','lambda',[j,i],[1,1]); +lambda5=ncread('../SoilProperty/lambda/lambda_l5.nc','lambda',[j,i],[1,1]); +lambda6=ncread('../SoilProperty/lambda/lambda_l6.nc','lambda',[j,i],[1,1]); +lambda7=ncread('../SoilProperty/lambda/lambda_l7.nc','lambda',[j,i],[1,1]); +lambda8=ncread('../SoilProperty/lambda/lambda_l8.nc','lambda',[j,i],[1,1]); +Coef_Lamda=[lambda1 lambda3 lambda5 lambda6 lambda7 lambda8]; +%% load soil hydrulic parameters +lat=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','latitude'); +lon=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','longitude'); +% 0cm +alpha_fit_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','alpha_fit_0cm'); +n_fit_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','n_fit_0cm'); +mean_theta_s_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','mean_theta_s_0cm'); +mean_theta_r_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','mean_theta_r_0cm'); +mean_L_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','mean_L_0cm'); +mean_Ks_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','mean_Ks_0cm'); +var_scaling_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','var_scaling_0cm'); +valid_subpixels_0cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl1.nc','valid_subpixels_0cm'); +% 5cm +alpha_fit_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','alpha_fit_5cm'); +n_fit_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','n_fit_5cm'); +mean_theta_s_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','mean_theta_s_5cm'); +mean_theta_r_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','mean_theta_r_5cm'); +mean_L_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','mean_L_5cm'); +mean_Ks_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','mean_Ks_5cm'); +var_scaling_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','var_scaling_5cm'); +valid_subpixels_5cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl2.nc','valid_subpixels_5cm'); +% 15cm +alpha_fit_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','alpha_fit_15cm'); +n_fit_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','n_fit_15cm'); +mean_theta_s_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','mean_theta_s_15cm'); +mean_theta_r_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','mean_theta_r_15cm'); +mean_L_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','mean_L_15cm'); +mean_Ks_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','mean_Ks_15cm'); +var_scaling_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','var_scaling_15cm'); +valid_subpixels_15cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl3.nc','valid_subpixels_15cm'); +% 30cm +alpha_fit_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','alpha_fit_30cm'); +n_fit_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','n_fit_30cm'); +mean_theta_s_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','mean_theta_s_30cm'); +mean_theta_r_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','mean_theta_r_30cm'); +mean_L_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','mean_L_30cm'); +mean_Ks_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','mean_Ks_30cm'); +var_scaling_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','var_scaling_30cm'); +valid_subpixels_30cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl4.nc','valid_subpixels_30cm'); +% 60cm +alpha_fit_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','alpha_fit_60cm'); +n_fit_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','n_fit_60cm'); +mean_theta_s_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','mean_theta_s_60cm'); +mean_theta_r_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','mean_theta_r_60cm'); +mean_L_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','mean_L_60cm'); +mean_Ks_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','mean_Ks_60cm'); +var_scaling_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','var_scaling_60cm'); +valid_subpixels_60cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl5.nc','valid_subpixels_60cm'); +% 100cm +alpha_fit_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','alpha_fit_100cm'); +n_fit_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','n_fit_100cm'); +mean_theta_s_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','mean_theta_s_100cm'); +mean_theta_r_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','mean_theta_r_100cm'); +mean_L_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','mean_L_100cm'); +mean_Ks_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','mean_Ks_100cm'); +var_scaling_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','var_scaling_100cm'); +valid_subpixels_100cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl6.nc','valid_subpixels_100cm'); +% 200cm +alpha_fit_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','alpha_fit_200cm'); +n_fit_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','n_fit_200cm'); +mean_theta_s_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','mean_theta_s_200cm'); +mean_theta_r_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','mean_theta_r_200cm'); +mean_L_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','mean_L_200cm'); +mean_Ks_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','mean_Ks_200cm'); +var_scaling_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','var_scaling_200cm'); +valid_subpixels_200cm=ncread('../SoilProperty/Hydraul_Param_SoilGrids_Schaap_sl7.nc','valid_subpixels_200cm'); +% read data +for i=1:600 + if abs(lat(i)-latitude)<0.25 + break + end +end + for j=1:1440 + if abs(lon(j)-longitude)<0.25 + break + end + end + % 0cm + alpha0=alpha_fit_0cm(j,i); + n0=n_fit_0cm(j,i); + theta_s0=mean_theta_s_0cm(j,i); + theta_r0=mean_theta_r_0cm(j,i); + Ks0=mean_Ks_0cm(j,i); + % 5cm + alpha5=alpha_fit_5cm(j,i); + n5=n_fit_5cm(j,i); + theta_s5=mean_theta_s_5cm(j,i); + theta_r5=mean_theta_r_5cm(j,i); + Ks5=mean_Ks_5cm(j,i); + % 15cm + alpha15=alpha_fit_15cm(j,i); + n15=n_fit_15cm(j,i); + theta_s15=mean_theta_s_15cm(j,i); + theta_r15=mean_theta_r_15cm(j,i); + Ks15=mean_Ks_15cm(j,i); + % 30cm + alpha30=alpha_fit_30cm(j,i); + n30=n_fit_30cm(j,i); + theta_s30=mean_theta_s_30cm(j,i); + theta_r30=mean_theta_r_30cm(j,i); + Ks30=mean_Ks_30cm(j,i); + % 60cm + alpha60=alpha_fit_60cm(j,i); + n60=n_fit_60cm(j,i); + theta_s60=mean_theta_s_60cm(j,i); + theta_r60=mean_theta_r_60cm(j,i); + Ks60=mean_Ks_60cm(j,i); + % 100cm + alpha100=alpha_fit_100cm(j,i); + n100=n_fit_100cm(j,i); + theta_s100=mean_theta_s_100cm(j,i); + theta_r100=mean_theta_r_100cm(j,i); + Ks100=mean_Ks_100cm(j,i); + % 200cm + alpha200=alpha_fit_200cm(j,i); + n200=n_fit_200cm(j,i); + theta_s200=mean_theta_s_200cm(j,i); + theta_r200=mean_theta_r_200cm(j,i); + Ks200=mean_Ks_200cm(j,i); +% soil property +SaturatedK=[Ks0/(3600*24) Ks5/(3600*24) Ks30/(3600*24) Ks60/(3600*24) Ks100/(3600*24) Ks200/(3600*24)];%[2.67*1e-3 1.79*1e-3 1.14*1e-3 4.57*1e-4 2.72*1e-4]; %[2.3*1e-4 2.3*1e-4 0.94*1e-4 0.94*1e-4 0.68*1e-4] 0.18*1e-4Saturation hydraulic conductivity (cm.s^-1); +SaturatedMC=[theta_s0 theta_s5 theta_s30 theta_s60 theta_s100 theta_s200]; % 0.42 0.55 Saturated water content; +ResidualMC=[theta_r0 theta_r5 theta_r30 theta_r60 theta_r100 theta_r200]; %0.037 0.017 0.078 The residual water content of soil; +Coefficient_n=[n0 n5 n30 n60 n100 n200]; %1.2839 1.3519 1.2139 Coefficient in VG model; +Coefficient_Alpha=[alpha0 alpha5 alpha30 alpha60 alpha100 alpha200]; % 0.02958 0.007383 Coefficient in VG model; +porosity=[theta_s0 theta_s5 theta_s30 theta_s60 theta_s100 theta_s200]; % Soil porosity; +fieldMC=(1./(((341.09.*Coefficient_Alpha).^(Coefficient_n)+1).^(1-1./Coefficient_n))).*(SaturatedMC-ResidualMC)+ResidualMC; diff --git a/src/soltir_tp7.m b/src/soltir_tp7.m new file mode 100644 index 00000000..b0dd03ab --- /dev/null +++ b/src/soltir_tp7.m @@ -0,0 +1,222 @@ +function [wn,wl,Tall] = soltir_tp7(filename) + +% soltir_tp7 Reads MODTRAN tp7 file and applies a new MIT algorithm to derive +% 18 spectral functions for atmospheric correction and simulations at BOA +% and TOA + +% This function reads a MODTRAN tp7 output file that contains data for 4 +% runs with different albedos a: +% +% For a = 0.5 at ground altitude +% For a = 1.0 at ground altitude +% For a = 0.0 at TOA +% For a = 1.0 at TOA +% +% From the MODTRAN outputs 18 atmospheric properties are derived, +% named t1...t18 +% The radiance data are converted into units of mW m-2 sr-1 nm-1 +% +% © Wouter Verhoef 2011-2014 + +fid = fopen(filename,'r'); +modname = filename(1:size(filename,2)-4); +outname = [modname '.atm']; + +for i = 1:7, fgetl(fid); end + +rline = str2num(fgetl(fid)); +tts = rline(4); +cts = cosd(tts); + +s = fgetl(fid); +rline = sscanf(s,'%10f',3); +wns = rline(1); wne = rline(2); wstep = rline(3); +nw = int32((wne-wns)/wstep)+1; + +datarec = zeros(nw,15,4); % MODTRAN5.2.1 tp7 15 column output format +Tall = zeros(nw,18); % 18 output spectra + +fgetl(fid); fgetl(fid); + +for ipass = 1:4 + for il=1:nw + s=fgetl(fid); + dline=str2num(s); + datarec(il,:,ipass)=dline; + end + for j = 1:12, fgetl(fid); end +end + +wn = datarec(:,1,1); +fac = wn.*wn; +wl = 1e7./wn; +wls = wl(nw); +wle = wl(1); + +% MIT algorithm supporting fluorescence retrievals +% Wout Verhoef Sept. 2011 + +% Support all applications, T-18 system +% OpT in heavy absorption bands now estimnated from Planck Tb at 6500 nm +% Wout Verhoef Oct. - Nov. 2012 + +% Constants of Planck function + +c1 = 1.191066e-22; +c2 = 14388.33; + +tran_boa = datarec(:,2,1); +tran_toa = datarec(:,2,3); + +too = tran_toa; + +toasun = datarec(:,14,4).*fac/pi*cts; % = Eso cos(tts) / pi + +%BOA + +grfl50_boa = datarec(:,7,1).*fac; +sfem50 = datarec(:,4,1).*fac; +sfem0_boa = 2*sfem50; +grfl100_boa = datarec(:,7,2).*fac; +delgtot_boa = grfl100_boa-sfem0_boa; +crdd = (grfl50_boa-sfem50)./(grfl100_boa-grfl50_boa-sfem50); + +rdd = max(0,1-crdd); + +OpT = crdd.*delgtot_boa./tran_boa; + +% OpT at 6500 nm is used to estimate brightness temperature of La(b), which +% is used to get a minimum radiance where O is zero + +wlp = 6500; +Lp = interp1(wl,OpT,wlp,'nearest'); +Tp = c2/(wlp*1e-3*log(1+c1*(wlp*1e-9)^(-5)/Lp)); +Lmin = c1*(wl*1e-9).^(-5)./(exp(c2./(wl*1e-3*Tp))-1); + +%TOA + +grfl100_toa = datarec(:,7,4).*fac; +sfem0 = datarec(:,4,3).*fac; +delgtot_toa = grfl100_toa - sfem0; +OpTtran = crdd.*delgtot_toa; +path100 = datarec(:,5,4).*fac; +path0 = datarec(:,5,3).*fac; + +rso = path0./toasun; + +delpath = path100 - path0; +ptem100 = datarec(:,3,4).*fac; +ptem0 = datarec(:,3,3).*fac; +delptem = max(0,ptem100-ptem0); +delatmo = delpath + delptem; + +iT = (wl > 4600); +ia = (~iT & delpath == 0) | (iT & delptem == 0); + +fO = delpath./(delatmo+1e-60).*~ia + ~iT.*ia; +fT = delptem./(delatmo+1e-60).*~ia + iT.*ia; + +O = fO.*OpT; +T = fT.*OpT; + +% Correct cases where T = 0 + +i0 = (T == 0); +T(i0) = Lmin(i0); +fT(i0) = T(i0)./OpT(i0); +Ttran = fT.*OpTtran; +Otran = OpTtran-Ttran; + +tdo = delatmo./(delgtot_toa+1e-6).*tran_toa; + +tdo(ia) = 0; + +gsun100_toa = datarec(:,8,4).*fac; +gsun100_boa = datarec(:,8,2).*fac; + +tsstoo = gsun100_toa./toasun; +tss = gsun100_boa./toasun; +tsdM = O./toasun-tss; + +tsdM(ia) = 0; + +% Apply log regression to predict tsd from tdo, too, tss, and wl + +Ir = (wl>1500 & wl<1700) | (wl>2100 & wl<2300) | ... + (wl>3950 & wl<4100); +y = log(tsdM(Ir)./tss(Ir))-log(tdo(Ir)./too(Ir)); +x = log(wl(Ir)); +n = size(x,1); +xm = sum(x)/n; +ym = sum(y)/n; +a = (x-xm)'*(y-ym)/((x-xm)'*(x-xm)); +b = ym-a*xm; +p = a*log(wl)+b; +tsdp = tss.*tdo./(too+1e-60).*exp(p); + +% weight proportional to delatmo squared + +wgtM = delatmo.^2; + +tsd = (wgtM.*tsdM+tsdp)./(wgtM+1); + +fsun = (tss+1e-60)./(tss+1e-60+tsd); +iH = (wl>2600); + +tsdtoo = Otran./toasun-tsstoo; +tsdtoo(iH) = tsd(iH).*too(iH); + +tssrddtoo = tsstoo.*rdd; +toordd = too.*rdd; +tssrdd = tss.*rdd; +tsstdo = fsun.*delpath.*crdd./toasun; +tsdtdo = (1-fsun).*delpath.*crdd./toasun; +Lat = ptem0-sfem0_boa./crdd.*tdo; +Lab = T+sfem0_boa.*crdd; +Labtoo = Ttran+crdd.*sfem0_boa.*too; +Labtdo = crdd.*(delptem+sfem0_boa.*tdo); + +Tall = [toasun rso rdd tss tsd too tdo tsstoo tsdtoo tsstdo tsdtdo ... + tssrdd toordd tssrddtoo Lat Lab Labtoo Labtdo]; + +fclose(fid); + +% Verification against MODTRAN + +% pt0 = Lat; +% pt100 = Lat+Labtdo./(1-rdd); +% pa0 = rso.*toasun; +% pa100 = toasun.*(rso+(tsstdo+tsdtdo)./(1-rdd)); +% gb50 = (toasun*.5.*(tss+(2*tsd+tssrdd)./(2-rdd))+Lab./(2-rdd)).*tran_boa; +% gb100 = (toasun.*(tss+tsd)./(1-rdd)+Lab./(1-rdd)).*tran_boa; +% gt100 = toasun.*(tsstoo+(tsdtoo+tssrddtoo)./(1-rdd))+Labtoo./(1-rdd); +% gs100 = toasun.*tsstoo; + +% Write data to output file + +fid=fopen(outname,'w'); +str1=' WN (cm-1) WL (nm) '; +str2=' T1 T2 T3 T4 T5 T6 T7 '; +str3=' T8 T9 T10 T11 T12 T13 T14 '; +str4=' T15 T16 T17 T18'; +str5=[' toasun rso rdd tss tsd too' ... + ' tdo tsstoo tsdtoo tsstdo tsdtdo tssrdd' ... + ' toordd tssrddtoo Lat Lab Labtoo Labtdo']; +str=[str1 str2 str3 str4]; +fprintf(fid,'%s\r\n',str); +fprintf(fid,'%s\r\n\r\n',str5); + +for i = 1:nw + str = sprintf('%9.2f',wn(i)); + str = [str sprintf('%10.3f',wl(i))]; + str = [str sprintf('%10.5f',Tall(i,1))]; + str = [str sprintf('%10.6f',Tall(i,2:14));]; + a = sprintf('%14.6e',Tall(i,15:18)); + str = [str a]; + fprintf(fid,'%s\r\n',str); +end + +fclose('all'); + +end +