mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-08-17 03:47:04 +00:00
Multirotating axis motion for version 1.0
This commit is contained in:
@ -31,19 +31,179 @@ void pFlow::multiRotatingAxisMotion::impl_setTime
|
||||
Kokkos::parallel_for(
|
||||
"multiRotatingAxisMotion::impl_setTime",
|
||||
deviceRPolicyStatic(0, numComponents_),
|
||||
LAMBDA_HD(uint32 i){
|
||||
LAMBDA_D(uint32 i){
|
||||
motion[i].setTime(t);
|
||||
});
|
||||
Kokkos::fence();
|
||||
}
|
||||
|
||||
bool pFlow::multiRotatingAxisMotion::impl_move(uint32 iter, real t , real dt ) const
|
||||
{
|
||||
|
||||
auto motion = motionComponents_.deviceViewAll();
|
||||
Kokkos::parallel_for(
|
||||
"multiRotatingAxisMotion::impl_move",
|
||||
deviceRPolicyStatic(0, numComponents_),
|
||||
LAMBDA_D(uint32 i){
|
||||
motion[i].move(dt);
|
||||
});
|
||||
Kokkos::fence();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::multiRotatingAxisMotion::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();
|
||||
|
||||
wordList rotationAxisNames;
|
||||
|
||||
|
||||
// in the first round read all dictionaries
|
||||
for(auto& compName: compNames)
|
||||
{
|
||||
auto& axDict = motionInfo.subDict(compName);
|
||||
|
||||
if(auto axPtr = makeUnique<rotatingAxis>(axDict); axPtr)
|
||||
{
|
||||
rotationAxisNames.push_back(
|
||||
axDict.getValOrSet<word>("rotationAxis", "none"));
|
||||
}
|
||||
else
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"could not read rotating axis from "<< axDict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( !compNames.search("none") )
|
||||
{
|
||||
compNames.push_back("none");
|
||||
rotationAxisNames.push_back("none");
|
||||
}
|
||||
|
||||
using intPair = std::pair<int32, int32>;
|
||||
|
||||
std::vector<intPair> numRotAxis;
|
||||
|
||||
for(size_t i=0; i< compNames.size(); i++)
|
||||
{
|
||||
word rotAxis = rotationAxisNames[i];
|
||||
int32 n=0;
|
||||
while(rotAxis != "none")
|
||||
{
|
||||
n++;
|
||||
if(int32 iAxis = compNames.findi(rotAxis) ; iAxis != -1)
|
||||
{
|
||||
rotAxis = rotationAxisNames[iAxis];
|
||||
}else
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"rotation axis name "<< rotAxis << "is does not exist!"<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
numRotAxis.push_back({n,i});
|
||||
}
|
||||
|
||||
auto compareFunc = [](const intPair& a, const intPair& b)
|
||||
{ return a.first > b.first; };
|
||||
|
||||
std::sort(numRotAxis.begin(), numRotAxis.end(), compareFunc);
|
||||
Vector<int> sortedIndex;
|
||||
componentNames_.clear();
|
||||
|
||||
output<<compNames<<endl;
|
||||
|
||||
for(auto ax:numRotAxis)
|
||||
{
|
||||
componentNames_.push_back(compNames[ax.second]);
|
||||
sortedIndex.push_back(ax.second);
|
||||
}
|
||||
|
||||
numComponents_ = componentNames_.size();
|
||||
motionComponents_.reserve(numComponents_);
|
||||
sortedIndex_.assign(sortedIndex);
|
||||
|
||||
Vector<ModelComponent> components("Read::modelComponent",
|
||||
compNames.size()+1,
|
||||
0,
|
||||
RESERVE());
|
||||
|
||||
|
||||
for(auto& compName: componentNames_)
|
||||
{
|
||||
|
||||
if(compName != "none")
|
||||
{
|
||||
auto& compDict = motionInfo.subDict(compName);
|
||||
components.emplace_back(
|
||||
motionComponents_.data(),
|
||||
componentNames_,
|
||||
compDict);
|
||||
}
|
||||
else
|
||||
{
|
||||
components.emplace_back(impl_noneComponent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
motionComponents_.assign(components);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::multiRotatingAxisMotion::impl_writeDictionary
|
||||
(
|
||||
dictionary& dict
|
||||
)const
|
||||
{
|
||||
word modelName = "multiRotatingAxis";
|
||||
|
||||
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, componentNames_))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in writing axis "<< componentNames_[i] << " to dicrionary "
|
||||
<< motionInfo.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pFlow::multiRotatingAxisMotion::multiRotatingAxisMotion(
|
||||
const objectFile &objf,
|
||||
repository *owner)
|
||||
: fileDictionary(objf, owner)
|
||||
{
|
||||
|
||||
if(! impl_readDictionary(*this) )
|
||||
if(! getModel().impl_readDictionary(*this) )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
fatalExit;
|
||||
@ -59,7 +219,7 @@ pFlow::multiRotatingAxisMotion::multiRotatingAxisMotion
|
||||
:
|
||||
fileDictionary(objf, dict, owner)
|
||||
{
|
||||
if(!impl_readDictionary(*this) )
|
||||
if(!getModel().impl_readDictionary(*this) )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
fatalExit;
|
||||
@ -76,7 +236,7 @@ bool pFlow::multiRotatingAxisMotion::write
|
||||
dictionary newDict(fileDictionary::dictionary::name(), true);
|
||||
if( iop.thisProcWriteData() )
|
||||
{
|
||||
if( !this->impl_writeDictionary(newDict) ||
|
||||
if( !getModel().impl_writeDictionary(newDict) ||
|
||||
!newDict.write(os))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
|
Reference in New Issue
Block a user