mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-22 16:28:30 +00:00
refactor up to particles.hpp
This commit is contained in:
@ -19,36 +19,107 @@ Licence:
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "AdamsBashforth2.hpp"
|
||||
#include "pointStructure.hpp"
|
||||
#include "Time.hpp"
|
||||
#include "vocabs.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
/// Range policy for integration kernel (alias)
|
||||
using rpIntegration = Kokkos::RangePolicy<
|
||||
DefaultExecutionSpace,
|
||||
Kokkos::Schedule<Kokkos::Static>,
|
||||
Kokkos::IndexType<uint32>
|
||||
>;
|
||||
|
||||
bool intAllActive(
|
||||
real dt,
|
||||
realx3PointField_D& y,
|
||||
realx3PointField_D& dy,
|
||||
realx3PointField_D& dy1)
|
||||
{
|
||||
|
||||
auto d_dy = dy.fieldDevice();
|
||||
auto d_y = y.fieldDevice();
|
||||
auto d_dy1= dy1.fieldDevice();
|
||||
auto activeRng = dy1.activeRange();
|
||||
|
||||
Kokkos::parallel_for(
|
||||
"AdamsBashforth2::correct",
|
||||
rpIntegration (activeRng.start(), activeRng.end()),
|
||||
LAMBDA_HD(int32 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,
|
||||
realx3PointField_D& y,
|
||||
realx3PointField_D& dy,
|
||||
realx3PointField_D& dy1
|
||||
)
|
||||
{
|
||||
|
||||
auto d_dy = dy.fieldDevice();
|
||||
auto d_y = y.fieldDevice();
|
||||
auto d_dy1 = dy1.fieldDevice();
|
||||
auto activeRng = dy1.activeRange();
|
||||
const auto& activeP = dy1.activePointsMaskDevice();
|
||||
|
||||
Kokkos::parallel_for(
|
||||
"AdamsBashforth2::correct",
|
||||
rpIntegration (activeRng.start(), activeRng.end()),
|
||||
LAMBDA_HD(int32 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//const real AB2_coef[] = { 3.0 / 2.0, 1.0 / 2.0};
|
||||
|
||||
pFlow::AdamsBashforth2::AdamsBashforth2
|
||||
(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField
|
||||
)
|
||||
:
|
||||
integration(baseName, owner, pStruct, method),
|
||||
dy1_(
|
||||
owner.emplaceObject<realx3PointField_D>(
|
||||
objectFile(
|
||||
groupNames(baseName,"dy1"),
|
||||
"",
|
||||
objectFile::READ_IF_PRESENT,
|
||||
objectFile::WRITE_ALWAYS),
|
||||
pStruct,
|
||||
zero3))
|
||||
{
|
||||
|
||||
}
|
||||
integration(baseName, pStruct, method, initialValField),
|
||||
realx3PointField_D
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
groupNames(baseName,"dy1"),
|
||||
pStruct.time().integrationFolder(),
|
||||
objectFile::READ_IF_PRESENT,
|
||||
objectFile::WRITE_ALWAYS
|
||||
),
|
||||
pStruct,
|
||||
zero3
|
||||
)
|
||||
{}
|
||||
|
||||
bool pFlow::AdamsBashforth2::predict
|
||||
(
|
||||
real UNUSED(dt),
|
||||
realx3Vector_D& UNUSED(y),
|
||||
realx3Vector_D& UNUSED(dy)
|
||||
realx3PointField_D& UNUSED(y),
|
||||
realx3PointField_D& UNUSED(dy)
|
||||
)
|
||||
{
|
||||
|
||||
@ -58,17 +129,19 @@ bool pFlow::AdamsBashforth2::predict
|
||||
bool pFlow::AdamsBashforth2::correct
|
||||
(
|
||||
real dt,
|
||||
realx3Vector_D& y,
|
||||
realx3Vector_D& dy
|
||||
realx3PointField_D& y,
|
||||
realx3PointField_D& dy
|
||||
)
|
||||
{
|
||||
if(this->pStruct().allActive())
|
||||
auto& dy1l = dy1();
|
||||
|
||||
if(dy1l.isAllActive())
|
||||
{
|
||||
return intAll(dt, y, dy, this->pStruct().activeRange());
|
||||
return intAllActive(dt, y, dy, dy1l);
|
||||
}
|
||||
else
|
||||
{
|
||||
return intRange(dt, y, dy, this->pStruct().activePointsMaskD());
|
||||
return intScattered(dt, y, dy, dy1l);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -81,25 +154,3 @@ bool pFlow::AdamsBashforth2::setInitialVals(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::AdamsBashforth2::intAll(
|
||||
real dt,
|
||||
realx3Vector_D& y,
|
||||
realx3Vector_D& dy,
|
||||
range activeRng)
|
||||
{
|
||||
|
||||
auto d_dy = dy.deviceVectorAll();
|
||||
auto d_y = y.deviceVectorAll();
|
||||
auto d_dy1= dy1_.deviceVectorAll();
|
||||
|
||||
Kokkos::parallel_for(
|
||||
"AdamsBashforth2::correct",
|
||||
rpIntegration (activeRng.first, activeRng.second),
|
||||
LAMBDA_HD(int32 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;
|
||||
}
|
@ -36,20 +36,16 @@ namespace pFlow
|
||||
*/
|
||||
class AdamsBashforth2
|
||||
:
|
||||
public integration
|
||||
public integration,
|
||||
public realx3PointField_D
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
/// dy at t-dt
|
||||
realx3PointField_D& dy1_;
|
||||
|
||||
/// Range policy for integration kernel (alias)
|
||||
using rpIntegration = Kokkos::RangePolicy<
|
||||
DefaultExecutionSpace,
|
||||
Kokkos::Schedule<Kokkos::Static>,
|
||||
Kokkos::IndexType<int32>
|
||||
>;
|
||||
|
||||
auto& dy1()
|
||||
{
|
||||
return static_cast<realx3PointField_D&>(*this);
|
||||
}
|
||||
public:
|
||||
|
||||
/// Type info
|
||||
@ -60,17 +56,12 @@ public:
|
||||
/// Construct from components
|
||||
AdamsBashforth2(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method);
|
||||
|
||||
uniquePtr<integration> clone()const override
|
||||
{
|
||||
return makeUnique<AdamsBashforth2>(*this);
|
||||
}
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField);
|
||||
|
||||
/// Destructor
|
||||
virtual ~AdamsBashforth2()=default;
|
||||
~AdamsBashforth2()final = default;
|
||||
|
||||
/// Add this to the virtual constructor table
|
||||
add_vCtor(
|
||||
@ -80,71 +71,33 @@ public:
|
||||
|
||||
|
||||
// - Methods
|
||||
/// return integration method
|
||||
word method()const override
|
||||
{
|
||||
return "AdamsBashforth2";
|
||||
}
|
||||
|
||||
bool predict(
|
||||
real UNUSED(dt),
|
||||
realx3Vector_D& UNUSED(y),
|
||||
realx3Vector_D& UNUSED(dy)) override;
|
||||
realx3PointField_D& UNUSED(y),
|
||||
realx3PointField_D& UNUSED(dy)) final;
|
||||
|
||||
bool correct(
|
||||
real dt,
|
||||
realx3Vector_D& y,
|
||||
realx3Vector_D& dy) override;
|
||||
realx3PointField_D& y,
|
||||
realx3PointField_D& dy) final;
|
||||
|
||||
bool setInitialVals(
|
||||
const int32IndexContainer& newIndices,
|
||||
const realx3Vector& y) override;
|
||||
const realx3Vector& y) final;
|
||||
|
||||
bool needSetInitialVals()const override
|
||||
bool needSetInitialVals()const final
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 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
|
||||
template<typename activeFunctor>
|
||||
bool intRange(
|
||||
real dt,
|
||||
realx3Vector_D& y,
|
||||
realx3Vector_D& dy,
|
||||
activeFunctor activeP );
|
||||
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
|
||||
list(APPEND SourceFiles
|
||||
integration/integration.cpp
|
||||
AdamsBashforth5/AdamsBashforth5.cpp
|
||||
AdamsBashforth4/AdamsBashforth4.cpp
|
||||
AdamsBashforth3/AdamsBashforth3.cpp
|
||||
AdamsBashforth2/AdamsBashforth2.cpp
|
||||
AdamsMoulton3/AdamsMoulton3.cpp
|
||||
AdamsMoulton4/AdamsMoulton4.cpp
|
||||
AdamsMoulton5/AdamsMoulton5.cpp
|
||||
#AdamsBashforth5/AdamsBashforth5.cpp
|
||||
#AdamsBashforth4/AdamsBashforth4.cpp
|
||||
#AdamsBashforth3/AdamsBashforth3.cpp
|
||||
#AdamsMoulton3/AdamsMoulton3.cpp
|
||||
#AdamsMoulton4/AdamsMoulton4.cpp
|
||||
#AdamsMoulton5/AdamsMoulton5.cpp
|
||||
)
|
||||
|
||||
set(link_libs Kokkos::kokkos phasicFlow)
|
||||
|
@ -19,33 +19,35 @@ Licence:
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "integration.hpp"
|
||||
#include "pointStructure.hpp"
|
||||
#include "repository.hpp"
|
||||
|
||||
pFlow::integration::integration
|
||||
(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method
|
||||
pointStructure& pStruct,
|
||||
const word&,
|
||||
const realx3Field_D&
|
||||
)
|
||||
:
|
||||
owner_(owner),
|
||||
baseName_(baseName),
|
||||
pStruct_(pStruct)
|
||||
{
|
||||
CONSUME_PARAM(method);
|
||||
}
|
||||
owner_(*pStruct.owner()),
|
||||
pStruct_(pStruct),
|
||||
baseName_(baseName)
|
||||
{}
|
||||
|
||||
|
||||
pFlow::uniquePtr<pFlow::integration>
|
||||
pFlow::integration::create(
|
||||
pFlow::integration::create
|
||||
(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method)
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField
|
||||
)
|
||||
{
|
||||
if( wordvCtorSelector_.search(method) )
|
||||
{
|
||||
return wordvCtorSelector_[method] (baseName, owner, pStruct, method);
|
||||
return wordvCtorSelector_[method] (baseName, pStruct, method, initialValField);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -23,14 +23,16 @@ Licence:
|
||||
|
||||
|
||||
#include "virtualConstructor.hpp"
|
||||
#include "Vectors.hpp"
|
||||
#include "pointStructure.hpp"
|
||||
#include "repository.hpp"
|
||||
#include "pointFields.hpp"
|
||||
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
// - Forward
|
||||
class repository;
|
||||
class pointStructure;
|
||||
|
||||
/**
|
||||
* Base class for integrating the first order ODE (IVP)
|
||||
*
|
||||
@ -48,19 +50,19 @@ namespace pFlow
|
||||
*/
|
||||
class integration
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
// - Protected data members
|
||||
|
||||
/// The owner repository that all fields are storred in
|
||||
repository& owner_;
|
||||
|
||||
/// The base name for integration
|
||||
const word baseName_;
|
||||
|
||||
/// A reference to pointStructure
|
||||
const pointStructure& pStruct_;
|
||||
|
||||
/// The base name for integration
|
||||
const word baseName_;
|
||||
|
||||
public:
|
||||
|
||||
/// Type info
|
||||
@ -72,9 +74,9 @@ public:
|
||||
/// Construct from components
|
||||
integration(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method);
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField);
|
||||
|
||||
/// Copy constructor
|
||||
integration(const integration&) = default;
|
||||
@ -88,22 +90,22 @@ public:
|
||||
/// Move assignment
|
||||
integration& operator = (integration&&) = default;
|
||||
|
||||
/// Polymorphic copy/cloning
|
||||
virtual
|
||||
uniquePtr<integration> clone()const=0;
|
||||
|
||||
/// Destructor
|
||||
virtual ~integration()=default;
|
||||
|
||||
/// Add a virtual constructor
|
||||
create_vCtor(
|
||||
create_vCtor
|
||||
(
|
||||
integration,
|
||||
word,
|
||||
(const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method),
|
||||
(baseName, owner, pStruct, method) );
|
||||
(
|
||||
const word& baseName,
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField
|
||||
),
|
||||
(baseName, pStruct, method, initialValField)
|
||||
);
|
||||
|
||||
|
||||
// - Methods
|
||||
@ -129,13 +131,17 @@ public:
|
||||
return owner_;
|
||||
}
|
||||
|
||||
/// return integration method
|
||||
virtual
|
||||
word method()const = 0 ;
|
||||
|
||||
/// Prediction step in integration
|
||||
virtual
|
||||
bool predict(real dt, realx3Vector_D& y, realx3Vector_D& dy) = 0;
|
||||
bool predict(real dt, realx3PointField_D& y, realx3PointField_D& dy) = 0;
|
||||
|
||||
/// Correction/main integration step
|
||||
virtual
|
||||
bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) = 0;
|
||||
bool correct(real dt, realx3PointField_D& y, realx3PointField_D& dy) = 0;
|
||||
|
||||
/// Set the initial values for new indices
|
||||
virtual
|
||||
@ -152,9 +158,9 @@ public:
|
||||
static
|
||||
uniquePtr<integration> create(
|
||||
const word& baseName,
|
||||
repository& owner,
|
||||
const pointStructure& pStruct,
|
||||
const word& method);
|
||||
pointStructure& pStruct,
|
||||
const word& method,
|
||||
const realx3Field_D& initialValField);
|
||||
|
||||
}; // integration
|
||||
|
||||
|
Reference in New Issue
Block a user