# PhasicFlow: src/Integration/AdamsBashforth2/AdamsBashforth2.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.

AdamsBashforth2.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 "AdamsBashforth2.hpp"
#include "pointStructure.hpp"
#include "Time.hpp"
#include "vocabs.hpp"
namespace pFlow
{
using rpIntegration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<uint32>
>;
bool intAllActive(
real dt,
realx3Field_D& y,
realx3PointField_D& dy,
realx3PointField_D& dy1)
{
auto d_dy = dy.deviceView();
auto d_y = y.deviceView();
auto d_dy1= dy1.deviceView();
auto activeRng = dy1.activeRange();
Kokkos::parallel_for(
"AdamsBashforth2::correct",
rpIntegration (activeRng.start(), activeRng.end()),
LAMBDA_HD(uint32 i){
d_y[i] += dt*(static_cast< real >(1.5) * d_dy[i] - static_cast< real >(0.5) * d_dy1[i]);
d_dy1[i] = d_dy[i];
});
Kokkos::fence();
return true;
}
bool intScattered
(
real dt,
realx3Field_D& y,
realx3PointField_D& dy,
realx3PointField_D& dy1
)
{
auto d_dy = dy.deviceView();
auto d_y = y.deviceView();
auto d_dy1 = dy1.deviceView();
auto activeRng = dy1.activeRange();
const auto& activeP = dy1.activePointsMaskDevice();
Kokkos::parallel_for(
"AdamsBashforth2::correct",
rpIntegration (activeRng.start(), activeRng.end()),
LAMBDA_HD(uint32 i){
if( activeP(i))
{
d_y[i] += dt*(static_cast< real >(1.5) * d_dy[i] - static_cast< real >(0.5) * d_dy1[i]);
d_dy1[i] = d_dy[i];
}
});
Kokkos::fence();
return true;
}
}
pFlow::AdamsBashforth2::AdamsBashforth2
(
const word& baseName,
pointStructure& pStruct,
const word& method,
const realx3Field_D& initialValField
)
:
integration(baseName, pStruct, method, initialValField),
realx3PointField_D
(
objectFile
(
groupNames(baseName,"dy1"),
pStruct.time().integrationFolder(),
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS
),
pStruct,
zero3,
zero3
),
boundaryList_(pStruct, method, *this)
{}
void pFlow::AdamsBashforth2::updateBoundariesSlaveToMasterIfRequested()
{
realx3PointField_D::updateBoundariesSlaveToMasterIfRequested();
}
bool pFlow::AdamsBashforth2::predict(
real UNUSED(dt),
realx3PointField_D &UNUSED(y),
realx3PointField_D &UNUSED(dy))
{
return true;
}
bool pFlow::AdamsBashforth2::predict
(
real dt,
realx3Field_D &y,
realx3PointField_D &dy
)
{
return true;
}
bool pFlow::AdamsBashforth2::correct
(
real dt,
realx3PointField_D& y,
realx3PointField_D& dy
)
{
auto& dy1l = dy1();
bool success = false;
if(dy1l.isAllActive())
{
success = intAllActive(dt, y.field(), dy, dy1l);
}
else
{
success = intScattered(dt, y.field(), dy, dy1l);
}
success = success && boundaryList_.correct(dt, y, dy);
return success;
}
bool pFlow::AdamsBashforth2::correctPStruct(
real dt,
pointStructure &pStruct,
realx3PointField_D &vel)
{
auto& dy1l = dy1();
bool success = false;
if(dy1l.isAllActive())
{
success = intAllActive(dt, pStruct.pointPosition(), vel, dy1l);
}
else
{
success = intScattered(dt, pStruct.pointPosition(), vel, dy1l);
}
success = success && boundaryList_.correctPStruct(dt, pStruct, vel);
return success;
}
bool pFlow::AdamsBashforth2::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
return true;
}
pFlow::AdamsBashforth2::predict
bool predict(real UNUSED(dt), realx3PointField_D &UNUSED(y), realx3PointField_D &UNUSED(dy)) final
Definition: AdamsBashforth2.cpp:123
pFlow::real
float real
Definition: builtinTypes.hpp:45
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::AdamsBashforth2::AdamsBashforth2
AdamsBashforth2(const word &baseName, pointStructure &pStruct, const word &method, const realx3Field_D &initialValField)
Construct from components.
Definition: AdamsBashforth2.cpp:94
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::internalField::activePointsMaskDevice
const pFlagTypeDevice & activePointsMaskDevice() const
Definition: internalField.hpp:120
pFlow::realx3PointField_D
pointField_D< realx3 > realx3PointField_D
Definition: pointFields.hpp:52
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:137
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Default execution space, it can be device exe.
Definition: KokkosTypes.hpp:61
pFlow::intAllActive
bool intAllActive(real dt, realx3Field_D &y, realx3PointField_D &dy, realx3PointField_D &dy1)
Definition: AdamsBashforth2.cpp:36
pFlow::Field< realx3 >
pFlow::AdamsBashforth2::correct
bool correct(real dt, realx3PointField_D &y, realx3PointField_D &dy) final
Correction/main integration step.
Definition: AdamsBashforth2.cpp:142
pFlow::intScattered
bool intScattered(real dt, realx3Field_D &y, realx3PointField_D &dy, realx3PointField_D &dy1)
Definition: AdamsBashforth2.cpp:61
pFlow
Definition: demGeometry.hpp:27
pFlow::VectorSingle::deviceView
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
Definition: VectorSingle.cpp:263
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::AdamsBashforth2::correctPStruct
bool correctPStruct(real dt, pointStructure &pStruct, realx3PointField_D &vel) final
Definition: AdamsBashforth2.cpp:165
pFlow::internalField::field
const FieldType & field() const
Definition: internalField.hpp:109
pFlow::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< uint32 > > rpIntegration
Range policy for integration kernel (alias)
Definition: AdamsBashforth2.cpp:34
Time.hpp
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField_old.hpp:138
pFlow::objectFile
Definition: objectFile.hpp:30
AdamsBashforth2.hpp
pFlow::AdamsBashforth2::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) final
Set the initial values for new indices.
Definition: AdamsBashforth2.cpp:187
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::pointField::updateBoundariesSlaveToMasterIfRequested
void updateBoundariesSlaveToMasterIfRequested()
update boundaries if it is requested previousely (slave to master).
Definition: pointField.hpp:115
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::AdamsBashforth2::updateBoundariesSlaveToMasterIfRequested
void updateBoundariesSlaveToMasterIfRequested() override
Definition: AdamsBashforth2.cpp:118
vocabs.hpp
pFlow::Vector< realx3 >
pointStructure.hpp
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39
pFlow::internalField::deviceView
auto deviceView() const
Definition: internalField.hpp:97