mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Vector --> Container since we also read/write strings.
This commit is contained in:
parent
2520aab0a1
commit
61144a73af
@ -41,8 +41,9 @@ namespace Opm {
|
|||||||
stream.read( (char *) &value, sizeof( T ) );
|
stream.read( (char *) &value, sizeof( T ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write any container that provides a size method and a data method
|
||||||
template <class Vector>
|
template <class Vector>
|
||||||
void writeVector( std::ostream& stream, const Vector& vector)
|
void writeContainer( std::ostream& stream, const Vector& vector)
|
||||||
{
|
{
|
||||||
typedef typename Vector :: value_type T;
|
typedef typename Vector :: value_type T;
|
||||||
unsigned int size = vector.size() * sizeof( T );
|
unsigned int size = vector.size() * sizeof( T );
|
||||||
@ -52,6 +53,8 @@ namespace Opm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write map where the key is a std::string
|
||||||
|
// and the value is a std::vector or std::array
|
||||||
template <class Map>
|
template <class Map>
|
||||||
void writeMap( std::ostream& stream, const Map& m)
|
void writeMap( std::ostream& stream, const Map& m)
|
||||||
{
|
{
|
||||||
@ -62,55 +65,57 @@ namespace Opm {
|
|||||||
const auto& end = m.end();
|
const auto& end = m.end();
|
||||||
for(auto it = m.begin(); it != end; ++it )
|
for(auto it = m.begin(); it != end; ++it )
|
||||||
{
|
{
|
||||||
// write key
|
// write key (assume that key is a container)
|
||||||
writeVector( stream, (*it).first );
|
writeContainer( stream, (*it).first );
|
||||||
// write value
|
// write value (assume that value is a container)
|
||||||
writeVector( stream, (*it).second );
|
writeContainer( stream, (*it).second );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Vector>
|
template <class Container>
|
||||||
void resizeVector( Vector& vector, size_t size )
|
void resizeContainer( Container& container, size_t size )
|
||||||
{
|
{
|
||||||
vector.resize( size );
|
container.resize( size );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, unsigned long n>
|
template <class T, unsigned long n>
|
||||||
void resizeVector( std::array<T, n>& vector, size_t size )
|
void resizeContainer( std::array<T, n>& a, size_t size )
|
||||||
{
|
{
|
||||||
assert( int(size) == int(n) );
|
assert( int(size) == int(n) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Vector>
|
template <class Container>
|
||||||
void readVectorImpl( std::istream& stream, Vector& vector, const bool adjustSize )
|
void readContainerImpl( std::istream& stream, Container& container, const bool adjustSize )
|
||||||
{
|
{
|
||||||
typedef typename Vector :: value_type T;
|
typedef typename Container :: value_type T;
|
||||||
unsigned int dataSize = 0;
|
unsigned int dataSize = 0;
|
||||||
readValue( stream, dataSize );
|
readValue( stream, dataSize );
|
||||||
if( adjustSize && dataSize > 0 ) {
|
if( adjustSize && dataSize > 0 ) {
|
||||||
resizeVector( vector, dataSize/sizeof(T) );
|
resizeContainer( container, dataSize/sizeof(T) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( dataSize != vector.size() * sizeof( T ) )
|
if( dataSize != container.size() * sizeof( T ) )
|
||||||
{
|
{
|
||||||
OPM_THROW(std::logic_error,"Size of stored data and simulation data does not match" << dataSize << " " << (vector.size() * sizeof( T )) );
|
OPM_THROW(std::logic_error,
|
||||||
|
"Size of stored data and simulation data does not match"
|
||||||
|
<< dataSize << " " << (container.size() * sizeof( T )) );
|
||||||
}
|
}
|
||||||
if( dataSize > 0 ) {
|
if( dataSize > 0 ) {
|
||||||
stream.read( (char *) vector.data(), dataSize );
|
stream.read( (char *) container.data(), dataSize );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Vector>
|
template <class Container>
|
||||||
void readAndResizeVector( std::istream& stream, Vector& vector )
|
void readAndResizeContainer( std::istream& stream, Container& container )
|
||||||
{
|
{
|
||||||
readVectorImpl( stream, vector, true );
|
readContainerImpl( stream, container, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Vector>
|
template <class Container>
|
||||||
void readVector( std::istream& stream, Vector& vector )
|
void readContainer( std::istream& stream, Container& container )
|
||||||
{
|
{
|
||||||
readVectorImpl( stream, vector, false );
|
readContainerImpl( stream, container, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Map>
|
template <class Map>
|
||||||
@ -123,9 +128,9 @@ namespace Opm {
|
|||||||
{
|
{
|
||||||
std::pair< typename Map :: key_type, typename Map :: mapped_type > mapEntry;
|
std::pair< typename Map :: key_type, typename Map :: mapped_type > mapEntry;
|
||||||
// read key
|
// read key
|
||||||
readAndResizeVector( stream, mapEntry.first );
|
readAndResizeContainer( stream, mapEntry.first );
|
||||||
// read values
|
// read values
|
||||||
readVector( stream, mapEntry.second );
|
readContainer( stream, mapEntry.second );
|
||||||
|
|
||||||
// insert entry into map
|
// insert entry into map
|
||||||
m.insert( mapEntry );
|
m.insert( mapEntry );
|
||||||
@ -172,11 +177,11 @@ namespace Opm {
|
|||||||
writeValue( out, numPhases );
|
writeValue( out, numPhases );
|
||||||
|
|
||||||
// write variables
|
// write variables
|
||||||
writeVector( out, state.pressure() );
|
writeContainer( out, state.pressure() );
|
||||||
writeVector( out, state.temperature() );
|
writeContainer( out, state.temperature() );
|
||||||
writeVector( out, state.facepressure() );
|
writeContainer( out, state.facepressure() );
|
||||||
writeVector( out, state.faceflux() );
|
writeContainer( out, state.faceflux() );
|
||||||
writeVector( out, state.saturation() );
|
writeContainer( out, state.saturation() );
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -194,11 +199,11 @@ namespace Opm {
|
|||||||
OPM_THROW(std::logic_error,"num phases wrong");
|
OPM_THROW(std::logic_error,"num phases wrong");
|
||||||
|
|
||||||
// read variables
|
// read variables
|
||||||
readVector( in, state.pressure() );
|
readContainer( in, state.pressure() );
|
||||||
readVector( in, state.temperature() );
|
readContainer( in, state.temperature() );
|
||||||
readVector( in, state.facepressure() );
|
readContainer( in, state.facepressure() );
|
||||||
readVector( in, state.faceflux() );
|
readContainer( in, state.faceflux() );
|
||||||
readVector( in, state.saturation() );
|
readContainer( in, state.saturation() );
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@ -215,9 +220,9 @@ namespace Opm {
|
|||||||
out << simstate;
|
out << simstate;
|
||||||
|
|
||||||
// backup additional blackoil state variables
|
// backup additional blackoil state variables
|
||||||
writeVector( out, state.surfacevol() );
|
writeContainer( out, state.surfacevol() );
|
||||||
writeVector( out, state.gasoilratio() );
|
writeContainer( out, state.gasoilratio() );
|
||||||
writeVector( out, state.rv() );
|
writeContainer( out, state.rv() );
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -233,9 +238,9 @@ namespace Opm {
|
|||||||
in >> simstate;
|
in >> simstate;
|
||||||
|
|
||||||
// backup additional blackoil state variables
|
// backup additional blackoil state variables
|
||||||
readVector( in, state.surfacevol() );
|
readContainer( in, state.surfacevol() );
|
||||||
readVector( in, state.gasoilratio() );
|
readContainer( in, state.gasoilratio() );
|
||||||
readVector( in, state.rv() );
|
readContainer( in, state.rv() );
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@ -248,11 +253,11 @@ namespace Opm {
|
|||||||
writeValue( out, objectId( state ) );
|
writeValue( out, objectId( state ) );
|
||||||
|
|
||||||
// backup well state
|
// backup well state
|
||||||
writeVector( out, state.bhp() );
|
writeContainer( out, state.bhp() );
|
||||||
writeVector( out, state.temperature() );
|
writeContainer( out, state.temperature() );
|
||||||
writeVector( out, state.wellRates() );
|
writeContainer( out, state.wellRates() );
|
||||||
writeVector( out, state.perfRates() );
|
writeContainer( out, state.perfRates() );
|
||||||
writeVector( out, state.perfPress() );
|
writeContainer( out, state.perfPress() );
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -264,11 +269,11 @@ namespace Opm {
|
|||||||
checkObjectId( in, state );
|
checkObjectId( in, state );
|
||||||
|
|
||||||
// restore well state
|
// restore well state
|
||||||
readAndResizeVector( in, state.bhp() );
|
readAndResizeContainer( in, state.bhp() );
|
||||||
readAndResizeVector( in, state.temperature() );
|
readAndResizeContainer( in, state.temperature() );
|
||||||
readAndResizeVector( in, state.wellRates() );
|
readAndResizeContainer( in, state.wellRates() );
|
||||||
readAndResizeVector( in, state.perfRates() );
|
readAndResizeContainer( in, state.perfRates() );
|
||||||
readAndResizeVector( in, state.perfPress() );
|
readAndResizeContainer( in, state.perfPress() );
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@ -292,8 +297,8 @@ namespace Opm {
|
|||||||
writeValue( out, numPhases );
|
writeValue( out, numPhases );
|
||||||
|
|
||||||
// backup additional variables
|
// backup additional variables
|
||||||
writeVector( out, state.perfPhaseRates() );
|
writeContainer( out, state.perfPhaseRates() );
|
||||||
writeVector( out, state.currentControls() );
|
writeContainer( out, state.currentControls() );
|
||||||
writeMap( out, state.wellMap() );
|
writeMap( out, state.wellMap() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,8 +328,8 @@ namespace Opm {
|
|||||||
OPM_THROW(std::logic_error,"wrong numPhases");
|
OPM_THROW(std::logic_error,"wrong numPhases");
|
||||||
|
|
||||||
// restore additional variables
|
// restore additional variables
|
||||||
readAndResizeVector( in, state.perfPhaseRates() );
|
readAndResizeContainer( in, state.perfPhaseRates() );
|
||||||
readAndResizeVector( in, state.currentControls() );
|
readAndResizeContainer( in, state.currentControls() );
|
||||||
readMap( in, state.wellMap() );
|
readMap( in, state.wellMap() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user