MPI-parallelization upto IO file
This commit is contained in:
parent
280f53a230
commit
f5d8daa608
|
@ -74,7 +74,7 @@ add_subdirectory(src)
|
|||
|
||||
#add_subdirectory(solvers)
|
||||
|
||||
add_subdirectory(utilities)
|
||||
#add_subdirectory(utilities)
|
||||
|
||||
#add_subdirectory(DEMSystems)
|
||||
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="$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
|
||||
|
||||
processors/processors.cpp
|
||||
processors/localProcessors.cpp
|
||||
processors/pFlowProcessors.cpp
|
||||
|
||||
streams/token/tokenIO.cpp
|
||||
streams/token/token.cpp
|
||||
streams/iStream/IOstream.cpp
|
||||
|
@ -20,14 +24,10 @@ streams/TStream/oTstream.cpp
|
|||
streams/Fstream/iFstream.cpp
|
||||
streams/Fstream/oFstream.cpp
|
||||
streams/Fstream/fileStream.cpp
|
||||
streams/dataIO/dataIO.cpp
|
||||
streams/dataIO/dataIONoMPI.cpp
|
||||
streams/streams.cpp
|
||||
|
||||
fileSystem/fileSystem.cpp
|
||||
|
||||
processors/processors.cpp
|
||||
|
||||
dictionary/dictionary.cpp
|
||||
dictionary/fileDictionary.cpp
|
||||
dictionary/entry/iEntry.cpp
|
||||
|
@ -39,6 +39,9 @@ containers/Field/Fields.cpp
|
|||
containers/List/anyList/anyList.cpp
|
||||
containers/pointField/pointFields.cpp
|
||||
|
||||
#setFieldList/setFieldList.cpp
|
||||
#setFieldList/setFieldEntry.cpp
|
||||
|
||||
Timer/Timer.cpp
|
||||
Timer/Timers.cpp
|
||||
|
||||
|
@ -64,21 +67,58 @@ structuredData/plane/plane.cpp
|
|||
structuredData/domain/domain.cpp
|
||||
structuredData/domain/simulationDomain.cpp
|
||||
structuredData/domain/regularSimulationDomain.cpp
|
||||
structuredData/pointStructure/boundaryList.cpp
|
||||
structuredData/pointStructure/internalPoints.cpp
|
||||
structuredData/pointStructure/pointStructure.cpp
|
||||
structuredData/boundaries/boundaryBase/boundaryBase.cpp
|
||||
structuredData/boundaries/boundaryExit/boundaryExit.cpp
|
||||
structuredData/pointStructure/boundaryList.cpp
|
||||
|
||||
commandLine/commandLine.cpp
|
||||
|
||||
|
||||
)
|
||||
|
||||
set(link_libs)
|
||||
if(MPI_FOUND)
|
||||
set(link_libs Kokkos::kokkos tbb PRIVATE MPI::MPI_CXX)
|
||||
set(link_libs Kokkos::kokkos tbb)
|
||||
|
||||
|
||||
|
||||
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()
|
||||
set(link_libs Kokkos::kokkos tbb)
|
||||
pFlow_add_library_install(phasicFlow SourceFiles link_libs)
|
||||
target_include_directories(phasicFlow PUBLIC ./globals)
|
||||
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(
|
||||
"--description",
|
||||
[disptn, appName]() {
|
||||
output<<"\n"<<yellowText(versoinCopyright)<<endl;
|
||||
output<<yellowText(floatingPointDescription())<<endl<<endl;
|
||||
output<<"Description for "<< boldText(appName)<<":\n";
|
||||
output<<" "<<disptn<<endl;
|
||||
mOutput<<"\n"<<Yellow_Text(versoinCopyright)<<endl;
|
||||
mOutput<<Yellow_Text(floatingPointDescription())<<endl<<endl;
|
||||
mOutput<<"Description for "<< Bold_Text(appName)<<":\n";
|
||||
mOutput<<" "<<disptn<<endl;
|
||||
},
|
||||
"What does this app do?"
|
||||
)->configurable(false);
|
||||
|
|
|
@ -185,12 +185,14 @@ template<template<class, class> class VectorField, class T, class PropType>
|
|||
bool pFlow::Field<VectorField, T, PropType>::read
|
||||
(
|
||||
iIstream& is,
|
||||
IOPattern::IOType iotype
|
||||
const IOPattern& iop
|
||||
)
|
||||
{
|
||||
|
||||
bool tokenFound;
|
||||
tokenFound = is.findToken(fieldKey_);
|
||||
bool tokenFound = true;
|
||||
|
||||
if(iop.thisProcReadData())
|
||||
tokenFound = is.findToken(fieldKey_);
|
||||
|
||||
if( !tokenFound )
|
||||
{
|
||||
|
@ -199,12 +201,13 @@ bool pFlow::Field<VectorField, T, PropType>::read
|
|||
return false;
|
||||
}
|
||||
|
||||
if( !VectorType::read(is, iotype) )
|
||||
if( !VectorType::read(is, iop) )
|
||||
{
|
||||
ioErrorInFile(is.name(), is.lineNumber())<<
|
||||
"error in reading field data from field "<< this->name()<<endl;
|
||||
}
|
||||
is.readEndStatement("Field::read");
|
||||
if(iop.thisProcReadData())
|
||||
is.readEndStatement("Field::read");
|
||||
|
||||
|
||||
return true;
|
||||
|
@ -213,14 +216,14 @@ bool pFlow::Field<VectorField, T, PropType>::read
|
|||
template<template<class, class> class VectorField, class T, class PropType>
|
||||
bool pFlow::Field<VectorField, T, PropType>::write(
|
||||
iOstream& os,
|
||||
IOPattern::IOType iotype)const
|
||||
const IOPattern& iop)const
|
||||
{
|
||||
|
||||
os.writeWordKeyword(fieldKey_)<<endl;
|
||||
|
||||
if(!os.check(FUNCTION_NAME))return false;
|
||||
|
||||
if(!VectorType::write(os, iotype)) return false;
|
||||
if(!VectorType::write(os, iop)) return false;
|
||||
|
||||
os.endEntry();
|
||||
if(!os.check(FUNCTION_NAME))return false;
|
||||
|
|
|
@ -27,7 +27,7 @@ Licence:
|
|||
|
||||
#include "types.hpp"
|
||||
#include "Vector.hpp"
|
||||
|
||||
#include "streams.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
@ -193,15 +193,15 @@ public:
|
|||
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>
|
||||
bool write(
|
||||
iOstream& os,
|
||||
IOPattern::IOType iotype,
|
||||
const IOPattern& iop,
|
||||
const HostMask& mask)const
|
||||
{
|
||||
|
||||
|
@ -209,7 +209,7 @@ public:
|
|||
|
||||
if(!os.check(FUNCTION_NAME))return false;
|
||||
|
||||
if(!VectorType::write(os, iotype)) return false;
|
||||
if(!VectorType::write(os, iop)) return false;
|
||||
|
||||
os.endEntry();
|
||||
if(!os.check(FUNCTION_NAME))return false;
|
||||
|
|
|
@ -23,10 +23,10 @@ template<typename T, typename Allocator>
|
|||
bool pFlow::Vector<T, Allocator>::readVector
|
||||
(
|
||||
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
|
||||
(
|
||||
iOstream& os,
|
||||
IOPattern::IOType iotype
|
||||
const IOPattern& iop
|
||||
) const
|
||||
{
|
||||
return writeStdVector(os, vectorField(), iotype);
|
||||
return writeStdVector(os, vectorField(), iop);
|
||||
}
|
||||
|
||||
/*template<typename T, typename Allocator>
|
||||
|
|
|
@ -334,7 +334,7 @@ public:
|
|||
inline
|
||||
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()
|
||||
|
@ -357,19 +357,19 @@ public:
|
|||
inline VectorType operator -()const;
|
||||
|
||||
/// Read vector (assume ASCII in input)
|
||||
bool readVector(iIstream& is, IOPattern::IOType iotype);
|
||||
bool readVector(iIstream& is, const IOPattern& iop);
|
||||
|
||||
/// 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 "iOstream.hpp"
|
||||
#include "iIstream.hpp"
|
||||
#include "dataIO.hpp"
|
||||
|
||||
#include "createDataIO.hpp"
|
||||
#include "pFlowProcessors.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
@ -54,11 +54,11 @@ inline
|
|||
bool writeSpan(
|
||||
iOstream& os,
|
||||
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)
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
|
@ -73,32 +73,27 @@ bool writeSpan(
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename Allocator>
|
||||
bool writeStdVector
|
||||
(
|
||||
iOstream& os,
|
||||
const std::vector<T,Allocator>& vec,
|
||||
IOPattern::IOType iotype
|
||||
const IOPattern& iop
|
||||
)
|
||||
{
|
||||
span<T> sp( const_cast<T*>(vec.data()), vec.size());
|
||||
|
||||
return writeSpan(os, sp, iotype);
|
||||
auto sp = makeSpan(vec);
|
||||
return writeSpan(os, sp, iop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T, typename Allocator>
|
||||
bool readStdVector
|
||||
(
|
||||
iIstream& is,
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -415,7 +415,7 @@ template<typename T, typename MemorySpace>
|
|||
INLINE_FUNCTION_H
|
||||
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>
|
||||
|
|
|
@ -370,10 +370,10 @@ public:
|
|||
|
||||
/// Read vector from stream (ASCII)
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is, IOPattern::IOType iotype)
|
||||
bool read(iIstream& is, const IOPattern& iop)
|
||||
{
|
||||
std::vector<T> vecFromFile;
|
||||
if(! readStdVector(is, vecFromFile, iotype)) return false;
|
||||
if(! readStdVector(is, vecFromFile, iop)) return false;
|
||||
|
||||
this->assign(vecFromFile);
|
||||
|
||||
|
@ -382,18 +382,18 @@ public:
|
|||
|
||||
/// Write the vector to os
|
||||
FUNCTION_H
|
||||
bool write(iOstream& os, IOPattern::IOType iotype)const
|
||||
bool write(iOstream& os, const IOPattern& iop)const
|
||||
{
|
||||
auto hVec = hostVector();
|
||||
auto sp = span<T>( const_cast<T*>(hVec.data()), hVec.size());
|
||||
|
||||
return writeSpan(os, sp, iotype);
|
||||
return writeSpan(os, sp, iop);
|
||||
|
||||
}
|
||||
|
||||
template<typename HostMask>
|
||||
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();
|
||||
|
||||
|
@ -413,7 +413,7 @@ public:
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -19,8 +19,8 @@ Licence:
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "demComponent.hpp"
|
||||
|
||||
|
||||
#include "systemControl.hpp"
|
||||
#include "Time.hpp"
|
||||
|
||||
pFlow::demComponent::demComponent(const word& name, systemControl& control)
|
||||
:
|
||||
|
@ -28,4 +28,14 @@ pFlow::demComponent::demComponent(const word& name, systemControl& control)
|
|||
control_(control),
|
||||
time_(control.time()),
|
||||
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__
|
||||
#define __demComponent_hpp__
|
||||
|
||||
#include "systemControl.hpp"
|
||||
#include "Time.hpp"
|
||||
|
||||
#include "types.hpp"
|
||||
#include "typeInfo.hpp"
|
||||
#include "Timers.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class systemControl;
|
||||
class Time;
|
||||
/**
|
||||
* A base class for every main component of DEM system.
|
||||
*
|
||||
|
@ -96,19 +98,11 @@ public:
|
|||
}
|
||||
|
||||
/// Time step of integration
|
||||
inline
|
||||
real dt()const
|
||||
{
|
||||
return time_.dt();
|
||||
}
|
||||
|
||||
real dt()const;
|
||||
|
||||
/// Current simulation time
|
||||
inline
|
||||
real currentTime()const
|
||||
{
|
||||
return time_.currentTime();
|
||||
}
|
||||
|
||||
real currentTime()const;
|
||||
|
||||
inline
|
||||
const auto& time()const
|
||||
{
|
||||
|
|
|
@ -218,6 +218,9 @@ public:
|
|||
template<typename T>
|
||||
bool addOrKeep(const word& keyword, const T& v);
|
||||
|
||||
template<typename T>
|
||||
bool addOrReplace(const word& keyword, const T& v);
|
||||
|
||||
void clear();
|
||||
|
||||
/// 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
|
||||
|
||||
|
||||
#endif // __dictionary_hpp__
|
||||
|
|
|
@ -1,22 +1,50 @@
|
|||
#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)
|
||||
:
|
||||
dictionary(keyword, file)
|
||||
{
|
||||
}
|
||||
fileDictionary
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
keyword,
|
||||
file,
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
nullptr
|
||||
)
|
||||
{}
|
||||
|
||||
bool pFlow::fileDictionary::read(iIstream &is, const IOPattern &iop)
|
||||
{
|
||||
|
||||
return dictionary::read(is);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,17 +17,18 @@ Licence:
|
|||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
#ifndef __fileDictionary_hpp__
|
||||
#define __fileDictionary_hpp__
|
||||
|
||||
#include "dictionary.hpp"
|
||||
|
||||
#include "IOobject.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class IOPattern;
|
||||
|
||||
class fileDictionary
|
||||
:
|
||||
public IOobject,
|
||||
public dictionary
|
||||
{
|
||||
public:
|
||||
|
@ -35,19 +36,22 @@ public:
|
|||
TypeInfo("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);
|
||||
|
||||
|
||||
|
||||
/// read from stream
|
||||
virtual bool read(iIstream& is, const IOPattern& iop);
|
||||
/// read from stream
|
||||
bool read(iIstream& is, const IOPattern& iop) override;
|
||||
|
||||
/// 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 "error.hpp"
|
||||
#include "iOstream.hpp"
|
||||
#include "streams.hpp"
|
||||
|
||||
|
||||
bool pFlow::fileSystem::checkFileName(const word& name)
|
||||
|
@ -47,7 +47,6 @@ pFlow::fileSystem::fileSystem(const word & wPath)
|
|||
path_(wPath),
|
||||
isDir_(std::filesystem::is_directory(path_))
|
||||
{
|
||||
std::cout<<"file name is " << fileName()<<std::endl;
|
||||
if( !isDir_ && !checkFileName(fileName()))
|
||||
{
|
||||
fatalExit;
|
||||
|
@ -276,7 +275,7 @@ pFlow::fileSystem pFlow::operator /
|
|||
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() );
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
@ -57,9 +59,9 @@ pFlow::iOstream& notImplementedErrorMessage(const char*fnName, const char* fileN
|
|||
{
|
||||
|
||||
errorStream<<"\n>>> Fatal error in phasicFlow\n";
|
||||
errorStream<<" Function "<< Red_Text(fnName) << " has not implmented yet!\n" <<
|
||||
" Function definition is in source file "<< Red_Text(fileName) <<
|
||||
" at line "<< Red_Text(lineNumber) <<'\n';
|
||||
errorStream<<" Function "<< Red_Text(fnName) << " has not been implemented yet!\n" <<
|
||||
" File "<< Yellow_Text(fileName) <<
|
||||
" at line "<< Yellow_Text(lineNumber) <<'\n';
|
||||
return errorStream;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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);
|
||||
}
|
|
@ -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"
|
||||
|
||||
#ifdef pFlow_Build_MPI
|
||||
#include <mpi.h>
|
||||
#include "mpiCommunication.hpp"
|
||||
#endif
|
||||
|
||||
// from PhasicFlow
|
||||
|
@ -29,7 +29,15 @@ Licence:
|
|||
#include "processors.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[])
|
||||
{
|
||||
|
@ -40,17 +48,31 @@ void pFlow::processors::initProcessors(int argc, char *argv[])
|
|||
CheckMPI(MPI_Init(&argc, &argv), true);
|
||||
isSelfInitialized_ = true;
|
||||
|
||||
processors::globalSize_ = MPI::COMM_WORLD.Get_size();
|
||||
processors::globalRank_ = MPI::COMM_WORLD.Get_rank();
|
||||
argc_ = argc;
|
||||
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.setPrefixNum(processors::globalRank_);
|
||||
}
|
||||
|
||||
pFlow::mOutput.setMasterSlave(processors::isMaster());
|
||||
pFlow::errReport.setMasterSlave(processors::isMaster());
|
||||
pFlow::mOutput.setMasterSlave(processors::globalMaster());
|
||||
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
|
||||
|
||||
|
@ -64,6 +86,9 @@ void pFlow::processors::finalizeProcessors()
|
|||
#ifdef pFlow_Build_MPI
|
||||
if(isSelfInitialized_ && !isFinalized())
|
||||
{
|
||||
MPI::TypeFree(&pFlow::MPI::realx3Type__);
|
||||
MPI::TypeFree(&pFlow::MPI::realx4Type__);
|
||||
MPI::TypeFree(&pFlow::MPI::int32x3Type__);
|
||||
CheckMPI(MPI_Finalize(), true);
|
||||
}
|
||||
#else
|
||||
|
@ -75,7 +100,7 @@ pFlow::processors::processors()
|
|||
{
|
||||
|
||||
#ifdef pFlow_Build_MPI
|
||||
if(isParallel() && !isInitialized())
|
||||
if(globalParallel() && !isInitialized())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"MPI communication is not initialized yet!"<<endl;
|
||||
|
|
|
@ -17,11 +17,11 @@ Licence:
|
|||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __processors_H__
|
||||
#define __processors_H__
|
||||
|
||||
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
// - Forward
|
||||
|
@ -64,6 +64,12 @@ protected:
|
|||
static inline
|
||||
int globalSize_ = 1;
|
||||
|
||||
static inline
|
||||
int argc_ = 0;
|
||||
|
||||
static inline
|
||||
char** argv_ = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
/// Initialize MPI processors
|
||||
|
@ -77,28 +83,27 @@ public:
|
|||
/// Constructor
|
||||
processors();
|
||||
|
||||
|
||||
/// Destructor
|
||||
~processors();
|
||||
|
||||
/// Master processors number (globaly in MPI).
|
||||
static inline
|
||||
int masterNo()
|
||||
int globalMasterNo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Is this a parallel MPI run.
|
||||
static inline
|
||||
bool isParallel()
|
||||
bool globalParallel()
|
||||
{
|
||||
return processors::globalSize()>1;
|
||||
}
|
||||
|
||||
static inline
|
||||
const char* runTypeName()
|
||||
const char* globalRunTypeName()
|
||||
{
|
||||
if(isParallel())
|
||||
if(globalParallel())
|
||||
{
|
||||
return "MPI";
|
||||
}
|
||||
|
@ -117,9 +122,9 @@ public:
|
|||
|
||||
/// Is this processor the master processor?
|
||||
static inline
|
||||
bool isMaster()
|
||||
bool globalMaster()
|
||||
{
|
||||
return processors::globalRank() == processors::masterNo();
|
||||
return processors::globalRank() == processors::globalMasterNo();
|
||||
}
|
||||
|
||||
/// Global size of processors
|
||||
|
@ -136,10 +141,30 @@ public:
|
|||
return globalRank_;
|
||||
}
|
||||
|
||||
static inline
|
||||
int argc()
|
||||
{
|
||||
return argc_;
|
||||
}
|
||||
|
||||
static inline
|
||||
char** argv()
|
||||
{
|
||||
return argv_;
|
||||
}
|
||||
|
||||
/// Abort MPI run or regular run
|
||||
static
|
||||
void abort(int error);
|
||||
|
||||
/*#ifdef pFlow_Build_MPI
|
||||
static inline
|
||||
auto worldCommunicator()
|
||||
{
|
||||
return pFlow::MPI::CommWorld;
|
||||
}
|
||||
#endif*/
|
||||
|
||||
}; //processors
|
||||
|
||||
|
||||
|
|
|
@ -25,14 +25,11 @@ pFlow::IOPattern::IOPattern( IOType iotype)
|
|||
ioType_(iotype),
|
||||
globalSize_(processors::globalSize()),
|
||||
globalRank_(processors::globalRank()),
|
||||
isMaster_(processors::isMaster()),
|
||||
isParallel_(processors::isParallel())
|
||||
isMaster_(processors::globalMaster()),
|
||||
isParallel_(processors::globalParallel())
|
||||
{}
|
||||
|
||||
pFlow::word pFlow::IOPattern::exeMode()
|
||||
{
|
||||
if(processors::isParallel())
|
||||
return word("MPI");
|
||||
else
|
||||
return word("NoMPI");
|
||||
return processors::globalRunTypeName();
|
||||
}
|
|
@ -54,13 +54,13 @@ public:
|
|||
MasterProcessorOnly = 0,
|
||||
AllProcessorsSimilar = 1,
|
||||
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
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
IOType ioType_;
|
||||
IOType ioType_;
|
||||
|
||||
int globalSize_ = 1;
|
||||
|
||||
|
@ -116,11 +116,18 @@ public:
|
|||
return isParallel_;
|
||||
}
|
||||
|
||||
inline
|
||||
bool thisCallRead()const
|
||||
{
|
||||
if(isMasterProcessorOnly() && !isMaster())return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool thisProcReadData()const
|
||||
{
|
||||
if(isMasterProcessorOnly() && !isMaster())return false;
|
||||
if(isMasterProcessorDistribute() && !isMaster()) return false;
|
||||
if(isMasterProcessorDistribute()&& !isMaster())return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -128,6 +135,7 @@ public:
|
|||
bool thisProcWriteData()const
|
||||
{
|
||||
if(isAllProcessorsDifferent()) return true;
|
||||
if(isMasterProcessorDistribute())return true;
|
||||
return isMaster();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ Licence:
|
|||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include "processors.hpp"
|
||||
|
||||
#include "IOfileHeader.hpp"
|
||||
#include "repository.hpp"
|
||||
|
||||
|
@ -31,13 +31,11 @@ pFlow::uniquePtr<pFlow::iFstream> pFlow::IOfileHeader::inStream()const
|
|||
|
||||
pFlow::uniquePtr<pFlow::oFstream> pFlow::IOfileHeader::outStream()const
|
||||
{
|
||||
|
||||
|
||||
auto osPtr = makeUnique<oFstream>(path(), outFileBinary());
|
||||
|
||||
if(osPtr && owner_)
|
||||
if(osPtr && owner())
|
||||
{
|
||||
auto outPrecision = owner_->outFilePrecision();
|
||||
auto outPrecision = owner()->outFilePrecision();
|
||||
osPtr->precision(outPrecision);
|
||||
}
|
||||
|
||||
|
@ -46,21 +44,19 @@ pFlow::uniquePtr<pFlow::oFstream> pFlow::IOfileHeader::outStream()const
|
|||
|
||||
pFlow::IOfileHeader::IOfileHeader
|
||||
(
|
||||
const objectFile& objf,
|
||||
const repository* owner
|
||||
const objectFile& objf
|
||||
)
|
||||
:
|
||||
objectFile(objf),
|
||||
owner_(owner)
|
||||
objectFile(objf)
|
||||
{}
|
||||
|
||||
pFlow::fileSystem pFlow::IOfileHeader::path() const
|
||||
{
|
||||
fileSystem f;
|
||||
|
||||
if( owner_ )
|
||||
if( owner() )
|
||||
{
|
||||
f = owner_->path()/localPath();
|
||||
f = owner()->path()/localPath();
|
||||
|
||||
}else
|
||||
{
|
||||
|
@ -72,8 +68,8 @@ pFlow::fileSystem pFlow::IOfileHeader::path() const
|
|||
|
||||
bool pFlow::IOfileHeader::outFileBinary()const
|
||||
{
|
||||
if(owner_)
|
||||
return owner_->outFileBinary();
|
||||
if(owner())
|
||||
return owner()->outFileBinary();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -137,7 +133,6 @@ bool pFlow::IOfileHeader::writeHeader()const
|
|||
{
|
||||
|
||||
if( !this->readWriteHeader() ) return false;
|
||||
if( !processors::isMaster() ) return false;
|
||||
if( !implyWrite() ) return false;
|
||||
|
||||
return true;
|
||||
|
@ -185,15 +180,15 @@ bool pFlow::IOfileHeader::writeHeader(iOstream& os, bool forceWrite) const
|
|||
bool pFlow::IOfileHeader::readHeader()const
|
||||
{
|
||||
if( !implyRead())return false;
|
||||
if( !this->readWriteHeader() ) return false;
|
||||
return ioPattern().thisProcReadHeader();
|
||||
if( !this->readWriteHeader() ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::IOfileHeader::readHeader(iIstream& is, bool silent)
|
||||
{
|
||||
|
||||
if(!readHeader()) return true;
|
||||
|
||||
if(!readHeader()) return true;
|
||||
|
||||
if( !is.findTokenAndNextSilent("objectName", objectName_) )
|
||||
{
|
||||
if(!silent)
|
||||
|
@ -231,18 +226,6 @@ bool pFlow::IOfileHeader::readHeader(iIstream& is, bool silent)
|
|||
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
|
||||
{
|
||||
os<<
|
||||
|
|
|
@ -40,9 +40,7 @@ protected:
|
|||
|
||||
|
||||
//// - data members
|
||||
// owner repository
|
||||
const repository* owner_ = nullptr;
|
||||
|
||||
|
||||
// object name read from file
|
||||
word objectName_;
|
||||
|
||||
|
@ -63,7 +61,7 @@ protected:
|
|||
public:
|
||||
|
||||
// with owner
|
||||
IOfileHeader(const objectFile& objf, const repository* owner = nullptr);
|
||||
IOfileHeader(const objectFile& objf);
|
||||
|
||||
// - object name
|
||||
const word& objectName()const
|
||||
|
@ -78,11 +76,12 @@ public:
|
|||
}
|
||||
|
||||
// - pointer to owner repository
|
||||
const repository* owner()const
|
||||
{
|
||||
return owner_;
|
||||
}
|
||||
|
||||
virtual
|
||||
const repository* owner()const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// - path to file name
|
||||
fileSystem path() const;
|
||||
|
||||
|
@ -118,18 +117,13 @@ public:
|
|||
/// Write the header to the file, typeName comes from the one read from file
|
||||
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
|
||||
bool readHeader()const;
|
||||
|
||||
/// Read the header in the file
|
||||
bool readHeader(iIstream& is, bool silent=false);
|
||||
|
||||
/// Check if data should be read from file
|
||||
/// Always return true
|
||||
bool readData()const;
|
||||
|
||||
|
||||
/// write the banner
|
||||
bool writeBanner(iOstream& os)const;
|
||||
|
|
|
@ -24,53 +24,54 @@ Licence:
|
|||
|
||||
pFlow::IOobject::IOobject
|
||||
(
|
||||
const objectFile& objf,
|
||||
const repository* owner,
|
||||
uniquePtr<iObject>&& obj
|
||||
const objectFile& objf,
|
||||
const IOPattern& iop,
|
||||
repository* owner
|
||||
)
|
||||
:
|
||||
IOfileHeader(objf, owner),
|
||||
object_(obj.release())
|
||||
IOfileHeader(objf),
|
||||
ioPattern_(iop),
|
||||
owner_(owner)
|
||||
{
|
||||
|
||||
if(!read(this->readWriteHeader()))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"error in reading " << name() << " from path " << path()<<endl;
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
if(owner_&& !owner->addToRepository(this))
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
||||
pFlow::IOobject::~IOobject()
|
||||
{
|
||||
if(owner_)
|
||||
{
|
||||
owner_->removeFromRepository(this);
|
||||
}
|
||||
}
|
||||
|
||||
pFlow::IOobject::IOobject
|
||||
pFlow::repository* pFlow::IOobject::releaseOwner
|
||||
(
|
||||
const objectFile& objf,
|
||||
const repository* owner,
|
||||
uniquePtr<IOobject>&& obj
|
||||
bool fromOwner
|
||||
)
|
||||
:
|
||||
IOfileHeader(objf, owner),
|
||||
object_( obj->object_.release())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::IOobject::isObjectValid()const
|
||||
{
|
||||
return object_.get() != nullptr;
|
||||
{
|
||||
auto* old = owner_;
|
||||
if(old && !fromOwner)
|
||||
{
|
||||
old->removeFromRepository(this);
|
||||
}
|
||||
owner_ = nullptr;
|
||||
return old;
|
||||
}
|
||||
|
||||
bool pFlow::IOobject::read(bool rdHdr)
|
||||
{
|
||||
|
||||
|
||||
if( implyRead() )
|
||||
{
|
||||
if( rdHdr )
|
||||
if( rdHdr & ioPattern().thisCallRead())
|
||||
{
|
||||
if( auto ptrIS = inStream(); ptrIS )
|
||||
{
|
||||
if(!readHeader(ptrIS()))return false;
|
||||
ptrIS.reset(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -80,17 +81,20 @@ bool pFlow::IOobject::read(bool rdHdr)
|
|||
}
|
||||
}
|
||||
|
||||
if( auto ptrIS = inStream(); ptrIS )
|
||||
{
|
||||
if(!read(ptrIS(), rdHdr))return false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
warningInFunction<<
|
||||
"could not open file " << path() <<endl;
|
||||
return false;
|
||||
}
|
||||
if(ioPattern().thisCallRead())
|
||||
{
|
||||
if( auto ptrIS = inStream(); ptrIS )
|
||||
{
|
||||
if(!read(ptrIS(), rdHdr))return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
warningInFunction<<
|
||||
"could not open file " << path() <<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -101,16 +105,19 @@ bool pFlow::IOobject::write() const
|
|||
{
|
||||
if(implyWrite())
|
||||
{
|
||||
if(auto ptrOS = outStream(); ptrOS )
|
||||
{
|
||||
return write(ptrOS());
|
||||
}
|
||||
else
|
||||
{
|
||||
warningInFunction<<
|
||||
"error in opening file "<< path() <<endl;
|
||||
return false;
|
||||
}
|
||||
if(ioPattern().thisProcWriteData())
|
||||
{
|
||||
if(auto ptrOS = outStream(); ptrOS )
|
||||
{
|
||||
return write(ptrOS());
|
||||
}
|
||||
else
|
||||
{
|
||||
warningInFunction<<
|
||||
"error in opening file "<< path() <<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -119,18 +126,34 @@ bool pFlow::IOobject::write() const
|
|||
|
||||
bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
|
||||
{
|
||||
if(rdHdr)
|
||||
if(rdHdr && ioPattern().thisCallRead() )
|
||||
{
|
||||
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
|
||||
{
|
||||
if(this->readWriteHeader())
|
||||
if(this->writeHeader() && ioPattern().thisProcWriteHeader())
|
||||
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 "IOPattern.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
@ -36,177 +36,49 @@ class IOobject
|
|||
:
|
||||
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:
|
||||
|
||||
//// - data members
|
||||
IOPattern ioPattern_;
|
||||
|
||||
// underlaying data object
|
||||
uniquePtr<iObject> object_ = nullptr;
|
||||
|
||||
|
||||
mutable repository* owner_;
|
||||
|
||||
public:
|
||||
|
||||
// - typeinfo
|
||||
word typeName()const
|
||||
{
|
||||
return object_->typeName();
|
||||
}
|
||||
virtual
|
||||
word typeName() const = 0;
|
||||
|
||||
//// - Constructors
|
||||
|
||||
// - construct from components, transfer the ownership of iObject (object_t) to the
|
||||
// onwner and read the object from file
|
||||
IOobject(const objectFile& objf, const repository* owner, uniquePtr<iObject>&& obj );
|
||||
|
||||
// - construct from components, transfer the ownership of IOobject to the owner (no read happens)
|
||||
IOobject(const objectFile& objf, const repository* owner, uniquePtr<IOobject>&& obj);
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
IOobject(
|
||||
const objectFile& objf,
|
||||
const IOPattern& iop,
|
||||
repository* owner);
|
||||
|
||||
~IOobject();
|
||||
|
||||
// - copy construct
|
||||
IOobject(const IOobject& src)=delete;
|
||||
|
||||
// - move construct
|
||||
IOobject(IOobject&& src) = default;
|
||||
|
||||
|
||||
// - 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);
|
||||
IOobject(IOobject&& src) = delete;
|
||||
|
||||
|
||||
//// - Access to data object
|
||||
inline
|
||||
const IOPattern& ioPattern()const
|
||||
{
|
||||
return ioPattern_;
|
||||
}
|
||||
|
||||
// - is object valid
|
||||
bool isObjectValid()const;
|
||||
// - pointer to owner repository
|
||||
const repository* owner()const override
|
||||
{
|
||||
return owner_;
|
||||
}
|
||||
|
||||
// - ref to data object
|
||||
template<typename T>
|
||||
auto& getObject();
|
||||
|
||||
// - const ref to data object
|
||||
template<typename T>
|
||||
const auto& getObject()const;
|
||||
|
||||
repository* releaseOwner(bool fromOwner = false);
|
||||
|
||||
//// - IO operations
|
||||
|
||||
|
@ -221,7 +93,12 @@ public:
|
|||
|
||||
// - write to istream
|
||||
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
|
||||
(
|
||||
const objectFile& objf,
|
||||
|
@ -62,4 +62,4 @@ const auto& pFlow::IOobject::getObject()const
|
|||
fatalExit;
|
||||
}
|
||||
return static_cast<const object_t<T>&>(*object_).data();
|
||||
}
|
||||
}*/
|
|
@ -34,15 +34,13 @@ pFlow::objectFile::objectFile
|
|||
const fileSystem& localPath,
|
||||
const readFlag& rf,
|
||||
const writeFlag& wf,
|
||||
IOPattern::IOType ioType,
|
||||
bool rwHdr
|
||||
bool rwHeader
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
rFlag_(rf),
|
||||
wFlag_(wf),
|
||||
localPath_(localPath),
|
||||
ioPattern_(ioType),
|
||||
readWriteHeader_(rwHdr)
|
||||
readWriteHeader_(rwHeader)
|
||||
{
|
||||
}
|
|
@ -23,14 +23,10 @@ Licence:
|
|||
|
||||
#include "types.hpp"
|
||||
#include "fileSystem.hpp"
|
||||
#include "IOPattern.hpp"
|
||||
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
|
||||
|
||||
class objectFile
|
||||
{
|
||||
public:
|
||||
|
@ -66,10 +62,8 @@ protected:
|
|||
/// Number of bytes used for writing/reading real variable (used for binray)
|
||||
int numBytesForReal_ = numBytesForReal__;
|
||||
|
||||
IOPattern ioPattern_ = {IOPattern::MasterProcessorOnly};
|
||||
|
||||
/// Does the objectFile write the header or not
|
||||
bool readWriteHeader_ = true;
|
||||
/// Does the objectFile read & write the header?
|
||||
bool readWriteHeader_ = true;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -88,8 +82,7 @@ public:
|
|||
const fileSystem& localPath,
|
||||
const readFlag& rf = READ_NEVER,
|
||||
const writeFlag& wf = WRITE_NEVER,
|
||||
IOPattern::IOType ioType = IOPattern::MasterProcessorOnly,
|
||||
bool rwHdr = true
|
||||
bool rwHeader = true
|
||||
);
|
||||
|
||||
// copy construct
|
||||
|
@ -156,11 +149,6 @@ public:
|
|||
return wFlag_ == WRITE_NEVER;
|
||||
}
|
||||
|
||||
const IOPattern& ioPattern()const
|
||||
{
|
||||
return ioPattern_;
|
||||
}
|
||||
|
||||
inline
|
||||
bool readWriteHeader()const
|
||||
{
|
||||
|
|
|
@ -104,6 +104,11 @@ pFlow::Time::Time(
|
|||
}
|
||||
}
|
||||
|
||||
pFlow::fileSystem pFlow::Time::localPath()const
|
||||
{
|
||||
return fileSystem(timeName());
|
||||
}
|
||||
|
||||
bool pFlow::Time::write
|
||||
(
|
||||
bool verbose
|
||||
|
|
|
@ -70,10 +70,8 @@ public:
|
|||
|
||||
|
||||
//// - Methods
|
||||
virtual fileSystem localPath()const
|
||||
{
|
||||
return fileSystem(timeName());
|
||||
}
|
||||
fileSystem localPath()const override;
|
||||
|
||||
|
||||
// - geometry repository
|
||||
const repository& geometry()const
|
||||
|
|
|
@ -18,7 +18,6 @@ Licence:
|
|||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "repository.hpp"
|
||||
|
||||
|
||||
|
@ -33,7 +32,7 @@ pFlow::repository::repository
|
|||
localPath_(localPath),
|
||||
owner_(owner)
|
||||
{
|
||||
|
||||
|
||||
if(owner)
|
||||
{
|
||||
owner->addToRepository(this);
|
||||
|
@ -42,10 +41,20 @@ 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
|
||||
|
@ -106,26 +115,57 @@ bool pFlow::repository::addToRepository(repository* rep)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::repository::removeRepository(repository* rep)
|
||||
bool pFlow::repository::removeFromRepository(repository* rep)
|
||||
{
|
||||
auto name = rep->name();
|
||||
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
|
||||
{
|
||||
return objects_.search(nm);
|
||||
}
|
||||
|
||||
pFlow::word pFlow::repository::lookupObjectTypeName(
|
||||
pFlow::word pFlow::repository::lookupObjectTypeName
|
||||
(
|
||||
const word& nm
|
||||
)const
|
||||
)const
|
||||
{
|
||||
if(auto [iter, found] = objects_.findIf(nm); found)
|
||||
{
|
||||
return iter->second.typeName();
|
||||
return iter->second->typeName();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -143,13 +183,11 @@ bool pFlow::repository::globalLookupObjectName
|
|||
)const
|
||||
{
|
||||
|
||||
|
||||
|
||||
if(!downward)
|
||||
{
|
||||
// the object to start search and its owner
|
||||
auto object = this;
|
||||
auto owner = object->owner();
|
||||
auto* object = this;
|
||||
auto* owner = object->owner();
|
||||
|
||||
// get to the top-most repository
|
||||
while(!owner)
|
||||
|
@ -245,10 +283,10 @@ bool pFlow::repository::write
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ protected:
|
|||
repository* owner_;
|
||||
|
||||
// - sorted names of objects with object index in vector of objects
|
||||
wordMap<IOobject> objects_;
|
||||
wordMap<IOobject*> objects_;
|
||||
|
||||
// - list of repositories that this repository owns
|
||||
// - it is not a managed list of pointers!
|
||||
|
@ -100,61 +100,20 @@ public:
|
|||
// - ref to this repository
|
||||
repository& thisRepository();
|
||||
|
||||
// - add rep to this repository
|
||||
// return false if the name already exists
|
||||
/// @brief add repository to this repository
|
||||
/// return false if the name already exists
|
||||
bool addToRepository(repository* rep);
|
||||
|
||||
// - remove rep from the list of repositories
|
||||
bool removeRepository(repository* rep);
|
||||
|
||||
/// @brief remove rep from the list of repositories
|
||||
bool removeFromRepository(repository* rep);
|
||||
|
||||
//// - Add/remove objects
|
||||
|
||||
// - 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 add IOobject to this repository
|
||||
bool addToRepository(IOobject* io);
|
||||
|
||||
/// @brief remove rep from the list of repositories
|
||||
bool removeFromRepository(IOobject* io);
|
||||
|
||||
repository* releaseOwner(bool fromOwner = false);
|
||||
//// - lookups and queries
|
||||
|
||||
// - check if name of object exists
|
||||
|
|
|
@ -17,22 +17,7 @@ Licence:
|
|||
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>
|
||||
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>
|
||||
T& pFlow::repository::lookupObject(const word& name)
|
||||
{
|
||||
|
@ -150,14 +154,15 @@ T& pFlow::repository::lookupObject(const word& name)
|
|||
|
||||
if( checkType<T>(iter->second) )
|
||||
{
|
||||
return iter->second.template getObject<T>();
|
||||
return static_cast<T&>(iter->second);
|
||||
|
||||
|
||||
}else
|
||||
{
|
||||
fatalErrorInFunction <<
|
||||
reportTypeError<T>(iter->second)<<endl;
|
||||
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 "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
|
||||
(
|
||||
|
@ -108,55 +126,58 @@ pFlow::systemControl::systemControl
|
|||
(
|
||||
getTopFolder(path)
|
||||
),
|
||||
settings_
|
||||
settingsDict_
|
||||
(
|
||||
settingsRepository__,
|
||||
settingsFolder__,
|
||||
this
|
||||
),
|
||||
caseSetup_
|
||||
(
|
||||
caseSetupRepository__,
|
||||
caseSetupFolder__,
|
||||
this
|
||||
),
|
||||
settingsDict_
|
||||
(
|
||||
settings().emplaceObject<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
settingsFile__,
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER,
|
||||
IOPattern::AllProcessorsSimilar
|
||||
),
|
||||
settingsFile__
|
||||
)
|
||||
),
|
||||
libs_(settingsDict_),
|
||||
outFilePrecision_(
|
||||
settingsDict_.getValOrSet("outFilePrecision", static_cast<uint64>(6))
|
||||
),
|
||||
Time_
|
||||
makeUnique<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
settingsFile__,
|
||||
settingsFolder__,
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
this
|
||||
)
|
||||
),
|
||||
Time_
|
||||
(
|
||||
this,
|
||||
settingsDict_
|
||||
settingsDict_()
|
||||
),
|
||||
g_(
|
||||
settingsDict_.getVal<realx3>("g")
|
||||
settings_
|
||||
(
|
||||
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_),
|
||||
timersReport_
|
||||
(
|
||||
settingsDict_.getValOrSet("timersReport", Logical("Yes"))
|
||||
settingsDict_().getValOrSet("timersReport", Logical("Yes"))
|
||||
),
|
||||
writeToFileTimer_("Write to file", &timers_)
|
||||
{}
|
||||
{
|
||||
readDomainDict();
|
||||
}
|
||||
|
||||
pFlow::systemControl::systemControl(
|
||||
const real startTime,
|
||||
|
@ -179,71 +200,62 @@ pFlow::systemControl::systemControl(
|
|||
(
|
||||
getTopFolder(path)
|
||||
),
|
||||
settings_
|
||||
settingsDict_
|
||||
(
|
||||
settingsRepository__,
|
||||
settingsFolder__,
|
||||
this
|
||||
),
|
||||
caseSetup_
|
||||
(
|
||||
caseSetupRepository__,
|
||||
caseSetupFolder__,
|
||||
this
|
||||
),
|
||||
settingsDict_
|
||||
(
|
||||
settings().emplaceObject<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
settingsFile__,
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
settingsFile__
|
||||
)
|
||||
),
|
||||
libs_(settingsDict_),
|
||||
Time_
|
||||
makeUnique<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
settingsFile__,
|
||||
settingsFolder__,
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
this
|
||||
)
|
||||
),
|
||||
Time_
|
||||
(
|
||||
this,
|
||||
settingsDict_,
|
||||
settingsDict_(),
|
||||
startTime,
|
||||
endTime,
|
||||
saveInterval,
|
||||
startTimeName
|
||||
),
|
||||
settings_
|
||||
(
|
||||
makeUnique<repository>
|
||||
(
|
||||
settingsRepository__,
|
||||
settingsFolder__,
|
||||
this
|
||||
)
|
||||
),
|
||||
caseSetup_
|
||||
(
|
||||
makeUnique<repository>
|
||||
(
|
||||
caseSetupRepository__,
|
||||
caseSetupFolder__,
|
||||
this
|
||||
)
|
||||
),
|
||||
libs_(settingsDict_()),
|
||||
externalTimeControl_(true),
|
||||
g_(
|
||||
settingsDict_.getVal<realx3>("g")
|
||||
),
|
||||
domain_(
|
||||
settingsDict_.subDict("domain")
|
||||
),
|
||||
timers_(runName_),
|
||||
timersReport_
|
||||
(
|
||||
settingsDict_.getValOrSet("timersReport", Logical("Yes"))
|
||||
settingsDict_->getValOrSet("timersReport", Logical("Yes"))
|
||||
),
|
||||
writeToFileTimer_("Write to file", &timers_)
|
||||
{}
|
||||
{
|
||||
readDomainDict();
|
||||
}
|
||||
|
||||
pFlow::fileDictionary& pFlow::systemControl::domainDict()
|
||||
{
|
||||
return
|
||||
settings().emplaceObjectOrGet<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
domainFile__,
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
domainFile__
|
||||
);
|
||||
return domainDict_();
|
||||
}
|
||||
|
||||
bool pFlow::systemControl::operator ++(int)
|
||||
|
|
|
@ -50,35 +50,29 @@ protected:
|
|||
// - path to top-level folder
|
||||
const fileSystem topLevelFolder_;
|
||||
|
||||
/// settingsDict fileDictionary
|
||||
uniquePtr<fileDictionary> settingsDict_;
|
||||
|
||||
/// time repository
|
||||
Time Time_;
|
||||
|
||||
/// settings folder repository
|
||||
repository settings_;
|
||||
uniquePtr<repository> settings_;
|
||||
|
||||
/// caseSetup folder repository
|
||||
repository caseSetup_;
|
||||
uniquePtr<repository> caseSetup_;
|
||||
|
||||
/// settingsDict fileDictionary
|
||||
fileDictionary& settingsDict_;
|
||||
uniquePtr<fileDictionary> domainDict_ = nullptr;
|
||||
|
||||
/// extra libs to be loaded
|
||||
dynamicLinkLibs libs_;
|
||||
dynamicLinkLibs libs_;
|
||||
|
||||
/// precision for writing to file
|
||||
size_t outFilePrecision_ = 6;
|
||||
|
||||
/// time repository
|
||||
Time Time_;
|
||||
|
||||
/// if time control is managed externaly
|
||||
|
||||
bool externalTimeControl_ = false;
|
||||
|
||||
// - acceleration
|
||||
realx3 g_;
|
||||
|
||||
// - domain for dem world
|
||||
box domain_;
|
||||
bool externalTimeControl_ = false;
|
||||
|
||||
// all timers
|
||||
Timers timers_;
|
||||
|
@ -87,6 +81,8 @@ protected:
|
|||
|
||||
Timer writeToFileTimer_;
|
||||
|
||||
bool readDomainDict();
|
||||
|
||||
static word getRunName( const fileSystem& path);
|
||||
|
||||
static word getTopFolder(const fileSystem& path);
|
||||
|
@ -104,25 +100,25 @@ public:
|
|||
const fileSystem path = CWD() );
|
||||
|
||||
const repository& settings() const{
|
||||
return settings_;
|
||||
return settings_();
|
||||
}
|
||||
|
||||
repository& settings(){
|
||||
return settings_;
|
||||
return settings_();
|
||||
}
|
||||
|
||||
const repository& caseSetup()const{
|
||||
return caseSetup_;
|
||||
return caseSetup_();
|
||||
}
|
||||
|
||||
repository& caseSetup(){
|
||||
return caseSetup_;
|
||||
return caseSetup_();
|
||||
}
|
||||
|
||||
|
||||
const Time& time() const
|
||||
{
|
||||
return const_cast<Time&>(Time_);
|
||||
return Time_;
|
||||
}
|
||||
|
||||
Time& time()
|
||||
|
@ -156,11 +152,11 @@ public:
|
|||
}
|
||||
|
||||
const fileDictionary& settingsDict()const{
|
||||
return settingsDict_;
|
||||
return settingsDict_();
|
||||
}
|
||||
|
||||
fileDictionary& settingsDict(){
|
||||
return settingsDict_;
|
||||
return settingsDict_();
|
||||
}
|
||||
|
||||
fileDictionary& domainDict();
|
||||
|
@ -171,14 +167,14 @@ public:
|
|||
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);
|
||||
|
|
|
@ -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 "iOstream.hpp"
|
||||
#include "iIstream.hpp"
|
||||
#include "virtualConstructor.hpp"
|
||||
|
||||
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class fileSystem;
|
||||
|
||||
|
||||
template<typename T>
|
||||
class dataIO
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
static inline const uint64 ErrorReturn = static_cast<uint64>(-1);
|
||||
|
||||
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 )
|
||||
{
|
||||
return span<char>( reinterpret_cast<char*>(sp.data()), sp.size()*sizeof(T) );
|
||||
}
|
||||
|
||||
/// gather data from all processors and put the results in buffer_
|
||||
virtual bool gatherData(span<T> data) = 0;
|
||||
|
||||
public:
|
||||
|
||||
/// Type info
|
||||
TypeInfo("dataIO");
|
||||
|
||||
dataIO(IOPattern::IOType iotype, word exeMode)
|
||||
dataIO(const IOPattern& iop)
|
||||
:
|
||||
ioPattern_(iotype),
|
||||
executionMode_(exeMode)
|
||||
ioPattern_(iop)
|
||||
{}
|
||||
|
||||
|
||||
dataIO(const dataIO&) = default;
|
||||
|
||||
dataIO(dataIO &&) = default;
|
||||
|
@ -62,199 +50,24 @@ public:
|
|||
|
||||
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.
|
||||
/// This method should be called from all processors.
|
||||
template<typename T>
|
||||
bool writeData(iOstream& os, span<T> data);
|
||||
|
||||
template<typename T>
|
||||
bool readData(iIstream& is, std::vector<T>& data);
|
||||
bool readData(
|
||||
iIstream& is,
|
||||
std::vector<T>& data);
|
||||
|
||||
template<typename T>
|
||||
bool readAscii(
|
||||
iIstream& is,
|
||||
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"
|
||||
|
||||
#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
|
|
@ -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>
|
||||
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)
|
||||
if(!gatherData( createSpan(data) ) )
|
||||
if(!gatherData( data ) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"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() )
|
||||
{
|
||||
// first write the size of data
|
||||
uint64 len = buffer_.size()/sizeof(T);
|
||||
os<< len << endl;
|
||||
// first write the number of data
|
||||
uint64 numData = bufferSpan_.size();
|
||||
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<<
|
||||
"error in writing binary data to "<<os.name()<<endl;
|
||||
|
@ -28,13 +31,7 @@ bool pFlow::dataIO::writeData(iOstream& os, span<T> data)
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
/// cast the data into T
|
||||
span<T> allData(
|
||||
reinterpret_cast<T*>(buffer_.data()),
|
||||
buffer_.size()/sizeof(T));
|
||||
|
||||
if( !allData.writeASCII(os) )
|
||||
if( !bufferSpan_.writeASCII(os) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"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>
|
||||
bool pFlow::dataIO::readData
|
||||
bool pFlow::dataIO<T>::readData
|
||||
(
|
||||
iIstream& is,
|
||||
std::vector<T>& data
|
||||
)
|
||||
{
|
||||
|
||||
data.clear();
|
||||
|
||||
if(ioPattern_.thisProcReadData())
|
||||
{
|
||||
if(is.isBinary())
|
||||
{
|
||||
|
||||
// read length of data
|
||||
token firstToken(is);
|
||||
|
||||
|
@ -98,7 +119,7 @@ bool pFlow::dataIO::readData
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool pFlow::dataIO::readAscii
|
||||
bool pFlow::dataIO<T>::readAscii
|
||||
(
|
||||
iIstream& is,
|
||||
std::vector<T>& vec
|
||||
|
@ -107,7 +128,6 @@ bool pFlow::dataIO::readAscii
|
|||
|
||||
if( !ioPattern_.thisProcReadData() ) return true;
|
||||
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
vec.clear();
|
||||
|
@ -161,331 +181,10 @@ bool pFlow::dataIO::readAscii
|
|||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
realx3& minPoint()
|
||||
{
|
||||
return min_;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
realx3& maxPoint()
|
||||
{
|
||||
return max_;
|
||||
}
|
||||
|
||||
//// - IO operation
|
||||
FUNCTION_H
|
||||
bool read(iIstream & is);
|
||||
|
|
|
@ -56,4 +56,25 @@ pFlow::domain::domain(const box& db)
|
|||
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);
|
||||
}
|
||||
|
||||
/*FUNCTION_H
|
||||
iIstream& operator >>(iIstream& is, box& b);
|
||||
FUNCTION_H
|
||||
iIstream& operator >>(iIstream& is, domain& d);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
pFlow::regularSimulationDomain::regularSimulationDomain(
|
||||
const dictionary &dict)
|
||||
: simulationDomain(dict)
|
||||
{
|
||||
}
|
||||
|
||||
bool pFlow::regularSimulationDomain::updateDomains
|
||||
pFlow::regularSimulationDomain::regularSimulationDomain
|
||||
(
|
||||
const realx3Vector& pointPos
|
||||
const dictionary &dict
|
||||
)
|
||||
:
|
||||
simulationDomain(dict)
|
||||
{}
|
||||
|
||||
bool pFlow::regularSimulationDomain::initialUpdateDomains(span<realx3> pointPos)
|
||||
{
|
||||
thisNumPoints_ = pointPos.size();
|
||||
if(!createBoundaryDicts()) return false;
|
||||
if(!setThisDomain()) return false;
|
||||
|
||||
initialNumPoints_ = pointPos.size();
|
||||
if(!setThisDomain()) return false;
|
||||
if(!createBoundaryDicts()) return false;
|
||||
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> dst,
|
||||
uint32 sizeOfBlock
|
||||
size_t sizeOfElement
|
||||
)
|
||||
{
|
||||
size_t requiredSize = sizeOfBlock*thisNumPoints();
|
||||
size_t requiredSize = sizeOfElement*initialNumberInThis();
|
||||
if(dst.size() < requiredSize)
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
|
@ -103,6 +118,54 @@ bool pFlow::regularSimulationDomain::transferBlockData
|
|||
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
|
||||
{
|
||||
return globalDomainDict_.subDict("regularSimulationDomainBoundaries");
|
||||
|
|
|
@ -13,7 +13,7 @@ class regularSimulationDomain
|
|||
{
|
||||
protected:
|
||||
|
||||
uint32 thisNumPoints_=0;
|
||||
uint32 initialNumPoints_=0;
|
||||
|
||||
bool createBoundaryDicts() override;
|
||||
|
||||
|
@ -35,16 +35,44 @@ public:
|
|||
dictionary
|
||||
);
|
||||
|
||||
bool updateDomains(
|
||||
const realx3Vector& pointPos)override;
|
||||
bool initialUpdateDomains(span<realx3> pointPos) override;
|
||||
|
||||
uint32 thisNumPoints()const override;
|
||||
uint32 initialNumberInThis()const override;
|
||||
|
||||
|
||||
bool transferBlockData(
|
||||
/*bool updateDomains(
|
||||
span<realx3> pointPos,
|
||||
pFlagTypeHost flags) override;*/
|
||||
|
||||
uint32 numberToBeImported()const override;
|
||||
|
||||
uint32 numberToBeExported()const override;
|
||||
|
||||
bool initialTransferBlockData(
|
||||
span<char> src,
|
||||
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;
|
||||
|
||||
|
|
|
@ -19,23 +19,23 @@ Licence:
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "simulationDomain.hpp"
|
||||
#include "processors.hpp"
|
||||
#include "pFlowProcessors.hpp"
|
||||
|
||||
pFlow::simulationDomain::simulationDomain(const dictionary& dict)
|
||||
:
|
||||
globalBox_(dict.subDict("globalBox")),
|
||||
globalDomainDict_(dict)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
pFlow::uniquePtr<pFlow::simulationDomain>
|
||||
pFlow::simulationDomain::create(const dictionary &dict)
|
||||
{
|
||||
|
||||
word sType = angleBracketsNames(
|
||||
"simulationDomain",
|
||||
processors::runTypeName());
|
||||
pFlowProcessors().localRunTypeName());
|
||||
|
||||
|
||||
if( dictionaryvCtorSelector_.search(sType) )
|
||||
{
|
||||
|
|
|
@ -17,19 +17,22 @@ Licence:
|
|||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __simulationDomain_hpp__
|
||||
#define __simulationDomain_hpp__
|
||||
|
||||
#include "domain.hpp"
|
||||
#include "virtualConstructor.hpp"
|
||||
#include "Vectors.hpp"
|
||||
#include <array>
|
||||
|
||||
#include "domain.hpp"
|
||||
#include "span.hpp"
|
||||
#include "streams.hpp"
|
||||
#include "virtualConstructor.hpp"
|
||||
#include "pointFlag.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
//class pFlagTypeHost;
|
||||
|
||||
class simulationDomain
|
||||
{
|
||||
private:
|
||||
|
@ -56,9 +59,9 @@ protected:
|
|||
|
||||
bool boundariesSet_ = false;
|
||||
|
||||
virtual bool createBoundaryDicts() = 0;
|
||||
virtual bool createBoundaryDicts() = 0;
|
||||
|
||||
virtual bool setThisDomain() = 0;
|
||||
virtual bool setThisDomain() = 0;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -84,23 +87,64 @@ public:
|
|||
virtual
|
||||
const dictionary& thisBoundaryDict()const = 0;
|
||||
|
||||
virtual
|
||||
bool initialUpdateDomains(span<realx3> pointPos) = 0;
|
||||
|
||||
virtual
|
||||
bool updateDomains(
|
||||
const realx3Vector& pointPos) = 0;
|
||||
virtual
|
||||
uint32 initialNumberInThis()const = 0;
|
||||
|
||||
//virtual getImportExportList() = 0;
|
||||
|
||||
//virtual getNumberInThisList() = 0;
|
||||
|
||||
virtual
|
||||
uint32 thisNumPoints()const = 0;
|
||||
|
||||
virtual
|
||||
bool transferBlockData(
|
||||
virtual
|
||||
bool initialTransferBlockData(
|
||||
span<char> src,
|
||||
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
|
||||
bool requiresDataTransfer() const = 0;
|
||||
|
|
|
@ -29,7 +29,7 @@ Licence:
|
|||
namespace pFlow
|
||||
{
|
||||
|
||||
class infinitePlane
|
||||
class infinitePlane
|
||||
{
|
||||
protected:
|
||||
|
||||
|
@ -137,6 +137,33 @@ public:
|
|||
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
|
||||
|
||||
FUNCTION_H
|
||||
|
|
|
@ -54,13 +54,11 @@ pFlow::plane pFlow::plane::parallelPlane(real distance)const
|
|||
return plane(pp1, pp2, pp3, pp4);
|
||||
}
|
||||
|
||||
bool pFlow::plane::validPlane4
|
||||
(
|
||||
const realx3& p1,
|
||||
const realx3& p2,
|
||||
const realx3& p3,
|
||||
const realx3& p4
|
||||
)
|
||||
bool pFlow::plane::validPlane4(
|
||||
const realx3 &p1,
|
||||
const realx3 &p2,
|
||||
const realx3 &p3,
|
||||
const realx3 &p4)
|
||||
{
|
||||
if( !validPlane3(p1,p2,p3)) return false;
|
||||
if( !infinitePlane(p1,p2,p3).pointOnPlane(p4)) return false;
|
||||
|
|
|
@ -122,6 +122,7 @@ public:
|
|||
// return the parallel plane to this plane
|
||||
plane parallelPlane(real distance)const;
|
||||
|
||||
|
||||
static
|
||||
bool validPlane4(
|
||||
const realx3& p1,
|
||||
|
|
|
@ -173,20 +173,48 @@ pFlow::internalPoints::internalPoints
|
|||
}
|
||||
|
||||
|
||||
const pFlow::internalPoints::pFlagTypeDevice&
|
||||
const pFlow::pFlagTypeDevice&
|
||||
pFlow::internalPoints::activePointsMaskD() const
|
||||
{
|
||||
return pFlagsD_;
|
||||
}
|
||||
|
||||
|
||||
const pFlow::internalPoints::pFlagTypeHost&
|
||||
const pFlow::pFlagTypeHost&
|
||||
pFlow::internalPoints::activePointsMaskH() const
|
||||
{
|
||||
syncPFlag();
|
||||
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
|
||||
pFlow::realx3Field_D &pFlow::internalPoints::pointPosition()
|
||||
{
|
||||
|
@ -218,13 +246,13 @@ FUNCTION_H
|
|||
bool pFlow::internalPoints::read
|
||||
(
|
||||
iIstream& is,
|
||||
IOPattern::IOType iotype
|
||||
const IOPattern& iop
|
||||
)
|
||||
{
|
||||
|
||||
Field<Vector, realx3 , vecAllocator<realx3>> fRead("internalPoints", "internalPoints");
|
||||
|
||||
if( !fRead.read(is, iotype))
|
||||
if( !fRead.read(is, iop))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
||||
|
@ -249,16 +277,16 @@ FUNCTION_H
|
|||
bool pFlow::internalPoints::write
|
||||
(
|
||||
iOstream& os,
|
||||
IOPattern::IOType iotype
|
||||
const IOPattern& iop
|
||||
)const
|
||||
{
|
||||
if( pFlagsD_.isAllActive())
|
||||
{
|
||||
return pointPosition_.write(os, iotype);
|
||||
return pointPosition_.write(os, iop);
|
||||
}
|
||||
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 pFlagTypeDevice = pointFlag<execution_space>;
|
||||
|
||||
using pFlagTypeHost = pointFlag<DefaultHostExecutionSpace>;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//// - data members
|
||||
|
@ -120,11 +115,19 @@ public:
|
|||
FUNCTION_H
|
||||
realx3Field_D& pointPosition();
|
||||
|
||||
/*INLINE_FUNCTION_H
|
||||
auto pointPositionHostAll()
|
||||
{
|
||||
return pointPosition_.hostVectorAll();
|
||||
}*/
|
||||
INLINE_FUNCTION_H
|
||||
auto pointPositionHost()const
|
||||
{
|
||||
return pointPosition_.hostVector();
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_H
|
||||
auto pointPositionDevice()const
|
||||
{
|
||||
return pointPosition_.deviceVector();
|
||||
}
|
||||
|
||||
hostViewType1D<realx3> activePointsHost()const;
|
||||
|
||||
// - size of data structure
|
||||
INLINE_FUNCTION_H
|
||||
|
@ -216,12 +219,12 @@ public:
|
|||
|
||||
/// Read
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is, IOPattern::IOType iotype);
|
||||
bool read(iIstream& is, const IOPattern& iop);
|
||||
|
||||
|
||||
/// Write
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
template<typename ExecutionSpace>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*------------------------------- phasicFlow ---------------------------------
|
||||
O C enter of
|
||||
O O E ngineering and
|
||||
|
@ -19,53 +20,61 @@ Licence:
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pointStructure.hpp"
|
||||
#include "simulationDomain.hpp"
|
||||
#include "systemControl.hpp"
|
||||
#include "vocabs.hpp"
|
||||
|
||||
#include "streams.hpp"
|
||||
|
||||
bool pFlow::pointStructure::distributePoints
|
||||
(
|
||||
const realx3Vector &points
|
||||
)
|
||||
bool pFlow::pointStructure::setupPointStructure(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",
|
||||
thisN,
|
||||
thisN,
|
||||
RESERVE());
|
||||
RESERVE()
|
||||
);
|
||||
|
||||
auto pSpan = makeSpan(points);
|
||||
auto iSpan = internal.getSpan();
|
||||
|
||||
auto l = sizeof(realx3);
|
||||
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))
|
||||
if(!simulationDomain_->initialTransferBlockData(pSpan, iSpan))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"Error in transfering the block data "<<endl;
|
||||
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());
|
||||
pFlagSync_ = false;
|
||||
syncPFlag();
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
pFlow::pointStructure::pointStructure
|
||||
|
@ -73,7 +82,19 @@ pFlow::pointStructure::pointStructure
|
|||
systemControl& control
|
||||
)
|
||||
:
|
||||
demComponent("particlesCM", control),
|
||||
IOobject
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
pointStructureFile__,
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_ALWAYS
|
||||
),
|
||||
IOPattern::MasterProcessorDistribute,
|
||||
&control.time()
|
||||
),
|
||||
demComponent("particlesCenterMass", control),
|
||||
internalPoints(),
|
||||
simulationDomain_
|
||||
(
|
||||
|
@ -84,37 +105,52 @@ pFlow::pointStructure::pointStructure
|
|||
simulationDomain_(),
|
||||
*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(
|
||||
systemControl& control,
|
||||
const realx3Vector &posVec)
|
||||
:
|
||||
demComponent("particlesCM", control),
|
||||
internalPoints(),
|
||||
simulationDomain_(
|
||||
simulationDomain::create(control.domainDict())),
|
||||
boundaries_(
|
||||
IOobject
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
pointStructureFile__,
|
||||
"",
|
||||
objectFile::READ_NEVER,
|
||||
objectFile::WRITE_ALWAYS
|
||||
),
|
||||
IOPattern::MasterProcessorDistribute,
|
||||
&control.time()
|
||||
),
|
||||
demComponent("particlesCenterMass", control),
|
||||
internalPoints(),
|
||||
simulationDomain_
|
||||
(
|
||||
simulationDomain::create(control.domainDict())
|
||||
),
|
||||
boundaries_
|
||||
(
|
||||
simulationDomain_(),
|
||||
*this)
|
||||
*this
|
||||
)
|
||||
{
|
||||
if(!simulationDomain_->updateDomains(posVec) )
|
||||
if(!setupPointStructure(posVec))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"Failed to update domains."<<endl;
|
||||
"Error in seting up pointStructure"<<endl;
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
boundaries_.updateLists();
|
||||
|
||||
if( !distributePoints(posVec) )
|
||||
{
|
||||
fatalErrorInFunction<<"Faild to distributes poinst"<<endl;
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool pFlow::pointStructure::beforeIteration()
|
||||
|
@ -134,28 +170,49 @@ bool pFlow::pointStructure::afterIteration()
|
|||
|
||||
bool pFlow::pointStructure::read(
|
||||
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<<
|
||||
"Error in reading pointPosition from stream "<< is.name()<<endl;
|
||||
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<<
|
||||
"error in updating domains"<<endl;
|
||||
"Error in writing pointStructure in stream "<<
|
||||
os.name()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
boundaries_.updateLists();
|
||||
|
||||
return distributePoints(fRead);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,12 @@ Licence:
|
|||
#ifndef __pointStructure_hpp__
|
||||
#define __pointStructure_hpp__
|
||||
|
||||
#include "IOobject.hpp"
|
||||
#include "demComponent.hpp"
|
||||
#include "internalPoints.hpp"
|
||||
#include "simulationDomain.hpp"
|
||||
#include "boundaryList.hpp"
|
||||
#include "streams.hpp"
|
||||
|
||||
|
||||
|
||||
|
@ -33,6 +35,7 @@ namespace pFlow
|
|||
|
||||
class pointStructure
|
||||
:
|
||||
public IOobject,
|
||||
public demComponent,
|
||||
public internalPoints
|
||||
{
|
||||
|
@ -42,9 +45,11 @@ protected:
|
|||
uniquePtr<simulationDomain> simulationDomain_ = nullptr;
|
||||
|
||||
boundaryList boundaries_;
|
||||
|
||||
|
||||
bool distributePoints(const realx3Vector& points);
|
||||
|
||||
|
||||
bool setupPointStructure(const realx3Vector& points);
|
||||
|
||||
bool initializePoints(const realx3Vector& points);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -63,19 +68,12 @@ public:
|
|||
systemControl& control,
|
||||
const realx3Vector& posVec);
|
||||
|
||||
// - copy construct
|
||||
//
|
||||
// should be changed, may causs undefined behavior
|
||||
//////////////////////////////////////////////////////////////
|
||||
pointStructure(const pointStructure&) = delete;
|
||||
|
||||
// - no move construct
|
||||
pointStructure(pointStructure&&) = delete;
|
||||
|
||||
// - copy assignment
|
||||
//
|
||||
// should be changed, may causs undefined behavior
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
pointStructure& operator=(const pointStructure&) = delete;
|
||||
|
||||
// - no move assignment
|
||||
|
@ -122,15 +120,14 @@ public:
|
|||
|
||||
/// @brief read the point structure from the input stream.
|
||||
/// @param is: input stream
|
||||
/// @param iotype: type of input pattern
|
||||
/// @param iop: type of input pattern
|
||||
/// @return true on success
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is, IOPattern::IOType iotype);
|
||||
bool read(iIstream& is, const IOPattern& iop) override;
|
||||
|
||||
|
||||
/// Write
|
||||
/*FUNCTION_H
|
||||
bool write(iOstream& os, IOPattern::IOType iotype)const; */
|
||||
bool write(iOstream& os, const IOPattern& iop)const override;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -106,10 +106,10 @@ public:
|
|||
size_t size()const;
|
||||
|
||||
// - vertecies of ith solid
|
||||
const realx3x3Vector& solid(label i)const;
|
||||
const realx3x3Vector& solid(uint64 i)const;
|
||||
|
||||
// - name of ith solid
|
||||
const word& name(label i)const;
|
||||
const word& name(uint64 i)const;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -146,6 +146,8 @@ struct triple
|
|||
/// access component
|
||||
INLINE_FUNCTION_HD const T & z()const { return z_; }
|
||||
|
||||
INLINE_FUNCTION_HD const T& comp(uint32 i) const {return *(this+i);}
|
||||
|
||||
//// methods
|
||||
|
||||
/// Dot product of two vectors
|
||||
|
|
|
@ -23,7 +23,7 @@ Licence:
|
|||
|
||||
// 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();
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ Licence:
|
|||
#ifndef __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__);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ Licence:
|
|||
#ifndef __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& surfGeometry = surfGeometryPtr();
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
|
||||
#add_subdirectory(checkPhasicFlow)
|
||||
|
||||
#add_subdirectory(particlesPhasicFlow)
|
||||
add_subdirectory(particlesPhasicFlow)
|
||||
|
||||
#add_subdirectory(geometryPhasicFlow)
|
||||
|
||||
#add_subdirectory(pFlowToVTK)
|
||||
|
||||
#add_subdirectory(Utilities)
|
||||
add_subdirectory(Utilities)
|
||||
|
||||
#add_subdirectory(postprocessPhasicFlow)
|
||||
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
set(SourceFiles
|
||||
readFromTimeFolder.cpp
|
||||
readControlDict.cpp
|
||||
vtkFile/vtkFile.cpp
|
||||
geometryPhasicFlow/Wall/Wall.cpp
|
||||
geometryPhasicFlow/planeWall/planeWall.cpp
|
||||
geometryPhasicFlow/stlWall/stlWall.cpp
|
||||
geometryPhasicFlow/cylinderWall/cylinderWall.cpp
|
||||
geometryPhasicFlow/cuboidWall/cuboidWall.cpp
|
||||
#vtkFile/vtkFile.cpp
|
||||
#geometryPhasicFlow/Wall/Wall.cpp
|
||||
#geometryPhasicFlow/planeWall/planeWall.cpp
|
||||
#geometryPhasicFlow/stlWall/stlWall.cpp
|
||||
#geometryPhasicFlow/cylinderWall/cylinderWall.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)
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ bool pFlow::cylinderWall::createCylinder(
|
|||
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 theta = 0;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ bool pFlow::stlWall::readSTLWall
|
|||
return false;
|
||||
}
|
||||
|
||||
for(label i=0; i<stl.size(); i++)
|
||||
for(uint64 i=0; i<stl.size(); i++)
|
||||
{
|
||||
auto it = triangles_.end();
|
||||
triangles_.insert(it, stl.solid(i).begin(), stl.solid(i).end());
|
||||
|
|
|
@ -20,7 +20,7 @@ Licence:
|
|||
#ifndef __readFromTimeFolder_hpp__
|
||||
#define __readFromTimeFolder_hpp__
|
||||
|
||||
|
||||
#include "vocabs.hpp"
|
||||
#include "repository.hpp"
|
||||
#include "pointFields.hpp"
|
||||
#include "utilityFunctions.hpp"
|
||||
|
|
|
@ -6,6 +6,8 @@ positionOrdered/positionOrdered.cpp
|
|||
#positionRandom/positionRandom.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)
|
||||
|
|
|
@ -21,25 +21,14 @@ Licence:
|
|||
|
||||
#include "positionParticles.hpp"
|
||||
#include "pointStructure.hpp"
|
||||
#include "setFields.hpp"
|
||||
//#include "setFields.hpp"
|
||||
#include "systemControl.hpp"
|
||||
#include "commandLine.hpp"
|
||||
#include "vocabs.hpp"
|
||||
|
||||
//#include "readControlDict.hpp"
|
||||
|
||||
using pFlow::output;
|
||||
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;
|
||||
using namespace pFlow;
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
|
@ -83,7 +72,7 @@ int main( int argc, char* argv[] )
|
|||
// this should be palced in each main
|
||||
#include "initialize_Control.hpp"
|
||||
|
||||
auto objCPDict = IOobject::make<dictionary>
|
||||
auto objCPDict = IOobject::make<fileDictionary>
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
|
@ -92,11 +81,10 @@ int main( int argc, char* argv[] )
|
|||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_ALWAYS
|
||||
),
|
||||
"particlesDict",
|
||||
true
|
||||
"particlesDict"
|
||||
);
|
||||
|
||||
auto& cpDict = objCPDict().getObject<dictionary>();
|
||||
auto& cpDict = objCPDict().getObject<fileDictionary>();
|
||||
|
||||
pointStructure* pStructPtr = nullptr;
|
||||
|
||||
|
@ -128,19 +116,19 @@ int main( int argc, char* argv[] )
|
|||
|
||||
pStructPtr = &pStruct;
|
||||
|
||||
|
||||
REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<<
|
||||
pStruct.capacity()<<" . . ."<< END_REPORT;
|
||||
|
||||
REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< END_REPORT<<endl<<endl;
|
||||
|
||||
if( !Control.time().write())
|
||||
//REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< END_REPORT<<endl<<endl;
|
||||
|
||||
/*if( !Control.time().write())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"ERRor in writing to file. \n ";
|
||||
return 1;
|
||||
}
|
||||
}else
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
auto& pStruct = Control.time().emplaceObject<pointStructure>
|
||||
|
@ -163,8 +151,8 @@ int main( int argc, char* argv[] )
|
|||
|
||||
if(!positionOnly)
|
||||
{
|
||||
|
||||
auto& pStruct = *pStructPtr;
|
||||
WARNING<< "setFields is not active "<<END_WARNING;
|
||||
/* auto& pStruct = *pStructPtr;
|
||||
|
||||
auto& sfDict = cpDict.subDict("setFields");
|
||||
|
||||
|
@ -197,10 +185,16 @@ int main( int argc, char* argv[] )
|
|||
return 1;
|
||||
}
|
||||
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;
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ Licence:
|
|||
#include "cylinder.hpp"
|
||||
#include "sphere.hpp"
|
||||
#include "cells.hpp"
|
||||
#include "contactSearchFunctions.hpp"
|
||||
//#include "contactSearchFunctions.hpp"
|
||||
|
||||
#include "streams.hpp"
|
||||
|
||||
|
@ -32,20 +32,20 @@ pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& pos
|
|||
{
|
||||
struct indexMorton
|
||||
{
|
||||
size_t morton;
|
||||
size_t index;
|
||||
uint64 morton;
|
||||
uint64 index;
|
||||
};
|
||||
|
||||
realx3 minP = min(position);
|
||||
/*realx3 minP = min(position);
|
||||
realx3 maxP = max(position);
|
||||
real cellsize = maxDiameter();
|
||||
cells<size_t> allCells( box(minP, maxP), cellsize);
|
||||
cells<uint64> allCells( box(minP, maxP), cellsize);
|
||||
|
||||
Vector<indexMorton> indMor(position.size(),RESERVE());
|
||||
|
||||
indMor.clear();
|
||||
|
||||
size_t ind=0;
|
||||
uint64 ind=0;
|
||||
for(const auto& p:position)
|
||||
{
|
||||
auto cellInd = allCells.pointIndex(p);
|
||||
|
@ -68,9 +68,10 @@ pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& pos
|
|||
for(auto& ind:indMor)
|
||||
{
|
||||
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
|
||||
)
|
||||
{
|
||||
maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<size_t>(10000));
|
||||
maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<uint64>(10000));
|
||||
|
||||
mortonSorting_ = dict.getValOrSet("mortonSorting", Logical("Yes"));
|
||||
|
||||
|
@ -90,11 +91,13 @@ pFlow::positionParticles::positionParticles
|
|||
}
|
||||
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"))
|
||||
{
|
||||
region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
|
||||
WARNING<<"sphere region is not set!"<<END_WARNING;
|
||||
//region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -112,7 +115,7 @@ pFlow::realx3Vector pFlow::positionParticles::getFinalPosition()
|
|||
}
|
||||
else
|
||||
{
|
||||
realx3Vector vec(position().capacity(), RESERVE());
|
||||
realx3Vector vec("final position",position().capacity(), 0 , RESERVE());
|
||||
vec.assign( position().begin(), position().end());
|
||||
|
||||
return std::move(vec);
|
||||
|
@ -132,7 +135,7 @@ pFlow::uniquePtr<pFlow::positionParticles>
|
|||
|
||||
if( dictionaryvCtorSelector_.search(method) )
|
||||
{
|
||||
return dictionaryvCtorSelector_[method] (dict);
|
||||
return dictionaryvCtorSelector_[method] (control, dict);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue