AdamsMoulton4.cpp
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 #include "AdamsMoulton4.hpp"
22 
23 //const real AB2_coef[] = { 3.0 / 2.0, 1.0 / 2.0};
24 
26 (
27  const word& baseName,
28  repository& owner,
29  const pointStructure& pStruct,
30  const word& method
31 )
32 :
33  integration(baseName, owner, pStruct, method),
34  y0_(
36  objectFile(
37  groupNames(baseName,"y0"),
38  "",
39  objectFile::READ_IF_PRESENT,
40  objectFile::WRITE_ALWAYS),
41  pStruct,
42  zero3,
43  false
44  )
45  ),
46  dy0_(
48  objectFile(
49  groupNames(baseName,"dy0"),
50  "",
51  objectFile::READ_IF_PRESENT,
52  objectFile::WRITE_ALWAYS),
53  pStruct,
54  zero3
55  )
56  ),
57  dy1_(
59  objectFile(
60  groupNames(baseName,"dy1"),
61  "",
62  objectFile::READ_IF_PRESENT,
63  objectFile::WRITE_ALWAYS),
64  pStruct,
65  zero3
66  )
67  ),
68  dy2_(
70  objectFile(
71  groupNames(baseName,"dy2"),
72  "",
73  objectFile::READ_IF_PRESENT,
74  objectFile::WRITE_ALWAYS),
75  pStruct,
76  zero3
77  )
78  )
79 {
80 
81 }
82 
84 (
85  real dt,
86  realx3Vector_D& y,
87  realx3Vector_D& dy
88 )
89 {
90 
91  if(this->pStruct().allActive())
92  {
93  return predictAll(dt, y, dy, this->pStruct().activeRange());
94  }
95  else
96  {
97  return predictRange(dt, y, dy, this->pStruct().activePointsMaskD());
98  }
99 
100  return true;
101 }
102 
104 (
105  real dt,
106  realx3Vector_D& y,
107  realx3Vector_D& dy
108 )
109 {
110  if(this->pStruct().allActive())
111  {
112  return intAll(dt, y, dy, this->pStruct().activeRange());
113  }
114  else
115  {
116  return intRange(dt, y, dy, this->pStruct().activePointsMaskD());
117  }
118 
119  return true;
120 }
121 
123  const int32IndexContainer& newIndices,
124  const realx3Vector& y)
125 {
126  y0_.insertSetElement(newIndices, y);
127 
128  return true;
129 }
130 
132  real dt,
133  realx3Vector_D& y,
134  realx3Vector_D& dy,
135  range activeRng)
136 {
137 
138  auto d_dy = dy.deviceVectorAll();
139  auto d_y = y.deviceVectorAll();
140 
141  auto d_y0 = y0_.deviceVectorAll();
142  auto d_dy0 = dy0_.deviceVectorAll();
143  auto d_dy1 = dy1_.deviceVectorAll();
144  auto d_dy2 = dy2_.deviceVectorAll();
145 
146  Kokkos::parallel_for(
147  "AdamsMoulton4::predict",
148  rpIntegration (activeRng.first, activeRng.second),
149  LAMBDA_HD(int32 i){
150  d_dy0[i] = d_dy[i];
151  d_y[i] = d_y0[i] + dt*(
152  static_cast<real>(23.0 /12.0 ) * d_dy[i]
153  - static_cast<real>(16.0 / 12.0) * d_dy1[i]
154  + static_cast<real>( 5.0 / 12.0) * d_dy2[i]);
155  });
156  Kokkos::fence();
157 
158  return true;
159 }
160 
162  real dt,
163  realx3Vector_D& y,
164  realx3Vector_D& dy,
165  range activeRng)
166 {
167 
168  auto d_dy = dy.deviceVectorAll();
169  auto d_y = y.deviceVectorAll();
170 
171  auto d_dy0 = dy0_.deviceVectorAll();
172  auto d_y0 = y0_.deviceVectorAll();
173  auto d_dy1 = dy1_.deviceVectorAll();
174  auto d_dy2 = dy2_.deviceVectorAll();
175 
176  Kokkos::parallel_for(
177  "AdamsMoulton4::correct",
178  rpIntegration (activeRng.first, activeRng.second),
179  LAMBDA_HD(int32 i){
180  auto corrct_y = d_y0[i] + dt*(
181  static_cast<real>(9.0/24.0)*d_dy[i]
182  + static_cast<real>(19.0/24.0)*d_dy0[i]
183  - static_cast<real>( 5.0/24.0)*d_dy1[i]
184  + static_cast<real>( 1.0/24.0)*d_dy2[i]);
185 
186  d_dy2[i]= d_dy1[i];
187  d_dy1[i]= d_dy0[i];
188  d_y0[i] = corrct_y;
189  d_y[i] = corrct_y;
190  });
191  Kokkos::fence();
192 
193  return true;
194 }
pFlow::AdamsMoulton4::AdamsMoulton4
AdamsMoulton4(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsMoulton4.cpp:26
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::integration
Definition: integration.hpp:35
pFlow::AdamsMoulton4::y0_
realx3PointField_D & y0_
Definition: AdamsMoulton4.hpp:38
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
pFlow::AdamsMoulton4::predict
bool predict(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton4.cpp:84
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:97
pFlow::repository::emplaceObject
T & emplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:38
pFlow::AdamsMoulton4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsMoulton4.cpp:122
pFlow::baseName
word baseName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:156
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
AdamsMoulton4.hpp
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::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::objectFile
Definition: objectFile.hpp:33
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::AdamsMoulton4::predictAll
bool predictAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton4.cpp:131
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Definition: bTypesFunctions.cpp:151
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 >