| 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 |
|
| 24 |
/** |
| 25 |
\example locomotive_laminar.cc |
| 26 |
Example: Locomotive with laminar flow |
| 27 |
Required input file: [locomotive.stl](http://asl.org.il/input_data/locomotive.stl) |
| 28 |
*/ |
| 29 |
|
| 30 |
#include <math/aslTemplates.h> |
| 31 |
#include <aslGeomInc.h> |
| 32 |
#include <math/aslPositionFunction.h> |
| 33 |
#include <aslDataInc.h> |
| 34 |
#include <acl/aclGenerators.h> |
| 35 |
#include <writers/aslVTKFormatWriters.h> |
| 36 |
#include <num/aslLBGK.h> |
| 37 |
#include <num/aslLBGKBC.h> |
| 38 |
#include <utilities/aslTimer.h> |
| 39 |
#include <acl/aclUtilities.h> |
| 40 |
#include <readers/aslVTKFormatReaders.h> |
| 41 |
#include <utilities/aslParametersManager.h> |
| 42 |
|
| 43 |
|
| 44 |
typedef float FlT; |
| 45 |
//typedef double FlT; |
| 46 |
typedef asl::UValue<double> Param; |
| 47 |
|
| 48 |
using asl::AVec; |
| 49 |
using asl::makeAVec; |
| 50 |
|
| 51 |
asl::SPDistanceFunction generateTunnel(asl::Block & bl) |
| 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 |
} |