Skip to content

Commit

Permalink
fix date 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Dec 9, 2023
1 parent 7227860 commit 351ef63
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 37 deletions.
5 changes: 3 additions & 2 deletions DATA/PROJECT/Troy/SETTINGS/parameters.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ tilt=0
tilt_mode=dem

[snow]
tempMaxWithSnow=1
tempMaxWithSnow=2
tempMinWithRain=-0.5
snowWaterHoldingCapacity=0.05
snowSkinThickness=0.003
snowVegetationHeight=0.1
snowVegetationHeight=1
soilAlbedo=0.2
skinThickness=0.02
7 changes: 4 additions & 3 deletions agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,12 @@ Crit3DTime Project::getCrit3DCurrentTime()

QDateTime Project::getCurrentTime()
{
QDateTime myTime;
myTime.setDate(this->currentDate);
return myTime.addSecs(this->currentHour * HOUR_SECONDS);
QDateTime myDateTime;
myDateTime.setDate(this->currentDate);
return myDateTime.addSecs(this->currentHour * HOUR_SECONDS);
}


void Project::getMeteoPointsRange(float& minimum, float& maximum, bool useNotActivePoints)
{
minimum = NODATA;
Expand Down
8 changes: 4 additions & 4 deletions agrolib/snow/snow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Crit3DSnowParameters::Crit3DSnowParameters()
void Crit3DSnowParameters::initialize()
{
// default values
skinThickness = 0.02; /*!< [m] */ // LC: VERSIONI DIVERSE IN BROOKS: 3mm (nel testo), 2-3cm (nel codice)
soilAlbedo = 0.2; /*!< [-] bare soil - 20% */
skinThickness = 0.02; /*!< [m] */ // LC: VERSIONI DIVERSE IN BROOKS: 3mm (nel testo), 2-3cm (nel codice)
soilAlbedo = 0.2; /*!< [-] bare soil */
snowVegetationHeight = 1;
snowWaterHoldingCapacity = 0.05;
snowMaxWaterContent = 0.1;
Expand Down Expand Up @@ -205,8 +205,8 @@ void Crit3DSnow::computeSnowBrooksModel()
else
cloudCover = 0.1;

// ombreggiamento per vegetazione (4m sopra manto nevoso: ombreggiamento completo)
// TODO improve - use LAI when available
// vegetation shadowing (4 m sopra manto nevoso: ombreggiamento completo)
// TODO: use LAI when available
double maxSnowDensity = 10; // 1 mm snow = 1 cm water
double maxVegetationHeight = 4; // [m]
double vegetationShadowing; // [-]
Expand Down
17 changes: 13 additions & 4 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ bool Crit3DProject::runModels(QDateTime firstTime, QDateTime lastTime)
int firstHour = (myDate == firstDate) ? hour1 : 0;
int lastHour = (myDate == lastDate) ? hour2 : 23;

for (currentHour = firstHour; currentHour <= lastHour; currentHour++)
for (int hour = firstHour; hour <= lastHour; hour++)
{
QDateTime myTime = QDateTime(myDate, QTime(currentHour, 0, 0), Qt::UTC);
currentHour = hour;
QDateTime myTime = QDateTime(myDate, QTime(hour, 0, 0), Qt::UTC);

if (! modelHourlyCycle(myTime, currentOutputPath))
{
Expand Down Expand Up @@ -1191,8 +1192,16 @@ bool Crit3DProject::loadModelState(QString statePath)
int month = stateStr.mid(4,2).toInt();
int day = stateStr.mid(6,2).toInt();
int hour = stateStr.mid(10,2).toInt();
setCurrentDate(QDate(year, month, day));
setCurrentHour(hour);
if (hour == 24)
{
setCurrentDate(QDate(year, month, day).addDays(1));
setCurrentHour(0);
}
else
{
setCurrentDate(QDate(year, month, day));
setCurrentHour(hour);
}

// snow model
QString snowPath = statePath + "/snow";
Expand Down
50 changes: 38 additions & 12 deletions bin/CRITERIA3D/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "dialogWaterFluxesSettings.h"
#include "utilities.h"

#include <QDebug>
#include <QTime>


extern Crit3DProject myProject;
Expand Down Expand Up @@ -1876,11 +1876,20 @@ bool selectDates(QDateTime &firstTime, QDateTime &lastTime)
return false;
}

firstTime.setTimeSpec(Qt::UTC);
firstTime.setDate(myProject.getCurrentDate());
firstTime = firstTime.addSecs((myProject.getCurrentHour() +1) * HOUR_SECONDS);
firstTime.setTimeZone(QTimeZone::UTC);
if (myProject.getCurrentHour() == 24)
{
firstTime.setDate(myProject.getCurrentDate().addDays(1));
firstTime.setTime(QTime(0,0,0,0));
}
else
{
firstTime.setDate(myProject.getCurrentDate());
firstTime.setTime(QTime(myProject.getCurrentHour(),0,0,0));
}
firstTime = firstTime.addSecs(HOUR_SECONDS);

lastTime.setTimeSpec(Qt::UTC);
lastTime.setTimeZone(QTimeZone::UTC);
lastTime = firstTime;
lastTime.setTime(QTime(23,0,0));

Expand Down Expand Up @@ -2076,15 +2085,25 @@ void MainWindow::on_actionSnow_run_model_triggered()
startModels(firstTime, lastTime);
}

void MainWindow::on_actionSnow_compute_current_hour_triggered()

void MainWindow::on_actionSnow_compute_next_hour_triggered()
{
if (! myProject.snowMaps.isInitialized)
{
if (! myProject.initializeSnowModel())
return;
}

QDateTime currentTime = myProject.getCurrentTime();
QDateTime currentTime;
if (myProject.getCurrentHour() == 23)
{
currentTime.setDate(myProject.getCurrentDate().addDays(1));
currentTime.setTime(QTime(0, 0, 0, 0));
}
else
{
currentTime = myProject.getCurrentTime().addSecs(HOUR_SECONDS);
}

myProject.processes.initialize();
myProject.processes.computeMeteo = true;
Expand All @@ -2094,6 +2113,7 @@ void MainWindow::on_actionSnow_compute_current_hour_triggered()
startModels(currentTime, currentTime);
}


void MainWindow::on_actionSnow_settings_triggered()
{
DialogSnowSettings dialogSnowSetting;
Expand Down Expand Up @@ -2211,15 +2231,24 @@ void MainWindow::on_actionCriteria3D_Initialize_triggered()
}


void MainWindow::on_actionCriteria3D_compute_current_hour_triggered()
void MainWindow::on_actionCriteria3D_compute_next_hour_triggered()
{
if (! myProject.isCriteria3DInitialized)
{
myProject.logError("Initialize 3D water fluxes before");
return;
}

QDateTime currentTime = myProject.getCurrentTime();
QDateTime currentTime;
if (myProject.getCurrentHour() == 23)
{
currentTime.setDate(myProject.getCurrentDate().addDays(1));
currentTime.setTime(QTime(0, 0, 0, 0));
}
else
{
currentTime = myProject.getCurrentTime().addSecs(HOUR_SECONDS);
}

startModels(currentTime, currentTime);
}
Expand Down Expand Up @@ -2398,9 +2427,6 @@ void MainWindow::on_actionLoad_state_triggered()
updateDateTime();
loadMeteoPointsDataSingleDay(myProject.getCurrentDate(), true);
redrawMeteoPoints(currentPointsVisualization, true);

//myProject.logInfoGUI("Model state successfully loaded: " + myProject.getCurrentDate().toString()
// + " H:" + QString::number(myProject.getCurrentHour()));
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions bin/CRITERIA3D/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

void on_actionSnow_settings_triggered();
void on_actionSnow_initialize_triggered();
void on_actionSnow_compute_current_hour_triggered();
void on_actionSnow_compute_next_hour_triggered();
void on_actionSnow_run_model_triggered();

void on_actionView_Snow_water_equivalent_triggered();
Expand All @@ -121,6 +121,7 @@
void on_flagSave_state_daily_step_toggled(bool isChecked);

void on_actionCriteria3D_Initialize_triggered();
void on_actionCriteria3D_compute_next_hour_triggered();
void on_actionCriteria3D_run_models_triggered();

void on_buttonModelPause_clicked();
Expand Down Expand Up @@ -196,8 +197,6 @@

void on_actionTopographicDistanceMapLoad_triggered();

void on_actionCriteria3D_compute_current_hour_triggered();

void on_actionShow_3D_viewer_triggered();

void on_viewer3DClosed();
Expand Down
18 changes: 9 additions & 9 deletions bin/CRITERIA3D/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,8 @@
<minute>0</minute>
<second>0</second>
<year>1752</year>
<month>10</month>
<day>1</day>
<month>9</month>
<day>29</day>
</datetime>
</property>
<property name="maximumDate">
Expand Down Expand Up @@ -1848,7 +1848,7 @@
<x>0</x>
<y>0</y>
<width>1280</width>
<height>23</height>
<height>28</height>
</rect>
</property>
<property name="palette">
Expand Down Expand Up @@ -1976,7 +1976,7 @@
<addaction name="actionWaterFluxes_settings"/>
<addaction name="separator"/>
<addaction name="actionCriteria3D_Initialize"/>
<addaction name="actionCriteria3D_compute_current_hour"/>
<addaction name="actionCriteria3D_compute_next_hour"/>
<addaction name="actionCriteria3D_run_models"/>
<addaction name="separator"/>
<addaction name="actionUpdate_subHourly"/>
Expand Down Expand Up @@ -2123,7 +2123,7 @@
<addaction name="actionSave_state"/>
<addaction name="separator"/>
<addaction name="actionSnow_initialize"/>
<addaction name="actionSnow_compute_current_hour"/>
<addaction name="actionSnow_compute_next_hour"/>
<addaction name="actionSnow_run_model"/>
<addaction name="separator"/>
<addaction name="flagSave_state_daily_step"/>
Expand Down Expand Up @@ -2544,9 +2544,9 @@
<string>Age of snow</string>
</property>
</action>
<action name="actionSnow_compute_current_hour">
<action name="actionSnow_compute_next_hour">
<property name="text">
<string>Compute current hour</string>
<string>Compute next hour</string>
</property>
</action>
<action name="actionView_Snowmelt">
Expand Down Expand Up @@ -2781,9 +2781,9 @@
<string>Load...</string>
</property>
</action>
<action name="actionCriteria3D_compute_current_hour">
<action name="actionCriteria3D_compute_next_hour">
<property name="text">
<string>Compute current hour</string>
<string>Compute next hour</string>
</property>
</action>
<action name="actionShow_3D_viewer">
Expand Down

0 comments on commit 351ef63

Please sign in to comment.