这段代码是一个用于运行温室环境模拟的MATLAB脚本,使用了GreenLight模型来模拟温室内的环境参数(如温度、湿度、CO2浓度等)以及作物的生长情况。代码通过预定义的输入和设置来运行模拟,并绘制了多个输出结果的图表。以下是代码的详细解释:
1. 设置文件路径
currentFile = mfilename('fullpath'); currentFolder = fileparts(currentFile); dataFolder = strrep(currentFolder, '\Code\runScenarios', '\Code\inputs\energyPlus\data\'); outputFolder = strrep(currentFolder, '\Code\runScenarios', '\Output\');
mfilename('fullpath')
获取当前文件的完整路径。fileparts
提取当前文件所在的文件夹路径。strrep
用于替换路径中的部分字符串,生成数据文件夹和输出文件夹的路径。
2. 天气输入设置
weatherInput = 'bei'; % Choose name of location, see folder inputs\energyPlus\data\ seasonLength = 1; % season length in days firstDay = 1; % Beginning of season (days since January 1)
weatherInput
指定了天气数据文件的名称(例如bei
表示北京的天气数据)。seasonLength
设置了模拟的季节长度(1天)。firstDay
设置了模拟开始的时间(从1月1日开始的第一天)。
3. 作物设置
isMature = true; % Start with a mature crop, use false to start with a small crop
isMature
是一个布尔值,用于指定作物是否从成熟状态开始。如果设置为false
,则作物从幼苗状态开始。
4. 灯具选择
lampType = 'led'; % 'led', 'hps', or 'none'
lampType
指定了温室中使用的灯具类型,可以是led
(LED灯)、hps
(高压钠灯)或none
(无灯具)。
5. 温室结构设置
p.psi = 22; % Mean greenhouse cover slope [°] p.aFlr = 4e4; % Floor area of [m^{2}] p.aCov = 4.84e4; % Surface of the cover including side walls [m^{2}] p.hAir = 6.3; % Height of the main compartment [m] p.hGh = 6.905; % Mean height of the greenhouse [m] p.aRoof = 0.1169*4e4; % Maximum roof ventilation area p.hVent = 1.3; % Vertical dimension of single ventilation opening [m] p.cDgh = 0.75; % Ventilation discharge coefficient [-] p.lPipe = 1.25; % Length of pipe rail system [m m^{-2}] p.phiExtCo2 = 7.2e4*4e4/1.4e4; % Capacity of CO2 injection for the entire greenhouse [mg s^{-1}] p.pBoil = 300*p.aFlr; % Capacity of boiler for the entire greenhouse [W]
- 这些参数定义了温室的结构和物理特性,例如温室的高度、面积、通风面积、CO2注入能力等。
6. 控制设置
p.co2SpDay = 1000; % CO2 setpoint during the light period [ppm] p.tSpNight = 18.5; % temperature set point dark period [°C] p.tSpDay = 19.5; % temperature set point light period [°C] p.rhMax = 87; % maximum relative humidity [%] p.ventHeatPband = 4; % P-band for ventilation due to high temperature [°C] p.ventRhPband = 50; % P-band for ventilation due to high relative humidity [% humidity] p.thScrRhPband = 10; % P-band for screen opening due to high relative humidity [% humidity] p.lampsOn = 0; % time of day (in morning) to switch on lamps [h] p.lampsOff = 18; % time of day (in evening) to switch off lamps [h] p.lampsOffSun = 400; % lamps are switched off if global radiation is above this value [W m^{-2}] p.lampRadSumLimit = 10; % Predicted daily radiation sum from the sun where lamps are not used that day [MJ m^{-2} day^{-1}]
- 这些参数定义了温室的控制策略,例如温度、湿度和CO2的设定值,灯具的开关时间,以及通风和遮阳的控制逻辑。
7. 运行模拟
tic; filename = ''; % add file name for saving file if ~isempty(filename) filename = [outputFolder filename]; end season = cutEnergyPlusData(firstDay, seasonLength, [dataFolder weatherInput 'EnergyPlus.mat']); gl = runGreenLight(lampType, season, filename, paramNames, paramVals, isMature); toc;
tic
和toc
用于计时。cutEnergyPlusData
函数从天气数据文件中提取指定时间段的数据。runGreenLight
函数运行GreenLight模型,生成模拟结果gl
。
8. 绘制输出结果
代码使用 subplot
创建了多个子图,分别绘制了以下内容:
- 温度和室外温度(
tAir
和tOut
)。 - 室内外水汽压(
vpAir
和vpOut
)。 - 室内外相对湿度(
rhIn
和rhOut
)。 - 室内外CO2浓度(
co2Air
和co2Out
)。 - 室内外CO2浓度(ppm)(
co2InPpm
和co2Out
)。 - 室外总辐射、PAR辐射和灯具输入(
iGlob
、rParGhSun
、rParGhLamp
等)。 - 光合有效辐射(PPFD)(
parJtoUmolSun
和zetaLampPar
)。 - 作物同化、呼吸和生长(
mcAirCan
、mcAirBuf
等)。 - 作物干物质分配(
cFruit
、cStem
、cLeaf
等)。 - 果实干重和收获(
cFruit
和mcFruitHar
)。
9. 时间格式化
dateFormat = 'HH:00'; numticks = get(gca,'XTick'); dateticks = datenum(datenum(gl.t.label)+numticks/86400); datestrings = datestr(dateticks,dateFormat); xticklabels(datestrings);
- 将X轴的时间刻度格式化为小时和分钟(
HH:00
)。
总结
这段代码的主要功能是:
- 加载天气数据和温室参数。
- 运行GreenLight模型,模拟温室环境和作物生长。
- 绘制温室环境参数(温度、湿度、CO2浓度等)和作物生长指标(干物质分配、光合作用等)的变化曲线。
通过调整输入参数(如灯具类型、温室结构、控制策略等),用户可以研究不同设置对温室环境和作物生长的影响。
这段代码定义了温室的结构和物理特性参数,这些参数用于GreenLight模型中的温室环境模拟。以下是每个参数的具体含义和单位:
1. 温室覆盖坡度
p.psi = 22; % Mean greenhouse cover slope [°]
- 含义:温室覆盖的平均坡度(倾斜角度)。
- 单位:度(°)。
- 作用:影响温室的光照接收和热交换。
2. 温室地板面积
p.aFlr = 4e4; % Floor area of [m^{2}]
- 含义:温室的地板面积。
- 单位:平方米(m²)。
- 作用:用于计算温室的总空间和作物的种植面积。
3. 温室覆盖面积(包括侧墙)
p.aCov = 4.84e4; % Surface of the cover including side walls [m^{2}]
- 含义:温室覆盖的总面积,包括屋顶和侧墙。
- 单位:平方米(m²)。
- 作用:用于计算温室的热交换和光照分布。
4. 主室高度
p.hAir = 6.3; % Height of the main compartment [m]
- 含义:温室主室的高度。
- 单位:米(m)。
- 作用:影响温室内的空气流动和温度分布。
5. 温室平均高度
p.hGh = 6.905; % Mean height of the greenhouse [m]
- 含义:温室的平均高度。
- 单位:米(m)。
- 作用:用于计算温室的热容量和空气体积。
6. 最大屋顶通风面积
p.aRoof = 0.1169*4e4; % Maximum roof ventilation area
- 含义:温室屋顶的最大通风面积。
- 单位:平方米(m²)。
- 作用:影响温室的通风能力和空气交换效率。
7. 单通风口的垂直尺寸
p.hVent = 1.3; % Vertical dimension of single ventilation opening [m]
- 含义:单个通风口的垂直高度。
- 单位:米(m)。
- 作用:用于计算通风口的空气流量。
8. 通风排放系数
p.cDgh = 0.75; % Ventilation discharge coefficient [-]
- 含义:通风口的排放系数,表示通风效率。
- 单位:无量纲。
- 作用:用于计算通风口的实际空气流量。
9. 管道轨道系统长度
p.lPipe = 1.25; % Length of pipe rail system [m m^{-2}]
- 含义:每平方米地板面积的管道轨道系统长度。
- 单位:米每平方米(m/m²)。
- 作用:用于计算温室内的加热或冷却系统的分布。
10. CO2注入能力
p.phiExtCo2 = 7.2e4*4e4/1.4e4; % Capacity of CO2 injection for the entire greenhouse [mg s^{-1}]
- 含义:整个温室的CO2注入能力。
- 单位:毫克每秒(mg/s)。
- 作用:用于模拟CO2浓度对作物光合作用的影响。
11. 锅炉容量
p.pBoil = 300*p.aFlr; % Capacity of boiler for the entire greenhouse [W]
- 含义:整个温室的锅炉加热容量。
- 单位:瓦特(W)。
- 作用:用于模拟温室的加热系统对温度的影响。
总结
这段代码定义了温室的结构、通风、加热和CO2注入等关键参数。这些参数用于GreenLight模型中,以模拟温室内的环境条件(如温度、湿度、CO2浓度等)以及作物的生长情况。通过调整这些参数,用户可以研究不同温室设计对环境和作物生长的影响。