I/O

namespace io
class BathymetryLoader
#include <BathymetryLoader.h>

Public Functions

~BathymetryLoader()

Destructor

Author

Luca-Philipp Grumbach

Author

Richard Hofmann

Description

Loads bathymetry data from files

void loadBathymetry(const std::string &i_file)

Load the bathymetry data from a file

Parameters:

i_file – bathymetry file path

inline t_real getBathymetry(t_real i_x, t_real i_y)

Gets the bathymetry at a given point.

Parameters:
  • i_x – point coordinate in x-direction

  • i_y – point coordinate in y-direction

Returns:

bathymetry at given point

Private Members

t_real *m_b = nullptr

bathymetry

t_real m_sizeX = 0

domain size in metres in x-direction

t_real m_sizeY = 0

domain size in metres in y-direction

class Csv
#include <Csv.h>

Public Static Functions

static void write(t_real i_dx, t_real i_dy, t_idx i_nx, t_idx i_ny, t_idx i_stride, t_real const *i_h, t_real const *i_hu, t_real const *i_hv, t_real const *i_b, std::ostream &io_stream)

Writes the data as CSV to the given stream.

Author

Luca-Philipp Grumbach

Author

Richard Hofmann

Description

IO-routines for writing a snapshot as Comma Separated Values (CSV).

Parameters:
  • i_dx – cell width in x-direction.

  • i_dy – cell width in y-direction.

  • i_nx – number of cells in x-direction.

  • i_ny – number of cells in y-direction.

  • i_stride – stride of the data arrays in y-direction (x is assumed to be stride-1).

  • i_h – water height of the cells; optional: use nullptr if not required.

  • i_hu – momentum in x-direction of the cells; optional: use nullptr if not required.

  • i_hv – momentum in y-direction of the cells; optional: use nullptr if not required.

  • i_b – bathymetry; optional: use nullptr if not required.

  • io_stream – stream to which the CSV-data is written.

static void splitLine(std::stringstream line, char separator, std::vector<std::string> &valuesVector)

Splits a CSV-style line into a vector of strings.

Parameters:
  • line – input line as stringstream

  • separator – character which separates the words (will be used to split)

  • valuesVector – a vector of stringsto which the words of the csv line are written.

class Logger
#include <Logger.h>

Public Functions

Logger()
void log(std::string i_line)
void logError(std::string i_line)
void logWarning(std::string i_line)
void clear()
inline std::string getLog()
inline std::string getLastLine()

Private Members

std::string m_data
std::string m_lastLine
class NetCdf
#include <NetCdf.h>

Public Functions

NetCdf(t_idx i_nx, t_idx i_ny, t_idx i_nk, t_real i_simulationSizeX, t_real i_simulationSizeY, t_real i_offsetX, t_real i_offsetY, const char *i_netcdfOutputFile, const char *i_checkpointFile)

Constructor for initialization

Parameters:
  • i_nx – amount of cells in x-direction

  • i_ny – amount of cells in y-direction

  • i_nk – amount of cells in x- and y-direction whose output will be grouped together

  • i_simulationSizeX – simulation size in x-direction

  • i_simulationSizeY – simulation size in y-direction

  • i_offsetX – offset in x-direction

  • i_offsetY – offset in y-direction

  • i_netcdfOutputFile – path of the netcdf output file

  • i_checkpointFile – path of the checkpoint file

NetCdf(const char *i_netcdfOutputFile, const char *i_checkpointFile)

Constructor for when we have a checkpoint file to read from

Parameters:
  • i_netcdfOutputFile – path of the netcdf output file

  • i_checkpointFile – path of the checkpoint file

~NetCdf()

Destructor

void write(t_idx i_stride, t_real const *i_h, t_real const *i_hu, t_real const *i_hv, t_real const *i_b, t_real i_t)

Writes data into netcdf file

Parameters:
  • i_stride – stride

  • i_h – water heights

  • i_hu – momentum x-direction

  • i_hv – momentum y-direction

  • i_b – bathymetry

  • i_t – current timestep

void writeCheckpoint(const char *i_checkpointFile, t_idx i_stride, t_real const *i_h, t_real const *i_hu, t_real const *i_hv, t_real const *i_b, t_real i_t, t_real i_timeStep)

Writes checkpoint data to a file.

Parameters:
  • i_checkpointFile – path of the checkpoint file

  • i_stride – stride

  • i_h – water heights

  • i_hu – momentum x-direction

  • i_hv – momentum y-direction

  • i_b – bathymetry

  • i_t – simulation time

  • i_timeStep – timestep

void loadCheckpointDimensions(const char *i_checkpointFile, t_idx &o_nx, t_idx &o_ny, t_idx &o_nk, t_real &o_simulationSizeX, t_real &o_simulationSizeY, t_real &o_offsetX, t_real &o_offsetY, t_real &o_t, t_idx &o_timeStep)

Loads checkpoint data from a file.

Parameters:
  • i_checkpointFile – path of the checkpoint file

  • o_nx – amount of cells in x-direction

  • o_ny – amount of cells in y-direction

  • o_nk – amount of cells in x- and y-direction whose output will be grouped together

  • o_simulationSizeX – simulation size in x-direction

  • o_simulationSizeY – simulation size in y-direction

  • o_offsetX – offset in x-direction

  • o_offsetY – offset in y-direction

  • o_t – simulation time

  • o_timeStep – timestep

void flush()

Public Static Functions

static void getDimensionSize(const char *i_file, const char *i_dimName, t_idx &o_n)

Gets the size of a dimension

Parameters:
  • i_file – path of the file to read from

  • i_dimName – name of the dimension

  • o_n – number of entries along that axis

static void read(const char *i_file, const char *i_var, t_real **o_xData, t_real **o_yData, t_real **o_data)

Reads from the cdf file.

Parameters:
  • i_file – path of the file to read from

  • i_var – variable to be read

  • o_xData – data of x dimension

  • o_yData – data of y dimension

  • o_data – output data

static void read(const char *i_file, const char *i_var, t_real **o_data)

Reads from the cdf file.

Parameters:
  • i_file – path of the file to read from

  • i_var – variable to be read

  • o_data – output data

Private Functions

void setUpFile(const char *i_file)

Sets up a netcdf file for writing.

Parameters:

i_file – path of the netcdf output file

void setUpCheckpointFile(const char *i_checkpointFile)

Sets up a netcdf file for checkpointing.

Parameters:

i_checkpointFile – path of the checkpoint file

void loadNetCdfIds()

Loads dimension and variable ids from an existing netcdf file.

Private Members

t_idx m_nx = 0
t_idx m_ny = 0
t_real m_simulationSizeX = 0
t_real m_simulationSizeY = 0
t_real m_offsetX = 0
t_real m_offsetY = 0
int m_err = 0
t_idx m_k = 0
t_idx m_nkx = 0
t_idx m_nky = 0
const char *m_netcdfOutputFile = nullptr
const char *m_checkpointFile = nullptr
bool m_hasCheckpointFileBeenSetup = false
bool m_doesSolutionExist = false
int m_ncId = 0
int m_dimXId = 0
int m_dimYId = 0
int m_dimTId = 0
int m_varXId = 0
int m_varYId = 0
int m_varTId = 0
int m_varHId = 0
int m_varTHId = 0
int m_varBId = 0
int m_varHuId = 0
int m_varHvId = 0
int m_ncCheckId = 0
int m_dimCheckXId = 0
int m_dimCheckYId = 0
int m_dimCheckTId = 0
int m_varCheckXId = 0
int m_varCheckYId = 0
int m_varCheckTId = 0
int m_varCheckHId = 0
int m_varCheckHuId = 0
int m_varCheckHvId = 0
int m_varCheckBId = 0
int m_varCheckTimeStepId = 0
int m_varCheckWritingStepsCountId = 0
int m_varCheckSimSizeXId = 0
int m_varCheckSimSizeYId = 0
int m_varCheckOffsetXId = 0
int m_varCheckOffsetYId = 0
int m_varCheckKId = 0
t_idx m_writingStepsCount = 0
bool m_outputFileOpened = false
class Station
#include <Station.h>

Public Functions

Station(t_real i_x, t_real i_y, std::string i_name, tsunami_lab::patches::WavePropagation *i_waveProp)

Constructor

Author

Luca-Philipp Grumbach

Author

Richard Hofmann

Description

A station which can capture data in a specified location on demand and also save it to a csv file

Parameters:
  • i_x – position in x-direction

  • i_y – position in y-direction

  • i_name – name the station

  • i_waveProp – active wave propagation patch

~Station()

Destructor

void capture(t_real i_time)

Captures data and stores it privately.

Parameters:

i_time – time of capture

void write()

Writes the stored data into a csv file.

inline std::vector<std::vector<tsunami_lab::t_real>> getData()

Gets the captured data.

Returns:

captured data as vector of vectors.

inline void setWaveProp(tsunami_lab::patches::WavePropagation *i_waveProp)

Sets the wave propagation object for the station.

Parameters:

i_waveProp – Pointer to the WavePropagation object.

Private Members

t_real m_x = 0

x-position

t_real m_y = 0

y-position

t_real m_stride = 0

stride

std::string m_name

name of the station

tsunami_lab::patches::WavePropagation *m_waveProp = nullptr

wave propagation object

std::string m_filepath = "stations"

filepath for captured data

std::vector<std::vector<tsunami_lab::t_real>> *m_data = nullptr

captured data