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 
31 
33 :
34  public integration
35 {
36 protected:
37 
39 
41 
43 
45 
47 
48  using rpIntegration = Kokkos::RangePolicy<
50  Kokkos::Schedule<Kokkos::Static>,
51  Kokkos::IndexType<int32>
52  >;
53 public:
54 
55  // type info
56  TypeInfo("AdamsMoulton5");
57 
60  const word& baseName,
62  const pointStructure& pStruct,
63  const word& method);
64 
65  virtual ~AdamsMoulton5()=default;
66 
67  // - add a virtual constructor
68  add_vCtor(
71  word);
72 
73 
75  bool predict(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
76 
77  bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
78 
79  bool setInitialVals(
80  const int32IndexContainer& newIndices,
81  const realx3Vector& y) override;
82 
83  bool needSetInitialVals()const override
84  {
85  return true;
86  }
87 
88  uniquePtr<integration> clone()const override
89  {
90  return makeUnique<AdamsMoulton5>(*this);
91  }
92 
93  bool predictAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
94 
95  template<typename activeFunctor>
96  bool predictRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP);
97 
98  bool intAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
99 
100  template<typename activeFunctor>
101  bool intRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP );
102 
103 };
104 
105 
106 template<typename activeFunctor>
108  real dt,
109  realx3Vector_D& y,
110  realx3Vector_D& dy,
111  activeFunctor activeP )
112 {
113  auto d_dy = dy.deviceVectorAll();
114  auto d_y = y.deviceVectorAll();
115 
116  auto d_y0 = y0_.deviceVectorAll();
117  auto d_dy0 = dy0_.deviceVectorAll();
118  auto d_dy1 = dy1_.deviceVectorAll();
119  auto d_dy2 = dy2_.deviceVectorAll();
120  auto d_dy3 = dy3_.deviceVectorAll();
121 
122  auto activeRng = activeP.activeRange();
123 
124  Kokkos::parallel_for(
125  "AdamsMoulton5::predictRange",
126  rpIntegration (activeRng.first, activeRng.second),
127  LAMBDA_HD(int32 i){
128  if(activeP(i))
129  {
130  d_dy0[i] = d_dy[i];
131  d_y[i] = d_y0[i] + dt*(
132  static_cast<real>(55.0/24.0) * d_dy[i]
133  - static_cast<real>(59.0/24.0) * d_dy1[i]
134  + static_cast<real>(37.0/24.0) * d_dy2[i]
135  - static_cast<real>( 9.0/24.0) * d_dy3[i]);
136  }
137  });
138  Kokkos::fence();
139 
140  return true;
141 
142 }
143 
144 template<typename activeFunctor>
146  real dt,
147  realx3Vector_D& y,
148  realx3Vector_D& dy,
149  activeFunctor activeP )
150 {
151 
152  auto d_dy = dy.deviceVectorAll();
153  auto d_y = y.deviceVectorAll();
154 
155  auto d_dy0 = dy0_.deviceVectorAll();
156  auto d_y0 = y0_.deviceVectorAll();
157  auto d_dy1 = dy1_.deviceVectorAll();
158  auto d_dy2 = dy2_.deviceVectorAll();
159  auto d_dy3 = dy3_.deviceVectorAll();
160 
161  auto activeRng = activeP.activeRange();
162 
163  Kokkos::parallel_for(
164  "AdamsMoulton5::correct",
165  rpIntegration (activeRng.first, activeRng.second),
166  LAMBDA_HD(int32 i){
167  if( activeP(i))
168  {
169  auto corrct_y = d_y0[i] + dt*(
170  static_cast<real>(251.0/720.0)*d_dy[i]
171  + static_cast<real>(646.0/720.0)*d_dy0[i]
172  - static_cast<real>(264.0/720.0)*d_dy1[i]
173  + static_cast<real>(106.0/720.0)*d_dy2[i]
174  - static_cast<real>( 19.0/720.0)*d_dy3[i]);
175 
176  d_dy3[i]= d_dy2[i];
177  d_dy2[i]= d_dy1[i];
178  d_dy1[i]= d_dy0[i];
179  d_y0[i] = corrct_y;
180  d_y[i] = corrct_y;
181  }
182  });
183  Kokkos::fence();
184 
185 
186  return true;
187 }
188 
189 } // pFlow
190 
191 #endif //__integration_hpp__
pFlow::AdamsMoulton5::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsMoulton5.cpp:132
pFlow::AdamsMoulton5::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsMoulton5.hpp:52
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::AdamsMoulton5::predictRange
bool predictRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsMoulton5.hpp:107
pFlow::integration
Definition: integration.hpp:35
pFlow::AdamsMoulton5::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton5.cpp:174
pFlow::integration::pStruct
const auto & pStruct() const
Definition: integration.hpp:72
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pointFields.hpp
pFlow::AdamsMoulton5::add_vCtor
add_vCtor(integration, AdamsMoulton5, word)
pFlow::AdamsMoulton5
Definition: AdamsMoulton5.hpp:32
pFlow::AdamsMoulton5::predictAll
bool predictAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton5.cpp:141
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Definition: KokkosTypes.hpp:47
pFlow::integration::baseName
const word & baseName() const
Definition: integration.hpp:89
pFlow
Definition: demComponent.hpp:28
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::AdamsMoulton5::dy0_
realx3PointField_D & dy0_
Definition: AdamsMoulton5.hpp:40
pFlow::AdamsMoulton5::dy1_
realx3PointField_D & dy1_
Definition: AdamsMoulton5.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::AdamsMoulton5::clone
uniquePtr< integration > clone() const override
Definition: AdamsMoulton5.hpp:88
pFlow::AdamsMoulton5::y0_
realx3PointField_D & y0_
Definition: AdamsMoulton5.hpp:38
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::AdamsMoulton5::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton5.cpp:114
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::AdamsMoulton5::AdamsMoulton5
AdamsMoulton5(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsMoulton5.cpp:25
pFlow::AdamsMoulton5::needSetInitialVals
bool needSetInitialVals() const override
Definition: AdamsMoulton5.hpp:83
pFlow::integration::owner
repository & owner()
Definition: integration.hpp:94
pFlow::AdamsMoulton5::predict
bool predict(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton5.cpp:94
pFlow::AdamsMoulton5::dy2_
realx3PointField_D & dy2_
Definition: AdamsMoulton5.hpp:44
pFlow::AdamsMoulton5::dy3_
realx3PointField_D & dy3_
Definition: AdamsMoulton5.hpp:46
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
integration.hpp
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::AdamsMoulton5::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsMoulton5.hpp:145
pFlow::AdamsMoulton5::~AdamsMoulton5
virtual ~AdamsMoulton5()=default
pFlow::repository
Definition: repository.hpp:34
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::Vector< realx3 >
pFlow::AdamsMoulton5::TypeInfo
TypeInfo("AdamsMoulton5")
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::indexContainer< int32 >