| 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_stability.cc |
| 26 |
Example: Locomotive stability |
| 27 |
Required input file: [locomotive.stl](http://asl.org.il/input_data/locomotive.stl) |
| 28 |
*/ |
| 29 |
|
| 30 |
#include <math/aslVectors.h> |
| 31 |
#include <math/aslTemplates.h> |
| 32 |
#include <aslGeomInc.h> |
| 33 |
#include <math/aslPositionFunction.h> |
| 34 |
#include <aslDataInc.h> |
| 35 |
#include <acl/aclGenerators.h> |
| 36 |
#include <writers/aslVTKFormatWriters.h> |
| 37 |
#include <num/aslLBGK.h> |
| 38 |
#include <num/aslLBGKBC.h> |
| 39 |
#include <utilities/aslTimer.h> |
| 40 |
#include <acl/aclUtilities.h> |
| 41 |
#include <readers/aslVTKFormatReaders.h> |
| 42 |
#include <utilities/aslParametersManager.h> |
| 43 |
|
| 44 |
|
| 45 |
typedef float FlT; |
| 46 |
//typedef double FlT; |
| 47 |
typedef asl::UValue<double> Param; |
| 48 |
|
| 49 |
using asl::AVec; |
| 50 |
using asl::makeAVec; |
| 51 |
|
| 52 |
asl::SPDistanceFunction generateNozzels(asl::Block & bl) |
| 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 |
|
| 65 |
asl::SPDistanceFunction res(generateDFCylinder(rNozzel, |
| 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), |
| 125 |
{asl::X0, asl::XE,asl::Y0,asl::YE,asl::Z0,asl::ZE})); |
| 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 |
} |