| 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 flow3.cc |
| 26 |
Example: Flow3 |
| 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 |
typedef float FlT; |
| 42 |
//typedef double FlT; |
| 43 |
typedef asl::UValue<double> Param; |
| 44 |
|
| 45 |
using asl::AVec; |
| 46 |
using asl::makeAVec; |
| 47 |
|
| 48 |
asl::SPDistanceFunction generateOrderedCylinders(asl::Block & block) |
| 49 |
{ |
| 50 |
double r(2.); |
| 51 |
double spacing(4.); |
| 52 |
|
| 53 |
asl::SPDistanceFunction cylinder; |
| 54 |
asl::SPDistanceFunction resultGeometry; |
| 55 |
asl::AVec<double> orientation(asl::makeAVec(0., 0., 1.)); |
| 56 |
for (int i = 0; i < block.getSize()[0] / (2 * r + spacing); ++i) |
| 57 |
{ |
| 58 |
for (int j = 0; j < block.getSize()[1] / (2 * r + spacing); ++j) |
| 59 |
{ |
| 60 |
cylinder = generateDFCylinderInf(r, orientation, asl::makeAVec(i * (2. * r + spacing) + r + spacing / 2., j * (2. * r + spacing) + r + spacing / 2., 0.)); |
| 61 |
resultGeometry = resultGeometry | cylinder; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return resultGeometry; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
int main(int argc, char* argv[]) |
| 70 |
{ |
| 71 |
// Optionally add appParamsManager to be able to manipulate at least |
| 72 |
// hardware parameters(platform/device) through command line/parameters file |
| 73 |
asl::ApplicationParametersManager appParamsManager("flow3", |
| 74 |
"1.0"); |
| 75 |
appParamsManager.load(argc, argv); |
| 76 |
|
| 77 |
Param dx(1.); |
| 78 |
Param dt(1.); |
| 79 |
Param nu(.00625); |
| 80 |
|
| 81 |
Param nuNum(nu.v()*dt.v()/dx.v()/dx.v()); |
| 82 |
AVec<int> size(asl::makeAVec(50, 50, 50)); |
| 83 |
|
| 84 |
auto gSize(dx.v()*AVec<>(size)); |
| 85 |
|
| 86 |
|
| 87 |
std::cout << "Flow: Data initialization..."; |
| 88 |
|
| 89 |
asl::Block block(size,dx.v()); |
| 90 |
|
| 91 |
auto cylindersMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 92 |
asl::initData(cylindersMapMem, generateOrderedCylinders(block)); |
| 93 |
|
| 94 |
|
| 95 |
std::cout << "Finished" << endl; |
| 96 |
|
| 97 |
std::cout << "Flow: Numerics initialization..."; |
| 98 |
|
| 99 |
asl::SPLBGK lbgk(new asl::LBGK(block, |
| 100 |
acl::generateVEConstant(FlT(nuNum.v())), |
| 101 |
&asl::d3q15())); |
| 102 |
|
| 103 |
lbgk->init(); |
| 104 |
asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk)); |
| 105 |
lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0)); |
| 106 |
|
| 107 |
auto bcNoSlip(generateBCNoSlip(lbgk,{asl::Y0, asl::YE, asl::Z0, asl::ZE})); |
| 108 |
auto bcNoSlipM(generateBCNoSlip(lbgk, cylindersMapMem)); |
| 109 |
auto bcNoSlipV(generateBCNoSlipVel(lbgk, cylindersMapMem)); |
| 110 |
asl::BCConstantPressure bcIn(lbgk, acl::generateVEConstant(1.2)); |
| 111 |
asl::BCConstantPressure bcOut(lbgk, acl::generateVEConstant(0.8)); |
| 112 |
|
| 113 |
addSliceX0(bcIn); |
| 114 |
addSliceXE(bcOut); |
| 115 |
|
| 116 |
bcNoSlip->init(); |
| 117 |
bcNoSlipM->init(); |
| 118 |
bcNoSlipV->init(); |
| 119 |
bcIn.init(); |
| 120 |
bcOut.init(); |
| 121 |
|
| 122 |
std::cout << "Finished" << endl; |
| 123 |
std::cout << "Computing..."; |
| 124 |
asl::Timer timer; |
| 125 |
|
| 126 |
asl::WriterVTKXML writer("flow3Res"); |
| 127 |
writer.addScalars("map", *cylindersMapMem); |
| 128 |
writer.addScalars("rho", *lbgk->getRho()); |
| 129 |
writer.addVector("v", *lbgk->getVelocity()); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
bcIn.execute(); |
| 134 |
bcOut.execute(); |
| 135 |
bcNoSlip->execute(); |
| 136 |
bcNoSlipM->execute(); |
| 137 |
|
| 138 |
bcNoSlipV->execute(); |
| 139 |
writer.write(); |
| 140 |
|
| 141 |
timer.start(); |
| 142 |
for (unsigned int i(0); i < 1000; ++i) |
| 143 |
{ |
| 144 |
lbgk->execute(); |
| 145 |
bcIn.execute(); |
| 146 |
bcOut.execute(); |
| 147 |
bcNoSlip->execute(); |
| 148 |
bcNoSlipM->execute(); |
| 149 |
if (!(i%100)) |
| 150 |
{ |
| 151 |
cout << i << endl; |
| 152 |
bcNoSlipV->execute(); |
| 153 |
writer.write(); |
| 154 |
} |
| 155 |
} |
| 156 |
timer.stop(); |
| 157 |
|
| 158 |
|
| 159 |
cout << "Finished" << endl; |
| 160 |
|
| 161 |
cout << "Computation statistic:" << endl; |
| 162 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 163 |
<< timer.processorTime() << "; Processor Load = " |
| 164 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 165 |
|
| 166 |
return 0; |
| 167 |
} |