| 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 flow2.cc |
| 26 |
Example: Flow2 |
| 27 |
*/ |
| 28 |
|
| 29 |
#include <utilities/aslParametersManager.h> |
| 30 |
#include <aslDataInc.h> |
| 31 |
#include <math/aslTemplates.h> |
| 32 |
#include <aslGeomInc.h> |
| 33 |
#include <acl/aclGenerators.h> |
| 34 |
#include <writers/aslVTKFormatWriters.h> |
| 35 |
#include <num/aslLBGK.h> |
| 36 |
#include <num/aslLBGKBC.h> |
| 37 |
#include <utilities/aslTimer.h> |
| 38 |
#include <acl/aclUtilities.h> |
| 39 |
|
| 40 |
|
| 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 generateMirror(double x, double y) |
| 50 |
{ |
| 51 |
double hCyl (10.); |
| 52 |
double rCyl (1.5); |
| 53 |
double a(10.); |
| 54 |
double b(6.); |
| 55 |
vector<AVec<>> rect({.5*makeAVec( .866*a,-b,-a*.5),.5*makeAVec(-.866*a,-b, a*.5), |
| 56 |
.5*makeAVec(-.866*a, b, a*.5),.5*makeAVec( .866*a, b,-a*.5)}); |
| 57 |
vector<AVec<>> r1(rect.size()); |
| 58 |
vector<AVec<>> r2(rect.size()); |
| 59 |
auto r1C(makeAVec(x,y+rCyl*.5+b*.5,hCyl)); |
| 60 |
auto r2C(makeAVec(x,y-rCyl*.5-b*.5,hCyl)); |
| 61 |
for(unsigned int i(0); i<rect.size();++i) |
| 62 |
{ |
| 63 |
r1[i]=r1C + rect[i]; |
| 64 |
r2[i]=r2C + rect[i]; |
| 65 |
} |
| 66 |
|
| 67 |
auto res(asl::generateDFConvexPolygonPrism(r1) | generateDFConvexPolygonPrism(r2)); |
| 68 |
res = (res & |
| 69 |
generateDFPlane(makeAVec(.5,0.,.866), r1C + makeAVec(rCyl,0.,0.)) & |
| 70 |
generateDFPlane(makeAVec(-.5,0.,-.866), r1C - makeAVec(rCyl,0.,0.))) | |
| 71 |
generateDFCylinder(rCyl, makeAVec(0.,0.,hCyl), makeAVec(x,y,hCyl*.5)); |
| 72 |
return res; |
| 73 |
} |
| 74 |
|
| 75 |
asl::SPDistanceFunction generateMirrors() |
| 76 |
{ |
| 77 |
vector<double> xValues; |
| 78 |
vector<double> yValues; |
| 79 |
|
| 80 |
for(unsigned int i(0); i < 8; ++i) |
| 81 |
for(unsigned int j(0); j < 10; ++j) |
| 82 |
{ |
| 83 |
xValues.push_back(25.+ 20.*i); |
| 84 |
yValues.push_back(25.+ 15.*j); |
| 85 |
} |
| 86 |
|
| 87 |
auto res(generateMirror(xValues[0], yValues[0])); |
| 88 |
for(unsigned int i(1); i < xValues.size(); ++i) |
| 89 |
res = res | generateMirror(xValues[i], yValues[i]); |
| 90 |
|
| 91 |
return res; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
int main(int argc, char* argv[]) |
| 96 |
{ |
| 97 |
// Optionally add appParamsManager to be able to manipulate at least |
| 98 |
// hardware parameters(platform/device) through command line/parameters file |
| 99 |
asl::ApplicationParametersManager appParamsManager("flow2", |
| 100 |
"1.0"); |
| 101 |
appParamsManager.load(argc, argv); |
| 102 |
|
| 103 |
Param dx(1.); |
| 104 |
Param dt(1.); |
| 105 |
Param nu(.0125); |
| 106 |
|
| 107 |
Param nuNum(nu.v()*dt.v()/dx.v()/dx.v()); |
| 108 |
AVec<int> size(asl::makeAVec(200,200,25)); |
| 109 |
|
| 110 |
AVec<> gSize(dx.v()*AVec<>(size)); |
| 111 |
|
| 112 |
|
| 113 |
std::cout << "Data initialization... "; |
| 114 |
|
| 115 |
asl::Block block(size,dx.v()); |
| 116 |
|
| 117 |
auto mirrorsMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 118 |
asl::initData(mirrorsMapMem, generateMirrors()); |
| 119 |
|
| 120 |
std::cout << "Finished" << endl; |
| 121 |
|
| 122 |
std::cout << "Numerics initialization... "; |
| 123 |
|
| 124 |
asl::SPLBGK lbgk(new asl::LBGK(block, |
| 125 |
acl::generateVEConstant(FlT(nuNum.v())), |
| 126 |
&asl::d3q15())); |
| 127 |
|
| 128 |
lbgk->init(); |
| 129 |
asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk)); |
| 130 |
lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0)); |
| 131 |
// lbgkUtil->initF(acl::generateVEConstant(.1), acl::generateVEConstant(.0,.0,.0)); |
| 132 |
|
| 133 |
auto bcNoSlip(generateBCNoSlip(lbgk,{asl::Y0, asl::YE, asl::Z0})); |
| 134 |
auto bcNoSlipM(generateBCNoSlip(lbgk, mirrorsMapMem)); |
| 135 |
auto bcNoSlipV(generateBCNoSlipVel(lbgk, mirrorsMapMem)); |
| 136 |
auto bcP(asl::generateBCConstantPressure(lbgk, 1., {asl::X0, asl::XE})); |
| 137 |
auto bcTop(asl::generateBCConstantVelocity(lbgk, asl::makeAVec(0.1,0.,0.), {asl::ZE})); |
| 138 |
|
| 139 |
bcNoSlip->init(); |
| 140 |
bcNoSlipM->init(); |
| 141 |
bcNoSlipV->init(); |
| 142 |
bcP->init(); |
| 143 |
bcTop->init(); |
| 144 |
|
| 145 |
std::cout << "Finished" << endl; |
| 146 |
std::cout << "Computing..."; |
| 147 |
asl::Timer timer; |
| 148 |
|
| 149 |
asl::WriterVTKXML writer("flow2"); |
| 150 |
writer.addScalars("map", *mirrorsMapMem); |
| 151 |
writer.addScalars("rho", *lbgk->getRho()); |
| 152 |
writer.addVector("v", *lbgk->getVelocity()); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
bcP->execute(); |
| 157 |
bcTop->execute(); |
| 158 |
bcNoSlip->execute(); |
| 159 |
bcNoSlipM->execute(); |
| 160 |
|
| 161 |
bcNoSlipV->execute(); |
| 162 |
writer.write(); |
| 163 |
|
| 164 |
timer.start(); |
| 165 |
for (unsigned int i(0); i < 1000 ; ++i) |
| 166 |
{ |
| 167 |
lbgk->execute(); |
| 168 |
bcP->execute(); |
| 169 |
bcTop->execute(); |
| 170 |
bcNoSlip->execute(); |
| 171 |
bcNoSlipM->execute(); |
| 172 |
if (!(i%100)) |
| 173 |
{ |
| 174 |
cout << i << endl; |
| 175 |
bcNoSlipV->execute(); |
| 176 |
writer.write(); |
| 177 |
} |
| 178 |
} |
| 179 |
timer.stop(); |
| 180 |
|
| 181 |
|
| 182 |
cout << "Finished" << endl; |
| 183 |
|
| 184 |
cout << "Computation statistic:" << endl; |
| 185 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 186 |
<< timer.processorTime() << "; Processor Load = " |
| 187 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 188 |
|
| 189 |
return 0; |
| 190 |
} |