# PhasicFlow: src/Integration/AdamsMoulton4/AdamsMoulton4.cpp Source File

AdamsMoulton4.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 "AdamsMoulton4.hpp"
//const real AB2_coef[] = { 3.0 / 2.0, 1.0 / 2.0};
pFlow::AdamsMoulton4::AdamsMoulton4
(
const word& baseName,
repository& owner,
const pointStructure& pStruct,
const word& method
)
:
integration(baseName, owner, pStruct, method),
y0_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"y0"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3,
false
)
),
dy0_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"dy0"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3
)
),
dy1_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"dy1"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3
)
),
dy2_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"dy2"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3
)
)
{
}
bool pFlow::AdamsMoulton4::predict
(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy
)
{
if(this->pStruct().allActive())
{
return predictAll(dt, y, dy, this->pStruct().activeRange());
}
else
{
return predictRange(dt, y, dy, this->pStruct().activePointsMaskD());
}
return true;
}
bool pFlow::AdamsMoulton4::correct
(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy
)
{
if(this->pStruct().allActive())
{
return intAll(dt, y, dy, this->pStruct().activeRange());
}
else
{
return intRange(dt, y, dy, this->pStruct().activePointsMaskD());
}
return true;
}
bool pFlow::AdamsMoulton4::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
y0_.insertSetElement(newIndices, y);
return true;
}
bool pFlow::AdamsMoulton4::predictAll(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
range activeRng)
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_dy1 = dy1_.deviceVectorAll();
auto d_dy2 = dy2_.deviceVectorAll();
Kokkos::parallel_for(
"AdamsMoulton4::predict",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
d_dy0[i] = d_dy[i];
d_y[i] = d_y0[i] + dt*(
static_cast< real >(23.0 /12.0 ) * d_dy[i]
- static_cast< real >(16.0 / 12.0) * d_dy1[i]
+ static_cast< real >( 5.0 / 12.0) * d_dy2[i]);
});
Kokkos::fence();
return true;
}
bool pFlow::AdamsMoulton4::intAll(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
range activeRng)
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy1 = dy1_.deviceVectorAll();
auto d_dy2 = dy2_.deviceVectorAll();
Kokkos::parallel_for(
"AdamsMoulton4::correct",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
auto corrct_y = d_y0[i] + dt*(
static_cast< real >(9.0/24.0)*d_dy[i]
+ static_cast< real >(19.0/24.0)*d_dy0[i]
- static_cast< real >( 5.0/24.0)*d_dy1[i]
+ static_cast< real >( 1.0/24.0)*d_dy2[i]);
d_dy2[i]= d_dy1[i];
d_dy1[i]= d_dy0[i];
d_y0[i] = corrct_y;
d_y[i] = corrct_y;
});
Kokkos::fence();
return true;
}
pFlow::AdamsMoulton4::AdamsMoulton4
AdamsMoulton4(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsMoulton4.cpp:26
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::integration
Definition: integration.hpp:35
pFlow::AdamsMoulton4::y0_
realx3PointField_D & y0_
Definition: AdamsMoulton4.hpp:38
pFlow::AdamsMoulton4::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton4.cpp:104
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::AdamsMoulton4::predict
bool predict(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton4.cpp:84
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:97
pFlow::repository::emplaceObject
T & emplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:38
pFlow::AdamsMoulton4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsMoulton4.cpp:122
pFlow::baseName
word baseName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:156
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
AdamsMoulton4.hpp
pFlow::AdamsMoulton4::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsMoulton4.hpp:50
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::objectFile
Definition: objectFile.hpp:33
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::AdamsMoulton4::predictAll
bool predictAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton4.cpp:131
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Definition: bTypesFunctions.cpp:151
pFlow::AdamsMoulton4::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton4.cpp:161
pFlow::repository
Definition: repository.hpp:34
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::Vector< realx3 >
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::indexContainer< int32 >