ASL  0.1.7
Advanced Simulation Library
compressor.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 
31 #include <math/aslTemplates.h>
32 #include <aslGeomInc.h>
33 #include <aslDataInc.h>
35 #include <acl/aclGenerators.h>
37 #include <num/aslLBGK.h>
38 #include <num/aslLBGKBC.h>
39 #include <utilities/aslTimer.h>
41 
42 typedef float FlT;
43 //typedef double FlT;
45 
46 using asl::AVec;
47 using asl::makeAVec;
48 
50 {
51  double rCase((bl.getBPosition()[1] - bl.position[1]) / 2.);
52 
53  asl::AVec<> center(.5*(bl.getBPosition() + bl.position));
54  center[1] = bl.position[1] + rCase;
55 
56  auto comprCase(-(generateDFCylinderInf(rCase, makeAVec(0., 0., 1.), center)));
57 
58  return normalize(comprCase, bl.dx);
59 }
60 
61 
62 int main(int argc, char* argv[])
63 {
64  // Optionally add appParamsManager to be able to manipulate at least
65  // hardware parameters(platform/device) through command line/parameters file
66  asl::ApplicationParametersManager appParamsManager("compressor",
67  "1.0");
68  asl::Parameter<string> input("input", "path to the compressor geometry input file");
69  appParamsManager.load(argc, argv);
70 
71  Param dx(0.5);
72  Param dt(.001);
73  Param nu(.2);
74  // Angular velocity
75  Param w(6.*3.14*2./60.);
76 
77  AVec<int> size(makeAVec(33., 33., 90.)*(1./dx.v()));
78  asl::Block bl(size, dx.v(), makeAVec(-16.65, -26.15, -67.7));
79 
80 // Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
81  Param nuNum(.2);
82  // Angular velocity in one iteration
83  Param wNum(w.v()*dt.v());
84 
85  std::cout << "Data initialization..." << flush;
86 
87 
88  auto compressorMap(asl::readSurface(input.v(), bl));
89 
90  asl::Block block(compressorMap->getInternalBlock());
91 
92  auto comprCaseMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
93  asl::initData(comprCaseMap, generateCase(block));
94 
95 
96  std::cout << "Finished" << endl;
97 
98  std::cout << "Numerics initialization..." << flush;
99 
100  asl::SPLBGK lbgk(new asl::LBGK(block,
101  acl::generateVEConstant(FlT(nuNum.v())),
102  &asl::d3q15()));
103  // Set angular velocity in lbgk
104  lbgk->setOmega(acl::generateVEConstant(makeAVec(0.,0.,wNum.v())));
105  lbgk->init();
106 
107  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
108  // Initialization of lbgk
109  lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0));
110 
111  std::vector<asl::SPNumMethod> bc;
112  std::vector<asl::SPNumMethod> bcVis;
113 
114  // Position Function Angular Velocity Field
115  auto vfCase(asl::generatePFRotationField(makeAVec(0.,0., wNum.v()/dx.v()),
116  .5*(block.getBPosition() + block.position)));
117  // Boundary condition
118  bc.push_back(generateBCVelocity(lbgk, vfCase, comprCaseMap));
119  // Boundary condition for visualization
120  bcVis.push_back(generateBCVelocityVel(lbgk, vfCase, comprCaseMap));
121  bc.push_back(asl::generateBCConstantPressure(lbgk, 1., {asl::Z0, asl::ZE}));
122  bc.push_back(generateBCNoSlip(lbgk, compressorMap));
123  bcVis.push_back(generateBCNoSlipVel(lbgk, compressorMap));
124 
125  initAll(bc);
126  initAll(bcVis);
127 
128 
129  std::cout << "Finished" << endl;
130  std::cout << "Computing..." << endl;
131  asl::Timer timer;
132 
133  asl::WriterVTKXML writer("compressor");
134  writer.addScalars("compressor", *compressorMap);
135  writer.addScalars("case", *comprCaseMap);
136  writer.addScalars("rho", *lbgk->getRho());
137  writer.addVector("v", *lbgk->getVelocity());
138 
139  executeAll(bc);
140  executeAll(bcVis);
141 
142  writer.write();
143 
144  timer.start();
145  for (unsigned int i(1); i < 10001; ++i)
146  {
147  lbgk->execute();
148  executeAll(bc);
149  if (!(i%2000))
150  {
151  cout << i << endl;
152  executeAll(bcVis);
153  writer.write();
154  }
155  }
156  timer.stop();
157 
158  cout << "Finished" << endl;
159 
160  cout << "Computation statistic:" << endl;
161  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
162  << timer.processorTime() << "; Processor Load = "
163  << timer.processorLoad() * 100 << "%" << endl;
164 
165  return 0;
166 }
const double realTime() const
Definition: aslTimer.h:45
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
const T & v() const
Definition: aslUValue.h:43
const AVec normalize(const AVec< T > &a)
int main(int argc, char *argv[])
Definition: compressor.cc:62
float FlT
Definition: compressor.cc:42
void addVector(std::string name, AbstractData &data)
asl::SPDistanceFunction generateCase(asl::Block &bl)
Definition: compressor.cc:49
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
AVec< T > makeAVec(T a1)
SPDataWithGhostNodesACLData readSurface(const string &fileName, double dx, acl::CommandQueue queue=acl::hardware.defaultQueue)
asl::UValue< double > Param
Definition: compressor.cc:44
double dx
Definition: aslBlocks.h:66
SPDistanceFunction generateDFCylinderInf(double r, const AVec< double > &l, const AVec< double > &c)
generates infinite cylinder
std::shared_ptr< LBGKUtilities > SPLBGKUtilities
Definition: aslLBGK.h:161
std::shared_ptr< LBGK > SPLBGK
Definition: aslLBGK.h:133
const VectorTemplate & d3q15()
Vector template.
const T & v() const
cl_int flush(void)
Definition: cl.hpp:7042
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
SPNumMethod generateBCVelocityVel(SPLBGK nm, SPPositionFunction v, SPAbstractDataWithGhostNodes map)
void initData(SPAbstractData d, double a)
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
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.
SPPositionFunction generatePFRotationField(const AVec< double > &axis, const AVec< double > &c)
const V getBPosition() const
Definition: aslBlocks.h:214
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
SPNumMethod generateBCVelocity(SPLBGK nm, SPPositionFunction v, SPAbstractDataWithGhostNodes map)
SPBCond generateBCNoSlip(SPLBGK nm, const std::vector< SlicesNames > &sl)