ASL  0.1.6
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 
29 #include <math/aslVectors.h>
30 #include <math/aslTemplates.h>
31 #include <aslGeomInc.h>
33 #include <aslDataInc.h>
34 #include <acl/aclGenerators.h>
36 #include <num/aslLBGK.h>
37 #include <num/aslLBGKBC.h>
38 #include <utilities/aslTimer.h>
39 #include <acl/aclUtilities.h>
42 
43 
44 typedef float FlT;
45 //typedef double FlT;
47 
48 using asl::AVec;
49 using asl::makeAVec;
50 
52 {
53 
54  double y(10.33);
55  double z(3.08);
56  double h(1.);
57  double rNozzel(.3);
58  double n(4.);
59  double x0(-20.);
60  double xE(-6.);
61 
62  double dx(bl.dx);
63 
65  makeAVec(0., 0., h),
66  makeAVec(x0, y, z + h * .5)));
67  for(unsigned int i(1); i < n; ++i)
68  res = res | generateDFCylinder(rNozzel,
69  makeAVec(0., 0., h),
70  makeAVec(x0 + i * (xE-x0)/n, y, z+h*.5));
71  return normalize(res, dx);
72 }
73 
74 
75 int main(int argc, char* argv[])
76 {
77  // Optionally add appParamsManager to be able to manipulate at least
78  // hardware parameters(platform/device) through command line/parameters file
79  asl::ApplicationParametersManager appParamsManager("locomotive_stability",
80  "1.0");
81  asl::Parameter<string> input("input", "path to the geometry input file");
82  appParamsManager.load(argc, argv);
83 
84  Param dx(0.25);
85  Param dt(1.);
86  Param nu(.01);
87 
88  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
89 
90  std::cout << "Data initialization... " << flush;
91 
92  auto locomotive(asl::readSurface(input.v(), dx.v(), .5, 1., 0., 1., 2., 4.));
93 
94  asl::Block block(locomotive->getInternalBlock());
95 
96  auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
97  asl::initData(forceField, makeAVec(0., 0., 0.));
98 
99  std::cout << "Finished" << endl;
100 
101  std::cout << "Numerics initialization... " << flush;
102 
103  asl::SPLBGK lbgk(new asl::LBGK(block,
104  acl::generateVEConstant(FlT(nu.v())),
105  &asl::d3q15()));
106 
107  lbgk->init();
108  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
109  lbgkUtil->initF(acl::generateVEConstant(.1,.0,.05));
110 
111  auto vfTunnel(asl::generatePFConstant(makeAVec(0.1,0.,0.)));
112 
113  std::vector<asl::SPNumMethod> bc;
114  std::vector<asl::SPNumMethod> bcV;
115 
116  auto nozzelsMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
117  asl::initData(nozzelsMap, generateNozzels(block));
118 
119 
120  bc.push_back(generateBCNoSlip(lbgk, locomotive));
121  bcV.push_back(generateBCNoSlipVel(lbgk, locomotive));
122  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
123  makeAVec(0.1,0.,0.05),
125  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1., makeAVec(0.,0.,-0.1), nozzelsMap));
126  initAll(bc);
127  initAll(bcV);
128 
129  auto computeForce(generateComputeSurfaceForce(lbgk, forceField, locomotive));
130  computeForce->init();
131 
132 
133  std::cout << "Finished" << endl;
134  std::cout << "Computing..." << endl;
135 
136  asl::WriterVTKXML writer(appParamsManager.getDir() + "locomotive_stability");
137  writer.addScalars("locomotive", *locomotive);
138  writer.addScalars("nozzels", *nozzelsMap);
139  writer.addScalars("rho", *lbgk->getRho());
140  writer.addVector("v", *lbgk->getVelocity());
141  writer.addVector("force", *forceField);
142 
143  executeAll(bc);
144  executeAll(bcV);
145  computeForce->execute();
146 
147  writer.write();
148 
149  asl::Timer timer, timer1, timer2;
150  timer.start();
151  for(unsigned int i(1); i < 40001; ++i)
152  {
153  lbgk->execute();
154  executeAll(bc);
155  if(!(i%1000))
156  {
157  cout << i << endl;
158  executeAll(bcV);
159  computeForce->execute();
160  writer.write();
161  }
162  }
163  timer.stop();
164 
165  std::cout << "Finished" << endl;
166 
167  cout << "time=" << timer.getTime() << "; clockTime="
168  << timer.getClockTime() << "; load="
169  << timer.getProcessorLoad() * 100 << "%" << endl;
170 
171  std::cout << "Output...";
172  std::cout << "Finished" << endl;
173  std::cout << "Ok" << endl;
174 
175  return 0;
176 }
const double getTime() const
Definition: aslTimer.h:46
const double getProcessorLoad() const
Definition: aslTimer.h:48
AVec< T > makeAVec(T a1)
Numerical method for fluid flow.
Definition: aslLBGK.h:77
const double getClockTime() const
Definition: aslTimer.h:47
const AVec normalize(const AVec< T > &a)
const T & v() const
Definition: aslUValue.h:43
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
const T & v() const
const VectorTemplate & d3q15()
Vector template.
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:45
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[])
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)