www.cemf.ir
AdamsMoulton3.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 __AdamsMoulton3_hpp__
22 #define __AdamsMoulton3_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
37 :
38  public integration
39 {
40 protected:
41 
44 
47 
50 
52  using rpIntegration = Kokkos::RangePolicy<
54  Kokkos::Schedule<Kokkos::Static>,
55  Kokkos::IndexType<int32>
56  >;
57 public:
58 
60  TypeInfo("AdamsMoulton3");
61 
62  // - Constructors
63 
66  const word& baseName,
68  const pointStructure& pStruct,
69  const word& method);
70 
71  uniquePtr<integration> clone()const override
72  {
73  return makeUnique<AdamsMoulton3>(*this);
74  }
75 
77  virtual ~AdamsMoulton3()=default;
78 
80  add_vCtor(
83  word);
84 
85 
86  // - Methods
87 
88  bool predict(
89  real dt,
90  realx3Vector_D& y,
91  realx3Vector_D& dy) override;
92 
93  bool correct(
94  real dt,
95  realx3Vector_D& y,
96  realx3Vector_D& dy) override;
97 
98  bool setInitialVals(
99  const int32IndexContainer& newIndices,
100  const realx3Vector& y) override;
101 
102  bool needSetInitialVals()const override
103  {
104  return true;
105  }
106 
108  bool predictAll(
109  real dt,
110  realx3Vector_D& y,
111  realx3Vector_D& dy,
112  range activeRng);
113 
115  template<typename activeFunctor>
116  bool predictRange(
117  real dt,
118  realx3Vector_D& y,
119  realx3Vector_D& dy,
120  activeFunctor activeP);
121 
123  bool intAll(
124  real dt,
125  realx3Vector_D& y,
126  realx3Vector_D& dy,
127  range activeRng);
128 
130  template<typename activeFunctor>
131  bool intRange(
132  real dt,
133  realx3Vector_D& y,
134  realx3Vector_D& dy,
135  activeFunctor activeP);
136 
137 };
138 
139 
140 template<typename activeFunctor>
142  real dt,
143  realx3Vector_D& y,
144  realx3Vector_D& dy,
145  activeFunctor activeP)
146 {
147  auto d_dy = dy.deviceViewAll();
148  auto d_y = y.deviceViewAll();
149  auto d_y0 = y0_.deviceViewAll();
150  auto d_dy0 = dy0_.deviceViewAll();
151  auto d_dy1= dy1_.deviceViewAll();
152 
153  auto activeRng = activeP.activeRange();
154 
155  Kokkos::parallel_for(
156  "AdamsMoulton3::predictRange",
157  rpIntegration (activeRng.first, activeRng.second),
158  LAMBDA_HD(int32 i){
159  if(activeP(i))
160  {
161  d_dy0[i] = d_dy[i];
162  d_y[i] = d_y0[i] +
163  dt*
164  (
165  static_cast<real>(3.0 / 2.0) * d_dy[i]
166  - static_cast<real>(1.0 / 2.0) * d_dy1[i]
167  );
168  }
169  });
170  Kokkos::fence();
171 
172  return true;
173 
174 }
175 
176 
177 template<typename activeFunctor>
179  real dt,
180  realx3Vector_D& y,
181  realx3Vector_D& dy,
182  activeFunctor activeP)
183 {
184 
185  auto d_dy = dy.deviceViewAll();
186  auto d_y = y.deviceViewAll();
187 
188  auto d_dy0 = dy0_.deviceViewAll();
189  auto d_y0 = y0_.deviceViewAll();
190  auto d_dy1 = dy1_.deviceViewAll();
191 
192  auto activeRng = activeP.activeRange();
193 
194  Kokkos::parallel_for(
195  "AdamsMoulton3::correct",
196  rpIntegration (activeRng.first, activeRng.second),
197  LAMBDA_HD(int32 i){
198  if( activeP(i))
199  {
200  auto corrct_y = d_y0[i] + dt*(
201  static_cast<real>(5.0/12.0)*d_dy[i]
202  + static_cast<real>(8.0/12.0)*d_dy0[i]
203  - static_cast<real>(1.0/12.0)*d_dy1[i]);
204  d_dy1[i]= d_dy0[i];
205  d_y0[i] = corrct_y;
206  d_y[i] = corrct_y;
207  }
208  });
209  Kokkos::fence();
210 
211 
212  return true;
213 }
214 
215 } // pFlow
216 
217 #endif //
pFlow::AdamsMoulton3::TypeInfo
TypeInfo("AdamsMoulton3")
Type info.
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::AdamsMoulton3::add_vCtor
add_vCtor(integration, AdamsMoulton3, word)
Add this to the virtual constructor table.
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::internalField::deviceViewAll
const auto & deviceViewAll() const
Definition: internalField.hpp:92
pFlow::integration::pStruct
const auto & pStruct() const
Const ref to pointStructure.
Definition: integration.hpp:115
pFlow::AdamsMoulton3::AdamsMoulton3
AdamsMoulton3(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Construct from components.
Definition: AdamsMoulton3.cpp:26
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pointFields.hpp
pFlow::AdamsMoulton3::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsMoulton3.cpp:146
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Default execution space, it can be device exe.
Definition: KokkosTypes.hpp:61
pFlow::AdamsMoulton3::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel.
Definition: AdamsMoulton3.hpp:56
pFlow::integration::baseName
const word & baseName() const
Base name.
Definition: integration.hpp:122
pFlow
Definition: demGeometry.hpp:27
pFlow::AdamsMoulton3::predictRange
bool predictRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Prediction step on active points in the active range.
Definition: AdamsMoulton3.hpp:141
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::AdamsMoulton3::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsMoulton3.cpp:111
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::AdamsMoulton3::dy0_
realx3PointField_D & dy0_
dy at time t
Definition: AdamsMoulton3.hpp:46
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::AdamsMoulton3::clone
uniquePtr< integration > clone() const override
Definition: AdamsMoulton3.hpp:71
pFlow::integration::owner
repository & owner()
Ref to the owner repository.
Definition: integration.hpp:129
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::AdamsMoulton3::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsMoulton3.hpp:178
pFlow::AdamsMoulton3::predictAll
bool predictAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Prediction step on all points in the active range.
Definition: AdamsMoulton3.cpp:120
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
integration.hpp
pFlow::AdamsMoulton3::dy1_
realx3PointField_D & dy1_
dy at time t-dt
Definition: AdamsMoulton3.hpp:49
pFlow::AdamsMoulton3::predict
bool predict(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton3.cpp:73
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::AdamsMoulton3::y0_
realx3PointField_D & y0_
y at time t
Definition: AdamsMoulton3.hpp:43
pFlow::AdamsMoulton3::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton3.cpp:93
pFlow::AdamsMoulton3::~AdamsMoulton3
virtual ~AdamsMoulton3()=default
Destructor.
pFlow::integration::method
virtual word method() const =0
return integration method
pFlow::repository
Definition: repository.hpp:34
pFlow::AdamsMoulton3
Third order Adams-Moulton integration method for solving ODE.
Definition: AdamsMoulton3.hpp:36
pFlow::Vector< realx3 >
pFlow::AdamsMoulton3::needSetInitialVals
bool needSetInitialVals() const override
Check if the method requires any set initial vals.
Definition: AdamsMoulton3.hpp:102
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39