Skip to content

Commit 6d3eb37

Browse files
authored
Merge pull request #41 from dvalters/restart-water
Initialise water depths from pre-existing water depth raster file
2 parents d856fa9 + 533e023 commit 6d3eb37

File tree

7 files changed

+1181
-1
lines changed

7 files changed

+1181
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TARGET := bin/HAIL-CAESAR.exe
88
SRCEXT := cpp
99
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
1010
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
11-
CFLAGS := -g -std=c++11 -Wall -DOMP_COMPILE_FOR_PARALLEL -fopenmp $(GITREV)# -Wall #-DDEBUG
11+
CFLAGS := -g -std=c++11 -fopenmp $(GITREV) -DOMP_COMPILE_FOR_PARALLEL #-Wall -DDEBUG
1212
LIB := -fopenmp
1313
INC := -I include
1414

include/catchmentmodel/LSDCatchmentModel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ class LSDCatchmentModel: public LSDRaster
696696

697697
bool soil_j_mean_depends_on = false;
698698
bool rainfall_data_on = false;
699+
bool water_init_from_raster = false;
699700
bool hydro_only = false;
700701
bool vegetation_on = false;
701702
bool bedrock_layer_on = false;
@@ -720,6 +721,7 @@ class LSDCatchmentModel: public LSDRaster
720721
std::string rainfall_data_file = "";
721722
std::string grain_data_file = "";
722723
std::string bedrock_data_file = "";
724+
std::string water_init_raster_file = "";
723725

724726
/// output file names
725727
std::string elev_fname = "";

src/catchmentmodel/LSDCatchmentModel.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ void LSDCatchmentModel::load_data()
143143
LSDRaster elevR;
144144
/// Hydroindex LSDRaster: tells rainfall input where to be distributed
145145
LSDRaster hydroindexR;
146+
/// Holds the initial water depths if oading from file
147+
LSDRaster waterinitR;
146148
/// Bedrock LSDRaster object
147149
LSDRaster bedrockR;
148150
std::string DEM_FILENAME = read_path + "/" + read_fname + "." \
@@ -276,6 +278,52 @@ void LSDCatchmentModel::load_data()
276278
}
277279
}
278280

281+
// LOAD THE WATERDEPTHS FILE
282+
if (water_init_from_raster==true)
283+
{
284+
std::string WATER_INIT_RASTER_FILENAME = read_path + "/" + water_init_raster_file;
285+
// Check for the file first of all
286+
if (!does_file_exist(WATER_INIT_RASTER_FILENAME))
287+
{
288+
std::cout << "No surface water level initialisation DEM found by name of: "
289+
<< WATER_INIT_RASTER_FILENAME
290+
<< std::endl
291+
<< "You specified to intialise the model with initial water depths, \
292+
\n but no matching water DEM file was found. Try again." << std::endl;
293+
exit(EXIT_FAILURE);
294+
}
295+
try
296+
{
297+
waterinitR.read_ascii_raster(WATER_INIT_RASTER_FILENAME);
298+
// Load the raw ascii raster data
299+
TNT::Array2D<double> waterinit_raw = waterinitR.get_RasterData_dbl();
300+
std::cout << "The water depth initialisation file: " << WATER_INIT_RASTER_FILENAME
301+
<< " was successfully read." << std::endl;
302+
303+
// We want an edge pixel of zeros surrounding the raster data
304+
// So start the counters at one, rather than zero, this
305+
// will ensure that elev[0][n] is not written to and left set to zero.
306+
// remember this data member is set with dim size equal to jmax + 2 to
307+
// allow the border of zeros
308+
for (unsigned i=0; i<imax; i++)
309+
{
310+
for (unsigned j=0; j<jmax; j++)
311+
{
312+
water_depth[i+1][j+1] = waterinit_raw[i][j];
313+
}
314+
}
315+
}
316+
catch (...)
317+
{
318+
std::cout << "Something is wrong with your water initialisation file." << std::endl
319+
<< "Common causes are: " << std::endl
320+
<< "1) Data type is not correct" <<
321+
std::endl << "2) Non standard ASCII data format" << std::endl;
322+
exit(EXIT_FAILURE);
323+
}
324+
}
325+
326+
279327
// Load the RAINDATA file
280328
// Remember the format is not the same as a standard ASCII DEM...
281329
if (rainfall_data_on==true)
@@ -659,6 +707,15 @@ void LSDCatchmentModel::initialise_variables(std::string pname,
659707
RemoveControlCharactersFromEndOfString(bedrock_data_file);
660708
std::cout << "bedrock data file: " << bedrock_data_file << std::endl;
661709
}
710+
else if (lower == "water_init_raster_file")
711+
{
712+
std::cout << value << "VALUE " << lower << "LOWER";
713+
water_init_raster_file = value;
714+
RemoveControlCharactersFromEndOfString(water_init_raster_file);
715+
std::cout << "water depth initialistion file: " << water_init_raster_file << std::endl;
716+
}
717+
718+
662719

663720
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
664721
// Numerical
@@ -935,6 +992,12 @@ void LSDCatchmentModel::initialise_variables(std::string pname,
935992
std::cout << "rainfall_data_on: " << rainfall_data_on << std::endl;
936993
}
937994

995+
else if (lower == "water_init_from_raster_on")
996+
{
997+
water_init_from_raster = (value == "yes") ? true : false;
998+
std::cout << "Initialise the water depths from raster file: " << water_init_from_raster << std::endl;
999+
}
1000+
9381001
else if (lower == "topmodel_m_value")
9391002
{
9401003
M = atof(value.c_str());

0 commit comments

Comments
 (0)