Doc for Geometry added

This commit is contained in:
Hamidreza Norouzi 2023-04-13 11:42:41 -07:00
parent c34c55bdde
commit 1fe2256079
5 changed files with 198 additions and 131 deletions

View File

@ -27,13 +27,16 @@ Licence:
namespace pFlow namespace pFlow
{ {
/** base for geometry that manages control
*
*/
class demGeometry class demGeometry
: :
public demComponent public demComponent
{ {
public: public:
demGeometry(systemControl& control) demGeometry(systemControl& control)
: :
demComponent("geometry", control) demComponent("geometry", control)

View File

@ -190,7 +190,7 @@ pFlow::geometry::geometry
objectFile( objectFile(
"contactForceWall", "contactForceWall",
"", "",
objectFile::READ_IF_PRESENT, objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS), objectFile::WRITE_ALWAYS),
surface(), surface(),
zero3) ), zero3) ),
@ -199,7 +199,7 @@ pFlow::geometry::geometry
objectFile( objectFile(
"stressWall", "stressWall",
"", "",
objectFile::READ_IF_PRESENT, objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS), objectFile::WRITE_ALWAYS),
surface(), surface(),
zero3) ) zero3) )
@ -271,6 +271,33 @@ pFlow::uniquePtr<pFlow::geometry>
return nullptr; return nullptr;
} }
bool pFlow::geometry::beforeIteration()
{
this->zeroForce();
return true;
}
bool pFlow::geometry::afterIteration()
{
auto Force = contactForceWall_.deviceVectorAll();
auto area = triSurface_.area().deviceVectorAll();
auto stress = stressWall_.deviceVectorAll();
auto numTri =triSurface_.size();
Kokkos::parallel_for(
"geometry::calculateStress",
numTri,
LAMBDA_HD(int32 i){
stress[i] = Force[i]/area[i];
});
Kokkos::fence();
return true;
}
pFlow::uniquePtr<pFlow::geometry> pFlow::uniquePtr<pFlow::geometry>
pFlow::geometry::create( pFlow::geometry::create(
systemControl& control, systemControl& control,

View File

@ -34,34 +34,51 @@ Licence:
namespace pFlow namespace pFlow
{ {
/**
* Base class for geometry for managing tri-surfaces, geometry motion,
* and surface physical properties.
*
*/
class geometry class geometry
: :
public demGeometry public demGeometry
{ {
protected: protected:
// - Protected members
/// Const reference to physical property of materials
const property& wallProperty_; const property& wallProperty_;
// - this object is owned by geometryRepository_ /// Repository to store geometry data at each simulation moment
repository& geometryRepository_; repository& geometryRepository_;
// all triangles of walls /// All triangles in the set of wall surfaces
multiTriSurface& triSurface_; multiTriSurface& triSurface_;
// /// The name of motion component of each wall surface
wordField& motionComponentName_; wordField& motionComponentName_;
// /// Material name of each wall surface
wordField& materialName_; wordField& materialName_;
/// Property id of each triangle in the set of wall surfaces
int8TriSurfaceField_D& propertyId_; int8TriSurfaceField_D& propertyId_;
/// Contact force on each triangle in the set of wall surfaces
realx3TriSurfaceField_D& contactForceWall_; realx3TriSurfaceField_D& contactForceWall_;
/// Stress on ech triangle in the set of wall surfaces
realx3TriSurfaceField_D& stressWall_; realx3TriSurfaceField_D& stressWall_;
// - Protected member functions
/// Find property id of each triangle based on the supplied material name
/// and the surface wall that the triangle belongs to.
bool findPropertyId(); bool findPropertyId();
/// Initialize contact force to zero
void zeroForce() void zeroForce()
{ {
contactForceWall_.fill(zero3); contactForceWall_.fill(zero3);
@ -70,15 +87,15 @@ protected:
public: public:
// - type info /// Type info
TypeInfo("geometry"); TypeInfo("geometry");
//// - Constructors // - Constructors
// - empty /// Construct from controlSystem and property, for reading from file
geometry(systemControl& control, const property& prop); geometry(systemControl& control, const property& prop);
// - from components /// Construct from components
geometry(systemControl& control, geometry(systemControl& control,
const property& prop, const property& prop,
const multiTriSurface& triSurface, const multiTriSurface& triSurface,
@ -86,6 +103,8 @@ public:
const wordVector& propName const wordVector& propName
); );
/// Construct from components and dictionary that contains
/// motionModel
geometry(systemControl& control, geometry(systemControl& control,
const property& prop, const property& prop,
const dictionary& dict, const dictionary& dict,
@ -93,9 +112,10 @@ public:
const wordVector& motionCompName, const wordVector& motionCompName,
const wordVector& propName); const wordVector& propName);
/// Destructor
virtual ~geometry() = default; virtual ~geometry() = default;
/// Virtual constructor
create_vCtor create_vCtor
( (
geometry, geometry,
@ -107,6 +127,7 @@ public:
(control, prop) (control, prop)
); );
/// Virtual constructor
create_vCtor create_vCtor
( (
geometry, geometry,
@ -120,135 +141,135 @@ public:
(control, prop, dict, triSurface, motionCompName, propName) (control, prop, dict, triSurface, motionCompName, propName)
); );
////- Methods //- Methods
/// Size of tri-surface
inline inline
auto size()const auto size()const
{ {
return triSurface_.size(); return triSurface_.size();
} }
/// Number of points in the set of surface walls
inline inline
auto numPoints()const auto numPoints()const
{ {
return triSurface_.numPoints(); return triSurface_.numPoints();
} }
/// Number of triangles in the set of surface walls
inline inline
auto numTriangles()const auto numTriangles()const
{ {
return size(); return size();
} }
/// Access to the points
inline inline
const auto& points()const const auto& points()const
{ {
return triSurface_.points(); return triSurface_.points();
} }
/// Access to the vertices
inline inline
const auto& vertices()const const auto& vertices()const
{ {
return triSurface_.vertices(); return triSurface_.vertices();
} }
/// Obtain an object for accessing triangles
inline auto getTriangleAccessor()const inline auto getTriangleAccessor()const
{ {
return triSurface_.getTriangleAccessor(); return triSurface_.getTriangleAccessor();
} }
/// Surface
inline auto& surface() inline auto& surface()
{ {
return triSurface_; return triSurface_;
} }
/// Surface
inline const auto& surface()const inline const auto& surface()const
{ {
return triSurface_; return triSurface_;
} }
/// Access to contact force
inline inline
realx3TriSurfaceField_D& contactForceWall() realx3TriSurfaceField_D& contactForceWall()
{ {
return contactForceWall_; return contactForceWall_;
} }
/// Access to contact force
inline inline
const realx3TriSurfaceField_D& contactForceWall() const const realx3TriSurfaceField_D& contactForceWall() const
{ {
return contactForceWall_; return contactForceWall_;
} }
/// Access to property
inline const auto& wallProperty()const inline const auto& wallProperty()const
{ {
return wallProperty_; return wallProperty_;
} }
// owner repository /// Owner repository
inline inline
const repository& owner()const const repository& owner()const
{ {
return geometryRepository_; return geometryRepository_;
} }
/// Owner repository
inline inline
repository& owner() repository& owner()
{ {
return geometryRepository_; return geometryRepository_;
} }
/// Path to the repository folder
inline auto path() inline auto path()
{ {
return owner().path(); return owner().path();
} }
/// The name of motion model
virtual virtual
word motionModelTypeName()const = 0; word motionModelTypeName()const = 0;
/// Motion model index of triangles
virtual virtual
const int8Vector_HD& triMotionIndex() const =0; const int8Vector_HD& triMotionIndex() const =0;
/// Motion model index of points
virtual virtual
const int8Vector_HD& pointMotionIndex()const = 0; const int8Vector_HD& pointMotionIndex()const = 0;
/// Property ide of triangles
const int8TriSurfaceField_D& propertyId() const const int8TriSurfaceField_D& propertyId() const
{ {
return propertyId_; return propertyId_;
} }
bool beforeIteration() override { /// Operations before each iteration
bool beforeIteration() override;
this->zeroForce(); /// Operations after each iteration
return true; bool afterIteration() override;
} //- IO
bool afterIteration() override {
auto Force = contactForceWall_.deviceVectorAll();
auto area = triSurface_.area().deviceVectorAll();
auto stress = stressWall_.deviceVectorAll();
auto numTri =triSurface_.size();
Kokkos::parallel_for(
"geometry::calculateStress",
numTri,
LAMBDA_HD(int32 i){
stress[i] = Force[i]/area[i];
});
Kokkos::fence();
return true;
}
/// write
bool write()const bool write()const
{ {
return owner().write(); return owner().write();
} }
// static //- Static members
static static
uniquePtr<geometry> create(systemControl& control, const property& prop); uniquePtr<geometry> create(systemControl& control, const property& prop);

View File

@ -18,38 +18,6 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::moveGeometry()
{
real dt = this->dt();
real t = this->currentTime();
auto pointMIndex= pointMotionIndex_.deviceVector();
auto mModel = motionModel_.getModel(t);
realx3* points = triSurface_.pointsData_D();
auto numPoints = triSurface_.numPoints();
Kokkos::parallel_for(
"geometryMotion<MotionModel>::movePoints",
numPoints,
LAMBDA_HD(int32 i){
auto newPos = mModel.transferPoint(pointMIndex[i], points[i], dt);
points[i] = newPos;
});
Kokkos::fence();
// move the motion components
motionModel_.move(t,dt);
// end of calculations
moveGeomTimer_.end();
return true;
}
template<typename MotionModel> template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::findMotionIndex() bool pFlow::geometryMotion<MotionModel>::findMotionIndex()
{ {
@ -88,6 +56,7 @@ bool pFlow::geometryMotion<MotionModel>::findMotionIndex()
return true; return true;
} }
template<typename MotionModel> template<typename MotionModel>
pFlow::geometryMotion<MotionModel>::geometryMotion pFlow::geometryMotion<MotionModel>::geometryMotion
( (
@ -180,6 +149,13 @@ pFlow::geometryMotion<MotionModel>::geometryMotion
findMotionIndex(); findMotionIndex();
} }
template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::beforeIteration()
{
geometry::beforeIteration();
return true;
}
template<typename MotionModel> template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::iterate() bool pFlow::geometryMotion<MotionModel>::iterate()
{ {
@ -191,3 +167,42 @@ bool pFlow::geometryMotion<MotionModel>::iterate()
} }
return true; return true;
} }
template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::afterIteration()
{
geometry::afterIteration();
return true;
}
template<typename MotionModel>
bool pFlow::geometryMotion<MotionModel>::moveGeometry()
{
real dt = this->dt();
real t = this->currentTime();
auto pointMIndex= pointMotionIndex_.deviceVector();
auto mModel = motionModel_.getModel(t);
realx3* points = triSurface_.pointsData_D();
auto numPoints = triSurface_.numPoints();
Kokkos::parallel_for(
"geometryMotion<MotionModel>::movePoints",
numPoints,
LAMBDA_HD(int32 i){
auto newPos = mModel.transferPoint(pointMIndex[i], points[i], dt);
points[i] = newPos;
});
Kokkos::fence();
// move the motion components
motionModel_.move(t,dt);
// end of calculations
moveGeomTimer_.end();
return true;
}

View File

@ -17,8 +17,6 @@ Licence:
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#ifndef __geometryMotion_hpp__ #ifndef __geometryMotion_hpp__
#define __geometryMotion_hpp__ #define __geometryMotion_hpp__
@ -29,7 +27,11 @@ Licence:
namespace pFlow namespace pFlow
{ {
/**
* A class that represent surfaces in the simulation and moves surfaces
* based on the MotionModelType. MotionModelType can be any motion model.
*
*/
template<typename MotionModelType> template<typename MotionModelType>
class geometryMotion class geometryMotion
: :
@ -41,34 +43,34 @@ public:
protected: protected:
/// Ref to motion model
MotionModel& motionModel_; MotionModel& motionModel_;
// motion indext mapped on each surface /// motion indext mapped on each surface
int32Vector_HD motionIndex_; int32Vector_HD motionIndex_;
// motion index mapped on each triangle /// motion index mapped on each triangle
int8Vector_HD triMotionIndex_; int8Vector_HD triMotionIndex_;
/// motion index mapped on each point /// motion index mapped on each point
int8Vector_HD pointMotionIndex_; int8Vector_HD pointMotionIndex_;
// timer for moveGeometry /// timer for moveGeometry
Timer moveGeomTimer_; Timer moveGeomTimer_;
/// determine the motion index of each triangle
bool findMotionIndex(); bool findMotionIndex();
public: public:
// type info /// Type info
TypeInfoTemplate("geometry", MotionModel); TypeInfoTemplate("geometry", MotionModel);
//// - Constructors // - Constructors
geometryMotion(systemControl& control, const property& prop); geometryMotion(systemControl& control, const property& prop);
// construct from components
geometryMotion( geometryMotion(
systemControl& control, systemControl& control,
const property& prop, const property& prop,
@ -77,8 +79,8 @@ public:
const wordVector& propName, const wordVector& propName,
const MotionModel& motionModel); const MotionModel& motionModel);
// - construct from components and dictionary that contains /// Construct from components and dictionary that contains
// motionModel /// motionModel
geometryMotion(systemControl& control, geometryMotion(systemControl& control,
const property& prop, const property& prop,
const dictionary& dict, const dictionary& dict,
@ -86,8 +88,7 @@ public:
const wordVector& motionCompName, const wordVector& motionCompName,
const wordVector& propName); const wordVector& propName);
/// Add virtual constructor
add_vCtor add_vCtor
( (
geometry, geometry,
@ -95,6 +96,7 @@ public:
systemControl systemControl
); );
/// Add virtual constructor
add_vCtor add_vCtor
( (
geometry, geometry,
@ -102,48 +104,47 @@ public:
dictionary dictionary
); );
//// - Methods // - Methods
/// Obtain motion model at time t
auto getModel(real t)const auto getModel(real t)const
{ {
return motionModel_.getModel(t); return motionModel_.getModel(t);
} }
/// TypeName / TypeInfo of motion model
word motionModelTypeName()const override word motionModelTypeName()const override
{ {
return motionModel_.typeName(); return motionModel_.typeName();
} }
/// Access to motion model index of triangles
const int8Vector_HD& triMotionIndex()const override const int8Vector_HD& triMotionIndex()const override
{ {
return triMotionIndex_; return triMotionIndex_;
} }
/// Access to motion model index of points
const int8Vector_HD& pointMotionIndex()const override const int8Vector_HD& pointMotionIndex()const override
{ {
return pointMotionIndex_; return pointMotionIndex_;
} }
// - iterate /// Operations before each iteration
bool beforeIteration() override { bool beforeIteration() override;
geometry::beforeIteration();
return true;
}
/// Iterate geometry one time step
bool iterate() override ; bool iterate() override ;
bool afterIteration() override { /// Operations after each iteration
geometry::afterIteration(); bool afterIteration() override;
return true;
}
/// Move geometry
bool moveGeometry(); bool moveGeometry();
}; };
} // pFlow
}
#include "geometryMotion.cpp" #include "geometryMotion.cpp"