Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 62 additions & 30 deletions src/bmi_soil_freeze_thaw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,33 @@ Finalize()
int BmiSoilFreezeThaw::
GetVarGrid(std::string name)
{
if (name.compare("num_cells") == 0
|| name.compare("ice_fraction_scheme_bmi") == 0
|| name.compare("serialization_free") == 0)
if (name.compare("num_cells") == 0 ||
name.compare("ice_fraction_scheme_bmi") == 0 ||
name.compare("serialization_free") == 0)
return 0; // int
else if (name.compare("ground_temperature") == 0 || name.compare("ice_fraction_schaake") == 0
|| name.compare("ice_fraction_xinanjiang") == 0 || name.compare("soil_ice_fraction") == 0
|| name.compare("ground_heat_flux") == 0 || name.compare("smcmax") == 0
|| name.compare("b") == 0 || name.compare("satpsi") == 0
|| name == "reset_time")
else if (name.compare("ground_temperature") == 0 ||
name.compare("ice_fraction_schaake") == 0 ||
name.compare("ice_fraction_xinanjiang") == 0 ||
name.compare("soil_ice_fraction") == 0 ||
name.compare("ground_heat_flux") == 0 ||
name.compare("smcmax") == 0 ||
name.compare("b") == 0 ||
name.compare("satpsi") == 0 ||
name.compare("quartz") == 0 ||
name == "reset_time")
return 1; //double
else if (name.compare("soil_moisture_profile") == 0 || name.compare("soil_temperature_profile") == 0)
else if (name.compare("soil_moisture_profile") == 0 ||
name.compare("soil_temperature_profile") == 0)
return 2; // arrays
else if (name.compare("serialization_state") == 0)
return 3; // char
else if (name.compare("serialization_create") == 0
|| name.compare("serialization_size") == 0)
else if (name.compare("serialization_create") == 0 ||
name.compare("serialization_size") == 0)
return 4; // unit64_t
else
return -1;
}


std::string BmiSoilFreezeThaw::
GetVarType(std::string name)
{
Expand All @@ -130,8 +135,11 @@ GetVarType(std::string name)
return "char";
else if (grid_id == 4)
return "uint64_t";
else
return "";
else {
std::string errMsg = "Variable " + name + " does not exist";
LOG(LogLevel::FATAL, errMsg);
throw std::runtime_error(errMsg);
}
}


Expand Down Expand Up @@ -164,8 +172,14 @@ GetVarUnits(std::string name)
else if (name.compare("ice_fraction_schaake") == 0 ||
name.compare("ice_fraction_xinanjiang") == 0 ||
name.compare("soil_ice_fraction") == 0 ||
name.compare("soil_moisture_profile") == 0)
name.compare("soil_moisture_profile") == 0 ||
name.compare("ice_fraction_scheme_bmi") == 0 ||
name.compare("smcmax") == 0 ||
name.compare("b") == 0 ||
name.compare("quartz") == 0)
return "1"; // UDUNITS dimensionless
else if (name.compare("satpsi") == 0)
return "m";
else
return "none";
}
Expand All @@ -189,15 +203,26 @@ GetVarLocation(std::string name)
{
if (name.compare("ground_temperature") == 0)
return "node";
else if (name.compare("ice_fraction_xinanjiang") == 0 || name.compare("soil_ice_fraction") == 0)
else if (name.compare("ice_fraction_xinanjiang") == 0 ||
name.compare("soil_ice_fraction") == 0)
return "node";
else if (name.compare("ice_fraction_schaake") == 0 || name.compare("num_cells") == 0
|| name.compare("ground_heat_flux") == 0)
else if (name.compare("ice_fraction_schaake") == 0 ||
name.compare("num_cells") == 0 ||
name.compare("ground_heat_flux") == 0 ||
name.compare("ice_fraction_scheme_bmi") == 0 ||
name.compare("smcmax") == 0 ||
name.compare("b") == 0 ||
name.compare("satpsi") == 0 ||
name.compare("quartz") == 0)
return "node";
else if (name.compare("soil_moisture_profile") == 0 || name.compare("soil_temperature_profile") == 0)
else if (name.compare("soil_moisture_profile") == 0 ||
name.compare("soil_temperature_profile") == 0)
return "node";
else
return "";
else {
std::string errMsg = "Variable " + name + " does not exist";
LOG(LogLevel::FATAL, errMsg);
throw std::runtime_error(errMsg);
}
}


Expand All @@ -213,7 +238,7 @@ GetGridShape(const int grid, int *shape)
void BmiSoilFreezeThaw::
GetGridSpacing (const int grid, double * spacing)
{
if (grid == 0) {
if (grid == 2) {
spacing[0] = this->state->spacing[0];
}
}
Expand All @@ -222,7 +247,7 @@ GetGridSpacing (const int grid, double * spacing)
void BmiSoilFreezeThaw::
GetGridOrigin (const int grid, double *origin)
{
if (grid == 0) {
if (grid == 2) {
origin[0] = this->state->origin[0];
}
}
Expand All @@ -231,7 +256,9 @@ GetGridOrigin (const int grid, double *origin)
int BmiSoilFreezeThaw::
GetGridRank(const int grid)
{
if (grid == 0 || grid == 1 || grid == 2)
if (grid == 0 || grid == 1 || grid == 3 || grid == 4)
return 0;
else if (grid == 2)
return 1;
else
return -1;
Expand All @@ -253,17 +280,20 @@ GetGridSize(const int grid)
return -1;
}


std::string BmiSoilFreezeThaw::
GetGridType(const int grid)
{
if (grid == 0)
if (grid == 0 || grid == 1 || grid == 3 || grid == 4)
return "scalar";
else if (grid == 2)
return "uniform_rectilinear";
else
return "";
else {
std::string errMsg = "Grid " + std::to_string(grid) + " does not exist";
LOG(LogLevel::FATAL, errMsg);
throw std::runtime_error(errMsg);
}
}


void BmiSoilFreezeThaw::
GetGridX(const int grid, double *x)
{
Expand Down Expand Up @@ -291,7 +321,7 @@ GetGridZ(const int grid, double *z)
int BmiSoilFreezeThaw::
GetGridNodeCount(const int grid)
{
if (grid == 0)
if (grid == 2)
return this->state->shape[0];
else
return -1;
Expand Down Expand Up @@ -342,6 +372,8 @@ GetValuePtr (std::string name)
return (void*)(&this->state->b);
else if (name.compare("satpsi") == 0)
return (void*)(&this->state->satpsi);
else if (name.compare("quartz") == 0)
return (void*)(&this->state->quartz);
else if (name.compare("serialization_state") == 0)
return (void*)(this->m_serialized_vec.data());
else if (name.compare("serialization_size") == 0) {
Expand Down
51 changes: 15 additions & 36 deletions tests/main_unittest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -447,22 +447,12 @@ int main(int argc, char *argv[])
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// compare benchmark value with bmi GetValue
if (var_name == "soil_moisture_profile") {
bool check = false;
for (int i1 =0; i1 < nz; i1++) {
assert (fabs(var[i] - soil_moisture_profile[i]) < 0.001);
check=true;
}
if (check)
test_status &= true;
else {
test_status &= false;
std::string passed = test_status == true ? "Yes" : "No";
std::cout<<"Test passed: "<<passed<<"\n";
std::stringstream errMsg;
errMsg << "Soil moisture should be: "<<soil_moisture_profile[0]<<" "<<soil_moisture_profile[1]<<" "
<<soil_moisture_profile[2]<<" "<<soil_moisture_profile[3]<<"\n";
throw std::runtime_error(errMsg.str());
}
bool check = false;
for (int i1 = 0; i1 < nz; i1++) {
assert(fabs(var[i1] - soil_moisture_profile[i1]) < 0.001);
check = fabs(var[i1] - soil_moisture_profile[i1]) < 0.001;
}
test_status &= check;
}
else if (var_name == "ground_temperature") {
// Go ahead and test set_value_*() for last time step here
Expand Down Expand Up @@ -532,27 +522,16 @@ int main(int argc, char *argv[])
test_status &= false;
}
else if (var_name.compare("soil_temperature_profile") == 0) {
double *var = new double[nz];
model.GetValue(var_name, &(var[0]));
bool check = false;
for (int i1 =0; i1 < nz; i1++) {
assert (fabs(var[i] - soil_T[i]) < 0.001);
check=true;
}
delete [] var;
if (check)
test_status &= true;
else {
test_status &= false;
std::string passed = test_status == true ? "Yes" : "No";
std::cout<<"Test passed: "<<passed<<"\n";
std::stringstream errMsg;
errMsg << "Soil temperature should be: "<<soil_T[0]<<" "<<soil_T[1]<<" "
<<soil_T[2]<<" "<<soil_T[3]<<"\n";
throw std::runtime_error(errMsg.str());
}
double *var = new double[nz];
model.GetValue(var_name, &(var[0]));
bool check = false;
for (int i1 = 0; i1 < nz; i1++) {
assert(fabs(var[i1] - soil_T[i1]) < 0.001);
check = fabs(var[i1] - soil_T[i1]) < 0.001;
}
delete [] var;
test_status &= check;
}

}


Expand Down
42 changes: 38 additions & 4 deletions tests/run_unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,42 @@ if [ ! -d "${EWTS_LIB_DIR}" ] && [ -d "${EWTS_PREFIX}/lib64" ]; then
EWTS_LIB_DIR="${EWTS_PREFIX}/lib64"
fi

${CXX:-g++} -std=c++17 -Wall -O -g \
./main_unittest.cxx \
../src/bmi_soil_freeze_thaw.cxx \
../src/soil_freeze_thaw.cxx \
${CXX:-g++} -Og -std=c++17 -Wall \
-DBMI_ACTIVE \
-DEWTS_HAVE_NGEN_BRIDGE \
-I../include \
-I../bmi \
-I"${EWTS_PREFIX}/include" \
-c ./main_unittest.cxx \
-o main_unittest.o

${CXX:-g++} -Og -std=c++17 -Wall \
-DBMI_ACTIVE \
-DEWTS_HAVE_NGEN_BRIDGE \
-I../include \
-I../bmi \
-I"${EWTS_PREFIX}/include" \
-c ../src/bmi_soil_freeze_thaw.cxx \
-o bmi_soil_freeze_thaw.o

${CXX:-g++} -Og -std=c++17 -Wall \
-DBMI_ACTIVE \
-DEWTS_HAVE_NGEN_BRIDGE \
-I../include \
-I../bmi \
-I"${EWTS_PREFIX}/include" \
-c ../src/soil_freeze_thaw.cxx \
-o soil_freeze_thaw.o

${CXX:-g++} \
main_unittest.o \
bmi_soil_freeze_thaw.o \
soil_freeze_thaw.o \
-L"${EWTS_LIB_DIR}" \
-Wl,-rpath,"${EWTS_LIB_DIR}" \
-Wl,--no-as-needed \
-lewts_ngen_bridge \
-Wl,--as-needed \
-lewts_cpp \
-lboost_serialization \
-lm \
Expand All @@ -25,7 +52,14 @@ ${CXX:-g++} -std=c++17 -Wall -O -g \
./run_sft configs/unittest.txt
test_pass=$?

rm -f main_unittest.o bmi_soil_freeze_thaw.o soil_freeze_thaw.o
rm -f run_sft
rm -rf run_sft.dSYM

if [ "$test_pass" -eq 0 ]; then
echo "SFT BMI unit test passed"
else
echo "SFT BMI unit test failed with exit code ${test_pass}"
fi

exit $test_pass