MotionModel folder completed

This commit is contained in:
Hamidreza Norouzi 2024-03-22 09:42:23 -07:00
parent f27fbdd82c
commit be56d8ee2e
16 changed files with 127 additions and 900 deletions

View File

@ -32,7 +32,9 @@ Licence:
namespace pFlow namespace pFlow
{ {
/**
* @brief Motion model abstract class (CRTP) for all the motion models
*/
template<typename Model, typename Component> template<typename Model, typename Component>
class MotionModel class MotionModel
{ {
@ -123,49 +125,45 @@ private:
protected: protected:
/// @brief obtain a reference to the actual motion model
inline inline
auto& getModel() auto& getModel()
{ {
return static_cast<ModelType&>(*this); return static_cast<ModelType&>(*this);
} }
/// @brief Obtain a const reference to the actual motion model
inline inline
const auto& getModel()const const auto& getModel()const
{ {
return static_cast<const ModelType&>(*this); return static_cast<const ModelType&>(*this);
} }
// implementation details goes here /// Return a none object for the motion model
inline inline
auto impl_noneComponent()const auto impl_noneComponent()const
{ {
return ModelType::noneComponent(); return ModelType::noneComponent();
} }
/// name of the compoenent to index of the component /// Name of the compoenent to index of the component
bool impl_nameToIndex(const word& name, uint32& idx)const; bool impl_nameToIndex(const word& name, uint32& idx)const;
/// Component index to motion component name /// Component index to motion component name
bool impl_indexToName(uint32 i, word& name)const; bool impl_indexToName(uint32 i, word& name)const;
/// const reference to the list of component names
inline
const wordList& impl_componentNames()const const wordList& impl_componentNames()const
{ {
return componentNames_; return componentNames_;
} }
bool impl_isMoving()const /// Return model interface
{
return false;
}
bool impl_move(uint32, real, real)const
{
return true;
}
auto impl_getModelInterface(uint32 iter, real t, real dt)const auto impl_getModelInterface(uint32 iter, real t, real dt)const
{ {
getModel().impl_setTime(iter, t, dt);
return ModelInterface( return ModelInterface(
motionComponents_.deviceViewAll(), motionComponents_.deviceViewAll(),
numComponents_); numComponents_);
@ -174,6 +172,7 @@ protected:
/// Read from dictionary /// Read from dictionary
bool impl_readDictionary(const dictionary& dict); bool impl_readDictionary(const dictionary& dict);
/// Write to dictionary
bool impl_writeDictionary(dictionary& dict)const; bool impl_writeDictionary(dictionary& dict)const;
public: public:
@ -199,20 +198,6 @@ public:
~MotionModel() = default; ~MotionModel() = default;
// - Methods // - Methods
/// Return the motion model at time t
/*Model getModel(real t)
{
for(int32 i= 0; i<numAxis_; i++ )
{
axis_[i].setTime(t);
}
axis_.modifyOnHost();
axis_.syncViews();
return Model(axis_.deviceVector(), numAxis_);
}*/
/// Motion component name to index
/// name of the compoenent to index of the component /// name of the compoenent to index of the component
bool nameToIndex(const word& name, uint32& idx)const bool nameToIndex(const word& name, uint32& idx)const
@ -226,23 +211,26 @@ public:
return getModel().impl_indexToName(idx, name); return getModel().impl_indexToName(idx, name);
} }
/// @brief Return a const reference to the list of compoenent names
/// @return
const wordList& componentNames()const const wordList& componentNames()const
{ {
return getModel().impl_componentNames(); return getModel().impl_componentNames();
} }
/// Are walls moving /// Is the wall assocciated to this motion component moving?
bool isMoving()const bool isMoving()const
{ {
return getModel().impl_isMoving(); return getModel().impl_isMoving();
} }
/// Move /// Move the component itself
bool move(uint32 iter, real t, real dt) bool move(uint32 iter, real t, real dt)
{ {
return getModel().impl_move(iter, t, dt); return getModel().impl_move(iter, t, dt);
} }
/// Obtain an object to model interface
auto getModelInterface(uint32 iter, real t, real dt)const auto getModelInterface(uint32 iter, real t, real dt)const
{ {
return getModel().impl_getModelInterface(iter, t, dt); return getModel().impl_getModelInterface(iter, t, dt);

View File

@ -78,7 +78,7 @@ class multiRotatingAxis
{ {
protected: protected:
/// This is either host/device pointer to all axes /// This is device pointer to all axes
multiRotatingAxis* axisList_; multiRotatingAxis* axisList_;
/// Index of parent axis /// Index of parent axis
@ -170,7 +170,7 @@ public:
/// Set the pointer to the list of all axes. /// Set the pointer to the list of all axes.
/// This pointer is device pointer /// This pointer is device pointer
INLINE_FUNCTION_H INLINE_FUNCTION_H
void setAxisList(multiRotatingAxis* axisList) void setAxisListPtr(multiRotatingAxis* axisList)
{ {
axisList_ = axisList; axisList_ = axisList;
} }

View File

@ -129,7 +129,7 @@ public:
realx3 linVelocityPoint(const realx3 &p)const; realx3 linVelocityPoint(const realx3 &p)const;
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
realx3 transferPoint(const realx3 p, real dt); realx3 transferPoint(const realx3 p, real dt)const;
// - IO operation // - IO operation

View File

@ -30,7 +30,7 @@ pFlow::realx3 pFlow::rotatingAxis::linVelocityPoint(const realx3 &p)const
} }
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
pFlow::realx3 pFlow::rotatingAxis::transferPoint(const realx3 p, real dt) pFlow::realx3 pFlow::rotatingAxis::transferPoint(const realx3 p, real dt)const
{ {
return rotate(p, *this, dt); return rotate(p, *this, dt);
} }

View File

@ -60,13 +60,13 @@ public:
{} {}
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
realx3 linTangentialVelocityPoint(const realx3 &)const realx3 linVelocityPoint(const realx3 &)const
{ {
return zero3; return zero3;
} }
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
realx3 transferPoint(const realx3& p, real dt) realx3 transferPoint(const realx3& p, real)const
{ {
return p; return p;
} }

View File

@ -117,13 +117,13 @@ public:
} }
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
realx3 linTangentialVelocityPoint(const realx3 &)const realx3 linVelocityPoint(const realx3 &)const
{ {
return velocity_; return velocity_;
} }
INLINE_FUNCTION_HD INLINE_FUNCTION_HD
realx3 transferPoint(const realx3& p, real dt) realx3 transferPoint(const realx3& p, real dt)const
{ {
if(!inTimeRange()) return p; if(!inTimeRange()) return p;
return p + 0.5*dt*(velocity0_+velocity_); return p + 0.5*dt*(velocity0_+velocity_);

View File

@ -1,170 +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.
-----------------------------------------------------------------------------*/
#include "rotatingAxisMotion.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
bool pFlow::rotatingAxisMotion::readDictionary
(
const dictionary& dict
)
{
auto motionModel = dict.getVal<word>("motionModel");
if(motionModel != "rotatingAxisMotion")
{
fatalErrorInFunction<<
" motionModel should be rotatingAxisMotion, but found "
<< motionModel <<endl;
return false;
}
auto& motionInfo = dict.subDict("rotatingAxisMotionInfo");
auto axisNames = motionInfo.dictionaryKeywords();
axis_.reserve(axisNames.size()+1);
axis_.clear();
axisName_.clear();
for(auto& aName: axisNames)
{
auto& axDict = motionInfo.subDict(aName);
if(auto axPtr = makeUnique<rotatingAxis>(axDict); axPtr)
{
axis_.push_back(axPtr());
axisName_.push_back(aName);
}
else
{
fatalErrorInFunction<<
"could not read rotating axis from "<< axDict.globalName()<<endl;
return false;
}
}
if( !axisName_.search("none") )
{
axis_.push_back
(
rotatingAxis(
realx3(0.0,0.0,0.0),
realx3(1.0,0.0,0.0),
0.0
)
);
axisName_.push_back("none");
}
axis_.syncViews();
numAxis_ = axis_.size();
return true;
}
bool pFlow::rotatingAxisMotion::writeDictionary
(
dictionary& dict
)const
{
dict.add("motionModel", "rotatingAxisMotion");
auto& motionInfo = dict.subDictOrCreate("rotatingAxisMotionInfo");
ForAll(i, axis_)
{
auto& axDict = motionInfo.subDictOrCreate(axisName_[i]);
if( !axis_.hostVectorAll()[i].write(axDict))
{
fatalErrorInFunction<<
" error in writing axis "<< axisName_[i] << " to dicrionary "
<< motionInfo.globalName()<<endl;
return false;
}
}
return true;
}
pFlow::rotatingAxisMotion::rotatingAxisMotion()
{}
pFlow::rotatingAxisMotion::rotatingAxisMotion
(
const dictionary& dict
)
{
if(! readDictionary(dict) )
{
fatalExit;
}
}
bool pFlow::rotatingAxisMotion::read
(
iIstream& is
)
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
// read dictionary from stream
if( !motionInfo.read(is) )
{
ioErrorInFile(is.name(), is.lineNumber()) <<
" error in reading dictionray " << motionModelFile__ <<" from file. \n";
return false;
}
if( !readDictionary(motionInfo) ) return false;
return true;
}
bool pFlow::rotatingAxisMotion::write
(
iOstream& os
)const
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
if( !writeDictionary(motionInfo))
{
return false;
}
if( !motionInfo.write(os) )
{
ioErrorInFile( os.name(), os.lineNumber() )<<
" error in writing dictionray to file. \n";
return false;
}
return true;
}

View File

@ -1,247 +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.
-----------------------------------------------------------------------------*/
#ifndef __rotatingAxisMotion_hpp__
#define __rotatingAxisMotion_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
#include "VectorDual.hpp"
#include "Vectors.hpp"
#include "List.hpp"
#include "rotatingAxis.hpp"
namespace pFlow
{
class dictionary;
/**
* Rotating axis motion model for walls
*
* This class is used for simulaiton that at least one wall components
* is moving according to rotatingAxis motion mode. One or more than one
* motion components can be defined in rotatingAxisMotionInfo dictionary
*
\verbatim
// In geometryDict file, this will defines rotating walls during simulation
...
motionModel rotatingAxisMotion;
rotatingAxisMotionInfo
{
rotationAxis1
{
// the definition based on class rotatingAxis
}
rotatoinAxis2
{
// the definition based on calss rotatingAxis
}
}
...
\endverbatim
*
*/
class rotatingAxisMotion
{
public:
/** Motion model class to be passed to computational units/kernels for
* transfing points and returning velocities at various positions
*/
class Model
{
protected:
deviceViewType1D<rotatingAxis> axis_;
int32 numAxis_=0;
public:
INLINE_FUNCTION_HD
Model(deviceViewType1D<rotatingAxis> 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<rotatingAxis>;
/// 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<numAxis_; i++ )
{
axis_[i].setTime(t);
}
axis_.modifyOnHost();
axis_.syncViews();
return Model(axis_.deviceVector(), numAxis_);
}
/// Motion component name to index
INLINE_FUNCTION_H
int32 nameToIndex(const word& name)const
{
if( auto i = axisName_.findi(name); i == -1)
{
fatalErrorInFunction<<
"axis name " << name << " does not exist. \n";
fatalExit;
return i;
}
else
{
return i;
}
}
/// Motion index to motion component name
INLINE_FUNCTION_H
word indexToName(label i)const
{
if(i < numAxis_ )
return axisName_[i];
else
{
fatalErrorInFunction<<
"out of range access to the list of axes " << i <<endl<<
" size of axes_ is "<<numAxis_<<endl;
fatalExit;
return "";
}
}
/// Are walls moving
INLINE_FUNCTION_HD
bool isMoving()const
{
return true;
}
/// Move
INLINE_FUNCTION_H
bool move(real t, real dt)
{
return true;
}
// - IO operation
/// Read from input stream is
FUNCTION_H
bool read(iIstream& is);
/// Write to output stream os
FUNCTION_H
bool write(iOstream& os)const;
};
} // pFlow
#endif //__rotatingAxisMotion_hpp__

View File

@ -20,17 +20,30 @@ Licence:
#include "rotatingAxisMotion.hpp" #include "rotatingAxisMotion.hpp"
void pFlow::rotatingAxisMotion::impl_setTime
pFlow::rotatingAxisMotion::rotatingAxisMotion
( (
uint32 iter,
real t,
real dt
)const
{
auto motion = motionComponents_.deviceViewAll();
Kokkos::parallel_for(
"rotatingAxisMotion::impl_setTime",
deviceRPolicyStatic(0, numComponents_),
LAMBDA_HD(uint32 i){
motion[i].setTime(t);
});
Kokkos::fence();
}
pFlow::rotatingAxisMotion::rotatingAxisMotion(
const objectFile &objf, const objectFile &objf,
repository *owner repository *owner)
) : fileDictionary(objf, owner)
:
fileDictionary(objf, owner)
{ {
if(! getModel().impl_readDictionary(*this) ) if(! impl_readDictionary(*this) )
{ {
fatalErrorInFunction; fatalErrorInFunction;
fatalExit; fatalExit;
@ -46,7 +59,7 @@ pFlow::rotatingAxisMotion::rotatingAxisMotion
: :
fileDictionary(objf, dict, owner) fileDictionary(objf, dict, owner)
{ {
if(! getModel().impl_readDictionary(*this) ) if(!impl_readDictionary(*this) )
{ {
fatalErrorInFunction; fatalErrorInFunction;
fatalExit; fatalExit;

View File

@ -34,7 +34,7 @@ namespace pFlow
* *
* This class is used for simulaiton that at least one wall components * This class is used for simulaiton that at least one wall components
* is moving according to rotatingAxis motion mode. One or more than one * is moving according to rotatingAxis motion mode. One or more than one
* motion components can be defined in rotatingAxisMotionInfo dictionary * motion components can be defined in rotatingAxisInfo dictionary
* *
\verbatim \verbatim
// In geometryDict file, this will defines rotating walls during simulation // In geometryDict file, this will defines rotating walls during simulation
@ -63,11 +63,22 @@ class rotatingAxisMotion
{ {
protected: protected:
friend MotionModel<rotatingAxisMotion, rotatingAxis>;
/// is the geometry attached to this component moving
bool impl_isMoving()const bool impl_isMoving()const
{ {
return true; return true;
} }
/// move the component itself
bool impl_move(uint32, real, real)const
{
return true;
}
void impl_setTime(uint32 iter, real t, real dt)const;
public: public:
TypeInfo("rotatingAxisMotion"); TypeInfo("rotatingAxisMotion");

View File

@ -30,7 +30,7 @@ pFlow::stationaryWall::stationaryWall
fileDictionary(objf, owner) fileDictionary(objf, owner)
{ {
if(! getModel().impl_readDictionary(*this) ) if(!impl_readDictionary(*this) )
{ {
fatalErrorInFunction; fatalErrorInFunction;
fatalExit; fatalExit;
@ -46,7 +46,7 @@ pFlow::stationaryWall::stationaryWall
: :
fileDictionary(objf, dict, owner) fileDictionary(objf, dict, owner)
{ {
if(! getModel().impl_readDictionary(*this) ) if(!impl_readDictionary(*this) )
{ {
fatalErrorInFunction; fatalErrorInFunction;
fatalExit; fatalExit;

View File

@ -30,6 +30,26 @@ namespace pFlow
{ {
/**
* stationary model for walls
*
* This class is used for simulaiton that all wall components
* are fixed.
*
\verbatim
// In geometryDict file, this will defines stationary walls
...
motionModel stationary;
// this dictionary is optional
stationaryInfo
{
}
...
\endverbatim
*
*/
class stationaryWall class stationaryWall
: :
public fileDictionary, public fileDictionary,
@ -37,11 +57,21 @@ class stationaryWall
{ {
protected: protected:
friend MotionModel<stationaryWall, stationary>;
bool impl_isMoving()const bool impl_isMoving()const
{ {
return false; return false;
} }
bool impl_move(uint32, real, real)const
{
return true;
}
void impl_setTime(uint32 ,real ,real )const
{}
public: public:
TypeInfo("stationaryWall"); TypeInfo("stationaryWall");

View File

@ -1,167 +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.
-----------------------------------------------------------------------------*/
#include "vibratingMotion.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
bool pFlow::vibratingMotion::readDictionary
(
const dictionary& dict
)
{
auto motionModel = dict.getVal<word>("motionModel");
if(motionModel != "vibratingMotion")
{
fatalErrorInFunction<<
" motionModel should be vibratingMotion, but found "
<< motionModel <<endl;
return false;
}
auto& motionInfo = dict.subDict("vibratingMotionInfo");
auto compNames = motionInfo.dictionaryKeywords();
components_.reserve(compNames.size()+1);
components_.clear();
componentName_.clear();
for(auto& cName: compNames)
{
auto& compDict = motionInfo.subDict(cName);
if(auto compPtr = makeUnique<vibrating>(compDict); compPtr)
{
components_.push_back(compPtr());
componentName_.push_back(cName);
}
else
{
fatalErrorInFunction<<
"could not read vibrating motion from "<< compDict.globalName()<<endl;
return false;
}
}
if( !componentName_.search("none") )
{
components_.push_back
(
vibrating()
);
componentName_.push_back("none");
}
components_.syncViews();
numComponents_ = components_.size();
return true;
}
bool pFlow::vibratingMotion::writeDictionary
(
dictionary& dict
)const
{
dict.add("motionModel", "vibratingMotion");
auto& motionInfo = dict.subDictOrCreate("vibratingMotionInfo");
ForAll(i, components_)
{
auto& compDict = motionInfo.subDictOrCreate(componentName_[i]);
if( !components_.hostVectorAll()[i].write(compDict))
{
fatalErrorInFunction<<
" error in writing motion compoonent "<< componentName_[i] << " to dicrionary "
<< motionInfo.globalName()<<endl;
return false;
}
}
return true;
}
pFlow::vibratingMotion::vibratingMotion()
{}
pFlow::vibratingMotion::vibratingMotion
(
const dictionary& dict
)
{
if(! readDictionary(dict) )
{
fatalExit;
}
}
bool pFlow::vibratingMotion::read
(
iIstream& is
)
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
// read dictionary from stream
if( !motionInfo.read(is) )
{
ioErrorInFile(is.name(), is.lineNumber()) <<
" error in reading dictionray " << motionModelFile__ <<" from file. \n";
return false;
}
if( !readDictionary(motionInfo) ) return false;
return true;
}
bool pFlow::vibratingMotion::write
(
iOstream& os
)const
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
if( !writeDictionary(motionInfo))
{
return false;
}
if( !motionInfo.write(os) )
{
ioErrorInFile( os.name(), os.lineNumber() )<<
" error in writing dictionray to file. \n";
return false;
}
return true;
}

View File

@ -1,259 +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.
-----------------------------------------------------------------------------*/
#ifndef __vibratingMotion_hpp__
#define __vibratingMotion_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
#include "VectorDual.hpp"
#include "Vectors.hpp"
#include "List.hpp"
#include "vibrating.hpp"
namespace pFlow
{
// forward
class dictionary;
/**
* Vibrating motion model for walls
*
* This class is used for simulaiton that at least one wall components
* are moving according to a sinoidal viration defined in class vibrating.
* One or more than one motion components can be defined in
* vibratingMotionInfo dictionary
*
\verbatim
// In geometryDict file, this will defines vibrating walls during simulation
...
motionModel vibratingMotion;
vibratingMotionInfo
{
vibComponent1
{
// the definition based on class vibrating
}
vibComponent2
{
// the definition based on calss vibrating
}
}
...
\endverbatim
*
*/
class vibratingMotion
{
public:
/** Motion model class to be passed to computational units/kernels for
* transfing points and returning velocities at various positions
*/
class Model
{
protected:
deviceViewType1D<vibrating> components_;
int32 numComponents_=0;
public:
INLINE_FUNCTION_HD
Model(deviceViewType1D<vibrating> 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>;
/// 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<numComponents_; i++ )
{
components_[i].setTime(t);
}
components_.modifyOnHost();
components_.syncViews();
return Model(components_.deviceVectorAll(), numComponents_);
}
/// Name to component index
INLINE_FUNCTION_H
int32 nameToIndex(const word& name)const
{
if( auto i = componentName_.findi(name); i == -1)
{
fatalErrorInFunction<<
"component name " << name << " does not exist. \n";
fatalExit;
return i;
}
else
{
return i;
}
}
/// Index to name
INLINE_FUNCTION_H
word indexToName(label i)const
{
if(i < numComponents_ )
return componentName_[i];
else
{
fatalErrorInFunction<<
"out of range access to the list of axes " << i <<endl<<
" size of components_ is "<<numComponents_<<endl;
fatalExit;
return "";
}
}
/// velocity at point p according to motion component n
INLINE_FUNCTION_H
realx3 pointVelocity(label n, const realx3& p)const
{
return components_.hostVectorAll()[n].linTangentialVelocityPoint(p);
}
/// Transfer point p for dt seconds based on motion component n
INLINE_FUNCTION_H
realx3 transferPoint(label n, const realx3 p, real dt)const
{
return components_.hostVectorAll()[n].transferPoint(p, dt);
}
/// Is moving
INLINE_FUNCTION_HD
bool isMoving()const
{
return true;
}
/// Move ponits at time t for dt seconds
INLINE_FUNCTION_H
bool move(real t, real dt)
{
return true;
}
/// Read from input stream is
FUNCTION_H
bool read(iIstream& is);
/// Write to output stream os
FUNCTION_H
bool write(iOstream& os)const;
};
} // pFlow
#endif //__rotatingAxisMotion_hpp__

View File

@ -1,10 +1,28 @@
#include "vibratingMotion.hpp" #include "vibratingMotion.hpp"
void pFlow::vibratingMotion::impl_setTime
(
uint32 iter,
real t,
real dt
)const
{
auto motion = motionComponents_.deviceViewAll();
Kokkos::parallel_for(
"vibratingMotion::impl_setTime",
deviceRPolicyStatic(0, numComponents_),
LAMBDA_HD(uint32 i){
motion[i].setTime(t);
});
Kokkos::fence();
}
pFlow::vibratingMotion::vibratingMotion pFlow::vibratingMotion::vibratingMotion
( (
const objectFile &objf, const objectFile &objf,
repository *owner repository *owner
): )
:
fileDictionary(objf, owner) fileDictionary(objf, owner)
{ {
if(! getModel().impl_readDictionary(*this) ) if(! getModel().impl_readDictionary(*this) )

View File

@ -39,14 +39,14 @@ namespace pFlow
* This class is used for simulaiton that at least one wall components * This class is used for simulaiton that at least one wall components
* are moving according to a sinoidal viration defined in class vibrating. * are moving according to a sinoidal viration defined in class vibrating.
* One or more than one motion components can be defined in * One or more than one motion components can be defined in
* vibratingMotionInfo dictionary * vibratingInfo dictionary
* *
\verbatim \verbatim
// In geometryDict file, this will defines vibrating walls during simulation // In geometryDict file, this will defines vibrating walls during simulation
... ...
motionModel vibratingMotion; motionModel vibrating;
vibratingMotionInfo vibratingInfo
{ {
vibComponent1 vibComponent1
{ {
@ -69,11 +69,21 @@ class vibratingMotion
protected: protected:
friend MotionModel<vibratingMotion, vibrating>;
bool impl_isMoving()const bool impl_isMoving()const
{ {
return true; return true;
} }
/// move the component itself
bool impl_move(uint32, real, real)const
{
return true;
}
void impl_setTime(uint32 iter, real t, real dt)const;
public: public:
/// Type info /// Type info