MotionModel CRTP, rotatingAxis and vibrating

This commit is contained in:
Hamidreza Norouzi 2024-02-04 23:58:57 -08:00
parent fd039f234f
commit 80b61d4d73
25 changed files with 1463 additions and 711 deletions

View File

@ -9,7 +9,7 @@ add_subdirectory(Particles)
#add_subdirectory(Interaction)
#add_subdirectory(MotionModel)
add_subdirectory(MotionModel)
#add_subdirectory(Geometry)

View File

@ -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)

View File

@ -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<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_nameToIndex(const word& name, uint32& indx)const
{
if( auto i = componentNames_.findi(name); i == -1)
{
return false;
}
else
{
indx = static_cast<uint32>(i);
return true;
}
}
template<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_indexToName(uint32 i, word& name)const
{
if(i < numComponents_ )
{
name = componentNames_[i];
return true;
}
else
{
return false;
}
}
template<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_readDictionary
(
const dictionary& dict
)
{
auto modelName = dict.getVal<word>("motionModel");
if(modelName != getTypeName<ModelComponent>())
{
fatalErrorInFunction<<
" motionModel should be "<< Yellow_Text(getTypeName<ModelComponent>())<<
", but found "<< Yellow_Text(modelName)<<endl;
return false;
}
auto& motionInfo = dict.subDict(modelName+"Info");
auto compNames = motionInfo.dictionaryKeywords();
Vector<ModelComponent> components(
"Read::modelComponent",
compNames.size()+1,
0,
RESERVE());
componentNames_.clear();
for(auto& cName: compNames)
{
auto& compDict = motionInfo.subDict(cName);
if(auto compPtr = makeUnique<ModelComponent>(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<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_writeDictionary
(
dictionary& dict
)const
{
word modelName = getTypeName<ModelComponent>();
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()<<endl;
return false;
}
}
return true;
}
template<typename Model, typename Component>
pFlow::MotionModel<Model, Component>::MotionModel()
:
motionComponents_("motionComponents")
{}

View File

@ -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<typename Model, typename Component>
class MotionModel
{
public:
using ModelType = Model;
using ModelComponent = Component;
using ComponentVector_D = VectorSingle<ModelComponent>;
/** Motion model class to be passed to computational units/kernels for
* transfing points and returning velocities at various positions
*/
class ModelInterface
{
private:
deviceViewType1D<ModelComponent> components_;
uint32 numComponents_=0;
public:
INLINE_FUNCTION_HD
ModelInterface
(
deviceViewType1D<ModelComponent> 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<ModelType&>(*this);
}
inline
const auto& getModel()const
{
return static_cast<const ModelType&>(*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<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
bool nameToIndex(const word& name, uint32& idx)const
{
return getModel().impl_nameToIndex(name, idx);
}
/// Component index to motion component name
bool indexToName(uint32 idx, word& name)const
{
return getModel().impl_indexToName(idx, name);
}
/// Are walls moving
bool isMoving()const
{
return getModel().impl_isMoving();
}
/// Move
bool move(uint32 iter, real t, real dt)
{
return getModel().impl_move(iter, t, dt);
}
auto getModelInterface(uint32 iter, real t, real dt)const
{
return getModel().impl_getModelInterface(iter, t, dt);
}
};
} // pFlow
#include "MotionModel.cpp"
#endif //__MotionModel_hpp__

View File

@ -28,7 +28,6 @@ pFlow::rotatingAxis::rotatingAxis
const dictionary& dict
)
{
if(!read(dict))
{
fatalErrorInFunction<<
@ -73,7 +72,7 @@ bool pFlow::rotatingAxis::read
if(!timeInterval::read(dict))return false;
if(!line::read(dict)) return false;
real omega = dict.getValOrSet("omega", static_cast<real>(0.0));
real omega = dict.getValOrSet("omega", 0.0);
setOmega(omega);
return true;

View File

@ -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

View File

@ -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);
}

View File

@ -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<n; i++ )
for(uint32 i=0; i<n; i++ )
{
res.x_ = (lp1.x_*(v2 + w2) - (nv.x_*(lp1.y_*nv.y_ + lp1.z_*nv.z_ - nv.x_*p[i].x_ - nv.y_*p[i].y_ - nv.z_*p[i].z_)))*(1 - cos_tet) +
p[i].x_ * cos_tet +
@ -133,7 +140,7 @@ void pFlow::rotate(realx3* p, size_t n, const line& ln, real theta)
}
INLINE_FUNCTION_HD
void pFlow::rotate(realx3* p, size_t n, const rotatingAxis& ax, real dt)
void pFlow::rotate(realx3* p, uint32 n, const rotatingAxis& ax, real dt)
{
if(!ax.inTimeRange()) return;
@ -148,7 +155,7 @@ void pFlow::rotate(realx3* p, size_t n, const rotatingAxis& ax, real dt)
// (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<n; i++ )
for(uint32 i=0; i<n; i++ )
{
res.x_ = (lp1.x_*(v2 + w2) - (nv.x_*(lp1.y_*nv.y_ + lp1.z_*nv.z_ - nv.x_*p[i].x_ - nv.y_*p[i].y_ - nv.z_*p[i].z_)))*(1 - cos_tet) +
p[i].x_ * cos_tet +

View File

@ -67,7 +67,7 @@ class vibrating
public timeInterval
{
protected:
private:
// rotation speed
realx3 angularFreq_{0,0,0};
@ -95,10 +95,10 @@ protected:
public:
FUNCTION_HD
vibrating(){}
vibrating()=default;
FUNCTION_H
vibrating(const dictionary& dict);
explicit vibrating(const dictionary& dict);
FUNCTION_HD
@ -115,7 +115,7 @@ public:
}
INLINE_FUNCTION_HD
realx3 linTangentialVelocityPoint(const realx3 &p)const
realx3 linTangentialVelocityPoint(const realx3 &)const
{
return velocity_;
}
@ -124,7 +124,7 @@ public:
realx3 transferPoint(const realx3& p, real dt)
{
if(!inTimeRange()) return p;
return p + static_cast<real>(0.5)*dt*(velocity0_+velocity_);
return p + 0.5*dt*(velocity0_+velocity_);
}
// - IO operation

View File

@ -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<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

@ -0,0 +1,247 @@
/*------------------------------- 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

@ -19,152 +19,41 @@ Licence:
-----------------------------------------------------------------------------*/
#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
const objectFile &objf,
repository *owner
)
:
fileDictionary(objf, owner)
{
if(! readDictionary(dict) )
if(! getModel().impl_readDictionary(*this) )
{
fatalErrorInFunction;
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
iOstream &os,
const IOPattern &iop
) const
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
if( !writeDictionary(motionInfo))
// a global dictionary
dictionary newDict(fileDictionary::dictionary::name(), true);
if( iop.thisProcWriteData() )
{
return false;
if( !this->impl_writeDictionary(newDict) ||
!newDict.write(os))
{
fatalErrorInFunction<<
" error in writing to dictionary "<< newDict.globalName()<<endl;
return false;
}
}
if( !motionInfo.write(os) )
{
ioErrorInFile( os.name(), os.lineNumber() )<<
" error in writing dictionray to file. \n";
return false;
}
return true;
}
return true;
}

View File

@ -22,19 +22,13 @@ Licence:
#define __rotatingAxisMotion_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
#include "VectorDual.hpp"
#include "Vectors.hpp"
#include "List.hpp"
#include "MotionModel.hpp"
#include "rotatingAxis.hpp"
#include "fileDictionary.hpp"
namespace pFlow
{
class dictionary;
/**
* Rotating axis motion model for walls
*
@ -45,9 +39,9 @@ class dictionary;
\verbatim
// In geometryDict file, this will defines rotating walls during simulation
...
motionModel rotatingAxisMotion;
motionModel rotatingAxis;
rotatingAxisMotionInfo
rotatingAxisInfo
{
rotationAxis1
{
@ -63,185 +57,34 @@ rotatingAxisMotionInfo
*
*/
class rotatingAxisMotion
:
public fileDictionary,
public MotionModel<rotatingAxisMotion, rotatingAxis>
{
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_;
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<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;
bool write(iOstream& os, const IOPattern& iop)const override;
static
auto noneComponent()
{
return rotatingAxis({0,0,0}, {1,0,0}, 0.0);
}
};
} // pFlow
#endif //__rotatingAxisMotion_hpp__
#endif // __rotatingAxisMotion_hpp__

View File

@ -0,0 +1,167 @@
/*------------------------------- 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

@ -0,0 +1,259 @@
/*------------------------------- 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,167 +1,32 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#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
)
const objectFile &objf,
repository *owner
):
fileDictionary(objf, owner)
{
if(! readDictionary(dict) )
if(! getModel().impl_readDictionary(*this) )
{
fatalErrorInFunction;
fatalExit;
}
}
bool pFlow::vibratingMotion::read
(
iIstream& is
)
bool pFlow::vibratingMotion::write(iOstream &os, const IOPattern &iop) const
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
// read dictionary from stream
if( !motionInfo.read(is) )
// a global dictionary
dictionary newDict(fileDictionary::dictionary::name(), true);
if( iop.thisProcWriteData() )
{
ioErrorInFile(is.name(), is.lineNumber()) <<
" error in reading dictionray " << motionModelFile__ <<" from file. \n";
return false;
if( !getModel().impl_writeDictionary(newDict) ||
!newDict.write(os))
{
fatalErrorInFunction<<
" error in writing to dictionary "<< newDict.globalName()<<endl;
return false;
}
}
if( !readDictionary(motionInfo) ) return false;
return true;
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

@ -22,20 +22,16 @@ Licence:
#define __vibratingMotion_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
#include "VectorDual.hpp"
#include "Vectors.hpp"
#include "List.hpp"
#include "MotionModel.hpp"
#include "vibrating.hpp"
#include "fileDictionary.hpp"
namespace pFlow
{
// forward
class dictionary;
/**
* Vibrating motion model for walls
@ -66,194 +62,39 @@ vibratingMotionInfo
*
*/
class vibratingMotion
:
public fileDictionary,
public MotionModel<vibratingMotion, vibrating>
{
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;
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<numComponents_; i++ )
{
components_[i].setTime(t);
}
components_.modifyOnHost();
components_.syncViews();
bool write(iOstream& os, const IOPattern& iop)const override;
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;
static
auto noneComponent()
{
return vibrating();
}
};
} // pFlow
#endif //__rotatingAxisMotion_hpp__
#endif //__vibratingMotion_hpp__

View File

@ -28,8 +28,6 @@ Licence:
namespace pFlow
{
// forward
class dictionary;
/**
* property holds the pure properties of materials.

View File

@ -40,12 +40,14 @@ public:
ITEM_DELETE = 3,
ITEM_INSERT = 4,
RANGE_CHANGED = 5,
ITEM_REARRANGE = 6
ITEM_REARRANGE = 6,
ITEM_TRANSFER = 7,
RESET_COUNTERS = 8
};
protected:
static constexpr size_t numberOfEvents_ = 8;
static constexpr size_t numberOfEvents_ = 9;
std::bitset<numberOfEvents_> events_{0x0000};

View File

@ -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

View File

@ -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()

View File

@ -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; i<observerList_.size(); i++)
{
for( auto obsvr: observerList_[i] )
{
if(obsvr) obsvr->changeSubscriber(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; i<observerList_.size(); i++)
{
for( auto obsvr: observerList_[i] )
{
if(obsvr) obsvr->changeSubscriber(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
)

View File

@ -35,7 +35,7 @@ class anyList;
class subscriber
{
protected:
private:
// - list of subsribed objectd that recieve updage messages
mutable std::array<List<observer*>,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<eventObserver*>& exclutionList );
bool notify(
uint32 iter,
real t,
real dt,
uint32 iter,
const message msg,
const anyList& varList);

View File

@ -160,7 +160,8 @@ pFlow::multiTriSurface::multiTriSurface
repository *owner
)
:
triSurface(obj, owner)
triSurface(obj, owner),
subscriber("multiTriSurface")
{
if( !IOobject::readObject() )
{

View File

@ -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;