ASL  0.1.7
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 
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 l(bl.getBPosition()[0]-bl.position[0]+bl.dx);
55  double rTunnel((bl.getBPosition()[2]-bl.position[2])/2.);
56 
57  double dx(bl.dx);
58 
59  asl::AVec<int> size(bl.getSize());
60 
61  asl::AVec<> center(.5*(bl.getBPosition()+bl.position));
62  center[1]=bl.position[1]+.25*rTunnel;
63  asl::AVec<> centerG(center);
64  centerG[1]=bl.position[1];
65 
66  auto tunnel(-(generateDFCylinder(rTunnel, makeAVec(l,0.,0.), center) &
67  generateDFPlane(makeAVec(0.,-1.,0.), centerG)));
68 
69  return normalize(tunnel, dx);
70 }
71 
72 
73 int main(int argc, char* argv[])
74 {
75  // Optionally add appParamsManager to be able to manipulate at least
76  // hardware parameters(platform/device) through command line/parameters file
77  asl::ApplicationParametersManager appParamsManager("locomotive_laminar",
78  "1.0");
79  asl::Parameter<string> input("input", "path to the geometry input file");
80  appParamsManager.load(argc, argv);
81 
82  Param dx(0.5);
83  Param dt(1.);
84  Param nu(.01);
85 
86 
87  AVec<int> size(makeAVec(150., 37., 53.2)*(1./dx.v()));
88  asl::Block bl(size,dx.v(),makeAVec(-10.,-1.63, -31.6));
89 
90  Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
91 
92  std::cout << "Data initialization..." << endl;
93 
94  auto locomotive(asl::readSurface(input.v(), bl));
95 
96  asl::Block block(locomotive->getInternalBlock());
97 
98  auto tunnelMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
99  asl::initData(tunnelMap, generateTunnel(block));
100 
101  auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
102  asl::initData(forceField, makeAVec(0.,0.,0.));
103 
104  std::cout << "Finished"<<endl;
105 
106  std::cout << "Numerics initialization..." << endl;
107 
108  asl::SPLBGK lbgk(new asl::LBGK(block,
109  acl::generateVEConstant(FlT(nuNum.v())),
110  &asl::d3q15()));
111 
112  lbgk->init();
113  asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
114  lbgkUtil->initF(acl::generateVEConstant(.1,.0,.0));
115 
116  auto vfTunnel(asl::generatePFConstant(makeAVec(0.1,0.,0.)));
117 
118  std::vector<asl::SPNumMethod> bc;
119  std::vector<asl::SPNumMethod> bcV;
120 
121  bc.push_back(generateBCVelocity(lbgk, vfTunnel, tunnelMap));
122  bcV.push_back(generateBCVelocityVel(lbgk, vfTunnel, tunnelMap));
123 // bcV.push_back(generateBCNoSlipRho(lbgk, tunnelMap));
124  bc.push_back(generateBCNoSlip(lbgk, locomotive));
125  bcV.push_back(generateBCNoSlipVel(lbgk, locomotive));
126 // bcV.push_back(generateBCNoSlipRho(lbgk, locomotive));
127  bc.push_back(generateBCConstantPressureVelocity(lbgk, 1., makeAVec(0.1,0.,0.), {asl::X0, asl::XE}));
128 
129  initAll(bc);
130  initAll(bcV);
131 
132  auto computeForce(generateComputeSurfaceForce(lbgk, forceField, locomotive));
133  computeForce->init();
134 
135  cout << "Finished" << endl;
136  cout << "Computing..." << endl;
137  asl::Timer timer;
138 
139  asl::WriterVTKXML writer(appParamsManager.getDir() + "locomotive_laminar");
140  writer.addScalars("locomotive", *locomotive);
141  writer.addScalars("tunnel", *tunnelMap);
142  writer.addScalars("rho", *lbgk->getRho());
143  writer.addVector("v", *lbgk->getVelocity());
144  writer.addVector("force", *forceField);
145 
146  executeAll(bc);
147  executeAll(bcV);
148  computeForce->execute();
149 
150  writer.write();
151 
152  timer.start();
153  for(unsigned int i(1); i < 2001; ++i)
154  {
155  lbgk->execute();
156  executeAll(bc);
157  if(!(i%200))
158  {
159  cout<<i<<endl;
160  executeAll(bcV);
161  computeForce->execute();
162  writer.write();
163  }
164  }
165  timer.stop();
166 
167  cout << "Finished" << endl;
168 
169  cout << "Computation statistic:" << endl;
170  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
171  << timer.processorTime() << "; Processor Load = "
172  << timer.processorLoad() * 100 << "%" << endl;
173 
174  return 0;
175 }
const double realTime() const
Definition: aslTimer.h:45
std::shared_ptr< DistanceFunction > SPDistanceFunction
Definition: aslGeomInc.h:44
const DV & getSize() const
Definition: aslBlocks.h:208
const double processorTime() const
Definition: aslTimer.h:46
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)
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
float FlT
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)
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)
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[])
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
SPNumMethod generateBCVelocity(SPLBGK nm, SPPositionFunction v, SPAbstractDataWithGhostNodes map)
SPBCond generateBCNoSlip(SPLBGK nm, const std::vector< SlicesNames > &sl)