www.cemf.ir
AdamsBashforth2.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __AdamsBashforth2_hpp__
22 #define __AdamsBashforth2_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
38 :
39  public integration
40 {
41 protected:
42 
45 
47  using rpIntegration = Kokkos::RangePolicy<
49  Kokkos::Schedule<Kokkos::Static>,
50  Kokkos::IndexType<int32>
51  >;
52 
53 public:
54 
56  TypeInfo("AdamsBashforth2");
57 
58  // - Constructors
59 
62  const word& baseName,
64  const pointStructure& pStruct,
65  const word& method);
66 
67  uniquePtr<integration> clone()const override
68  {
69  return makeUnique<AdamsBashforth2>(*this);
70  }
71 
73  virtual ~AdamsBashforth2()=default;
74 
76  add_vCtor(
79  word);
80 
81 
82  // - Methods
83 
84  bool predict(
85  real UNUSED(dt),
87  realx3Vector_D& UNUSED(dy)) override;
88 
89  bool correct(
90  real dt,
91  realx3Vector_D& y,
92  realx3Vector_D& dy) override;
93 
94  bool setInitialVals(
95  const int32IndexContainer& newIndices,
96  const realx3Vector& y) override;
97 
98  bool needSetInitialVals()const override
99  {
100  return false;
101  }
102 
104  bool intAll(
105  real dt,
106  realx3Vector_D& y,
107  realx3Vector_D& dy,
108  range activeRng);
109 
111  template<typename activeFunctor>
112  bool intRange(
113  real dt,
114  realx3Vector_D& y,
115  realx3Vector_D& dy,
116  activeFunctor activeP );
117 
118 };
119 
120 template<typename activeFunctor>
122  real dt,
123  realx3Vector_D& y,
124  realx3Vector_D& dy,
125  activeFunctor activeP )
126 {
127 
128  auto d_dy = dy.deviceVectorAll();
129  auto d_y = y.deviceVectorAll();
130  auto d_dy1= dy1_.deviceVectorAll();
131  auto activeRng = activeP.activeRange();
132 
133  Kokkos::parallel_for(
134  "AdamsBashforth2::correct",
135  rpIntegration (activeRng.first, activeRng.second),
136  LAMBDA_HD(int32 i){
137  if( activeP(i))
138  {
139  d_y[i] += dt*(static_cast<real>(3.0 / 2.0) * d_dy[i] - static_cast<real>(1.0 / 2.0) * d_dy1[i]);
140  d_dy1[i] = d_dy[i];
141  }
142  });
143  Kokkos::fence();
144 
145 
146  return true;
147 }
148 
149 } // pFlow
150 
151 #endif //__integration_hpp__
pFlow::AdamsBashforth2::needSetInitialVals
bool needSetInitialVals() const override
Check if the method requires any set initial vals.
Definition: AdamsBashforth2.hpp:98
pFlow::AdamsBashforth2::dy1_
realx3PointField_D & dy1_
dy at t-dt
Definition: AdamsBashforth2.hpp:44
pFlow::AdamsBashforth2::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Correction/main integration step.
Definition: AdamsBashforth2.cpp:59
pFlow::AdamsBashforth2::clone
uniquePtr< integration > clone() const override
Polymorphic copy/cloning.
Definition: AdamsBashforth2.hpp:67
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::AdamsBashforth2::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsBashforth2.hpp:121
pFlow::range
kRange< int > range
Definition: KokkosTypes.hpp:59
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::AdamsBashforth2::~AdamsBashforth2
virtual ~AdamsBashforth2()=default
Destructor.
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:49
pFlow::integration::pStruct
const auto & pStruct() const
Const ref to pointStructure.
Definition: integration.hpp:113
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pointFields.hpp
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Definition: KokkosTypes.hpp:49
pFlow::AdamsBashforth2::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsBashforth2.cpp:77
pFlow::integration::baseName
const word & baseName() const
Base name.
Definition: integration.hpp:120
pFlow
Definition: demComponent.hpp:28
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::VectorSingle
Definition: VectorSingle.hpp:47
pFlow::integration::owner
repository & owner()
Ref to the owner repository.
Definition: integration.hpp:127
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::AdamsBashforth2
Second order Adams-Bashforth integration method for solving ODE.
Definition: AdamsBashforth2.hpp:37
integration.hpp
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::AdamsBashforth2::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsBashforth2.cpp:84
pFlow::AdamsBashforth2::AdamsBashforth2
AdamsBashforth2(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Construct from components.
Definition: AdamsBashforth2.cpp:26
pFlow::AdamsBashforth2::TypeInfo
TypeInfo("AdamsBashforth2")
Type info.
pFlow::repository
Definition: repository.hpp:34
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:297
pFlow::Vector< realx3 >
pFlow::indexContainer< int32 >
pFlow::AdamsBashforth2::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel (alias)
Definition: AdamsBashforth2.hpp:51
pFlow::AdamsBashforth2::add_vCtor
add_vCtor(integration, AdamsBashforth2, word)
Add this to the virtual constructor table.
pFlow::AdamsBashforth2::predict
bool predict(real UNUSED(dt), realx3Vector_D &UNUSED(y), realx3Vector_D &UNUSED(dy)) override
Definition: AdamsBashforth2.cpp:48