ASL  0.1.7
Advanced Simulation Library
flow2.cc
Go to the documentation of this file.
1 /*
2  * Advanced Simulation Library <http://asl.org.il>
3  *
4  * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5  *
6  *
7  * This file is part of Advanced Simulation Library (ASL).
8  *
9  * ASL is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU Affero General Public License as
11  * published by the Free Software Foundation, version 3 of the License.
12  *
13  * ASL is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 
30 #include <aslDataInc.h>
31 #include <math/aslTemplates.h>
32 #include <aslGeomInc.h>
33 #include <acl/aclGenerators.h>
35 #include <num/aslLBGK.h>
36 #include <num/aslLBGKBC.h>
37 #include <utilities/aslTimer.h>
38 #include <acl/aclUtilities.h>
39 
40 
41 
42 typedef float FlT;
43 //typedef double FlT;
45 
46 using asl::AVec;
47 using asl::makeAVec;
48 
50 {
51  double hCyl (10.);
52  double rCyl (1.5);
53  double a(10.);
54  double b(6.);
55  vector<AVec<>> rect({.5*makeAVec( .866*a,-b,-a*.5),.5*makeAVec(-.866*a,-b, a*.5),
56  .5*makeAVec(-.866*a, b, a*.5),.5*makeAVec( .866*a, b,-a*.5)});
57  vector<AVec<>> r1(rect.size());
58  vector<AVec<>> r2(rect.size());
59  auto r1C(makeAVec(x,y+rCyl*.5+b*.5,hCyl));
60  auto r2C(makeAVec(x,y-rCyl*.5-b*.5,hCyl));
61  for(unsigned int i(0); i<rect.size();++i)
62  {
63  r1[i]=r1C + rect[i];
64  r2[i]=r2C + rect[i];
65  }
66 
68  res = (res &
69  generateDFPlane(makeAVec(.5,0.,.866), r1C + makeAVec(rCyl,0.,0.)) &
70  generateDFPlane(makeAVec(-.5,0.,-.866), r1C - makeAVec(rCyl,0.,0.))) |
71  generateDFCylinder(rCyl, makeAVec(0.,0.,hCyl), makeAVec(x,y,hCyl*.5));
72  return res;
73 }
74 
76 {
77  vector<double> xValues;
78  vector<double> yValues;
79 
80  for(unsigned int i(0); i < 8; ++i)
81  for(unsigned int j(0); j < 10; ++j)
82  {
83  xValues.push_back(25.+ 20.*i);
84  yValues.push_back(25.+ 15.*j);
85  }
86 
87  auto res(generateMirror(xValues[0], yValues[0]));
88  for(unsigned int i(1); i < xValues.size(); ++i)
89  res = res | generateMirror(xValues[i], yValues[i]);
90 
91  return res;
92 }
93 
94 
95 int main(int argc, char* argv[])
96 {
97  // Optionally add appParamsManager to be able to manipulate at least
98  // hardware parameters(platform/device) through command line/parameters file
99  asl::ApplicationParametersManager appParamsManager("flow2",
100  "1.0");
101  appParamsManager.load(argc, argv);
102 
103  Param dx(1.);
104  Param dt(1.);
105  Param nu(.0125);
106 
107  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
108  AVec<int> size(asl::makeAVec(200,200,25));
109 
110  AVec<> gSize(dx.v()*AVec<>(size));
111 
112 
113  std::cout << "Data initialization... ";
114 
115  asl::Block block(size,dx.v());
116 
117  auto mirrorsMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
118  asl::initData(mirrorsMapMem, generateMirrors());
119 
120  std::cout << "Finished" << endl;
121 
122  std::cout << "Numerics initialization... ";
123 
124  asl::SPLBGK lbgk(new asl::LBGK(block,
125  acl::generateVEConstant(FlT(nuNum.v())),
126  &asl::d3q15()));
127 
128  lbgk->init();
129  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
130  lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0));
131 // lbgkUtil->initF(acl::generateVEConstant(.1), acl::generateVEConstant(.0,.0,.0));
132 
133  auto bcNoSlip(generateBCNoSlip(lbgk,{asl::Y0, asl::YE, asl::Z0}));
134  auto bcNoSlipM(generateBCNoSlip(lbgk, mirrorsMapMem));
135  auto bcNoSlipV(generateBCNoSlipVel(lbgk, mirrorsMapMem));
136  auto bcP(asl::generateBCConstantPressure(lbgk, 1., {asl::X0, asl::XE}));
137  auto bcTop(asl::generateBCConstantVelocity(lbgk, asl::makeAVec(0.1,0.,0.), {asl::ZE}));
138 
139  bcNoSlip->init();
140  bcNoSlipM->init();
141  bcNoSlipV->init();
142  bcP->init();
143  bcTop->init();
144 
145  std::cout << "Finished" << endl;
146  std::cout << "Computing...";
147  asl::Timer timer;
148 
149  asl::WriterVTKXML writer("flow2");
150  writer.addScalars("map", *mirrorsMapMem);
151  writer.addScalars("rho", *lbgk->getRho());
152  writer.addVector("v", *lbgk->getVelocity());
153 
154 
155 
156  bcP->execute();
157  bcTop->execute();
158  bcNoSlip->execute();
159  bcNoSlipM->execute();
160 
161  bcNoSlipV->execute();
162  writer.write();
163 
164  timer.start();
165  for (unsigned int i(0); i < 1000 ; ++i)
166  {
167  lbgk->execute();
168  bcP->execute();
169  bcTop->execute();
170  bcNoSlip->execute();
171  bcNoSlipM->execute();
172  if (!(i%100))
173  {
174  cout << i << endl;
175  bcNoSlipV->execute();
176  writer.write();
177  }
178  }
179  timer.stop();
180 
181 
182  cout << "Finished" << endl;
183 
184  cout << "Computation statistic:" << endl;
185  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
186  << timer.processorTime() << "; Processor Load = "
187  << timer.processorLoad() * 100 << "%" << endl;
188 
189  return 0;
190 }
const double realTime() const
Definition: aslTimer.h:45
int main(int argc, char *argv[])
Definition: flow2.cc:95
std::shared_ptr< DistanceFunction > SPDistanceFunction
Definition: aslGeomInc.h:44
const double processorTime() const
Definition: aslTimer.h:46
AVec< T > makeAVec(T a1)
Numerical method for fluid flow.
Definition: aslLBGK.h:77
float FlT
Definition: flow2.cc:42
asl::SPDistanceFunction generateMirror(double x, double y)
Definition: flow2.cc:49
const T & v() const
Definition: aslUValue.h:43
void addVector(std::string name, AbstractData &data)
AVec< T > makeAVec(T a1)
SPDistanceFunction generateDFConvexPolygonPrism(std::vector< AVec< double >> points)
generates infinite prism with convex polygon at its base
SPDistanceFunction generateDFPlane(const AVec< double > &n, const AVec< double > &p0)
asl::UValue< double > Param
Definition: flow2.cc:44
asl::SPDistanceFunction generateMirrors()
Definition: flow2.cc:75
std::shared_ptr< LBGKUtilities > SPLBGKUtilities
Definition: aslLBGK.h:161
std::shared_ptr< LBGK > SPLBGK
Definition: aslLBGK.h:133
SPBCond generateBCConstantVelocity(SPLBGK nm, AVec<> v, const std::vector< SlicesNames > &sl)
const VectorTemplate & d3q15()
Vector template.
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
void initData(SPAbstractData d, double a)
void addScalars(std::string name, AbstractData &data)
SPBCond generateBCConstantPressure(SPLBGK nm, double p, const std::vector< SlicesNames > &sl)
void stop()
Definition: aslTimer.h:44
void start()
Definition: aslTimer.h:43
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
SPDistanceFunction generateDFCylinder(double r, const AVec< double > &l, const AVec< double > &c)
generates cylinder
void load(int argc, char *argv[])
const double processorLoad() const
Definition: aslTimer.h:47
SPNumMethod generateBCNoSlipVel(SPLBGK nmU, SPAbstractDataWithGhostNodes map)
for velocity field
contains different kernels for preprocessing and posprocessing of data used by LBGK
Definition: aslLBGK.h:137
SPBCond generateBCNoSlip(SPLBGK nm, const std::vector< SlicesNames > &sl)