Debian Codegraph @

examples/massTransferSM/testSMPhiBV.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 testSMPhiBV.cc
26 */
27
28 #include <utilities/aslParametersManager.h>
29 #include <math/aslTemplates.h>
30 #include <aslGeomInc.h>
31 #include <aslDataInc.h>
32 #include <acl/aclGenerators.h>
33 #include <writers/aslVTKFormatWriters.h>
34 #include <num/aslFDStefanMaxwell.h>
35 #include <num/aslFDAdvectionDiffusion.h>
36 #include <num/aslFDElChemKinetics.h>
37 #include <num/aslBasicBC.h>
38 #include <utilities/aslTimer.h>
39 #include <acl/aclMath/aclVectorOfElements.h>
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
49 int main(int argc, char* argv[])
50 {
51 // Optionally add appParamsManager to be able to manipulate at least
52 // hardware parameters(platform/device) through command line/parameters file
53 asl::ApplicationParametersManager appParamsManager("testSMPhiBV",
54 "1.0");
55 appParamsManager.load(argc, argv);
56
57 Param dx(1.);
58 Param dt(1.);
59 Param diffCoef(.15);
60
61 Param diffCoefNum(diffCoef.v()*dt.v()/dx.v()/dx.v());
62
63 AVec<int> size(asl::makeAVec(10,20,20));
64
65 auto gSize(dx.v()*AVec<>(size));
66
67 std::cout << "Data initialization... ";
68
69 asl::Block block(size,dx.v());
70
71 auto c1Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
72 asl::initData(c1Field, 0.5);
73 auto c2Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
74 asl::initData(c2Field, 0.5);
75 auto c1aField(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
76 asl::initData(c1aField, 0.5);
77
78 auto phiField(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
79 asl::initData(phiField, 0.5);
80
81 auto phiSField(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
82 asl::initData(phiSField, 0.);
83
84 std::cout << "Finished" << endl;
85
86 std::cout << "Numerics initialization... ";
87
88 auto templ(&asl::d3q7());
89 auto nm(generateFDStefanMaxwell(c1Field, c2Field, diffCoefNum.v(), templ));
90 nm->setDustDiffusionCoefficient(0,acl::generateVEConstant(diffCoefNum.v()*.5));
91 nm->setDustDiffusionCoefficient(1,acl::generateVEConstant(diffCoefNum.v()));
92 nm->setElectricField(asl::generateDataContainer_SP(block,
93 phiField->getEContainer()*1e5/8.31/300,
94 1u));
95 nm->setCharge(0,acl::generateVEConstant(-2.));
96 nm->setCharge(1,acl::generateVEConstant(0.));
97 nm->init();
98
99 auto nmA(generateFDAdvectionDiffusion(c1aField, diffCoefNum.v(), templ));
100 nmA->init();
101
102 auto nmPhi(make_shared<asl::FDStefanMaxwellElectricField>(nm, phiField));
103 nmPhi->setPhiS(asl::generateDataContainer_SP(block,
104 -phiSField->getEContainer()*.1,
105 1u));
106 nmPhi->init();
107
108 auto nmBV(generateFDBVKinetics(c1aField, -1., c1Field, 1., phiSField,
109 asl::generateDataContainer_SP(block,
110 phiField->getEContainer()+.2,
111 1u),
112 1., .5, 1.));
113 nmBV->addAI(c2Field, -1);
114 nmBV->init();
115
116 std::vector<asl::SPNumMethod> bc;
117 std::vector<asl::SPNumMethod> bcPhi;
118
119 bc.push_back(asl::generateBCConstantGradient(c1Field, 0, templ, {asl::XE,asl::Y0,asl::YE,asl::Z0,asl::ZE}));
120 bc.push_back(asl::generateBCConstantValue(c1Field, 0., {asl::X0}));
121 bc.push_back(asl::generateBCConstantGradient(c2Field, 0, templ, {asl::XE,asl::Y0,asl::YE,asl::Z0,asl::ZE}));
122 bc.push_back(asl::generateBCConstantValue(c2Field, 1, {asl::X0}));
123 bc.push_back(asl::generateBCConstantGradient(c1aField, 0, templ, {asl::X0,asl::Y0,asl::YE,asl::Z0,asl::ZE}));
124 bc.push_back(asl::generateBCConstantValue(c1aField, 1, {asl::XE}));
125 initAll(bc);
126 bcPhi.push_back(asl::generateBCConstantGradient(phiField, 0, templ, {asl::XE,asl::Y0,asl::YE,asl::Z0,asl::ZE}));
127 bcPhi.push_back(asl::generateBCConstantValue(phiField, 0, {asl::X0}));
128 initAll(bcPhi);
129
130 std::cout << "Finished" << endl;
131 std::cout << "Computing..." << flush;
132 asl::Timer timer;
133
134 asl::WriterVTKXML writer(appParamsManager.getDir() + "testSMPhiBV");
135 writer.addScalars("c1", *c1Field);
136 writer.addScalars("c2", *c2Field);
137 writer.addScalars("c1a", *c1aField);
138 writer.addScalars("phi", *phiField);
139 writer.addScalars("phiS", *phiSField);
140
141 executeAll(bc);
142 executeAll(bcPhi);
143 writer.write();
144
145 timer.start();
146 for (unsigned int i(1); i < 401; ++i)
147 {
148 for (unsigned int j(0); j<50; ++j)
149 {
150 nmBV->executeJ();
151 nmPhi->execute();
152 executeAll(bcPhi);
153 }
154 nm->execute();
155 nmA->execute();
156 nmBV->execute();
157 executeAll(bc);
158 if (!(i%40))
159 {
160 cout << i << endl;
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 }