# PhasicFlow: src/Particles/Insertion/InsertionRegion/InsertionRegion.cpp Source File

InsertionRegion.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.
-----------------------------------------------------------------------------*/
template<typename ShapeType>
bool pFlow::InsertionRegion<ShapeType>::checkForContact
(
const realx3Vector& pos,
const realVector& diams,
const realx3& p,
const real& d
)
{
ForAll(i, pos)
{
if( length(pos[i]-p) < 0.5*(diams[i]+d) ) return true;
}
return false;
}
template<typename ShapeType>
pFlow::InsertionRegion<ShapeType>::InsertionRegion
(
const dictionary& dict,
const ShapeType& shapes
)
:
insertionRegion(dict),
shapes_(shapes)
{
}
template<typename ShapeType>
bool pFlow::InsertionRegion<ShapeType>::insertParticles
(
real currentTime,
real dt,
wordVector& names,
realx3Vector& pos,
bool& insertionOccured
)
{
insertionOccured = false;
if(!insertionTime( currentTime, dt)) return true;
size_t newNum = numberToBeInserted(currentTime);
if(newNum == 0) return true;
names.reserve(max(newNum,names.capacity()));
pos.reserve(max(newNum,pos.capacity()));
names.clear();
pos.clear();
realVector diams(newNum, RESERVE());
mixture_->getNextShapeNameN(newNum, names);
if(!shapes_.shapeToDiameter(names,diams))
{
fatalErrorInFunction<<
" error occured in insertion region "<< name() <<
" while converting shapes to diameter. \n";
return false;
}
size_t n = 0;
for(label iter=0; iter< 10*newNum ; ++iter)
{
if( !(n < newNum) )
{
addToNumInserted(newNum);
insertionOccured = true;
return true;
}
realx3 p = pRegion_().peek();
real d = diams[pos.size()];
if( !checkForContact(pos, diams, p, d) )
{
pos.push_back(p);
n++;
}
}
fatalErrorInFunction<<
" Cannot insert "<< newNum << " new particles from region "<< name()<<". \n"
" pFlow could position only "<< n<< " particles in this region. \n";
addToNumInserted(n);
insertionOccured = false;
return false;
}
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::InsertionRegion::insertParticles
bool insertParticles(real currentTime, real dt, wordVector &names, realx3Vector &pos, bool &insertionOccured)
Definition: InsertionRegion.cpp:55
pFlow::InsertionRegion::checkForContact
static bool checkForContact(const realx3Vector &pos, const realVector &diams, const realx3 &p, const real &d)
Definition: InsertionRegion.cpp:23
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::insertionRegion
Definition: insertionRegion.hpp:34
RESERVE
Definition: Vector.hpp:38
n
int32 n
Definition: NBSCrossLoop.hpp:24
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::Vector::capacity
auto capacity() const
Definition: Vector.hpp:304
pFlow::Vector::reserve
auto reserve(label len)
Definition: Vector.hpp:309
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::InsertionRegion::InsertionRegion
InsertionRegion(const dictionary &dict, const ShapeType &shapes)
Definition: InsertionRegion.cpp:41
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::dictionary
Definition: dictionary.hpp:38