mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-12 16:26:23 +00:00
MPI-parallelization upto IO file
This commit is contained in:
@ -74,7 +74,7 @@ add_subdirectory(src)
|
|||||||
|
|
||||||
#add_subdirectory(solvers)
|
#add_subdirectory(solvers)
|
||||||
|
|
||||||
add_subdirectory(utilities)
|
#add_subdirectory(utilities)
|
||||||
|
|
||||||
#add_subdirectory(DEMSystems)
|
#add_subdirectory(DEMSystems)
|
||||||
add_subdirectory(testIO)
|
add_subdirectory(testIO)
|
||||||
|
@ -29,7 +29,7 @@ export PATH="$pFlow_BIN_DIR:$PATH"
|
|||||||
|
|
||||||
export LD_LIBRARY_PATH="$pFlow_LIB_DIR:$LD_LIBRARY_PATH"
|
export LD_LIBRARY_PATH="$pFlow_LIB_DIR:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
export LD_LIBRARY_PATH="$Zoltan_DIR/build/lib:$LD_LIBRARY_PATH"
|
export LD_LIBRARY_PATH="$Zoltan_DIR/lib:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
@ -6,6 +6,10 @@ types/types.cpp
|
|||||||
|
|
||||||
globals/error.cpp
|
globals/error.cpp
|
||||||
|
|
||||||
|
processors/processors.cpp
|
||||||
|
processors/localProcessors.cpp
|
||||||
|
processors/pFlowProcessors.cpp
|
||||||
|
|
||||||
streams/token/tokenIO.cpp
|
streams/token/tokenIO.cpp
|
||||||
streams/token/token.cpp
|
streams/token/token.cpp
|
||||||
streams/iStream/IOstream.cpp
|
streams/iStream/IOstream.cpp
|
||||||
@ -20,14 +24,10 @@ streams/TStream/oTstream.cpp
|
|||||||
streams/Fstream/iFstream.cpp
|
streams/Fstream/iFstream.cpp
|
||||||
streams/Fstream/oFstream.cpp
|
streams/Fstream/oFstream.cpp
|
||||||
streams/Fstream/fileStream.cpp
|
streams/Fstream/fileStream.cpp
|
||||||
streams/dataIO/dataIO.cpp
|
|
||||||
streams/dataIO/dataIONoMPI.cpp
|
|
||||||
streams/streams.cpp
|
streams/streams.cpp
|
||||||
|
|
||||||
fileSystem/fileSystem.cpp
|
fileSystem/fileSystem.cpp
|
||||||
|
|
||||||
processors/processors.cpp
|
|
||||||
|
|
||||||
dictionary/dictionary.cpp
|
dictionary/dictionary.cpp
|
||||||
dictionary/fileDictionary.cpp
|
dictionary/fileDictionary.cpp
|
||||||
dictionary/entry/iEntry.cpp
|
dictionary/entry/iEntry.cpp
|
||||||
@ -39,6 +39,9 @@ containers/Field/Fields.cpp
|
|||||||
containers/List/anyList/anyList.cpp
|
containers/List/anyList/anyList.cpp
|
||||||
containers/pointField/pointFields.cpp
|
containers/pointField/pointFields.cpp
|
||||||
|
|
||||||
|
#setFieldList/setFieldList.cpp
|
||||||
|
#setFieldList/setFieldEntry.cpp
|
||||||
|
|
||||||
Timer/Timer.cpp
|
Timer/Timer.cpp
|
||||||
Timer/Timers.cpp
|
Timer/Timers.cpp
|
||||||
|
|
||||||
@ -64,21 +67,58 @@ structuredData/plane/plane.cpp
|
|||||||
structuredData/domain/domain.cpp
|
structuredData/domain/domain.cpp
|
||||||
structuredData/domain/simulationDomain.cpp
|
structuredData/domain/simulationDomain.cpp
|
||||||
structuredData/domain/regularSimulationDomain.cpp
|
structuredData/domain/regularSimulationDomain.cpp
|
||||||
structuredData/pointStructure/boundaryList.cpp
|
|
||||||
structuredData/pointStructure/internalPoints.cpp
|
structuredData/pointStructure/internalPoints.cpp
|
||||||
structuredData/pointStructure/pointStructure.cpp
|
structuredData/pointStructure/pointStructure.cpp
|
||||||
structuredData/boundaries/boundaryBase/boundaryBase.cpp
|
structuredData/boundaries/boundaryBase/boundaryBase.cpp
|
||||||
structuredData/boundaries/boundaryExit/boundaryExit.cpp
|
structuredData/boundaries/boundaryExit/boundaryExit.cpp
|
||||||
|
structuredData/pointStructure/boundaryList.cpp
|
||||||
|
|
||||||
|
commandLine/commandLine.cpp
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(link_libs)
|
set(link_libs)
|
||||||
if(MPI_FOUND)
|
set(link_libs Kokkos::kokkos tbb)
|
||||||
set(link_libs Kokkos::kokkos tbb PRIVATE MPI::MPI_CXX)
|
|
||||||
|
|
||||||
|
|
||||||
|
if(pFlow_Build_MPI)
|
||||||
|
|
||||||
|
set(Zoltan_Install_DIR)
|
||||||
|
if(DEFINED ENV{Zoltan_DIR})
|
||||||
|
set(Zoltan_Install_DIR $ENV{Zoltan_DIR})
|
||||||
|
else()
|
||||||
|
set(Zoltan_Install_DIR $ENV{HOME}/PhasicFlow/Zoltan)
|
||||||
|
endif()
|
||||||
|
message(STATUS "Zoltan install directory is ${Zoltan_Install_DIR}")
|
||||||
|
|
||||||
|
set(ZOLTAN_PREFIX "${Zoltan_Install_DIR}" CACHE STRING "Zoltan install directory")
|
||||||
|
|
||||||
|
find_path(ZOLTAN_INCLUDE_DIR zoltan.h PATHS "${ZOLTAN_PREFIX}/include")
|
||||||
|
|
||||||
|
message(STATUS "Zoltan include path: ${ZOLTAN_INCLUDE_DIR}")
|
||||||
|
|
||||||
|
find_library(ZOLTAN_LIBRARY zoltan PATHS "${ZOLTAN_PREFIX}/lib")
|
||||||
|
message(STATUS "Zoltan lib path: ${ZOLTAN_LIBRARY}")
|
||||||
|
|
||||||
|
list(APPEND SourceFiles
|
||||||
|
MPIParallelization/partitioning.cpp
|
||||||
|
MPIParallelization/rcb1DPartitioning.cpp
|
||||||
|
MPIParallelization/domain/MPISimulationDomain.cpp
|
||||||
|
#MPIParallelization/dataIOMPI.cpp
|
||||||
|
MPIParallelization/procCommunication.cpp
|
||||||
|
MPIParallelization/boundaryProcessor.cpp
|
||||||
|
MPIParallelization/scatteredMasterDistributeChar.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND link_libs MPI::MPI_CXX ${ZOLTAN_LIBRARY} -lm )
|
||||||
|
pFlow_add_library_install(phasicFlow SourceFiles link_libs)
|
||||||
|
target_include_directories(phasicFlow PUBLIC ./globals ${ZOLTAN_INCLUDE_DIR})
|
||||||
|
|
||||||
else()
|
else()
|
||||||
set(link_libs Kokkos::kokkos tbb)
|
pFlow_add_library_install(phasicFlow SourceFiles link_libs)
|
||||||
|
target_include_directories(phasicFlow PUBLIC ./globals)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
pFlow_add_library_install(phasicFlow SourceFiles link_libs)
|
|
||||||
target_include_directories(phasicFlow PUBLIC ./globals)
|
|
||||||
|
@ -38,10 +38,10 @@ pFlow::commandLine::commandLine(word appName, word disptn)
|
|||||||
CLI::App::add_flag_callback(
|
CLI::App::add_flag_callback(
|
||||||
"--description",
|
"--description",
|
||||||
[disptn, appName]() {
|
[disptn, appName]() {
|
||||||
output<<"\n"<<yellowText(versoinCopyright)<<endl;
|
mOutput<<"\n"<<Yellow_Text(versoinCopyright)<<endl;
|
||||||
output<<yellowText(floatingPointDescription())<<endl<<endl;
|
mOutput<<Yellow_Text(floatingPointDescription())<<endl<<endl;
|
||||||
output<<"Description for "<< boldText(appName)<<":\n";
|
mOutput<<"Description for "<< Bold_Text(appName)<<":\n";
|
||||||
output<<" "<<disptn<<endl;
|
mOutput<<" "<<disptn<<endl;
|
||||||
},
|
},
|
||||||
"What does this app do?"
|
"What does this app do?"
|
||||||
)->configurable(false);
|
)->configurable(false);
|
||||||
|
@ -185,12 +185,14 @@ template<template<class, class> class VectorField, class T, class PropType>
|
|||||||
bool pFlow::Field<VectorField, T, PropType>::read
|
bool pFlow::Field<VectorField, T, PropType>::read
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool tokenFound;
|
bool tokenFound = true;
|
||||||
tokenFound = is.findToken(fieldKey_);
|
|
||||||
|
if(iop.thisProcReadData())
|
||||||
|
tokenFound = is.findToken(fieldKey_);
|
||||||
|
|
||||||
if( !tokenFound )
|
if( !tokenFound )
|
||||||
{
|
{
|
||||||
@ -199,12 +201,13 @@ bool pFlow::Field<VectorField, T, PropType>::read
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !VectorType::read(is, iotype) )
|
if( !VectorType::read(is, iop) )
|
||||||
{
|
{
|
||||||
ioErrorInFile(is.name(), is.lineNumber())<<
|
ioErrorInFile(is.name(), is.lineNumber())<<
|
||||||
"error in reading field data from field "<< this->name()<<endl;
|
"error in reading field data from field "<< this->name()<<endl;
|
||||||
}
|
}
|
||||||
is.readEndStatement("Field::read");
|
if(iop.thisProcReadData())
|
||||||
|
is.readEndStatement("Field::read");
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -213,14 +216,14 @@ bool pFlow::Field<VectorField, T, PropType>::read
|
|||||||
template<template<class, class> class VectorField, class T, class PropType>
|
template<template<class, class> class VectorField, class T, class PropType>
|
||||||
bool pFlow::Field<VectorField, T, PropType>::write(
|
bool pFlow::Field<VectorField, T, PropType>::write(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
IOPattern::IOType iotype)const
|
const IOPattern& iop)const
|
||||||
{
|
{
|
||||||
|
|
||||||
os.writeWordKeyword(fieldKey_)<<endl;
|
os.writeWordKeyword(fieldKey_)<<endl;
|
||||||
|
|
||||||
if(!os.check(FUNCTION_NAME))return false;
|
if(!os.check(FUNCTION_NAME))return false;
|
||||||
|
|
||||||
if(!VectorType::write(os, iotype)) return false;
|
if(!VectorType::write(os, iop)) return false;
|
||||||
|
|
||||||
os.endEntry();
|
os.endEntry();
|
||||||
if(!os.check(FUNCTION_NAME))return false;
|
if(!os.check(FUNCTION_NAME))return false;
|
||||||
|
@ -27,7 +27,7 @@ Licence:
|
|||||||
|
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "Vector.hpp"
|
#include "Vector.hpp"
|
||||||
|
#include "streams.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
@ -193,15 +193,15 @@ public:
|
|||||||
bool writeField(iOstream& os)const;*/
|
bool writeField(iOstream& os)const;*/
|
||||||
|
|
||||||
|
|
||||||
bool read(iIstream& is, IOPattern::IOType iotype);
|
bool read(iIstream& is, const IOPattern& iop);
|
||||||
|
|
||||||
|
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype )const;
|
bool write(iOstream& os, const IOPattern& iop )const;
|
||||||
|
|
||||||
template<typename HostMask>
|
template<typename HostMask>
|
||||||
bool write(
|
bool write(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
IOPattern::IOType iotype,
|
const IOPattern& iop,
|
||||||
const HostMask& mask)const
|
const HostMask& mask)const
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ public:
|
|||||||
|
|
||||||
if(!os.check(FUNCTION_NAME))return false;
|
if(!os.check(FUNCTION_NAME))return false;
|
||||||
|
|
||||||
if(!VectorType::write(os, iotype)) return false;
|
if(!VectorType::write(os, iop)) return false;
|
||||||
|
|
||||||
os.endEntry();
|
os.endEntry();
|
||||||
if(!os.check(FUNCTION_NAME))return false;
|
if(!os.check(FUNCTION_NAME))return false;
|
||||||
|
@ -23,10 +23,10 @@ template<typename T, typename Allocator>
|
|||||||
bool pFlow::Vector<T, Allocator>::readVector
|
bool pFlow::Vector<T, Allocator>::readVector
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return readStdVector(is, vectorField(), iotype);
|
return readStdVector(is, vectorField(), iop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,10 +34,10 @@ template<typename T, typename Allocator>
|
|||||||
bool pFlow::Vector<T, Allocator>::writeVector
|
bool pFlow::Vector<T, Allocator>::writeVector
|
||||||
(
|
(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return writeStdVector(os, vectorField(), iotype);
|
return writeStdVector(os, vectorField(), iop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*template<typename T, typename Allocator>
|
/*template<typename T, typename Allocator>
|
||||||
|
@ -334,7 +334,7 @@ public:
|
|||||||
inline
|
inline
|
||||||
auto getSpan()const
|
auto getSpan()const
|
||||||
{
|
{
|
||||||
return span<const T>(this->data(), this->size());
|
return span<T>(const_cast<T*>(this->data()), this->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr bool isHostAccessible()
|
static constexpr bool isHostAccessible()
|
||||||
@ -357,19 +357,19 @@ public:
|
|||||||
inline VectorType operator -()const;
|
inline VectorType operator -()const;
|
||||||
|
|
||||||
/// Read vector (assume ASCII in input)
|
/// Read vector (assume ASCII in input)
|
||||||
bool readVector(iIstream& is, IOPattern::IOType iotype);
|
bool readVector(iIstream& is, const IOPattern& iop);
|
||||||
|
|
||||||
/// write vector
|
/// write vector
|
||||||
bool writeVector(iOstream& os, IOPattern::IOType iotype) const;
|
bool writeVector(iOstream& os, const IOPattern& iop) const;
|
||||||
|
|
||||||
bool read(iIstream& is, IOPattern::IOType iotype)
|
bool read(iIstream& is, const IOPattern& iop)
|
||||||
{
|
{
|
||||||
return readVector(is, iotype);
|
return readVector(is, iop);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype)const
|
bool write(iOstream& os, const IOPattern& iop)const
|
||||||
{
|
{
|
||||||
return writeVector(os, iotype);
|
return writeVector(os, iop);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -28,8 +28,8 @@ Licence:
|
|||||||
#include "span.hpp"
|
#include "span.hpp"
|
||||||
#include "iOstream.hpp"
|
#include "iOstream.hpp"
|
||||||
#include "iIstream.hpp"
|
#include "iIstream.hpp"
|
||||||
#include "dataIO.hpp"
|
#include "createDataIO.hpp"
|
||||||
|
#include "pFlowProcessors.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
@ -54,11 +54,11 @@ inline
|
|||||||
bool writeSpan(
|
bool writeSpan(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
const span<T>& sp,
|
const span<T>& sp,
|
||||||
IOPattern::IOType iotype)
|
const IOPattern& iop)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto ioPtr = dataIO::create(iotype, IOPattern::exeMode());
|
auto ioPtr = createDataIO<T>(pFlowProcessors().localRunTypeName(), iop);
|
||||||
|
|
||||||
if(!ioPtr)
|
if(!ioPtr)
|
||||||
{
|
{
|
||||||
fatalErrorInFunction;
|
fatalErrorInFunction;
|
||||||
@ -73,32 +73,27 @@ bool writeSpan(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T, typename Allocator>
|
template<typename T, typename Allocator>
|
||||||
bool writeStdVector
|
bool writeStdVector
|
||||||
(
|
(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
const std::vector<T,Allocator>& vec,
|
const std::vector<T,Allocator>& vec,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
span<T> sp( const_cast<T*>(vec.data()), vec.size());
|
auto sp = makeSpan(vec);
|
||||||
|
return writeSpan(os, sp, iop);
|
||||||
return writeSpan(os, sp, iotype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T, typename Allocator>
|
template<typename T, typename Allocator>
|
||||||
bool readStdVector
|
bool readStdVector
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
std::vector<T,Allocator>& vec,
|
std::vector<T,Allocator>& vec,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto ioPtr = dataIO::create(iotype, IOPattern::exeMode());
|
auto ioPtr = createDataIO<T>(pFlowProcessors().localRunTypeName(), iop);
|
||||||
|
|
||||||
if(!ioPtr)
|
if(!ioPtr)
|
||||||
{
|
{
|
||||||
|
@ -415,7 +415,7 @@ template<typename T, typename MemorySpace>
|
|||||||
INLINE_FUNCTION_H
|
INLINE_FUNCTION_H
|
||||||
auto pFlow::VectorSingle<T,MemorySpace>::getSpan()const
|
auto pFlow::VectorSingle<T,MemorySpace>::getSpan()const
|
||||||
{
|
{
|
||||||
return span<const T>(view_.data(), this->size());
|
return span<T>(const_cast<T*>(view_.data()), this->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename MemorySpace>
|
template<typename T, typename MemorySpace>
|
||||||
|
@ -370,10 +370,10 @@ public:
|
|||||||
|
|
||||||
/// Read vector from stream (ASCII)
|
/// Read vector from stream (ASCII)
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool read(iIstream& is, IOPattern::IOType iotype)
|
bool read(iIstream& is, const IOPattern& iop)
|
||||||
{
|
{
|
||||||
std::vector<T> vecFromFile;
|
std::vector<T> vecFromFile;
|
||||||
if(! readStdVector(is, vecFromFile, iotype)) return false;
|
if(! readStdVector(is, vecFromFile, iop)) return false;
|
||||||
|
|
||||||
this->assign(vecFromFile);
|
this->assign(vecFromFile);
|
||||||
|
|
||||||
@ -382,18 +382,18 @@ public:
|
|||||||
|
|
||||||
/// Write the vector to os
|
/// Write the vector to os
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype)const
|
bool write(iOstream& os, const IOPattern& iop)const
|
||||||
{
|
{
|
||||||
auto hVec = hostVector();
|
auto hVec = hostVector();
|
||||||
auto sp = span<T>( const_cast<T*>(hVec.data()), hVec.size());
|
auto sp = span<T>( const_cast<T*>(hVec.data()), hVec.size());
|
||||||
|
|
||||||
return writeSpan(os, sp, iotype);
|
return writeSpan(os, sp, iop);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename HostMask>
|
template<typename HostMask>
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype, const HostMask& mask)const
|
bool write(iOstream& os, const IOPattern& iop, const HostMask& mask)const
|
||||||
{
|
{
|
||||||
auto hVec = hostVector();
|
auto hVec = hostVector();
|
||||||
|
|
||||||
@ -413,7 +413,7 @@ public:
|
|||||||
|
|
||||||
auto sp = span<T>( finalField.data(), finalField.size());
|
auto sp = span<T>( finalField.data(), finalField.size());
|
||||||
|
|
||||||
return writeSpan(os, sp, iotype);
|
return writeSpan(os, sp, iop);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +192,42 @@ iOstream& operator<<(iOstream& os, const span<T>& s)
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, template<class> class Container>
|
||||||
|
span<T> makeSpan(Container<T>& container)
|
||||||
|
{
|
||||||
|
return span<T>(container.data(), container.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, template<class> class Container>
|
||||||
|
span<T> makeSpan(const Container<T>& container)
|
||||||
|
{
|
||||||
|
return span<T>(
|
||||||
|
const_cast<T*>(container.data()),
|
||||||
|
container.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline
|
||||||
|
span<char> charSpan(span<T> s)
|
||||||
|
{
|
||||||
|
auto el = sizeof(T);
|
||||||
|
return span<char>(
|
||||||
|
reinterpret_cast<char*>(s.data()),
|
||||||
|
s.size()*el);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline
|
||||||
|
span<const char> charSpan(span<const T> s)
|
||||||
|
{
|
||||||
|
auto el = sizeof(T);
|
||||||
|
return span<const char>(
|
||||||
|
reinterpret_cast<const char*>(s.data()),
|
||||||
|
s.size()*el);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // pFlow
|
} // pFlow
|
||||||
|
@ -19,8 +19,8 @@ Licence:
|
|||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "demComponent.hpp"
|
#include "demComponent.hpp"
|
||||||
|
#include "systemControl.hpp"
|
||||||
|
#include "Time.hpp"
|
||||||
|
|
||||||
pFlow::demComponent::demComponent(const word& name, systemControl& control)
|
pFlow::demComponent::demComponent(const word& name, systemControl& control)
|
||||||
:
|
:
|
||||||
@ -28,4 +28,14 @@ pFlow::demComponent::demComponent(const word& name, systemControl& control)
|
|||||||
control_(control),
|
control_(control),
|
||||||
time_(control.time()),
|
time_(control.time()),
|
||||||
timers_(name, &control.timers())
|
timers_(name, &control.timers())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
pFlow::real pFlow::demComponent::dt()const
|
||||||
|
{
|
||||||
|
return time_.dt();
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::real pFlow::demComponent::currentTime()const
|
||||||
|
{
|
||||||
|
return time_.currentTime();
|
||||||
|
}
|
||||||
|
@ -21,13 +21,15 @@ Licence:
|
|||||||
#ifndef __demComponent_hpp__
|
#ifndef __demComponent_hpp__
|
||||||
#define __demComponent_hpp__
|
#define __demComponent_hpp__
|
||||||
|
|
||||||
#include "systemControl.hpp"
|
#include "types.hpp"
|
||||||
#include "Time.hpp"
|
#include "typeInfo.hpp"
|
||||||
|
#include "Timers.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class systemControl;
|
||||||
|
class Time;
|
||||||
/**
|
/**
|
||||||
* A base class for every main component of DEM system.
|
* A base class for every main component of DEM system.
|
||||||
*
|
*
|
||||||
@ -96,19 +98,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Time step of integration
|
/// Time step of integration
|
||||||
inline
|
real dt()const;
|
||||||
real dt()const
|
|
||||||
{
|
|
||||||
return time_.dt();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Current simulation time
|
/// Current simulation time
|
||||||
inline
|
real currentTime()const;
|
||||||
real currentTime()const
|
|
||||||
{
|
|
||||||
return time_.currentTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
const auto& time()const
|
const auto& time()const
|
||||||
{
|
{
|
||||||
|
@ -218,6 +218,9 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool addOrKeep(const word& keyword, const T& v);
|
bool addOrKeep(const word& keyword, const T& v);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool addOrReplace(const word& keyword, const T& v);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
/// pointer to a subdictionary
|
/// pointer to a subdictionary
|
||||||
@ -384,8 +387,20 @@ T dictionary::getValOrSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool dictionary::addOrReplace
|
||||||
|
(
|
||||||
|
const word &keyword,
|
||||||
|
const T &v
|
||||||
|
)
|
||||||
|
{
|
||||||
|
uniquePtr<iEntry> ptr = makeUnique<dataEntry>(keyword, *this ,v);
|
||||||
|
return addPtr(keyword, ptr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // pFlow
|
} // pFlow
|
||||||
|
|
||||||
|
|
||||||
#endif // __dictionary_hpp__
|
#endif // __dictionary_hpp__
|
||||||
|
@ -1,22 +1,50 @@
|
|||||||
#include "fileDictionary.hpp"
|
#include "fileDictionary.hpp"
|
||||||
#include "IOPattern.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
pFlow::fileDictionary::fileDictionary(const word &keyword)
|
pFlow::fileDictionary::fileDictionary
|
||||||
|
(
|
||||||
|
const objectFile & of,
|
||||||
|
repository* owner
|
||||||
|
)
|
||||||
:
|
:
|
||||||
dictionary(keyword, true)
|
IOobject
|
||||||
|
(
|
||||||
|
of,
|
||||||
|
IOPattern::IOPattern::AllProcessorsSimilar,
|
||||||
|
owner
|
||||||
|
),
|
||||||
|
dictionary
|
||||||
|
(
|
||||||
|
of.name(),
|
||||||
|
true
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
dictionary::name_ = IOobject::path().wordPath();
|
||||||
|
if(!IOobject::read())
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"Error in reading from dictionary "<< globalName()<<endl;
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::fileDictionary::fileDictionary(const word &keyword, const fileSystem &file)
|
pFlow::fileDictionary::fileDictionary(const word &keyword, const fileSystem &file)
|
||||||
:
|
:
|
||||||
dictionary(keyword, file)
|
fileDictionary
|
||||||
{
|
(
|
||||||
}
|
objectFile
|
||||||
|
(
|
||||||
|
keyword,
|
||||||
|
file,
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_NEVER
|
||||||
|
),
|
||||||
|
nullptr
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
bool pFlow::fileDictionary::read(iIstream &is, const IOPattern &iop)
|
bool pFlow::fileDictionary::read(iIstream &is, const IOPattern &iop)
|
||||||
{
|
{
|
||||||
|
|
||||||
return dictionary::read(is);
|
return dictionary::read(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,17 +17,18 @@ Licence:
|
|||||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
#ifndef __fileDictionary_hpp__
|
||||||
|
#define __fileDictionary_hpp__
|
||||||
|
|
||||||
#include "dictionary.hpp"
|
#include "dictionary.hpp"
|
||||||
|
#include "IOobject.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
class IOPattern;
|
|
||||||
|
|
||||||
class fileDictionary
|
class fileDictionary
|
||||||
:
|
:
|
||||||
|
public IOobject,
|
||||||
public dictionary
|
public dictionary
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -35,19 +36,22 @@ public:
|
|||||||
TypeInfo("fileDictionary");
|
TypeInfo("fileDictionary");
|
||||||
|
|
||||||
/// construct an empty dictionary with keyword and make it global/fileDictionary
|
/// construct an empty dictionary with keyword and make it global/fileDictionary
|
||||||
fileDictionary(const word& keyword);
|
fileDictionary(const objectFile & of, repository* owner = nullptr);
|
||||||
|
|
||||||
/// construct a dictionary with name and read it from file
|
/// construct a dictionary with name and read it from file
|
||||||
fileDictionary(const word& keyword, const fileSystem& file);
|
fileDictionary(const word& keyword, const fileSystem& file);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// read from stream
|
/// read from stream
|
||||||
virtual bool read(iIstream& is, const IOPattern& iop);
|
bool read(iIstream& is, const IOPattern& iop) override;
|
||||||
|
|
||||||
/// write to stream
|
/// write to stream
|
||||||
virtual bool write(iOstream& os, const IOPattern& iop) const;
|
|
||||||
|
bool write(iOstream& os, const IOPattern& iop) const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //__fileDictionary_hpp__
|
@ -21,7 +21,7 @@ Licence:
|
|||||||
|
|
||||||
#include "fileSystem.hpp"
|
#include "fileSystem.hpp"
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
#include "iOstream.hpp"
|
#include "streams.hpp"
|
||||||
|
|
||||||
|
|
||||||
bool pFlow::fileSystem::checkFileName(const word& name)
|
bool pFlow::fileSystem::checkFileName(const word& name)
|
||||||
@ -47,7 +47,6 @@ pFlow::fileSystem::fileSystem(const word & wPath)
|
|||||||
path_(wPath),
|
path_(wPath),
|
||||||
isDir_(std::filesystem::is_directory(path_))
|
isDir_(std::filesystem::is_directory(path_))
|
||||||
{
|
{
|
||||||
std::cout<<"file name is " << fileName()<<std::endl;
|
|
||||||
if( !isDir_ && !checkFileName(fileName()))
|
if( !isDir_ && !checkFileName(fileName()))
|
||||||
{
|
{
|
||||||
fatalExit;
|
fatalExit;
|
||||||
@ -276,7 +275,7 @@ pFlow::fileSystem pFlow::operator /
|
|||||||
const fileSystem& fs2
|
const fileSystem& fs2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
fileSystem::pathType cmbPath(fs1.dirPath().path_ / fs2.dirPath().path_);
|
fileSystem::pathType cmbPath(fs1.dirPath().path_ / fs2.path_);
|
||||||
|
|
||||||
return fileSystem( cmbPath.c_str() );
|
return fileSystem( cmbPath.c_str() );
|
||||||
|
|
||||||
|
@ -30,7 +30,9 @@ Licence:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static pFlow::Ostream& errorStream = pFlow::errReport;
|
//static pFlow::Ostream& errorStream = pFlow::errReport;
|
||||||
|
|
||||||
|
static pFlow::Ostream& errorStream = pFlow::pOutput;
|
||||||
|
|
||||||
|
|
||||||
pFlow::iOstream& fatalErrorMessage(const char* fileName, int linNumber )
|
pFlow::iOstream& fatalErrorMessage(const char* fileName, int linNumber )
|
||||||
@ -57,9 +59,9 @@ pFlow::iOstream& notImplementedErrorMessage(const char*fnName, const char* fileN
|
|||||||
{
|
{
|
||||||
|
|
||||||
errorStream<<"\n>>> Fatal error in phasicFlow\n";
|
errorStream<<"\n>>> Fatal error in phasicFlow\n";
|
||||||
errorStream<<" Function "<< Red_Text(fnName) << " has not implmented yet!\n" <<
|
errorStream<<" Function "<< Red_Text(fnName) << " has not been implemented yet!\n" <<
|
||||||
" Function definition is in source file "<< Red_Text(fileName) <<
|
" File "<< Yellow_Text(fileName) <<
|
||||||
" at line "<< Red_Text(lineNumber) <<'\n';
|
" at line "<< Yellow_Text(lineNumber) <<'\n';
|
||||||
return errorStream;
|
return errorStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
117
src/phasicFlow/processors/localProcessors.cpp
Normal file
117
src/phasicFlow/processors/localProcessors.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "localProcessors.hpp"
|
||||||
|
|
||||||
|
pFlow::localProcessors::localProcessors(const word &name)
|
||||||
|
:
|
||||||
|
processors(),
|
||||||
|
localSize_(processors::globalSize()),
|
||||||
|
localRank_(processors::globalRank()),
|
||||||
|
name_(name)
|
||||||
|
{
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
parrentCommunicator_ = pFlow::MPI::CommWorld;
|
||||||
|
localCommunicator_ = pFlow::MPI::CommWorld;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::localProcessors::localProcessors
|
||||||
|
(
|
||||||
|
const word &name,
|
||||||
|
const std::vector<int> &ranks
|
||||||
|
)
|
||||||
|
:
|
||||||
|
processors(),
|
||||||
|
name_(name)
|
||||||
|
{
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
parrentCommunicator_ = pFlow::MPI::CommWorld;
|
||||||
|
|
||||||
|
if(ranks.size()> this->globalSize() )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"the size of ranks is larger than parrent communicator size "<<endl;
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::MPI::Group globalGroup;
|
||||||
|
MPI_Comm_group(parrentCommunicator_, &globalGroup);
|
||||||
|
|
||||||
|
pFlow::MPI::Group localGroup;
|
||||||
|
MPI_Group_incl(globalGroup, ranks.size(), ranks.data(), &localGroup);
|
||||||
|
|
||||||
|
// Create the new communicator from that group of processes.
|
||||||
|
|
||||||
|
CheckMPI( MPI_Comm_create(parrentCommunicator_, localGroup, &localCommunicator_), true);
|
||||||
|
|
||||||
|
isPartOfLocal_ = localCommunicator_ != MPI::CommNull;
|
||||||
|
|
||||||
|
if(isPartOfLocal_)
|
||||||
|
{
|
||||||
|
MPI_Comm_set_name(localCommunicator_, name.c_str());
|
||||||
|
|
||||||
|
MPI_Comm_size(localCommunicator_, &localSize_);
|
||||||
|
MPI_Comm_rank(localCommunicator_, &localRank_);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
if(ranks.size()> 1 )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"rank size for processors should not be greater than 1.";
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
localSize_ = processors::globalSize();
|
||||||
|
localRank_ = processors::globalRank();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
|
||||||
|
pFlow::localProcessors::localProcessors
|
||||||
|
(
|
||||||
|
pFlow::MPI::Comm parrentComm,
|
||||||
|
const word &name,
|
||||||
|
const std::vector<int> &ranks
|
||||||
|
)
|
||||||
|
:
|
||||||
|
processors(),
|
||||||
|
name_(name)
|
||||||
|
{
|
||||||
|
parrentCommunicator_ = parrentComm;
|
||||||
|
|
||||||
|
int parSize;
|
||||||
|
|
||||||
|
MPI_Comm_size(parrentCommunicator_, &parSize);
|
||||||
|
|
||||||
|
if(ranks.size()> parSize )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"the size of ranks is larger than parrent communicator size "<<endl;
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::MPI::Group parGroup;
|
||||||
|
MPI_Comm_group(parrentCommunicator_, &parGroup);
|
||||||
|
|
||||||
|
pFlow::MPI::Group localGroup;
|
||||||
|
MPI_Group_incl(parGroup, ranks.size(), ranks.data(), &localGroup);
|
||||||
|
|
||||||
|
// Create the new communicator from that group of processes.
|
||||||
|
|
||||||
|
CheckMPI( MPI_Comm_create(parrentCommunicator_, localGroup, &localCommunicator_), true);
|
||||||
|
|
||||||
|
isPartOfLocal_ = localCommunicator_ != MPI::CommNull;
|
||||||
|
|
||||||
|
if(isPartOfLocal_)
|
||||||
|
{
|
||||||
|
MPI_Comm_set_name(localCommunicator_, name.c_str());
|
||||||
|
|
||||||
|
MPI_Comm_size(localCommunicator_, &localSize_);
|
||||||
|
MPI_Comm_rank(localCommunicator_, &localRank_);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
152
src/phasicFlow/processors/localProcessors.hpp
Normal file
152
src/phasicFlow/processors/localProcessors.hpp
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/*------------------------------- 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 __pFlowProcessors_hpp__
|
||||||
|
#define __pFlowProcessors_hpp__
|
||||||
|
|
||||||
|
|
||||||
|
#include "processors.hpp"
|
||||||
|
#include "types.hpp"
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
#include "mpiTypes.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace pFlow
|
||||||
|
{
|
||||||
|
|
||||||
|
class localProcessors
|
||||||
|
:
|
||||||
|
public processors
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
pFlow::MPI::Comm parrentCommunicator_;
|
||||||
|
|
||||||
|
pFlow::MPI::Comm localCommunicator_;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int localSize_ = 0 ;
|
||||||
|
|
||||||
|
int localRank_ = -1;
|
||||||
|
|
||||||
|
bool isPartOfLocal_ = true;
|
||||||
|
|
||||||
|
word name_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// @brief Construct a local processor communication similar
|
||||||
|
/// to global with specified name
|
||||||
|
/// @param name a given name to the local communicator
|
||||||
|
localProcessors(const word& name);
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Construct a local processor communication from global
|
||||||
|
/// communicator using a name and ranks
|
||||||
|
/// @param name a given name to the local communicator
|
||||||
|
/// @param ranks ranks to be included in the new communicator
|
||||||
|
localProcessors(
|
||||||
|
const word& name,
|
||||||
|
const std::vector<int>& ranks);
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
localProcessors(
|
||||||
|
pFlow::MPI::Comm parrentComm,
|
||||||
|
const word& name,
|
||||||
|
const std::vector<int>& ranks);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// - Access
|
||||||
|
|
||||||
|
/// @brief return name of the local communicator
|
||||||
|
inline
|
||||||
|
const auto& name()const
|
||||||
|
{
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
auto localRank()const
|
||||||
|
{
|
||||||
|
return localRank_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
auto localSize()const
|
||||||
|
{
|
||||||
|
return localSize_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// - Methods
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool localMaster()const
|
||||||
|
{
|
||||||
|
return localRank_ == localMasterNo();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int localMasterNo()const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool localParallel()const
|
||||||
|
{
|
||||||
|
return localSize_>1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
const char* localRunTypeName()
|
||||||
|
{
|
||||||
|
if(localParallel())
|
||||||
|
return "MPI";
|
||||||
|
else
|
||||||
|
return "regular";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool isThisActive()const
|
||||||
|
{
|
||||||
|
return isPartOfLocal_;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
inline
|
||||||
|
auto parrentCommunicator()const
|
||||||
|
{
|
||||||
|
return parrentCommunicator_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
auto localCommunicator()const
|
||||||
|
{
|
||||||
|
return localCommunicator_;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
18
src/phasicFlow/processors/pFlowProcessors.cpp
Normal file
18
src/phasicFlow/processors/pFlowProcessors.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "pFlowProcessors.hpp"
|
||||||
|
|
||||||
|
static pFlow::localProcessors pFlowProcessors__{"pFlowProcessors"};
|
||||||
|
|
||||||
|
pFlow::localProcessors& pFlow::pFlowProcessors()
|
||||||
|
{
|
||||||
|
return pFlowProcessors__;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pFlow::initialize_pFlowProcessors()
|
||||||
|
{
|
||||||
|
pFlowProcessors__ = localProcessors("pFlowProcessors");
|
||||||
|
}
|
||||||
|
|
||||||
|
void pFlow::initialize_pFlowProcessors(const std::vector<int>& ranks)
|
||||||
|
{
|
||||||
|
pFlowProcessors__ = localProcessors("pFlowProcessors", ranks);
|
||||||
|
}
|
14
src/phasicFlow/processors/pFlowProcessors.hpp
Normal file
14
src/phasicFlow/processors/pFlowProcessors.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
#include "localProcessors.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace pFlow
|
||||||
|
{
|
||||||
|
|
||||||
|
localProcessors& pFlowProcessors();
|
||||||
|
|
||||||
|
void initialize_pFlowProcessors();
|
||||||
|
|
||||||
|
void initialize_pFlowProcessors(const std::vector<int>& ranks);
|
||||||
|
|
||||||
|
}
|
@ -21,7 +21,7 @@ Licence:
|
|||||||
#include "phasicFlowConfig.H"
|
#include "phasicFlowConfig.H"
|
||||||
|
|
||||||
#ifdef pFlow_Build_MPI
|
#ifdef pFlow_Build_MPI
|
||||||
#include <mpi.h>
|
#include "mpiCommunication.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// from PhasicFlow
|
// from PhasicFlow
|
||||||
@ -29,7 +29,15 @@ Licence:
|
|||||||
#include "processors.hpp"
|
#include "processors.hpp"
|
||||||
#include "streams.hpp"
|
#include "streams.hpp"
|
||||||
|
|
||||||
|
static int numVarsInitialized__ = 0;
|
||||||
|
|
||||||
|
#ifdef pFlow_Build_MPI
|
||||||
|
|
||||||
|
pFlow::MPI::DataType pFlow::MPI::realx3Type__;
|
||||||
|
pFlow::MPI::DataType pFlow::MPI::realx4Type__;
|
||||||
|
pFlow::MPI::DataType pFlow::MPI::int32x3Type__;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void pFlow::processors::initProcessors(int argc, char *argv[])
|
void pFlow::processors::initProcessors(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -40,17 +48,31 @@ void pFlow::processors::initProcessors(int argc, char *argv[])
|
|||||||
CheckMPI(MPI_Init(&argc, &argv), true);
|
CheckMPI(MPI_Init(&argc, &argv), true);
|
||||||
isSelfInitialized_ = true;
|
isSelfInitialized_ = true;
|
||||||
|
|
||||||
processors::globalSize_ = MPI::COMM_WORLD.Get_size();
|
argc_ = argc;
|
||||||
processors::globalRank_ = MPI::COMM_WORLD.Get_rank();
|
argv_ = argv;
|
||||||
|
|
||||||
|
MPI_Comm_rank(MPI_COMM_WORLD, &processors::globalRank_);
|
||||||
|
MPI_Comm_size(MPI_COMM_WORLD, &processors::globalSize_);
|
||||||
|
|
||||||
|
|
||||||
if(processors::isParallel())
|
if(processors::globalParallel())
|
||||||
{
|
{
|
||||||
pFlow::pOutput.activatePrefix();
|
pFlow::pOutput.activatePrefix();
|
||||||
pFlow::pOutput.setPrefixNum(processors::globalRank_);
|
pFlow::pOutput.setPrefixNum(processors::globalRank_);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::mOutput.setMasterSlave(processors::isMaster());
|
pFlow::mOutput.setMasterSlave(processors::globalMaster());
|
||||||
pFlow::errReport.setMasterSlave(processors::isMaster());
|
pFlow::errReport.setMasterSlave(processors::globalMaster());
|
||||||
|
|
||||||
|
MPI_Type_contiguous(3, pFlow::MPI::Type<real>(), &pFlow::MPI::realx3Type__);
|
||||||
|
MPI_Type_commit(&pFlow::MPI::realx3Type__);
|
||||||
|
|
||||||
|
MPI_Type_contiguous(4, pFlow::MPI::Type<real>(), &pFlow::MPI::realx4Type__);
|
||||||
|
MPI_Type_commit(&pFlow::MPI::realx3Type__);
|
||||||
|
|
||||||
|
MPI_Type_contiguous(3, pFlow::MPI::Type<int32>(), &pFlow::MPI::int32x3Type__);
|
||||||
|
MPI_Type_commit(&pFlow::MPI::int32x3Type__);
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -64,6 +86,9 @@ void pFlow::processors::finalizeProcessors()
|
|||||||
#ifdef pFlow_Build_MPI
|
#ifdef pFlow_Build_MPI
|
||||||
if(isSelfInitialized_ && !isFinalized())
|
if(isSelfInitialized_ && !isFinalized())
|
||||||
{
|
{
|
||||||
|
MPI::TypeFree(&pFlow::MPI::realx3Type__);
|
||||||
|
MPI::TypeFree(&pFlow::MPI::realx4Type__);
|
||||||
|
MPI::TypeFree(&pFlow::MPI::int32x3Type__);
|
||||||
CheckMPI(MPI_Finalize(), true);
|
CheckMPI(MPI_Finalize(), true);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -75,7 +100,7 @@ pFlow::processors::processors()
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef pFlow_Build_MPI
|
#ifdef pFlow_Build_MPI
|
||||||
if(isParallel() && !isInitialized())
|
if(globalParallel() && !isInitialized())
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"MPI communication is not initialized yet!"<<endl;
|
"MPI communication is not initialized yet!"<<endl;
|
||||||
|
@ -17,11 +17,11 @@ Licence:
|
|||||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef __processors_H__
|
#ifndef __processors_H__
|
||||||
#define __processors_H__
|
#define __processors_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
// - Forward
|
// - Forward
|
||||||
@ -64,6 +64,12 @@ protected:
|
|||||||
static inline
|
static inline
|
||||||
int globalSize_ = 1;
|
int globalSize_ = 1;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int argc_ = 0;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
char** argv_ = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Initialize MPI processors
|
/// Initialize MPI processors
|
||||||
@ -77,28 +83,27 @@ public:
|
|||||||
/// Constructor
|
/// Constructor
|
||||||
processors();
|
processors();
|
||||||
|
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~processors();
|
~processors();
|
||||||
|
|
||||||
/// Master processors number (globaly in MPI).
|
/// Master processors number (globaly in MPI).
|
||||||
static inline
|
static inline
|
||||||
int masterNo()
|
int globalMasterNo()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this a parallel MPI run.
|
/// Is this a parallel MPI run.
|
||||||
static inline
|
static inline
|
||||||
bool isParallel()
|
bool globalParallel()
|
||||||
{
|
{
|
||||||
return processors::globalSize()>1;
|
return processors::globalSize()>1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
const char* runTypeName()
|
const char* globalRunTypeName()
|
||||||
{
|
{
|
||||||
if(isParallel())
|
if(globalParallel())
|
||||||
{
|
{
|
||||||
return "MPI";
|
return "MPI";
|
||||||
}
|
}
|
||||||
@ -117,9 +122,9 @@ public:
|
|||||||
|
|
||||||
/// Is this processor the master processor?
|
/// Is this processor the master processor?
|
||||||
static inline
|
static inline
|
||||||
bool isMaster()
|
bool globalMaster()
|
||||||
{
|
{
|
||||||
return processors::globalRank() == processors::masterNo();
|
return processors::globalRank() == processors::globalMasterNo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Global size of processors
|
/// Global size of processors
|
||||||
@ -136,10 +141,30 @@ public:
|
|||||||
return globalRank_;
|
return globalRank_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int argc()
|
||||||
|
{
|
||||||
|
return argc_;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
char** argv()
|
||||||
|
{
|
||||||
|
return argv_;
|
||||||
|
}
|
||||||
|
|
||||||
/// Abort MPI run or regular run
|
/// Abort MPI run or regular run
|
||||||
static
|
static
|
||||||
void abort(int error);
|
void abort(int error);
|
||||||
|
|
||||||
|
/*#ifdef pFlow_Build_MPI
|
||||||
|
static inline
|
||||||
|
auto worldCommunicator()
|
||||||
|
{
|
||||||
|
return pFlow::MPI::CommWorld;
|
||||||
|
}
|
||||||
|
#endif*/
|
||||||
|
|
||||||
}; //processors
|
}; //processors
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,14 +25,11 @@ pFlow::IOPattern::IOPattern( IOType iotype)
|
|||||||
ioType_(iotype),
|
ioType_(iotype),
|
||||||
globalSize_(processors::globalSize()),
|
globalSize_(processors::globalSize()),
|
||||||
globalRank_(processors::globalRank()),
|
globalRank_(processors::globalRank()),
|
||||||
isMaster_(processors::isMaster()),
|
isMaster_(processors::globalMaster()),
|
||||||
isParallel_(processors::isParallel())
|
isParallel_(processors::globalParallel())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
pFlow::word pFlow::IOPattern::exeMode()
|
pFlow::word pFlow::IOPattern::exeMode()
|
||||||
{
|
{
|
||||||
if(processors::isParallel())
|
return processors::globalRunTypeName();
|
||||||
return word("MPI");
|
|
||||||
else
|
|
||||||
return word("NoMPI");
|
|
||||||
}
|
}
|
@ -54,13 +54,13 @@ public:
|
|||||||
MasterProcessorOnly = 0,
|
MasterProcessorOnly = 0,
|
||||||
AllProcessorsSimilar = 1,
|
AllProcessorsSimilar = 1,
|
||||||
MasterProcessorDistribute = 4,
|
MasterProcessorDistribute = 4,
|
||||||
AllProcessorsDifferent = 8 // this is used for << and >> operators for
|
AllProcessorsDifferent = 8 // this is used for << and >> operators for
|
||||||
// standard input and output streams
|
// standard input and output streams
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
IOType ioType_;
|
IOType ioType_;
|
||||||
|
|
||||||
int globalSize_ = 1;
|
int globalSize_ = 1;
|
||||||
|
|
||||||
@ -116,11 +116,18 @@ public:
|
|||||||
return isParallel_;
|
return isParallel_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool thisCallRead()const
|
||||||
|
{
|
||||||
|
if(isMasterProcessorOnly() && !isMaster())return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
bool thisProcReadData()const
|
bool thisProcReadData()const
|
||||||
{
|
{
|
||||||
if(isMasterProcessorOnly() && !isMaster())return false;
|
if(isMasterProcessorOnly() && !isMaster())return false;
|
||||||
if(isMasterProcessorDistribute() && !isMaster()) return false;
|
if(isMasterProcessorDistribute()&& !isMaster())return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +135,7 @@ public:
|
|||||||
bool thisProcWriteData()const
|
bool thisProcWriteData()const
|
||||||
{
|
{
|
||||||
if(isAllProcessorsDifferent()) return true;
|
if(isAllProcessorsDifferent()) return true;
|
||||||
|
if(isMasterProcessorDistribute())return true;
|
||||||
return isMaster();
|
return isMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ Licence:
|
|||||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
#include "processors.hpp"
|
|
||||||
#include "IOfileHeader.hpp"
|
#include "IOfileHeader.hpp"
|
||||||
#include "repository.hpp"
|
#include "repository.hpp"
|
||||||
|
|
||||||
@ -31,13 +31,11 @@ pFlow::uniquePtr<pFlow::iFstream> pFlow::IOfileHeader::inStream()const
|
|||||||
|
|
||||||
pFlow::uniquePtr<pFlow::oFstream> pFlow::IOfileHeader::outStream()const
|
pFlow::uniquePtr<pFlow::oFstream> pFlow::IOfileHeader::outStream()const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
auto osPtr = makeUnique<oFstream>(path(), outFileBinary());
|
auto osPtr = makeUnique<oFstream>(path(), outFileBinary());
|
||||||
|
|
||||||
if(osPtr && owner_)
|
if(osPtr && owner())
|
||||||
{
|
{
|
||||||
auto outPrecision = owner_->outFilePrecision();
|
auto outPrecision = owner()->outFilePrecision();
|
||||||
osPtr->precision(outPrecision);
|
osPtr->precision(outPrecision);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,21 +44,19 @@ pFlow::uniquePtr<pFlow::oFstream> pFlow::IOfileHeader::outStream()const
|
|||||||
|
|
||||||
pFlow::IOfileHeader::IOfileHeader
|
pFlow::IOfileHeader::IOfileHeader
|
||||||
(
|
(
|
||||||
const objectFile& objf,
|
const objectFile& objf
|
||||||
const repository* owner
|
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
objectFile(objf),
|
objectFile(objf)
|
||||||
owner_(owner)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
pFlow::fileSystem pFlow::IOfileHeader::path() const
|
pFlow::fileSystem pFlow::IOfileHeader::path() const
|
||||||
{
|
{
|
||||||
fileSystem f;
|
fileSystem f;
|
||||||
|
|
||||||
if( owner_ )
|
if( owner() )
|
||||||
{
|
{
|
||||||
f = owner_->path()/localPath();
|
f = owner()->path()/localPath();
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
@ -72,8 +68,8 @@ pFlow::fileSystem pFlow::IOfileHeader::path() const
|
|||||||
|
|
||||||
bool pFlow::IOfileHeader::outFileBinary()const
|
bool pFlow::IOfileHeader::outFileBinary()const
|
||||||
{
|
{
|
||||||
if(owner_)
|
if(owner())
|
||||||
return owner_->outFileBinary();
|
return owner()->outFileBinary();
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -137,7 +133,6 @@ bool pFlow::IOfileHeader::writeHeader()const
|
|||||||
{
|
{
|
||||||
|
|
||||||
if( !this->readWriteHeader() ) return false;
|
if( !this->readWriteHeader() ) return false;
|
||||||
if( !processors::isMaster() ) return false;
|
|
||||||
if( !implyWrite() ) return false;
|
if( !implyWrite() ) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -185,15 +180,15 @@ bool pFlow::IOfileHeader::writeHeader(iOstream& os, bool forceWrite) const
|
|||||||
bool pFlow::IOfileHeader::readHeader()const
|
bool pFlow::IOfileHeader::readHeader()const
|
||||||
{
|
{
|
||||||
if( !implyRead())return false;
|
if( !implyRead())return false;
|
||||||
if( !this->readWriteHeader() ) return false;
|
if( !this->readWriteHeader() ) return false;
|
||||||
return ioPattern().thisProcReadHeader();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::IOfileHeader::readHeader(iIstream& is, bool silent)
|
bool pFlow::IOfileHeader::readHeader(iIstream& is, bool silent)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!readHeader()) return true;
|
|
||||||
|
|
||||||
|
if(!readHeader()) return true;
|
||||||
|
|
||||||
if( !is.findTokenAndNextSilent("objectName", objectName_) )
|
if( !is.findTokenAndNextSilent("objectName", objectName_) )
|
||||||
{
|
{
|
||||||
if(!silent)
|
if(!silent)
|
||||||
@ -231,18 +226,6 @@ bool pFlow::IOfileHeader::readHeader(iIstream& is, bool silent)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::IOfileHeader::writeData()const
|
|
||||||
{
|
|
||||||
if(!implyWrite())return false;
|
|
||||||
return ioPattern().thisProcWriteData();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool pFlow::IOfileHeader::readData()const
|
|
||||||
{
|
|
||||||
if(!implyRead())return false;
|
|
||||||
return ioPattern().thisProcReadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool pFlow::IOfileHeader::writeBanner(iOstream& os)const
|
bool pFlow::IOfileHeader::writeBanner(iOstream& os)const
|
||||||
{
|
{
|
||||||
os<<
|
os<<
|
||||||
|
@ -40,9 +40,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
//// - data members
|
//// - data members
|
||||||
// owner repository
|
|
||||||
const repository* owner_ = nullptr;
|
|
||||||
|
|
||||||
// object name read from file
|
// object name read from file
|
||||||
word objectName_;
|
word objectName_;
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
// with owner
|
// with owner
|
||||||
IOfileHeader(const objectFile& objf, const repository* owner = nullptr);
|
IOfileHeader(const objectFile& objf);
|
||||||
|
|
||||||
// - object name
|
// - object name
|
||||||
const word& objectName()const
|
const word& objectName()const
|
||||||
@ -78,11 +76,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// - pointer to owner repository
|
// - pointer to owner repository
|
||||||
const repository* owner()const
|
virtual
|
||||||
{
|
const repository* owner()const
|
||||||
return owner_;
|
{
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// - path to file name
|
// - path to file name
|
||||||
fileSystem path() const;
|
fileSystem path() const;
|
||||||
|
|
||||||
@ -118,18 +117,13 @@ public:
|
|||||||
/// Write the header to the file, typeName comes from the one read from file
|
/// Write the header to the file, typeName comes from the one read from file
|
||||||
bool writeHeader(iOstream& os, bool forceWrite = false) const;
|
bool writeHeader(iOstream& os, bool forceWrite = false) const;
|
||||||
|
|
||||||
/// Check if the data should be written to file
|
|
||||||
bool writeData()const;
|
|
||||||
|
|
||||||
/// Check if header should be read from file
|
/// Check if header should be read from file
|
||||||
bool readHeader()const;
|
bool readHeader()const;
|
||||||
|
|
||||||
/// Read the header in the file
|
/// Read the header in the file
|
||||||
bool readHeader(iIstream& is, bool silent=false);
|
bool readHeader(iIstream& is, bool silent=false);
|
||||||
|
|
||||||
/// Check if data should be read from file
|
|
||||||
/// Always return true
|
|
||||||
bool readData()const;
|
|
||||||
|
|
||||||
/// write the banner
|
/// write the banner
|
||||||
bool writeBanner(iOstream& os)const;
|
bool writeBanner(iOstream& os)const;
|
||||||
|
@ -24,53 +24,54 @@ Licence:
|
|||||||
|
|
||||||
pFlow::IOobject::IOobject
|
pFlow::IOobject::IOobject
|
||||||
(
|
(
|
||||||
const objectFile& objf,
|
const objectFile& objf,
|
||||||
const repository* owner,
|
const IOPattern& iop,
|
||||||
uniquePtr<iObject>&& obj
|
repository* owner
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
IOfileHeader(objf, owner),
|
IOfileHeader(objf),
|
||||||
object_(obj.release())
|
ioPattern_(iop),
|
||||||
|
owner_(owner)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!read(this->readWriteHeader()))
|
if(owner_&& !owner->addToRepository(this))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalExit;
|
||||||
"error in reading " << name() << " from path " << path()<<endl;
|
}
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pFlow::IOobject::~IOobject()
|
||||||
|
{
|
||||||
|
if(owner_)
|
||||||
|
{
|
||||||
|
owner_->removeFromRepository(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pFlow::IOobject::IOobject
|
pFlow::repository* pFlow::IOobject::releaseOwner
|
||||||
(
|
(
|
||||||
const objectFile& objf,
|
bool fromOwner
|
||||||
const repository* owner,
|
|
||||||
uniquePtr<IOobject>&& obj
|
|
||||||
)
|
)
|
||||||
:
|
{
|
||||||
IOfileHeader(objf, owner),
|
auto* old = owner_;
|
||||||
object_( obj->object_.release())
|
if(old && !fromOwner)
|
||||||
{
|
{
|
||||||
}
|
old->removeFromRepository(this);
|
||||||
|
}
|
||||||
|
owner_ = nullptr;
|
||||||
bool pFlow::IOobject::isObjectValid()const
|
return old;
|
||||||
{
|
|
||||||
return object_.get() != nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::IOobject::read(bool rdHdr)
|
bool pFlow::IOobject::read(bool rdHdr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if( implyRead() )
|
if( implyRead() )
|
||||||
{
|
{
|
||||||
if( rdHdr )
|
if( rdHdr & ioPattern().thisCallRead())
|
||||||
{
|
{
|
||||||
if( auto ptrIS = inStream(); ptrIS )
|
if( auto ptrIS = inStream(); ptrIS )
|
||||||
{
|
{
|
||||||
if(!readHeader(ptrIS()))return false;
|
if(!readHeader(ptrIS()))return false;
|
||||||
ptrIS.reset(nullptr);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -80,17 +81,20 @@ bool pFlow::IOobject::read(bool rdHdr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( auto ptrIS = inStream(); ptrIS )
|
if(ioPattern().thisCallRead())
|
||||||
{
|
{
|
||||||
if(!read(ptrIS(), rdHdr))return false;
|
if( auto ptrIS = inStream(); ptrIS )
|
||||||
|
{
|
||||||
}
|
if(!read(ptrIS(), rdHdr))return false;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
warningInFunction<<
|
{
|
||||||
"could not open file " << path() <<endl;
|
warningInFunction<<
|
||||||
return false;
|
"could not open file " << path() <<endl;
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -101,16 +105,19 @@ bool pFlow::IOobject::write() const
|
|||||||
{
|
{
|
||||||
if(implyWrite())
|
if(implyWrite())
|
||||||
{
|
{
|
||||||
if(auto ptrOS = outStream(); ptrOS )
|
if(ioPattern().thisProcWriteData())
|
||||||
{
|
{
|
||||||
return write(ptrOS());
|
if(auto ptrOS = outStream(); ptrOS )
|
||||||
}
|
{
|
||||||
else
|
return write(ptrOS());
|
||||||
{
|
}
|
||||||
warningInFunction<<
|
else
|
||||||
"error in opening file "<< path() <<endl;
|
{
|
||||||
return false;
|
warningInFunction<<
|
||||||
}
|
"error in opening file "<< path() <<endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -119,18 +126,34 @@ bool pFlow::IOobject::write() const
|
|||||||
|
|
||||||
bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
|
bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
|
||||||
{
|
{
|
||||||
if(rdHdr)
|
if(rdHdr && ioPattern().thisCallRead() )
|
||||||
{
|
{
|
||||||
if(!readHeader(is))return false;
|
if(!readHeader(is))return false;
|
||||||
}
|
}
|
||||||
return object_->read_object_t(is, ioPattern_);
|
|
||||||
|
if(ioPattern().thisCallRead())
|
||||||
|
{
|
||||||
|
return read(is, ioPattern());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool pFlow::IOobject::write(iOstream& os) const
|
bool pFlow::IOobject::write(iOstream& os) const
|
||||||
{
|
{
|
||||||
if(this->readWriteHeader())
|
if(this->writeHeader() && ioPattern().thisProcWriteHeader())
|
||||||
writeHeader(os, typeName());
|
writeHeader(os, typeName());
|
||||||
|
|
||||||
return (object_->write_object_t(os, ioPattern_) && writeSeparator(os));
|
if(ioPattern().thisProcWriteData())
|
||||||
|
{ //return (object_->write_object_t(os, ioPattern_) && writeSeparator(os));
|
||||||
|
notImplementedFunction;
|
||||||
|
//return object_->read_object_t(is, ioPattern_);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ Licence:
|
|||||||
|
|
||||||
|
|
||||||
#include "IOfileHeader.hpp"
|
#include "IOfileHeader.hpp"
|
||||||
|
#include "IOPattern.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
@ -36,177 +36,49 @@ class IOobject
|
|||||||
:
|
:
|
||||||
public IOfileHeader
|
public IOfileHeader
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
class iObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~iObject()=default;
|
|
||||||
|
|
||||||
// - clone
|
|
||||||
virtual uniquePtr<iObject> clone() const = 0;
|
|
||||||
|
|
||||||
virtual word typeName()const = 0;
|
|
||||||
|
|
||||||
virtual bool read_object_t(iIstream& is, IOPattern iop) = 0;
|
|
||||||
|
|
||||||
virtual bool write_object_t(iOstream& os, IOPattern iop)const = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename dataType>
|
|
||||||
class object_t
|
|
||||||
:
|
|
||||||
public iObject
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
dataType data_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
template<typename... Args,
|
|
||||||
typename = std::enable_if_t<std::is_constructible<dataType, Args&&...>::value>>
|
|
||||||
object_t(Args&&... args)
|
|
||||||
:
|
|
||||||
data_(std::forward<Args>(args)...)
|
|
||||||
{
|
|
||||||
/*constexpr word msg(dataType::TYPENAME()+"input is not a member function.")
|
|
||||||
static_assert(std::is_member_function_pointer<decltype(&dataType::write)>::value,
|
|
||||||
msg.c_str());*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// cunstruct by copying data
|
|
||||||
object_t(const dataType& data): data_(data)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
virtual uniquePtr<iObject> clone() const
|
|
||||||
{
|
|
||||||
return makeUnique<object_t>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual word typeName()const
|
|
||||||
{
|
|
||||||
return data_.typeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool read_object_t(iIstream& is, IOPattern iop) override
|
|
||||||
{
|
|
||||||
return data_.read(is, iop);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool write_object_t(iOstream& os, IOPattern iop)const override
|
|
||||||
{
|
|
||||||
return data_.write(os, iop);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& data()
|
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto& data()const
|
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//// - data members
|
IOPattern ioPattern_;
|
||||||
|
|
||||||
// underlaying data object
|
mutable repository* owner_;
|
||||||
uniquePtr<iObject> object_ = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// - typeinfo
|
// - typeinfo
|
||||||
word typeName()const
|
virtual
|
||||||
{
|
word typeName() const = 0;
|
||||||
return object_->typeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
//// - Constructors
|
//// - Constructors
|
||||||
|
|
||||||
// - construct from components, transfer the ownership of iObject (object_t) to the
|
// - construct from components, transfer the ownership of iObject (object_t) to the
|
||||||
// onwner and read the object from file
|
// onwner and read the object from file
|
||||||
IOobject(const objectFile& objf, const repository* owner, uniquePtr<iObject>&& obj );
|
IOobject(
|
||||||
|
const objectFile& objf,
|
||||||
// - construct from components, transfer the ownership of IOobject to the owner (no read happens)
|
const IOPattern& iop,
|
||||||
IOobject(const objectFile& objf, const repository* owner, uniquePtr<IOobject>&& obj);
|
repository* owner);
|
||||||
|
|
||||||
|
~IOobject();
|
||||||
template<typename T,
|
|
||||||
typename = std::enable_if_t<
|
|
||||||
!std::is_same<T, uniquePtr<IOobject::iObject>>::value &&
|
|
||||||
!std::is_same<T, uniquePtr<IOobject>>::value>>
|
|
||||||
IOobject(const objectFile& objf, const repository* owner, const T& data)
|
|
||||||
:
|
|
||||||
IOfileHeader(objf, owner),
|
|
||||||
object_(makeUnique<object_t<T>>(data))
|
|
||||||
{
|
|
||||||
if(!read(this->readWriteHeader()))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"error in reading " << name() << " from path " << path()<<endl;
|
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T,
|
|
||||||
typename = std::enable_if_t<
|
|
||||||
!std::is_same<T, uniquePtr<IOobject::iObject>>::value &&
|
|
||||||
!std::is_same<T, uniquePtr<IOobject>>::value>>
|
|
||||||
IOobject(const objectFile& objf, const repository* owner, T&& data)
|
|
||||||
:
|
|
||||||
IOfileHeader(objf, owner),
|
|
||||||
object_(makeUnique<object_t<T>>(data))
|
|
||||||
{
|
|
||||||
if(!read(this->readWriteHeader()))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"error in reading " << name() << " from path " << path()<<endl;
|
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// - copy construct
|
// - copy construct
|
||||||
IOobject(const IOobject& src)=delete;
|
IOobject(const IOobject& src)=delete;
|
||||||
|
|
||||||
// - move construct
|
// - move construct
|
||||||
IOobject(IOobject&& src) = default;
|
IOobject(IOobject&& src) = delete;
|
||||||
|
|
||||||
|
|
||||||
// - make object from components, considering no owner for this object, and
|
|
||||||
// read from file
|
|
||||||
// Args are the arguments of object constructor
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
static auto make(const objectFile& objf, Args&&... args);
|
|
||||||
|
|
||||||
// - construct object_t with the Args as the arguments of object constructor
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
static uniquePtr<iObject> make_object_t(Args&&... args);
|
|
||||||
|
|
||||||
|
|
||||||
//// - Access to data object
|
inline
|
||||||
|
const IOPattern& ioPattern()const
|
||||||
|
{
|
||||||
|
return ioPattern_;
|
||||||
|
}
|
||||||
|
|
||||||
// - is object valid
|
// - pointer to owner repository
|
||||||
bool isObjectValid()const;
|
const repository* owner()const override
|
||||||
|
{
|
||||||
|
return owner_;
|
||||||
|
}
|
||||||
|
|
||||||
// - ref to data object
|
repository* releaseOwner(bool fromOwner = false);
|
||||||
template<typename T>
|
|
||||||
auto& getObject();
|
|
||||||
|
|
||||||
// - const ref to data object
|
|
||||||
template<typename T>
|
|
||||||
const auto& getObject()const;
|
|
||||||
|
|
||||||
|
|
||||||
//// - IO operations
|
//// - IO operations
|
||||||
|
|
||||||
@ -221,7 +93,12 @@ public:
|
|||||||
|
|
||||||
// - write to istream
|
// - write to istream
|
||||||
bool write(iOstream& os) const;
|
bool write(iOstream& os) const;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool write(iOstream& is, const IOPattern& iop)const = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool read(iIstream& is, const IOPattern& iop) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ Licence:
|
|||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
/*template<typename T, typename... Args>
|
||||||
auto pFlow::IOobject::make
|
auto pFlow::IOobject::make
|
||||||
(
|
(
|
||||||
const objectFile& objf,
|
const objectFile& objf,
|
||||||
@ -62,4 +62,4 @@ const auto& pFlow::IOobject::getObject()const
|
|||||||
fatalExit;
|
fatalExit;
|
||||||
}
|
}
|
||||||
return static_cast<const object_t<T>&>(*object_).data();
|
return static_cast<const object_t<T>&>(*object_).data();
|
||||||
}
|
}*/
|
@ -34,15 +34,13 @@ pFlow::objectFile::objectFile
|
|||||||
const fileSystem& localPath,
|
const fileSystem& localPath,
|
||||||
const readFlag& rf,
|
const readFlag& rf,
|
||||||
const writeFlag& wf,
|
const writeFlag& wf,
|
||||||
IOPattern::IOType ioType,
|
bool rwHeader
|
||||||
bool rwHdr
|
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
name_(name),
|
name_(name),
|
||||||
rFlag_(rf),
|
rFlag_(rf),
|
||||||
wFlag_(wf),
|
wFlag_(wf),
|
||||||
localPath_(localPath),
|
localPath_(localPath),
|
||||||
ioPattern_(ioType),
|
readWriteHeader_(rwHeader)
|
||||||
readWriteHeader_(rwHdr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -23,14 +23,10 @@ Licence:
|
|||||||
|
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "fileSystem.hpp"
|
#include "fileSystem.hpp"
|
||||||
#include "IOPattern.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class objectFile
|
class objectFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -66,10 +62,8 @@ protected:
|
|||||||
/// Number of bytes used for writing/reading real variable (used for binray)
|
/// Number of bytes used for writing/reading real variable (used for binray)
|
||||||
int numBytesForReal_ = numBytesForReal__;
|
int numBytesForReal_ = numBytesForReal__;
|
||||||
|
|
||||||
IOPattern ioPattern_ = {IOPattern::MasterProcessorOnly};
|
/// Does the objectFile read & write the header?
|
||||||
|
bool readWriteHeader_ = true;
|
||||||
/// Does the objectFile write the header or not
|
|
||||||
bool readWriteHeader_ = true;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -88,8 +82,7 @@ public:
|
|||||||
const fileSystem& localPath,
|
const fileSystem& localPath,
|
||||||
const readFlag& rf = READ_NEVER,
|
const readFlag& rf = READ_NEVER,
|
||||||
const writeFlag& wf = WRITE_NEVER,
|
const writeFlag& wf = WRITE_NEVER,
|
||||||
IOPattern::IOType ioType = IOPattern::MasterProcessorOnly,
|
bool rwHeader = true
|
||||||
bool rwHdr = true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// copy construct
|
// copy construct
|
||||||
@ -156,11 +149,6 @@ public:
|
|||||||
return wFlag_ == WRITE_NEVER;
|
return wFlag_ == WRITE_NEVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IOPattern& ioPattern()const
|
|
||||||
{
|
|
||||||
return ioPattern_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
bool readWriteHeader()const
|
bool readWriteHeader()const
|
||||||
{
|
{
|
||||||
|
@ -104,6 +104,11 @@ pFlow::Time::Time(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pFlow::fileSystem pFlow::Time::localPath()const
|
||||||
|
{
|
||||||
|
return fileSystem(timeName());
|
||||||
|
}
|
||||||
|
|
||||||
bool pFlow::Time::write
|
bool pFlow::Time::write
|
||||||
(
|
(
|
||||||
bool verbose
|
bool verbose
|
||||||
|
@ -70,10 +70,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//// - Methods
|
//// - Methods
|
||||||
virtual fileSystem localPath()const
|
fileSystem localPath()const override;
|
||||||
{
|
|
||||||
return fileSystem(timeName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// - geometry repository
|
// - geometry repository
|
||||||
const repository& geometry()const
|
const repository& geometry()const
|
||||||
|
@ -18,7 +18,6 @@ Licence:
|
|||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#include "repository.hpp"
|
#include "repository.hpp"
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ pFlow::repository::repository
|
|||||||
localPath_(localPath),
|
localPath_(localPath),
|
||||||
owner_(owner)
|
owner_(owner)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(owner)
|
if(owner)
|
||||||
{
|
{
|
||||||
owner->addToRepository(this);
|
owner->addToRepository(this);
|
||||||
@ -42,10 +41,20 @@ pFlow::repository::repository
|
|||||||
|
|
||||||
pFlow::repository::~repository()
|
pFlow::repository::~repository()
|
||||||
{
|
{
|
||||||
if(owner_)
|
for(auto& objcs: objects_)
|
||||||
|
{
|
||||||
|
objcs.second->releaseOwner(true);
|
||||||
|
}
|
||||||
|
for(auto& reps: repositories_)
|
||||||
|
{
|
||||||
|
reps.second->releaseOwner(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(owner_)
|
||||||
{
|
{
|
||||||
owner_->removeRepository(this);
|
owner_->removeFromRepository(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::word pFlow::repository::name()const
|
pFlow::word pFlow::repository::name()const
|
||||||
@ -106,26 +115,57 @@ bool pFlow::repository::addToRepository(repository* rep)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::repository::removeRepository(repository* rep)
|
bool pFlow::repository::removeFromRepository(repository* rep)
|
||||||
{
|
{
|
||||||
auto name = rep->name();
|
auto name = rep->name();
|
||||||
return repositories_.erase(name) == 1;
|
return repositories_.erase(name) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pFlow::repository::removeFromRepository(IOobject *io)
|
||||||
|
{
|
||||||
|
auto name = io->name();
|
||||||
|
return objects_.erase(name) == 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::repository *pFlow::repository::releaseOwner(bool fromOwner)
|
||||||
|
{
|
||||||
|
auto* old = owner_;
|
||||||
|
if(old && !fromOwner)
|
||||||
|
{
|
||||||
|
old->removeFromRepository(this);
|
||||||
|
}
|
||||||
|
owner_ = nullptr;
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::repository::addToRepository(IOobject* io)
|
||||||
|
{
|
||||||
|
if( !objects_.insertIf(io->name(), io ) )
|
||||||
|
{
|
||||||
|
warningInFunction<<
|
||||||
|
"Failed to add repository " << io->name() <<
|
||||||
|
" to repository " << this->name() <<
|
||||||
|
". It is already in this repository. \n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool pFlow::repository::lookupObjectName(const word& nm)const
|
bool pFlow::repository::lookupObjectName(const word& nm)const
|
||||||
{
|
{
|
||||||
return objects_.search(nm);
|
return objects_.search(nm);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::word pFlow::repository::lookupObjectTypeName(
|
pFlow::word pFlow::repository::lookupObjectTypeName
|
||||||
|
(
|
||||||
const word& nm
|
const word& nm
|
||||||
)const
|
)const
|
||||||
{
|
{
|
||||||
if(auto [iter, found] = objects_.findIf(nm); found)
|
if(auto [iter, found] = objects_.findIf(nm); found)
|
||||||
{
|
{
|
||||||
return iter->second.typeName();
|
return iter->second->typeName();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -143,13 +183,11 @@ bool pFlow::repository::globalLookupObjectName
|
|||||||
)const
|
)const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!downward)
|
if(!downward)
|
||||||
{
|
{
|
||||||
// the object to start search and its owner
|
// the object to start search and its owner
|
||||||
auto object = this;
|
auto* object = this;
|
||||||
auto owner = object->owner();
|
auto* owner = object->owner();
|
||||||
|
|
||||||
// get to the top-most repository
|
// get to the top-most repository
|
||||||
while(!owner)
|
while(!owner)
|
||||||
@ -245,10 +283,10 @@ bool pFlow::repository::write
|
|||||||
{
|
{
|
||||||
if(verbose)
|
if(verbose)
|
||||||
{
|
{
|
||||||
REPORT(1)<< "Writing to " << obj.second.path()<<END_REPORT;
|
REPORT(1)<< "Writing to " << obj.second->path()<<END_REPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!obj.second.write())
|
if(!obj.second->write())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ protected:
|
|||||||
repository* owner_;
|
repository* owner_;
|
||||||
|
|
||||||
// - sorted names of objects with object index in vector of objects
|
// - sorted names of objects with object index in vector of objects
|
||||||
wordMap<IOobject> objects_;
|
wordMap<IOobject*> objects_;
|
||||||
|
|
||||||
// - list of repositories that this repository owns
|
// - list of repositories that this repository owns
|
||||||
// - it is not a managed list of pointers!
|
// - it is not a managed list of pointers!
|
||||||
@ -100,61 +100,20 @@ public:
|
|||||||
// - ref to this repository
|
// - ref to this repository
|
||||||
repository& thisRepository();
|
repository& thisRepository();
|
||||||
|
|
||||||
// - add rep to this repository
|
/// @brief add repository to this repository
|
||||||
// return false if the name already exists
|
/// return false if the name already exists
|
||||||
bool addToRepository(repository* rep);
|
bool addToRepository(repository* rep);
|
||||||
|
|
||||||
// - remove rep from the list of repositories
|
/// @brief remove rep from the list of repositories
|
||||||
bool removeRepository(repository* rep);
|
bool removeFromRepository(repository* rep);
|
||||||
|
|
||||||
|
|
||||||
//// - Add/remove objects
|
/// @brief add IOobject to this repository
|
||||||
|
bool addToRepository(IOobject* io);
|
||||||
// - insert the object into repository if it does not exist
|
|
||||||
// return a refernce to underlying data object, this reference never invalidated
|
|
||||||
// until it is deleted from repository.
|
|
||||||
// issue a fatal error if it is already exists
|
|
||||||
// ** one time construction and no move/copy of object **
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
T& emplaceObject(const objectFile& objf, Args&&... args);
|
|
||||||
|
|
||||||
// - insert the object into repository if it does not exist
|
|
||||||
// return a refernce to underlying data object, this reference never invalidated
|
|
||||||
// until it is deleted from repository.
|
|
||||||
// - if the object already exist, after type check(if consistent), return the
|
|
||||||
// reference of the existing object and create no new object.
|
|
||||||
// ** one time construction and no move/copy of object **
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
T& emplaceObjectOrGet(const objectFile& objf, Args&&... args);
|
|
||||||
|
|
||||||
// - insert the object into repository and replace if it already exists (old object is destroyed)
|
|
||||||
// return a refernce to underlying data object, this reference never invalidated
|
|
||||||
// until it is deleted from repository.
|
|
||||||
// ** one time construction and no move/copy of object **
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
T& emplaceReplaceObject(const objectFile& objf, Args&&... args);
|
|
||||||
|
|
||||||
|
|
||||||
// - Insert_or_replace the IOobejct into repository and change its ownership
|
|
||||||
// to this repository, take effect only if the object does not belong to
|
|
||||||
// any other repository
|
|
||||||
template<typename T>
|
|
||||||
T& insertReplaceObject(uniquePtr<IOobject>&& ptr );
|
|
||||||
|
|
||||||
|
|
||||||
// - Insert_or_replace the IOobejct into repository with new objectFile and
|
|
||||||
// change the ownership to this repository, take effect only if the object
|
|
||||||
// does not belong to any other repository
|
|
||||||
template<typename T>
|
|
||||||
T& insertReplaceObject(const objectFile& objf, uniquePtr<IOobject>&& ptr );
|
|
||||||
|
|
||||||
// - rease an object from this repository
|
|
||||||
bool eraseObject(const word& name)
|
|
||||||
{
|
|
||||||
return objects_.erase(name) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// @brief remove rep from the list of repositories
|
||||||
|
bool removeFromRepository(IOobject* io);
|
||||||
|
|
||||||
|
repository* releaseOwner(bool fromOwner = false);
|
||||||
//// - lookups and queries
|
//// - lookups and queries
|
||||||
|
|
||||||
// - check if name of object exists
|
// - check if name of object exists
|
||||||
|
@ -17,22 +17,7 @@ Licence:
|
|||||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
template <typename Type1>
|
|
||||||
pFlow::word pFlow::repository::reportTypeError (IOobject& object)
|
|
||||||
{
|
|
||||||
word err;
|
|
||||||
err = "The requested object " + object.name() + " with type " + Type1::TYPENAME() + ", while the type " +
|
|
||||||
object.typeName() + "is found in repository " + this->name();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
bool pFlow::repository::checkForObjectType(IOobject& object)
|
|
||||||
{
|
|
||||||
return Type::TYPENAME() == object.typeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
T& pFlow::repository::emplaceObject(const objectFile& objf, Args&&... args)
|
T& pFlow::repository::emplaceObject(const objectFile& objf, Args&&... args)
|
||||||
@ -142,6 +127,25 @@ T& pFlow::repository::insertReplaceObject(const objectFile& objf, uniquePtr<IOob
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <typename Type1>
|
||||||
|
pFlow::word pFlow::repository::reportTypeError(IOobject& object)
|
||||||
|
{
|
||||||
|
word err;
|
||||||
|
err = "Object " + object.name() + " with type " + Type1::TYPENAME() +
|
||||||
|
"is requested, while the type " +
|
||||||
|
object.typeName() + "is found in repository " + this->name()+".";
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
bool pFlow::repository::checkForObjectType(IOobject& object)
|
||||||
|
{
|
||||||
|
return Type::TYPENAME() == object.typeName();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& pFlow::repository::lookupObject(const word& name)
|
T& pFlow::repository::lookupObject(const word& name)
|
||||||
{
|
{
|
||||||
@ -150,14 +154,15 @@ T& pFlow::repository::lookupObject(const word& name)
|
|||||||
|
|
||||||
if( checkType<T>(iter->second) )
|
if( checkType<T>(iter->second) )
|
||||||
{
|
{
|
||||||
return iter->second.template getObject<T>();
|
return static_cast<T&>(iter->second);
|
||||||
|
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
fatalErrorInFunction <<
|
fatalErrorInFunction <<
|
||||||
reportTypeError<T>(iter->second)<<endl;
|
reportTypeError<T>(iter->second)<<endl;
|
||||||
fatalExit;
|
fatalExit;
|
||||||
return iter->second.template getObject<T>();
|
return static_cast<T&>(iter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
/*------------------------------- 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 __Control_hpp__
|
|
||||||
#define __Control_hpp__
|
|
||||||
|
|
||||||
|
|
||||||
// top-level entity repository for the whole application
|
|
||||||
// Each application that is executed in pFlow, should have
|
|
||||||
// settings/systemControl file in it.
|
|
||||||
// This repository holds two main repositories: Time and settings
|
|
||||||
|
|
||||||
#include "systemControl.hpp"
|
|
||||||
#include "timeFolder.hpp"
|
|
||||||
|
|
||||||
namespace pFlow
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
inline systemControl& Control()
|
|
||||||
{
|
|
||||||
static systemControl control_;
|
|
||||||
return control_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // pFlow
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __Control_hpp__
|
|
@ -25,6 +25,24 @@ Licence:
|
|||||||
#include "systemControl.hpp"
|
#include "systemControl.hpp"
|
||||||
#include "vocabs.hpp"
|
#include "vocabs.hpp"
|
||||||
|
|
||||||
|
bool pFlow::systemControl::readDomainDict()
|
||||||
|
{
|
||||||
|
if(!domainDict_)
|
||||||
|
{
|
||||||
|
domainDict_ = makeUnique<fileDictionary>
|
||||||
|
(
|
||||||
|
objectFile
|
||||||
|
(
|
||||||
|
domainFile__,
|
||||||
|
"",
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_NEVER
|
||||||
|
),
|
||||||
|
&settings()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
pFlow::word pFlow::systemControl::getRunName
|
pFlow::word pFlow::systemControl::getRunName
|
||||||
(
|
(
|
||||||
@ -108,55 +126,58 @@ pFlow::systemControl::systemControl
|
|||||||
(
|
(
|
||||||
getTopFolder(path)
|
getTopFolder(path)
|
||||||
),
|
),
|
||||||
settings_
|
settingsDict_
|
||||||
(
|
(
|
||||||
settingsRepository__,
|
makeUnique<fileDictionary>
|
||||||
settingsFolder__,
|
(
|
||||||
this
|
objectFile
|
||||||
),
|
(
|
||||||
caseSetup_
|
settingsFile__,
|
||||||
(
|
settingsFolder__,
|
||||||
caseSetupRepository__,
|
objectFile::READ_ALWAYS,
|
||||||
caseSetupFolder__,
|
objectFile::WRITE_NEVER
|
||||||
this
|
),
|
||||||
),
|
this
|
||||||
settingsDict_
|
)
|
||||||
(
|
),
|
||||||
settings().emplaceObject<fileDictionary>
|
Time_
|
||||||
(
|
|
||||||
objectFile
|
|
||||||
(
|
|
||||||
settingsFile__,
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_NEVER,
|
|
||||||
IOPattern::AllProcessorsSimilar
|
|
||||||
),
|
|
||||||
settingsFile__
|
|
||||||
)
|
|
||||||
),
|
|
||||||
libs_(settingsDict_),
|
|
||||||
outFilePrecision_(
|
|
||||||
settingsDict_.getValOrSet("outFilePrecision", static_cast<uint64>(6))
|
|
||||||
),
|
|
||||||
Time_
|
|
||||||
(
|
(
|
||||||
this,
|
this,
|
||||||
settingsDict_
|
settingsDict_()
|
||||||
),
|
),
|
||||||
g_(
|
settings_
|
||||||
settingsDict_.getVal<realx3>("g")
|
(
|
||||||
|
makeUnique<repository>
|
||||||
|
(
|
||||||
|
settingsRepository__,
|
||||||
|
settingsFolder__,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
),
|
||||||
|
caseSetup_
|
||||||
|
(
|
||||||
|
makeUnique<repository>
|
||||||
|
(
|
||||||
|
caseSetupRepository__,
|
||||||
|
caseSetupFolder__,
|
||||||
|
this
|
||||||
|
)
|
||||||
),
|
),
|
||||||
domain_(
|
|
||||||
settingsDict_.subDict("domain")
|
libs_(settingsDict_()),
|
||||||
|
outFilePrecision_
|
||||||
|
(
|
||||||
|
settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
|
||||||
),
|
),
|
||||||
timers_(runName_),
|
timers_(runName_),
|
||||||
timersReport_
|
timersReport_
|
||||||
(
|
(
|
||||||
settingsDict_.getValOrSet("timersReport", Logical("Yes"))
|
settingsDict_().getValOrSet("timersReport", Logical("Yes"))
|
||||||
),
|
),
|
||||||
writeToFileTimer_("Write to file", &timers_)
|
writeToFileTimer_("Write to file", &timers_)
|
||||||
{}
|
{
|
||||||
|
readDomainDict();
|
||||||
|
}
|
||||||
|
|
||||||
pFlow::systemControl::systemControl(
|
pFlow::systemControl::systemControl(
|
||||||
const real startTime,
|
const real startTime,
|
||||||
@ -179,71 +200,62 @@ pFlow::systemControl::systemControl(
|
|||||||
(
|
(
|
||||||
getTopFolder(path)
|
getTopFolder(path)
|
||||||
),
|
),
|
||||||
settings_
|
settingsDict_
|
||||||
(
|
(
|
||||||
settingsRepository__,
|
makeUnique<fileDictionary>
|
||||||
settingsFolder__,
|
(
|
||||||
this
|
objectFile
|
||||||
),
|
(
|
||||||
caseSetup_
|
settingsFile__,
|
||||||
(
|
settingsFolder__,
|
||||||
caseSetupRepository__,
|
objectFile::READ_ALWAYS,
|
||||||
caseSetupFolder__,
|
objectFile::WRITE_NEVER
|
||||||
this
|
),
|
||||||
),
|
this
|
||||||
settingsDict_
|
)
|
||||||
(
|
),
|
||||||
settings().emplaceObject<fileDictionary>
|
Time_
|
||||||
(
|
|
||||||
objectFile
|
|
||||||
(
|
|
||||||
settingsFile__,
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_NEVER
|
|
||||||
),
|
|
||||||
settingsFile__
|
|
||||||
)
|
|
||||||
),
|
|
||||||
libs_(settingsDict_),
|
|
||||||
Time_
|
|
||||||
(
|
(
|
||||||
this,
|
this,
|
||||||
settingsDict_,
|
settingsDict_(),
|
||||||
startTime,
|
startTime,
|
||||||
endTime,
|
endTime,
|
||||||
saveInterval,
|
saveInterval,
|
||||||
startTimeName
|
startTimeName
|
||||||
),
|
),
|
||||||
|
settings_
|
||||||
|
(
|
||||||
|
makeUnique<repository>
|
||||||
|
(
|
||||||
|
settingsRepository__,
|
||||||
|
settingsFolder__,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
),
|
||||||
|
caseSetup_
|
||||||
|
(
|
||||||
|
makeUnique<repository>
|
||||||
|
(
|
||||||
|
caseSetupRepository__,
|
||||||
|
caseSetupFolder__,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
),
|
||||||
|
libs_(settingsDict_()),
|
||||||
externalTimeControl_(true),
|
externalTimeControl_(true),
|
||||||
g_(
|
|
||||||
settingsDict_.getVal<realx3>("g")
|
|
||||||
),
|
|
||||||
domain_(
|
|
||||||
settingsDict_.subDict("domain")
|
|
||||||
),
|
|
||||||
timers_(runName_),
|
timers_(runName_),
|
||||||
timersReport_
|
timersReport_
|
||||||
(
|
(
|
||||||
settingsDict_.getValOrSet("timersReport", Logical("Yes"))
|
settingsDict_->getValOrSet("timersReport", Logical("Yes"))
|
||||||
),
|
),
|
||||||
writeToFileTimer_("Write to file", &timers_)
|
writeToFileTimer_("Write to file", &timers_)
|
||||||
{}
|
{
|
||||||
|
readDomainDict();
|
||||||
|
}
|
||||||
|
|
||||||
pFlow::fileDictionary& pFlow::systemControl::domainDict()
|
pFlow::fileDictionary& pFlow::systemControl::domainDict()
|
||||||
{
|
{
|
||||||
return
|
return domainDict_();
|
||||||
settings().emplaceObjectOrGet<fileDictionary>
|
|
||||||
(
|
|
||||||
objectFile
|
|
||||||
(
|
|
||||||
domainFile__,
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_NEVER
|
|
||||||
),
|
|
||||||
domainFile__
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::systemControl::operator ++(int)
|
bool pFlow::systemControl::operator ++(int)
|
||||||
|
@ -50,35 +50,29 @@ protected:
|
|||||||
// - path to top-level folder
|
// - path to top-level folder
|
||||||
const fileSystem topLevelFolder_;
|
const fileSystem topLevelFolder_;
|
||||||
|
|
||||||
|
/// settingsDict fileDictionary
|
||||||
|
uniquePtr<fileDictionary> settingsDict_;
|
||||||
|
|
||||||
|
/// time repository
|
||||||
|
Time Time_;
|
||||||
|
|
||||||
/// settings folder repository
|
/// settings folder repository
|
||||||
repository settings_;
|
uniquePtr<repository> settings_;
|
||||||
|
|
||||||
/// caseSetup folder repository
|
/// caseSetup folder repository
|
||||||
repository caseSetup_;
|
uniquePtr<repository> caseSetup_;
|
||||||
|
|
||||||
/// settingsDict fileDictionary
|
uniquePtr<fileDictionary> domainDict_ = nullptr;
|
||||||
fileDictionary& settingsDict_;
|
|
||||||
|
|
||||||
/// extra libs to be loaded
|
/// extra libs to be loaded
|
||||||
dynamicLinkLibs libs_;
|
dynamicLinkLibs libs_;
|
||||||
|
|
||||||
/// precision for writing to file
|
/// precision for writing to file
|
||||||
size_t outFilePrecision_ = 6;
|
size_t outFilePrecision_ = 6;
|
||||||
|
|
||||||
/// time repository
|
|
||||||
Time Time_;
|
|
||||||
|
|
||||||
/// if time control is managed externaly
|
/// if time control is managed externaly
|
||||||
|
bool externalTimeControl_ = false;
|
||||||
bool externalTimeControl_ = false;
|
|
||||||
|
|
||||||
// - acceleration
|
|
||||||
realx3 g_;
|
|
||||||
|
|
||||||
// - domain for dem world
|
|
||||||
box domain_;
|
|
||||||
|
|
||||||
// all timers
|
// all timers
|
||||||
Timers timers_;
|
Timers timers_;
|
||||||
@ -87,6 +81,8 @@ protected:
|
|||||||
|
|
||||||
Timer writeToFileTimer_;
|
Timer writeToFileTimer_;
|
||||||
|
|
||||||
|
bool readDomainDict();
|
||||||
|
|
||||||
static word getRunName( const fileSystem& path);
|
static word getRunName( const fileSystem& path);
|
||||||
|
|
||||||
static word getTopFolder(const fileSystem& path);
|
static word getTopFolder(const fileSystem& path);
|
||||||
@ -104,25 +100,25 @@ public:
|
|||||||
const fileSystem path = CWD() );
|
const fileSystem path = CWD() );
|
||||||
|
|
||||||
const repository& settings() const{
|
const repository& settings() const{
|
||||||
return settings_;
|
return settings_();
|
||||||
}
|
}
|
||||||
|
|
||||||
repository& settings(){
|
repository& settings(){
|
||||||
return settings_;
|
return settings_();
|
||||||
}
|
}
|
||||||
|
|
||||||
const repository& caseSetup()const{
|
const repository& caseSetup()const{
|
||||||
return caseSetup_;
|
return caseSetup_();
|
||||||
}
|
}
|
||||||
|
|
||||||
repository& caseSetup(){
|
repository& caseSetup(){
|
||||||
return caseSetup_;
|
return caseSetup_();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Time& time() const
|
const Time& time() const
|
||||||
{
|
{
|
||||||
return const_cast<Time&>(Time_);
|
return Time_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Time& time()
|
Time& time()
|
||||||
@ -156,11 +152,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fileDictionary& settingsDict()const{
|
const fileDictionary& settingsDict()const{
|
||||||
return settingsDict_;
|
return settingsDict_();
|
||||||
}
|
}
|
||||||
|
|
||||||
fileDictionary& settingsDict(){
|
fileDictionary& settingsDict(){
|
||||||
return settingsDict_;
|
return settingsDict_();
|
||||||
}
|
}
|
||||||
|
|
||||||
fileDictionary& domainDict();
|
fileDictionary& domainDict();
|
||||||
@ -171,14 +167,14 @@ public:
|
|||||||
return runName_;
|
return runName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const realx3& g()const
|
inline const realx3 g()const
|
||||||
{
|
{
|
||||||
return g_;
|
return settingsDict_().getVal<realx3>("g");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const box& domain()const
|
inline box domain()
|
||||||
{
|
{
|
||||||
return domain_;
|
return box(domainDict().subDict("globalBox"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ++(int);
|
bool operator ++(int);
|
||||||
|
35
src/phasicFlow/streams/dataIO/createDataIO.hpp
Normal file
35
src/phasicFlow/streams/dataIO/createDataIO.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef __createDataIO_hpp__
|
||||||
|
#define __createDataIO_hpp__
|
||||||
|
|
||||||
|
#include "uniquePtr.hpp"
|
||||||
|
#include "dataIO.hpp"
|
||||||
|
#include "dataIORegular.hpp"
|
||||||
|
#include "dataIOMPI.hpp"
|
||||||
|
|
||||||
|
namespace pFlow
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
uniquePtr<dataIO<T>> createDataIO(
|
||||||
|
const word& runType, const IOPattern& iop)
|
||||||
|
{
|
||||||
|
if(runType == "regular")
|
||||||
|
{
|
||||||
|
return makeUnique<dataIORegular<T>>(iop);
|
||||||
|
}
|
||||||
|
else if(runType == "MPI")
|
||||||
|
{
|
||||||
|
return makeUnique<dataIOMPI<T>>(iop);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<< "not dataIO pattern is specified for this "<<
|
||||||
|
runType<<endl;
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,34 +0,0 @@
|
|||||||
|
|
||||||
#include "dataIO.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
pFlow::uniquePtr<pFlow::dataIO> pFlow::dataIO::create
|
|
||||||
(
|
|
||||||
IOPattern::IOType iotype,
|
|
||||||
word exeMode
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto ioMode = angleBracketsNames("dataIO", exeMode);
|
|
||||||
|
|
||||||
if( wordvCtorSelector_.search(ioMode) )
|
|
||||||
{
|
|
||||||
auto objPtr = wordvCtorSelector_[ioMode]
|
|
||||||
(
|
|
||||||
iotype,
|
|
||||||
exeMode
|
|
||||||
);
|
|
||||||
return objPtr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printKeys
|
|
||||||
(
|
|
||||||
fatalError << "Ctor Selector "<< Yellow_Text(ioMode) << " dose not exist. \n"
|
|
||||||
<<"Avaiable ones are: \n\n"
|
|
||||||
,
|
|
||||||
wordvCtorSelector_
|
|
||||||
);
|
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
@ -9,49 +9,37 @@
|
|||||||
#include "IOPattern.hpp"
|
#include "IOPattern.hpp"
|
||||||
#include "iOstream.hpp"
|
#include "iOstream.hpp"
|
||||||
#include "iIstream.hpp"
|
#include "iIstream.hpp"
|
||||||
#include "virtualConstructor.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
class fileSystem;
|
template<typename T>
|
||||||
|
|
||||||
|
|
||||||
class dataIO
|
class dataIO
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
static inline const uint64 ErrorReturn = static_cast<uint64>(-1);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
IOPattern ioPattern_;
|
IOPattern ioPattern_;
|
||||||
|
|
||||||
word executionMode_;
|
std::vector<T> buffer_;
|
||||||
|
|
||||||
span<char> buffer_;
|
span<T> bufferSpan_;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
span<char> createSpan( span<T> sp )
|
/// gather data from all processors and put the results in buffer_
|
||||||
{
|
virtual bool gatherData(span<T> data) = 0;
|
||||||
return span<char>( reinterpret_cast<char*>(sp.data()), sp.size()*sizeof(T) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Type info
|
/// Type info
|
||||||
TypeInfo("dataIO");
|
TypeInfo("dataIO");
|
||||||
|
|
||||||
dataIO(IOPattern::IOType iotype, word exeMode)
|
dataIO(const IOPattern& iop)
|
||||||
:
|
:
|
||||||
ioPattern_(iotype),
|
ioPattern_(iop)
|
||||||
executionMode_(exeMode)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
dataIO(const dataIO&) = default;
|
dataIO(const dataIO&) = default;
|
||||||
|
|
||||||
dataIO(dataIO &&) = default;
|
dataIO(dataIO &&) = default;
|
||||||
@ -62,199 +50,24 @@ public:
|
|||||||
|
|
||||||
virtual ~dataIO() = default;
|
virtual ~dataIO() = default;
|
||||||
|
|
||||||
create_vCtor
|
|
||||||
(
|
|
||||||
dataIO,
|
|
||||||
word,
|
|
||||||
(
|
|
||||||
IOPattern::IOType iotype,
|
|
||||||
word exeMode
|
|
||||||
),
|
|
||||||
(iotype, exeMode)
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Gather data from all processors and put the results in
|
|
||||||
/// buffer_
|
|
||||||
virtual bool gatherData(span<char> sp ) = 0;
|
|
||||||
|
|
||||||
/// Write data to the end of file from all processors.
|
/// Write data to the end of file from all processors.
|
||||||
/// This method should be called from all processors.
|
/// This method should be called from all processors.
|
||||||
template<typename T>
|
|
||||||
bool writeData(iOstream& os, span<T> data);
|
bool writeData(iOstream& os, span<T> data);
|
||||||
|
|
||||||
template<typename T>
|
bool readData(
|
||||||
bool readData(iIstream& is, std::vector<T>& data);
|
iIstream& is,
|
||||||
|
std::vector<T>& data);
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool readAscii(
|
bool readAscii(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
std::vector<T>& vec );
|
std::vector<T>& vec );
|
||||||
|
|
||||||
static
|
|
||||||
uniquePtr<dataIO> create(IOPattern::IOType iotype, word exeMode);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline
|
|
||||||
bool dataIO::writeData<word>(iOstream& os, span<word> data)
|
|
||||||
{
|
|
||||||
/*std::ostringstream ist();
|
|
||||||
|
|
||||||
for(auto i=0; i<data.size(); i++)
|
|
||||||
{
|
|
||||||
ist<< data[i]<<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
span<char> sp(ist.str().data(), ist.str().size());
|
|
||||||
|
|
||||||
if(!gatherData( sp) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"Error in gathering data for out stream "<< os.name()<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64 len = buffer_.size();
|
|
||||||
os<< len << endl;
|
|
||||||
|
|
||||||
if(!os.write(buffer_.data(), buffer_.size()))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"error in writing binary data to "<<os.name()<<endl;
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if( !data.writeASCII(os) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"error in writing ASCII data to "<<os.name()<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "dataIOTemplate.cpp"
|
#include "dataIOTemplate.cpp"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*bool writeDataToFileEndSTD(
|
|
||||||
const word& wordPath,
|
|
||||||
const span<unsigned char>& data);
|
|
||||||
|
|
||||||
bool writeDataToFileEndMPI(
|
|
||||||
const word& wordPath,
|
|
||||||
const span<unsigned char>& data);
|
|
||||||
|
|
||||||
bool readDataSTD(
|
|
||||||
const word& wordPath,
|
|
||||||
const std::vector<uint64> chunkSizes,
|
|
||||||
span<unsigned char>& data,
|
|
||||||
uint64 binaryBlockStart);
|
|
||||||
|
|
||||||
bool readDataMPI(
|
|
||||||
const word& wordPath,
|
|
||||||
const std::vector<uint64> chunkSizes,
|
|
||||||
span<unsigned char>& data,
|
|
||||||
uint64 binaryBlockStart);
|
|
||||||
|
|
||||||
bool readMetaMPI(
|
|
||||||
const word& wordPath,
|
|
||||||
std::vector<uint64>& chunkSizes,
|
|
||||||
uint64 startPosSearch,
|
|
||||||
uint64 &startPosBinaryBlock);
|
|
||||||
|
|
||||||
bool readMetaSTD(
|
|
||||||
const word& wordPath,
|
|
||||||
std::vector<uint64>& chunkSizes,
|
|
||||||
uint64 startPosSearch,
|
|
||||||
uint64 &startPosBinaryBlock);
|
|
||||||
|
|
||||||
bool waitForAllMPI();
|
|
||||||
|
|
||||||
bool maxReduction( uint64& src, uint64& dst);
|
|
||||||
|
|
||||||
bool BcastPos(uint64 & pos);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
dataIO(IOPattern::IOType iotype)
|
|
||||||
:
|
|
||||||
ioPattern_(iotype)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~dataIO()=default;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool writeDataEnd(
|
|
||||||
const word& wordPath,
|
|
||||||
const span<T>& data);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool writeAsciiEnd(
|
|
||||||
iOstream& os,
|
|
||||||
const span<T>& data);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool readDataBinary(
|
|
||||||
const word& wordPath,
|
|
||||||
std::vector<T>& data,
|
|
||||||
uint64 startPos = 0);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool readAscii(
|
|
||||||
iIstream& is,
|
|
||||||
std::vector<T>& vec );
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool readData(
|
|
||||||
iIstream& is,
|
|
||||||
std::vector<T>& vec,
|
|
||||||
bool resume = false); // resume only works for binary
|
|
||||||
// for ascii, by default it starts from the current position
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool writeData(iOstream& os,
|
|
||||||
const span<T>& data);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline
|
|
||||||
bool pFlow::dataIO::writeData<pFlow::word>
|
|
||||||
(
|
|
||||||
iOstream& os,
|
|
||||||
const span<word>& data
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if( !writeAsciiEnd(os, data) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline
|
|
||||||
bool pFlow::dataIO::readData<pFlow::word>(
|
|
||||||
iIstream& is,
|
|
||||||
std::vector<word>& vec,
|
|
||||||
bool resume)
|
|
||||||
{
|
|
||||||
if(!readAscii(is, vec))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}*/
|
|
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
#include "dataIONoMPI.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
pFlow::dataIONoMPI::dataIONoMPI
|
|
||||||
(
|
|
||||||
IOPattern::IOType iotype,
|
|
||||||
word exeMode
|
|
||||||
)
|
|
||||||
:
|
|
||||||
dataIO(iotype, exeMode)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
bool pFlow::dataIONoMPI::gatherData( span<char> sp )
|
|
||||||
{
|
|
||||||
/// in serial mode, no gathering is required.
|
|
||||||
buffer_ = sp;
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
#ifndef __datIONoMPI_hpp__
|
|
||||||
#define __datIONoMPI_hpp__
|
|
||||||
|
|
||||||
#include "dataIO.hpp"
|
|
||||||
|
|
||||||
namespace pFlow
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
class dataIONoMPI
|
|
||||||
:
|
|
||||||
public dataIO
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
TypeInfo("dataIO<NoMPI>");
|
|
||||||
|
|
||||||
dataIONoMPI(IOPattern::IOType iotype, word exeMode);
|
|
||||||
|
|
||||||
dataIONoMPI(const dataIONoMPI&) = default;
|
|
||||||
|
|
||||||
dataIONoMPI(dataIONoMPI&&) = default;
|
|
||||||
|
|
||||||
|
|
||||||
dataIONoMPI& operator=(const dataIONoMPI&) = default;
|
|
||||||
|
|
||||||
dataIONoMPI& operator=(dataIONoMPI&&) = default;
|
|
||||||
|
|
||||||
~dataIONoMPI() = default;
|
|
||||||
|
|
||||||
add_vCtor
|
|
||||||
(
|
|
||||||
dataIO,
|
|
||||||
dataIONoMPI,
|
|
||||||
word
|
|
||||||
);
|
|
||||||
|
|
||||||
bool gatherData(span<char> sp ) override;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
47
src/phasicFlow/streams/dataIO/dataIORegular.hpp
Normal file
47
src/phasicFlow/streams/dataIO/dataIORegular.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __datIONoMPI_hpp__
|
||||||
|
#define __datIONoMPI_hpp__
|
||||||
|
|
||||||
|
#include "dataIO.hpp"
|
||||||
|
|
||||||
|
namespace pFlow
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
class dataIORegular
|
||||||
|
:
|
||||||
|
public dataIO<T>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
bool gatherData(span<T> data ) override
|
||||||
|
{
|
||||||
|
/// in serial mode, no gathering is required.
|
||||||
|
this->bufferSpan_ = data;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TypeInfo("dataIO<regular>");
|
||||||
|
|
||||||
|
dataIORegular(const IOPattern& iop)
|
||||||
|
:
|
||||||
|
dataIO<T>(iop)
|
||||||
|
{}
|
||||||
|
|
||||||
|
dataIORegular(const dataIORegular&) = default;
|
||||||
|
|
||||||
|
dataIORegular(dataIORegular&&) = default;
|
||||||
|
|
||||||
|
dataIORegular& operator=(const dataIORegular&) = default;
|
||||||
|
|
||||||
|
dataIORegular& operator=(dataIORegular&&) = default;
|
||||||
|
|
||||||
|
~dataIORegular() = default;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool pFlow::dataIO::writeData(iOstream& os, span<T> data)
|
bool pFlow::dataIO<T>::writeData(iOstream& os, span<T> data)
|
||||||
{
|
{
|
||||||
/// first gather data from all processors (if any)
|
/// first gather data from all processors (if any)
|
||||||
if(!gatherData( createSpan(data) ) )
|
if(!gatherData( data ) )
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"Error in gathering data for out stream "<< os.name()<<endl;
|
"Error in gathering data for out stream "<< os.name()<<endl;
|
||||||
@ -14,11 +14,14 @@ bool pFlow::dataIO::writeData(iOstream& os, span<T> data)
|
|||||||
{
|
{
|
||||||
if( os.isBinary() )
|
if( os.isBinary() )
|
||||||
{
|
{
|
||||||
// first write the size of data
|
// first write the number of data
|
||||||
uint64 len = buffer_.size()/sizeof(T);
|
uint64 numData = bufferSpan_.size();
|
||||||
os<< len << endl;
|
os<< numData << endl;
|
||||||
|
|
||||||
if(!os.write(buffer_.data(), buffer_.size()))
|
// write the bindary data
|
||||||
|
auto chBuffer = charSpan(bufferSpan_);
|
||||||
|
|
||||||
|
if(!os.write(chBuffer.data(), chBuffer.size()))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"error in writing binary data to "<<os.name()<<endl;
|
"error in writing binary data to "<<os.name()<<endl;
|
||||||
@ -28,13 +31,7 @@ bool pFlow::dataIO::writeData(iOstream& os, span<T> data)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if( !bufferSpan_.writeASCII(os) )
|
||||||
/// cast the data into T
|
|
||||||
span<T> allData(
|
|
||||||
reinterpret_cast<T*>(buffer_.data()),
|
|
||||||
buffer_.size()/sizeof(T));
|
|
||||||
|
|
||||||
if( !allData.writeASCII(os) )
|
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"error in writing ASCII data to "<<os.name()<<endl;
|
"error in writing ASCII data to "<<os.name()<<endl;
|
||||||
@ -50,20 +47,44 @@ bool pFlow::dataIO::writeData(iOstream& os, span<T> data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline
|
||||||
|
bool pFlow::dataIO<pFlow::word>::writeData(iOstream& os, span<word> data)
|
||||||
|
{
|
||||||
|
notImplementedFunction;
|
||||||
|
fatalExit;
|
||||||
|
/// first gather data from all processors (if any)
|
||||||
|
if(!gatherData( data ) )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"Error in gathering data for out stream "<< os.name()<<endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !bufferSpan_.writeASCII(os) )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"error in writing ASCII data to "<<os.name()<<endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool pFlow::dataIO::readData
|
bool pFlow::dataIO<T>::readData
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
std::vector<T>& data
|
std::vector<T>& data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
data.clear();
|
data.clear();
|
||||||
|
|
||||||
if(ioPattern_.thisProcReadData())
|
if(ioPattern_.thisProcReadData())
|
||||||
{
|
{
|
||||||
if(is.isBinary())
|
if(is.isBinary())
|
||||||
{
|
{
|
||||||
|
|
||||||
// read length of data
|
// read length of data
|
||||||
token firstToken(is);
|
token firstToken(is);
|
||||||
|
|
||||||
@ -98,7 +119,7 @@ bool pFlow::dataIO::readData
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool pFlow::dataIO::readAscii
|
bool pFlow::dataIO<T>::readAscii
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
std::vector<T>& vec
|
std::vector<T>& vec
|
||||||
@ -107,7 +128,6 @@ bool pFlow::dataIO::readAscii
|
|||||||
|
|
||||||
if( !ioPattern_.thisProcReadData() ) return true;
|
if( !ioPattern_.thisProcReadData() ) return true;
|
||||||
|
|
||||||
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
is.fatalCheck(FUNCTION_NAME);
|
||||||
|
|
||||||
vec.clear();
|
vec.clear();
|
||||||
@ -161,331 +181,10 @@ bool pFlow::dataIO::readAscii
|
|||||||
|
|
||||||
if(len>0&& len != vec.size())
|
if(len>0&& len != vec.size())
|
||||||
{
|
{
|
||||||
warningInFunction<<"vector lendth specified "<< len <<
|
warningInFunction<<"vector length specified "<< len <<
|
||||||
" is different from number of elements "<< vec.size()<<endl;
|
" is different from number of elements "<< vec.size()<<endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*template<typename T>
|
|
||||||
bool pFlow::dataIO::writeDataEnd(
|
|
||||||
const word& wordPath,
|
|
||||||
const span<T>& data)
|
|
||||||
{
|
|
||||||
|
|
||||||
if( ioPattern_.thisProcWriteData() )
|
|
||||||
{
|
|
||||||
span<unsigned char> charSpan(
|
|
||||||
reinterpret_cast<unsigned char*> (const_cast<T*>(data.data())),
|
|
||||||
data.size()*sizeof(T));
|
|
||||||
|
|
||||||
if( ioPattern_.isParallel() )
|
|
||||||
{
|
|
||||||
return writeDataToFileEndMPI(wordPath, charSpan);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return writeDataToFileEndSTD(wordPath, charSpan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool pFlow::dataIO::writeAsciiEnd
|
|
||||||
(
|
|
||||||
iOstream& os,
|
|
||||||
const span<T>& data
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if(ioPattern_.thisProcWriteData())
|
|
||||||
{
|
|
||||||
return data.writeASCII(os);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool pFlow::dataIO::readDataBinary
|
|
||||||
(
|
|
||||||
const word& wordPath,
|
|
||||||
std::vector<T>& data,
|
|
||||||
uint64 startPos
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::vector<uint64> chunkSizes;
|
|
||||||
uint64 startPosBinaryBlock;
|
|
||||||
|
|
||||||
data.clear();
|
|
||||||
|
|
||||||
if( ioPattern_.thisProcReadData())
|
|
||||||
{
|
|
||||||
|
|
||||||
// read meta
|
|
||||||
if(!readMetaSTD(
|
|
||||||
wordPath,
|
|
||||||
chunkSizes,
|
|
||||||
startPos,
|
|
||||||
startPosBinaryBlock))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( ioPattern_.isMasterProcessor() ||
|
|
||||||
ioPattern_.isAllProcessorSimilar()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
auto sizeOfData = std::accumulate(
|
|
||||||
chunkSizes.begin(),
|
|
||||||
chunkSizes.end(),
|
|
||||||
static_cast<uint64>(0));
|
|
||||||
|
|
||||||
|
|
||||||
data.resize(sizeOfData/sizeof(T));
|
|
||||||
|
|
||||||
span<unsigned char> charSpan(
|
|
||||||
reinterpret_cast<unsigned char*>(data.data()),
|
|
||||||
data.size()*sizeof(T));
|
|
||||||
|
|
||||||
if(!readDataSTD(wordPath, chunkSizes, charSpan, startPosBinaryBlock))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if( ioPattern_.isAllProcessorDifferent() )
|
|
||||||
{
|
|
||||||
|
|
||||||
if(chunkSizes.size() != ioPattern_.globalSize())
|
|
||||||
{
|
|
||||||
if( ioPattern_.isMaster())
|
|
||||||
{
|
|
||||||
auto sizeOfData = std::accumulate(
|
|
||||||
chunkSizes.begin(),
|
|
||||||
chunkSizes.end(),
|
|
||||||
static_cast<uint64>(0));
|
|
||||||
|
|
||||||
|
|
||||||
data.resize(sizeOfData/sizeof(T));
|
|
||||||
|
|
||||||
span<unsigned char> charSpan(
|
|
||||||
reinterpret_cast<unsigned char*>(data.data()),
|
|
||||||
data.size()*sizeof(T));
|
|
||||||
|
|
||||||
if(!readDataSTD(wordPath, chunkSizes, charSpan, startPosBinaryBlock))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto thisProc = ioPattern_.globalRank();
|
|
||||||
|
|
||||||
data.resize(chunkSizes[thisProc]/sizeof(T));
|
|
||||||
|
|
||||||
span<unsigned char> charSpan(
|
|
||||||
reinterpret_cast<unsigned char*>(data.data()),
|
|
||||||
data.size()*sizeof(T));
|
|
||||||
|
|
||||||
|
|
||||||
if( !readDataMPI(wordPath, chunkSizes, charSpan, startPosBinaryBlock) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool pFlow::dataIO::readAscii
|
|
||||||
(
|
|
||||||
iIstream& is,
|
|
||||||
std::vector<T>& vec
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
if( !ioPattern_.thisProcReadData() ) return true;
|
|
||||||
|
|
||||||
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
|
|
||||||
vec.clear();
|
|
||||||
|
|
||||||
token firstToken(is);
|
|
||||||
|
|
||||||
size_t len = 0;
|
|
||||||
if( firstToken.isInt64())
|
|
||||||
{
|
|
||||||
len = firstToken.int64Token();
|
|
||||||
vec.reserve(len);
|
|
||||||
firstToken = token(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
T val{};
|
|
||||||
if( firstToken.isPunctuation() ) // start of vector
|
|
||||||
{
|
|
||||||
if(firstToken != token::BEGIN_LIST)
|
|
||||||
{
|
|
||||||
warningInFunction
|
|
||||||
<< "expected token "<< token::BEGIN_LIST
|
|
||||||
<< " but found "<< firstToken ;
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
token lastToken(is);
|
|
||||||
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
|
|
||||||
while(!(lastToken.isPunctuation()
|
|
||||||
&& lastToken == token::END_LIST ))
|
|
||||||
{
|
|
||||||
|
|
||||||
is.putBack(lastToken);
|
|
||||||
|
|
||||||
is >> val;
|
|
||||||
vec.push_back(val);
|
|
||||||
|
|
||||||
is >> lastToken;
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
warningInFunction
|
|
||||||
<< "expected token "<< token::BEGIN_LIST
|
|
||||||
<< " but found "<< firstToken<<endl; ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(len>0&& len != vec.size())
|
|
||||||
{
|
|
||||||
warningInFunction<<"vector lendth specified "<< len <<
|
|
||||||
" is different from number of elements "<< vec.size()<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool pFlow::dataIO::readData
|
|
||||||
(
|
|
||||||
iIstream& is,
|
|
||||||
std::vector<T>& vec,
|
|
||||||
bool resume
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if(is.isBinary())
|
|
||||||
{
|
|
||||||
uint64 currPos = 0;
|
|
||||||
if( resume )
|
|
||||||
{
|
|
||||||
currPos = is.tell();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(! BcastPos(currPos) ) return false;
|
|
||||||
|
|
||||||
if(!this->readDataBinary(is.name(), vec, currPos))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto lastPos = lastPosRead_;
|
|
||||||
maxReduction( lastPos, lastPosRead_);
|
|
||||||
//std::cout<<"last post read "<< lastPosRead_<<std::endl;
|
|
||||||
|
|
||||||
/// set the stream indicator to the last position
|
|
||||||
is.seek(lastPosRead_);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!readAscii(is, vec))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool pFlow::dataIO::writeData
|
|
||||||
(
|
|
||||||
iOstream& os,
|
|
||||||
const span<T>& sp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if( os.isBinary() )
|
|
||||||
{
|
|
||||||
os.startOfBinaryStreaming();
|
|
||||||
|
|
||||||
if(!writeDataEnd(os.name(), sp))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
os.endOfBinaryStreaming();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( !writeAsciiEnd(os, sp) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -97,6 +97,18 @@ public:
|
|||||||
return max_;
|
return max_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
realx3& minPoint()
|
||||||
|
{
|
||||||
|
return min_;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
realx3& maxPoint()
|
||||||
|
{
|
||||||
|
return max_;
|
||||||
|
}
|
||||||
|
|
||||||
//// - IO operation
|
//// - IO operation
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool read(iIstream & is);
|
bool read(iIstream & is);
|
||||||
|
@ -56,4 +56,25 @@ pFlow::domain::domain(const box& db)
|
|||||||
realx3(db.minPoint().x(), db.maxPoint().y(), db.maxPoint().z()))
|
realx3(db.minPoint().x(), db.maxPoint().y(), db.maxPoint().z()))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FUNCTION_H
|
||||||
|
pFlow::iIstream& pFlow::operator >>(
|
||||||
|
pFlow::iIstream& is,
|
||||||
|
pFlow::domain& d)
|
||||||
|
{
|
||||||
|
box b;
|
||||||
|
is>>b;
|
||||||
|
d = domain(b);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
FUNCTION_H
|
||||||
|
pFlow::iOstream& pFlow::operator << (
|
||||||
|
pFlow::iOstream& os,
|
||||||
|
const pFlow::domain& d)
|
||||||
|
{
|
||||||
|
os<< d.domainBox();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
@ -156,17 +156,12 @@ bool operator ==(const domain& d1, const domain& d2)
|
|||||||
return equal(d1, d2);
|
return equal(d1, d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*FUNCTION_H
|
FUNCTION_H
|
||||||
iIstream& operator >>(iIstream& is, box& b);
|
iIstream& operator >>(iIstream& is, domain& d);
|
||||||
|
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
iOstream& operator << (iOstream& os, const box& b);
|
iOstream& operator << (iOstream& os, const domain& d);
|
||||||
|
|
||||||
INLINE_FUNCTION_HD
|
|
||||||
box extendBox(const box& b, const realx3& dl)
|
|
||||||
{
|
|
||||||
return box(b.minPoint()-dl , b.maxPoint()+dl);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,37 +50,52 @@ bool pFlow::regularSimulationDomain::setThisDomain()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::regularSimulationDomain::regularSimulationDomain(
|
pFlow::regularSimulationDomain::regularSimulationDomain
|
||||||
const dictionary &dict)
|
|
||||||
: simulationDomain(dict)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool pFlow::regularSimulationDomain::updateDomains
|
|
||||||
(
|
(
|
||||||
const realx3Vector& pointPos
|
const dictionary &dict
|
||||||
)
|
)
|
||||||
|
:
|
||||||
|
simulationDomain(dict)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialUpdateDomains(span<realx3> pointPos)
|
||||||
{
|
{
|
||||||
thisNumPoints_ = pointPos.size();
|
initialNumPoints_ = pointPos.size();
|
||||||
if(!createBoundaryDicts()) return false;
|
if(!setThisDomain()) return false;
|
||||||
if(!setThisDomain()) return false;
|
if(!createBoundaryDicts()) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::uint32 pFlow::regularSimulationDomain::thisNumPoints() const
|
pFlow::uint32 pFlow::regularSimulationDomain::initialNumberInThis() const
|
||||||
{
|
{
|
||||||
return thisNumPoints_;
|
return initialNumPoints_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::regularSimulationDomain::transferBlockData
|
/*bool pFlow::regularSimulationDomain::updateDomains(
|
||||||
|
span<realx3> pointPos,
|
||||||
|
pFlagTypeHost flags)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
pFlow::uint32 pFlow::regularSimulationDomain::numberToBeImported() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::uint32 pFlow::regularSimulationDomain::numberToBeExported() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialTransferBlockData
|
||||||
(
|
(
|
||||||
span<char> src,
|
span<char> src,
|
||||||
span<char> dst,
|
span<char> dst,
|
||||||
uint32 sizeOfBlock
|
size_t sizeOfElement
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size_t requiredSize = sizeOfBlock*thisNumPoints();
|
size_t requiredSize = sizeOfElement*initialNumberInThis();
|
||||||
if(dst.size() < requiredSize)
|
if(dst.size() < requiredSize)
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
@ -103,6 +118,54 @@ bool pFlow::regularSimulationDomain::transferBlockData
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialTransferBlockData
|
||||||
|
(
|
||||||
|
span<realx3> src,
|
||||||
|
span<realx3> dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return initialTransferBlockData(
|
||||||
|
charSpan(src),
|
||||||
|
charSpan(dst),
|
||||||
|
sizeof(realx3));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialTransferBlockData
|
||||||
|
(
|
||||||
|
span<real> src,
|
||||||
|
span<real> dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return initialTransferBlockData(
|
||||||
|
charSpan(src),
|
||||||
|
charSpan(dst),
|
||||||
|
sizeof(real));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialTransferBlockData
|
||||||
|
(
|
||||||
|
span<uint32> src,
|
||||||
|
span<uint32> dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return initialTransferBlockData(
|
||||||
|
charSpan(src),
|
||||||
|
charSpan(dst),
|
||||||
|
sizeof(uint32));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::regularSimulationDomain::initialTransferBlockData
|
||||||
|
(
|
||||||
|
span<int32> src,
|
||||||
|
span<int32> dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return initialTransferBlockData(
|
||||||
|
charSpan(src),
|
||||||
|
charSpan(dst),
|
||||||
|
sizeof(int32));
|
||||||
|
}
|
||||||
|
|
||||||
const pFlow::dictionary &pFlow::regularSimulationDomain::thisBoundaryDict() const
|
const pFlow::dictionary &pFlow::regularSimulationDomain::thisBoundaryDict() const
|
||||||
{
|
{
|
||||||
return globalDomainDict_.subDict("regularSimulationDomainBoundaries");
|
return globalDomainDict_.subDict("regularSimulationDomainBoundaries");
|
||||||
|
@ -13,7 +13,7 @@ class regularSimulationDomain
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint32 thisNumPoints_=0;
|
uint32 initialNumPoints_=0;
|
||||||
|
|
||||||
bool createBoundaryDicts() override;
|
bool createBoundaryDicts() override;
|
||||||
|
|
||||||
@ -35,16 +35,44 @@ public:
|
|||||||
dictionary
|
dictionary
|
||||||
);
|
);
|
||||||
|
|
||||||
bool updateDomains(
|
bool initialUpdateDomains(span<realx3> pointPos) override;
|
||||||
const realx3Vector& pointPos)override;
|
|
||||||
|
|
||||||
uint32 thisNumPoints()const override;
|
uint32 initialNumberInThis()const override;
|
||||||
|
|
||||||
|
/*bool updateDomains(
|
||||||
bool transferBlockData(
|
span<realx3> pointPos,
|
||||||
|
pFlagTypeHost flags) override;*/
|
||||||
|
|
||||||
|
uint32 numberToBeImported()const override;
|
||||||
|
|
||||||
|
uint32 numberToBeExported()const override;
|
||||||
|
|
||||||
|
bool initialTransferBlockData(
|
||||||
span<char> src,
|
span<char> src,
|
||||||
span<char> dst,
|
span<char> dst,
|
||||||
uint32 sizeOfBlock) override;
|
size_t sizeOfElement) override;
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief
|
||||||
|
/// @param src
|
||||||
|
/// @param dst
|
||||||
|
/// @return
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<realx3> src,
|
||||||
|
span<realx3> dst) override;
|
||||||
|
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<real> src,
|
||||||
|
span<real> dst) override;
|
||||||
|
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<uint32> src,
|
||||||
|
span<uint32> dst) override;
|
||||||
|
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<int32> src,
|
||||||
|
span<int32> dst) override;
|
||||||
|
|
||||||
|
|
||||||
const dictionary& thisBoundaryDict()const override;
|
const dictionary& thisBoundaryDict()const override;
|
||||||
|
|
||||||
|
@ -19,23 +19,23 @@ Licence:
|
|||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "simulationDomain.hpp"
|
#include "simulationDomain.hpp"
|
||||||
#include "processors.hpp"
|
#include "pFlowProcessors.hpp"
|
||||||
|
|
||||||
pFlow::simulationDomain::simulationDomain(const dictionary& dict)
|
pFlow::simulationDomain::simulationDomain(const dictionary& dict)
|
||||||
:
|
:
|
||||||
globalBox_(dict.subDict("globalBox")),
|
globalBox_(dict.subDict("globalBox")),
|
||||||
globalDomainDict_(dict)
|
globalDomainDict_(dict)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::uniquePtr<pFlow::simulationDomain>
|
pFlow::uniquePtr<pFlow::simulationDomain>
|
||||||
pFlow::simulationDomain::create(const dictionary &dict)
|
pFlow::simulationDomain::create(const dictionary &dict)
|
||||||
{
|
{
|
||||||
|
|
||||||
word sType = angleBracketsNames(
|
word sType = angleBracketsNames(
|
||||||
"simulationDomain",
|
"simulationDomain",
|
||||||
processors::runTypeName());
|
pFlowProcessors().localRunTypeName());
|
||||||
|
|
||||||
|
|
||||||
if( dictionaryvCtorSelector_.search(sType) )
|
if( dictionaryvCtorSelector_.search(sType) )
|
||||||
{
|
{
|
||||||
|
@ -17,19 +17,22 @@ Licence:
|
|||||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef __simulationDomain_hpp__
|
#ifndef __simulationDomain_hpp__
|
||||||
#define __simulationDomain_hpp__
|
#define __simulationDomain_hpp__
|
||||||
|
|
||||||
#include "domain.hpp"
|
#include <array>
|
||||||
#include "virtualConstructor.hpp"
|
|
||||||
#include "Vectors.hpp"
|
|
||||||
|
|
||||||
|
#include "domain.hpp"
|
||||||
|
#include "span.hpp"
|
||||||
#include "streams.hpp"
|
#include "streams.hpp"
|
||||||
|
#include "virtualConstructor.hpp"
|
||||||
|
#include "pointFlag.hpp"
|
||||||
|
|
||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//class pFlagTypeHost;
|
||||||
|
|
||||||
class simulationDomain
|
class simulationDomain
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -56,9 +59,9 @@ protected:
|
|||||||
|
|
||||||
bool boundariesSet_ = false;
|
bool boundariesSet_ = false;
|
||||||
|
|
||||||
virtual bool createBoundaryDicts() = 0;
|
virtual bool createBoundaryDicts() = 0;
|
||||||
|
|
||||||
virtual bool setThisDomain() = 0;
|
virtual bool setThisDomain() = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -84,23 +87,64 @@ public:
|
|||||||
virtual
|
virtual
|
||||||
const dictionary& thisBoundaryDict()const = 0;
|
const dictionary& thisBoundaryDict()const = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool initialUpdateDomains(span<realx3> pointPos) = 0;
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
bool updateDomains(
|
uint32 initialNumberInThis()const = 0;
|
||||||
const realx3Vector& pointPos) = 0;
|
|
||||||
|
|
||||||
//virtual getImportExportList() = 0;
|
virtual
|
||||||
|
bool initialTransferBlockData(
|
||||||
//virtual getNumberInThisList() = 0;
|
|
||||||
|
|
||||||
virtual
|
|
||||||
uint32 thisNumPoints()const = 0;
|
|
||||||
|
|
||||||
virtual
|
|
||||||
bool transferBlockData(
|
|
||||||
span<char> src,
|
span<char> src,
|
||||||
span<char> dst,
|
span<char> dst,
|
||||||
uint32 sizeOfBlock) = 0;
|
size_t sizeOfElement) = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<realx3> src,
|
||||||
|
span<realx3> dst) = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<real> src,
|
||||||
|
span<real> dst) = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<uint32> src,
|
||||||
|
span<uint32> dst) = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<int32> src,
|
||||||
|
span<int32> dst) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*template<typename T>
|
||||||
|
bool initialTransferBlockData(
|
||||||
|
span<T> src,
|
||||||
|
span<T> dst )
|
||||||
|
{
|
||||||
|
size_t el=sizeof(T);
|
||||||
|
return initialTransferBlockData
|
||||||
|
(
|
||||||
|
charSpan(src),
|
||||||
|
charSpan(dst),
|
||||||
|
el
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Number of points to be imported after updating domains
|
||||||
|
/// @return number of points
|
||||||
|
virtual
|
||||||
|
uint32 numberToBeImported()const = 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
uint32 numberToBeExported()const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
bool requiresDataTransfer() const = 0;
|
bool requiresDataTransfer() const = 0;
|
||||||
|
@ -29,7 +29,7 @@ Licence:
|
|||||||
namespace pFlow
|
namespace pFlow
|
||||||
{
|
{
|
||||||
|
|
||||||
class infinitePlane
|
class infinitePlane
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -137,6 +137,33 @@ public:
|
|||||||
return t*normal_ + p;
|
return t*normal_ + p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
bool parallel(const infinitePlane& pln)const
|
||||||
|
{
|
||||||
|
return equal(normal_, pln.normal_) ||
|
||||||
|
equal(normal_,-pln.normal_);
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
bool parallelTouch(const infinitePlane& pln)const
|
||||||
|
{
|
||||||
|
if(equal(normal_, pln.normal_) && equal(d_, pln.d_))return true;
|
||||||
|
if(equal(normal_,-pln.normal_) && equal(d_,-pln.d_))return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
const auto& normal()const
|
||||||
|
{
|
||||||
|
return normal_;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD
|
||||||
|
const auto& d()const
|
||||||
|
{
|
||||||
|
return d_;
|
||||||
|
}
|
||||||
|
|
||||||
//// - IO operation
|
//// - IO operation
|
||||||
|
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
|
@ -54,13 +54,11 @@ pFlow::plane pFlow::plane::parallelPlane(real distance)const
|
|||||||
return plane(pp1, pp2, pp3, pp4);
|
return plane(pp1, pp2, pp3, pp4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::plane::validPlane4
|
bool pFlow::plane::validPlane4(
|
||||||
(
|
const realx3 &p1,
|
||||||
const realx3& p1,
|
const realx3 &p2,
|
||||||
const realx3& p2,
|
const realx3 &p3,
|
||||||
const realx3& p3,
|
const realx3 &p4)
|
||||||
const realx3& p4
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if( !validPlane3(p1,p2,p3)) return false;
|
if( !validPlane3(p1,p2,p3)) return false;
|
||||||
if( !infinitePlane(p1,p2,p3).pointOnPlane(p4)) return false;
|
if( !infinitePlane(p1,p2,p3).pointOnPlane(p4)) return false;
|
||||||
|
@ -122,6 +122,7 @@ public:
|
|||||||
// return the parallel plane to this plane
|
// return the parallel plane to this plane
|
||||||
plane parallelPlane(real distance)const;
|
plane parallelPlane(real distance)const;
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
bool validPlane4(
|
bool validPlane4(
|
||||||
const realx3& p1,
|
const realx3& p1,
|
||||||
|
@ -173,20 +173,48 @@ pFlow::internalPoints::internalPoints
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const pFlow::internalPoints::pFlagTypeDevice&
|
const pFlow::pFlagTypeDevice&
|
||||||
pFlow::internalPoints::activePointsMaskD() const
|
pFlow::internalPoints::activePointsMaskD() const
|
||||||
{
|
{
|
||||||
return pFlagsD_;
|
return pFlagsD_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const pFlow::internalPoints::pFlagTypeHost&
|
const pFlow::pFlagTypeHost&
|
||||||
pFlow::internalPoints::activePointsMaskH() const
|
pFlow::internalPoints::activePointsMaskH() const
|
||||||
{
|
{
|
||||||
syncPFlag();
|
syncPFlag();
|
||||||
return pFlagsH_;
|
return pFlagsH_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FUNCTION_H
|
||||||
|
const pFlow::realx3Field_D&
|
||||||
|
pFlow::internalPoints::pointPosition()const
|
||||||
|
{
|
||||||
|
return pointPosition_;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFlow::hostViewType1D<pFlow::realx3>
|
||||||
|
pFlow::internalPoints::activePointsHost() const
|
||||||
|
{
|
||||||
|
auto maskH = activePointsMaskH();
|
||||||
|
auto pointsH = pointPositionHost();
|
||||||
|
|
||||||
|
hostViewType1D<realx3> aPoints("Active pointst", maskH.numActive());
|
||||||
|
auto aRange = maskH.activeRange();
|
||||||
|
uint32 n = 0;
|
||||||
|
for(auto i=aRange.start(); i<aRange.end(); i++)
|
||||||
|
{
|
||||||
|
if( maskH.isActive(i) )
|
||||||
|
{
|
||||||
|
aPoints[n] = pointsH[i];
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return aPoints;
|
||||||
|
}
|
||||||
|
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
pFlow::realx3Field_D &pFlow::internalPoints::pointPosition()
|
pFlow::realx3Field_D &pFlow::internalPoints::pointPosition()
|
||||||
{
|
{
|
||||||
@ -218,13 +246,13 @@ FUNCTION_H
|
|||||||
bool pFlow::internalPoints::read
|
bool pFlow::internalPoints::read
|
||||||
(
|
(
|
||||||
iIstream& is,
|
iIstream& is,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
Field<Vector, realx3 , vecAllocator<realx3>> fRead("internalPoints", "internalPoints");
|
Field<Vector, realx3 , vecAllocator<realx3>> fRead("internalPoints", "internalPoints");
|
||||||
|
|
||||||
if( !fRead.read(is, iotype))
|
if( !fRead.read(is, iop))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
||||||
@ -249,16 +277,16 @@ FUNCTION_H
|
|||||||
bool pFlow::internalPoints::write
|
bool pFlow::internalPoints::write
|
||||||
(
|
(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
IOPattern::IOType iotype
|
const IOPattern& iop
|
||||||
)const
|
)const
|
||||||
{
|
{
|
||||||
if( pFlagsD_.isAllActive())
|
if( pFlagsD_.isAllActive())
|
||||||
{
|
{
|
||||||
return pointPosition_.write(os, iotype);
|
return pointPosition_.write(os, iop);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return pointPosition_.write(os, iotype, activePointsMaskH());
|
return pointPosition_.write(os, iop, activePointsMaskH());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +47,6 @@ public:
|
|||||||
|
|
||||||
using execution_space = typename pointsType::execution_space;
|
using execution_space = typename pointsType::execution_space;
|
||||||
|
|
||||||
using pFlagTypeDevice = pointFlag<execution_space>;
|
|
||||||
|
|
||||||
using pFlagTypeHost = pointFlag<DefaultHostExecutionSpace>;
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//// - data members
|
//// - data members
|
||||||
@ -120,11 +115,19 @@ public:
|
|||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
realx3Field_D& pointPosition();
|
realx3Field_D& pointPosition();
|
||||||
|
|
||||||
/*INLINE_FUNCTION_H
|
INLINE_FUNCTION_H
|
||||||
auto pointPositionHostAll()
|
auto pointPositionHost()const
|
||||||
{
|
{
|
||||||
return pointPosition_.hostVectorAll();
|
return pointPosition_.hostVector();
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
INLINE_FUNCTION_H
|
||||||
|
auto pointPositionDevice()const
|
||||||
|
{
|
||||||
|
return pointPosition_.deviceVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
hostViewType1D<realx3> activePointsHost()const;
|
||||||
|
|
||||||
// - size of data structure
|
// - size of data structure
|
||||||
INLINE_FUNCTION_H
|
INLINE_FUNCTION_H
|
||||||
@ -216,12 +219,12 @@ public:
|
|||||||
|
|
||||||
/// Read
|
/// Read
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool read(iIstream& is, IOPattern::IOType iotype);
|
bool read(iIstream& is, const IOPattern& iop);
|
||||||
|
|
||||||
|
|
||||||
/// Write
|
/// Write
|
||||||
FUNCTION_H
|
FUNCTION_H
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype)const;
|
bool write(iOstream& os, const IOPattern& iop)const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -244,6 +244,9 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using pFlagTypeDevice = pointFlag<DefaultExecutionSpace>;
|
||||||
|
|
||||||
|
using pFlagTypeHost = pointFlag<DefaultHostExecutionSpace>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,8 +258,6 @@ void pFlow::pointFlag<ExecutionSpace>::fillNeighborsLists
|
|||||||
});
|
});
|
||||||
Kokkos::fence();
|
Kokkos::fence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ExecutionSpace>
|
template<typename ExecutionSpace>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*------------------------------- phasicFlow ---------------------------------
|
/*------------------------------- phasicFlow ---------------------------------
|
||||||
O C enter of
|
O C enter of
|
||||||
O O E ngineering and
|
O O E ngineering and
|
||||||
@ -19,53 +20,61 @@ Licence:
|
|||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "pointStructure.hpp"
|
#include "pointStructure.hpp"
|
||||||
#include "simulationDomain.hpp"
|
#include "systemControl.hpp"
|
||||||
|
#include "vocabs.hpp"
|
||||||
|
|
||||||
#include "streams.hpp"
|
|
||||||
|
|
||||||
bool pFlow::pointStructure::distributePoints
|
bool pFlow::pointStructure::setupPointStructure(const realx3Vector &points)
|
||||||
(
|
|
||||||
const realx3Vector &points
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
uint32 thisN = simulationDomain_->thisNumPoints();
|
if(!simulationDomain_->initialUpdateDomains(points.getSpan()))
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"error in updating domains"<<endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 thisN = simulationDomain_->initialNumberInThis();
|
||||||
|
|
||||||
Field<Vector, realx3 , vecAllocator<realx3>> internal(
|
Field<Vector, realx3 , vecAllocator<realx3>> internal
|
||||||
|
(
|
||||||
"internalPoints",
|
"internalPoints",
|
||||||
"internalPoints",
|
"internalPoints",
|
||||||
thisN,
|
thisN,
|
||||||
thisN,
|
thisN,
|
||||||
RESERVE());
|
RESERVE()
|
||||||
|
);
|
||||||
|
|
||||||
|
auto pSpan = makeSpan(points);
|
||||||
|
auto iSpan = internal.getSpan();
|
||||||
|
|
||||||
auto l = sizeof(realx3);
|
if(!simulationDomain_->initialTransferBlockData(pSpan, iSpan))
|
||||||
auto pointsSpan = span<char>(
|
|
||||||
reinterpret_cast<char*>
|
|
||||||
(
|
|
||||||
const_cast<realx3*>(points.data())
|
|
||||||
),
|
|
||||||
points.size()*l );
|
|
||||||
|
|
||||||
auto internalSpan = span<char>(reinterpret_cast<char*>(internal.data()), internal.size()*l);
|
|
||||||
|
|
||||||
if(!simulationDomain_->transferBlockData(pointsSpan, internalSpan, l))
|
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"Error in transfering the block data "<<endl;
|
"Error in transfering the block data "<<endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointPosition_.assign(internal.vectorField());
|
if( !initializePoints(internal) )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boundaries_.updateLists();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool pFlow::pointStructure::initializePoints(const realx3Vector &points)
|
||||||
|
{
|
||||||
|
pointPosition_.assign(points.vectorField());
|
||||||
|
|
||||||
|
|
||||||
pFlagsD_ = pFlagTypeDevice(pointPosition_.capacity(), 0, pointPosition_.size());
|
pFlagsD_ = pFlagTypeDevice(pointPosition_.capacity(), 0, pointPosition_.size());
|
||||||
pFlagSync_ = false;
|
pFlagSync_ = false;
|
||||||
syncPFlag();
|
syncPFlag();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFlow::pointStructure::pointStructure
|
pFlow::pointStructure::pointStructure
|
||||||
@ -73,7 +82,19 @@ pFlow::pointStructure::pointStructure
|
|||||||
systemControl& control
|
systemControl& control
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
demComponent("particlesCM", control),
|
IOobject
|
||||||
|
(
|
||||||
|
objectFile
|
||||||
|
(
|
||||||
|
pointStructureFile__,
|
||||||
|
"",
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS
|
||||||
|
),
|
||||||
|
IOPattern::MasterProcessorDistribute,
|
||||||
|
&control.time()
|
||||||
|
),
|
||||||
|
demComponent("particlesCenterMass", control),
|
||||||
internalPoints(),
|
internalPoints(),
|
||||||
simulationDomain_
|
simulationDomain_
|
||||||
(
|
(
|
||||||
@ -84,37 +105,52 @@ pFlow::pointStructure::pointStructure
|
|||||||
simulationDomain_(),
|
simulationDomain_(),
|
||||||
*this
|
*this
|
||||||
)
|
)
|
||||||
{}
|
{
|
||||||
|
REPORT(0)<< "Reading point structure from file"<<
|
||||||
|
IOobject::localPath()<<END_REPORT;
|
||||||
|
|
||||||
|
if( !IOobject::read() )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"Error in reading from file "<<IOobject::localPath()<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pFlow::pointStructure::pointStructure(
|
pFlow::pointStructure::pointStructure(
|
||||||
systemControl& control,
|
systemControl& control,
|
||||||
const realx3Vector &posVec)
|
const realx3Vector &posVec)
|
||||||
:
|
:
|
||||||
demComponent("particlesCM", control),
|
IOobject
|
||||||
internalPoints(),
|
(
|
||||||
simulationDomain_(
|
objectFile
|
||||||
simulationDomain::create(control.domainDict())),
|
(
|
||||||
boundaries_(
|
pointStructureFile__,
|
||||||
|
"",
|
||||||
|
objectFile::READ_NEVER,
|
||||||
|
objectFile::WRITE_ALWAYS
|
||||||
|
),
|
||||||
|
IOPattern::MasterProcessorDistribute,
|
||||||
|
&control.time()
|
||||||
|
),
|
||||||
|
demComponent("particlesCenterMass", control),
|
||||||
|
internalPoints(),
|
||||||
|
simulationDomain_
|
||||||
|
(
|
||||||
|
simulationDomain::create(control.domainDict())
|
||||||
|
),
|
||||||
|
boundaries_
|
||||||
|
(
|
||||||
simulationDomain_(),
|
simulationDomain_(),
|
||||||
*this)
|
*this
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if(!simulationDomain_->updateDomains(posVec) )
|
if(!setupPointStructure(posVec))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"Failed to update domains."<<endl;
|
"Error in seting up pointStructure"<<endl;
|
||||||
fatalExit;
|
fatalExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
boundaries_.updateLists();
|
|
||||||
|
|
||||||
if( !distributePoints(posVec) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<"Faild to distributes poinst"<<endl;
|
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::pointStructure::beforeIteration()
|
bool pFlow::pointStructure::beforeIteration()
|
||||||
@ -134,28 +170,49 @@ bool pFlow::pointStructure::afterIteration()
|
|||||||
|
|
||||||
bool pFlow::pointStructure::read(
|
bool pFlow::pointStructure::read(
|
||||||
iIstream &is,
|
iIstream &is,
|
||||||
IOPattern::IOType iotype)
|
const IOPattern& iop)
|
||||||
{
|
{
|
||||||
Field<Vector, realx3 , vecAllocator<realx3>> fRead("file_internalPoints", "internalPoints");
|
|
||||||
|
|
||||||
|
|
||||||
|
Field<Vector, realx3 , vecAllocator<realx3>>
|
||||||
|
fRead("file_internalPoints", "internalPoints");
|
||||||
|
|
||||||
if( !fRead.read(is, iotype))
|
if( !fRead.read(is, iop))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!simulationDomain_->updateDomains(fRead))
|
return setupPointStructure(fRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::pointStructure::write
|
||||||
|
(
|
||||||
|
iOstream& os,
|
||||||
|
const IOPattern& iop
|
||||||
|
)const
|
||||||
|
{
|
||||||
|
|
||||||
|
hostViewType1D<realx3> pointsH;
|
||||||
|
|
||||||
|
if(isAllActive())
|
||||||
|
{
|
||||||
|
pointsH = pointPositionHost();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pointsH = activePointsHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = span<realx3>(pointsH.data(), pointsH.size());
|
||||||
|
|
||||||
|
if( !writeSpan(os, data, iop) )
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"error in updating domains"<<endl;
|
"Error in writing pointStructure in stream "<<
|
||||||
|
os.name()<<endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boundaries_.updateLists();
|
return true;
|
||||||
|
}
|
||||||
return distributePoints(fRead);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -20,10 +20,12 @@ Licence:
|
|||||||
#ifndef __pointStructure_hpp__
|
#ifndef __pointStructure_hpp__
|
||||||
#define __pointStructure_hpp__
|
#define __pointStructure_hpp__
|
||||||
|
|
||||||
|
#include "IOobject.hpp"
|
||||||
#include "demComponent.hpp"
|
#include "demComponent.hpp"
|
||||||
#include "internalPoints.hpp"
|
#include "internalPoints.hpp"
|
||||||
#include "simulationDomain.hpp"
|
#include "simulationDomain.hpp"
|
||||||
#include "boundaryList.hpp"
|
#include "boundaryList.hpp"
|
||||||
|
#include "streams.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +35,7 @@ namespace pFlow
|
|||||||
|
|
||||||
class pointStructure
|
class pointStructure
|
||||||
:
|
:
|
||||||
|
public IOobject,
|
||||||
public demComponent,
|
public demComponent,
|
||||||
public internalPoints
|
public internalPoints
|
||||||
{
|
{
|
||||||
@ -42,9 +45,11 @@ protected:
|
|||||||
uniquePtr<simulationDomain> simulationDomain_ = nullptr;
|
uniquePtr<simulationDomain> simulationDomain_ = nullptr;
|
||||||
|
|
||||||
boundaryList boundaries_;
|
boundaryList boundaries_;
|
||||||
|
|
||||||
|
|
||||||
bool distributePoints(const realx3Vector& points);
|
bool setupPointStructure(const realx3Vector& points);
|
||||||
|
|
||||||
|
bool initializePoints(const realx3Vector& points);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -63,19 +68,12 @@ public:
|
|||||||
systemControl& control,
|
systemControl& control,
|
||||||
const realx3Vector& posVec);
|
const realx3Vector& posVec);
|
||||||
|
|
||||||
// - copy construct
|
|
||||||
//
|
|
||||||
// should be changed, may causs undefined behavior
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
pointStructure(const pointStructure&) = delete;
|
pointStructure(const pointStructure&) = delete;
|
||||||
|
|
||||||
// - no move construct
|
// - no move construct
|
||||||
pointStructure(pointStructure&&) = delete;
|
pointStructure(pointStructure&&) = delete;
|
||||||
|
|
||||||
// - copy assignment
|
|
||||||
//
|
|
||||||
// should be changed, may causs undefined behavior
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
pointStructure& operator=(const pointStructure&) = delete;
|
pointStructure& operator=(const pointStructure&) = delete;
|
||||||
|
|
||||||
// - no move assignment
|
// - no move assignment
|
||||||
@ -122,15 +120,14 @@ public:
|
|||||||
|
|
||||||
/// @brief read the point structure from the input stream.
|
/// @brief read the point structure from the input stream.
|
||||||
/// @param is: input stream
|
/// @param is: input stream
|
||||||
/// @param iotype: type of input pattern
|
/// @param iop: type of input pattern
|
||||||
/// @return true on success
|
/// @return true on success
|
||||||
FUNCTION_H
|
bool read(iIstream& is, const IOPattern& iop) override;
|
||||||
bool read(iIstream& is, IOPattern::IOType iotype);
|
|
||||||
|
|
||||||
|
|
||||||
/// Write
|
/// Write
|
||||||
/*FUNCTION_H
|
bool write(iOstream& os, const IOPattern& iop)const override;
|
||||||
bool write(iOstream& os, IOPattern::IOType iotype)const; */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -141,6 +138,16 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*inline iOstream& operator << (iOstream& os, const pointStructure& ps )
|
||||||
|
{
|
||||||
|
if( !ps.write(os, IOPattern::AllProcessorsDifferent) )
|
||||||
|
{
|
||||||
|
ioErrorInFile(os.name(), os.lineNumber());
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}*/
|
||||||
|
|
||||||
} // pFlow
|
} // pFlow
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,10 +106,10 @@ public:
|
|||||||
size_t size()const;
|
size_t size()const;
|
||||||
|
|
||||||
// - vertecies of ith solid
|
// - vertecies of ith solid
|
||||||
const realx3x3Vector& solid(label i)const;
|
const realx3x3Vector& solid(uint64 i)const;
|
||||||
|
|
||||||
// - name of ith solid
|
// - name of ith solid
|
||||||
const word& name(label i)const;
|
const word& name(uint64 i)const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,6 +146,8 @@ struct triple
|
|||||||
/// access component
|
/// access component
|
||||||
INLINE_FUNCTION_HD const T & z()const { return z_; }
|
INLINE_FUNCTION_HD const T & z()const { return z_; }
|
||||||
|
|
||||||
|
INLINE_FUNCTION_HD const T& comp(uint32 i) const {return *(this+i);}
|
||||||
|
|
||||||
//// methods
|
//// methods
|
||||||
|
|
||||||
/// Dot product of two vectors
|
/// Dot product of two vectors
|
||||||
|
@ -23,7 +23,7 @@ Licence:
|
|||||||
|
|
||||||
// initilized and finalize should be placed in onc scope
|
// initilized and finalize should be placed in onc scope
|
||||||
}
|
}
|
||||||
pFlow::output<< "\nFinalizing host/device execution space ...."<<pFlow::endl;
|
REPORT(0)<< "\nFinalizing host/device execution space ...."<<END_REPORT;
|
||||||
Kokkos::finalize();
|
Kokkos::finalize();
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ Licence:
|
|||||||
#ifndef __setProperty_hpp__
|
#ifndef __setProperty_hpp__
|
||||||
#define __setProperty_hpp__
|
#define __setProperty_hpp__
|
||||||
|
|
||||||
REPORT(0)<<"\nReading proprties . . . "<<endREPORT;
|
REPORT(0)<<"\nReading proprties . . . "<<END_REPORT;
|
||||||
|
|
||||||
auto proprties = pFlow::property(Control.caseSetup().path()+pFlow::propertyFile__);
|
auto proprties = pFlow::property(Control.caseSetup().path()+pFlow::propertyFile__);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ Licence:
|
|||||||
#ifndef __setSurfaceGeometry_hpp__
|
#ifndef __setSurfaceGeometry_hpp__
|
||||||
#define __setSurfaceGeometry_hpp__
|
#define __setSurfaceGeometry_hpp__
|
||||||
|
|
||||||
REPORT(0)<< "\nCreating surface geometry . . . "<<endREPORT;
|
REPORT(0)<< "\nCreating surface geometry . . . "<<END_REPORT;
|
||||||
auto surfGeometryPtr = pFlow::geometry::create(Control, proprties);
|
auto surfGeometryPtr = pFlow::geometry::create(Control, proprties);
|
||||||
auto& surfGeometry = surfGeometryPtr();
|
auto& surfGeometry = surfGeometryPtr();
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#add_subdirectory(checkPhasicFlow)
|
#add_subdirectory(checkPhasicFlow)
|
||||||
|
|
||||||
#add_subdirectory(particlesPhasicFlow)
|
add_subdirectory(particlesPhasicFlow)
|
||||||
|
|
||||||
#add_subdirectory(geometryPhasicFlow)
|
#add_subdirectory(geometryPhasicFlow)
|
||||||
|
|
||||||
#add_subdirectory(pFlowToVTK)
|
#add_subdirectory(pFlowToVTK)
|
||||||
|
|
||||||
#add_subdirectory(Utilities)
|
add_subdirectory(Utilities)
|
||||||
|
|
||||||
#add_subdirectory(postprocessPhasicFlow)
|
#add_subdirectory(postprocessPhasicFlow)
|
||||||
|
|
||||||
|
@ -2,15 +2,17 @@
|
|||||||
set(SourceFiles
|
set(SourceFiles
|
||||||
readFromTimeFolder.cpp
|
readFromTimeFolder.cpp
|
||||||
readControlDict.cpp
|
readControlDict.cpp
|
||||||
vtkFile/vtkFile.cpp
|
#vtkFile/vtkFile.cpp
|
||||||
geometryPhasicFlow/Wall/Wall.cpp
|
#geometryPhasicFlow/Wall/Wall.cpp
|
||||||
geometryPhasicFlow/planeWall/planeWall.cpp
|
#geometryPhasicFlow/planeWall/planeWall.cpp
|
||||||
geometryPhasicFlow/stlWall/stlWall.cpp
|
#geometryPhasicFlow/stlWall/stlWall.cpp
|
||||||
geometryPhasicFlow/cylinderWall/cylinderWall.cpp
|
#geometryPhasicFlow/cylinderWall/cylinderWall.cpp
|
||||||
geometryPhasicFlow/cuboidWall/cuboidWall.cpp
|
#geometryPhasicFlow/cuboidWall/cuboidWall.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(link_libs Kokkos::kokkos phasicFlow Particles Geometry)
|
#set(link_libs Kokkos::kokkos phasicFlow Particles Geometry)
|
||||||
|
|
||||||
|
set(link_libs Kokkos::kokkos phasicFlow)
|
||||||
|
|
||||||
pFlow_add_library_install(Utilities SourceFiles link_libs)
|
pFlow_add_library_install(Utilities SourceFiles link_libs)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ bool pFlow::cylinderWall::createCylinder(
|
|||||||
real L = zAx.length();
|
real L = zAx.length();
|
||||||
|
|
||||||
|
|
||||||
realx3Vector r1P(numDiv + 1), r2P(numDiv + 1);
|
realx3Vector r1P("r1P",numDiv + 1), r2P("r1P",numDiv + 1);
|
||||||
real dTheta = 2 * Pi / numDiv;
|
real dTheta = 2 * Pi / numDiv;
|
||||||
real theta = 0;
|
real theta = 0;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ bool pFlow::stlWall::readSTLWall
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(label i=0; i<stl.size(); i++)
|
for(uint64 i=0; i<stl.size(); i++)
|
||||||
{
|
{
|
||||||
auto it = triangles_.end();
|
auto it = triangles_.end();
|
||||||
triangles_.insert(it, stl.solid(i).begin(), stl.solid(i).end());
|
triangles_.insert(it, stl.solid(i).begin(), stl.solid(i).end());
|
||||||
|
@ -20,7 +20,7 @@ Licence:
|
|||||||
#ifndef __readFromTimeFolder_hpp__
|
#ifndef __readFromTimeFolder_hpp__
|
||||||
#define __readFromTimeFolder_hpp__
|
#define __readFromTimeFolder_hpp__
|
||||||
|
|
||||||
|
#include "vocabs.hpp"
|
||||||
#include "repository.hpp"
|
#include "repository.hpp"
|
||||||
#include "pointFields.hpp"
|
#include "pointFields.hpp"
|
||||||
#include "utilityFunctions.hpp"
|
#include "utilityFunctions.hpp"
|
||||||
|
@ -6,6 +6,8 @@ positionOrdered/positionOrdered.cpp
|
|||||||
#positionRandom/positionRandom.cpp
|
#positionRandom/positionRandom.cpp
|
||||||
empty/empty.cpp
|
empty/empty.cpp
|
||||||
)
|
)
|
||||||
set(link_lib phasicFlow Kokkos::kokkos Interaction Utilities)
|
#set(link_lib phasicFlow Kokkos::kokkos Interaction Utilities)
|
||||||
|
|
||||||
|
set(link_lib phasicFlow Kokkos::kokkos Utilities)
|
||||||
|
|
||||||
pFlow_make_executable_install(particlesPhasicFlow source_files link_lib)
|
pFlow_make_executable_install(particlesPhasicFlow source_files link_lib)
|
||||||
|
@ -21,25 +21,14 @@ Licence:
|
|||||||
|
|
||||||
#include "positionParticles.hpp"
|
#include "positionParticles.hpp"
|
||||||
#include "pointStructure.hpp"
|
#include "pointStructure.hpp"
|
||||||
#include "setFields.hpp"
|
//#include "setFields.hpp"
|
||||||
#include "systemControl.hpp"
|
#include "systemControl.hpp"
|
||||||
#include "commandLine.hpp"
|
#include "commandLine.hpp"
|
||||||
#include "vocabs.hpp"
|
#include "vocabs.hpp"
|
||||||
|
|
||||||
//#include "readControlDict.hpp"
|
//#include "readControlDict.hpp"
|
||||||
|
|
||||||
using pFlow::output;
|
using namespace pFlow;
|
||||||
using pFlow::endl;
|
|
||||||
using pFlow::dictionary;
|
|
||||||
using pFlow::uniquePtr;
|
|
||||||
using pFlow::IOobject;
|
|
||||||
using pFlow::objectFile;
|
|
||||||
using pFlow::fileSystem;
|
|
||||||
using pFlow::pointStructure;
|
|
||||||
using pFlow::pointStructureFile__;
|
|
||||||
using pFlow::positionParticles;
|
|
||||||
using pFlow::commandLine;
|
|
||||||
using pFlow::setFieldList;
|
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
@ -83,7 +72,7 @@ int main( int argc, char* argv[] )
|
|||||||
// this should be palced in each main
|
// this should be palced in each main
|
||||||
#include "initialize_Control.hpp"
|
#include "initialize_Control.hpp"
|
||||||
|
|
||||||
auto objCPDict = IOobject::make<dictionary>
|
auto objCPDict = IOobject::make<fileDictionary>
|
||||||
(
|
(
|
||||||
objectFile
|
objectFile
|
||||||
(
|
(
|
||||||
@ -92,11 +81,10 @@ int main( int argc, char* argv[] )
|
|||||||
objectFile::READ_ALWAYS,
|
objectFile::READ_ALWAYS,
|
||||||
objectFile::WRITE_ALWAYS
|
objectFile::WRITE_ALWAYS
|
||||||
),
|
),
|
||||||
"particlesDict",
|
"particlesDict"
|
||||||
true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
auto& cpDict = objCPDict().getObject<dictionary>();
|
auto& cpDict = objCPDict().getObject<fileDictionary>();
|
||||||
|
|
||||||
pointStructure* pStructPtr = nullptr;
|
pointStructure* pStructPtr = nullptr;
|
||||||
|
|
||||||
@ -128,19 +116,19 @@ int main( int argc, char* argv[] )
|
|||||||
|
|
||||||
pStructPtr = &pStruct;
|
pStructPtr = &pStruct;
|
||||||
|
|
||||||
|
|
||||||
REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<<
|
REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<<
|
||||||
pStruct.capacity()<<" . . ."<< END_REPORT;
|
pStruct.capacity()<<" . . ."<< END_REPORT;
|
||||||
|
|
||||||
REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< END_REPORT<<endl<<endl;
|
//REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< END_REPORT<<endl<<endl;
|
||||||
|
|
||||||
if( !Control.time().write())
|
/*if( !Control.time().write())
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
"ERRor in writing to file. \n ";
|
"ERRor in writing to file. \n ";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}*/
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
auto& pStruct = Control.time().emplaceObject<pointStructure>
|
auto& pStruct = Control.time().emplaceObject<pointStructure>
|
||||||
@ -163,8 +151,8 @@ int main( int argc, char* argv[] )
|
|||||||
|
|
||||||
if(!positionOnly)
|
if(!positionOnly)
|
||||||
{
|
{
|
||||||
|
WARNING<< "setFields is not active "<<END_WARNING;
|
||||||
auto& pStruct = *pStructPtr;
|
/* auto& pStruct = *pStructPtr;
|
||||||
|
|
||||||
auto& sfDict = cpDict.subDict("setFields");
|
auto& sfDict = cpDict.subDict("setFields");
|
||||||
|
|
||||||
@ -197,10 +185,16 @@ int main( int argc, char* argv[] )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
output<<endl;
|
output<<endl;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Control.time().write(true);
|
|
||||||
|
if( !Control.time().write(true))
|
||||||
|
{
|
||||||
|
fatalErrorInFunction<<
|
||||||
|
"ERRor in writing to file. \n ";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
REPORT(0)<< Green_Text("\nFinished successfully.\n")<<END_REPORT;
|
REPORT(0)<< Green_Text("\nFinished successfully.\n")<<END_REPORT;
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ Licence:
|
|||||||
#include "cylinder.hpp"
|
#include "cylinder.hpp"
|
||||||
#include "sphere.hpp"
|
#include "sphere.hpp"
|
||||||
#include "cells.hpp"
|
#include "cells.hpp"
|
||||||
#include "contactSearchFunctions.hpp"
|
//#include "contactSearchFunctions.hpp"
|
||||||
|
|
||||||
#include "streams.hpp"
|
#include "streams.hpp"
|
||||||
|
|
||||||
@ -32,20 +32,20 @@ pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& pos
|
|||||||
{
|
{
|
||||||
struct indexMorton
|
struct indexMorton
|
||||||
{
|
{
|
||||||
size_t morton;
|
uint64 morton;
|
||||||
size_t index;
|
uint64 index;
|
||||||
};
|
};
|
||||||
|
|
||||||
realx3 minP = min(position);
|
/*realx3 minP = min(position);
|
||||||
realx3 maxP = max(position);
|
realx3 maxP = max(position);
|
||||||
real cellsize = maxDiameter();
|
real cellsize = maxDiameter();
|
||||||
cells<size_t> allCells( box(minP, maxP), cellsize);
|
cells<uint64> allCells( box(minP, maxP), cellsize);
|
||||||
|
|
||||||
Vector<indexMorton> indMor(position.size(),RESERVE());
|
Vector<indexMorton> indMor(position.size(),RESERVE());
|
||||||
|
|
||||||
indMor.clear();
|
indMor.clear();
|
||||||
|
|
||||||
size_t ind=0;
|
uint64 ind=0;
|
||||||
for(const auto& p:position)
|
for(const auto& p:position)
|
||||||
{
|
{
|
||||||
auto cellInd = allCells.pointIndex(p);
|
auto cellInd = allCells.pointIndex(p);
|
||||||
@ -68,9 +68,10 @@ pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& pos
|
|||||||
for(auto& ind:indMor)
|
for(auto& ind:indMor)
|
||||||
{
|
{
|
||||||
sortedPos.push_back( position[ind.index] );
|
sortedPos.push_back( position[ind.index] );
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return sortedPos;
|
WARNING<<"Morton sorting is inactive!"<<END_WARNING;
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ pFlow::positionParticles::positionParticles
|
|||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<size_t>(10000));
|
maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<uint64>(10000));
|
||||||
|
|
||||||
mortonSorting_ = dict.getValOrSet("mortonSorting", Logical("Yes"));
|
mortonSorting_ = dict.getValOrSet("mortonSorting", Logical("Yes"));
|
||||||
|
|
||||||
@ -90,11 +91,13 @@ pFlow::positionParticles::positionParticles
|
|||||||
}
|
}
|
||||||
else if(dict.containsDictionay("cylinder"))
|
else if(dict.containsDictionay("cylinder"))
|
||||||
{
|
{
|
||||||
region_ = makeUnique<region<cylinder>>(dict.subDict("cylinder"));
|
WARNING<<"cylinder region is not set!"<<END_WARNING;
|
||||||
|
//region_ = makeUnique<region<cylinder>>(dict.subDict("cylinder"));
|
||||||
}
|
}
|
||||||
else if(dict.containsDictionay("sphere"))
|
else if(dict.containsDictionay("sphere"))
|
||||||
{
|
{
|
||||||
region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
|
WARNING<<"sphere region is not set!"<<END_WARNING;
|
||||||
|
//region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -112,7 +115,7 @@ pFlow::realx3Vector pFlow::positionParticles::getFinalPosition()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
realx3Vector vec(position().capacity(), RESERVE());
|
realx3Vector vec("final position",position().capacity(), 0 , RESERVE());
|
||||||
vec.assign( position().begin(), position().end());
|
vec.assign( position().begin(), position().end());
|
||||||
|
|
||||||
return std::move(vec);
|
return std::move(vec);
|
||||||
@ -132,7 +135,7 @@ pFlow::uniquePtr<pFlow::positionParticles>
|
|||||||
|
|
||||||
if( dictionaryvCtorSelector_.search(method) )
|
if( dictionaryvCtorSelector_.search(method) )
|
||||||
{
|
{
|
||||||
return dictionaryvCtorSelector_[method] (dict);
|
return dictionaryvCtorSelector_[method] (control, dict);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user