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