# PhasicFlow: src/phasicFlow/structuredData/pointStructure/pointStructure/pointStructure.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

pointStructure.cpp
Go to the documentation of this file.
/*------------------------------- 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 "pointStructure.hpp"
#include "systemControl.hpp"
#include "vocabs.hpp"
#include "anyList.hpp"
bool pFlow::pointStructure::setupPointStructure(const realx3Vector& points)
{
PointsTypeHost hPoints
(
pointPosition().name(),
pointPosition().fieldKey()
);
hPoints.assign(points);
return setupPointStructure(hPoints);
}
bool pFlow::pointStructure::setupPointStructure(const PointsTypeHost &points)
{
if(!simulationDomain_->initialUpdateDomains(points.getSpan()))
{
fatalErrorInFunction<<
"error in updating domains"<<endl;
return false;
}
uint32 thisN = simulationDomain_->initialNumberInThis();
PointsTypeHost internal
(
pointPosition().name(),
pointPosition().fieldKey(),
thisN,
thisN,
RESERVE()
);
auto pSpan = points.getSpan();
if(auto iSpan = internal.getSpan();
!simulationDomain_->initialTransferBlockData(pSpan, iSpan))
{
fatalErrorInFunction<<
"Error in transfering the block data "<<endl;
return false;
}
if( !initializePoints(internal) )
{
fatalErrorInFunction;
return false;
}
boundaries_.createBoundaries();
boundaries_.updateNeighborLists(0u, true);
return true;
}
bool pFlow::pointStructure::initializePoints(const PointsTypeHost &points)
{
pointPosition().assignFromHost(points);
createDeviceFlag(pointPosition().capacity(), 0, pointPosition().size());
syncPFlag();
return true;
}
pFlow::pointStructure::pointStructure
(
systemControl& control
)
:
IOobject
(
objectFile
(
pointStructureFile__,
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_ALWAYS
),
IOPattern::MasterProcessorDistribute,
&control.time()
),
demComponent("particlesCenterMass", control),
internalPoints(),
simulationDomain_
(
simulationDomain::create(control)
),
//pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
boundaries_
(
*this
),
boundaryUpdateTimer_("boundaryUpdate", &timers()),
boundaryDataTransferTimer_("boundaryDataTransferTimer", &timers())
{
REPORT(1)<< "Reading "<< Green_Text("pointStructure")<<
" from "<<IOobject::path()<<END_REPORT;
if( !IOobject::readObject() )
{
fatalErrorInFunction<<
"Error in reading from file "<<IOobject::path()<<endl;
fatalExit;
}
pointSorting_ = makeUnique<pointSorting>(simulationDomain_->subDictOrCreate("pointSorting"));
}
pFlow::pointStructure::pointStructure(
systemControl& control,
const realx3Vector &posVec)
:
IOobject
(
objectFile
(
pointStructureFile__,
"",
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
IOPattern::MasterProcessorDistribute,
&control.time()
),
demComponent("particlesCenterMass", control),
internalPoints(),
simulationDomain_
(
simulationDomain::create(control)
),
//pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
boundaries_
(
*this
)
{
if(!setupPointStructure(posVec))
{
fatalErrorInFunction<<
"Error in seting up pointStructure"<<endl;
fatalExit;
}
pointSorting_ = makeUnique<pointSorting>(simulationDomain_->subDictOrCreate("pointSorting"));
}
bool pFlow::pointStructure::beforeIteration()
{
const timeInfo ti = TimeInfo();
if(pointSorting_().sortTime(ti.iter(), ti.t(), ti.dt()))
{
auto sortedIndices = pointSorting_().getSortedIndices(
simulationDomain_().globalBox(),
pointPositionDevice(),
activePointsMaskDevice()
);
if( !sortPoints(sortedIndices) )
{
fatalErrorInFunction;
return false;
}
boundaryUpdateTimer_.start();
boundaries_.beforeIteration(ti, true);
boundaryUpdateTimer_.end();
INFORMATION<<"Reordering of particles has been done. New active range for particles is "<<
activeRange()<<END_INFO;
message msg;
anyList varList;
varList.emplaceBack(
msg.addAndName(message::ITEM_REARRANGE),
sortedIndices);
if(!notify(ti, msg, varList))
{
fatalErrorInFunction<<
"cannot notify for reordering items."<<endl;
return false;
}
return true;
// notify others about this change
}
else
{
boundaryUpdateTimer_.start();
if( !boundaries_.beforeIteration(ti) )
{
fatalErrorInFunction<<
"Unable to perform beforeIteration for boundaries"<<endl;
return false;
}
boundaryUpdateTimer_.end();
}
return true;
}
bool pFlow::pointStructure::iterate()
{
if( !boundaries_.iterate(TimeInfo()) )
{
fatalErrorInFunction<<
"Unable to perform iterate for boundaries"<<endl;
return false;
}
return true;
}
bool pFlow::pointStructure::afterIteration()
{
boundaryDataTransferTimer_.start();
if( !boundaries_.afterIteration(TimeInfo()) )
{
fatalErrorInFunction<<
"Unable to perform afterIteration for boundaries"<<endl;
return false;
}
boundaryDataTransferTimer_.end();
return true;
}
bool pFlow::pointStructure::read(
iIstream &is,
const IOPattern& iop)
{
PointsTypeHost fRead
(
this->pointPosition().name(),
this->pointPosition().fieldKey()
);
if( !fRead.read(is, iop))
{
fatalErrorInFunction<<
"Error in reading pointPosition from stream "<< is.name()<<endl;
return false;
}
return setupPointStructure(fRead);
}
bool pFlow::pointStructure::write
(
iOstream& os,
const IOPattern& iop
)const
{
return internalPoints::write(os, iop);
}
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
anyList.hpp
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::message
Definition: message.hpp:33
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::pointStructure::read
bool read(iIstream &is, const IOPattern &iop) override
read the point structure from the input stream.
Definition: pointStructure.cpp:257
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::pointStructure::beforeIteration
bool beforeIteration() override
In the time loop before iterate.
Definition: pointStructure.cpp:175
systemControl.hpp
pFlow::pointStructure::pointStructure
pointStructure(systemControl &control)
an empty pointStructure, good for reading from file
Definition: pointStructure.cpp:94
pFlow::internalPoints::pointPosition
const PointsType & pointPosition() const
Definition: internalPoints.cpp:209
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::message::ITEM_REARRANGE
@ ITEM_REARRANGE
Definition: message.hpp:44
pFlow::pointStructure::pointSorting_
uniquePtr< pointSorting > pointSorting_
Definition: pointStructure.hpp:57
pFlow::IOobject
Definition: IOobject.hpp:35
RESERVE
Definition: Vector.hpp:40
pFlow::anyList
Definition: anyList.hpp:35
pFlow::pointStructureFile__
const char *const pointStructureFile__
Definition: vocabs.hpp:42
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::IOobject::readObject
bool readObject(bool rdHdr=true)
Definition: IOobject.cpp:83
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::IOfileHeader::path
fileSystem path() const
Definition: IOfileHeader.cpp:63
pFlow::demComponent
A base class for every main component of DEM system.
Definition: demComponent.hpp:42
pFlow::objectFile::name
virtual const word & name() const
Definition: objectFile.hpp:101
pFlow::systemControl::time
const Time & time() const
Definition: systemControl.hpp:122
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::internalPoints::PointsTypeHost
typename PointsType::FieldTypeHost PointsTypeHost
Definition: internalPoints.hpp:48
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::pointStructure::write
bool write(iOstream &os, const IOPattern &iop) const override
Write.
Definition: pointStructure.cpp:279
pFlow::timeInfo::dt
const real & dt() const
Definition: timeInfo.hpp:51
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::pointStructure::iterate
bool iterate() override
This is called in time loop.
Definition: pointStructure.cpp:232
pFlow::pointStructure::initializePoints
bool initializePoints(const PointsTypeHost &points)
Definition: pointStructure.cpp:83
pFlow::timeInfo::t
const real & t() const
Definition: timeInfo.hpp:47
pFlow::message::addAndName
const word & addAndName(EVENT evnt)
Definition: message.hpp:119
pFlow::simulationDomain::create
static uniquePtr< simulationDomain > create(systemControl &control)
Definition: simulationDomain.cpp:121
pFlow::timeInfo::iter
const uint32 & iter() const
Definition: timeInfo.hpp:55
pFlow::pointStructure::setupPointStructure
bool setupPointStructure(const realx3Vector &points)
Definition: pointStructure.cpp:27
pFlow::pointStructure::simulationDomain_
uniquePtr< simulationDomain > simulationDomain_
Definition: pointStructure.hpp:55
pFlow::simulationDomain
Definition: simulationDomain.hpp:38
pFlow::internalPoints::write
bool write(iOstream &os) const
Write.
Definition: internalPoints.cpp:556
pFlow::pointStructure::afterIteration
bool afterIteration() override
This is called in time loop, after iterate.
Definition: pointStructure.cpp:244
vocabs.hpp
pFlow::Vector< realx3 >
END_INFO
#define END_INFO
Definition: streams.hpp:37
pointStructure.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::IOPattern::MasterProcessorDistribute
@ MasterProcessorDistribute
Definition: IOPattern.hpp:56
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
INFORMATION
#define INFORMATION
Definition: streams.hpp:36