ASL  0.1.6
Advanced Simulation Library
locomotive_laminar.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/aslTemplates.h>
30 #include <aslGeomInc.h>
32 #include <aslDataInc.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>
41 
42 
43 typedef float FlT;
44 //typedef double FlT;
46 
47 using asl::AVec;
48 using asl::makeAVec;
49 
51 {
52 
53  double l(bl.getBPosition()[0]-bl.position[0]+bl.dx);
54  double rTunnel((bl.getBPosition()[2]-bl.position[2])/2.);
55 
56  double dx(bl.dx);
57 
58  asl::AVec<int> size(bl.getSize());
59 
60  asl::AVec<> center(.5*(bl.getBPosition()+bl.position));
61  center[1]=bl.position[1]+.25*rTunnel;
62  asl::AVec<> centerG(center);
63  centerG[1]=bl.position[1];
64 
65  auto tunnel(-(generateDFCylinder(rTunnel, makeAVec(l,0.,0.), center) &
66  generateDFPlane(makeAVec(0.,-1.,0.), centerG)));
67 
68  return normalize(tunnel, dx);
69 }
70 
71 
72 int main(int argc, char* argv[])
73 {
74  // Optionally add appParamsManager to be able to manipulate at least
75  // hardware parameters(platform/device) through command line/parameters file
76  asl::ApplicationParametersManager appParamsManager("locomotive_laminar",
77  "1.0");
78  asl::Parameter<string> input("input", "path to the geometry input file");
79  appParamsManager.load(argc, argv);
80 
81  Param dx(0.5);
82  Param dt(1.);
83  Param nu(.01);
84 
85 
86  AVec<int> size(makeAVec(150., 37., 53.2)*(1./dx.v()));
87  asl::Block bl(size,dx.v(),makeAVec(-10.,-1.63, -31.6));
88 
89  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
90 
91  std::cout << "Data initialization..." << endl;
92 
93  auto locomotive(asl::readSurface(input.v(), bl));
94 
95  asl::Block block(locomotive->getInternalBlock());
96 
97  auto tunnelMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
98  asl::initData(tunnelMap, generateTunnel(block));
99 
100  auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
101  asl::initData(forceField, makeAVec(0.,0.,0.));
102 
103  std::cout << "Finished"<<endl;
104 
105  std::cout << "Numerics initialization..." << endl;
106 
107  asl::SPLBGK lbgk(new asl::LBGK(block,
108  acl::generateVEConstant(FlT(nuNum.v())),
109  &asl::d3q15()));
110 
111  lbgk->init();
112  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
113  lbgkUtil->initF(acl::generateVEConstant(.1,.0,.0));
114 
115  auto vfTunnel(asl::generatePFConstant(makeAVec(0.1,0.,0.)));
116 
117  std::vector<asl::SPNumMethod> bc;
118  std::vector<asl::SPNumMethod> bcV;
119 
120  bc.push_back(generateBCVelocity(lbgk, vfTunnel, tunnelMap));
121  bcV.push_back(generateBCVelocityVel(lbgk, vfTunnel, tunnelMap));
122 // bcV.push_back(generateBCNoSlipRho(lbgk, tunnelMap));
123  bc.push_back(generateBCNoSlip(lbgk, locomotive));
124  bcV.push_back(generateBCNoSlipVel(lbgk, locomotive));
125 // bcV.push_back(generateBCNoSlipRho(lbgk, locomotive));
126  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1., makeAVec(0.1,0.,0.), {asl::X0, asl::XE}));
127 
128  initAll(bc);
129  initAll(bcV);
130 
131  auto computeForce(generateComputeSurfaceForce(lbgk, forceField, locomotive));
132  computeForce->init();
133 
134  cout << "Finished" << endl;
135  cout << "Computing..." << endl;
136  asl::Timer timer;
137 
138  asl::WriterVTKXML writer(appParamsManager.getDir() + "locomotive_laminar");
139  writer.addScalars("locomotive", *locomotive);
140  writer.addScalars("tunnel", *tunnelMap);
141  writer.addScalars("rho", *lbgk->getRho());
142  writer.addVector("v", *lbgk->getVelocity());
143  writer.addVector("force", *forceField);
144 
145  executeAll(bc);
146  executeAll(bcV);
147  computeForce->execute();
148 
149  writer.write();
150 
151  timer.start();
152  for(unsigned int i(1); i < 2001; ++i)
153  {
154  lbgk->execute();
155  executeAll(bc);
156  if(!(i%200))
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 << "time = " << timer.getTime() << "; clockTime = "
170  << timer.getClockTime() << "; load = "
171  << timer.getProcessorLoad() * 100 << "%" << endl;
172 
173  return 0;
174 }
const DV & getSize() const
Definition: aslBlocks.h:208
AVec< T > makeAVec(T a1)
Numerical method for fluid flow.
Definition: aslLBGK.h:77
asl::UValue< double > Param
const T & v() const
Definition: aslUValue.h:43
int main(int argc, char *argv[])
const AVec normalize(const AVec< T > &a)
void initAll(std::vector< T *> &v)
Definition: aslNumMethod.h:67
AVec< T > makeAVec(T a1)
asl::SPDistanceFunction generateTunnel(asl::Block &bl)
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
SPDistanceFunction generateDFPlane(const AVec< double > &n, const AVec< double > &p0)
const double getProcessorLoad() const
Definition: aslTimer.h:48
const VectorTemplate & d3q15()
Vector template.
const T & v() const
float FlT
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
const double getClockTime() const
Definition: aslTimer.h:47
void executeAll(std::vector< T *> &v)
Definition: aslNumMethod.h:55
SPNumMethod generateBCVelocityVel(SPLBGK nm, SPPositionFunction v, SPAbstractDataWithGhostNodes map)
void initData(SPAbstractData d, double a)
const double getTime() const
Definition: aslTimer.h:46
void addScalars(std::string name, AbstractData &data)
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)
const V getBPosition() const
Definition: aslBlocks.h:214
SPDistanceFunction generateDFCylinder(double r, const AVec< double > &l, const AVec< double > &c)
generates cylinder
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
SPNumMethod generateBCVelocity(SPLBGK nm, SPPositionFunction v, SPAbstractDataWithGhostNodes map)
SPBCond generateBCNoSlip(SPLBGK nm, const std::vector< SlicesNames > &sl)