diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 2129f985..021ad360 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -29,6 +29,7 @@ fileSystem/fileSystem.cpp processors/processors.cpp dictionary/dictionary.cpp +dictionary/fileDictionary.cpp dictionary/entry/iEntry.cpp dictionary/entry/dataEntry.cpp dictionary/twoPartEntry/twoPartEntry.cpp @@ -36,6 +37,7 @@ dictionary/twoPartEntry/twoPartEntry.cpp containers/Vector/Vectors.cpp containers/Field/Fields.cpp containers/List/anyList/anyList.cpp +containers/pointField/pointFields.cpp Timer/Timer.cpp Timer/Timers.cpp @@ -53,6 +55,8 @@ repository/systemControl/dynamicLinkLibs.cpp eventManagement/subscriber.cpp eventManagement/observer.cpp +demComponent/demComponent.cpp + structuredData/box/box.cpp structuredData/line/line.cpp structuredData/infinitePlane/infinitePlane.cpp diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp new file mode 100644 index 00000000..c2b85e79 --- /dev/null +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp @@ -0,0 +1,596 @@ +/*------------------------------- 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 +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::changeSize +( + uint32 n, + bool withInit +) +{ + if(n > this->capacity() ) + { + uint32 newCap = evalCapacity(n); + changeCapacity(newCap, withInit); + } + return setSize(n); +} + +template +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::changeCapacitySize +( + uint32 actualCap, + uint32 n, + bool withInit +) +{ + changeCapacity(actualCap, withInit); + return setSize(n); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::changeCapacity +( + uint32 actualCap, + bool withInit +) +{ + if(withInit) + { + resizeInit(view_, actualCap); + } + else + { + resizeNoInit(view_, actualCap); + } +} + +template +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::reallocateCapacitySize +( + uint32 cap, + uint32 s +) +{ + reallocNoInit(view_, cap); + return setSize(s); +} + +template +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::setSize(uint32 n) +{ + auto os = size_; + size_ = n; + return os; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *// + +template +pFlow::VectorSingle::VectorSingle() +: + VectorSingle("VectorSingle") +{} + +template +pFlow::VectorSingle::VectorSingle(const word& name) +: + size_(0), + view_(name,2) +{} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + uint32 n +) +: + size_(n), + view_(name, evalCapacity(n)) +{} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + uint32 n, + const T& val +) +: + VectorSingle(name, n) +{ + assign(n, val); +} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + uint32 cap, + uint32 n, + RESERVE +) +: + size_(n), + view_(name, cap) +{} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + const std::vector & src +) +: + VectorSingle(name) +{ + assign(src); +} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + const std::vector & src, + uint32 cap +) +: + VectorSingle(name) +{ + assign(src, cap); +} + +template +pFlow::VectorSingle::VectorSingle +( + const VectorSingle& src +) +: + VectorSingle(src.name(), src) +{} + +template +pFlow::VectorSingle::VectorSingle +( + const word& name, + const VectorSingle& src +) +: + VectorSingle(name, src.capacity(), src.size(), RESERVE()) +{ + copy(deviceVector(), src.deviceVector()); +} + +template +pFlow::VectorSingle& + pFlow::VectorSingle::operator = (const VectorSingle& rhs) +{ + if(&rhs == this) return *this; + VectorSingle temp(rhs); + + size_ = temp.size(); + view_ = temp.view_; + + return *this; +} + +template +pFlow::VectorSingle::~VectorSingle() +{ + view_ = viewType(); + size_ = 0; +} + +template +INLINE_FUNCTION_H +pFlow::uniquePtr> + pFlow::VectorSingle::clone() const +{ + return makeUnique( this->name(), *this); +} + +template +INLINE_FUNCTION_H +pFlow::VectorSingle* + pFlow::VectorSingle::clonePtr()const +{ + return new VectorSingle(this->name(), *this); +} + +template +INLINE_FUNCTION_H +pFlow::VectorSingle& + pFlow::VectorSingle::VectorField() +{ + return *this; +} + +template +INLINE_FUNCTION_H +const pFlow::VectorSingle& +pFlow::VectorSingle::VectorField()const +{ + return *this; +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::deviceVectorAll() const +{ + return view_; +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::deviceVector()const +{ + return Kokkos::subview(view_, Kokkos::make_pair(0,int(size_))); +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::hostVectorAll()const +{ + auto hView = Kokkos::create_mirror_view(view_); + copy(hView, view_); + return hView; +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::hostVector()const +{ + auto hView = Kokkos::create_mirror_view(deviceVector()); + copy(hView, deviceVector()); + return hView; +} + +template +INLINE_FUNCTION_H +pFlow::word pFlow::VectorSingle::name()const +{ + return view_.label(); +} + +template +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::size()const +{ + return size_; +} + +template +INLINE_FUNCTION_H +pFlow::uint32 pFlow::VectorSingle::capacity()const +{ + return view_.extent(0); +} + +template +INLINE_FUNCTION_H +bool pFlow::VectorSingle::empty()const +{ + return size_==0; +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::reserve(uint32 cap) +{ + changeCapacity(cap); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::reallocate(uint32 cap) +{ + reallocateCapacitySize(cap, 0); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::reallocate +( + uint32 cap, + uint32 newSize +) +{ + reallocateCapacitySize(cap, newSize); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::resize(uint32 n) +{ + changeSize(n); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::resize(uint32 n, const T& val) +{ + assign(n, val); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::clear() +{ + size_ = 0; +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::fill(const T& val) +{ + if(empty())return; + pFlow::fill(view_, rangeU32(0 ,size_) ,val); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::assign +( + size_t n, + const T& val +) +{ + if( n > capacity() ) + { + reallocateCapacitySize(evalCapacity(n), n); + } + else + { + setSize(n); + } + this->fill(val); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::assign +( + const std::vector& src, + uint32 cap +) +{ + uint32 srcSize = src.size(); + + if(cap != capacity()) + { + reallocateCapacitySize(cap, srcSize); + } + else + { + setSize(srcSize); + } + + // - unmanaged view in the host + hostViewType1D temp(src.data(), srcSize ); + copy(deviceVector(), temp); +} + +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::assign +( + const std::vector& src +) +{ + assign(src, src.capacity()); +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::getSpan() +{ + return span(view_.data(), size()); +} + +template +INLINE_FUNCTION_H +auto pFlow::VectorSingle::getSpan()const +{ + return span(view_.data(), this->size()); +} + +template +INLINE_FUNCTION_H +bool pFlow::VectorSingle::insertSetElement(uint32IndexContainer indices, const T& val) +{ + if(indices.empty()) return true; + + auto maxInd = indices.max(); + + if(this->empty() || maxInd > size()-1 ) + { + resize(maxInd+1); + } + + using policy = Kokkos::RangePolicy>; + + if constexpr( isDeviceAccessible_ ) + { + auto v = view_; + auto ind = indices.deviceView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), + LAMBDA_HD(uint32 i){ + v[ind[i]]= val; + }); + + Kokkos::fence(); + } + else + { + + auto v = view_; + auto ind = indices.hostView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), + LAMBDA_HD(uint32 i){ + v[ind[i]]= val; + }); + + Kokkos::fence(); + + } + + return true; +} + + +template +INLINE_FUNCTION_H +bool pFlow::VectorSingle::insertSetElement +( + const uint32IndexContainer indices, + const std::vector& vals +) +{ + + if(indices.size() == 0)return true; + if(indices.size() != vals.size())return false; + + auto maxInd = indices.max(); + + if(this->empty() || maxInd > size()-1 ) + { + resize(maxInd+1); + } + + using policy = Kokkos::RangePolicy>; + + hostViewType1D hVals( vals.data(), vals.size()); + + if constexpr( isDeviceAccessible_ ) + { + deviceViewType1D dVals("dVals", indices.size()); + copy(dVals, hVals); + auto dVec = view_; + auto ind = indices.deviceView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), LAMBDA_HD(int32 i){ + dVec(ind(i))= dVals(i);} + ); + + Kokkos::fence(); + + } + else + { + auto dVec = view_; + auto ind = indices.hostView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), LAMBDA_HD(int32 i){ + dVec(ind(i))= hVals(i);} + ); + + Kokkos::fence(); + + } + + return true; +} + + +template +INLINE_FUNCTION_H +bool pFlow::VectorSingle::reorderItems(uint32IndexContainer indices) +{ + if(indices.size() == 0) + { + setSize(0); + return true; + } + + auto maxInd = indices.max(); + + if(maxInd >= this->size()) + { + fatalErrorInFunction<<"In reordering the VectorSingle (" + << this->name()<< ") maximum index ("<< maxInd << + ") exceeds the size of the vector (" << this->size()<<")"<name(), newSize); + + using policy = Kokkos::RangePolicy< execution_space,Kokkos::IndexType>; + + if constexpr( isDeviceAccessible_) + { + auto d_indices = indices.deviceView(); + auto d_view = view_; + + Kokkos::parallel_for + ( + "VectorSingle::sortItems", + policy(0,newSize), + LAMBDA_HD(uint32 i) + { + sortedView(i) = d_view(d_indices(i)); + } + ); + + Kokkos::fence(); + + } + else + { + auto h_indices = indices.hostView(); + auto d_view = view_; + + Kokkos::parallel_for + ( + "VectorSingle::sortItems", + policy(0,newSize), + LAMBDA_HD(uint32 i) + { + sortedView(i) = d_view(h_indices(i)); + } + ); + + Kokkos::fence(); + } + + copy(deviceVector(), sortedView); + + return true; +} \ No newline at end of file diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 4e3b3d2d..7a2ea557 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -17,23 +17,18 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - - #ifndef __VectorSingle_hpp__ #define __VectorSingle_hpp__ #include - #include "globalSettings.hpp" +#include "phasicFlowKokkos.hpp" #include "types.hpp" #include "error.hpp" #include "indexContainer.hpp" -#include "iOstream.hpp" -#include "iIstream.hpp" +#include "streams.hpp" #include "span.hpp" -#include "Vector.hpp" -#include "phasicFlowKokkos.hpp" #include "dataIO.hpp" @@ -49,8 +44,6 @@ namespace pFlow template class VectorSingle; - - template class VectorSingle { @@ -103,7 +96,6 @@ protected: /// Is the memory of this vector accessible from Host static constexpr bool isHostAccessible_ = isHostAccessible(); - //Kokkos::SpaceAccessibility::accessible; /// Is the memory of this vector accessiple from Divce static constexpr @@ -123,356 +115,177 @@ protected: return static_cast(n*growthFactor_+1); } - /// Change size to n and preserve the conetent if realloc + /// @brief Change size to n and preserve the conetent if realloc /// occurs INLINE_FUNCTION_H - uint32 changeSize(uint32 n, bool withInit= false) - { - if(n > this->capacity() ) - { - uint32 newCap = evalCapacity(n); - changeCapacity(newCap, withInit); - } - return setSize(n); - } + uint32 changeSize(uint32 n, bool withInit= false); + /// @brief Change the size and capacity of Vector INLINE_FUNCTION_H - uint32 changeCapacitySize(uint32 actualCap, uint32 n, bool withInit= false) - { - changeCapacity(actualCap, withInit); - return setSize(n); - } - + uint32 changeCapacitySize(uint32 actualCap, uint32 n, bool withInit= false); + INLINE_FUNCTION_H - void changeCapacity(uint32 actualCap, bool withInit= false) - { - if(withInit) - { - resizeInit(view_, actualCap); - } - else - { - resizeNoInit(view_, actualCap); - } - } - + void changeCapacity(uint32 actualCap, bool withInit= false); + INLINE_FUNCTION_H - uint32 reallocateCapacitySize(uint32 cap, uint32 s) - { - reallocNoInit(view_, cap); - return setSize(s); - } - + uint32 reallocateCapacitySize(uint32 cap, uint32 s); + INLINE_FUNCTION_H - uint32 setSize(uint32 n) - { - auto os = size_; - size_ = n; - return os; - } + uint32 setSize(uint32 n); public: - // - type info + /// Type info TypeInfoTemplateNV2("VectorSingle", T, memoerySpaceName()); //// - Constructors /// Empty vector - VectorSingle() - : - VectorSingle("VectorSingle") - {} - - /// Empty vector with a name - VectorSingle(const word& name) - : - size_(0), - view_(name,2) - {} - + VectorSingle(); + + /// Empty vector with a name (capacity = 2) + VectorSingle(const word& name); /// Vector with name and size n - VectorSingle(const word& name, uint32 n) - : - size_(n), - view_(name, evalCapacity(n)) - {} - + VectorSingle(const word& name, uint32 n); - /// Vector with name, size and value - VectorSingle(const word& name, uint32 n, const T& val) - : - VectorSingle(name, n) - { - assign(n, val); - } - + VectorSingle(const word& name, uint32 n, const T& val); /// Vector with name, size (n) and reserved capacity - VectorSingle(const word& name, uint32 cap, uint32 n, RESERVE ) - : - size_(n), - view_(name, cap) - {} - + VectorSingle(const word& name, uint32 cap, uint32 n, RESERVE ); + /// Construct with a name and form std::vector (host memory) - VectorSingle(const word& name, const std::vector & src) - : - VectorSingle(name) - { - assign(src); - } - - /// Construct with a name and form std::vector (host memory) - /// and with a desired capacity. - VectorSingle(const word& name, const std::vector & src, uint32 cap) - : - VectorSingle(name) - { - assign(src, cap); - } + VectorSingle(const word& name, const std::vector & src); + /// Construct with a name and form std::vector (host memory) and with a desired capacity. + VectorSingle(const word& name, const std::vector & src, uint32 cap); + /// Copy construct (performs deep copy) - VectorSingle(const VectorSingle& src) - : - VectorSingle(src.name(), src) - { - //copy(deviceVector(), src.deviceVector()); - } - - /// Copy construct with a new name (perform deep copy) - VectorSingle(const word& name, const VectorSingle& src) - : - VectorSingle(name, src.capacity(), src.size(), RESERVE()) - { - copy(deviceVector(), src.deviceVector()); - } - + VectorSingle(const VectorSingle& src); + + /// Copy construct with a new name (perform deep copy) + VectorSingle(const word& name, const VectorSingle& src); + /// Copy assignment (perform deep copy from rhs to *this) - VectorSingle& operator = (const VectorSingle& rhs) - { - if(&rhs == this) return *this; - VectorSingle temp(rhs); - - size_ = temp.size(); - view_ = temp.view_; - - return *this; - } - + VectorSingle& operator = (const VectorSingle& rhs) ; + /// Move construct VectorSingle(VectorSingle&&) = default; /// Move assignment VectorSingle& operator= (VectorSingle&&) = default; - /// This may not destroy the underlying memory, sice view is + /// @brief Descructor + /// This may not destroy the underlying memory, sice view is /// shared_ptr and maybe referenced by another object too - ~VectorSingle() - { - view_ = viewType(); - size_ = 0; - } + ~VectorSingle(); /// Clone as a uniquePtr (perform deep copy) INLINE_FUNCTION_H - uniquePtr clone() const - { - return makeUnique( this->name(), *this); - } + uniquePtr clone() const; /// Clone as a pointer (perform deep copy) INLINE_FUNCTION_H - VectorSingle* clonePtr()const - { - return new VectorSingle(this->name(), *this); - } - + VectorSingle* clonePtr()const; + //// - Methods /// Return *this INLINE_FUNCTION_H - VectorType& VectorField() - { - return *this; - } + VectorType& VectorField(); /// Return *this INLINE_FUNCTION_H - const VectorType& VectorField()const - { - return *this; - } + const VectorType& VectorField()const; /// Device vector range [0,capcity) INLINE_FUNCTION_H - viewType deviceVectorAll() const{ - return view_; - } + auto deviceVectorAll() const; /// Device vector range [0, size) INLINE_FUNCTION_H - viewType deviceVector()const - { - return Kokkos::subview(view_, Kokkos::make_pair(0,int(size_))); - } + auto deviceVector()const; /// Return a vector accessible on Host in range [0,capacity) INLINE_FUNCTION_H - auto hostVectorAll()const - { - auto hView = Kokkos::create_mirror_view(view_); - copy(hView, view_); - return hView; - } + auto hostVectorAll()const; + /// Return a vector accessible on Host in range [0,size) INLINE_FUNCTION_H - auto hostVector()const - { - auto hView = Kokkos::create_mirror_view(deviceVector()); - copy(hView, deviceVector()); - return hView; - } + auto hostVector()const; /// Name of the vector INLINE_FUNCTION_H - const word name()const - { - return view_.label(); - } + word name()const; + /// Size of the vector INLINE_FUNCTION_H - uint32 size()const - { - return size_; - } + uint32 size()const; + // Capcity of the vector INLINE_FUNCTION_H - uint32 capacity()const - { - return view_.extent(0); - } - + uint32 capacity()const; + /// If vector is empty INLINE_FUNCTION_H - bool empty()const - { - return size_==0; - } - + bool empty()const; + /// Reserve capacity for vector /// Preserve the content. INLINE_FUNCTION_H - void reserve(uint32 cap) - { - changeCapacity(cap); - } + void reserve(uint32 cap); /// Reallocate memory to new cap and set size to 0. INLINE_FUNCTION_H - void reallocate(uint32 cap) - { - reallocateCapacitySize(cap, 0); - } - + void reallocate(uint32 cap); + /// Reallocate memory to new cap and set size to newSize. /// Do not preserve the content INLINE_FUNCTION_H - void reallocate(uint32 cap, uint32 newSize) - { - reallocateCapacitySize(cap, newSize); - } - + void reallocate(uint32 cap, uint32 newSize); + /// Resize the vector and preserve the content INLINE_FUNCTION_H - void resize(uint32 n){ - changeSize(n); - } + void resize(uint32 n); /// Resize the vector and assign the value to it. INLINE_FUNCTION_H - void resize(uint32 n, const T& val) { - assign(n, val); - } + void resize(uint32 n, const T& val); /// Clear the vector, but keep the allocated memory unchanged INLINE_FUNCTION_H - void clear() - { - size_ = 0; - } - + void clear(); + /// Fill the range [0,size) with val INLINE_FUNCTION_H - void fill(const T& val) - { - if(empty())return; - pFlow::fill(view_, rangeU32(0 ,size_) ,val); - } + void fill(const T& val); /// Change size of the vector and assign val to vector and INLINE_FUNCTION_H - void assign(size_t n, const T& val) - { - if( n > capacity() ) - { - reallocateCapacitySize(evalCapacity(n), n); - } - else - { - setSize(n); - } - this->fill(val); - } - + void assign(size_t n, const T& val); /// Assign source vector with specified capacity. /// The size of *this becomes the size of src. INLINE_FUNCTION_H - void assign(const std::vector& src, uint32 cap) - { - uint32 srcSize = src.size(); - - if(cap != capacity()) - { - reallocateCapacitySize(cap, srcSize); - } - else - { - setSize(srcSize); - } - - // - unmanaged view in the host - hostViewType1D temp(src.data(), srcSize ); - copy(deviceVector(), temp); - } + void assign(const std::vector& src, uint32 cap); + /// Assign source vector. /// The size of *this becomes the size of src. /// The capacity of *this becomes the capacity of src. INLINE_FUNCTION_H - void assign(const std::vector& src) - { - assign(src, src.capacity()); - } - - INLINE_FUNCTION_H - auto getSpan() - { - return span(view_.data(), size()); - } + void assign(const std::vector& src); + INLINE_FUNCTION_H + auto getSpan(); + INLINE_FUNCTION_H - auto getSpan()const - { - return span(view_.data(), this->size()); - } - + auto getSpan()const; + INLINE_FUNCTION_H bool insertSetElement(uint32IndexContainer indices, const T& val); @@ -482,40 +295,8 @@ public: INLINE_FUNCTION_H bool reorderItems(uint32IndexContainer indices); - - /*INLINE_FUNCTION_H - bool append(const deviceViewType1D& dVec, size_t numElems) - { - - if(numElems == 0 )return true; - auto oldSize = size_; - auto newSize = size_ + numElems; - - if(this->empty() || newSize > capacity() ) - { - resize(newSize); - } - else - { - size_ = size_+numElems; - } - - auto dSubView = Kokkos::subview(view_, Kokkos::make_pair(oldSize, newSize)); - copy(dSubView, dVec); - - return true; - } - - INLINE_FUNCTION_H - bool append(const VectorSingle& Vec) - { - return append(Vec.deviceVector(), Vec.size()); - }*/ - - // - host calls only - // push a new element at the end - // resize if necessary - // works on host accessible vector + /// @brief push a new element at the end (host call only) + /// resize if necessary and works on host accessible vector. template INLINE_FUNCTION_H typename std::enable_if::type @@ -535,7 +316,7 @@ public: return view_.data(); } - /// Return begin iterator. it works when host is accessible. + /// Return begin iterator. It works when devices is host accessible. template INLINE_FUNCTION_H typename std::enable_if_t @@ -666,8 +447,39 @@ inline iOstream& operator << (iOstream& os, const VectorSingle& } // - pFlow #include "VectorSingleAlgorithms.hpp" -#include "VectorSingleI.hpp" +#include "VectorSingle.cpp" + + #endif //__VectorSingle_hpp__ + +/*INLINE_FUNCTION_H + bool append(const deviceViewType1D& dVec, size_t numElems) + { + + if(numElems == 0 )return true; + auto oldSize = size_; + auto newSize = size_ + numElems; + + if(this->empty() || newSize > capacity() ) + { + resize(newSize); + } + else + { + size_ = size_+numElems; + } + + auto dSubView = Kokkos::subview(view_, Kokkos::make_pair(oldSize, newSize)); + copy(dSubView, dVec); + + return true; + } + + INLINE_FUNCTION_H + bool append(const VectorSingle& Vec) + { + return append(Vec.deviceVector(), Vec.size()); + }*/ \ No newline at end of file diff --git a/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp b/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp index bdd5c521..13bce66b 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp @@ -17,8 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - - #ifndef __VectorSingleMath_hpp__ #define __VectorSingleMath_hpp__ diff --git a/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp b/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp deleted file mode 100644 index 2dabf14a..00000000 --- a/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp +++ /dev/null @@ -1,197 +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. - ------------------------------------------------------------------------------*/ - - -template -INLINE_FUNCTION_H -bool pFlow::VectorSingle::insertSetElement(uint32IndexContainer indices, const T& val) -{ - if(indices.empty()) return true; - - auto maxInd = indices.max(); - - if(this->empty() || maxInd > size()-1 ) - { - resize(maxInd+1); - } - - using policy = Kokkos::RangePolicy>; - - if constexpr( isDeviceAccessible_ ) - { - auto v = view_; - auto ind = indices.deviceView(); - - Kokkos::parallel_for( - "VectorSingle::insertSetElement", - policy(0,indices.size()), - LAMBDA_HD(uint32 i){ - v[ind[i]]= val; - }); - - Kokkos::fence(); - } - else - { - - auto v = view_; - auto ind = indices.hostView(); - - Kokkos::parallel_for( - "VectorSingle::insertSetElement", - policy(0,indices.size()), - LAMBDA_HD(uint32 i){ - v[ind[i]]= val; - }); - - Kokkos::fence(); - - } - - return true; -} - - -template -INLINE_FUNCTION_H -bool pFlow::VectorSingle::insertSetElement -( - const uint32IndexContainer indices, - const std::vector& vals -) -{ - - if(indices.size() == 0)return true; - if(indices.size() != vals.size())return false; - - auto maxInd = indices.max(); - - if(this->empty() || maxInd > size()-1 ) - { - resize(maxInd+1); - } - - using policy = Kokkos::RangePolicy>; - - hostViewType1D hVals( vals.data(), vals.size()); - - if constexpr( isDeviceAccessible_ ) - { - deviceViewType1D dVals("dVals", indices.size()); - copy(dVals, hVals); - auto dVec = view_; - auto ind = indices.deviceView(); - - Kokkos::parallel_for( - "VectorSingle::insertSetElement", - policy(0,indices.size()), LAMBDA_HD(int32 i){ - dVec(ind(i))= dVals(i);} - ); - - Kokkos::fence(); - - } - else - { - auto dVec = view_; - auto ind = indices.hostView(); - - Kokkos::parallel_for( - "VectorSingle::insertSetElement", - policy(0,indices.size()), LAMBDA_HD(int32 i){ - dVec(ind(i))= hVals(i);} - ); - - Kokkos::fence(); - - } - - return true; -} - - -template -INLINE_FUNCTION_H -bool pFlow::VectorSingle::reorderItems(uint32IndexContainer indices) -{ - if(indices.size() == 0) - { - setSize(0); - return true; - } - - auto maxInd = indices.max(); - - if(maxInd >= this->size()) - { - fatalErrorInFunction<<"In reordering the VectorSingle (" - << this->name()<< ") maximum index ("<< maxInd << - ") exceeds the size of the vector (" << this->size()<<")"<name(), newSize); - - using policy = Kokkos::RangePolicy< execution_space,Kokkos::IndexType>; - - if constexpr( isDeviceAccessible_) - { - auto d_indices = indices.deviceView(); - auto d_view = view_; - - Kokkos::parallel_for - ( - "VectorSingle::sortItems", - policy(0,newSize), - LAMBDA_HD(uint32 i) - { - sortedView(i) = d_view(d_indices(i)); - } - ); - - Kokkos::fence(); - - } - else - { - auto h_indices = indices.hostView(); - auto d_view = view_; - - Kokkos::parallel_for - ( - "VectorSingle::sortItems", - policy(0,newSize), - LAMBDA_HD(uint32 i) - { - sortedView(i) = d_view(h_indices(i)); - } - ); - - Kokkos::fence(); - } - - copy(deviceVector(), sortedView); - - return true; -} \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/boundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField.cpp new file mode 100644 index 00000000..21db4031 --- /dev/null +++ b/src/phasicFlow/containers/pointField/boundaryField.cpp @@ -0,0 +1,32 @@ +/*------------------------------- 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::boundaryField::boundaryField +( + const boundaryBase& boundary, + FieldType &internal +) +: + observer(), + boundary_(boundary), + internal_(internal) +{} + diff --git a/src/phasicFlow/containers/pointField/boundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField.hpp new file mode 100644 index 00000000..fca7cd3f --- /dev/null +++ b/src/phasicFlow/containers/pointField/boundaryField.hpp @@ -0,0 +1,65 @@ +/*------------------------------- 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 __boundaryField_hpp__ +#define __boundaryField_hpp__ + +#include "observer.hpp" +#include "boundaryBase.hpp" +#include "Field.hpp" + +namespace pFlow +{ + +template< template class VectorField, class T, class MemorySpace = void> +class boundaryField +: + public observer +{ +public: + using FieldType = Field; +protected: + + const boundaryBase& boundary_; + + /// @brief a ref to the internal field + FieldType& internal_; + +public: + + boundaryField(const boundaryBase& boundary, FieldType& internal); + + bool update + ( + const message& msg, + const anyList& varList + ) override + { + notImplementedFunction; + return false; + } + +}; + +} + +#include "boundaryField.cpp" + +#endif + diff --git a/src/phasicFlow/containers/pointField/boundaryFieldList.hpp b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp new file mode 100644 index 00000000..29f3c786 --- /dev/null +++ b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp @@ -0,0 +1,72 @@ +/*------------------------------- 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 __boundaryFieldList_hpp__ +#define __boundaryFieldList_hpp__ + +#include "boundaryField.hpp" +#include "boundaryList.hpp" +#include "ListPtr.hpp" + +namespace pFlow +{ + +template< template class VectorField, class T, class MemorySpace = void > +class boundaryFieldList +: + ListPtr> +{ +public: + + using boundaryFieldType = boundaryField; + + using FieldType = typename boundaryFieldType::FieldType; + +protected: + + const boundaryList& boundaries_; + +public: + + boundaryFieldList(const boundaryList& boundaries, FieldType& internal) + : + ListPtr(boundaries.size()), + boundaries_(boundaries) + { + for(auto i=0; iset + ( + i, + makeUnique + ( + boundaries_[i], + internal + ) + ); + } + } + + + +}; + +} + +#endif \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/pointField.cpp b/src/phasicFlow/containers/pointField/pointField.cpp index bc0a62e0..a8a0c6ff 100644 --- a/src/phasicFlow/containers/pointField/pointField.cpp +++ b/src/phasicFlow/containers/pointField/pointField.cpp @@ -18,8 +18,20 @@ Licence: -----------------------------------------------------------------------------*/ - template class VectorField, class T, class MemorySpace> +pFlow::pointField::pointField +( + const pointStructure& pStruct, + const T& defVal, + message msg +) +: + boundaryFieldList_(pStruct.boundaries(), *this), + pStruct_(pStruct), + defaultValue_(defVal) +{} + +/*template class VectorField, class T, class MemorySpace> bool pFlow::pointField::readPointField ( iIstream& is @@ -113,9 +125,7 @@ bool pFlow::pointField::update(const eventMessage& if( msg.isDeleted() ) { - /*const auto& dp = pStruct_.markedDeletePoints(); - return this->deleteElement(dp); - notImplementedFunction;*/ + } else if( msg.isInsert()) { @@ -132,5 +142,5 @@ bool pFlow::pointField::update(const eventMessage& } return true; -} +}*/ diff --git a/src/phasicFlow/containers/pointField/pointField.hpp b/src/phasicFlow/containers/pointField/pointField.hpp index 5c074243..9dcace79 100644 --- a/src/phasicFlow/containers/pointField/pointField.hpp +++ b/src/phasicFlow/containers/pointField/pointField.hpp @@ -21,20 +21,18 @@ Licence: #ifndef __pointField_hpp__ #define __pointField_hpp__ - -#include "Field.hpp" +#include "boundaryFieldList.hpp" #include "pointStructure.hpp" -#include "error.hpp" +#include "Field.hpp" +#include "observer.hpp" namespace pFlow { - - template class VectorField, class T, class MemorySpace=void> class pointField : - public eventObserver, + public observer, public Field { public: @@ -42,29 +40,36 @@ public: using pointFieldType = pointField; using FieldType = Field; + + using boundaryFieldListType = boundaryFieldList; using VectorType = typename FieldType::VectorType; using iterator = typename FieldType::iterator; - using constIterator = typename FieldType::constIterator; + using const_iterator = typename FieldType::const_iterator; using reference = typename FieldType::reference; - using constReference = typename FieldType::constReference; + using const_reference = typename FieldType::const_reference; - using valueType = typename FieldType::valueType; + using value_type = typename FieldType::value_type; using pointer = typename FieldType::pointer; - using constPointer = typename FieldType::constPointer; + using const_pointer = typename FieldType::const_pointer; protected: - ////- data members - const pointStructure& pStruct_; + //// - data members - // - value when a new item is added to field + /// @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_; @@ -77,10 +82,13 @@ public: //// - Constructors // - construct a field from pointStructure and set defaultValue_ and field value to defVal - pointField( const pointStructure& pStruct, const T& defVal, bool subscribe = true); + pointField( + const pointStructure& pStruct, + const T& defVal, + message msg); // - construct from iIOEntity, pointStructure and a value - pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true); + /*pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true); // - construct from another pointField // subscribe to events if true @@ -159,10 +167,10 @@ public: bool write(iOstream& os)const { return writePointField(os); - } + }*/ }; -template class VectorField, class T, class MemorySpace> +/*template class VectorField, class T, class MemorySpace> iIstream& operator >> (iIstream & is, pointField & pF ) { if( !pF.read(is)) @@ -186,11 +194,11 @@ iOstream& operator << (iOstream& os, const pointField class VectorField, class T, class MemorySpace=void> +class pointField +: + public eventObserver, + public Field +{ +public: + + using pointFieldType = pointField; + + using FieldType = Field; + + using VectorType = typename FieldType::VectorType; + + using iterator = typename FieldType::iterator; + + using constIterator = typename FieldType::constIterator; + + using reference = typename FieldType::reference; + + using constReference = typename FieldType::constReference; + + using valueType = typename FieldType::valueType; + + using pointer = typename FieldType::pointer; + + using constPointer = typename FieldType::constPointer; + +protected: + + ////- data members + const pointStructure& pStruct_; + + // - 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 pointStructure& pStruct, const T& defVal, bool subscribe = true); + + // - 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/pointFields.cpp b/src/phasicFlow/containers/pointField/pointFields.cpp index da0084b7..e503dd41 100644 --- a/src/phasicFlow/containers/pointField/pointFields.cpp +++ b/src/phasicFlow/containers/pointField/pointFields.cpp @@ -24,7 +24,7 @@ Licence: template class pFlow::pointField; -template class pFlow::pointField; +/*template class pFlow::pointField; template class pFlow::pointField; @@ -52,7 +52,7 @@ template class pFlow::pointField; -template class pFlow::pointField; +template class pFlow::pointField;*/ diff --git a/src/phasicFlow/containers/pointField/pointFields.hpp b/src/phasicFlow/containers/pointField/pointFields.hpp index a3183143..65dde6b1 100644 --- a/src/phasicFlow/containers/pointField/pointFields.hpp +++ b/src/phasicFlow/containers/pointField/pointFields.hpp @@ -35,21 +35,17 @@ template template using pointField_D = pointField; -template - using pointField_HD = pointField; +/*template + using pointField_HD = pointField;*/ using int8PointField_D = pointField; using int8PointField_H = pointField; -using int16PointField_D = pointField; - -using int16PointField_H = pointField; - using int32PointField_D = pointField; -using int32PointField_H = pointField; +/*using int32PointField_H = pointField; using int64PointField_D = pointField; @@ -89,7 +85,7 @@ using realPointField_HD = pointField; using realx3PointField_HD = pointField; -using wordPointField = pointField>; +using wordPointField = pointField>;*/ } diff --git a/src/phasicFlow/demComponent/demComponent.cpp b/src/phasicFlow/demComponent/demComponent.cpp new file mode 100644 index 00000000..4b76b245 --- /dev/null +++ b/src/phasicFlow/demComponent/demComponent.cpp @@ -0,0 +1,31 @@ +/*------------------------------- 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 "demComponent.hpp" + + + +pFlow::demComponent::demComponent(const word& name, systemControl& control) +: + componentName_(name), + control_(control), + time_(control.time()), + timers_(name, &control.timers()) +{} \ No newline at end of file diff --git a/src/demComponent/demComponent.hpp b/src/phasicFlow/demComponent/demComponent.hpp similarity index 91% rename from src/demComponent/demComponent.hpp rename to src/phasicFlow/demComponent/demComponent.hpp index d5ad1635..d6ca633c 100644 --- a/src/demComponent/demComponent.hpp +++ b/src/phasicFlow/demComponent/demComponent.hpp @@ -22,7 +22,7 @@ Licence: #define __demComponent_hpp__ #include "systemControl.hpp" - +#include "Time.hpp" namespace pFlow @@ -46,7 +46,9 @@ protected: word componentName_; /// Reference to systemControl - systemControl& control_; + systemControl& control_; + + Time& time_; /// All timers (if any) of this component Timers timers_; @@ -59,13 +61,8 @@ public: // - Constructors /// construct from components - demComponent(const word& name, systemControl& control) - : - componentName_(name), - control_(control), - timers_(name, &control.timers()) - {} - + demComponent(const word& name, systemControl& control); + /// No copy constructor demComponent(const demComponent&) = delete; @@ -102,16 +99,29 @@ public: inline real dt()const { - return control_.time().dt(); + return time_.dt(); } /// Current simulation time inline real currentTime()const { - return control_.time().currentTime(); + return time_.currentTime(); } + inline + const auto& time()const + { + return time_; + } + + inline + auto& time() + { + return time_; + } + + /// Const ref to timers inline const auto& timers() const diff --git a/src/phasicFlow/dictionary/dictionary.hpp b/src/phasicFlow/dictionary/dictionary.hpp index fcd55ba4..f6b75a55 100644 --- a/src/phasicFlow/dictionary/dictionary.hpp +++ b/src/phasicFlow/dictionary/dictionary.hpp @@ -84,7 +84,7 @@ protected: /// ref to parrent dictionary const dictionary& parDict_; - bool isGlobal_; + bool isGlobal_ = false; ///// protected methods @@ -106,6 +106,12 @@ protected: /// write dictionary to stream - with keyword bool writeDictionary(iOstream& os, bool withBlock = true)const; + + /// construct an empty dictionary with keyword and make it global/fileDictionary (if true) + dictionary(const word& keyword, bool global); + + /// construct a dictionary with name and read it from file + dictionary(const word& keyword, const fileSystem& file); public: @@ -123,12 +129,6 @@ public: /// construct an empty dictionary with keyword dictionary(const word& keyword); - /// construct an empty dictionary with keyword and make it global/fileDictionary (if true) - dictionary(const word& keyword, bool global); - - /// construct a dictionary with name and read it from file - dictionary(const word& keyword, const fileSystem& file); - /// cunstruct an empty dictionary with keyword and parDict dictionary(const word& keyword, const dictionary& parDict); diff --git a/src/phasicFlow/dictionary/fileDictionary.cpp b/src/phasicFlow/dictionary/fileDictionary.cpp new file mode 100644 index 00000000..e550311f --- /dev/null +++ b/src/phasicFlow/dictionary/fileDictionary.cpp @@ -0,0 +1,26 @@ +#include "fileDictionary.hpp" +#include "IOPattern.hpp" + + +pFlow::fileDictionary::fileDictionary(const word &keyword) +: + dictionary(keyword, true) +{ +} + +pFlow::fileDictionary::fileDictionary(const word &keyword, const fileSystem &file) +: + dictionary(keyword, file) +{ +} + +bool pFlow::fileDictionary::read(iIstream &is, const IOPattern &iop) +{ + + return dictionary::read(is); +} + +bool pFlow::fileDictionary::write(iOstream &os, const IOPattern &iop) const +{ + return dictionary::write(os); +} diff --git a/src/phasicFlow/dictionary/fileDictionary.hpp b/src/phasicFlow/dictionary/fileDictionary.hpp new file mode 100644 index 00000000..b029f50b --- /dev/null +++ b/src/phasicFlow/dictionary/fileDictionary.hpp @@ -0,0 +1,53 @@ +/*------------------------------- 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 "dictionary.hpp" + + +namespace pFlow +{ + +class IOPattern; + +class fileDictionary +: + public dictionary +{ +public: + + TypeInfo("fileDictionary"); + + /// construct an empty dictionary with keyword and make it global/fileDictionary + fileDictionary(const word& keyword); + + /// 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); + + /// write to stream + virtual bool write(iOstream& os, const IOPattern& iop) const; + +}; + +} diff --git a/src/phasicFlow/repository/IOobject/IOobject.cpp b/src/phasicFlow/repository/IOobject/IOobject.cpp index e49d757c..02cd841d 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.cpp +++ b/src/phasicFlow/repository/IOobject/IOobject.cpp @@ -123,7 +123,7 @@ bool pFlow::IOobject::read(iIstream& is, bool rdHdr) { if(!readHeader(is))return false; } - return object_->read_object_t(is); + return object_->read_object_t(is, ioPattern_); } @@ -132,5 +132,5 @@ bool pFlow::IOobject::write(iOstream& os) const if(this->readWriteHeader()) writeHeader(os, typeName()); - return (object_->write_object_t(os) && writeSeparator(os)); + return (object_->write_object_t(os, ioPattern_) && writeSeparator(os)); } \ No newline at end of file diff --git a/src/phasicFlow/repository/IOobject/IOobject.hpp b/src/phasicFlow/repository/IOobject/IOobject.hpp index 2b947946..d2ef1c18 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.hpp +++ b/src/phasicFlow/repository/IOobject/IOobject.hpp @@ -50,9 +50,9 @@ private: virtual word typeName()const = 0; - virtual bool read_object_t(iIstream& is) = 0; + virtual bool read_object_t(iIstream& is, IOPattern iop) = 0; - virtual bool write_object_t(iOstream& os)const = 0; + virtual bool write_object_t(iOstream& os, IOPattern iop)const = 0; }; @@ -92,14 +92,14 @@ private: return data_.typeName(); } - virtual bool read_object_t(iIstream& is) + bool read_object_t(iIstream& is, IOPattern iop) override { - return data_.read(is); + return data_.read(is, iop); } - virtual bool write_object_t(iOstream& os)const + bool write_object_t(iOstream& os, IOPattern iop)const override { - return data_.write(os); + return data_.write(os, iop); } auto& data() diff --git a/src/phasicFlow/repository/systemControl/systemControl.cpp b/src/phasicFlow/repository/systemControl/systemControl.cpp index 974567fb..a9616a58 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.cpp +++ b/src/phasicFlow/repository/systemControl/systemControl.cpp @@ -122,17 +122,17 @@ pFlow::systemControl::systemControl ), settingsDict_ ( - settings().emplaceObject + settings().emplaceObject ( objectFile ( settingsFile__, "", objectFile::READ_ALWAYS, - objectFile::WRITE_NEVER + objectFile::WRITE_NEVER, + IOPattern::AllProcessorsSimilar ), - settingsFile__, - true + settingsFile__ ) ), libs_(settingsDict_), @@ -193,7 +193,7 @@ pFlow::systemControl::systemControl( ), settingsDict_ ( - settings().emplaceObject + settings().emplaceObject ( objectFile ( @@ -202,8 +202,7 @@ pFlow::systemControl::systemControl( objectFile::READ_ALWAYS, objectFile::WRITE_NEVER ), - settingsFile__, - true + settingsFile__ ) ), libs_(settingsDict_), @@ -231,10 +230,10 @@ pFlow::systemControl::systemControl( writeToFileTimer_("Write to file", &timers_) {} -pFlow::dictionary& pFlow::systemControl::domainDict() +pFlow::fileDictionary& pFlow::systemControl::domainDict() { return - settings().emplaceObjectOrGet + settings().emplaceObjectOrGet ( objectFile ( @@ -243,8 +242,7 @@ pFlow::dictionary& pFlow::systemControl::domainDict() objectFile::READ_ALWAYS, objectFile::WRITE_NEVER ), - domainFile__, - true + domainFile__ ); } diff --git a/src/phasicFlow/repository/systemControl/systemControl.hpp b/src/phasicFlow/repository/systemControl/systemControl.hpp index 8d6dfc3b..d79f157c 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.hpp +++ b/src/phasicFlow/repository/systemControl/systemControl.hpp @@ -30,7 +30,7 @@ Licence: #include "types.hpp" #include "Time.hpp" -#include "dictionary.hpp" +#include "fileDictionary.hpp" #include "box.hpp" #include "Timers.hpp" #include "dynamicLinkLibs.hpp" @@ -59,7 +59,7 @@ protected: repository caseSetup_; /// settingsDict fileDictionary - dictionary& settingsDict_; + fileDictionary& settingsDict_; /// extra libs to be loaded dynamicLinkLibs libs_; @@ -155,15 +155,15 @@ public: return timersReport_(); } - const dictionary& settingsDict()const{ + const fileDictionary& settingsDict()const{ return settingsDict_; } - dictionary& settingsDict(){ + fileDictionary& settingsDict(){ return settingsDict_; } - dictionary& domainDict(); + fileDictionary& domainDict(); virtual word runName() const diff --git a/src/phasicFlow/setFieldList/setFieldEntryTemplates.cpp b/src/phasicFlow/setFieldList/setFieldEntryTemplates.cpp index db9e4f28..83540daa 100644 --- a/src/phasicFlow/setFieldList/setFieldEntryTemplates.cpp +++ b/src/phasicFlow/setFieldList/setFieldEntryTemplates.cpp @@ -50,8 +50,8 @@ void* pFlow::setFieldEntry::setPointFieldDefaultValueNew Type defValue = entry_.secondPartVal(); if(verbose) - REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<< - " in repository "<< owner.name() <(); if(verbose) - REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<< - " in repository "<< owner.name() <(); if(verbose) - REPORT(2)<< "Setting selected points of " << greenText(fName) - << " to value " << cyanText(value) <::TYPENAME() == fieldTypeName ) + /*if( pointField::TYPENAME() == fieldTypeName ) { @@ -164,7 +164,7 @@ void* pFlow::setFieldEntry::setPointFieldSelected return &field; else return nullptr; - } + }*/ fatalErrorInFunction<< fieldTypeName<< " is not a supported field type for setFieldEntry.\n"; @@ -197,8 +197,8 @@ void* pFlow::setFieldEntry::setPointFieldSelectedStd Type value = entry_.secondPartVal(); if(verbose) - REPORT(2)<< "Setting selected points of " << greenText(fName) - << " to value " << cyanText(value) < makeUnique(Args&&... args) } - - - #endif diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp index 353912d5..5f0923a2 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp @@ -20,6 +20,7 @@ Licence: #include "boundaryBase.hpp" #include "dictionary.hpp" +#include "internalPoints.hpp" /*pFlow::boundaryBase::boundaryBase ( @@ -59,13 +60,30 @@ pFlow::boundaryBase::boundaryBase } +typename pFlow::boundaryBase::pointFieldAccessType + pFlow::boundaryBase::thisPoints() +{ + + return pointFieldAccessType + ( + indexList_.size(), + indexList_.deviceVectorAll(), + internal_.pointPosition().deviceVectorAll() + ); + +} -pFlow::uniquePtr pFlow::boundaryBase::create -( - const dictionary& dict, - const plane& bplane, - internalPoints& internal -) +typename pFlow::boundaryBase::pointFieldAccessType + pFlow::boundaryBase::neighborPoints() +{ + notImplementedFunction; + return pointFieldAccessType(); +} + +pFlow::uniquePtr pFlow::boundaryBase::create( + const dictionary &dict, + const plane &bplane, + internalPoints &internal) { word type = dict.getVal("type"); word bType = angleBracketsNames("boundary", type); diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp index b66ebc47..ed242180 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp @@ -25,6 +25,7 @@ Licence: #include "subscriber.hpp" #include "VectorSingles.hpp" #include "plane.hpp" +#include "scatterFieldAccess.hpp" #include "streams.hpp" @@ -42,6 +43,9 @@ class boundaryBase { public: + using pointFieldAccessType = + scatterFieldAccess; + enum DIRECTION: int8 { @@ -106,11 +110,20 @@ public: (dict, bplane, internal) ); - virtual bool beforeIteratoin(uint32 iterNum, real t) = 0 ; + virtual + bool beforeIteratoin(uint32 iterNum, real t) = 0 ; - virtual bool iterate(uint32 iterNum, real t) = 0; + virtual + bool iterate(uint32 iterNum, real t) = 0; - virtual bool afterIteration(uint32 iterNum, real t) = 0; + virtual + bool afterIteration(uint32 iterNum, real t) = 0; + + pointFieldAccessType thisPoints(); + + virtual + pointFieldAccessType neighborPoints(); + static uniquePtr create diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/scatterFieldAccess.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/scatterFieldAccess.hpp index b67ceb34..27c16f2a 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/scatterFieldAccess.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/scatterFieldAccess.hpp @@ -9,14 +9,18 @@ namespace pFlow { -template +template class scatterFieldAccess { public: - using execution_space = ExecutionSpace; + using viewType = ViewType1D; - using memory_space = typename execution_space::memory_space; + using device_type = typename viewType::device_type; + + using memory_space = typename viewType::memory_space; + + using execution_space = typename viewType::execution_space; protected: @@ -24,12 +28,17 @@ protected: ViewType1D indices_; - ViewType1D fieldVals_; + viewType fieldVals_; public: + scatterFieldAccess(): + indices_(), + fieldVals_() + {} + scatterFieldAccess( - uint32 sz + uint32 sz, ViewType1D ind, ViewType1D fVals) : @@ -50,31 +59,37 @@ public: // - Methods + INLINE_FUNCTION_HD T& operator()(uint32 i) { return fieldVals_(indices_(i)); } + INLINE_FUNCTION_HD const T& operator()(uint32 i)const { return fieldVals_(indices_(i)); } + INLINE_FUNCTION_HD T& operator[](uint32 i) { return fieldVals_(indices_(i)); } + INLINE_FUNCTION_HD const T& operator[](uint32 i)const { return fieldVals_(indices_(i)); } + INLINE_FUNCTION_HD uint32 size()const { return size_; } + INLINE_FUNCTION_HD bool empty()const { return size_ == 0; diff --git a/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp b/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp index cd25a6b2..4914ddbc 100644 --- a/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp +++ b/src/phasicFlow/structuredData/pointStructure/boundaryList.cpp @@ -27,9 +27,9 @@ pFlow::boundaryList::boundaryList internalPoints& internal ) : + ListPtr(simD.sizeOfBoundaries()), simDomain_(simD), - internal_(internal), - boundaryList_(simD.sizeOfBoundaries()) + internal_(internal) {} bool pFlow::boundaryList::updateLists() @@ -37,7 +37,7 @@ bool pFlow::boundaryList::updateLists() for(auto i=0; iset ( i, boundaryBase::create diff --git a/src/phasicFlow/structuredData/pointStructure/boundaryList.hpp b/src/phasicFlow/structuredData/pointStructure/boundaryList.hpp index cb52807f..7a7a5f16 100644 --- a/src/phasicFlow/structuredData/pointStructure/boundaryList.hpp +++ b/src/phasicFlow/structuredData/pointStructure/boundaryList.hpp @@ -33,6 +33,8 @@ namespace pFlow class simulationDomain; class boundaryList +: + public ListPtr { protected: @@ -42,8 +44,6 @@ protected: const simulationDomain& simDomain_; - ListPtr boundaryList_; - bool listSet_ = false; @@ -65,6 +65,16 @@ public: ~boundaryList() = default; bool updateLists(); + + 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 d797993c..96b763e6 100644 --- a/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp +++ b/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp @@ -187,6 +187,12 @@ const pFlow::internalPoints::pFlagTypeHost& return pFlagsH_; } +FUNCTION_H +pFlow::realx3Field_D &pFlow::internalPoints::pointPosition() +{ + return pointPosition_; +} + FUNCTION_H void pFlow::internalPoints::updateFlag ( diff --git a/src/phasicFlow/structuredData/pointStructure/internalPoints.hpp b/src/phasicFlow/structuredData/pointStructure/internalPoints.hpp index 095bdff1..743653ad 100644 --- a/src/phasicFlow/structuredData/pointStructure/internalPoints.hpp +++ b/src/phasicFlow/structuredData/pointStructure/internalPoints.hpp @@ -117,7 +117,8 @@ public: FUNCTION_H const realx3Field_D& pointPosition()const; - + FUNCTION_H + realx3Field_D& pointPosition(); /*INLINE_FUNCTION_H auto pointPositionHostAll() diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp index a2d4b690..30e2e187 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp @@ -23,23 +23,6 @@ Licence: #include "streams.hpp" -pFlow::pointStructure::pointStructure -( - const dictionary& domainDict -) -: - internalPoints(), - simulationDomain_ - ( - simulationDomain::create(domainDict) - ), - boundaries_ - ( - simulationDomain_(), - *this - ) -{} - bool pFlow::pointStructure::distributePoints ( const realx3Vector &points @@ -85,15 +68,36 @@ bool pFlow::pointStructure::distributePoints } +pFlow::pointStructure::pointStructure +( + systemControl& control +) +: + demComponent("particlesCM", control), + internalPoints(), + simulationDomain_ + ( + simulationDomain::create(control.domainDict()) + ), + boundaries_ + ( + simulationDomain_(), + *this + ) +{} + + pFlow::pointStructure::pointStructure( - const dictionary &domainDict, + systemControl& control, const realx3Vector &posVec) - : internalPoints(), - simulationDomain_( - simulationDomain::create(domainDict)), - boundaries_( - simulationDomain_(), - *this) +: + demComponent("particlesCM", control), + internalPoints(), + simulationDomain_( + simulationDomain::create(control.domainDict())), + boundaries_( + simulationDomain_(), + *this) { if(!simulationDomain_->updateDomains(posVec) ) { @@ -113,12 +117,24 @@ pFlow::pointStructure::pointStructure( } -FUNCTION_H -bool pFlow::pointStructure::read -( - iIstream& is, - IOPattern::IOType iotype -) +bool pFlow::pointStructure::beforeIteration() +{ + return true; +} + +bool pFlow::pointStructure::iterate() +{ + return true; +} + +bool pFlow::pointStructure::afterIteration() +{ + return true; +} + +bool pFlow::pointStructure::read( + iIstream &is, + IOPattern::IOType iotype) { Field> fRead("file_internalPoints", "internalPoints"); diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure.hpp b/src/phasicFlow/structuredData/pointStructure/pointStructure.hpp index e66a3b61..b29fd705 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure.hpp @@ -17,25 +17,23 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - - #ifndef __pointStructure_hpp__ #define __pointStructure_hpp__ +#include "demComponent.hpp" #include "internalPoints.hpp" #include "simulationDomain.hpp" #include "boundaryList.hpp" -#include "uniquePtr.hpp" + namespace pFlow { -class simulationDomain; - class pointStructure : + public demComponent, public internalPoints { protected: @@ -57,15 +55,12 @@ public: //// - Constructors - // - an empty pointStructure, good for reading from file - pointStructure(const dictionary& domainDict); - - // - construct from components - //pointStructure(const int8Vector& flgVec, const realx3Vector& posVec); + /// an empty pointStructure, good for reading from file + pointStructure(systemControl& control); /// construct from point positions, assume all points are active pointStructure( - const dictionary& domainDict, + systemControl& control, const realx3Vector& posVec); // - copy construct @@ -88,9 +83,47 @@ public: // - destructor virtual ~pointStructure() = default; - - /// Read + // - Iteration methods + + /// In the time loop before iterate + bool beforeIteration() override; + + /// @brief This is called in time loop. Perform the main calculations + /// when the component should evolve along time. + bool iterate() override; + + /// This is called in time loop, after iterate. + bool afterIteration() override; + + // - Access methods + + auto& boundaries() + { + return boundaries_; + } + + const auto& boundaries()const + { + return boundaries_; + } + + auto& boundary(size_t i ) + { + return boundaries_[i]; + } + + auto& boundary(size_t i)const + { + return boundaries_[i]; + } + + // - IO methods + + /// @brief read the point structure from the input stream. + /// @param is: input stream + /// @param iotype: type of input pattern + /// @return true on success FUNCTION_H bool read(iIstream& is, IOPattern::IOType iotype); diff --git a/utilities/particlesPhasicFlow/CMakeLists.txt b/utilities/particlesPhasicFlow/CMakeLists.txt index 4a46570a..c6766d21 100644 --- a/utilities/particlesPhasicFlow/CMakeLists.txt +++ b/utilities/particlesPhasicFlow/CMakeLists.txt @@ -3,7 +3,7 @@ set(source_files particlesPhasicFlow.cpp positionParticles/positionParticles.cpp positionOrdered/positionOrdered.cpp -positionRandom/positionRandom.cpp +#positionRandom/positionRandom.cpp empty/empty.cpp ) set(link_lib phasicFlow Kokkos::kokkos Interaction Utilities) diff --git a/utilities/particlesPhasicFlow/empty/empty.cpp b/utilities/particlesPhasicFlow/empty/empty.cpp index 71bd478a..5ed799a2 100755 --- a/utilities/particlesPhasicFlow/empty/empty.cpp +++ b/utilities/particlesPhasicFlow/empty/empty.cpp @@ -30,7 +30,7 @@ pFlow::empty::empty( positionParticles(control, dict), position_ ( - maxNumberOfParticles_, 0, RESERVE() + "empty",maxNumberOfParticles_, 0, RESERVE() ) { } \ No newline at end of file diff --git a/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp b/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp index 173f09ce..a7102840 100755 --- a/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp +++ b/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp @@ -24,6 +24,8 @@ Licence: #include "setFields.hpp" #include "systemControl.hpp" #include "commandLine.hpp" +#include "vocabs.hpp" + //#include "readControlDict.hpp" using pFlow::output; @@ -74,7 +76,7 @@ int main( int argc, char* argv[] ) if(setOnly && positionOnly) { ERR<< - "Options --positionParticles-only and --setFields-only cannot be used simeltanuously. \n"<("numPoints") + poDict_.getVal("numPoints") ), axisOrder_ ( @@ -146,7 +146,7 @@ pFlow::positionOrdered::positionOrdered ), position_ ( - maxNumberOfParticles_, RESERVE() + "positionOrdered", maxNumberOfParticles_, numPoints_ ,RESERVE() ) { diff --git a/utilities/particlesPhasicFlow/positionOrdered/positionOrdered.hpp b/utilities/particlesPhasicFlow/positionOrdered/positionOrdered.hpp index aa5a3881..5d18ae57 100755 --- a/utilities/particlesPhasicFlow/positionOrdered/positionOrdered.hpp +++ b/utilities/particlesPhasicFlow/positionOrdered/positionOrdered.hpp @@ -76,12 +76,12 @@ public: //// - Methods - virtual label numPoints()const + virtual uint64 numPoints()const { return position_.size(); } - virtual label size()const + virtual uint64 size()const { return position_.size(); } diff --git a/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp b/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp index 632fceb7..ecd4e670 100755 --- a/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp +++ b/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp @@ -54,7 +54,7 @@ pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& pos ind++}); } - INFORMATION<<"Performing morton sorting."< - pFlow::positionParticles::create(const dictionary & dict) + pFlow::positionParticles::create +( + systemControl& control, + const dictionary & dict +) { word method = dict.getVal("method"); diff --git a/utilities/particlesPhasicFlow/positionParticles/positionParticles.hpp b/utilities/particlesPhasicFlow/positionParticles/positionParticles.hpp index 37053a52..0cde29fb 100755 --- a/utilities/particlesPhasicFlow/positionParticles/positionParticles.hpp +++ b/utilities/particlesPhasicFlow/positionParticles/positionParticles.hpp @@ -127,8 +127,8 @@ public: ( positionParticles, dictionary, - (const dictionary& dict), - (dict) + (systemControl& control, const dictionary& dict), + (control, dict) ); virtual ~positionParticles() = default; @@ -151,7 +151,7 @@ public: virtual realx3Vector getFinalPosition(); static - uniquePtr create(const dictionary & dict); + uniquePtr create(systemControl& control, const dictionary & dict); };