sphereParticles tested

This commit is contained in:
Hamidreza Norouzi 2024-01-26 01:10:10 -08:00
parent 206df8924e
commit 0df384f546
16 changed files with 277 additions and 273 deletions

View File

@ -7,6 +7,7 @@ particles/particles.cpp
#particles/particleIdHandler.cpp
SphereParticles/sphereShape/sphereShape.cpp
SphereParticles/sphereParticles/sphereParticles.cpp
SphereParticles/sphereParticles/sphereParticlesKernels.cpp
#Insertion/shapeMixture/shapeMixture.cpp
#Insertion/insertion/insertion.cpp
#Insertion/Insertion/Insertions.cpp

View File

@ -21,9 +21,10 @@ Licence:
#include "sphereParticles.hpp"
#include "systemControl.hpp"
#include "vocabs.hpp"
//#include "setFieldList.hpp"
//#include "sphereParticlesKernels.hpp"
#include "sphereParticlesKernels.hpp"
//#include "setFieldList.hpp"
/*pFlow::uniquePtr<pFlow::List<pFlow::eventObserver*>>
pFlow::sphereParticles::getFieldObjectList()const
{
@ -205,14 +206,34 @@ bool pFlow::sphereParticles::initInertia()
exeSpace,
Kokkos::IndexType<uint32>>;
auto [minIndex, maxIndex] = minMax(shapeIndex().internal());
if( !spheres_.indexValid(maxIndex) )
{
fatalErrorInFunction<<
"the maximum value of shapeIndex is "<< maxIndex <<
" which is not valid."<<endl;
return false;
}
auto aPointsMask = dynPointStruct().activePointsMaskDevice();
auto aRange = aPointsMask.activeRange();
auto field_I = I_.fieldDevice();
auto field_shapeIndex = shapeIndex().fieldDevice();
auto field_diameter = diameter_.fieldDevice();
auto field_mass = mass_.fieldDevice();
auto field_propId = propertyId_.fieldDevice();
auto field_I = I_.fieldDevice();
const auto& shp = getShapes();
realVector_D I ("I", shp.Inertia());
// get info from spheres shape
realVector_D d("diameter", spheres_.boundingDiameter());
realVector_D mass("mass",spheres_.mass());
uint32Vector_D propId("propId", spheres_.shapePropertyIds());
realVector_D I("I", spheres_.Inertia());
auto d_d = d.deviceVector();
auto d_mass = mass.deviceVector();
auto d_propId = propId.deviceVector();
auto d_I = I.deviceVector();
Kokkos::parallel_for(
@ -224,9 +245,13 @@ bool pFlow::sphereParticles::initInertia()
{
uint32 index = field_shapeIndex[i];
field_I[i] = d_I[index];
field_diameter[i] = d_d[index];
field_mass[i] = d_mass[index];
field_propId[i] = d_propId[index];
}
});
Kokkos::fence();
return true;
}
@ -243,6 +268,38 @@ pFlow::sphereParticles::sphereParticles(
&control.caseSetup(),
prop
),
propertyId_
(
objectFile
(
"propertyId",
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
dynPointStruct(),
0u
),
diameter_
(
objectFile(
"diameter",
"",
objectFile::READ_NEVER,
objectFile::WRITE_NEVER),
dynPointStruct(),
0.00000000001
),
mass_
(
objectFile(
"mass",
"",
objectFile::READ_NEVER,
objectFile::WRITE_NEVER),
dynPointStruct(),
0.0000000001
),
I_
(
objectFile
@ -306,31 +363,10 @@ pFlow::sphereParticles::sphereParticles(
}
WARNING<<"setFields for rVelIntegration_"<<END_WARNING;
/*if(rVelIntegration_->needSetInitialVals())
{
auto [minInd, maxInd] = pStruct().activeRange();
int32IndexContainer indexHD(minInd, maxInd);
auto n = indexHD.size();
auto index = indexHD.indicesHost();
realx3Vector rvel(n,RESERVE());
const auto hrVel = rVelocity_.hostVector();
for(auto i=0; i<n; i++)
{
rvel.push_back( hrVel[index(i)]);
}
REPORT(2)<< "Initializing the required vectors for rotational velocity integratoin\n "<<endREPORT;
rVelIntegration_->setInitialVals(indexHD, rvel);
}*/
if(!initInertia())
{
fatalErrorInFunction;
fatalExit;
}
@ -437,18 +473,16 @@ bool pFlow::sphereParticles::iterate()
particles::iterate();
accelerationTimer_.start();
WARNING<<"pFlow::sphereParticlesKernels::acceleration"<<END_WARNING;
//INFO<<"before accelerationTimer_ "<<endINFO;
/*pFlow::sphereParticlesKernels::acceleration(
pFlow::sphereParticlesKernels::acceleration(
control().g(),
mass().deviceVectorAll(),
contactForce().deviceVectorAll(),
I().deviceVectorAll(),
contactTorque().deviceVectorAll(),
pStruct().activePointsMaskD(),
accelertion().deviceVectorAll(),
rAcceleration().deviceVectorAll()
);*/
mass().fieldDevice(),
contactForce().fieldDevice(),
I().fieldDevice(),
contactTorque().fieldDevice(),
dynPointStruct().activePointsMaskDevice(),
accelertion().fieldDevice(),
rAcceleration().fieldDevice()
);
accelerationTimer_.end();
intCorrectTimer_.start();
@ -485,3 +519,13 @@ const pFlow::shape &pFlow::sphereParticles::getShapes() const
{
return spheres_;
}
void pFlow::sphereParticles::boundingSphereMinMax
(
real & minDiam,
real& maxDiam
)const
{
minDiam = spheres_.minBoundingSphere();
maxDiam = spheres_.maxBoundingSphere();
}

View File

@ -51,6 +51,15 @@ private:
/// reference to shapes
ShapeType spheres_;
/// property id on device
uint32PointField_D propertyId_;
/// diameter / boundig sphere size of particles on device
realPointField_D diameter_;
/// mass of particles field
realPointField_D mass_;
/// pointField of inertial of particles
realPointField_D I_;
@ -151,6 +160,24 @@ public:
return false;
}
const uint32PointField_D& propertyId()const override
{
return propertyId_;
}
const realPointField_D& diameter()const override
{
return diameter_;
}
const realPointField_D& mass()const override
{
return mass_;
}
/// before iteration step
bool beforeIteration() override;
@ -179,6 +206,9 @@ public:
const shape& getShapes()const override;
void boundingSphereMinMax(real & minDiam, real& maxDiam)const override;
}; //sphereParticles
} // pFlow

View File

@ -0,0 +1,100 @@
/*------------------------------- 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 "sphereParticlesKernels.hpp"
using policy = Kokkos::RangePolicy<
pFlow::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32>>;
void pFlow::sphereParticlesKernels::addMassDiamInertiaProp
(
deviceViewType1D<uint32> shapeIndex,
deviceViewType1D<real> mass,
deviceViewType1D<real> diameter,
deviceViewType1D<real> I,
deviceViewType1D<uint32> propertyId,
pFlagTypeDevice incld,
deviceViewType1D<real> src_mass,
deviceViewType1D<real> src_diameter,
deviceViewType1D<real> src_I,
deviceViewType1D<uint32> src_propertyId
)
{
auto aRange = incld.activeRange();
Kokkos::parallel_for(
"particles::initInertia",
policy(aRange.start(), aRange.end()),
LAMBDA_HD(uint32 i)
{
if(incld(i))
{
uint32 index = shapeIndex[i];
I[i] = src_I[index];
diameter[i] = src_diameter[index];
mass[i] = src_mass[index];
propertyId[i] = src_propertyId[index];
}
});
}
void pFlow::sphereParticlesKernels::acceleration
(
realx3 g,
deviceViewType1D<real> mass,
deviceViewType1D<realx3> force,
deviceViewType1D<real> I,
deviceViewType1D<realx3> torque,
pFlagTypeDevice incld,
deviceViewType1D<realx3> lAcc,
deviceViewType1D<realx3> rAcc
)
{
auto activeRange = incld.activeRange();
if(incld.isAllActive())
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
policy(activeRange.start(), activeRange.end()),
LAMBDA_HD(uint32 i){
lAcc[i] = force[i]/mass[i] + g;
rAcc[i] = torque[i]/I[i];
});
}
else
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
policy(activeRange.start(), activeRange.end()),
LAMBDA_HD(uint32 i){
if(incld(i))
{
lAcc[i] = force[i]/mass[i] + g;
rAcc[i] = torque[i]/I[i];
}
});
}
Kokkos::fence();
}

View File

@ -21,56 +21,36 @@ Licence:
#ifndef __sphereParticlesKernels_hpp__
#define __sphereParticlesKernels_hpp__
#include "types.hpp"
#include "pointFlag.hpp"
namespace pFlow::sphereParticlesKernels
{
using rpAcceleration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>
>;
void addMassDiamInertiaProp(
deviceViewType1D<uint32> shapeIndex,
deviceViewType1D<real> mass,
deviceViewType1D<real> diameter,
deviceViewType1D<real> I,
deviceViewType1D<uint32> propertyId,
pFlagTypeDevice incld,
deviceViewType1D<real> src_mass,
deviceViewType1D<real> src_diameter,
deviceViewType1D<real> src_I,
deviceViewType1D<uint32> src_propertyId
);
template<typename IncludeFunctionType>
void acceleration(
realx3 g,
deviceViewType1D<real> mass,
deviceViewType1D<realx3> force,
deviceViewType1D<real> I,
deviceViewType1D<realx3> torque,
IncludeFunctionType incld,
pFlagTypeDevice incld,
deviceViewType1D<realx3> lAcc,
deviceViewType1D<realx3> rAcc
)
{
);
auto activeRange = incld.activeRange();
if(incld.allActive())
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
rpAcceleration(activeRange.first, activeRange.second),
LAMBDA_HD(int32 i){
lAcc[i] = force[i]/mass[i] + g;
rAcc[i] = torque[i]/I[i];
});
}
else
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
rpAcceleration(activeRange.first, activeRange.second),
LAMBDA_HD(int32 i){
if(incld(i))
{
lAcc[i] = force[i]/mass[i] + g;
rAcc[i] = torque[i]/I[i];
}
});
}
Kokkos::fence();
}
}

View File

@ -21,7 +21,7 @@ Licence:
#include "sphereShape.hpp"
bool pFlow::sphereShape::readDictionary()
bool pFlow::sphereShape::readFromDictionary3()
{
diameters_ = getVal<realVector>("diameters");
@ -61,6 +61,11 @@ pFlow::sphereShape::sphereShape
shape(fileName, owner, prop)
{
if(!readFromDictionary3())
{
fatalExit;
fatalErrorInFunction;
}
}
pFlow::real pFlow::sphereShape::maxBoundingSphere() const

View File

@ -26,8 +26,6 @@ Licence:
namespace pFlow
{
class sphereShape
:
public shape
@ -37,7 +35,7 @@ private:
// - diameter of spheres
realVector diameters_;
bool readDictionary();
bool readFromDictionary3();
protected:

View File

@ -76,37 +76,6 @@ pFlow::dynamicPointStructure::dynamicPointStructure
fatalExit;
}
WARNING << "Initialization of integrationPos_ and integrationVel_ should be doen!"<<END_WARNING;
/*if(!integrationPos_->needSetInitialVals()) return;
auto [minInd, maxInd] = pStruct().activeRange();
int32IndexContainer indexHD(minInd, maxInd);
auto n = indexHD.size();
auto index = indexHD.indicesHost();
realx3Vector pos(n,RESERVE());
realx3Vector vel(n,RESERVE());
const auto hVel = velocity().hostVector();
const auto hPos = pStruct().pointPosition().hostVector();
for(auto i=0; i<n; i++)
{
pos.push_back( hPos[index(i)]);
vel.push_back( hVel[index(i)]);
}
REPORT(2)<< "Initializing the required vectors for position integratoin "<<endREPORT;
integrationPos_->setInitialVals(indexHD, pos);
REPORT(2)<< "Initializing the required vectors for velocity integratoin\n "<<endREPORT;
integrationVel_->setInitialVals(indexHD, vel);*/
}
bool pFlow::dynamicPointStructure::predict

View File

@ -40,7 +40,7 @@ bool pFlow::baseShapeNames::createHashNames()
}
bool pFlow::baseShapeNames::readFromDictionary()
bool pFlow::baseShapeNames::readFromDictionary1()
{
shapeNames_ = getVal<wordVector>("names");
@ -69,18 +69,21 @@ pFlow::baseShapeNames::baseShapeNames
)
{
if( !readFromDictionary() )
if( !readFromDictionary1() )
{
fatalErrorInFunction;
fatalExit;
}
if( !createHashNames())
{
fatalErrorInFunction;
fatalExit;
}
}
bool pFlow::baseShapeNames::writeToDict(dictionary &dict)const
{

View File

@ -46,7 +46,7 @@ private:
bool createHashNames();
bool readFromDictionary();
bool readFromDictionary1();
protected:

View File

@ -21,60 +21,6 @@ Licence:
#include "particles.hpp"
bool pFlow::particles::initMassDiameter()const
{
auto [minIndex, maxIndex] = minMax(shapeIndex_.internal());
const auto& shp = getShapes();
if( !shp.indexValid(maxIndex) )
{
fatalErrorInFunction<<
"the maximum value of shape index is "<< maxIndex <<
" which is not valid."<<endl;
return false;
}
realVector_D d("diameter", shp.boundingDiameter());
realVector_D mass("mass",shp.mass());
uint8Vector_D propId("propId", shp.shapePropertyIds());
auto aPointsMask = dynPointStruct_.activePointsMaskDevice();
auto aRange = aPointsMask.activeRange();
using exeSpace = typename realPointField_D::execution_space;
using policy = Kokkos::RangePolicy<
exeSpace,
Kokkos::IndexType<uint32>>;
auto field_diameter = diameter_.fieldDevice();
auto field_mass = mass_.fieldDevice();
auto field_propId = propertyId_.fieldDevice();
auto field_shapeIndex = shapeIndex_.fieldDevice();
auto d_d = d.deviceVector();
auto d_mass = mass.deviceVector();
auto d_propId = propId.deviceVector();
Kokkos::parallel_for(
"particles::initMassDiameter",
policy(aRange.start(), aRange.end()),
LAMBDA_HD(uint32 i)
{
if(aPointsMask(i))
{
uint32 index = field_shapeIndex[i];
field_diameter[i] = d_d[index];
field_mass[i] = d_mass[index];
field_propId[i] = d_propId[index];
}
});
Kokkos::fence();
return true;
}
pFlow::particles::particles
(
@ -96,18 +42,6 @@ pFlow::particles::particles
dynPointStruct_,
static_cast<uint32>(-1)
),
propertyId_
(
objectFile
(
"propertyId",
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
dynPointStruct_,
static_cast<int8>(0)
),
shapeIndex_
(
objectFile
@ -120,26 +54,6 @@ pFlow::particles::particles
dynPointStruct_,
0
),
diameter_
(
objectFile(
"diameter",
"",
objectFile::READ_NEVER,
objectFile::WRITE_NEVER),
dynPointStruct_,
0.00000000001
),
mass_
(
objectFile(
"mass",
"",
objectFile::READ_NEVER,
objectFile::WRITE_NEVER),
dynPointStruct_,
0.0000000001
),
accelertion_
(
objectFile(
@ -167,14 +81,7 @@ pFlow::particles::particles
dynPointStruct_,
zero3)
{
this->addToSubscriber(dynPointStruct_);
if(!initMassDiameter())
{
fatalExit;
}
}
bool pFlow::particles::beforeIteration()

View File

@ -43,18 +43,9 @@ private:
/// id of particles on host
uint32PointField_D id_;
/// property id on device
uint8PointField_D propertyId_;
/// property id on device
uint32PointField_D shapeIndex_;
/// diameter / boundig sphere size of particles on device
realPointField_D diameter_;
/// mass of particles field
realPointField_D mass_;
/// acceleration on device
realx3PointField_D accelertion_;
@ -73,7 +64,6 @@ private:
message::ITEM_DELETE
);
bool initMassDiameter()const;
void zeroForce()
{
@ -152,29 +142,6 @@ public:
return dynPointStruct_.velocity();
}
inline
const auto& diameter()const
{
return diameter_;
}
inline
auto& diameter()
{
return diameter_;
}
inline
const auto& mass()const
{
return mass_;
}
inline auto& mass()
{
return mass_;
}
inline
const auto& accelertion()const
{
@ -211,18 +178,6 @@ public:
return contactTorque_;
}
inline
const auto& propertyId()const
{
return propertyId_;
}
inline
auto& propertyId()
{
return propertyId_;
}
bool beforeIteration() override;
bool iterate()override;
@ -237,7 +192,14 @@ public:
const setFieldList& setField
) = 0;*/
virtual
const uint32PointField_D& propertyId()const = 0;
virtual
const realPointField_D& diameter()const = 0;
virtual
const realPointField_D& mass()const = 0;
virtual
realx3PointField_D& rAcceleration() = 0;
@ -255,7 +217,7 @@ public:
const shape& getShapes()const = 0;
virtual
void boundingSphereMinMax(real & minDiam, real& maxDiam)const;
void boundingSphereMinMax(real & minDiam, real& maxDiam)const = 0;

View File

@ -7,10 +7,9 @@ bool pFlow::shape::findPropertyIds()
ForAll( i, materialNames_)
{
if(uint32 propId; property_.nameToIndex(materialNames_[i], propId) )
{
shapePropertyIds_[i] = static_cast<uint8>(propId);
shapePropertyIds_[i] = propId;
}
else
{
@ -19,10 +18,10 @@ bool pFlow::shape::findPropertyIds()
return false;
}
}
return false;
return true;
}
bool pFlow::shape::readFromDictionary()
bool pFlow::shape::readFromDictionary2()
{
materialNames_ = getVal<wordVector>("materials");
@ -49,13 +48,15 @@ pFlow::shape::shape
property_(prop)
{
if( !readFromDictionary() )
if( !readFromDictionary2() )
{
fatalErrorInFunction;
fatalExit;
}
if(!findPropertyIds())
{
fatalErrorInFunction;
fatalExit;
}

View File

@ -37,7 +37,7 @@ private:
const property& property_;
/// list of property ids of shapes (index)
uint8Vector shapePropertyIds_;
uint32Vector shapePropertyIds_;
/// list of material names
wordVector materialNames_;
@ -45,7 +45,7 @@ private:
bool findPropertyIds();
bool readFromDictionary();
bool readFromDictionary2();
protected:
@ -96,7 +96,7 @@ public:
}
inline
bool propIdValid(int8 propId)const
bool propIdValid(uint32 propId)const
{
return static_cast<uint32>(propId) < property_.numMaterials();
}

View File

@ -130,13 +130,16 @@ bool pFlow::readDataAscii
token firstToken(is);
size_t len = 0;
bool lenFound = false;
if( firstToken.isInt64())
{
len = firstToken.int64Token();
lenFound = true;
vec.reserve(len);
firstToken = token(is);
}
T val{};
if( firstToken.isPunctuation() ) // start of vector
{
@ -164,6 +167,7 @@ bool pFlow::readDataAscii
is >> lastToken;
is.fatalCheck(FUNCTION_NAME);
}
} else
@ -174,7 +178,7 @@ bool pFlow::readDataAscii
return false;
}
if(len>0&& len != vec.size())
if(lenFound && len>0 && len != vec.size())
{
warningInFunction<<"vector length specified "<< len <<
" is different from number of elements "<< vec.size()<<endl;