www.cemf.ir
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_(
35  owner.emplaceObject<realx3PointField_D>(
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_(
47  owner.emplaceObject<realx3PointField_D>(
48  objectFile(
49  groupNames(baseName,"dy0"),
50  "",
51  objectFile::READ_IF_PRESENT,
52  objectFile::WRITE_ALWAYS),
53  pStruct,
54  zero3
55  )
56  ),
57  dy1_(
58  owner.emplaceObject<realx3PointField_D>(
59  objectFile(
60  groupNames(baseName,"dy1"),
61  "",
62  objectFile::READ_IF_PRESENT,
63  objectFile::WRITE_ALWAYS),
64  pStruct,
65  zero3
66  )
67  ),
68  dy2_(
69  owner.emplaceObject<realx3PointField_D>(
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.deviceViewAll();
139  auto d_y = y.deviceViewAll();
140 
141  auto d_y0 = y0_.deviceViewAll();
142  auto d_dy0 = dy0_.deviceViewAll();
143  auto d_dy1 = dy1_.deviceViewAll();
144  auto d_dy2 = dy2_.deviceViewAll();
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.deviceViewAll();
169  auto d_y = y.deviceViewAll();
170 
171  auto d_dy0 = dy0_.deviceViewAll();
172  auto d_y0 = y0_.deviceViewAll();
173  auto d_dy1 = dy1_.deviceViewAll();
174  auto d_dy2 = dy2_.deviceViewAll();
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)
Construct from components.
Definition: AdamsMoulton4.cpp:26
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::AdamsMoulton4::y0_
realx3PointField_D & y0_
y at time t
Definition: AdamsMoulton4.hpp:43
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
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:137
pFlow::AdamsMoulton4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsMoulton4.cpp:122
pFlow::internalField::insertSetElement
bool insertSetElement(uint32IndexContainer indices, const T &val)
Definition: internalField.hpp:181
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
AdamsMoulton4.hpp
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::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::objectFile
Definition: objectFile.hpp:30
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
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
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
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::repository
Definition: repository.hpp:34
pFlow::Vector< realx3 >
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39