From 5c499f1eeef87c4f4ac4f33e9b5c97f86ef1c4d6 Mon Sep 17 00:00:00 2001 From: xuwenxuan Date: Fri, 14 Mar 2025 22:23:17 +0800 Subject: [PATCH] Revert "adapt the multiRotatingAxisMotion to v-1.0" This reverts commit bf0230956971c2a04ca9ce6019b48ec022239b7b. --- .../geometryMotion/geometryMotions.cpp | 2 +- .../geometryMotion/geometryMotions.hpp | 7 +- src/MotionModel/CMakeLists.txt | 4 +- .../multiRotatingAxis/multiRotatingAxis.cpp | 39 +-- .../multiRotatingAxis/multiRotatingAxis.hpp | 16 +- .../multiRotatingAxisMotion.cpp | 240 ++++++++++++++---- .../multiRotatingAxisMotion.hpp | 223 +++++++++++++--- 7 files changed, 393 insertions(+), 138 deletions(-) diff --git a/src/Geometry/geometryMotion/geometryMotions.cpp b/src/Geometry/geometryMotion/geometryMotions.cpp index 8636c1f7..6cdb4a3b 100644 --- a/src/Geometry/geometryMotion/geometryMotions.cpp +++ b/src/Geometry/geometryMotion/geometryMotions.cpp @@ -28,4 +28,4 @@ template class pFlow::geometryMotion; template class pFlow::geometryMotion; -template class pFlow::geometryMotion; +//template class pFlow::geometryMotion; diff --git a/src/Geometry/geometryMotion/geometryMotions.hpp b/src/Geometry/geometryMotion/geometryMotions.hpp index 4a916b6e..3b0a2867 100644 --- a/src/Geometry/geometryMotion/geometryMotions.hpp +++ b/src/Geometry/geometryMotion/geometryMotions.hpp @@ -25,7 +25,7 @@ Licence: #include "stationaryWall.hpp" #include "rotatingAxisMotion.hpp" #include "conveyorBeltMotion.hpp" -#include "multiRotatingAxisMotion.hpp" +//#include "multiRotatingAxisMotion.hpp" #include "vibratingMotion.hpp" @@ -40,7 +40,10 @@ using stationaryGeometry = geometryMotion; using conveyorBeltMotionGeometry = geometryMotion; -using multiRotationAxisMotionGeometry = geometryMotion; +//typedef geometryMotion multiRotationAxisMotionGeometry; + + + } diff --git a/src/MotionModel/CMakeLists.txt b/src/MotionModel/CMakeLists.txt index d28af4f5..1e92a989 100644 --- a/src/MotionModel/CMakeLists.txt +++ b/src/MotionModel/CMakeLists.txt @@ -14,8 +14,8 @@ entities/stationary/stationary.cpp conveyorBeltMotion/conveyorBeltMotion.cpp entities/conveyorBelt/conveyorBelt.cpp -entities/multiRotatingAxis/multiRotatingAxis.cpp -multiRotatingAxisMotion/multiRotatingAxisMotion.cpp +#entities/multiRotatingAxis/multiRotatingAxis.cpp +#multiRotatingAxisMotion/multiRotatingAxisMotion.cpp ) diff --git a/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.cpp b/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.cpp index 12f6596b..62733216 100644 --- a/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.cpp +++ b/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.cpp @@ -22,18 +22,6 @@ Licence: #include "multiRotatingAxisMotion.hpp" #include "dictionary.hpp" -/// Construct from dictionary -FUNCTION_H -pFlow::multiRotatingAxis::multiRotatingAxis(const dictionary& dict) -{ - if(!read(nullptr, dict)) - { - fatalErrorInFunction<< - " error in reading multiRotatingAxis from dictionary "<< dict.globalName()< nameToIndex(rotAxis, parentAxisIndex_); + parentAxisIndex_ = axisMotion-> nameToIndex(rotAxis); } return true; @@ -102,33 +90,10 @@ bool pFlow::multiRotatingAxis::write } else { - word rotAxis; - bool result = axisMotion->indexToName(parentAxisIndex_, rotAxis); + auto rotAxis = axisMotion->indexToName(parentAxisIndex_); dict.add("rotationAxis", rotAxis); } return true; } - -FUNCTION_H -bool pFlow::multiRotatingAxis::write -( - dictionary& dict -) const -{ - if( !rotatingAxis::write(dict) ) return false; - - if(parentAxisIndex_ == 0) - { - dict.add("rotationAxis", "none"); - } - // else - // { - // word rotAxis; - // bool result = axisMotion->indexToName(parentAxisIndex_, rotAxis); - // dict.add("rotationAxis", rotAxis); - // } - - return true; -} diff --git a/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.hpp b/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.hpp index 20c231e0..c79e87c8 100644 --- a/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.hpp +++ b/src/MotionModel/entities/multiRotatingAxis/multiRotatingAxis.hpp @@ -82,22 +82,16 @@ protected: multiRotatingAxis* axisList_; /// Index of parent axis - uint32 parentAxisIndex_ = static_cast(-1); + int32 parentAxisIndex_ = -1; public: - TypeInfoNV("multiRotatingAxis"); - // - Constructors /// Empty Constructor INLINE_FUNCTION_HD multiRotatingAxis(){} - /// Construct from dictionary - FUNCTION_H - explicit multiRotatingAxis(const dictionary& dict); - /// Empty with list of axes FUNCTION_H multiRotatingAxis(multiRotatingAxisMotion* axisMotion); @@ -129,11 +123,11 @@ public: while(parIndex != -1) { auto& ax = axisList_[parIndex]; - parentVel += ax.linVelocityPoint(p); + parentVel += ax.linTangentialVelocityPoint(p); parIndex = ax.parentAxisIndex(); } - return parentVel + rotatingAxis::linVelocityPoint(p); + return parentVel + rotatingAxis::linTangentialVelocityPoint(p); } /// Translate point p for dt seconds based on the axis information @@ -213,10 +207,6 @@ public: FUNCTION_H bool write(const multiRotatingAxisMotion* axisMotion, dictionary& dict) const; - /// Write to dictionary - FUNCTION_H - bool write(dictionary& dict) const; - }; diff --git a/src/MotionModel/multiRotatingAxisMotion/multiRotatingAxisMotion.cpp b/src/MotionModel/multiRotatingAxisMotion/multiRotatingAxisMotion.cpp index a14b92c5..360f1ee0 100644 --- a/src/MotionModel/multiRotatingAxisMotion/multiRotatingAxisMotion.cpp +++ b/src/MotionModel/multiRotatingAxisMotion/multiRotatingAxisMotion.cpp @@ -19,70 +19,220 @@ Licence: -----------------------------------------------------------------------------*/ #include "multiRotatingAxisMotion.hpp" +#include "dictionary.hpp" +#include "vocabs.hpp" -void pFlow::multiRotatingAxisMotion::impl_setTime + +bool pFlow::multiRotatingAxisMotion::readDictionary ( - uint32 iter, - real t, - real dt + const dictionary& dict +) +{ + + auto motionModel = dict.getVal("motionModel"); + + if(motionModel != "multiRotatingAxisMotion") + { + fatalErrorInFunction<< + " motionModel should be multiRotatingAxisMotion, but found " + << motionModel <(axDict); axPtr) + { + rotationAxis.push_back( + axDict.getValOrSet("rotationAxis", "none")); + } + else + { + fatalErrorInFunction<< + "could not read rotating axis from "<< axDict.globalName()<; + + std::vector numRotAxis; + + for(size_t i=0; i< axisNames.size(); i++) + { + word rotAxis = rotationAxis[i]; + int32 n=0; + while(rotAxis != "none") + { + n++; + if(int32 iAxis = axisNames.findi(rotAxis) ; iAxis != -1) + { + rotAxis = rotationAxis[iAxis]; + }else + { + fatalErrorInFunction<< + "rotation axis name "<< rotAxis << "is does not exist!"< b.first; }; + + algorithms::STD::sort(numRotAxis.data(), numRotAxis.size(), compareFunc); + + sortedIndex_.clear(); + axisName_.clear(); + + + for(auto ax:numRotAxis) + { + axisName_.push_back(axisNames[ax.second]); + sortedIndex_.push_back(ax.second); + } + + numAxis_ = axisName_.size(); + axis_.clear(); + axis_.reserve(numAxis_); + + + // create the actual axis vector + for(auto& aName: axisName_) + { + if(aName != "none") + { + auto& axDict = motionInfo.subDict(aName); + axis_.push_back( + multiRotatingAxis(this, axDict)); + } + else + { + axis_.push_back( + multiRotatingAxis(this)); + } + + } + + return true; +} + +bool pFlow::multiRotatingAxisMotion::writeDictionary +( + dictionary& dict )const { - auto motion = motionComponents_.deviceViewAll(); - Kokkos::parallel_for( - "multiRotatingAxisMotion::impl_setTime", - deviceRPolicyStatic(0, numComponents_), - LAMBDA_HD(uint32 i){ - motion[i].setTime(t); - }); - Kokkos::fence(); + dict.add("motionModel", "multiRotatingAxisMotion"); + + auto& motionInfo = dict.subDictOrCreate("multiRotatingAxisMotionInfo"); + + ForAll(i, axis_) + { + + auto& axDict = motionInfo.subDictOrCreate(axisName_[i]); + if( !axis_.hostVectorAll()[i].write(this,axDict)) + { + fatalErrorInFunction<< + " error in writing axis "<< axisName_[i] << " to dicrionary " + << motionInfo.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].pointTangentialVel(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 axis_[n].transferPoint(p, dt); + } + + INLINE_FUNCTION_HD int32 numComponents()const + { + return numAxis_; + } + }; + protected: - friend MotionModel; + using axisVector_HD = VectorDual; - /// is the geometry attached to this component moving - bool impl_isMoving()const - { - return true; - } + /// Vector of multiRotaingAxis axes + axisVector_HD axis_; + + /// Sorted index based on number of parrents each axis ha + VectorDual sortedIndex_; - /// move the component itself - bool impl_move(uint32, real, real)const - { - return true; - } + /// List of axes names + wordList axisName_; + + /// Number of axes + label numAxis_= 0; + + /// Read from a dictionary + bool readDictionary(const dictionary& dict); + + /// Write to a dictionary + bool writeDictionary(dictionary& dict)const; public: - TypeInfo("multiRotatingAxisMotion"); + /// Type info + TypeInfoNV("multiRotatingAxisMotion"); - multiRotatingAxisMotion(const objectFile& objf, repository* owner); + // - Constructor - multiRotatingAxisMotion( - const objectFile& objf, - const dictionary& dict, - repository* owner); + /// Empty constructor + FUNCTION_H + multiRotatingAxisMotion(); - using fileDictionary::write; + /// Construct with dictionary + FUNCTION_H + multiRotatingAxisMotion(const dictionary& dict); - bool write(iOstream& os, const IOPattern& iop)const override; + /// Copy constructor + FUNCTION_H + multiRotatingAxisMotion(const multiRotatingAxisMotion&) = default; - static - auto noneComponent() - { - return multiRotatingAxis{}; - } + /// No Move + multiRotatingAxisMotion(multiRotatingAxisMotion&&) = delete; - // TODO: make this method protected - void impl_setTime(uint32 iter, real t, real dt)const; + /// Copy assignment + FUNCTION_H + multiRotatingAxisMotion& operator=(const multiRotatingAxisMotion&) = default; + + /// No move assignment + multiRotatingAxisMotion& operator=(multiRotatingAxisMotion&&) = delete; + + /// Destructor + FUNCTION_H + ~multiRotatingAxisMotion() = default; + + // - Methods + + /// Retrun motion model at time t + Model getModel(real t) + { + for(int32 i= 0; i