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