From c0a2fd01df338b81bc2b8d2f6b96f54617149cd9 Mon Sep 17 00:00:00 2001 From: giadasan Date: Thu, 2 Nov 2023 17:37:23 +0100 Subject: [PATCH 1/3] update montue case --- criteriaModel/criteria1DCase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/criteriaModel/criteria1DCase.cpp b/criteriaModel/criteria1DCase.cpp index b2365d6a..d4f9aa6b 100644 --- a/criteriaModel/criteria1DCase.cpp +++ b/criteriaModel/criteria1DCase.cpp @@ -557,7 +557,6 @@ bool Crit1DCase::computeDailyModel(Crit3DDate &myDate, std::string &error) rootDensityMax = std::max(rootDensityMax, crop.roots.rootDensity[l]); } - // TODO add crop.roots.tensileStrength for (unsigned int l = 1; l < nrLayers; l++) { double rootDensityNorm; From 00561dbecde6003865cb11d998858f8b33d9b69e Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 15 Nov 2023 17:03:31 +0100 Subject: [PATCH 2/3] fix new soil --- soil/soilDbTools.cpp | 35 ++++++++++++++++++++++------------- soilWidget/soilWidget.cpp | 7 ++----- soilWidget/tabHorizons.cpp | 11 +++++------ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/soil/soilDbTools.cpp b/soil/soilDbTools.cpp index f891be4a..593c4b56 100644 --- a/soil/soilDbTools.cpp +++ b/soil/soilDbTools.cpp @@ -234,17 +234,18 @@ bool loadSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Cri { if (query.lastError().type() != QSqlError::NoError) { - errorStr = "dbSoil error: "+ query.lastError().text(); + errorStr = "dbSoil error: "+ query.lastError().text(); + return false; } else { - errorStr = "Soil " + soilCode + " is missing, check soil_code in dbSoil."; + // soil has no horizons + mySoil.initialize(soilCode.toStdString(), 0); + return true; } - return false; } int nrHorizons = query.at() + 1; // SQLITE doesn't support SIZE - mySoil.initialize(soilCode.toStdString(), nrHorizons); unsigned int i = 0; @@ -376,17 +377,25 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS } } - // error on the last horizon is tolerated (bedrock) - unsigned int lastHorizonIndex = mySoil.nrHorizons -1; - if (firstWrongIndex != NODATA) + // check total depth + // errors on the last horizon is tolerated (bedrock) + if (mySoil.nrHorizons > 0) { - if (mySoil.nrHorizons == 1) - return false; - else - lastHorizonIndex = firstWrongIndex-1; - } + int lastHorizonIndex = mySoil.nrHorizons-1; + if (firstWrongIndex != NODATA) + { + if (mySoil.nrHorizons == 1) + return false; + else + lastHorizonIndex = firstWrongIndex-1; + } - mySoil.totalDepth = mySoil.horizon[lastHorizonIndex].lowerDepth; + mySoil.totalDepth = mySoil.horizon[lastHorizonIndex].lowerDepth; + } + else + { + mySoil.totalDepth = 0; + } return true; } diff --git a/soilWidget/soilWidget.cpp b/soilWidget/soilWidget.cpp index a5acd8a0..e54cd7f4 100644 --- a/soilWidget/soilWidget.cpp +++ b/soilWidget/soilWidget.cpp @@ -386,7 +386,7 @@ void Crit3DSoilWidget::on_actionChooseSoil(QString soilCode) copyEstimatedParamTable->setEnabled(true); QString errorStr; - // somethig has been modified, ask for saving + // something has been modified, ask for saving if (changed) { QString soilCodeChanged = QString::fromStdString(mySoil.code); @@ -791,11 +791,11 @@ void Crit3DSoilWidget::setInfoTextural(int nHorizon) void Crit3DSoilWidget::tabChanged(int index) { - if (soilListComboBox.currentText().isEmpty()) { return; } + if (index == 0) { if (!horizonsTab->getInsertSoilElement()) @@ -809,9 +809,7 @@ void Crit3DSoilWidget::tabChanged(int index) else { horizonsTab->resetAll(); - horizonsTab->addRowClicked(); } - } } else if (index == 1) // tab water retention data @@ -829,7 +827,6 @@ void Crit3DSoilWidget::tabChanged(int index) wrDataTab->resetAll(); } } - } else if (index == 2) // tab water retention curve { diff --git a/soilWidget/tabHorizons.cpp b/soilWidget/tabHorizons.cpp index 31f426a2..ee1a686b 100644 --- a/soilWidget/tabHorizons.cpp +++ b/soilWidget/tabHorizons.cpp @@ -248,7 +248,6 @@ void TabHorizons::updateTableModel(soil::Crit3DSoil *soil) checkComputedValues(i); } } - } @@ -256,7 +255,7 @@ bool TabHorizons::checkDepths() { bool depthsOk = true; // reset background color - for (int horizonNum = 0; horizonNumrowCount(); horizonNum++) + for (int horizonNum = 0; horizonNum < tableDb->rowCount(); horizonNum++) { tableDb->item(horizonNum,0)->setBackground(Qt::white); tableDb->item(horizonNum,1)->setBackground(Qt::white); @@ -759,12 +758,11 @@ void TabHorizons::cellChanged(int row, int column) emit horizonSelected(row); emit updateSignal(); } - } + void TabHorizons::addRowClicked() { - tableDb->blockSignals(true); int numRow; @@ -793,12 +791,13 @@ void TabHorizons::addRowClicked() tableDb->insertRow(numRow); tableModel->insertRow(numRow); - for (int j=0; jcolumnCount(); j++) + for (int j=0; j < tableDb->columnCount(); j++) { tableDb->setItem(numRow, j, new QTableWidgetItem()); tableDb->item(numRow,j)->setTextAlignment(Qt::AlignRight); } - for (int j=0; jcolumnCount(); j++) + + for (int j=0; j < tableModel->columnCount(); j++) { tableModel->setItem(numRow, j, new QTableWidgetItem()); if (j>0) From 30086e7aa2be82fe2c057f44dd53d01b89895a6a Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 15 Nov 2023 19:41:25 +0100 Subject: [PATCH 3/3] update --- mathFunctions/physics.cpp | 12 +++++++----- soilFluxes3D/boundary.cpp | 18 +++++++++++++----- soilFluxes3D/header/boundary.h | 2 +- soilFluxes3D/soilFluxes3D.cpp | 10 ++++++++-- soilFluxes3D/water.cpp | 10 +++++----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/mathFunctions/physics.cpp b/mathFunctions/physics.cpp index 822e85e4..85d2d3f5 100644 --- a/mathFunctions/physics.cpp +++ b/mathFunctions/physics.cpp @@ -98,8 +98,8 @@ double vaporConcentrationFromPressure(double myPressure, double myT) double airVolumetricSpecificHeat(double myPressure, double myT) -{ // (J m-3 K-1) volumetric specific heat of air - +// (J m-3 K-1) volumetric specific heat of air +{ double myMolarDensity = airMolarDensity(myPressure, myT); // mol m-3 double mySpHeat = (HEAT_CAPACITY_AIR_MOLAR * myMolarDensity); return (mySpHeat); @@ -222,18 +222,20 @@ double aerodynamicConductance(double heightTemperature, H = K * Ch * (soilSurfaceTemperature - airTemperature); Sp = -VON_KARMAN_CONST * heightWind * GRAVITY * H / (Ch * airTemperature * (pow(uStar, 3))); if (Sp > 0) - {// stability + { + // stability psiH = 6 * log(1 + Sp); psiM = psiH; } else - {// unstability + { + // unstability psiH = -2 * log((1 + sqrt(1 - 16 * Sp)) / 2); psiM = 0.6 * psiH; } } - return (K); + return K; } diff --git a/soilFluxes3D/boundary.cpp b/soilFluxes3D/boundary.cpp index 9e8a1483..178d7067 100644 --- a/soilFluxes3D/boundary.cpp +++ b/soilFluxes3D/boundary.cpp @@ -200,12 +200,16 @@ double getSurfaceWaterFraction(int i) } } -void updateBoundary() +void updateConductance() { - for (long i = 0; i < myStructure.nrNodes; i++) - if (myNode[i].boundary != nullptr) - if (myStructure.computeHeat) + if (myStructure.computeHeat) + { + for (long i = 0; i < myStructure.nrNodes; i++) + { + if (myNode[i].boundary != nullptr) + { if (myNode[i].extra->Heat != nullptr) + { if (myNode[i].boundary->type == BOUNDARY_HEAT_SURFACE) { // update aerodynamic conductance @@ -218,12 +222,16 @@ void updateBoundary() myNode[i].boundary->Heat->windSpeed); if (myStructure.computeWater) - // update soil surface conductance { + // update soil surface conductance double theta = theta_from_sign_Psi(myNode[i].H - myNode[i].z, i); myNode[i].boundary->Heat->soilConductance = 1./ computeSoilSurfaceResistance(theta); } } + } + } + } + } } diff --git a/soilFluxes3D/header/boundary.h b/soilFluxes3D/header/boundary.h index 17fb93a3..f58d86fb 100644 --- a/soilFluxes3D/header/boundary.h +++ b/soilFluxes3D/header/boundary.h @@ -3,7 +3,7 @@ struct Tboundary; - void updateBoundary(); + void updateConductance(); void updateBoundaryHeat(); void updateBoundaryWater(double deltaT); void initializeBoundary(Tboundary *myBoundary, int myType, float slope, float boundaryArea); diff --git a/soilFluxes3D/soilFluxes3D.cpp b/soilFluxes3D/soilFluxes3D.cpp index cdc59337..84338497 100644 --- a/soilFluxes3D/soilFluxes3D.cpp +++ b/soilFluxes3D/soilFluxes3D.cpp @@ -815,8 +815,11 @@ int DLL_EXPORT __STDCALL setHydraulicProperties(int waterRetentionCurve, InitializeBalanceWater(); if (myStructure.computeHeat) initializeBalanceHeat(); + else + balanceWholePeriod.heatMBR = 1.; } + double DLL_EXPORT __STDCALL getWaterMBR() { return (balanceWholePeriod.waterMBR); @@ -901,8 +904,11 @@ double DLL_EXPORT __STDCALL computeStep(double maxTime) { double dtWater, dtHeat; - if (myStructure.computeHeat) initializeHeatFluxes(false, true); - updateBoundary(); + if (myStructure.computeHeat) + { + initializeHeatFluxes(false, true); + updateConductance(); + } if (myStructure.computeWater) computeWater(maxTime, &dtWater); diff --git a/soilFluxes3D/water.cpp b/soilFluxes3D/water.cpp index 1d30fb8e..5b781c97 100644 --- a/soilFluxes3D/water.cpp +++ b/soilFluxes3D/water.cpp @@ -347,10 +347,10 @@ bool computeWater(double maxTime, double *acceptedTime) /*! save the instantaneous H values - Prepare the solutions vector (X = H) */ for (long n = 0; n < myStructure.nrNodes; n++) - { - myNode[n].oldH = myNode[n].H; - X[n] = myNode[n].H; - } + { + myNode[n].oldH = myNode[n].H; + X[n] = myNode[n].H; + } /*! assign Theta_e for the surface nodes C = area */ @@ -363,7 +363,7 @@ bool computeWater(double maxTime, double *acceptedTime) } /*! update boundary conditions */ - updateBoundary(); + updateConductance(); updateBoundaryWater(*acceptedTime); isStepOK = waterFlowComputation(*acceptedTime);