| 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 compressor.cc |
| 26 |
Example: Axial Compressor |
| 27 |
Required input file: [axial-compressor.stl](http://asl.org.il/input_data/axial-compressor.stl) |
| 28 |
*/ |
| 29 |
|
| 30 |
#include <utilities/aslParametersManager.h> |
| 31 |
#include <math/aslTemplates.h> |
| 32 |
#include <aslGeomInc.h> |
| 33 |
#include <aslDataInc.h> |
| 34 |
#include <math/aslPositionFunction.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 <readers/aslVTKFormatReaders.h> |
| 41 |
|
| 42 |
typedef float FlT; |
| 43 |
//typedef double FlT; |
| 44 |
typedef asl::UValue<double> Param; |
| 45 |
|
| 46 |
using asl::AVec; |
| 47 |
using asl::makeAVec; |
| 48 |
|
| 49 |
asl::SPDistanceFunction generateCase(asl::Block & bl) |
| 50 |
{ |
| 51 |
double rCase((bl.getBPosition()[1] - bl.position[1]) / 2.); |
| 52 |
|
| 53 |
asl::AVec<> center(.5*(bl.getBPosition() + bl.position)); |
| 54 |
center[1] = bl.position[1] + rCase; |
| 55 |
|
| 56 |
auto comprCase(-(generateDFCylinderInf(rCase, makeAVec(0., 0., 1.), center))); |
| 57 |
|
| 58 |
return normalize(comprCase, bl.dx); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
int main(int argc, char* argv[]) |
| 63 |
{ |
| 64 |
// Optionally add appParamsManager to be able to manipulate at least |
| 65 |
// hardware parameters(platform/device) through command line/parameters file |
| 66 |
asl::ApplicationParametersManager appParamsManager("compressor", |
| 67 |
"1.0"); |
| 68 |
asl::Parameter<string> input("input", "path to the compressor geometry input file"); |
| 69 |
appParamsManager.load(argc, argv); |
| 70 |
|
| 71 |
Param dx(0.5); |
| 72 |
Param dt(.001); |
| 73 |
Param nu(.2); |
| 74 |
// Angular velocity |
| 75 |
Param w(6.*3.14*2./60.); |
| 76 |
|
| 77 |
AVec<int> size(makeAVec(33., 33., 90.)*(1./dx.v())); |
| 78 |
asl::Block bl(size, dx.v(), makeAVec(-16.65, -26.15, -67.7)); |
| 79 |
|
| 80 |
// Param nuNum(nu.v()*dt.v()/dx.v()/dx.v()); |
| 81 |
Param nuNum(.2); |
| 82 |
// Angular velocity in one iteration |
| 83 |
Param wNum(w.v()*dt.v()); |
| 84 |
|
| 85 |
std::cout << "Data initialization..." << flush; |
| 86 |
|
| 87 |
|
| 88 |
auto compressorMap(asl::readSurface(input.v(), bl)); |
| 89 |
|
| 90 |
asl::Block block(compressorMap->getInternalBlock()); |
| 91 |
|
| 92 |
auto comprCaseMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 93 |
asl::initData(comprCaseMap, generateCase(block)); |
| 94 |
|
| 95 |
|
| 96 |
std::cout << "Finished" << endl; |
| 97 |
|
| 98 |
std::cout << "Numerics initialization..." << flush; |
| 99 |
|
| 100 |
asl::SPLBGK lbgk(new asl::LBGK(block, |
| 101 |
acl::generateVEConstant(FlT(nuNum.v())), |
| 102 |
&asl::d3q15())); |
| 103 |
// Set angular velocity in lbgk |
| 104 |
lbgk->setOmega(acl::generateVEConstant(makeAVec(0.,0.,wNum.v()))); |
| 105 |
lbgk->init(); |
| 106 |
|
| 107 |
asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk)); |
| 108 |
// Initialization of lbgk |
| 109 |
lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0)); |
| 110 |
|
| 111 |
std::vector<asl::SPNumMethod> bc; |
| 112 |
std::vector<asl::SPNumMethod> bcVis; |
| 113 |
|
| 114 |
// Position Function Angular Velocity Field |
| 115 |
auto vfCase(asl::generatePFRotationField(makeAVec(0.,0., wNum.v()/dx.v()), |
| 116 |
.5*(block.getBPosition() + block.position))); |
| 117 |
// Boundary condition |
| 118 |
bc.push_back(generateBCVelocity(lbgk, vfCase, comprCaseMap)); |
| 119 |
// Boundary condition for visualization |
| 120 |
bcVis.push_back(generateBCVelocityVel(lbgk, vfCase, comprCaseMap)); |
| 121 |
bc.push_back(asl::generateBCConstantPressure(lbgk, 1., {asl::Z0, asl::ZE})); |
| 122 |
bc.push_back(generateBCNoSlip(lbgk, compressorMap)); |
| 123 |
bcVis.push_back(generateBCNoSlipVel(lbgk, compressorMap)); |
| 124 |
|
| 125 |
initAll(bc); |
| 126 |
initAll(bcVis); |
| 127 |
|
| 128 |
|
| 129 |
std::cout << "Finished" << endl; |
| 130 |
std::cout << "Computing..." << endl; |
| 131 |
asl::Timer timer; |
| 132 |
|
| 133 |
asl::WriterVTKXML writer("compressor"); |
| 134 |
writer.addScalars("compressor", *compressorMap); |
| 135 |
writer.addScalars("case", *comprCaseMap); |
| 136 |
writer.addScalars("rho", *lbgk->getRho()); |
| 137 |
writer.addVector("v", *lbgk->getVelocity()); |
| 138 |
|
| 139 |
executeAll(bc); |
| 140 |
executeAll(bcVis); |
| 141 |
|
| 142 |
writer.write(); |
| 143 |
|
| 144 |
timer.start(); |
| 145 |
for (unsigned int i(1); i < 10001; ++i) |
| 146 |
{ |
| 147 |
lbgk->execute(); |
| 148 |
executeAll(bc); |
| 149 |
if (!(i%2000)) |
| 150 |
{ |
| 151 |
cout << i << endl; |
| 152 |
executeAll(bcVis); |
| 153 |
writer.write(); |
| 154 |
} |
| 155 |
} |
| 156 |
timer.stop(); |
| 157 |
|
| 158 |
cout << "Finished" << endl; |
| 159 |
|
| 160 |
cout << "Computation statistic:" << endl; |
| 161 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 162 |
<< timer.processorTime() << "; Processor Load = " |
| 163 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 164 |
|
| 165 |
return 0; |
| 166 |
} |