diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 235f17a2..6f339f58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,7 @@ add_subdirectory(Particles) #add_subdirectory(Interaction) -#add_subdirectory(MotionModel) +add_subdirectory(MotionModel) #add_subdirectory(Geometry) diff --git a/src/MotionModel/CMakeLists.txt b/src/MotionModel/CMakeLists.txt index 9438c2ab..6f74b231 100644 --- a/src/MotionModel/CMakeLists.txt +++ b/src/MotionModel/CMakeLists.txt @@ -1,13 +1,16 @@ list(APPEND SourceFiles -entities/rotatingAxis/rotatingAxis.cpp -entities/multiRotatingAxis/multiRotatingAxis.cpp entities/timeInterval/timeInterval.cpp -entities/vibrating/vibrating.cpp -fixedWall/fixedWall.cpp +entities/rotatingAxis/rotatingAxis.cpp rotatingAxisMotion/rotatingAxisMotion.cpp -multiRotatingAxisMotion/multiRotatingAxisMotion.cpp + + +entities/vibrating/vibrating.cpp vibratingMotion/vibratingMotion.cpp +#fixedWall/fixedWall.cpp +#entities/multiRotatingAxis/multiRotatingAxis.cpp +#multiRotatingAxisMotion/multiRotatingAxisMotion.cpp + ) set(link_libs Kokkos::kokkos phasicFlow) diff --git a/src/MotionModel/MotionModel/MotionModel.cpp b/src/MotionModel/MotionModel/MotionModel.cpp new file mode 100644 index 00000000..6a530eaa --- /dev/null +++ b/src/MotionModel/MotionModel/MotionModel.cpp @@ -0,0 +1,147 @@ +/*------------------------------- 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 +bool pFlow::MotionModel::impl_nameToIndex(const word& name, uint32& indx)const +{ + if( auto i = componentNames_.findi(name); i == -1) + { + return false; + } + else + { + indx = static_cast(i); + return true; + } + +} + +template +inline +bool pFlow::MotionModel::impl_indexToName(uint32 i, word& name)const +{ + if(i < numComponents_ ) + { + name = componentNames_[i]; + return true; + } + else + { + return false; + } +} + +template +inline +bool pFlow::MotionModel::impl_readDictionary +( + const dictionary& dict +) +{ + + auto modelName = dict.getVal("motionModel"); + + if(modelName != getTypeName()) + { + fatalErrorInFunction<< + " motionModel should be "<< Yellow_Text(getTypeName())<< + ", but found "<< Yellow_Text(modelName)< components( + "Read::modelComponent", + compNames.size()+1, + 0, + RESERVE()); + + componentNames_.clear(); + + + for(auto& cName: compNames) + { + auto& compDict = motionInfo.subDict(cName); + + if(auto compPtr = makeUnique(compDict); compPtr) + { + components.push_back(compPtr()); + componentNames_.push_back(cName); + } + } + + if( !componentNames_.search("none") ) + { + components.push_back + ( + impl_noneComponent() + ); + componentNames_.push_back("none"); + } + + motionComponents_.assign(components); + numComponents_ = motionComponents_.size(); + + return true; +} + + +template +inline +bool pFlow::MotionModel::impl_writeDictionary +( + dictionary& dict +)const +{ + word modelName = getTypeName(); + + dict.add("motionModel", modelName ); + + auto modelDictName = modelName+"Info"; + + auto& motionInfo = dict.subDictOrCreate(modelDictName); + auto hostComponents = motionComponents_.hostView(); + + ForAll(i, motionComponents_) + { + + auto& axDict = motionInfo.subDictOrCreate(componentNames_[i]); + if( !hostComponents[i].write(axDict)) + { + fatalErrorInFunction<< + " error in writing axis "<< componentNames_[i] << " to dicrionary " + << motionInfo.globalName()< +pFlow::MotionModel::MotionModel() +: + motionComponents_("motionComponents") +{} \ No newline at end of file diff --git a/src/MotionModel/MotionModel/MotionModel.hpp b/src/MotionModel/MotionModel/MotionModel.hpp new file mode 100644 index 00000000..a6a2b2ab --- /dev/null +++ b/src/MotionModel/MotionModel/MotionModel.hpp @@ -0,0 +1,249 @@ +/*------------------------------- 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 __MotionModel_hpp__ +#define __MotionModel_hpp__ + + + +#include "VectorSingles.hpp" +#include "Vector.hpp" +#include "List.hpp" +#include "dictionary.hpp" + + +namespace pFlow +{ + + +template +class MotionModel +{ +public: + + using ModelType = Model; + + using ModelComponent = Component; + + using ComponentVector_D = VectorSingle; + + /** Motion model class to be passed to computational units/kernels for + * transfing points and returning velocities at various positions + */ + class ModelInterface + { + private: + + deviceViewType1D components_; + + uint32 numComponents_=0; + + public: + + INLINE_FUNCTION_HD + ModelInterface + ( + deviceViewType1D Comps, + uint32 numComp + ): + components_(Comps), + numComponents_(numComp) + {} + + INLINE_FUNCTION_HD + ModelInterface(const ModelInterface&) = default; + + INLINE_FUNCTION_HD + ModelInterface& operator=(const ModelInterface&) = default; + + INLINE_FUNCTION_HD + ModelInterface(ModelInterface&&) noexcept = default; + + INLINE_FUNCTION_HD + ModelInterface& operator=(ModelInterface&&) noexcept= default; + + INLINE_FUNCTION_HD + ~ModelInterface()=default; + + INLINE_FUNCTION_HD + realx3 pointVelocity(uint32 n, const realx3& p)const + { + return components_[n].linVelocityPoint(p); + } + + INLINE_FUNCTION_HD + realx3 operator()(uint32 n, const realx3& p)const + { + return pointVelocity(n,p); + } + + INLINE_FUNCTION_HD + realx3 transferPoint(uint32 n, const realx3 p, real dt)const + { + return components_[n].transferPoint(p, dt); + } + + INLINE_FUNCTION_HD + uint32 size()const + { + return numComponents_; + } + }; + +private: + + // friends + friend ModelType; + + /// Number of axes components + uint32 numComponents_= 0; + + /// Vector to store motion components + ComponentVector_D motionComponents_; + + /// Names of compoenents + wordList componentNames_; + +protected: + + inline + auto& getModel() + { + return static_cast(*this); + } + + inline + const auto& getModel()const + { + return static_cast(*this); + } + + // implementation details goes here + inline + auto impl_noneComponent()const + { + return ModelType::noneComponent(); + } + + /// name of the compoenent to index of the component + bool impl_nameToIndex(const word& name, uint32& idx)const; + + /// Component index to motion component name + + bool impl_indexToName(uint32 i, word& name)const; + + + bool impl_isMoving()const + { + return false; + } + + bool impl_move(uint32, real, real)const + { + return true; + } + + auto impl_getModelInterface(uint32 iter, real t, real dt)const + { + return ModelInterface( + motionComponents_.deviceViewAll(), + numComponents_); + } + + /// Read from dictionary + bool impl_readDictionary(const dictionary& dict); + + bool impl_writeDictionary(dictionary& dict)const; + +public: + + // - Constructors + + /// Empty + MotionModel(); + + /// Copy constructor + MotionModel(const MotionModel&) = default; + + /// Move constructor + MotionModel(MotionModel&&) = default; + + /// Copy assignment + MotionModel& operator=(const MotionModel&) = default; + + /// No move assignment + MotionModel& operator=(MotionModel&&) = default; + + /// Destructor + ~MotionModel() = default; + + // - Methods + /// Return the motion model at time t + /*Model getModel(real t) + { + for(int32 i= 0; i(0.0)); + real omega = dict.getValOrSet("omega", 0.0); setOmega(omega); return true; diff --git a/src/MotionModel/entities/rotatingAxis/rotatingAxis.hpp b/src/MotionModel/entities/rotatingAxis/rotatingAxis.hpp index ee37eba9..1f023e1c 100644 --- a/src/MotionModel/entities/rotatingAxis/rotatingAxis.hpp +++ b/src/MotionModel/entities/rotatingAxis/rotatingAxis.hpp @@ -24,13 +24,12 @@ Licence: #include "timeInterval.hpp" #include "line.hpp" +#include "rotatingAxisFwd.hpp" + namespace pFlow { class dictionary; -class rotatingAxis; - -#include "rotatingAxisFwd.hpp" /** * An axis which rotates around itself at specified speed @@ -64,7 +63,7 @@ class rotatingAxis public timeInterval, public line { -protected: +private: /// rotation speed real omega_ = 0; @@ -78,11 +77,11 @@ public: /// Empty constructor FUNCTION_HD - rotatingAxis(){} + rotatingAxis()=default; /// Construct from dictionary FUNCTION_H - rotatingAxis(const dictionary& dict); + explicit rotatingAxis(const dictionary& dict); /// Construct from components FUNCTION_HD @@ -92,9 +91,19 @@ public: FUNCTION_HD rotatingAxis(const rotatingAxis&) = default; + FUNCTION_HD + rotatingAxis(rotatingAxis&&) = default; + /// Copy asssignment rotatingAxis& operator=(const rotatingAxis&) = default; + /// Copy asssignment + rotatingAxis& operator=(rotatingAxis&&) = default; + + /// destructor + ~rotatingAxis()=default; + + /// Set omega FUNCTION_HD real setOmega(real omega); @@ -115,7 +124,10 @@ public: /// Linear tangential velocity at point p INLINE_FUNCTION_HD - realx3 linTangentialVelocityPoint(const realx3 &p)const; + realx3 linVelocityPoint(const realx3 &p)const; + + INLINE_FUNCTION_HD + realx3 transferPoint(const realx3 p, real dt); // - IO operation diff --git a/src/MotionModel/entities/rotatingAxis/rotatingAxisFwd.hpp b/src/MotionModel/entities/rotatingAxis/rotatingAxisFwd.hpp index 8cbfe593..140411c5 100755 --- a/src/MotionModel/entities/rotatingAxis/rotatingAxisFwd.hpp +++ b/src/MotionModel/entities/rotatingAxis/rotatingAxisFwd.hpp @@ -18,6 +18,11 @@ Licence: -----------------------------------------------------------------------------*/ +namespace pFlow +{ + +class rotatingAxis; + INLINE_FUNCTION_HD realx3 rotate(const realx3 &p, const line& ln, real theta); @@ -25,10 +30,10 @@ INLINE_FUNCTION_HD realx3 rotate(const realx3& p, const rotatingAxis& ax, real dt); INLINE_FUNCTION_HD -void rotate(realx3* p, size_t n, const line& ln, real theta); +void rotate(realx3* p, uint32 n, const line& ln, real theta); INLINE_FUNCTION_HD -void rotate(realx3* p, size_t n, const rotatingAxis& ax, real dt); - +void rotate(realx3* p, uint32 n, const rotatingAxis& ax, real dt); +} diff --git a/src/MotionModel/entities/rotatingAxis/rotatingAxisI.hpp b/src/MotionModel/entities/rotatingAxis/rotatingAxisI.hpp index c7563020..5ade50c2 100755 --- a/src/MotionModel/entities/rotatingAxis/rotatingAxisI.hpp +++ b/src/MotionModel/entities/rotatingAxis/rotatingAxisI.hpp @@ -1,3 +1,4 @@ +#include "rotatingAxis.hpp" /*------------------------------- phasicFlow --------------------------------- O C enter of O O E ngineering and @@ -19,7 +20,7 @@ Licence: -----------------------------------------------------------------------------*/ INLINE_FUNCTION_HD -pFlow::realx3 pFlow::rotatingAxis::linTangentialVelocityPoint(const realx3 &p)const +pFlow::realx3 pFlow::rotatingAxis::linVelocityPoint(const realx3 &p)const { if(!inTimeRange()) return {0,0,0}; @@ -28,6 +29,12 @@ pFlow::realx3 pFlow::rotatingAxis::linTangentialVelocityPoint(const realx3 &p)co return cross(omega_*unitVector(),L); } +INLINE_FUNCTION_HD +pFlow::realx3 pFlow::rotatingAxis::transferPoint(const realx3 p, real dt) +{ + return rotate(p, *this, dt); +} + INLINE_FUNCTION_HD pFlow::realx3 pFlow::rotate(const realx3& p, const rotatingAxis& ax, real dt) { @@ -97,7 +104,7 @@ pFlow::realx3 pFlow::rotate(const realx3 &p, const line& ln, real theta) } INLINE_FUNCTION_HD -void pFlow::rotate(realx3* p, size_t n, const line& ln, real theta) +void pFlow::rotate(realx3* p, uint32 n, const line& ln, real theta) { realx3 nv = ln.unitVector(); real cos_tet = cos(theta); @@ -110,7 +117,7 @@ void pFlow::rotate(realx3* p, size_t n, const line& ln, real theta) // (a(v2+w2) - u( bv + cw - ux - vy - wz)) (1-cos_tet) + x cos_tet + (- cv + bw - wy + vz) sin_tet realx3 res; - for(label i=0; i(0.5)*dt*(velocity0_+velocity_); + return p + 0.5*dt*(velocity0_+velocity_); } // - IO operation diff --git a/src/MotionModel/rotatingAxisMotion/rotatingAxisMotion-old.cpp b/src/MotionModel/rotatingAxisMotion/rotatingAxisMotion-old.cpp new file mode 100644 index 00000000..9ef21e44 --- /dev/null +++ b/src/MotionModel/rotatingAxisMotion/rotatingAxisMotion-old.cpp @@ -0,0 +1,170 @@ +/*------------------------------- 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 "rotatingAxisMotion.hpp" +#include "dictionary.hpp" +#include "vocabs.hpp" + + +bool pFlow::rotatingAxisMotion::readDictionary +( + const dictionary& dict +) +{ + + auto motionModel = dict.getVal("motionModel"); + + if(motionModel != "rotatingAxisMotion") + { + fatalErrorInFunction<< + " motionModel should be rotatingAxisMotion, but found " + << motionModel <(axDict); axPtr) + { + axis_.push_back(axPtr()); + axisName_.push_back(aName); + } + else + { + fatalErrorInFunction<< + "could not read rotating axis from "<< axDict.globalName()< axis_; + int32 numAxis_=0; + + public: + + INLINE_FUNCTION_HD + Model(deviceViewType1D axis, int32 numAxis): + axis_(axis), + numAxis_(numAxis) + {} + + INLINE_FUNCTION_HD + Model(const Model&) = default; + + + INLINE_FUNCTION_HD + Model& operator=(const Model&) = default; + + + INLINE_FUNCTION_HD + realx3 pointVelocity(int32 n, const realx3& p)const + { + return axis_[n].linTangentialVelocityPoint(p); + } + + INLINE_FUNCTION_HD + realx3 operator()(int32 n, const realx3& p)const + { + return pointVelocity(n,p); + } + + INLINE_FUNCTION_HD + realx3 transferPoint(int32 n, const realx3 p, real dt)const + { + return rotate(p, axis_[n], dt); + } + + INLINE_FUNCTION_HD int32 numComponents()const + { + return numAxis_; + } + }; + +protected: + + using axisVector_HD = VectorDual; + + /// Vector to store axes + axisVector_HD axis_; + + /// Names of axes + wordList axisName_; + + /// Number of axes components + label numAxis_= 0; + + /// Read from dictionary + bool readDictionary(const dictionary& dict); + + /// Write to dictionary + bool writeDictionary(dictionary& dict)const; + +public: + + /// Type info + TypeInfoNV("rotatingAxisMotion"); + + // - Constructors + + /// Empty + FUNCTION_H + rotatingAxisMotion(); + + /// Construct with dictionary + FUNCTION_H + rotatingAxisMotion(const dictionary& dict); + + /// Copy constructor + FUNCTION_H + rotatingAxisMotion(const rotatingAxisMotion&) = default; + + /// No move constructor + rotatingAxisMotion(rotatingAxisMotion&&) = delete; + + /// Copy assignment + FUNCTION_H + rotatingAxisMotion& operator=(const rotatingAxisMotion&) = default; + + /// No move assignment + rotatingAxisMotion& operator=(rotatingAxisMotion&&) = delete; + + /// Destructor + FUNCTION_H + ~rotatingAxisMotion() = default; + + // - Methods + /// Return the motion model at time t + Model getModel(real t) + { + for(int32 i= 0; i("motionModel"); - - if(motionModel != "rotatingAxisMotion") - { - fatalErrorInFunction<< - " motionModel should be rotatingAxisMotion, but found " - << motionModel <(axDict); axPtr) - { - axis_.push_back(axPtr()); - axisName_.push_back(aName); - } - else - { - fatalErrorInFunction<< - "could not read rotating axis from "<< axDict.globalName()<impl_writeDictionary(newDict) || + !newDict.write(os)) + { + fatalErrorInFunction<< + " error in writing to dictionary "<< newDict.globalName()< { -public: - - /** Motion model class to be passed to computational units/kernels for - * transfing points and returning velocities at various positions - */ - class Model - { - protected: - - deviceViewType1D axis_; - int32 numAxis_=0; - - public: - - INLINE_FUNCTION_HD - Model(deviceViewType1D axis, int32 numAxis): - axis_(axis), - numAxis_(numAxis) - {} - - INLINE_FUNCTION_HD - Model(const Model&) = default; - - - INLINE_FUNCTION_HD - Model& operator=(const Model&) = default; - - - INLINE_FUNCTION_HD - realx3 pointVelocity(int32 n, const realx3& p)const - { - return axis_[n].linTangentialVelocityPoint(p); - } - - INLINE_FUNCTION_HD - realx3 operator()(int32 n, const realx3& p)const - { - return pointVelocity(n,p); - } - - INLINE_FUNCTION_HD - realx3 transferPoint(int32 n, const realx3 p, real dt)const - { - return rotate(p, axis_[n], dt); - } - - INLINE_FUNCTION_HD int32 numComponents()const - { - return numAxis_; - } - }; - protected: - using axisVector_HD = VectorDual; - - /// Vector to store axes - axisVector_HD axis_; + bool impl_isMoving()const + { + return true; + } - /// Names of axes - wordList axisName_; - - /// Number of axes components - label numAxis_= 0; - - /// Read from dictionary - bool readDictionary(const dictionary& dict); - - /// Write to dictionary - bool writeDictionary(dictionary& dict)const; - public: - - /// Type info - TypeInfoNV("rotatingAxisMotion"); - // - Constructors - - /// Empty - FUNCTION_H - rotatingAxisMotion(); + TypeInfo("rotatingAxisMotion"); - /// Construct with dictionary - FUNCTION_H - rotatingAxisMotion(const dictionary& dict); + rotatingAxisMotion(const objectFile& objf, repository* owner); - /// Copy constructor - FUNCTION_H - rotatingAxisMotion(const rotatingAxisMotion&) = default; - /// No move constructor - rotatingAxisMotion(rotatingAxisMotion&&) = delete; - - /// Copy assignment - FUNCTION_H - rotatingAxisMotion& operator=(const rotatingAxisMotion&) = default; - - /// No move assignment - rotatingAxisMotion& operator=(rotatingAxisMotion&&) = delete; - - /// Destructor - FUNCTION_H - ~rotatingAxisMotion() = default; - - // - Methods - /// Return the motion model at time t - Model getModel(real t) - { - for(int32 i= 0; i("motionModel"); + + if(motionModel != "vibratingMotion") + { + fatalErrorInFunction<< + " motionModel should be vibratingMotion, but found " + << motionModel <(compDict); compPtr) + { + components_.push_back(compPtr()); + componentName_.push_back(cName); + } + else + { + fatalErrorInFunction<< + "could not read vibrating motion from "<< compDict.globalName()< components_; + int32 numComponents_=0; + + public: + + INLINE_FUNCTION_HD + Model(deviceViewType1D comps, int32 numComps): + components_(comps), + numComponents_(numComps) + {} + + INLINE_FUNCTION_HD + Model(const Model&) = default; + + + INLINE_FUNCTION_HD + Model& operator=(const Model&) = default; + + + INLINE_FUNCTION_HD + realx3 pointVelocity(int32 n, const realx3& p)const + { + return components_[n].linTangentialVelocityPoint(p); + } + + INLINE_FUNCTION_HD + realx3 operator()(int32 n, const realx3& p)const + { + return pointVelocity(n,p); + } + + INLINE_FUNCTION_HD + realx3 transferPoint(int32 n, const realx3 p, real dt)const + { + return components_[n].transferPoint(p, dt); + } + + INLINE_FUNCTION_HD int32 numComponents()const + { + return numComponents_; + } + }; + +protected: + + using axisVector_HD = VectorDual; + + /// Vibrating motion components + axisVector_HD components_; + + /// Names of components + wordList componentName_; + + /// Number of components + label numComponents_= 0; + + /// Read from a dictionary + bool readDictionary(const dictionary& dict); + + /// Write to a dictionary + bool writeDictionary(dictionary& dict)const; + +public: + + /// Type info + TypeInfoNV("vibratingMotion"); + + /// Empty + FUNCTION_H + vibratingMotion(); + + /// Construct with dictionary + FUNCTION_H + vibratingMotion(const dictionary& dict); + + /// Copy constructor + FUNCTION_H + vibratingMotion(const vibratingMotion&) = default; + + /// No move + vibratingMotion(vibratingMotion&&) = delete; + + /// Copy assignment + FUNCTION_H + vibratingMotion& operator=(const vibratingMotion&) = default; + + /// No Move assignment + vibratingMotion& operator=(vibratingMotion&&) = delete; + + /// Destructor + FUNCTION_H + ~vibratingMotion() = default; + + /// Return motion model at time t + Model getModel(real t) + { + for(int32 i= 0; i("motionModel"); - - if(motionModel != "vibratingMotion") - { - fatalErrorInFunction<< - " motionModel should be vibratingMotion, but found " - << motionModel <(compDict); compPtr) - { - components_.push_back(compPtr()); - componentName_.push_back(cName); - } - else - { - fatalErrorInFunction<< - "could not read vibrating motion from "<< compDict.globalName()< { -public: - - /** Motion model class to be passed to computational units/kernels for - * transfing points and returning velocities at various positions - */ - class Model - { - protected: - - deviceViewType1D components_; - int32 numComponents_=0; - - public: - - INLINE_FUNCTION_HD - Model(deviceViewType1D comps, int32 numComps): - components_(comps), - numComponents_(numComps) - {} - - INLINE_FUNCTION_HD - Model(const Model&) = default; - - - INLINE_FUNCTION_HD - Model& operator=(const Model&) = default; - - - INLINE_FUNCTION_HD - realx3 pointVelocity(int32 n, const realx3& p)const - { - return components_[n].linTangentialVelocityPoint(p); - } - - INLINE_FUNCTION_HD - realx3 operator()(int32 n, const realx3& p)const - { - return pointVelocity(n,p); - } - - INLINE_FUNCTION_HD - realx3 transferPoint(int32 n, const realx3 p, real dt)const - { - return components_[n].transferPoint(p, dt); - } - - INLINE_FUNCTION_HD int32 numComponents()const - { - return numComponents_; - } - }; protected: - using axisVector_HD = VectorDual; - - /// Vibrating motion components - axisVector_HD components_; - - /// Names of components - wordList componentName_; - - /// Number of components - label numComponents_= 0; - - /// Read from a dictionary - bool readDictionary(const dictionary& dict); - - /// Write to a dictionary - bool writeDictionary(dictionary& dict)const; + bool impl_isMoving()const + { + return true; + } public: /// Type info - TypeInfoNV("vibratingMotion"); - - /// Empty - FUNCTION_H - vibratingMotion(); - - /// Construct with dictionary - FUNCTION_H - vibratingMotion(const dictionary& dict); - - /// Copy constructor - FUNCTION_H - vibratingMotion(const vibratingMotion&) = default; - - /// No move - vibratingMotion(vibratingMotion&&) = delete; - - /// Copy assignment - FUNCTION_H - vibratingMotion& operator=(const vibratingMotion&) = default; - - /// No Move assignment - vibratingMotion& operator=(vibratingMotion&&) = delete; + TypeInfo("vibratingMotion"); + + vibratingMotion(const objectFile& objf, repository* owner); /// Destructor - FUNCTION_H - ~vibratingMotion() = default; + ~vibratingMotion()override = default; - /// Return motion model at time t - Model getModel(real t) - { - for(int32 i= 0; i events_{0x0000}; diff --git a/src/phasicFlow/eventManagement/observer.cpp b/src/phasicFlow/eventManagement/observer.cpp index d47fef24..7d131d75 100644 --- a/src/phasicFlow/eventManagement/observer.cpp +++ b/src/phasicFlow/eventManagement/observer.cpp @@ -19,11 +19,17 @@ Licence: -----------------------------------------------------------------------------*/ #include "observer.hpp" -#include "subscriber.hpp" +#include "subscriber.hpp" -pFlow::observer::observer(message msg): - subscriber_(nullptr), - message_(msg) +const pFlow::subscriber *pFlow::observer::changeSubscriber(const subscriber *newSub) +{ + const subscriber* old = subscriber_; + subscriber_ = newSub; + return old; +} + +pFlow::observer::observer(message msg) : subscriber_(nullptr), + message_(msg) {} pFlow::observer::observer diff --git a/src/phasicFlow/eventManagement/observer.hpp b/src/phasicFlow/eventManagement/observer.hpp index 6b8fca11..8a830c60 100644 --- a/src/phasicFlow/eventManagement/observer.hpp +++ b/src/phasicFlow/eventManagement/observer.hpp @@ -32,7 +32,7 @@ class anyList; class observer { -protected: +private: /// pointer to subscriber @@ -41,6 +41,14 @@ protected: /// list of events in the message message message_; + friend subscriber; + + const subscriber* changeSubscriber(const subscriber* newSub); + + inline void invalidateSubscriber() + { + subscriber_ = nullptr; + } public: @@ -69,10 +77,7 @@ public: bool addToSubscriber(const subscriber& subscriber); - inline void invalidateSubscriber() - { - subscriber_ = nullptr; - } + static constexpr auto numEvents() diff --git a/src/phasicFlow/eventManagement/subscriber.cpp b/src/phasicFlow/eventManagement/subscriber.cpp index db8009bd..6393e974 100644 --- a/src/phasicFlow/eventManagement/subscriber.cpp +++ b/src/phasicFlow/eventManagement/subscriber.cpp @@ -24,6 +24,48 @@ Licence: #include "observer.hpp" #include "message.hpp" +pFlow::subscriber::subscriber(const subscriber & src) +: + subName_(src.subName_) +{ +} + +pFlow::subscriber::subscriber(subscriber && src) +: + observerList_(std::move(src.observerList_)), + subName_(std::move(src.subName_)) +{ + + for(size_t i=0; ichangeSubscriber(this); + } + } +} + +pFlow::subscriber &pFlow::subscriber::operator=(const subscriber & rhs) +{ + this->subName_ = rhs.subName_; + return *this; +} + +pFlow::subscriber &pFlow::subscriber::operator=(subscriber && rhs) +{ + this->subName_ = std::move(rhs.subName_); + this->observerList_ = std::move(rhs.observerList_); + + for(size_t i=0; ichangeSubscriber(this); + } + } + + return *this; +} pFlow::subscriber::~subscriber() { @@ -82,9 +124,9 @@ bool pFlow::subscriber::unsubscribe bool pFlow::subscriber::notify ( + uint32 iter, real t, real dt, - uint32 iter, const message msg, const anyList& varList ) diff --git a/src/phasicFlow/eventManagement/subscriber.hpp b/src/phasicFlow/eventManagement/subscriber.hpp index 48143f18..6507de01 100644 --- a/src/phasicFlow/eventManagement/subscriber.hpp +++ b/src/phasicFlow/eventManagement/subscriber.hpp @@ -35,7 +35,7 @@ class anyList; class subscriber { -protected: +private: // - list of subsribed objectd that recieve updage messages mutable std::array,message::numEvents()> observerList_; @@ -49,13 +49,19 @@ public: subName_(name) {} - subscriber(const subscriber&) = delete; + /// Copy constructor, only copies the name, not the list + subscriber(const subscriber&); - subscriber(subscriber&&) = default; + /// @brief Move constructor, moves the name and the list, + /// also change the subriber of the object in the list + subscriber(subscriber&&); - subscriber& operator = (const subscriber&) = delete; + /// Copy assignemnt, only assign the name, do not assign the list + subscriber& operator = (const subscriber&); - subscriber& operator = (subscriber&&) = default; + /// @brief Move assignment, move assign name and list, + /// also change the subcriber of the object in the list + subscriber& operator = (subscriber&&); virtual ~subscriber(); @@ -63,16 +69,10 @@ public: virtual bool unsubscribe(observer* obsevr)const; - //bool notify(const eventMessage& msg); - - //bool notify(const eventMessage& msg, const List& exclutionList ); - - - bool notify( + uint32 iter, real t, real dt, - uint32 iter, const message msg, const anyList& varList); diff --git a/src/phasicFlow/triSurface/multiTriSurface.cpp b/src/phasicFlow/triSurface/multiTriSurface.cpp index 043919cd..8b62fa18 100644 --- a/src/phasicFlow/triSurface/multiTriSurface.cpp +++ b/src/phasicFlow/triSurface/multiTriSurface.cpp @@ -160,7 +160,8 @@ pFlow::multiTriSurface::multiTriSurface repository *owner ) : - triSurface(obj, owner) + triSurface(obj, owner), + subscriber("multiTriSurface") { if( !IOobject::readObject() ) { diff --git a/src/phasicFlow/triSurface/multiTriSurface.hpp b/src/phasicFlow/triSurface/multiTriSurface.hpp index 95dc9280..7b7360b8 100644 --- a/src/phasicFlow/triSurface/multiTriSurface.hpp +++ b/src/phasicFlow/triSurface/multiTriSurface.hpp @@ -22,18 +22,18 @@ Licence: #ifndef __multiTriSurface_hpp__ #define __multiTriSurface_hpp__ - +#include "subscriber.hpp" #include "triSurface.hpp" #include "subSurface.hpp" - namespace pFlow { class multiTriSurface : - public triSurface + public triSurface, + public subscriber { private: @@ -41,11 +41,6 @@ private: // - the index of last point of each triSurface - - - - - //void calculateVars(); public: @@ -55,16 +50,16 @@ public: //// - Constructors - // - emtpy + // multiTriSurface(const objectFile& obj, repository* owner); - /*multiTriSurface(const multiTriSurface&) = default; + multiTriSurface(const multiTriSurface&) = default; multiTriSurface& operator = (const multiTriSurface&) = default; multiTriSurface(multiTriSurface&&) = delete; - multiTriSurface& operator = (multiTriSurface&&) = delete; */ + multiTriSurface& operator = (multiTriSurface&&) = delete; ~multiTriSurface() override = default;