# PhasicFlow: src/phasicFlow/streams/dataIO/dataIO.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

dataIO.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __dataIO_hpp__
#define __dataIO_hpp__
#include <vector>
#include "span.hpp"
#include "IOPattern.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
#include "virtualConstructor.hpp"
#include "pFlowProcessors.hpp"
namespace pFlow
{
// - Forward
template<typename T>
bool writeDataAsciiBinary
(
iOstream& os,
span<T> data
);
template<typename T>
bool writeDataASCII
(
iOstream& os,
span<T> data
);
template<typename T>
bool readDataAscii
(
iIstream& is,
std::vector<T>& vec
);
template<typename T>
bool readDataAsciiBinary
(
iIstream& is,
std::vector<T>& data
);
template<typename T>
class dataIO
{
protected:
IOPattern ioPattern_;
std::vector<T> buffer_;
span<T> bufferSpan_;
virtual bool gatherData(span<T> data) = 0;
public:
TypeInfo("dataIO");
dataIO(const IOPattern& iop)
:
ioPattern_(iop)
{}
dataIO(const dataIO&) = default;
dataIO(dataIO &&) = default;
dataIO& operator = (const dataIO&) = default;
dataIO& operator = (dataIO&&) = default;
virtual ~dataIO() = default;
create_vCtor
(
dataIO,
IOPattern,
(const IOPattern& iop),
(iop)
);
bool writeData(iOstream& os, span<T> data);
bool readData(
iIstream& is,
std::vector<T>& data);
static
uniquePtr<dataIO> create(const IOPattern& iop);
};
template<typename T>
inline
iOstream& operator<<(iOstream& os, const span<T>& s)
{
if(!writeDataAsciiBinary(os, s))
{
ioErrorInFile(os.name(), os.lineNumber());
fatalExit;
}
return os;
}
}
#include "dataIO.cpp"
#endif
pFlow::span
Definition: span.hpp:31
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::writeDataAsciiBinary
bool writeDataAsciiBinary(iOstream &os, span< T > data)
Definition: dataIO.cpp:22
pFlow::dataIO::writeData
bool writeData(iOstream &os, span< T > data)
Write data to the end of file from all processors.
Definition: dataIO.cpp:193
iIstream.hpp
pFlow::dataIO::gatherData
virtual bool gatherData(span< T > data)=0
gather data from all processors and put the results in buffer_
pFlow::dataIO::create
static uniquePtr< dataIO > create(const IOPattern &iop)
Definition: dataIO.cpp:263
pFlow::dataIO
Definition: dataIO.hpp:67
pFlow::dataIO::TypeInfo
TypeInfo("dataIO")
Type info.
pFlow::dataIO::operator=
dataIO & operator=(const dataIO &)=default
pFlow::dataIO::dataIO
dataIO(const IOPattern &iop)
Definition: dataIO.hpp:86
pFlow
Definition: demGeometry.hpp:27
pFlow::writeDataASCII
bool writeDataASCII(iOstream &os, span< T > data)
Definition: dataIO.cpp:57
pFlow::dataIO::bufferSpan_
span< T > bufferSpan_
Definition: dataIO.hpp:75
pFlow::dataIO::ioPattern_
IOPattern ioPattern_
Definition: dataIO.hpp:71
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::readDataAsciiBinary
bool readDataAsciiBinary(iIstream &is, std::vector< T > &data)
Definition: dataIO.cpp:80
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::dataIO::buffer_
std::vector< T > buffer_
Definition: dataIO.hpp:73
pFlow::readDataAscii
bool readDataAscii(iIstream &is, std::vector< T > &vec)
Definition: dataIO.cpp:120
virtualConstructor.hpp
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::dataIO::~dataIO
virtual ~dataIO()=default
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
dataIO.cpp
IOPattern.hpp
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlowProcessors.hpp
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
iOstream.hpp
span.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::dataIO::create_vCtor
create_vCtor(dataIO, IOPattern,(const IOPattern &iop),(iop))
pFlow::dataIO::readData
bool readData(iIstream &is, std::vector< T > &data)
Definition: dataIO.cpp:245