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