ASL  0.1.6
Advanced Simulation Library
flow.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 
28 #include <utilities/aslParametersManager.h>
29 #include <aslDataInc.h>
30 #include <math/aslTemplates.h>
31 #include <aslGeomInc.h>
32 #include <acl/aclGenerators.h>
33 #include <writers/aslVTKFormatWriters.h>
34 #include <num/aslLBGK.h>
35 #include <num/aslLBGKBC.h>
36 #include <utilities/aslTimer.h>
37 #include <acl/aclUtilities.h>
38 
39 
40 
41 typedef float FlT;
42 //typedef double FlT;
44 
45 using asl::AVec;
46 using asl::makeAVec;
47 
48 
49 int main(int argc, char* argv[])
50 {
51  // Optionally add appParamsManager to be able to manipulate at least
52  // hardware parameters(platform/device) through command line/parameters file
53  asl::ApplicationParametersManager appParamsManager("flow",
54  "1.0");
55  appParamsManager.load(argc, argv);
56 
57  Param dx(1.);
58  Param dt(1.);
59  Param nu(.00625);
60 
61  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
62  AVec<int> size(asl::makeAVec(300, 50, 50));
63 
64  auto gSize(dx.v()*AVec<>(size));
65 
66 
67  std::cout << "Data initialization... ";
68 
69  asl::Block block(size,dx.v());
70 
71  auto ball(generateDFCylinderInf(.125*gSize[1],
72  makeAVec(0.,1.,0.),
73  .45*makeAVec(gSize[1],gSize[1],gSize[2])));
74  // Formula
75  auto ballMap(asl::generateDataContainer_SP(block, ball, 1u, acl::typeToTypeID<FlT>()));
76  // Data
77  auto ballMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
78  asl::initData(ballMapMem, ball);
79 
80 
81  std::cout << "Finished" << endl;
82 
83  std::cout << "Numerics initialization... ";
84 
85  asl::SPLBGK lbgk(new asl::LBGK(block,
86  acl::generateVEConstant(FlT(nuNum.v())),
87  &asl::d3q15()));
88  lbgk->init();
89 
90  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
91  // Initialization of lbgk
92  lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0));
93 // lbgkUtil->initF(acl::generateVEConstant(.1), acl::generateVEConstant(.0,.0,.0));
94 
95  std::vector<asl::SPNumMethod> bc;
96  std::vector<asl::SPNumMethod> bcVis;
97 
98  bc.push_back(asl::generateBCConstantPressure(lbgk, 1.2, {asl::X0}));
99  bc.push_back(asl::generateBCConstantPressure(lbgk, 0.8, {asl::XE}));
100  bc.push_back(generateBCNoSlip(lbgk, {asl::Y0, asl::YE, asl::Z0, asl::ZE}));
101  bc.push_back(generateBCNoSlip(lbgk, ballMap));
102  bcVis.push_back(generateBCNoSlipVel(lbgk, ballMap));
103 
104  initAll(bc);
105  initAll(bcVis);
106 
107  std::cout << "Finished" << endl;
108  std::cout << "Computing...";
109  asl::Timer timer;
110 
111  asl::WriterVTKXML writer("flow");
112  writer.addScalars("map", *ballMapMem);
113  writer.addScalars("rho", *lbgk->getRho());
114  writer.addVector("v", *lbgk->getVelocity());
115 
116 
117 
118  executeAll(bc);
119  executeAll(bcVis);
120  writer.write();
121 
122  timer.start();
123  for (unsigned int i(1); i < 1001; ++i)
124  {
125  lbgk->execute();
126  executeAll(bc);
127  if (!(i%5000))
128  {
129  cout << i << endl;
130  executeAll(bcVis);
131  writer.write();
132  }
133  }
134  timer.stop();
135 
136  std::cout << "Finished" << endl;
137 
138  cout << "time=" << timer.getTime() << "; clockTime="
139  << timer.getClockTime() << "; load="
140  << timer.getProcessorLoad() * 100 << "%" << endl;
141 
142  std::cout << "Output...";
143  std::cout << "Finished" << endl;
144  std::cout << "Ok" << endl;
145 
146  return 0;
147 }
const double getTime() const
Definition: aslTimer.h:46
const double getProcessorLoad() const
Definition: aslTimer.h:48
Numerical method for fluid flow.
Definition: aslLBGK.h:77
SPDataWrapperACL generateDataContainer_SP(const Block &b, const acl::VectorOfElements &a)
const double getClockTime() const
Definition: aslTimer.h:47
void addVector(std::string name, AbstractData &data)
const T & v() const
Definition: aslUValue.h:43
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
AVec< T > makeAVec(T a1)
SPDistanceFunction generateDFCylinderInf(double r, const AVec< double > &l, const AVec< double > &c)
generates infinite cylinder
const VectorTemplate & d3q15()
Vector template.
float FlT
Definition: flow.cc:41
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
AVec< T > makeAVec(T a1)
void initData(SPAbstractData d, double a)
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
int main(int argc, char *argv[])
Definition: flow.cc:49
void addScalars(std::string name, AbstractData &data)
asl::UValue< double > Param
Definition: flow.cc:43
SPBCond generateBCConstantPressure(SPLBGK nm, double p, const std::vector< SlicesNames > &sl)
void stop()
Definition: aslTimer.h:45
void start()
Definition: aslTimer.h:43
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
void load(int argc, char *argv[])
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)