code refactor upto pointFields and insertion etc.

This commit is contained in:
Hamidreza Norouzi 2024-01-25 03:10:44 -08:00
parent 8dc8009311
commit ab6308bb0a
47 changed files with 814 additions and 476 deletions

View File

@ -56,18 +56,14 @@ containers/Field/Fields.cpp
containers/List/anyList/anyList.cpp
containers/pointField/pointFields.cpp
#setFieldList/setFieldList.cpp
#setFieldList/setFieldEntry.cpp
setFieldList/setFieldList.cpp
setFieldList/setFieldEntry.cpp
Timer/Timer.cpp
Timer/Timers.cpp
structuredData/box/box.cpp
structuredData/line/line.cpp
structuredData/infinitePlane/infinitePlane.cpp
@ -81,6 +77,10 @@ structuredData/boundaries/boundaryBase/boundaryBase.cpp
structuredData/boundaries/boundaryExit/boundaryExit.cpp
structuredData/boundaries/boundaryNone/boundaryNone.cpp
structuredData/pointStructure/boundaryList.cpp
structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp
structuredData/pointStructure/selectors/selectBox/selectBox.cpp
structuredData/pointStructure/selectors/selectRange/selectRange.cpp
structuredData/pointStructure/selectors/selectRandom/selectRandom.cpp
commandLine/commandLine.cpp

View File

@ -158,20 +158,6 @@ public:
/// Move assignment
FieldType& operator = (FieldType&&) = default;
/// clone as a uniquePtr
INLINE_FUNCTION_H
uniquePtr<FieldType> clone() const
{
return makeUnique<FieldType>(*this);
}
/// clone as a raw pointer
INLINE_FUNCTION_H
FieldType* clonePtr()const
{
return new FieldType(*this);
}
//// - Methods
/// return field key
@ -184,7 +170,13 @@ public:
{
return VectorType::name();
}
void fillField(rangeU32 span, const T& val)
{
this->fill(span, val);
}
//// - IO operations
bool read(iIstream& is);

View File

@ -39,8 +39,12 @@ class ListPtr
public:
using ListPtrType = ListPtr<T> ;
using listType = std::list<T*>;
using iterator = typename listType::iterator;
using const_iterator = typename listType::const_iterator;
template<typename... Args>
inline static uniquePtr<T> makeSafe(Args&&... args)
@ -183,7 +187,25 @@ public:
// - clear the ith element
void clear(size_t i);
// - clone the object
iterator begin()
{
return list_.begin();
}
const_iterator begin()const
{
return list_.begin();
}
iterator end()
{
return list_.end();
}
const_iterator end()const
{
return list_.end();
}
};

View File

@ -23,6 +23,8 @@ Licence:
#include <set>
#include "types.hpp"
namespace pFlow
{
@ -30,6 +32,9 @@ namespace pFlow
template<typename Key>
using Set = std::set<Key,std::less<Key>,std::allocator<Key>>;
using wordSet = Set<word>;
}
#endif

View File

@ -351,6 +351,17 @@ void pFlow::VectorSingle<T,MemorySpace>::fill(const T& val)
pFlow::fill(view_, rangeU32(0 ,size_) ,val);
}
template<typename T, typename MemorySpace>
INLINE_FUNCTION_H
void pFlow::VectorSingle<T,MemorySpace>::fill
(
rangeU32 r,
const T& val
)
{
pFlow::fill(view_, r, val);
}
template<typename T, typename MemorySpace>
INLINE_FUNCTION_H
void pFlow::VectorSingle<T,MemorySpace>::assign
@ -494,7 +505,7 @@ bool pFlow::VectorSingle<T,MemorySpace>::insertSetElement
)
{
if(indices.size() == 0)return true;
if(indices.empty())return true;
if(indices.size() != vals.size())return false;
auto maxInd = indices.max();
@ -518,9 +529,7 @@ bool pFlow::VectorSingle<T,MemorySpace>::insertSetElement
Kokkos::parallel_for(
"VectorSingle::insertSetElement",
policy(0,indices.size()), LAMBDA_HD(int32 i){
dVec(ind(i))= dVals(i);}
);
dVec(ind(i))= dVals(i);});
Kokkos::fence();
}
@ -532,9 +541,7 @@ bool pFlow::VectorSingle<T,MemorySpace>::insertSetElement
Kokkos::parallel_for(
"VectorSingle::insertSetElement",
policy(0,indices.size()), LAMBDA_HD(int32 i){
dVec(ind(i))= hVals(i);}
);
dVec(ind(i))= hVals(i);});
Kokkos::fence();
}
@ -542,6 +549,57 @@ bool pFlow::VectorSingle<T,MemorySpace>::insertSetElement
return true;
}
template<typename T, typename MemorySpace>
INLINE_FUNCTION_H
bool pFlow::VectorSingle<T,MemorySpace>::insertSetElement
(
uint32IndexContainer indices,
const ViewType1D<T, memory_space> vals
)
{
if(indices.empty())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<
execution_space,
Kokkos::IndexType<uint32>>;
if constexpr( isDeviceAccessible_ )
{
auto dVec = view_;
auto dVals = vals;
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 hVals = vals;
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<typename T, typename MemorySpace>
INLINE_FUNCTION_H

View File

@ -256,6 +256,9 @@ public:
/// Fill the range [0,size) with val
INLINE_FUNCTION_H
void fill(const T& val);
INLINE_FUNCTION_H
void fill(rangeU32 r, const T& val);
/// Change size of the vector and assign val to vector and
INLINE_FUNCTION_H
@ -291,6 +294,11 @@ public:
INLINE_FUNCTION_H
bool insertSetElement(uint32IndexContainer indices, const std::vector<T>& vals);
INLINE_FUNCTION_H
bool insertSetElement(
uint32IndexContainer indices,
const ViewType1D<T, memory_space> vals);
INLINE_FUNCTION_H
bool reorderItems(uint32IndexContainer indices);

View File

@ -21,8 +21,6 @@ Licence:
#define __VectorSingleMath_hpp__
namespace pFlow
{
@ -51,8 +49,6 @@ INLINE_FUNCTION_H T max( const VectorSingle<T, MemorySpace>& vec)
);
}
}

View File

@ -25,7 +25,7 @@ pFlow::boundaryField<T, MemorySpace>::boundaryField
InternalFieldType& internal
)
:
observer(),
observer(&boundary, defaultMessage_),
boundary_(boundary),
internal_(internal)
{}

View File

@ -49,6 +49,15 @@ protected:
/// @brief a ref to the internal field
InternalFieldType& internal_;
static inline
const message defaultMessage_ =
(
message::CAP_CHANGED+
message::SIZE_CHANGED+
message::ITEM_INSERT+
message::ITEM_DELETE
);
public:
TypeInfo("boundaryField<none>");
@ -79,6 +88,9 @@ public:
bool hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
) override
@ -97,6 +109,12 @@ public:
return boundary_.capacity();
}
virtual
void fill(const T& val)
{
return ;
}
static
uniquePtr<boundaryField> create(
const boundaryBase& boundary,

View File

@ -60,6 +60,14 @@ public:
}
}
void fill(const T& val)
{
for(auto& bf: *this)
{
bf->fill(val);
}
}
};
}

View File

@ -63,6 +63,9 @@ public:
bool hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
) override

View File

@ -64,7 +64,7 @@ pFlow::internalField<T, MemorySpace>::internalField
),
internalPoints_(internal)
{
field_.fill(val);
fillInternal(val);
}

View File

@ -139,7 +139,26 @@ public:
return internalPoints_.isAllActive();
}
bool hearChanges(const message& msg, const anyList& varList) override
inline
void fillInternal(const T& val)
{
field_.fillField(activeRange(), val);
}
inline
bool insertSetElement(uint32IndexContainer indices, const T& val)
{
return field_.insertSetElement(indices, val);
}
bool hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
) override
{
notImplementedFunction;
return false;
@ -171,5 +190,6 @@ iOstream& operator<<
} // pFlow
#include "internalField.cpp"
#include "internalFieldAlgorithms.hpp"
#endif // __internalField_hpp__

View File

@ -0,0 +1,205 @@
/*------------------------------- 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 __internalFieldAlgorithms_hpp__
#define __internalFieldAlgorithms_hpp__
namespace pFlow
{
template<class T, class MemorySpace>
inline
T min(const internalField<T,MemorySpace>& iField)
{
using exeSpace = typename internalField<T,MemorySpace>::execution_space;
using policy = Kokkos::RangePolicy<
exeSpace,
Kokkos::IndexType<uint32> >;
if constexpr(isDeviceAccessible<exeSpace>())
{
// this is a device view
auto maskD = iField.activePointsMaskDevice();
auto aRange = maskD.activeRange();
auto filed = iField.field().deviceVectorAll();
T minElement;
Kokkos::parallel_reduce(
"min(internalField)",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i, T& minUpdate)
{
if( maskD(i) )
if(filed[i] < minUpdate) minUpdate = filed[i];
},
Kokkos::Min<T>(minElement));
return minElement;
}
else
{
// this is a host view
auto maskH = iField.activePointsMaskHost();
auto aRange = maskH.activeRange();
auto filed = iField.field().deviceVectorAll();
T minElement;
Kokkos::parallel_reduce(
"min(internalField)",
policy(aRange.start(), aRange.end()),
LAMBDA_HD(uint32 i, T& minUpdate)
{
if( maskH(i) )
if(filed[i] < minUpdate) minUpdate = filed[i];
},
Kokkos::Min<T>(minElement));
return minElement;
}
}
template<class T, class MemorySpace>
inline
T max(const internalField<T,MemorySpace>& iField)
{
using exeSpace = typename internalField<T,MemorySpace>::execution_space;
using policy = Kokkos::RangePolicy<
exeSpace,
Kokkos::IndexType<uint32> >;
if constexpr(isDeviceAccessible<exeSpace>())
{
// this is a device view
auto maskD = iField.activePointsMaskDevice();
auto aRange = maskD.activeRange();
auto filed = iField.field().deviceVectorAll();
T maxElement;
Kokkos::parallel_reduce(
"max(internalField)",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i, T& maxUpdate)
{
if( maskD(i) )
if( maxUpdate <filed[i]) maxUpdate = filed[i];
},
Kokkos::Max<T>(maxElement));
return maxElement;
}
else
{
// this is a host view
auto maskH = iField.activePointsMaskHost();
auto aRange = maskH.activeRange();
auto filed = iField.field().deviceVectorAll();
T maxElement;
Kokkos::parallel_reduce(
"max(internalField)",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i, T& maxUpdate)
{
if( maskH(i) )
if( maxUpdate <filed[i]) maxUpdate = filed[i];
},
Kokkos::Max<T>(maxElement));
return maxElement;
}
}
template<class T, class MemorySpace>
inline
Pair<T,T> minMax(const internalField<T,MemorySpace>& iField)
{
using exeSpace = typename internalField<T,MemorySpace>::execution_space;
using policy = Kokkos::RangePolicy<
exeSpace,
Kokkos::IndexType<uint32> >;
if constexpr(isDeviceAccessible<exeSpace>())
{
// this is a device view
auto maskD = iField.activePointsMaskDevice();
auto aRange = maskD.activeRange();
auto filed = iField.field().deviceVectorAll();
T minElement;
T maxElement;
Kokkos::parallel_reduce(
"minMax(internalField)",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i, T& minUpdate, T& maxUpdate)
{
if( maskD(i) )
{
if(maxUpdate < filed[i]) maxUpdate = filed[i];
if(filed[i] < minUpdate) minUpdate = filed[i];
}
},
Kokkos::Min<T>(minElement),
Kokkos::Max<T>(maxElement)
);
return {minElement, maxElement};
}
else
{
// this is a host view
auto maskH = iField.activePointsMaskHost();
auto aRange = maskH.activeRange();
auto filed = iField.field().deviceVectorAll();
T minElement;
T maxElement;
Kokkos::parallel_reduce(
"minMax(internalField)",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i, T& minUpdate, T& maxUpdate)
{
if( maskH(i) )
{
if(maxUpdate < filed[i]) maxUpdate = filed[i];
if(filed[i] < minUpdate) minUpdate = filed[i];
}
},
Kokkos::Min<T>(minElement),
Kokkos::Max<T>(maxElement)
);
return {minElement, maxElement};
}
}
}
#endif

View File

@ -93,77 +93,26 @@ public:
const T& defVal,
const T& val);
//// - Methods
const auto& internal()const
{
return static_cast<const InternalFieldType&>(*this);
}
// - 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<pointFieldType> clone() const
{
return makeUnique<pointFieldType>(*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
void fill(const T& val)
{
return pStruct_.pointFlag();
InternalFieldType::fillInternal(val);
boundaryFieldList_.fill(val);
}
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, const IOPattern& iop);

View File

@ -31,6 +31,31 @@ template class pFlow::pointField<pFlow::int8>;
createBaseBoundary(pFlow::int8, void);
createBoundary(pFlow::int8, void, exit);
template class pFlow::pointField<pFlow::uint8, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint8, pFlow::HostSpace);
createBoundary(pFlow::uint8, pFlow::HostSpace, exit);
template class pFlow::pointField<pFlow::uint8>;
createBaseBoundary(pFlow::uint8, void);
createBoundary(pFlow::uint8, void, exit);
template class pFlow::pointField<pFlow::int32, pFlow::HostSpace>;
createBaseBoundary(pFlow::int32, pFlow::HostSpace);
createBoundary(pFlow::int32, pFlow::HostSpace, exit);
template class pFlow::pointField<pFlow::int32>;
createBaseBoundary(pFlow::int32, void);
createBoundary(pFlow::int32, void, exit);
template class pFlow::pointField<pFlow::uint32, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint32, pFlow::HostSpace);
createBoundary(pFlow::uint32, pFlow::HostSpace, exit);
template class pFlow::pointField<pFlow::uint32>;
createBaseBoundary(pFlow::uint32, void);
createBoundary(pFlow::uint32, void, exit);
template class pFlow::pointField<pFlow::real, pFlow::HostSpace>;
createBaseBoundary(pFlow::real, pFlow::HostSpace);
createBoundary(pFlow::real, pFlow::HostSpace, exit);
@ -40,36 +65,25 @@ template class pFlow::pointField<pFlow::real>;
createBaseBoundary(pFlow::real, void);
createBoundary(pFlow::real, void, exit);
/*template class pFlow::pointField<pFlow::VectorSingle, pFlow::int8, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int16>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int16, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int32>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int32, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int64>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::int64, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::uint32>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::uint32, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::label>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::label, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::real>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::real, pFlow::HostSpace>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::realx3>;
template class pFlow::pointField<pFlow::VectorSingle, pFlow::realx3, pFlow::HostSpace>;*/
template class pFlow::pointField<pFlow::realx3, pFlow::HostSpace>;
createBaseBoundary(pFlow::realx3, pFlow::HostSpace);
createBoundary(pFlow::realx3, pFlow::HostSpace, exit);
template class pFlow::pointField<pFlow::realx3>;
createBaseBoundary(pFlow::realx3, void);
createBoundary(pFlow::realx3, void, exit);
template class pFlow::pointField<pFlow::realx4, pFlow::HostSpace>;
createBaseBoundary(pFlow::realx4, pFlow::HostSpace);
createBoundary(pFlow::realx4, pFlow::HostSpace, exit);
template class pFlow::pointField<pFlow::realx4>;
createBaseBoundary(pFlow::realx4, void);
createBoundary(pFlow::realx4, void, exit);
template class pFlow::pointField<pFlow::word, pFlow::HostSpace>;
createBaseBoundary(pFlow::word, pFlow::HostSpace);
createBoundary(pFlow::word, pFlow::HostSpace, exit);

View File

@ -49,14 +49,11 @@ using uint32PointField_D = pointField_D<uint32>;
using uint32PointField_H = pointField_H<uint32>;
using int64PointField_D = pointField_D<int64>;
using int63PointField_H = pointField_H<int64>;
using int64PointField_H = pointField_H<int64>;
using uint64PointField_D = pointField_D<uint64>;
using uint64PointField_H = pointField_H<uint64>;
using int32PointField_D = pointField_D<int32>;
using int32PointField_H = pointField_H<int32>;
using realPointField_D = pointField_D<real>;
using realPointField_H = pointField_H<real>;
@ -66,9 +63,7 @@ using realx3PointField_H = pointField_H<realx3>;
using realx4PointField_D = pointField_D<realx4>;
using realx4PointField_H = pointField_H<realx4>;
using wordPointField_H = pointField_H<word>;
}

View File

@ -24,10 +24,10 @@ Licence:
pFlow::demComponent::demComponent(const word& name, systemControl& control)
:
componentName_(name),
control_(control),
time_(control.time()),
timers_(name, &control.timers())
timers_(name, &control.timers()),
componentName_(name)
{}
pFlow::real pFlow::demComponent::dt()const
@ -37,5 +37,10 @@ pFlow::real pFlow::demComponent::dt()const
pFlow::real pFlow::demComponent::currentTime()const
{
return time_.currentTime();
return time_.currentTime();
}
pFlow::uint32 pFlow::demComponent::currentIter() const
{
return time_.currentIter();
}

View File

@ -40,13 +40,9 @@ class Time;
*/
class demComponent
{
protected:
// - Protected data members
/// Name of the DEM component
word componentName_;
private:
// - Protected data members
/// Reference to systemControl
systemControl& control_;
@ -55,6 +51,9 @@ protected:
/// All timers (if any) of this component
Timers timers_;
/// Name of the DEM component
word componentName_;
public:
/// Type info
@ -102,6 +101,8 @@ public:
/// Current simulation time
real currentTime()const;
uint32 currentIter()const;
inline
const auto& time()const
@ -134,7 +135,7 @@ public:
virtual
bool beforeTimeLoop()
{
notImplementedFunction
notImplementedFunction;
return false;
}
@ -155,7 +156,7 @@ public:
virtual
bool afterTimeLoop()
{
notImplementedFunction
notImplementedFunction;
return false;
}

View File

@ -107,11 +107,7 @@ 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:
@ -122,7 +118,12 @@ public:
TypeInfo("dictionary");
//// - Constructors
/// 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);
/// cunstructs a null dictionary
dictionary();

View File

@ -21,8 +21,9 @@ Licence:
#include "observer.hpp"
#include "subscriber.hpp"
pFlow::observer::observer():
subscriber_(nullptr)
pFlow::observer::observer(message msg):
subscriber_(nullptr),
message_(msg)
{}
pFlow::observer::observer
@ -30,30 +31,47 @@ pFlow::observer::observer
const subscriber* subscrbr,
message msg
)
:
subscriber_(subscrbr),
message_(msg)
{
addToSubscriber(subscrbr, msg);
}
pFlow::observer::~observer()
{
if(subscriber_)
subscriber_->unsubscribe(this);
invalidateSubscriber();
}
void pFlow::observer::addToSubscriber
(
const subscriber* subscrbr,
message msg
)
{
if(subscriber_)
subscriber_->unsubscribe(this);
invalidateSubscriber();
subscriber_ = subscrbr;
message_ = msg;
if(subscriber_)
{
if(!subscriber_->subscribe(msg, this))
if(!subscriber_->subscribe(message_, this))
{
fatalErrorInFunction<<
"error in subscribing an observer"<<endl;
fatalExit;
}
}
}
pFlow::observer::~observer()
{
if( subscriber_)
subscriber_->unsubscribe(this);
invalidateSubscriber();
}
}
bool pFlow::observer::addToSubscriber(const subscriber& subscrbr)
{
if(subscriber_)
subscriber_->unsubscribe(this);
invalidateSubscriber();
subscriber_ = &subscrbr;
return subscriber_->subscribe(message_, this);
}

View File

@ -39,12 +39,12 @@ protected:
const subscriber* subscriber_ = nullptr;
/// list of events in the message
const message message_;
message message_;
public:
observer();
observer(message msg);
observer(
const subscriber* subscrbr,
@ -53,12 +53,20 @@ public:
virtual
~observer();
void subscribe(
const subscriber* subscrbr,
message msg);
inline
bool subscribed()const
{
return subscriber_!=nullptr;
}
void addToSubscriber(
const subscriber* subscrbr,
message msg);
bool addToSubscriber(const subscriber& subscriber);
inline void invalidateSubscriber()
@ -72,7 +80,12 @@ public:
return message::numEvents();
}
virtual bool hearChanges(const message& msg, const anyList& varList)=0;
virtual bool hearChanges(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList)=0;
};
} // pFlow

View File

@ -82,6 +82,9 @@ bool pFlow::subscriber::unsubscribe
bool pFlow::subscriber::notify
(
real t,
real dt,
uint32 iter,
const message msg,
const anyList& varList
)
@ -93,7 +96,14 @@ bool pFlow::subscriber::notify
{
for( auto obsvr: observerList_[i] )
{
obsvr->hearChanges(message(i), varList);
obsvr->hearChanges
(
t,
dt,
iter,
message(i),
varList
);
}
}
}

View File

@ -69,7 +69,12 @@ public:
bool notify(const message msg, const anyList& varList);
bool notify(
real t,
real dt,
uint32 iter,
const message msg,
const anyList& varList);
};

View File

@ -62,7 +62,7 @@ pFlow::iOstream& reportAndExit(int errorCode = EXIT_FAILURE);
notImplementedErrorMessage ((functionName), __FILE__, __LINE__ )
/// Report that a function is yet not implemented.
#define notImplementedFunction Not_Implemented(FUNCTION_NAME);
#define notImplementedFunction Not_Implemented(FUNCTION_NAME)
/// Report an error in file operation with supplied fileName and lineNumber.
#define ioErrorInFile( fileName, lineNumber) \

View File

@ -37,9 +37,9 @@ const inline char* integrationFolder__ = "integration";
// file names
const inline char* settingsFile__ = "settingsDict";
const inline char* domainFile__ = "domainDict";
const inline char* domainFile__ = "domainDict";
const inline char* insertionFile__ = "particleInsertion";
const inline char* sphereShapeFile__ = "sphereShape";
const inline char* shapeFile__ = "shapes";
const inline char* pointStructureFile__ = "pStructure";
const inline char* triSurfaceFile__ = "triSurface";
const inline char* createParticles__ = "createParticles";

View File

@ -18,8 +18,8 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __uniformRandomInt32_hpp__
#define __uniformRandomInt32_hpp__
#ifndef __uniformRandomUint32_hpp__
#define __uniformRandomUint32_hpp__
#include <random>
@ -29,35 +29,35 @@ Licence:
namespace pFlow
{
class uniformRandomInt32
class uniformRandomUint32
{
protected:
std::mt19937_64 engineGen_;
std::uniform_int_distribution<int32> distrbution_;
std::uniform_int_distribution<uint32> distrbution_;
public:
// type info
TypeInfoNV("uniform");
explicit uniformRandomInt32(int32 min, int32 max)
explicit uniformRandomUint32(uint32 min, uint32 max)
:
engineGen_(std::random_device()()),
distrbution_(min, max)
{}
~uniformRandomInt32()= default;
~uniformRandomUint32()= default;
inline real randomNumber()
inline uint32 randomNumber()
{
return distrbution_(engineGen_);
}
inline int32x3 randomNumber3()
inline triple<uint32> randomNumber3()
{
return int32x3
return triple<uint32>
(
randomNumber(),
randomNumber(),
@ -65,9 +65,9 @@ public:
);
}
inline realx3 operator()()
inline triple<uint32> operator()()
{
return randomNumber();
return randomNumber3();
}

View File

@ -116,6 +116,8 @@ bool pFlow::IOfileHeader::implyRead() const
bool pFlow::IOfileHeader::implyWrite() const
{
if( isExcluded( name() ) ) return false;
if( isIncluded( name() ) ) return true;
return isWriteAlways();
}

View File

@ -81,6 +81,18 @@ public:
{
return nullptr;
}
virtual
bool isIncluded(const word& objName)const
{
return false;
}
virtual
bool isExcluded(const word& objName)const
{
return false;
}
// - path to file name
fileSystem path() const;

View File

@ -62,6 +62,21 @@ pFlow::repository* pFlow::IOobject::releaseOwner
return old;
}
bool pFlow::IOobject::isIncluded(const word& objName)const
{
if(owner_)
return owner_->isIncluded(objName);
return false;
}
bool pFlow::IOobject::isExcluded(const word& objName)const
{
if(owner_)
return owner_->isExcluded(objName);
return false;
}
bool pFlow::IOobject::readObject(bool rdHdr)
{
if(!implyRead())return true;

View File

@ -85,6 +85,12 @@ public:
repository* releaseOwner(bool fromOwner = false);
bool isIncluded(const word& objName)const override;
bool isExcluded(const word& objName)const override;
//// - IO operations
// - read from file

View File

@ -97,12 +97,14 @@ public:
virtual ~objectFile()=default;
virtual word name() const
virtual
const word& name() const
{
return name_;
}
virtual fileSystem localPath()const
virtual
const fileSystem& localPath()const
{
return localPath_;
}

View File

@ -283,7 +283,8 @@ bool pFlow::repository::write
{
if(verbose)
{
REPORT(1)<< "Writing to " << obj.second->path()<<END_REPORT;
if(obj.second->implyWrite())
REPORT(1)<< "Writing to " << obj.second->path()<<END_REPORT;
}
if(!obj.second->writeObject())

View File

@ -114,6 +114,23 @@ public:
bool removeFromRepository(IOobject* io);
repository* releaseOwner(bool fromOwner = false);
virtual
bool isIncluded(const word& objName)const
{
if(owner_)
return owner_->isIncluded(objName);
return false;
}
virtual
bool isExcluded(const word& objName)const
{
if(owner_)
return owner_->isExcluded(objName);
return false;
}
//// - lookups and queries
// - check if name of object exists

View File

@ -17,117 +17,7 @@ Licence:
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
/*
template<typename T, typename... Args>
T& pFlow::repository::emplaceObject(const objectFile& objf, Args&&... args)
{
if( auto [iter2, success2] = objects_.findIf(objf.name()); !success2 )
{
auto ptr = IOobject::make_object_t<T>(std::forward<Args>(args)...);
auto [iter, success] = objects_.emplace(std::piecewise_construct,
std::forward_as_tuple(objf.name()),
std::forward_as_tuple(objf, this, std::move(ptr) )
);
return iter->second.template getObject<T>();
}
else
{
fatalErrorInFunction<<
"IOobject " << objf.name() << " already exists in repository " << name() <<endl;
fatalExit;
return iter2->second.template getObject<T>();
}
}
template<typename T, typename... Args>
T& pFlow::repository::emplaceObjectOrGet(const objectFile& objf, Args&&... args)
{
if(auto [iter, success] = objects_.findIf(objf.name()); !success )
{
return emplaceObject<T>(objf, std::forward<Args>(args)... );
}
else
{
// type check
if( checkForObjectType<T>( iter->second ) )
{
return iter->second.template getObject<T>();
}
else
{
fatalErrorInFunction<<
" IOobject "<< objf.name() <<" already exist in the repository "<< name() <<
". Trying to return the existing object but there is a type mismatch. \n"<<
reportTypeError<T>( iter->second );
fatalExit;
return iter->second.template getObject<T>(); // this is never executed
}
}
}
template<typename T, typename... Args>
T& pFlow::repository::emplaceReplaceObject(const objectFile& objf, Args&&... args)
{
eraseObject(objf.name());
auto ptr = IOobject::make_object_t<T>(std::forward<Args>(args)...);
auto [iter, success] = objects_.emplace(std::piecewise_construct,
std::forward_as_tuple(objf.name()),
std::forward_as_tuple(objf, this, std::move(ptr) )
);
return iter->second.template getObject<T>();
}
template<typename T>
T& pFlow::repository::insertReplaceObject(uniquePtr<IOobject>&& ptr )
{
if( !ptr->owner() )
{
eraseObject(ptr->name());
objectFile objf( ptr() );
auto [iter, success] = objects_.emplace
(
std::piecewise_construct,
std::forward_as_tuple(ptr->name()),
std::forward_as_tuple(objf, this, std::move(ptr))
);
return iter->second.template getObject<T>();
}else
{
return ptr().getObject<T>();
}
}
template<typename T>
T& pFlow::repository::insertReplaceObject(const objectFile& objf, uniquePtr<IOobject>&& ptr )
{
if( !ptr->owner() )
{
eraseObject(objf.name());
auto [iter, success] = objects_.emplace
(
std::piecewise_construct,
std::forward_as_tuple(objf.name()),
std::forward_as_tuple(objf, this, std::move(ptr))
);
return iter->second.template getObject<T>();
}else
{
return ptr().getObject<T>();
}
}
*/
template <typename Type1>
pFlow::word pFlow::repository::reportTypeError(IOobject& object)
@ -154,15 +44,15 @@ T& pFlow::repository::lookupObject(const word& name)
if( checkType<T>(iter->second) )
{
return static_cast<T&>(iter->second);
return static_cast<T&>(*iter->second);
}else
{
fatalErrorInFunction <<
reportTypeError<T>(iter->second)<<endl;
reportTypeError<T>(*iter->second)<<endl;
fatalExit;
return static_cast<T&>(iter->second);
return static_cast<T&>(*iter->second);
}
}
@ -172,6 +62,6 @@ T& pFlow::repository::lookupObject(const word& name)
"Object with name " << name << " is not found in repository " << this->name()<<endl <<
"list of avaiable objest is \n" << objectNames();
fatalExit;
return iter->second.template getObject<T>();
return static_cast<T&>(*iter->second);
}
}

View File

@ -24,25 +24,32 @@ Licence:
#include "error.hpp"
#include "systemControl.hpp"
#include "vocabs.hpp"
#include "Lists.hpp"
/*bool pFlow::systemControl::readDomainDict()
bool pFlow::systemControl::readIncludeExclue
(
const dictionary& dict
)
{
if(!domainDict_)
{
domainDict_ = makeUnique<fileDictionary>
(
objectFile
(
domainFile__,
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
&settings()
);
}
return true;
}*/
if(dict.containsDataEntry("includeObjects"))
{
wordList incld = dict.getVal<wordList>("includeObjects");
for(auto& nm:incld)
{
includeList_.insert(nm);
}
}
if(dict.containsDataEntry("excludeObjects"))
{
wordList excld = dict.getVal<wordList>("excludeObjects");
for(auto& nm:excld)
{
excludeList_.insert(nm);
}
}
return true;
}
pFlow::word pFlow::systemControl::getRunName
(
@ -176,7 +183,7 @@ pFlow::systemControl::systemControl
),
writeToFileTimer_("Write to file", &timers_)
{
//readDomainDict();
readIncludeExclue(settingsDict_());
}
pFlow::systemControl::systemControl(
@ -250,13 +257,9 @@ pFlow::systemControl::systemControl(
),
writeToFileTimer_("Write to file", &timers_)
{
//readDomainDict();
readIncludeExclue(settingsDict_());
}
/*pFlow::fileDictionary& pFlow::systemControl::domainDict()
{
return domainDict_();
}*/
bool pFlow::systemControl::operator ++(int)
{

View File

@ -34,6 +34,7 @@ Licence:
#include "box.hpp"
#include "Timers.hpp"
#include "dynamicLinkLibs.hpp"
#include "Set.hpp"
namespace pFlow
{
@ -79,7 +80,12 @@ protected:
Timer writeToFileTimer_;
//bool readDomainDict();
wordSet includeList_;
wordSet excludeList_;
bool readIncludeExclue(const dictionary& dict);
static word getRunName( const fileSystem& path);
@ -189,6 +195,36 @@ public:
return outFilePrecision_;
}
bool isIncluded(const word& objName)const final
{
return includeList_.count(objName) == static_cast<size_t>(1);
}
bool isExcluded(const word& objName)const final
{
return excludeList_.count(objName) == static_cast<size_t>(1);
}
void clearIncludeExclude()
{
includeList_.clear();
excludeList_.clear();
}
bool addInclude(const word& objName)
{
auto [iter, success] = includeList_.insert(objName);
return success;
}
bool addExclude(const word& objName)
{
auto [ite, success] = excludeList_.insert(objName);
return success;
}
};

View File

@ -39,13 +39,15 @@ bool pFlow::setFieldEntry::checkForTypeAndValueAll()const
if(
!(
checkForTypeAndValue<int8>() ||
checkForTypeAndValue<int16>() ||
checkForTypeAndValue<uint8>() ||
checkForTypeAndValue<int32>() ||
checkForTypeAndValue<int64>() ||
checkForTypeAndValue<uint32>() ||
checkForTypeAndValue<label>() ||
checkForTypeAndValue<uint64>() ||
checkForTypeAndValue<real>() ||
checkForTypeAndValue<realx3>()
checkForTypeAndValue<realx3>() ||
checkForTypeAndValue<realx4>() ||
checkForTypeAndValue<word>()
)
)
{
@ -57,40 +59,58 @@ bool pFlow::setFieldEntry::checkForTypeAndValueAll()const
return true;
}
void* pFlow::setFieldEntry::setPointFieldDefaultValueNewAll
pFlow::uniquePtr<pFlow::IOobject>
pFlow::setFieldEntry::setPointFieldDefaultValueNewAll
(
repository& owner,
pointStructure& pStruct,
bool verbose
)
{
if( void* res = setPointFieldDefaultValueNew<int8> (owner, pStruct, verbose) ; res)
uniquePtr<IOobject> Ptr = nullptr;
if( Ptr = setPointFieldDefaultValueNew<int8>(pStruct, verbose) ; Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<int16>(owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<uint8>(pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<int32> (owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<int32> (pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<int64> (owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<int64> (pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<uint32> (owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<uint32> (pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<label>(owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<int64>(pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<real>(owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<uint64>(pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueNew<realx3>(owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<real>(pStruct, verbose); Ptr)
{
return res;
}else if(void* res = setPointFieldDefaultValueStdNew<word>(owner, pStruct, verbose); res)
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<realx3>(pStruct, verbose); Ptr)
{
return res;
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<realx4>(pStruct, verbose); Ptr)
{
return Ptr;
}
else if(Ptr = setPointFieldDefaultValueNew<word>(pStruct, verbose); Ptr)
{
return Ptr;
}else
{
fatalErrorInFunction<<
@ -100,46 +120,59 @@ void* pFlow::setFieldEntry::setPointFieldDefaultValueNewAll
}
void* pFlow::setFieldEntry::setPointFieldSelectedAll
bool pFlow::setFieldEntry::setPointFieldSelectedAll
(
repository& owner,
int32IndexContainer& selected,
uint32IndexContainer& selected,
bool verbose
)
{
if( void* res = setPointFieldSelected<int8> (owner, selected, verbose) ; res)
if( setPointFieldSelected<int8> (owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<int16>(owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<uint8>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<int32> (owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<int32>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<int64> (owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<uint32>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<uint32> (owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<int64>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<label>(owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<uint64>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<real>(owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<real>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelected<realx3>(owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<realx3>(owner, selected, verbose))
{
return res;
}else if(void* res = setPointFieldSelectedStd<word>(owner, selected, verbose); res)
return true;
}
else if( setPointFieldSelected<realx4>(owner, selected, verbose))
{
return res;
}else
return true;
}
else if( setPointFieldSelected<word>(owner, selected, verbose))
{
return true;
}
else
{
fatalErrorInFunction<<
" un-supported data type "<<entry_.firstPart() << " in setField for field " << fieldName() <<endl;
return nullptr;
return false;
}
}

View File

@ -65,48 +65,34 @@ public:
bool checkForTypeAndValueAll()const;
template <typename Type>
void* setPointFieldDefaultValueNew
uniquePtr<pointField_H<Type>>
setPointFieldDefaultValueNew
(
repository& owner,
pointStructure& pStruct,
bool verbose = false
);
template<typename Type>
void* setPointFieldDefaultValueStdNew
uniquePtr<IOobject>
setPointFieldDefaultValueNewAll
(
repository& owner,
pointStructure& pStruct,
bool verbose = false
);
void* setPointFieldDefaultValueNewAll
(
repository& owner,
pointStructure& pStruct,
bool verbose = false
);
template <typename Type>
void* setPointFieldSelected
bool setPointFieldSelected
(
repository& owner,
int32IndexContainer& selected,
uint32IndexContainer& selected,
bool verbose = false
);
template <typename Type>
void* setPointFieldSelectedStd
(
repository& owner,
int32IndexContainer& selected,
bool verbose = false
);
void* setPointFieldSelectedAll
bool setPointFieldSelectedAll
(
repository& owner,
int32IndexContainer& selected,
uint32IndexContainer& selected,
bool verbose = false
);

View File

@ -37,9 +37,9 @@ bool pFlow::setFieldEntry::checkForTypeAndValue()const
}
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldDefaultValueNew
pFlow::uniquePtr<pFlow::pointField_H<Type>>
pFlow::setFieldEntry::setPointFieldDefaultValueNew
(
repository& owner,
pointStructure& pStruct,
bool verbose
)
@ -50,13 +50,10 @@ void* pFlow::setFieldEntry::setPointFieldDefaultValueNew
Type defValue = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<<"Creating pointField " << Green_Text(fieldName())<< " with default value " << cyanText(defValue)<<
" in repository "<< owner.name() <<END_REPORT;
REPORT(2)<<"Creating pointField " << Green_Text(fieldName())<< " with default value " << Cyan_Text(defValue)<<
" in repository "<< pStruct.owner()->name() <<END_REPORT;
auto& field =
owner.emplaceObject<pointField<VectorSingle,Type>>
(
auto Ptr = makeUnique<pointField_H<Type>>(
objectFile
(
fieldName(),
@ -65,13 +62,14 @@ void* pFlow::setFieldEntry::setPointFieldDefaultValueNew
objectFile::WRITE_ALWAYS
),
pStruct,
defValue
defValue,
defValue
);
return &field;
return Ptr;
}
template <typename Type>
/*template <typename Type>
void* pFlow::setFieldEntry::setPointFieldDefaultValueStdNew
(
repository& owner,
@ -104,17 +102,17 @@ void* pFlow::setFieldEntry::setPointFieldDefaultValueStdNew
);
return &field;
}
}*/
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldSelected
bool pFlow::setFieldEntry::setPointFieldSelected
(
repository& owner,
int32IndexContainer& selected,
uint32IndexContainer& selected,
bool verbose
)
{
if( !checkForType<Type>() ) return nullptr;
if( !checkForType<Type>() ) return false;
auto fName = fieldName();
@ -123,56 +121,34 @@ void* pFlow::setFieldEntry::setPointFieldSelected
{
fatalErrorInFunction<<
"Cannot find "<< fName << " in repository " << owner.name() << ". \n";
return nullptr;
return false;
}
Type value = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<< "Setting selected points of " << Green_Text(fName)
<< " to value " << cyanText(value) <<END_REPORT;
<< " to value " << Cyan_Text(value) <<END_REPORT;
auto fieldTypeName = owner.lookupObjectTypeName(fName);
if( pointField<VectorSingle,Type>::TYPENAME() == fieldTypeName )
if( getTypeName<pointField_H<Type>>() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorSingle,Type>>(fName);
auto& field = owner.lookupObject<pointField_H<Type>>(fName);
if(field.insertSetElement(selected, value))
return &field;
return true;
else
return nullptr;
return false;
}
if( pointField<VectorSingle,Type, HostSpace>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorSingle,Type,HostSpace>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}
/*if( pointField<VectorDual,Type>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorDual,Type>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}*/
fatalErrorInFunction<<
fieldTypeName<< " is not a supported field type for setFieldEntry.\n";
return nullptr;
return false;
}
template <typename Type>
/*template <typename Type>
void* pFlow::setFieldEntry::setPointFieldSelectedStd
(
repository& owner,
@ -213,4 +189,4 @@ void* pFlow::setFieldEntry::setPointFieldSelectedStd
}
return nullptr;
}
}*/

View File

@ -210,8 +210,14 @@ template<>
inline
bool pFlow::dataIO<pFlow::word>::writeData(iOstream& os, span<word> data)
{
notImplementedFunction;
fatalExit;
if( ioPattern_.isParallel() )
{
notImplementedFunction<<
"data transfer for type word is not supported in parallel mode!"<<endl;
fatalExit;
}
/// first gather data from all processors (if any)
if(!gatherData( data ) )
{
@ -220,7 +226,14 @@ bool pFlow::dataIO<pFlow::word>::writeData(iOstream& os, span<word> data)
return false;
}
return false;
if( ioPattern_.thisProcWriteData())
{
return writeDataASCII(os, data);
}
else
{
return true;
}
}
template<typename T>

View File

@ -62,9 +62,9 @@ public:
const pointStructure& pStruct()const;
virtual const int32Vector& selectedPoinsts()const = 0;
virtual const uint32Vector& selectedPoinsts()const = 0;
virtual int32Vector& selectedPoinsts() = 0;
virtual uint32Vector& selectedPoinsts() = 0;
static

View File

@ -38,7 +38,7 @@ class selectBox
{
protected:
int32Vector selectedPoints_;
uint32Vector selectedPoints_;
box box_;
@ -63,12 +63,12 @@ public:
//// - Methods
virtual const int32Vector& selectedPoinsts()const override
virtual const uint32Vector& selectedPoinsts()const override
{
return selectedPoints_;
}
virtual int32Vector& selectedPoinsts() override
virtual uint32Vector& selectedPoinsts() override
{
return selectedPoints_;
}

View File

@ -21,31 +21,31 @@ Licence:
#include "selectRandom.hpp"
#include "dictionary.hpp"
#include "uniformRandomInt32.hpp"
#include "uniformRandomUint32.hpp"
#include "Set.hpp"
bool pFlow::selectRandom::selectAllPointsInRange()
{
// to reduct allocations
int32 maxNum = number_+1;
uint32 maxNum = number_+1;
selectedPoints_.reserve (maxNum);
selectedPoints_.clear();
uniformRandomInt32 intRand (begin_, end_);
uniformRandomUint32 intRand (begin_, end_);
int32 n = 0;
int32 iter = 0;
uint32 n = 0;
uint32 iter = 0;
bool finished = false;
Set<int32> selctedIndices;
Set<uint32> selctedIndices;
while( iter < number_*100)
{
int32 newInd = intRand.randomNumber();
uint32 newInd = intRand.randomNumber();
if( auto [it, inserted] = selctedIndices.insert(newInd); inserted )
{
@ -91,7 +91,7 @@ pFlow::selectRandom::selectRandom
),
begin_
(
dict.subDict("selectRandomInfo").getVal<int32>("begin")
dict.subDict("selectRandomInfo").getVal<uint32>("begin")
),
end_
(
@ -102,9 +102,9 @@ pFlow::selectRandom::selectRandom
dict.subDict("selectRandomInfo").getValOrSet("number", 1)
)
{
begin_ = max(begin_,1);
end_ = min(end_, static_cast<int32>(pStruct.size()));
number_ = max(number_,0);
begin_ = max(begin_,1u);
end_ = min(end_, static_cast<uint32>(pStruct.size()));
number_ = max(number_,0u);
if(end_-begin_ < number_)
{

View File

@ -37,16 +37,16 @@ class selectRandom
{
protected:
int32Vector selectedPoints_;
uint32Vector selectedPoints_;
// begin index
int32 begin_;
uint32 begin_;
// end index
int32 end_;
uint32 end_;
// stride
int32 number_;
uint32 number_;
bool selectAllPointsInRange();
@ -69,12 +69,12 @@ public:
//// - Methods
virtual const int32Vector& selectedPoinsts()const override
virtual const uint32Vector& selectedPoinsts()const override
{
return selectedPoints_;
}
virtual int32Vector& selectedPoinsts() override
virtual uint32Vector& selectedPoinsts() override
{
return selectedPoints_;
}

View File

@ -25,13 +25,13 @@ Licence:
void pFlow::selectRange::selectAllPointsInRange()
{
// to reduct allocations
int32 maxNum = (end_ - begin_)/stride_+2;
uint32 maxNum = (end_ - begin_)/stride_+2;
selectedPoints_.reserve (maxNum);
selectedPoints_.clear();
for(int32 i = begin_; i<end_; i+= stride_)
for(uint32 i = begin_; i<end_; i+= stride_)
{
selectedPoints_.push_back(i);
}
@ -49,20 +49,20 @@ pFlow::selectRange::selectRange
),
begin_
(
dict.subDict("selectRangeInfo").getVal<int32>("begin")
dict.subDict("selectRangeInfo").getVal<uint32>("begin")
),
end_
(
dict.subDict("selectRangeInfo").getValOrSet("end", pStruct.size())
dict.subDict("selectRangeInfo").getValOrSet<uint32>("end", pStruct.size())
),
stride_
(
dict.subDict("selectRangeInfo").getValOrSet("stride", 1)
dict.subDict("selectRangeInfo").getValOrSet<uint32>("stride", 1u)
)
{
begin_ = max(begin_,1);
end_ = min(end_, static_cast<int32>(pStruct.size()));
stride_ = max(stride_,1);
begin_ = max(begin_,1u);
end_ = min(end_, static_cast<uint32>(pStruct.size()));
stride_ = max(stride_,1u);
selectAllPointsInRange();
}

View File

@ -37,16 +37,16 @@ class selectRange
{
protected:
int32Vector selectedPoints_;
uint32Vector selectedPoints_;
// begin index
int32 begin_;
uint32 begin_;
// end index
int32 end_;
uint32 end_;
// stride
int32 stride_;
uint32 stride_;
void selectAllPointsInRange();
@ -69,12 +69,12 @@ public:
//// - Methods
virtual const int32Vector& selectedPoinsts()const override
virtual const uint32Vector& selectedPoinsts()const override
{
return selectedPoints_;
}
virtual int32Vector& selectedPoinsts() override
virtual uint32Vector& selectedPoinsts() override
{
return selectedPoints_;
}