# PhasicFlow: src/phasicFlow/containers/pointField/internalField/internalField.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.

internalField.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<class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>::insert(const anyList& varList)
{
const word eventName = message::eventName(message::ITEM_INSERT);
const auto& indices = varList.getObject<uint32IndexContainer>(
eventName);
bool success = false;
if(varList.contains(name()))
{
// a single value is assigned
T val = varList.getObject<T>(name());
success = field_.insertSetElement(indices, val);
}
else if(varList.contains(name()+"Vector"))
{
// a vector of values is going to be assigned
const auto& valVec = varList.getObject<Vector<T>>(name()+"Vector");
success = field_.insertSetElement(indices,valVec);
}
else
{
success = field_.insertSetElement(indices, defaultValue_);
}
if(!success)
{
fatalErrorInFunction;
return false;
}
return true;
}
template<class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>::rearrange(const anyList& varList)
{
const word eventName = message::eventName(message::ITEM_REARRANGE);
const auto& indices = varList.getObject<uint32IndexContainer>(
eventName);
field_.reserve( internalPoints_.capacity());
field_.resize(internalPoints_.size());
if(!field_.reorderItems(indices))
{
fatalErrorInFunction<<
"cannot reorder items in field "<< name()<<endl;
return false;
}
return true;
}
template<class T, class MemorySpace>
pFlow::internalField<T, MemorySpace>::internalField
(
const word& name,
const internalPoints& internal,
const T& defVal
)
:
observer
(
&internal,
defaultMessage_
),
field_
(
name,
"ineternalField",
internal.capacity(),
internal.size(),
RESERVE()
),
defaultValue_(defVal),
internalPoints_(internal)
{}
template<class T, class MemorySpace>
pFlow::internalField<T, MemorySpace>::internalField
(
const word &name,
const internalPoints &internal,
const T& defVal,
const T &val
)
:
observer
(
&internal,
defaultMessage_
),
field_
(
name,
"ineternalField",
internal.capacity(),
internal.size(),
RESERVE()
),
defaultValue_(defVal),
internalPoints_(internal)
{
fillInternal(val);
}
template <class T, class MemorySpace>
typename pFlow::internalField<T, MemorySpace>::FieldTypeHost
pFlow::internalField<T, MemorySpace>::activeValuesHost() const
{
auto maskH = internalPoints_.activePointsMaskHost();
auto fieldH = field_.hostView();
FieldTypeHost aField
(
field_.name(),
field_.fieldKey(),
maskH.numActive(),
maskH.numActive(),
RESERVE()
);
auto aRange = maskH.activeRange();
uint32 n = 0;
for(auto i=aRange.start(); i<aRange.end(); i++)
{
if( maskH.isActive(i) )
{
aField[n] = fieldH[i];
n++;
}
}
return aField;
}
template <class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>:: hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
)
{
if(msg.equivalentTo(message::CAP_CHANGED))
{
auto newCap = varList.getObject<uint32>(
message::eventName(message::CAP_CHANGED));
field_.reserve(newCap);
}
if(msg.equivalentTo(message::SIZE_CHANGED))
{
auto newSize = varList.getObject<uint32>(
message::eventName(message::SIZE_CHANGED));
field_.resize(newSize);
}
if(msg.equivalentTo(message::ITEM_DELETE))
{
// do nothing
}
if(msg.equivalentTo(message::ITEM_INSERT))
{
return insert(varList);
}
if(msg.equivalentTo(message::ITEM_REARRANGE))
{
return rearrange(varList);
}
return true;
}
template<class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>::write
(
iOstream& os,
const IOPattern& iop
)const
{
auto aField = activeValuesHost();
return aField.write(os, iop);
}
pFlow::message::equivalentTo
bool equivalentTo(EVENT evnt) const
Definition: message.hpp:131
pFlow::observer
Definition: observer.hpp:33
pFlow::internalField::internalField
internalField(const word &name, const internalPoints &internal, const T &defVal)
Definition: internalField.cpp:80
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::anyList::getObject
T & getObject(size_t i)
Get the reference to variable by index.
Definition: anyList.hpp:134
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::anyList::contains
bool contains(const word &name) const
Does container contain this variable name?
Definition: anyList.cpp:35
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::Field
Definition: Field.hpp:36
pFlow::internalField::hearChanges
bool hearChanges(real t, real dt, uint32 iter, const message &msg, const anyList &varList) override
Definition: internalField.cpp:164
RESERVE
Definition: Vector.hpp:40
pFlow::anyList
Definition: anyList.hpp:35
pFlow::internalField::rearrange
bool rearrange(const anyList &varList)
Definition: internalField.cpp:58
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::VectorSingle::hostView
INLINE_FUNCTION_H auto hostView() const
Return a view accessible on Host in range [0,size)
Definition: VectorSingle.cpp:281
pFlow::IOPattern
Definition: IOPattern.hpp:32
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::internalField::insert
bool insert(const anyList &varList)
Definition: internalField.cpp:22
pFlow::internalField::write
bool write(iOstream &os, const IOPattern &iop) const
Definition: internalField.cpp:203
pFlow::internalField::activeValuesHost
FieldTypeHost activeValuesHost() const
Definition: internalField.cpp:134
pFlow::Vector
Definition: Vector.hpp:48
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39