ASL  0.1.7
Advanced Simulation Library
locomotive_stability.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 <math/aslVectors.h>
31 #include <math/aslTemplates.h>
32 #include <aslGeomInc.h>
34 #include <aslDataInc.h>
35 #include <acl/aclGenerators.h>
37 #include <num/aslLBGK.h>
38 #include <num/aslLBGKBC.h>
39 #include <utilities/aslTimer.h>
40 #include <acl/aclUtilities.h>
43 
44 
45 typedef float FlT;
46 //typedef double FlT;
48 
49 using asl::AVec;
50 using asl::makeAVec;
51 
53 {
54 
55  double y(10.33);
56  double z(3.08);
57  double h(1.);
58  double rNozzel(.3);
59  double n(4.);
60  double x0(-20.);
61  double xE(-6.);
62 
63  double dx(bl.dx);
64 
66  makeAVec(0., 0., h),
67  makeAVec(x0, y, z + h * .5)));
68  for(unsigned int i(1); i < n; ++i)
69  res = res | generateDFCylinder(rNozzel,
70  makeAVec(0., 0., h),
71  makeAVec(x0 + i * (xE-x0)/n, y, z+h*.5));
72  return normalize(res, dx);
73 }
74 
75 
76 int main(int argc, char* argv[])
77 {
78  // Optionally add appParamsManager to be able to manipulate at least
79  // hardware parameters(platform/device) through command line/parameters file
80  asl::ApplicationParametersManager appParamsManager("locomotive_stability",
81  "1.0");
82  asl::Parameter<string> input("input", "path to the geometry input file");
83  appParamsManager.load(argc, argv);
84 
85  Param dx(0.25);
86  Param dt(1.);
87  Param nu(.01);
88 
89  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
90 
91  std::cout << "Data initialization... " << flush;
92 
93  auto locomotive(asl::readSurface(input.v(), dx.v(), .5, 1., 0., 1., 2., 4.));
94 
95  asl::Block block(locomotive->getInternalBlock());
96 
97  auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
98  asl::initData(forceField, makeAVec(0., 0., 0.));
99 
100  std::cout << "Finished" << endl;
101 
102  std::cout << "Numerics initialization... " << flush;
103 
104  asl::SPLBGK lbgk(new asl::LBGK(block,
105  acl::generateVEConstant(FlT(nu.v())),
106  &asl::d3q15()));
107 
108  lbgk->init();
109  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
110  lbgkUtil->initF(acl::generateVEConstant(.1,.0,.05));
111 
112  auto vfTunnel(asl::generatePFConstant(makeAVec(0.1,0.,0.)));
113 
114  std::vector<asl::SPNumMethod> bc;
115  std::vector<asl::SPNumMethod> bcV;
116 
117  auto nozzelsMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
118  asl::initData(nozzelsMap, generateNozzels(block));
119 
120 
121  bc.push_back(generateBCNoSlip(lbgk, locomotive));
122  bcV.push_back(generateBCNoSlipVel(lbgk, locomotive));
123  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
124  makeAVec(0.1,0.,0.05),
126  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1., makeAVec(0.,0.,-0.1), nozzelsMap));
127  initAll(bc);
128  initAll(bcV);
129 
130  auto computeForce(generateComputeSurfaceForce(lbgk, forceField, locomotive));
131  computeForce->init();
132 
133 
134  std::cout << "Finished" << endl;
135  std::cout << "Computing..." << endl;
136 
137  asl::WriterVTKXML writer(appParamsManager.getDir() + "locomotive_stability");
138  writer.addScalars("locomotive", *locomotive);
139  writer.addScalars("nozzels", *nozzelsMap);
140  writer.addScalars("rho", *lbgk->getRho());
141  writer.addVector("v", *lbgk->getVelocity());
142  writer.addVector("force", *forceField);
143 
144  executeAll(bc);
145  executeAll(bcV);
146  computeForce->execute();
147 
148  writer.write();
149 
150  asl::Timer timer, timer1, timer2;
151  timer.start();
152  for(unsigned int i(1); i < 40001; ++i)
153  {
154  lbgk->execute();
155  executeAll(bc);
156  if(!(i%1000))
157  {
158  cout << i << endl;
159  executeAll(bcV);
160  computeForce->execute();
161  writer.write();
162  }
163  }
164  timer.stop();
165 
166  cout << "Finished" << endl;
167 
168  cout << "Computation statistic:" << endl;
169  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
170  << timer.processorTime() << "; Processor Load = "
171  << timer.processorLoad() * 100 << "%" << endl;
172 
173  return 0;
174 }
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)
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
AVec< T > makeAVec(T a1)
std::string getDir()
SPDataWithGhostNodesACLData readSurface(const string &fileName, double dx, acl::CommandQueue queue=acl::hardware.defaultQueue)
SPBCond generateBCConstantPressureVelocity(SPLBGK nm, double p, AVec<> v, const std::vector< SlicesNames > &sl)
double dx
Definition: aslBlocks.h:66
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
asl::SPDistanceFunction generateNozzels(asl::Block &bl)
cl_int flush(void)
Definition: cl.hpp:7042
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
void initData(SPAbstractData d, double a)
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
int main(int argc, char *argv[])
void addScalars(std::string name, AbstractData &data)
asl::UValue< double > Param
definition of class АVec<T>
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.
SPNumMethod generateComputeSurfaceForce(SPLBGK nm, SPDataWithGhostNodesACLData fF, SPAbstractDataWithGhostNodes map)
SPDistanceFunction generateDFCylinder(double r, const AVec< double > &l, const AVec< double > &c)
generates cylinder
float FlT
void load(int argc, char *argv[])
const double processorLoad() const
Definition: aslTimer.h:47
SPNumMethod generateBCNoSlipVel(SPLBGK nmU, SPAbstractDataWithGhostNodes map)
for velocity field
SPPositionFunction generatePFConstant(const AVec< double > &a)
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)