# PhasicFlow: src/phasicFlow/structuredData/boundaries/boundaryList.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.

boundaryList.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 "boundaryList.hpp"
#include "pointStructure.hpp"
void
pFlow::boundaryList::setExtendedDomain()
{
if (!listSet_)
{
fatalErrorInFunction
<< "boundary list is not set yet and you used the objects." << endl;
fatalExit;
}
realx3 lowerExt = boundary(0).boundaryExtensionLength() +
boundary(2).boundaryExtensionLength() +
boundary(4).boundaryExtensionLength();
realx3 upperExt = boundary(1).boundaryExtensionLength() +
boundary(3).boundaryExtensionLength() +
boundary(5).boundaryExtensionLength();
extendedDomain_ = pStruct_.simDomain().extendThisDomain(lowerExt, upperExt);
}
bool
pFlow::boundaryList::resetLists()
{
clear();
listSet_ = false;
return true;
}
bool
pFlow::boundaryList::updateNeighborLists()
{
if (!listSet_)
{
createBoundaries();
}
std::array<real, 6> dist;
dist[0] = boundary(0).neighborLength();
dist[1] = boundary(1).neighborLength();
dist[2] = boundary(2).neighborLength();
dist[3] = boundary(3).neighborLength();
dist[4] = boundary(4).neighborLength();
dist[5] = boundary(5).neighborLength();
pStruct_.updateFlag(extendedDomain_, dist);
const auto& maskD = pStruct_.activePointsMaskDevice();
boundary(0).setSize(maskD.leftSize());
boundary(1).setSize(maskD.rightSize());
boundary(2).setSize(maskD.bottomSize());
boundary(3).setSize(maskD.topSize());
boundary(4).setSize(maskD.rearSize());
boundary(5).setSize(maskD.frontSize());
pStruct_.fillNeighborsLists(
boundary(0).indexList().deviceViewAll(),
boundary(1).indexList().deviceViewAll(),
boundary(2).indexList().deviceViewAll(),
boundary(3).indexList().deviceViewAll(),
boundary(4).indexList().deviceViewAll(),
boundary(5).indexList().deviceViewAll()
);
return true;
}
pFlow::boundaryList::boundaryList(pointStructure& pStruct)
: ListPtr<boundaryBase>(pStruct.simDomain().sizeOfBoundaries()),
pStruct_(pStruct)
{
const dictionary& dict= pStruct_.simDomain().thisBoundariesDict();
neighborListUpdateInterval_ = dict.getValMax(
"neighborListUpdateInterval",
1u
);
updateInterval_ = dict.getVal<uint32>("updateInterval");
}
bool
pFlow::boundaryList::updateNeighborLists(uint32 iter, bool force)
{
neighborListUpdate_ = false;
boundaryUpdate_ = false;
iterBeforeBoundaryUpdate_ = false;
if(iter%neighborListUpdateInterval_==0u || iter == 0u || force)
{
if(updateNeighborLists())
{
neighborListUpdate_ = true;
lastNeighborUpdated_ = iter;
}
else
{
fatalErrorInFunction<<"error in updating neighbor lists of boundaries"<<endl;
return false;
}
}
if( iter%updateInterval_ == 0u || iter == 0u || force )
{
boundaryUpdate_ = true;
}
if((iter+1)%updateInterval_ == 0u)
{
iterBeforeBoundaryUpdate_ = true;
}
return true;
}
bool
pFlow::boundaryList::createBoundaries()
{
if (listSet_)
return true;
for (auto i = 0; i < pStruct_.simDomain().sizeOfBoundaries(); i++)
{
this->set(
i,
boundaryBase::create(
pStruct_.simDomain().boundaryDict(i),
pStruct_.simDomain().boundaryPlane(i),
pStruct_,
*this,
i
)
);
}
listSet_ = true;
setExtendedDomain();
return true;
}
pFlow::box
pFlow::boundaryList::internalDomainBox() const
{
const auto& thisBox = pStruct_.thisDomain().domainBox();
const realx3 lowerPointDisplacement = {
boundary(0).neighborLengthIntoInternal(),
boundary(2).neighborLengthIntoInternal(),
boundary(4).neighborLengthIntoInternal()
};
const realx3 upperPointDisplacement = {
boundary(1).neighborLengthIntoInternal(),
boundary(3).neighborLengthIntoInternal(),
boundary(5).neighborLengthIntoInternal()
};
return { thisBox.minPoint() + lowerPointDisplacement,
thisBox.maxPoint() - upperPointDisplacement };
}
bool
pFlow::boundaryList::beforeIteration(const timeInfo& ti, bool force)
{
// it is time to update lists
if(!updateNeighborLists(ti.iter() , force) )
{
return false;
}
auto callAgain = boundariesMask<6>(true);
uint32 step = 1;
while(callAgain.anyElement(true) && step <= 10u)
{
for(size_t i=0; i<6ul; i++)
{
if(callAgain[i])
{
if(! boundary(i).beforeIteration(
step,
ti,
boundaryUpdate_,
iterBeforeBoundaryUpdate_,
callAgain[i]))
{
fatalErrorInFunction<<"error in performing beforeIteration for boundary"<<
boundary(i).name()<<" at step "<< step<<endl;
return false;
}
}
}
step++;
}
for (auto bdry : *this)
{
bdry->updataBoundaryData(1);
}
for (auto bdry : *this)
{
bdry->updataBoundaryData(2);
}
return true;
}
bool
pFlow::boundaryList::iterate(const timeInfo& ti, bool force)
{
for (auto& bdry : *this)
{
if (!bdry->iterate(ti))
{
fatalErrorInFunction << "Error in iterate in boundary "
<< bdry->name() << endl;
return false;
}
}
return true;
}
bool
pFlow::boundaryList::afterIteration(const timeInfo& ti, bool force)
{
auto callAgain = boundariesMask<6>(true);
int step = 1;
while(callAgain.anyElement(true)&& step <=10)
{
for(size_t i=0; i<6; i++)
{
if(callAgain[i])
{
if( !boundary(i).transferData(ti.iter(), step, callAgain[i]))
{
fatalErrorInFunction<<"Error in transfering data for boundary "<<
boundary(i).name()<<endl;
return false;
}
}
}
step++;
}
return true;
}
pFlow::boundaryList::internalDomainBox
box internalDomainBox() const
Definition: boundaryList.cpp:165
pFlow::ListPtr
Definition: ListPtr.hpp:37
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::boundaryList::pStruct_
pointStructure & pStruct_
Definition: boundaryList.hpp:42
pFlow::boundaryList::iterate
bool iterate(const timeInfo &tf, bool force=false)
Definition: boundaryList.cpp:237
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::boundaryList::beforeIteration
bool beforeIteration(const timeInfo &tf, bool force=false)
Definition: boundaryList.cpp:186
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::boundaryList::extendedDomain_
domain extendedDomain_
Definition: boundaryList.hpp:56
pFlow::pointStructure::simDomain
const auto & simDomain() const
Definition: pointStructure.hpp:149
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::boundaryList::boundaryList
boundaryList(pointStructure &pStruct)
Definition: boundaryList.cpp:91
pFlow::boundaryList::afterIteration
bool afterIteration(const timeInfo &tf, bool force=false)
Definition: boundaryList.cpp:252
boundaryList.hpp
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::dictionary::getValMax
T getValMax(const word &keyword, const T &maxVal) const
get the value of data entry and return max(value, maxVal)
Definition: dictionary.hpp:395
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::boundaryList::boundary
auto & boundary(size_t i)
Definition: boundaryList.hpp:95
pFlow::boundaryList::createBoundaries
bool createBoundaries()
Definition: boundaryList.cpp:141
pFlow::boundaryBase
Definition: boundaryBase.hpp:42
pFlow::boundaryList::setExtendedDomain
void setExtendedDomain()
Definition: boundaryList.cpp:25
pFlow::boundaryList::listSet_
bool listSet_
Definition: boundaryList.hpp:60
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::boundariesMask< 6 >
pFlow::boundaryList::updateNeighborLists
bool updateNeighborLists()
update neighbor list of boundaries regardless of the time intervals
Definition: boundaryList.cpp:54
pFlow::box
Definition: box.hpp:32
pFlow::timeInfo::iter
const uint32 & iter() const
Definition: timeInfo.hpp:55
pFlow::boundaryList::updateInterval_
uint32 updateInterval_
Definition: boundaryList.hpp:46
pFlow::boundaryList::neighborListUpdateInterval_
uint32 neighborListUpdateInterval_
Definition: boundaryList.hpp:44
pFlow::triple< real >
pFlow::boundaryList::resetLists
bool resetLists()
Definition: boundaryList.cpp:46
pointStructure.hpp
pFlow::boundaryBase::create
static uniquePtr< boundaryBase > create(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryBase.cpp:308
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67