2022-09-04 21:26:29 +00:00
|
|
|
/*------------------------------- 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.
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#ifndef __AdamsBashforth2_hpp__
|
|
|
|
#define __AdamsBashforth2_hpp__
|
2022-09-04 21:26:29 +00:00
|
|
|
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#include "integration.hpp"
|
|
|
|
#include "pointFields.hpp"
|
2022-09-04 21:26:29 +00:00
|
|
|
|
|
|
|
namespace pFlow
|
|
|
|
{
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
/**
|
|
|
|
* Second order Adams-Bashforth integration method for solving ODE
|
|
|
|
*
|
|
|
|
* This is a one-step integration method and does not have prediction step.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-04 21:26:29 +00:00
|
|
|
class AdamsBashforth2
|
|
|
|
:
|
|
|
|
public integration
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
/// dy at t-dt
|
2022-09-04 21:26:29 +00:00
|
|
|
realx3PointField_D& dy1_;
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
/// Range policy for integration kernel (alias)
|
2022-09-04 21:26:29 +00:00
|
|
|
using rpIntegration = Kokkos::RangePolicy<
|
|
|
|
DefaultExecutionSpace,
|
|
|
|
Kokkos::Schedule<Kokkos::Static>,
|
|
|
|
Kokkos::IndexType<int32>
|
|
|
|
>;
|
2023-04-23 19:47:12 +00:00
|
|
|
|
2022-09-04 21:26:29 +00:00
|
|
|
public:
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
/// Type info
|
2022-12-09 22:02:54 +00:00
|
|
|
TypeInfo("AdamsBashforth2");
|
2022-09-04 21:26:29 +00:00
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
// - Constructors
|
|
|
|
|
|
|
|
/// Construct from components
|
2022-09-04 21:26:29 +00:00
|
|
|
AdamsBashforth2(
|
|
|
|
const word& baseName,
|
|
|
|
repository& owner,
|
|
|
|
const pointStructure& pStruct,
|
|
|
|
const word& method);
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
uniquePtr<integration> clone()const override
|
|
|
|
{
|
|
|
|
return makeUnique<AdamsBashforth2>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructor
|
2022-09-04 21:26:29 +00:00
|
|
|
virtual ~AdamsBashforth2()=default;
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
/// Add this to the virtual constructor table
|
2022-09-04 21:26:29 +00:00
|
|
|
add_vCtor(
|
|
|
|
integration,
|
|
|
|
AdamsBashforth2,
|
|
|
|
word);
|
|
|
|
|
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
// - Methods
|
2022-09-04 21:26:29 +00:00
|
|
|
|
2023-04-23 19:47:12 +00:00
|
|
|
bool predict(
|
|
|
|
real UNUSED(dt),
|
|
|
|
realx3Vector_D& UNUSED(y),
|
|
|
|
realx3Vector_D& UNUSED(dy)) override;
|
|
|
|
|
|
|
|
bool correct(
|
|
|
|
real dt,
|
|
|
|
realx3Vector_D& y,
|
|
|
|
realx3Vector_D& dy) override;
|
2022-09-04 21:26:29 +00:00
|
|
|
|
2022-10-25 16:00:57 +00:00
|
|
|
bool setInitialVals(
|
|
|
|
const int32IndexContainer& newIndices,
|
|
|
|
const realx3Vector& y) override;
|
|
|
|
|
|
|
|
bool needSetInitialVals()const override
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-23 19:47:12 +00:00
|
|
|
|
|
|
|
/// Integrate on all points in the active range
|
|
|
|
bool intAll(
|
|
|
|
real dt,
|
|
|
|
realx3Vector_D& y,
|
|
|
|
realx3Vector_D& dy,
|
|
|
|
range activeRng);
|
|
|
|
|
|
|
|
/// Integrate on active points in the active range
|
2022-09-04 21:26:29 +00:00
|
|
|
template<typename activeFunctor>
|
2023-04-23 19:47:12 +00:00
|
|
|
bool intRange(
|
|
|
|
real dt,
|
|
|
|
realx3Vector_D& y,
|
|
|
|
realx3Vector_D& dy,
|
|
|
|
activeFunctor activeP );
|
2022-09-04 21:26:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename activeFunctor>
|
|
|
|
bool pFlow::AdamsBashforth2::intRange(
|
|
|
|
real dt,
|
|
|
|
realx3Vector_D& y,
|
|
|
|
realx3Vector_D& dy,
|
|
|
|
activeFunctor activeP )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto d_dy = dy.deviceVectorAll();
|
|
|
|
auto d_y = y.deviceVectorAll();
|
|
|
|
auto d_dy1= dy1_.deviceVectorAll();
|
|
|
|
auto activeRng = activeP.activeRange();
|
|
|
|
|
|
|
|
Kokkos::parallel_for(
|
|
|
|
"AdamsBashforth2::correct",
|
|
|
|
rpIntegration (activeRng.first, activeRng.second),
|
|
|
|
LAMBDA_HD(int32 i){
|
|
|
|
if( activeP(i))
|
|
|
|
{
|
|
|
|
d_y[i] += dt*(static_cast<real>(3.0 / 2.0) * d_dy[i] - static_cast<real>(1.0 / 2.0) * d_dy1[i]);
|
|
|
|
d_dy1[i] = d_dy[i];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Kokkos::fence();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // pFlow
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#endif //__integration_hpp__
|