Debian Codegraph @

examples/flow/flow.cc

raw
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 flow.cc
26 Example: Flow
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
50 int main(int argc, char* argv[])
51 {
52 // Optionally add appParamsManager to be able to manipulate at least
53 // hardware parameters(platform/device) through command line/parameters file
54 asl::ApplicationParametersManager appParamsManager("flow",
55 "1.0");
56 appParamsManager.load(argc, argv);
57
58 Param dx(1.);
59 Param dt(1.);
60 Param nu(.00625);
61
62 Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
63 AVec<int> size(asl::makeAVec(300, 50, 50));
64
65 auto gSize(dx.v()*AVec<>(size));
66
67
68 std::cout << "Data initialization... ";
69
70 asl::Block block(size,dx.v());
71
72 auto ball(generateDFCylinderInf(.125*gSize[1],
73 makeAVec(0.,1.,0.),
74 .45*makeAVec(gSize[1],gSize[1],gSize[2])));
75 // Formula
76 auto ballMap(asl::generateDataContainer_SP(block, ball, 1u, acl::typeToTypeID<FlT>()));
77 // Data
78 auto ballMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
79 asl::initData(ballMapMem, ball);
80
81
82 std::cout << "Finished" << endl;
83
84 std::cout << "Numerics initialization... ";
85
86 asl::SPLBGK lbgk(new asl::LBGK(block,
87 acl::generateVEConstant(FlT(nuNum.v())),
88 &asl::d3q15()));
89 lbgk->init();
90
91 asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
92 // Initialization of lbgk
93 lbgkUtil->initF(acl::generateVEConstant(.0,.0,.0));
94 // lbgkUtil->initF(acl::generateVEConstant(.1), acl::generateVEConstant(.0,.0,.0));
95
96 std::vector<asl::SPNumMethod> bc;
97 std::vector<asl::SPNumMethod> bcVis;
98
99 bc.push_back(asl::generateBCConstantPressure(lbgk, 1.2, {asl::X0}));
100 bc.push_back(asl::generateBCConstantPressure(lbgk, 0.8, {asl::XE}));
101 bc.push_back(generateBCNoSlip(lbgk, {asl::Y0, asl::YE, asl::Z0, asl::ZE}));
102 bc.push_back(generateBCNoSlip(lbgk, ballMap));
103 bcVis.push_back(generateBCNoSlipVel(lbgk, ballMap));
104
105 initAll(bc);
106 initAll(bcVis);
107
108 std::cout << "Finished" << endl;
109 std::cout << "Computing...";
110 asl::Timer timer;
111
112 asl::WriterVTKXML writer("flow");
113 writer.addScalars("map", *ballMapMem);
114 writer.addScalars("rho", *lbgk->getRho());
115 writer.addVector("v", *lbgk->getVelocity());
116
117
118
119 executeAll(bc);
120 executeAll(bcVis);
121 writer.write();
122
123 timer.start();
124 for (unsigned int i(1); i < 1001; ++i)
125 {
126 lbgk->execute();
127 executeAll(bc);
128 if (!(i%5000))
129 {
130 cout << i << endl;
131 executeAll(bcVis);
132 writer.write();
133 }
134 }
135 timer.stop();
136
137
138 cout << "Finished" << endl;
139
140 cout << "Computation statistic:" << endl;
141 cout << "Real Time = " << timer.realTime() << "; Processor Time = "
142 << timer.processorTime() << "; Processor Load = "
143 << timer.processorLoad() * 100 << "%" << endl;
144
145 return 0;
146 }