diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce683a4..233e18aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,12 +60,11 @@ if(pFlow_Build_MPI) find_package(MPI REQUIRED) endif() - include(cmake/makeLibraryGlobals.cmake) include(cmake/makeExecutableGlobals.cmake) configure_file(phasicFlowConfig.H.in phasicFlowConfig.H) - +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #add a global include directory include_directories(src/setHelpers src/demComponent "${PROJECT_BINARY_DIR}") diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 65c91b59..5024be68 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -52,6 +52,7 @@ repository/IOobject/IOPattern.cpp repository/repository/repository.cpp repository/Time/Time.cpp repository/Time/timeControl.cpp +repository/Time/baseTimeControl.cpp repository/systemControl/systemControl.cpp repository/systemControl/dynamicLinkLibs.cpp diff --git a/src/phasicFlow/Kokkos/KokkosUtilities.hpp b/src/phasicFlow/Kokkos/KokkosUtilities.hpp index 451920ab..b44a467d 100644 --- a/src/phasicFlow/Kokkos/KokkosUtilities.hpp +++ b/src/phasicFlow/Kokkos/KokkosUtilities.hpp @@ -178,6 +178,35 @@ iOstream& operator <<(iOstream& os, const Pair& p) return os; } +template +INLINE_FUNCTION_H +span makeSpan(ViewType1D & v) +{ + return span(v.data(), v.size()); +} + +template +INLINE_FUNCTION_H +span makeSpan(ViewType1D & v, uint32 size) +{ + return span(v.data(), size); +} + +template +INLINE_FUNCTION_H +span makeSpan(const ViewType1D & v) +{ + return span(const_cast(v.data()), v.size()); +} + +template +INLINE_FUNCTION_H +span makeSpan(const ViewType1D & v, uint32 size) +{ + return span(const_cast(v.data()), size); +} + + template INLINE_FUNCTION_H iOstream& operator <<(iOstream& os, const ViewType1D & v) diff --git a/src/phasicFlow/Kokkos/Range.hpp b/src/phasicFlow/Kokkos/Range.hpp index 72ecd20b..a47e451c 100644 --- a/src/phasicFlow/Kokkos/Range.hpp +++ b/src/phasicFlow/Kokkos/Range.hpp @@ -46,7 +46,7 @@ public Kokkos::pair { using Pair = Kokkos::pair; - TypeInfoTemplateNV("Range", T) + TypeInfoTemplateNV11("Range", T) //// - Constructors diff --git a/src/phasicFlow/Timer/Timer.cpp b/src/phasicFlow/Timer/Timer.cpp index 9a4546e4..424addec 100644 --- a/src/phasicFlow/Timer/Timer.cpp +++ b/src/phasicFlow/Timer/Timer.cpp @@ -22,7 +22,7 @@ Licence: #include "Timers.hpp" #include "streams.hpp" -pFlow::Timer::Timer(const word name, Timers* parrent) +pFlow::Timer::Timer(const word& name, Timers* parrent) : name_(name), parrent_(parrent) diff --git a/src/phasicFlow/Timer/Timer.hpp b/src/phasicFlow/Timer/Timer.hpp index 4c731444..ac32ba35 100644 --- a/src/phasicFlow/Timer/Timer.hpp +++ b/src/phasicFlow/Timer/Timer.hpp @@ -63,15 +63,15 @@ public: TypeInfo("Timer"); - Timer(){} + Timer() = default; - Timer(const word name) + explicit Timer(const word& name) : name_(name) {} - Timer(const word name, Timers* parrent); + Timer(const word& name, Timers* parrent); const word& name()const diff --git a/src/phasicFlow/containers/Field/Field.hpp b/src/phasicFlow/containers/Field/Field.hpp index 113437f6..ae6d90da 100644 --- a/src/phasicFlow/containers/Field/Field.hpp +++ b/src/phasicFlow/containers/Field/Field.hpp @@ -74,7 +74,7 @@ protected: public: /// type info - TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName()); + TypeInfoTemplateNV111("Field", T, VectorType::memoerySpaceName()); //// - Constructors @@ -178,10 +178,15 @@ public: //// - Methods /// return field key - const word& fieldKey()const + word fieldKey()const { return fieldKey_; } + + word name()const + { + return VectorType::name(); + } //// - IO operations /*bool readField(iIstream& is, const size_t len, bool resume, bool readLength = true); @@ -196,28 +201,7 @@ public: bool read(iIstream& is, const IOPattern& iop); - bool write(iOstream& os, const IOPattern& iop )const; - - template - bool write( - iOstream& os, - const IOPattern& iop, - const HostMask& mask)const - { - - os.writeWordKeyword(fieldKey_)<(); - - /// Name of the memory space - constexpr static inline - const char* memoerySpaceName() - { - return memory_space::name(); - } - /// Evaluate capacity based on the input size static INLINE_FUNCTION_H uint32 evalCapacity(uint32 n) { @@ -136,7 +128,7 @@ protected: public: /// Type info - TypeInfoTemplateNV2("VectorSingle", T, memoerySpaceName()); + TypeInfoTemplateNV111("VectorSingle", T, memoerySpaceName()); //// - Constructors @@ -416,6 +408,12 @@ public: return writeSpan(os, sp, iop); } + /// Name of the memory space + constexpr static inline + const char* memoerySpaceName() + { + return memory_space::name(); + } }; // class VectorSingle diff --git a/src/phasicFlow/containers/pointField/boundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField.cpp index 21db4031..5ef89d88 100644 --- a/src/phasicFlow/containers/pointField/boundaryField.cpp +++ b/src/phasicFlow/containers/pointField/boundaryField.cpp @@ -21,8 +21,8 @@ Licence: template class VectorField, class T, class MemorySpace> pFlow::boundaryField::boundaryField ( - const boundaryBase& boundary, - FieldType &internal + const boundaryBase& boundary, + InternalFieldType& internal ) : observer(), @@ -30,3 +30,33 @@ pFlow::boundaryField::boundaryField internal_(internal) {} + +template class VectorField, class T, class MemorySpace> +pFlow::uniquePtr> + pFlow::boundaryField::create +( + const boundaryBase& boundary, + InternalFieldType& internal +) +{ + + word bType = angleBracketsNames("boundaryField", boundary.type()); + + if(boundaryBasevCtorSelector_.search(bType)) + { + return boundaryBasevCtorSelector_[bType](boundary, internal); + } + else + { + printKeys + ( + fatalError << "Ctor Selector "<< bType << " dose not exist. \n" + <<"Avaiable ones are: \n\n" + , + boundaryBasevCtorSelector_ + ); + fatalExit; + + } + return nullptr; +} \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/boundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField.hpp index fca7cd3f..eed029c9 100644 --- a/src/phasicFlow/containers/pointField/boundaryField.hpp +++ b/src/phasicFlow/containers/pointField/boundaryField.hpp @@ -22,7 +22,7 @@ Licence: #include "observer.hpp" #include "boundaryBase.hpp" -#include "Field.hpp" +#include "internalField.hpp" namespace pFlow { @@ -33,19 +33,51 @@ class boundaryField public observer { public: - using FieldType = Field; + + using BoundaryFieldType = boundaryField; + + using InternalFieldType = internalField; + + using memory_space = typename InternalFieldType::memory_space; + + using execution_space = typename InternalFieldType::execution_space; + protected: const boundaryBase& boundary_; /// @brief a ref to the internal field - FieldType& internal_; + InternalFieldType& internal_; public: - boundaryField(const boundaryBase& boundary, FieldType& internal); + TypeInfo("boundaryField"); - bool update + boundaryField( + const boundaryBase& boundary, + InternalFieldType& internal); + + create_vCtor + ( + boundaryField, + boundaryBase, + ( + const boundaryBase& boundary, + InternalFieldType& internal + ), + (boundary, internal) + ); + + + add_vCtor + ( + BoundaryFieldType, + BoundaryFieldType, + boundaryBase + ); + + + bool hearChanges ( const message& msg, const anyList& varList @@ -55,6 +87,21 @@ public: return false; } + auto size()const + { + return boundary_.size(); + } + + auto capacity()const + { + return boundary_.capacity(); + } + + static + uniquePtr create( + const boundaryBase& boundary, + InternalFieldType& internal); + }; } diff --git a/src/phasicFlow/containers/pointField/boundaryFieldList.hpp b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp index 29f3c786..c457d8ed 100644 --- a/src/phasicFlow/containers/pointField/boundaryFieldList.hpp +++ b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp @@ -34,9 +34,10 @@ class boundaryFieldList { public: - using boundaryFieldType = boundaryField; + using BoundaryFieldType = boundaryField; - using FieldType = typename boundaryFieldType::FieldType; + using InternalFieldType = typename BoundaryFieldType::InternalFieldType; + protected: @@ -44,9 +45,9 @@ protected: public: - boundaryFieldList(const boundaryList& boundaries, FieldType& internal) + boundaryFieldList(const boundaryList& boundaries, InternalFieldType& internal) : - ListPtr(boundaries.size()), + ListPtr(boundaries.size()), boundaries_(boundaries) { for(auto i=0; iset ( i, - makeUnique - ( - boundaries_[i], - internal - ) + BoundaryFieldType::create(boundaries_[i], internal) ); } } - - }; } diff --git a/src/phasicFlow/containers/pointField/createBoundaryFields.hpp b/src/phasicFlow/containers/pointField/createBoundaryFields.hpp new file mode 100644 index 00000000..5200c257 --- /dev/null +++ b/src/phasicFlow/containers/pointField/createBoundaryFields.hpp @@ -0,0 +1,36 @@ +/*------------------------------- 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 __createBoundaryFields_hpp__ +#define __createBoundaryFields_hpp__ + +#include "boundaryField.hpp" +#include "exitBoundaryField.hpp" + +#define createBaseBoundary(VectorFieldType, DataType, MemorySpaceType) \ + template class pFlow::boundaryField; + + +#define createBoundary(VectorFieldType, DataType, MemorySpaceType, BoundaryType) \ + template class pFlow::BoundaryType##BoundaryField; + + +#endif //__createBoundaryFields_hpp__ + \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/exitBoundaryField.cpp b/src/phasicFlow/containers/pointField/exitBoundaryField.cpp new file mode 100644 index 00000000..046a2bec --- /dev/null +++ b/src/phasicFlow/containers/pointField/exitBoundaryField.cpp @@ -0,0 +1,29 @@ +/*------------------------------- 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. + +-----------------------------------------------------------------------------*/ + +template class VectorField, class T, class MemorySpace> + pFlow::exitBoundaryField::exitBoundaryField +( + const boundaryBase& boundary, + InternalFieldType& internal +) +: + BoundaryFieldType(boundary, internal) +{} \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/exitBoundaryField.hpp b/src/phasicFlow/containers/pointField/exitBoundaryField.hpp new file mode 100644 index 00000000..104314c1 --- /dev/null +++ b/src/phasicFlow/containers/pointField/exitBoundaryField.hpp @@ -0,0 +1,81 @@ +/*------------------------------- 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 __exitBoundaryField_hpp__ +#define __exitBoundaryField_hpp__ + +#include "boundaryField.hpp" + +namespace pFlow +{ + +template< template class VectorField, class T, class MemorySpace = void> +class exitBoundaryField +: + public boundaryField +{ +public: + + using ExitBoundaryFieldType = exitBoundaryField; + + using BoundaryFieldType = boundaryField; + + using InternalFieldType = typename BoundaryFieldType::InternalFieldType; + + using memory_space = typename BoundaryFieldType::memory_space; + + using execution_space = typename BoundaryFieldType::execution_space; + + + +public: + + TypeInfo("boundaryField"); + + exitBoundaryField( + const boundaryBase& boundary, + InternalFieldType& internal); + + + + add_vCtor + ( + BoundaryFieldType, + ExitBoundaryFieldType, + boundaryBase + ); + + + bool hearChanges + ( + const message& msg, + const anyList& varList + ) override + { + notImplementedFunction; + return false; + } + +}; + +} + +#include "exitBoundaryField.cpp" + +#endif diff --git a/src/phasicFlow/containers/pointField/internalField.cpp b/src/phasicFlow/containers/pointField/internalField.cpp new file mode 100644 index 00000000..6759e38e --- /dev/null +++ b/src/phasicFlow/containers/pointField/internalField.cpp @@ -0,0 +1,86 @@ +/*------------------------------- 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. + +-----------------------------------------------------------------------------*/ + +template class VectorField, class T, class MemorySpace> +pFlow::internalField::internalField +( + const word& name, + const internalPoints& internal +) +: + observer + ( + &internal, + message::CAP_CHANGED+message::ITEM_INSERT+message::ITEM_REARRANGE+message::ITEM_DELETE + ), + field_ + ( + name, + "ineternalField", + internal.capacity(), + internal.size(), + RESERVE() + ), + internalPoints_(internal) +{} + + +template class VectorField, class T, class MemorySpace> +pFlow::hostViewType1D + pFlow::internalField::activeValuesHost()const +{ + auto maskH = internalPoints_.activePointsMaskHost(); + auto fieldH = field_.hostVector(); + + hostViewType1D aField("Active field", maskH.numActive()); + auto aRange = maskH.activeRange(); + + uint32 n = 0; + for(auto i=aRange.start(); i class VectorField, class T, class MemorySpace> +bool pFlow::internalField::write +( + iOstream& os, + const IOPattern& iop +)const +{ + if( internalPoints_.isAllActive() ) + { + return field_.write(os, iop); + } + else + { + auto aValues = activeValuesHost(); + auto spanValues = makeSpan(aValues); + return writeSpan(os, spanValues, iop); + } +} + diff --git a/src/phasicFlow/containers/pointField/internalField.hpp b/src/phasicFlow/containers/pointField/internalField.hpp new file mode 100644 index 00000000..d8731fb8 --- /dev/null +++ b/src/phasicFlow/containers/pointField/internalField.hpp @@ -0,0 +1,135 @@ +/*------------------------------- 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 __internalField_hpp__ +#define __internalField_hpp__ + +#include "internalPoints.hpp" +#include "Field.hpp" +#include "observer.hpp" + + +namespace pFlow +{ + +template class VectorField, class T, class MemorySpace=void> +class internalField +: + public observer +{ + +public: + + using FieldType = Field; + + using VectorType = typename FieldType::VectorType; + + using memory_space = typename FieldType::memory_space; + + using execution_space = typename FieldType::execution_space; + +protected: + + FieldType field_; + + const internalPoints& internalPoints_; + +public: + + internalField( + const word& name, + const internalPoints& internal); + + + auto fieldDevice()const + { + return field_.deviceVector(); + } + + auto fieldHost()const + { + return field_.hostVector(); + } + + hostViewType1D activeValuesHost()const; + + inline + auto size()const + { + return field_.size(); + } + + inline + auto capacity()const + { + return field_.capacity(); + } + + inline + word name()const + { + return field_.name(); + } + + inline + word fieldKey()const + { + return field_.fieldKey(); + } + + inline + auto activeRange()const + { + return internalPoints_.activeRange(); + } + + inline + auto isAllActive()const + { + return internalPoints_.isAllActive(); + } + + //// - IO + + bool write(iOstream& os, const IOPattern& iop)const; + +}; + +/*template class VectorField, class T, class MemorySpace> +inline +iOstream& operator<< +( + iOstream& os, + const internalField& if +) +{ + if( !if.write(os, IOPattern::AllProcessorsDifferent) ) + { + ioErrorInFile(os.name(), os.lineNumber()); + fatalExit; + } + + return os; +}*/ + +} // pFlow + +#include "internalField.cpp" + +#endif // __internalField_hpp__ \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/pointField copy.hpp b/src/phasicFlow/containers/pointField/pointField copy.hpp new file mode 100644 index 00000000..791b5b32 --- /dev/null +++ b/src/phasicFlow/containers/pointField/pointField copy.hpp @@ -0,0 +1,204 @@ +/*------------------------------- 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 __internalField_hpp__ +#define __internalField_hpp__ + +#include "pointStructure.hpp" +#include "Field.hpp" +#include "observer.hpp" + + +namespace pFlow +{ + +template class VectorField, class T, class MemorySpace=void> +class internalField +: + public observer, + public Field +{ +public: + + using pointFieldType = pointField; + + using FieldType = Field; + + using boundaryFieldListType = boundaryFieldList; + + using VectorType = typename FieldType::VectorType; + + using iterator = typename FieldType::iterator; + + using const_iterator = typename FieldType::const_iterator; + + using reference = typename FieldType::reference; + + using const_reference = typename FieldType::const_reference; + + using value_type = typename FieldType::value_type; + + using pointer = typename FieldType::pointer; + + using const_pointer = typename FieldType::const_pointer; + +protected: + + //// - data members + + /// @brief list of boundaries + boundaryFieldListType boundaryFieldList_; + + /// @brief refrence to point structure + const pointStructure& pStruct_; + + /// @brief value when a new item is added to field + T defaultValue_; + + +public: + + // - type info + TypeInfoTemplateNV2("pointField", T, VectorType::memoerySpaceName()); + + + //// - Constructors + + // - construct a field from pointStructure and set defaultValue_ and field value to defVal + pointField( + const objectFile& objf, + pointStructure& pStruct, + const T& defVal); + + // - construct from iIOEntity, pointStructure and a value + /*pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true); + + // - construct from another pointField + // subscribe to events if true + pointField( const pointField& src, bool subscribe); + + + // - copy construct + pointField(const pointField& src); + + // - no move construct + pointField(pointField&& src) = delete; + + + // assignment, only assign the VectorField and preserve other parts of this + pointField& operator = (const pointField& rhs); + + // no move assignment + pointField& operator = (pointField&&) = delete; + + + inline uniquePtr clone() const + { + return makeUnique(*this); + } + + inline pointFieldType* clonePtr()const + { + return new pointFieldType(*this); + } + + //// - Methods + + // - reference to pointStructure + inline const pointStructure& pStruct()const { + return pStruct_; + } + + // if all points are active + INLINE_FUNCTION_H + bool allActive()const { + return pStruct_.allActive(); + } + + + INLINE_FUNCTION_H + bool isActive(label i)const { + return pStruct_.isActive(i); + } + + const auto& pointFlag()const + { + return pStruct_.pointFlag(); + } + + range activeRange()const + { + return pStruct_.activeRange(); + } + + // - update the field if any changes occure in pStruct + // for now it checks for deleted points + bool update(const eventMessage& msg); + + + //// - IO operations + bool readPointField(iIstream& is); + + bool writePointField(iOstream& os)const; + + + bool read(iIstream& is) + { + return readPointField(is); + } + + bool write(iOstream& os)const + { + return writePointField(os); + }*/ +}; + +/*template class VectorField, class T, class MemorySpace> +iIstream& operator >> (iIstream & is, pointField & pF ) +{ + if( !pF.read(is)) + { + ioErrorInFile( is.name(), is.lineNumber() ) << + "error in reading pointField from file. \n"; + fatalExit; + } + + return is; +} + +template class VectorField, class T, class MemorySpace> +iOstream& operator << (iOstream& os, const pointField& pF ) +{ + if(! pF.write(os) ) + { + ioErrorInFile( os.name(), os.lineNumber() )<< + "error in writing pointField into file. \n"; + fatalExit; + } + + return os; +}*/ + +} + +#include "pointField.cpp" +//#include "pointFieldAlgorithms.hpp" + +#endif // __pointField_hpp__ diff --git a/src/phasicFlow/containers/pointField/pointField.cpp b/src/phasicFlow/containers/pointField/pointField.cpp index a8a0c6ff..6696d856 100644 --- a/src/phasicFlow/containers/pointField/pointField.cpp +++ b/src/phasicFlow/containers/pointField/pointField.cpp @@ -21,34 +21,30 @@ Licence: template class VectorField, class T, class MemorySpace> pFlow::pointField::pointField ( - const pointStructure& pStruct, - const T& defVal, - message msg + const objectFile& objf, + pointStructure& pStruct, + const T& defVal ) : + IOobject + ( + objf, + pStruct.ioPattern(), + pStruct.owner() + ), + InternalFieldType + ( + objf.name(), + pStruct + ), boundaryFieldList_(pStruct.boundaries(), *this), pStruct_(pStruct), defaultValue_(defVal) -{} - -/*template class VectorField, class T, class MemorySpace> -bool pFlow::pointField::readPointField -( - iIstream& is -) { - return FieldType::readField(is, pStruct_.size(), false); } -template class VectorField, class T, class MemorySpace> -bool pFlow::pointField::writePointField -( - iOstream& os -)const -{ - return FieldType::write(os); -} +/* @@ -144,3 +140,58 @@ bool pFlow::pointField::update(const eventMessage& return true; }*/ + +template class VectorField, class T, class MemorySpace> +bool pFlow::pointField::readPointField +( + iIstream& is, + const IOPattern& iop +) +{ + Field> + fRead("file_read"+InternalFieldType::name(), InternalFieldType::fieldKey()); + + if( !fRead.read(is, iop)) + { + fatalErrorInFunction<< + "Error in reading pointPosition from stream "<< is.name()<> internal + ( + "internalField"+InternalFieldType::name(), + InternalFieldType::fieldKey(), + thisN, + thisN, + RESERVE() + ); + + auto pSpan = fRead.getSpan(); + auto iSpan = internal.getSpan(); + + if(!pStruct_.simDomain().initialTransferBlockData(pSpan, iSpan)) + { + fatalErrorInFunction<< + "Error in transfering the block data for field "<< + InternalFieldType::name()<field_.assign(internal); + + return true; +} + +template class VectorField, class T, class MemorySpace> +bool pFlow::pointField::writePointField +( + iOstream& os, + const IOPattern& iop +)const +{ + notImplementedFunction; + return false; +} \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/pointField.hpp b/src/phasicFlow/containers/pointField/pointField.hpp index 9dcace79..083f8242 100644 --- a/src/phasicFlow/containers/pointField/pointField.hpp +++ b/src/phasicFlow/containers/pointField/pointField.hpp @@ -21,10 +21,10 @@ Licence: #ifndef __pointField_hpp__ #define __pointField_hpp__ -#include "boundaryFieldList.hpp" + #include "pointStructure.hpp" -#include "Field.hpp" -#include "observer.hpp" +#include "internalField.hpp" +#include "boundaryFieldList.hpp" namespace pFlow { @@ -32,32 +32,24 @@ namespace pFlow template class VectorField, class T, class MemorySpace=void> class pointField : - public observer, - public Field + public IOobject, + public internalField { public: - using pointFieldType = pointField; - - using FieldType = Field; + using PointFieldType = pointField; + + using InternalFieldType = internalField; + + using FieldType = typename InternalFieldType::FieldType; using boundaryFieldListType = boundaryFieldList; - - using VectorType = typename FieldType::VectorType; - using iterator = typename FieldType::iterator; + using VectorType = typename InternalFieldType::VectorType; - using const_iterator = typename FieldType::const_iterator; + using memory_space = typename InternalFieldType::memory_space; - using reference = typename FieldType::reference; - - using const_reference = typename FieldType::const_reference; - - using value_type = typename FieldType::value_type; - - using pointer = typename FieldType::pointer; - - using const_pointer = typename FieldType::const_pointer; + using execution_space = typename InternalFieldType::execution_space; protected: @@ -74,18 +66,19 @@ protected: public: - + + // - type info - TypeInfoTemplateNV2("pointField", T, VectorType::memoerySpaceName()); + TypeInfoTemplate111("pointField", T, VectorType::memoerySpaceName()); //// - Constructors // - construct a field from pointStructure and set defaultValue_ and field value to defVal - pointField( - const pointStructure& pStruct, - const T& defVal, - message msg); + pointField( + const objectFile& objf, + pointStructure& pStruct, + const T& defVal); // - construct from iIOEntity, pointStructure and a value /*pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true); @@ -150,24 +143,24 @@ public: // - update the field if any changes occure in pStruct // for now it checks for deleted points - bool update(const eventMessage& msg); + bool update(const eventMessage& msg);*/ //// - IO operations - bool readPointField(iIstream& is); + bool readPointField(iIstream& is, const IOPattern& iop); - bool writePointField(iOstream& os)const; + bool writePointField(iOstream& os, const IOPattern& iop)const; - bool read(iIstream& is) + bool read(iIstream& is, const IOPattern& iop)override { - return readPointField(is); + return readPointField(is, iop); } - bool write(iOstream& os)const + bool write(iOstream& os, const IOPattern& iop)const override { - return writePointField(os); - }*/ + return writePointField(os, iop); + } }; /*template class VectorField, class T, class MemorySpace> diff --git a/src/phasicFlow/containers/pointField/pointFields.cpp b/src/phasicFlow/containers/pointField/pointFields.cpp index e503dd41..6ef70444 100644 --- a/src/phasicFlow/containers/pointField/pointFields.cpp +++ b/src/phasicFlow/containers/pointField/pointFields.cpp @@ -20,9 +20,17 @@ Licence: #include "pointFields.hpp" +#include "createBoundaryFields.hpp" template class pFlow::pointField; +createBaseBoundary(pFlow::VectorSingle, pFlow::int8, pFlow::HostSpace); +createBoundary(pFlow::VectorSingle, pFlow::int8, pFlow::HostSpace, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::VectorSingle, pFlow::real, pFlow::HostSpace); +createBoundary(pFlow::VectorSingle, pFlow::real, pFlow::HostSpace, exit); + /*template class pFlow::pointField; diff --git a/src/phasicFlow/containers/span/span.hpp b/src/phasicFlow/containers/span/span.hpp index fc625d86..c9ee5093 100644 --- a/src/phasicFlow/containers/span/span.hpp +++ b/src/phasicFlow/containers/span/span.hpp @@ -55,7 +55,7 @@ protected: public: - TypeInfoTemplateNV("span", T); + TypeInfoTemplateNV11("span", T); /// Constructor INLINE_FUNCTION_HD @@ -229,7 +229,6 @@ span charSpan(span s) - } // pFlow #endif //__span_hpp__ diff --git a/src/phasicFlow/demComponent/demComponent.hpp b/src/phasicFlow/demComponent/demComponent.hpp index fb229ae9..35d6dc67 100644 --- a/src/phasicFlow/demComponent/demComponent.hpp +++ b/src/phasicFlow/demComponent/demComponent.hpp @@ -134,7 +134,7 @@ public: virtual bool beforeTimeLoop() { - notImplementedFunction; + notImplementedFunction return false; } @@ -155,7 +155,7 @@ public: virtual bool afterTimeLoop() { - notImplementedFunction; + notImplementedFunction return false; } diff --git a/src/phasicFlow/eventManagement/message.hpp b/src/phasicFlow/eventManagement/message.hpp index bf2d2f9a..05a9de37 100644 --- a/src/phasicFlow/eventManagement/message.hpp +++ b/src/phasicFlow/eventManagement/message.hpp @@ -45,7 +45,9 @@ public: protected: - std::bitset<16> events_{0x0000}; + static constexpr size_t numberOfEvents_ = 8; + + std::bitset events_{0x0000}; public: @@ -59,7 +61,7 @@ public: message(size_t i ) { - if(i<16) + if(i16 ) - { - fatalErrorInFunction<< - "message size is greater than 16!"<16 ) - { - fatalErrorInFunction<< - "message size is greater than 16!"<update(message(i), varList); + obsvr->hearChanges(message(i), varList); } } } diff --git a/src/phasicFlow/eventManagement/subscriber.hpp b/src/phasicFlow/eventManagement/subscriber.hpp index 48090597..23570485 100644 --- a/src/phasicFlow/eventManagement/subscriber.hpp +++ b/src/phasicFlow/eventManagement/subscriber.hpp @@ -25,12 +25,12 @@ Licence: #include #include "List.hpp" +#include "message.hpp" namespace pFlow { class observer; -class message; class anyList; class subscriber @@ -38,7 +38,7 @@ class subscriber protected: // - list of subsribed objectd that recieve updage messages - mutable std::array,16> observerList_; + mutable std::array,message::numEvents()> observerList_; word subName_; diff --git a/src/phasicFlow/ranges/intervalRange.hpp b/src/phasicFlow/ranges/intervalRange.hpp index ca40826f..0108713d 100644 --- a/src/phasicFlow/ranges/intervalRange.hpp +++ b/src/phasicFlow/ranges/intervalRange.hpp @@ -43,7 +43,7 @@ protected: static inline const T minVal = largestNegative(); public: - TypeInfoTemplateNV("intervalRange",T); + TypeInfoTemplateNV11("intervalRange",T); intervalRange(T begin, T end) : diff --git a/src/phasicFlow/ranges/stridedRange.hpp b/src/phasicFlow/ranges/stridedRange.hpp index ca1cf7ba..0f7eb10f 100644 --- a/src/phasicFlow/ranges/stridedRange.hpp +++ b/src/phasicFlow/ranges/stridedRange.hpp @@ -35,18 +35,20 @@ stridedRange { protected: - T begin_; + T begin_ = 0; - T end_; + T end_ = 1; - T stride_; + T stride_ = 1; static inline const T maxVal = largestPositive(); static inline const T minVal = largestNegative(); public: - TypeInfoTemplateNV("stridedRange",T); + TypeInfoTemplateNV11("stridedRange",T); + + stridedRange()=default; stridedRange(T begin, T end, T stride) : @@ -96,12 +98,20 @@ public: { return stride_; } + + inline + bool isInRange(T val)const + { + return val>= begin_ && val<= end_; + } + inline bool isMember(T val, T epsilon = 0)const { + if(!isInRange(val)) return false; + if(abs(mod(val-begin_,stride_))<= epsilon) return true; if(equal(val,begin_))return true; if(equal(val,end_))return true; - if(abs(mod(val-begin_,stride_))<= epsilon) return true; return false; } diff --git a/src/phasicFlow/repository/IOobject/IOobject.hpp b/src/phasicFlow/repository/IOobject/IOobject.hpp index 7e947192..71acbc50 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.hpp +++ b/src/phasicFlow/repository/IOobject/IOobject.hpp @@ -78,6 +78,11 @@ public: return owner_; } + repository* owner() + { + return owner_; + } + repository* releaseOwner(bool fromOwner = false); //// - IO operations diff --git a/src/phasicFlow/repository/Time/baseTimeControl.cpp b/src/phasicFlow/repository/Time/baseTimeControl.cpp new file mode 100644 index 00000000..642af864 --- /dev/null +++ b/src/phasicFlow/repository/Time/baseTimeControl.cpp @@ -0,0 +1,77 @@ +/*------------------------------- 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. + +-----------------------------------------------------------------------------*/ + +#include "baseTimeControl.hpp" + + + +pFlow::baseTimeControl::baseTimeControl +( + const dictionary &dict, + const word& intervalPrefix +) +{ + auto tControl = dict.getVal("timeControl"); + if(tControl == "timeStep") + isTimeStep_ = true; + else if( tControl == "runTime" || + tControl == "simulationTime") + isTimeStep_ = false; + else + { + fatalErrorInFunction<< + "bad input for intervalControl in dictionary "<< dict.globalName()<("startTime", 0.0)); + auto endTime = (dict.getValOrSet("endTime", largeValue)); + auto interval = dict.getVal(intervalWord); + rRange_ = realStridedRange(startTime, endTime, interval); + + } + else + { + auto startTime = (dict.getValOrSet("startTime", 0.0)); + auto endTime = (dict.getValOrSet("endTime", largestPosInt32)); + auto interval = dict.getVal(intervalWord); + iRange_ = int32StridedRagne(startTime, endTime, interval); + } + +} + +bool pFlow::baseTimeControl::timeEvent(uint32 iter, real t, real dt) const +{ + if(isTimeStep_) + { + return iRange_.isMember(iter); + } + else + { + return rRange_.isMember(t, 0.51*dt); + } + return false; +} diff --git a/src/phasicFlow/repository/Time/baseTimeControl.hpp b/src/phasicFlow/repository/Time/baseTimeControl.hpp new file mode 100644 index 00000000..f82fda5f --- /dev/null +++ b/src/phasicFlow/repository/Time/baseTimeControl.hpp @@ -0,0 +1,52 @@ +/*------------------------------- 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 __baseTimeControl_hpp__ +#define __baseTimeControl_hpp__ + +#include "dictionary.hpp" +#include "ranges.hpp" + + +namespace pFlow +{ + +class baseTimeControl +{ +private: + + bool isTimeStep_; + + int32StridedRagne iRange_; + + realStridedRange rRange_; + + +public: + + baseTimeControl(const dictionary& dict, const word& intervalPrefix = ""); + + + bool timeEvent(uint32 iter, real t, real dt)const; + +}; + +} + +#endif \ No newline at end of file diff --git a/src/phasicFlow/repository/systemControl/systemControl.cpp b/src/phasicFlow/repository/systemControl/systemControl.cpp index f57fd453..77a7b684 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.cpp +++ b/src/phasicFlow/repository/systemControl/systemControl.cpp @@ -25,7 +25,7 @@ Licence: #include "systemControl.hpp" #include "vocabs.hpp" -bool pFlow::systemControl::readDomainDict() +/*bool pFlow::systemControl::readDomainDict() { if(!domainDict_) { @@ -42,7 +42,7 @@ bool pFlow::systemControl::readDomainDict() ); } return true; -} +}*/ pFlow::word pFlow::systemControl::getRunName ( @@ -176,7 +176,7 @@ pFlow::systemControl::systemControl ), writeToFileTimer_("Write to file", &timers_) { - readDomainDict(); + //readDomainDict(); } pFlow::systemControl::systemControl( @@ -250,13 +250,13 @@ pFlow::systemControl::systemControl( ), writeToFileTimer_("Write to file", &timers_) { - readDomainDict(); + //readDomainDict(); } -pFlow::fileDictionary& pFlow::systemControl::domainDict() +/*pFlow::fileDictionary& pFlow::systemControl::domainDict() { return domainDict_(); -} +}*/ bool pFlow::systemControl::operator ++(int) { diff --git a/src/phasicFlow/repository/systemControl/systemControl.hpp b/src/phasicFlow/repository/systemControl/systemControl.hpp index f48c9db7..3cf1317c 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.hpp +++ b/src/phasicFlow/repository/systemControl/systemControl.hpp @@ -62,8 +62,6 @@ protected: /// caseSetup folder repository uniquePtr caseSetup_; - uniquePtr domainDict_ = nullptr; - /// extra libs to be loaded dynamicLinkLibs libs_; @@ -81,7 +79,7 @@ protected: Timer writeToFileTimer_; - bool readDomainDict(); + //bool readDomainDict(); static word getRunName( const fileSystem& path); @@ -159,7 +157,7 @@ public: return settingsDict_(); } - fileDictionary& domainDict(); + //fileDictionary& domainDict(); virtual word runName() const @@ -172,10 +170,10 @@ public: return settingsDict_().getVal("g"); } - inline box domain() + /*inline box domain() { return box(domainDict().subDict("globalBox")); - } + }*/ bool operator ++(int); diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp index 5f0923a2..10decdd5 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp @@ -60,8 +60,18 @@ pFlow::boundaryBase::boundaryBase } -typename pFlow::boundaryBase::pointFieldAccessType - pFlow::boundaryBase::thisPoints() +void pFlow::boundaryBase::setSize(uint32 newSize) +{ + indexList_.resize(newSize); + + if( indexList_.capacity() <= newSize+1 ) + { + indexList_.reserve(newSize+1); + } +} + +typename pFlow::boundaryBase::pointFieldAccessType +pFlow::boundaryBase::thisPoints() { return pointFieldAccessType diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp index ed242180..db537d1d 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp @@ -46,10 +46,6 @@ public: using pointFieldAccessType = scatterFieldAccess; - enum DIRECTION: int8 - { - - }; protected: @@ -110,6 +106,37 @@ public: (dict, bplane, internal) ); + inline + auto neighborLength()const + { + return neighborLength_; + } + + + const word& type()const + { + return type_; + } + + const word& name()const + { + return name_; + } + + auto size()const + { + return indexList_.size(); + } + + auto capacity()const + { + return indexList_.capacity(); + } + + /// @brief set the size of indexList + /// Always make sure that size+1 <= capacity + void setSize(uint32 newSize); + virtual bool beforeIteratoin(uint32 iterNum, real t) = 0 ; @@ -119,6 +146,12 @@ public: virtual bool afterIteration(uint32 iterNum, real t) = 0; + + const auto& indexList()const + { + return indexList_; + } + pointFieldAccessType thisPoints(); virtual diff --git a/src/phasicFlow/structuredData/domain/regularSimulationDomain.cpp b/src/phasicFlow/structuredData/domain/regularSimulationDomain.cpp index 999f6b0e..5cc3c6fb 100644 --- a/src/phasicFlow/structuredData/domain/regularSimulationDomain.cpp +++ b/src/phasicFlow/structuredData/domain/regularSimulationDomain.cpp @@ -6,10 +6,10 @@ bool pFlow::regularSimulationDomain::createBoundaryDicts() { - auto& boundaries = globalDomainDict_.subDict("boundaries"); + auto& boundaries = this->subDict("boundaries"); - globalDomainDict_.addDict("regularSimulationDomainBoundaries", boundaries); - auto& rbBoundaries = globalDomainDict_.subDict("regularSimulationDomainBoundaries"); + this->addDict("regularSimulationDomainBoundaries", boundaries); + auto& rbBoundaries = this->subDict("regularSimulationDomainBoundaries"); real neighborLength = boundaries.getVal("neighborLength"); @@ -52,10 +52,10 @@ bool pFlow::regularSimulationDomain::setThisDomain() pFlow::regularSimulationDomain::regularSimulationDomain ( - const dictionary &dict + systemControl& control ) : - simulationDomain(dict) + simulationDomain(control) {} bool pFlow::regularSimulationDomain::initialUpdateDomains(span pointPos) @@ -93,7 +93,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData span src, span dst, size_t sizeOfElement -) +) const { size_t requiredSize = sizeOfElement*initialNumberInThis(); if(dst.size() < requiredSize) @@ -122,7 +122,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData ( span src, span dst -) +) const { return initialTransferBlockData( charSpan(src), @@ -134,7 +134,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData ( span src, span dst -) +) const { return initialTransferBlockData( charSpan(src), @@ -146,7 +146,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData ( span src, span dst -) +) const { return initialTransferBlockData( charSpan(src), @@ -158,7 +158,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData ( span src, span dst -) +) const { return initialTransferBlockData( charSpan(src), @@ -168,7 +168,7 @@ bool pFlow::regularSimulationDomain::initialTransferBlockData const pFlow::dictionary &pFlow::regularSimulationDomain::thisBoundaryDict() const { - return globalDomainDict_.subDict("regularSimulationDomainBoundaries"); + return this->subDict("regularSimulationDomainBoundaries"); } bool pFlow::regularSimulationDomain::requiresDataTransfer()const diff --git a/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp b/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp index 074ffc64..86fdf02e 100644 --- a/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp +++ b/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp @@ -23,7 +23,7 @@ public: TypeInfo("simulationDomain"); - regularSimulationDomain(const dictionary& dict); + regularSimulationDomain(systemControl& control); virtual ~regularSimulationDomain()=default; @@ -32,7 +32,7 @@ public: ( simulationDomain, regularSimulationDomain, - dictionary + systemControl ); bool initialUpdateDomains(span pointPos) override; @@ -50,7 +50,7 @@ public: bool initialTransferBlockData( span src, span dst, - size_t sizeOfElement) override; + size_t sizeOfElement) const override; /// @brief @@ -59,19 +59,19 @@ public: /// @return bool initialTransferBlockData( span src, - span dst) override; + span dst) const override; bool initialTransferBlockData( span src, - span dst) override; + span dst) const override; bool initialTransferBlockData( span src, - span dst) override; + span dst) const override; bool initialTransferBlockData( span src, - span dst) override; + span dst) const override; const dictionary& thisBoundaryDict()const override; diff --git a/src/phasicFlow/structuredData/domain/simulationDomain.cpp b/src/phasicFlow/structuredData/domain/simulationDomain.cpp index b45758b5..232706c8 100644 --- a/src/phasicFlow/structuredData/domain/simulationDomain.cpp +++ b/src/phasicFlow/structuredData/domain/simulationDomain.cpp @@ -20,26 +20,38 @@ Licence: #include "simulationDomain.hpp" #include "pFlowProcessors.hpp" +#include "systemControl.hpp" +#include "vocabs.hpp" -pFlow::simulationDomain::simulationDomain(const dictionary& dict) +pFlow::simulationDomain::simulationDomain(systemControl& control) : - globalBox_(dict.subDict("globalBox")), - globalDomainDict_(dict) + fileDictionary + ( + objectFile + ( + domainFile__, + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_NEVER + ), + &control.settings() + ), + globalBox_(subDict("globalBox")) { } pFlow::uniquePtr - pFlow::simulationDomain::create(const dictionary &dict) + pFlow::simulationDomain::create(systemControl& control) { word sType = angleBracketsNames( "simulationDomain", pFlowProcessors().localRunTypeName()); - if( dictionaryvCtorSelector_.search(sType) ) + if( systemControlvCtorSelector_.search(sType) ) { - return dictionaryvCtorSelector_[sType] (dict); + return systemControlvCtorSelector_[sType] (control); } else { @@ -48,7 +60,7 @@ pFlow::uniquePtr fatalError << "Ctor Selector "<< sType << " dose not exist. \n" <<"Avaiable ones are: \n\n" , - dictionaryvCtorSelector_ + systemControlvCtorSelector_ ); fatalExit; } diff --git a/src/phasicFlow/structuredData/domain/simulationDomain.hpp b/src/phasicFlow/structuredData/domain/simulationDomain.hpp index 205762ba..10307887 100644 --- a/src/phasicFlow/structuredData/domain/simulationDomain.hpp +++ b/src/phasicFlow/structuredData/domain/simulationDomain.hpp @@ -23,6 +23,7 @@ Licence: #include #include "domain.hpp" +#include "fileDictionary.hpp" #include "span.hpp" #include "streams.hpp" #include "virtualConstructor.hpp" @@ -31,9 +32,12 @@ Licence: namespace pFlow { +class systemControl; //class pFlagTypeHost; class simulationDomain +: + public fileDictionary { private: @@ -43,20 +47,20 @@ static inline const std::array boundaryNames_ = { "left", "right", - "top", "bottom", + "bottom", "top", "rear", "front" }; protected: + //fileDictionary globalDomainDict_ ; + /// @brief acutal limits of the simulation domain box globalBox_; /// @brief the actual limits of this processor domain domain thisDomain_; - dictionary globalDomainDict_ ; - bool boundariesSet_ = false; virtual bool createBoundaryDicts() = 0; @@ -69,7 +73,7 @@ public: TypeInfo("simulationDomain"); /// Constrcut from components - simulationDomain(const dictionary& dict); + simulationDomain(systemControl& control); /// Destructor virtual @@ -79,9 +83,9 @@ public: create_vCtor ( simulationDomain, - dictionary, - (const dictionary& dict), - (dict) + systemControl, + (systemControl& control), + (control) ); virtual @@ -97,33 +101,33 @@ public: bool initialTransferBlockData( span src, span dst, - size_t sizeOfElement) = 0; + size_t sizeOfElement) const = 0; virtual bool initialTransferBlockData( span src, - span dst) = 0; + span dst) const = 0; virtual bool initialTransferBlockData( span src, - span dst) = 0; + span dst) const = 0; virtual bool initialTransferBlockData( span src, - span dst) = 0; + span dst) const = 0; virtual bool initialTransferBlockData( span src, - span dst) = 0; + span dst) const = 0; - /*template + template bool initialTransferBlockData( span src, - span dst ) + span dst )const { size_t el=sizeof(T); return initialTransferBlockData @@ -132,7 +136,7 @@ public: charSpan(dst), el ); - }*/ + } @@ -149,6 +153,18 @@ public: virtual bool requiresDataTransfer() const = 0; + inline + const auto& thisDomain()const + { + return thisDomain_; + } + + inline + const auto& globalBoundaryDict()const + { + return static_cast(*this); + } + inline const dictionary& boundaryDict(uint32 i)const { @@ -174,7 +190,7 @@ public: } static - uniquePtr create(const dictionary& dict); + uniquePtr create(systemControl& control); }; // simulationDomain diff --git a/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp b/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp index 4914ddbc..e4f14e22 100644 --- a/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp +++ b/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp @@ -19,21 +19,78 @@ Licence: -----------------------------------------------------------------------------*/ #include "boundaryList.hpp" +#include "internalPoints.hpp" #include "simulationDomain.hpp" -pFlow::boundaryList::boundaryList -( - const simulationDomain& simD, - internalPoints& internal -) -: - ListPtr(simD.sizeOfBoundaries()), - simDomain_(simD), - internal_(internal) -{} +bool pFlow::boundaryList::resetLists() +{ + clear(); + listSet_ = false; + return true; +} bool pFlow::boundaryList::updateLists() { + + std::array dist; + dist[0] = boundary(0).neighborLength(); + dist[1] = boundary(1).neighborLength(); + dist[2] = boundary(2).neighborLength(); + dist[3] = boundary(3).neighborLength(); + dist[4] = boundary(4).neighborLength(); + dist[5] = boundary(5).neighborLength(); + + + internal_.updateFlag( + simDomain_.thisDomain(), + dist); + const auto& maskD = internal_.activePointsMaskDevice(); + boundary(0).setSize( maskD.leftSize() ); + boundary(1).setSize( maskD.rightSize() ); + boundary(2).setSize( maskD.bottomSize() ); + boundary(3).setSize( maskD.topSize() ); + boundary(4).setSize( maskD.rearSize() ); + boundary(5).setSize( maskD.frontSize() ); + + internal_.fillNeighborsLists( + boundary(0).indexList().deviceVectorAll(), + boundary(1).indexList().deviceVectorAll(), + boundary(2).indexList().deviceVectorAll(), + boundary(3).indexList().deviceVectorAll(), + boundary(4).indexList().deviceVectorAll(), + boundary(5).indexList().deviceVectorAll()); + + return true; +} + +pFlow::boundaryList::boundaryList +( + const simulationDomain &simD, + internalPoints &internal +) +: + ListPtr(simD.sizeOfBoundaries()), + internal_(internal), + simDomain_(simD), + timeControl_ + ( + simDomain_.subDict("boundaries"), + "update" + ) +{} + +bool pFlow::boundaryList::updateLists(uint32 iter, real t, real dt) +{ + if( timeControl_.timeEvent(iter, t, dt)) + { + return updateLists(); + } + return true; +} + +bool pFlow::boundaryList::setLists() +{ + if(listSet_)return true; for(auto i=0; i::operator[](i); - } + - const auto& boundary(size_t i)const - { - return ListPtr::operator[](i); - } + bool setLists(); + + auto& boundary(size_t i) + { + return ListPtr::operator[](i); + } + + const auto& boundary(size_t i)const + { + return ListPtr::operator[](i); + } }; } // pFlow diff --git a/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp b/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp index d64e35af..d0d9de79 100644 --- a/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp +++ b/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp @@ -20,7 +20,8 @@ Licence: #include "internalPoints.hpp" -#include "Vector.hpp" +#include "domain.hpp" +#include "Vectors.hpp" void pFlow::internalPoints::syncPFlag()const { @@ -31,6 +32,170 @@ void pFlow::internalPoints::syncPFlag()const } } +pFlow::internalPoints::internalPoints() +: + subscriber("internalPoints"), + pointPosition_("internalPoints", "internalPoints", initialCapacity_, 0, RESERVE()), + pFlagsD_(initialCapacity_, 0 , 0) +{} + + +pFlow::internalPoints::internalPoints +( + const realx3Vector& posVec +) +: + subscriber("internalPoints"), + pointPosition_("internalPoints", "internalPoints", posVec.capacity(), 0, RESERVE()), + pFlagsD_(posVec.capacity(), 0, posVec.size()) +{ + + pointPosition_.assign(posVec); + +} + + +const pFlow::pFlagTypeDevice& + pFlow::internalPoints::activePointsMaskDevice() const +{ + return pFlagsD_; +} + + +const pFlow::pFlagTypeHost& + pFlow::internalPoints::activePointsMaskHost() const +{ + syncPFlag(); + return pFlagsH_; +} + +FUNCTION_H +const pFlow::realx3Field_D& + pFlow::internalPoints::pointPosition()const +{ + return pointPosition_; +} + +pFlow::hostViewType1D + pFlow::internalPoints::activePointsHost() const +{ + auto maskH = activePointsMaskHost(); + auto pointsH = pointPositionHost(); + + hostViewType1D aPoints("Active pointst", maskH.numActive()); + auto aRange = maskH.activeRange(); + uint32 n = 0; + for(auto i=aRange.start(); i& dist +) +{ + return pFlagsD_.markPointRegions + ( + dm, + pointPosition_.deviceVectorAll(), + dist[0], + dist[1], + dist[2], + dist[3], + dist[4], + dist[5] + ); + + pFlagSync_ = false; +} + +void pFlow::internalPoints::fillNeighborsLists +( + ViewType1D leftList, + ViewType1D rightList, + ViewType1D bottomList, + ViewType1D topList, + ViewType1D rearList, + ViewType1D frontList +) +{ + pFlagsD_.fillNeighborsLists( + leftList, + rightList, + bottomList, + topList, + rearList, + frontList); + + pFlagSync_ = false; +} + +FUNCTION_H +bool pFlow::internalPoints::read +( + iIstream& is, + const IOPattern& iop +) +{ + + Field> fRead("internalPoints", "internalPoints"); + + if( !fRead.read(is, iop)) + { + fatalErrorInFunction<< + "Error in reading pointPosition from stream "<< is.name()<activePointsHost(); + auto spanPoints = makeSpan(aPoints); //span(aPoints.data(), aPoints.size()); + return writeSpan(os, spanPoints, iop); + } +} + /*FUNCTION_H bool pFlow::internalPoints::evaluateinternalPoints() @@ -144,150 +309,4 @@ pFlow::uniquePtr } return nullptr; -}*/ - -pFlow::internalPoints::internalPoints() -: - subscriber("internalPoints"), - pointPosition_("internalPoints", "internalPoints", initialCapacity_, 0, RESERVE()), - pFlagsD_(initialCapacity_, 0 , 0) -{ - syncPFlag(); -} - - -pFlow::internalPoints::internalPoints -( - const realx3Vector& posVec -) -: - subscriber("internalPoints"), - pointPosition_("internalPoints", "internalPoints", posVec.capacity(), 0, RESERVE()), - pFlagsD_(posVec.capacity(), 0, posVec.size()) -{ - - pointPosition_.assign(posVec); - - syncPFlag(); - -} - - -const pFlow::pFlagTypeDevice& - pFlow::internalPoints::activePointsMaskD() const -{ - return pFlagsD_; -} - - -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::internalPoints::activePointsHost() const -{ - auto maskH = activePointsMaskH(); - auto pointsH = pointPositionHost(); - - hostViewType1D aPoints("Active pointst", maskH.numActive()); - auto aRange = maskH.activeRange(); - uint32 n = 0; - for(auto i=aRange.start(); i& dist -) -{ - pFlagsD_.markPointRegions - ( - dm, - pointPosition_.deviceVectorAll(), - dist[0], - dist[1], - dist[2], - dist[3], - dist[4], - dist[5] - ); -} - - -FUNCTION_H -bool pFlow::internalPoints::read -( - iIstream& is, - const IOPattern& iop -) -{ - - Field> fRead("internalPoints", "internalPoints"); - - if( !fRead.read(is, iop)) - { - fatalErrorInFunction<< - "Error in reading pointPosition from stream "<< is.name()<& dist); - - /*FUNCTION_H - size_t markDeleteOutOfBox(const box& domain);*/ - - /////////////////////////////////////////////////////////////////////////////////////////////////// - - // - const access to points to be newly inserted - /*FUNCTION_H - auto insertedPointIndex()const - { - return tobeInsertedIndex_; - } - - FUNCTION_H - auto insertedPointIndexH()const - { - return tobeInsertedIndex_.hostView(); - } - - FUNCTION_H - auto insertedPointIndexD()const - { - return tobeInsertedIndex_.deviceView(); - } - - FUNCTION_H - auto mortonSortedIndex()const - { - return mortonSortedIndex_; - } - - - // - update data structure by inserting/setting new points - // Notifies all the fields in the registered list of data structure - // and exclude the fields that re in the exclusionList - // retrun nullptr if it fails - /*FUNCTION_H - virtual uniquePtr insertPoints( - const realx3Vector& pos, - const setFieldList& setField, - repository& owner, - const List& exclusionList={nullptr} - );*/ + void fillNeighborsLists( + ViewType1D leftList, + ViewType1D rightList, + ViewType1D bottomList, + ViewType1D topList, + ViewType1D rearList, + ViewType1D frontList); + + //// - IO operations @@ -243,8 +211,6 @@ iOstream& operator<<(iOstream& os, const internalPoints& ip) } // pFlow - - #endif //__internalPoints_hpp__ @@ -331,4 +297,50 @@ iOstream& operator<<(iOstream& os, const internalPoints& ip) bool allActive()const { return allActive_; } - };*/ \ No newline at end of file + };*/ + + + /*FUNCTION_H` + size_t markDeleteOutOfBox(const box& domain);*/ + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + + // - const access to points to be newly inserted + /*FUNCTION_H + auto insertedPointIndex()const + { + return tobeInsertedIndex_; + } + + FUNCTION_H + auto insertedPointIndexH()const + { + return tobeInsertedIndex_.hostView(); + } + + FUNCTION_H + auto insertedPointIndexD()const + { + return tobeInsertedIndex_.deviceView(); + } + + + FUNCTION_H + auto mortonSortedIndex()const + { + return mortonSortedIndex_; + } + + + // - update data structure by inserting/setting new points + // Notifies all the fields in the registered list of data structure + // and exclude the fields that re in the exclusionList + // retrun nullptr if it fails + /*FUNCTION_H + virtual uniquePtr insertPoints( + const realx3Vector& pos, + const setFieldList& setField, + repository& owner, + const List& exclusionList={nullptr} + );*/ diff --git a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp index e863e583..cbf1f539 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp @@ -134,6 +134,43 @@ public: return numActive_; } + INLINE_FUNCTION_HD + auto leftSize()const + { + return nLeft_; + } + + INLINE_FUNCTION_HD + auto rightSize()const + { + return nRight_; + } + + INLINE_FUNCTION_HD + auto bottomSize()const + { + return nBottom_; + } + + INLINE_FUNCTION_HD + auto topSize()const + { + return nTop_; + } + + INLINE_FUNCTION_HD + auto rearSize()const + { + return nRear_; + } + + INLINE_FUNCTION_HD + auto frontSize()const + { + return nFront_; + } + + INLINE_FUNCTION_HD bool operator()(uint32 i) { @@ -213,9 +250,28 @@ public: isAllActive_); } - - uint32 scanPointFlag(); + /// @brief Loop over the active points and mark those out of the box + /// and return number of deleted points + /// @param validBox the box whose inside is valid + /// @param points list of all points + /// @return number of deleted points + uint32 markOutOfBoxDelete( + const box& validBox, + ViewType1D points); + + /// @brief mark points based on their position in the domain. + /// This should be the first method to be called when updating + /// boundaries (step 1 of 2). + /// @param dm the domain for which particles are tested + /// @param points list of points + /// @param leftLength neighbor length of the left face + /// @param rightLength neighbor length of the right face + /// @param bottomLength neighbor length of the bottom face + /// @param topLength neighbor length of the top face + /// @param rearLength neighbor length of the rear face + /// @param frontLength neighbor length of the front face + /// @return number of deleted points uint32 markPointRegions( domain dm, ViewType1D points, @@ -226,6 +282,16 @@ public: real rearLength, real frontLength); + + /// @brief fill the lists for boundary faces. Lists keep the index + /// of particles in the neighborhood of the faces. This mehtod is + /// called after markPointRegions (step 2 of 2). + /// @param leftList neighbor list of the left face + /// @param rightList neighbor list of the right face + /// @param bottomList neighbor list of the bottom face + /// @param topList neighbor list of the top face + /// @param rearList neighbor list of the rear face + /// @param frontList neighbor list of the front face void fillNeighborsLists( ViewType1D leftList, ViewType1D rightList, diff --git a/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp b/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp index f63efa00..c5eaa78c 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp @@ -20,9 +20,78 @@ Licence: #ifndef __pointFlagKernels_hpp__ #define __pointFlagKernels_hpp__ - - template +pFlow::uint32 pFlow::pointFlag::markOutOfBoxDelete +( + const box& validBox, + ViewType1D points +) +{ + using rpScanFlag = Kokkos::RangePolicy>; + + uint32 numDeleted = 0; + + uint32 start = activeRange().start(); + uint32 end = activeRange().end(); + + uint32 minRange = end; + uint32 maxRange = start; + + if(start(minRange), + Kokkos::Max(maxRange), + numDeleted); + } + + if(numDeleted >= numActive_) + { + minRange = 0; + maxRange = 0; + numDeleted == numActive_; + } + else + { + // add one to maxRange to make it half-open + maxRange ++; + } + + activeRange_ = {minRange, maxRange}; + numActive_ = numActive_ - numDeleted; + isAllActive_ = + (activeRange_.numElements() == numActive_)&& numActive_>0; + + return numDeleted; +} + +/*template pFlow::uint32 pFlow::pointFlag::scanPointFlag() { @@ -77,7 +146,7 @@ pFlow::uint32 pFlow::pointFlag::scanPointFlag() isAllActive_ = activeRange_.numElements() == numActive_; return numActive; -} +}*/ template @@ -102,7 +171,7 @@ pFlow::uint32 pFlow::pointFlag::markPointRegions uint32 minRange = end; uint32 maxRange = start; - uint32 numMarked = 0; + uint32 numMarkedDelete = 0; uint32 nLeft = 0, nRight = 0; uint32 nBottom = 0, nTop = 0; uint32 nRear = 0, nFront = 0; @@ -181,7 +250,7 @@ pFlow::uint32 pFlow::pointFlag::markPointRegions }, Kokkos::Min(minRange), Kokkos::Max(maxRange), - numMarked, + numMarkedDelete, nLeft, nRight, nBottom, @@ -192,10 +261,11 @@ pFlow::uint32 pFlow::pointFlag::markPointRegions } // means either range was empty or all points have been deleted. - if(minRangeend) + if(numMarkedDelete>= numActive_) { minRange = 0; maxRange = 0; + numMarkedDelete = numActive_; } else { @@ -203,8 +273,8 @@ pFlow::uint32 pFlow::pointFlag::markPointRegions } activeRange_ = {minRange, maxRange}; - isAllActive_ = isAllActive_ && numMarked == 0; - numActive_ -= numMarked; + numActive_ -= numMarkedDelete; + isAllActive_ = (activeRange_.numElements() == numActive_)&& numActive_>0; nLeft_ = nLeft; nRight_ = nRight; @@ -213,7 +283,7 @@ pFlow::uint32 pFlow::pointFlag::markPointRegions nRear_ = nRear; nFront_ = nFront; - return numMarked; + return numMarkedDelete; } template @@ -235,7 +305,7 @@ void pFlow::pointFlag::fillNeighborsLists ViewType1D nElems("nElems",6); - fill(nElems, 0, 6, 0); + fill(nElems, 0, 6, static_cast(0)); if(start";\ @@ -86,7 +86,7 @@ Licence: virtual word typeName() const { return TYPENAME();} // this is the non-virtual version -#define TypeInfoTemplateNV(tName, Type) \ +#define TypeInfoTemplateNV11(tName, Type) \ has_static_member(TYPENAME); \ inline static word TYPENAME() \ { \ @@ -99,7 +99,7 @@ Licence: inline word typeName() const { return TYPENAME();} -#define TypeInfoTemplateNV2(tName, Type, tName2) \ +#define TypeInfoTemplateNV111(tName, Type, tName2) \ has_static_member(TYPENAME); \ inline static word TYPENAME() \ { \ @@ -111,6 +111,20 @@ Licence: } \ inline word typeName() const { return TYPENAME();} +#define TypeInfoTemplate111(tName, Type, tName2) \ + has_static_member(TYPENAME); \ + inline static word TYPENAME() \ + { \ + if constexpr ( has_static_member_TYPENAME::value) \ + { return word(tName)+"<"+Type::TYPENAME()+","+word(tName2)+">";} \ + else \ + return word(tName)+"<"+basicTypeName()+","+word(tName2)+">"; \ + return "noTYPE"; \ + } \ + virtual word typeName() const { return TYPENAME();} + + + diff --git a/src/phasicFlow/typeSelection/virtualConstructor.hpp b/src/phasicFlow/typeSelection/virtualConstructor.hpp index 573f7d31..0d7f64ff 100644 --- a/src/phasicFlow/typeSelection/virtualConstructor.hpp +++ b/src/phasicFlow/typeSelection/virtualConstructor.hpp @@ -75,7 +75,7 @@ public: \ #define add_vCtor(baseClass, derivedClass, selectorName) \ \ -inline static baseClass::create##selectorName##Callback baseClass##derivedClass##selectorName##_; +inline static typename baseClass::template create##selectorName##Callback baseClass##derivedClass##selectorName##_; diff --git a/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp b/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp index 0e29b280..6db66184 100755 --- a/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp +++ b/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp @@ -44,7 +44,14 @@ pFlow::int32 pFlow::countChar( const char* s, const char c) pFlow::word pFlow::toUpper(const word & inStr) { word oStr(inStr); - transform(inStr.begin(), inStr.end(), oStr.begin(), ::toupper); + std::transform(inStr.begin(), inStr.end(), oStr.begin(), ::toupper); + return oStr; +} + +pFlow::word pFlow::firstCapital(const word& inStr) +{ + word oStr(inStr); + oStr[0] = std::toupper(oStr[0]); return oStr; } diff --git a/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp b/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp index 77cd983a..8c9ce820 100755 --- a/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp +++ b/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp @@ -62,6 +62,8 @@ int32 countChar(const char* s, const char c); /// convert a word to all caps word toUpper(const word & inStr); +word firstCapital(const word& inStr); + /// Check if str equals "Yes", "Y", "True", "Ok", "ON", or "T" bool isYes(const word & str);