libROM  v1.0
Data-driven physical simulation library
Public Types | Public Member Functions | List of all members
CAROM::Database Class Referenceabstract

#include <Database.h>

Inheritance diagram for CAROM::Database:
CAROM::CSVDatabase CAROM::HDFDatabase CAROM::HDFDatabaseMPIO

Public Types

enum class  formats { HDF5 , CSV , HDF5_MPIO }
 Implemented database file formats. Add to this enum each time a new database format is implemented.
 

Public Member Functions

 Database ()
 Default constructor.
 
virtual ~Database ()
 Destructor.
 
virtual bool create (const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL)
 Creates a new database file with the supplied name. More...
 
virtual bool open (const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL)
 Opens an existing database file with the supplied name. More...
 
virtual bool close ()=0
 Closes the currently open database file. More...
 
void putInteger (const std::string &key, int data)
 Writes an integer associated with the supplied key to currently open database file. More...
 
virtual void putIntegerArray (const std::string &key, const int *const data, int nelements, const bool distributed=false)=0
 Writes an array of integers associated with the supplied key to the currently open database file. More...
 
void putDouble (const std::string &key, double data)
 Writes a double associated with the supplied key to currently open database file. More...
 
virtual void putDoubleArray (const std::string &key, const double *const data, int nelements, const bool distributed=false)=0
 Writes an array of doubles associated with the supplied key to the currently open database file. More...
 
virtual void putDoubleVector (const std::string &key, const std::vector< double > &data, int nelements, const bool distributed=false)=0
 Writes a vector of doubles associated with the supplied key to the currently open database file. More...
 
void getInteger (const std::string &key, int &data)
 Reads an integer associated with the supplied key from the currently open database file. More...
 
virtual void getIntegerArray (const std::string &key, int *data, int nelements, const bool distributed=false)=0
 Reads an array of integers associated with the supplied key from the currently open database file. More...
 
void getDouble (const std::string &key, double &data)
 Reads a double associated with the supplied key from the currently open database file. More...
 
virtual int getDoubleArraySize (const std::string &key)=0
 Count the number of elements in an array of doubles associated with the supplied key from the currently open database file. More...
 
virtual void getDoubleArray (const std::string &key, double *data, int nelements, const bool distributed=false)=0
 Reads an array of doubles associated with the supplied key from the currently open database file. More...
 
virtual void getDoubleArray (const std::string &key, double *data, int nelements, const std::vector< int > &idx, const bool distributed=false)=0
 Reads a sub-array of doubles associated with the supplied key from the currently open database file. More...
 
virtual void getDoubleArray (const std::string &key, double *data, int nelements, int offset, int block_size, int stride, const bool distributed=false)=0
 Reads an array of doubles associated with the supplied key from the currently open database file. More...
 

Detailed Description

Class Database is an abstract base class that provides basic ability to write to and read from a file. It's capabilities are limited to what the SVD algorithm needs to read and write its basis vectors.

Definition at line 30 of file Database.h.

Member Function Documentation

◆ close()

virtual bool CAROM::Database::close ( )
pure virtual

Closes the currently open database file.

Returns
True if the file close was successful.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ create()

bool CAROM::Database::create ( const std::string &  file_name,
const MPI_Comm  comm = MPI_COMM_NULL 
)
virtual

Creates a new database file with the supplied name.

Parameters
[in]file_nameName of database file to create.
[in]commMPI communicator for distributed data I/O. If MPI_COMM_NULL, the file will be created serially. The behavior for distributed I/O will vary by classes.
Returns
True if file create was successful.

Reimplemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

Definition at line 35 of file Database.cpp.

◆ getDouble()

void CAROM::Database::getDouble ( const std::string &  key,
double &  data 
)
inline

Reads a double associated with the supplied key from the currently open database file.

Parameters
[in]keyThe key associated with the value to be read.
[out]dataThe double value read.

Definition at line 216 of file Database.h.

◆ getDoubleArray() [1/3]

virtual void CAROM::Database::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
const bool  distributed = false 
)
pure virtual

Reads an array of doubles associated with the supplied key from the currently open database file.

Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of double values to be read.
[in]nelementsThe number of doubles in the array.
[in]distributedIf true, distributed double array will be read. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ getDoubleArray() [2/3]

virtual void CAROM::Database::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
const std::vector< int > &  idx,
const bool  distributed = false 
)
pure virtual

Reads a sub-array of doubles associated with the supplied key from the currently open database file.

Precondition
!key.empty()
data != nullptr || nelements == 0
Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated sub-array of double values to be read.
[in]nelementsThe number of doubles in the full array.
[in]idxThe set of indices in the sub-array.
[in]distributedIf true, distributed double array will be read. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ getDoubleArray() [3/3]

virtual void CAROM::Database::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
int  offset,
int  block_size,
int  stride,
const bool  distributed = false 
)
pure virtual

Reads an array of doubles associated with the supplied key from the currently open database file.

Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of double values to be read.
[in]nelementsThe number of doubles in the array.
[in]offsetThe initial offset in the array. Typically, this is a zero-based column index of the matrix data.
[in]block_sizeThe block size to read from the HDF5 dataset. Typically, this is a number of columns of the matrix data.
[in]strideThe stride to read from the HDF5 dataset. Typically, this is the total number of columns of the matrix data.
[in]distributedIf true, distributed double array will be read. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ getDoubleArraySize()

virtual int CAROM::Database::getDoubleArraySize ( const std::string &  key)
pure virtual

Count the number of elements in an array of doubles associated with the supplied key from the currently open database file.

Precondition
!key.empty()
Parameters
[in]keyThe key associated with the array of values to be read.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ getInteger()

void CAROM::Database::getInteger ( const std::string &  key,
int &  data 
)
inline

Reads an integer associated with the supplied key from the currently open database file.

Parameters
[in]keyThe key associated with the value to be read.
[out]dataThe integer value read.

Definition at line 182 of file Database.h.

◆ getIntegerArray()

virtual void CAROM::Database::getIntegerArray ( const std::string &  key,
int *  data,
int  nelements,
const bool  distributed = false 
)
pure virtual

Reads an array of integers associated with the supplied key from the currently open database file.

Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of integer values to be read.
[in]nelementsThe number of integers in the array.
[in]distributedIf true, distributed integer array will be read. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ open()

bool CAROM::Database::open ( const std::string &  file_name,
const std::string &  type,
const MPI_Comm  comm = MPI_COMM_NULL 
)
virtual

Opens an existing database file with the supplied name.

Parameters
[in]file_nameName of existing database file to open.
[in]typeRead/write type ("r"/"wr")
[in]commMPI communicator for distributed data I/O. If MPI_COMM_NULL, the file will be opened serially. The behavior for distributed I/O will vary by classes.
Returns
True if file open was successful.

Reimplemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

Definition at line 44 of file Database.cpp.

◆ putDouble()

void CAROM::Database::putDouble ( const std::string &  key,
double  data 
)
inline

Writes a double associated with the supplied key to currently open database file.

Parameters
[in]keyThe key associated with the value to be written.
[in]dataThe double value to be written.

Definition at line 129 of file Database.h.

◆ putDoubleArray()

virtual void CAROM::Database::putDoubleArray ( const std::string &  key,
const double *const  data,
int  nelements,
const bool  distributed = false 
)
pure virtual

Writes an array of doubles associated with the supplied key to the currently open database file.

Parameters
[in]keyThe key associated with the array of values to be written.
[in]dataThe array of double values to be written.
[in]nelementsThe number of doubles in the array.
[in]distributedIf true, distributed double array will be written. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ putDoubleVector()

virtual void CAROM::Database::putDoubleVector ( const std::string &  key,
const std::vector< double > &  data,
int  nelements,
const bool  distributed = false 
)
pure virtual

Writes a vector of doubles associated with the supplied key to the currently open database file.

Parameters
[in]keyThe key associated with the vector of values to be written.
[in]dataThe vector of double values to be written.
[in]nelementsThe number of doubles in the vector.
[in]distributedIf true, distributed double vector will be written. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.

◆ putInteger()

void CAROM::Database::putInteger ( const std::string &  key,
int  data 
)
inline

Writes an integer associated with the supplied key to currently open database file.

Parameters
[in]keyThe key associated with the value to be written.
[in]dataThe integer value to be written.

Definition at line 95 of file Database.h.

◆ putIntegerArray()

virtual void CAROM::Database::putIntegerArray ( const std::string &  key,
const int *const  data,
int  nelements,
const bool  distributed = false 
)
pure virtual

Writes an array of integers associated with the supplied key to the currently open database file.

Parameters
[in]keyThe key associated with the array of values to be written.
[in]dataThe array of integer values to be written.
[in]nelementsThe number of integers in the array.
[in]distributedIf true, distributed integer array will be written. the distributed I/O behavior varies with classes.

Implemented in CAROM::HDFDatabase, and CAROM::CSVDatabase.


The documentation for this class was generated from the following files: