| 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 testSMPhi.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/aslBasicBC.h> |
| 36 |
#include <utilities/aslTimer.h> |
| 37 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 38 |
|
| 39 |
typedef float FlT; |
| 40 |
//typedef double FlT; |
| 41 |
typedef asl::UValue<double> Param; |
| 42 |
|
| 43 |
using asl::AVec; |
| 44 |
using asl::makeAVec; |
| 45 |
|
| 46 |
|
| 47 |
int main(int argc, char* argv[]) |
| 48 |
{ |
| 49 |
// Optionally add appParamsManager to be able to manipulate at least |
| 50 |
// hardware parameters(platform/device) through command line/parameters file |
| 51 |
asl::ApplicationParametersManager appParamsManager("testSMPhi", |
| 52 |
"1.0"); |
| 53 |
appParamsManager.load(argc, argv); |
| 54 |
|
| 55 |
Param dx(1.); |
| 56 |
Param dt(1.); |
| 57 |
Param diffCoef(.15); |
| 58 |
|
| 59 |
Param diffCoefNum(diffCoef.v()*dt.v()/dx.v()/dx.v()); |
| 60 |
|
| 61 |
AVec<int> size(asl::makeAVec(10,20,20)); |
| 62 |
|
| 63 |
auto gSize(dx.v()*AVec<>(size)); |
| 64 |
|
| 65 |
std::cout << "Data initialization..."; |
| 66 |
|
| 67 |
asl::Block block(size,dx.v()); |
| 68 |
|
| 69 |
auto c1Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 70 |
asl::initData(c1Field, 0.5); |
| 71 |
auto c2Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 72 |
asl::initData(c2Field, 0.5); |
| 73 |
auto phiField(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 74 |
asl::initData(phiField, 0.5); |
| 75 |
|
| 76 |
std::cout << "Finished" << endl; |
| 77 |
|
| 78 |
std::cout << "Numerics initialization..."; |
| 79 |
|
| 80 |
auto templ(&asl::d3q7()); |
| 81 |
auto nm(generateFDStefanMaxwell(c1Field, c2Field, diffCoefNum.v(), templ)); |
| 82 |
nm->setDustDiffusionCoefficient(0,acl::generateVEConstant(diffCoefNum.v()*.5)); |
| 83 |
nm->setDustDiffusionCoefficient(1,acl::generateVEConstant(diffCoefNum.v())); |
| 84 |
nm->setElectricField(asl::generateDataContainer_SP(phiField->getInternalBlock(), |
| 85 |
phiField->getEContainer()*1e5/8.31/300, |
| 86 |
1u)); |
| 87 |
nm->setCharge(0,acl::generateVEConstant(-2.)); |
| 88 |
nm->setCharge(1,acl::generateVEConstant(0.)); |
| 89 |
nm->init(); |
| 90 |
|
| 91 |
auto nmPhi(make_shared<asl::FDStefanMaxwellElectricField>(nm, phiField)); |
| 92 |
nmPhi->init(); |
| 93 |
|
| 94 |
std::vector<asl::SPNumMethod> bc; |
| 95 |
std::vector<asl::SPNumMethod> bcPhi; |
| 96 |
|
| 97 |
bc.push_back(asl::generateBCConstantGradient(c1Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE})); |
| 98 |
bc.push_back(asl::generateBCConstantValue(c1Field, .1, {asl::X0})); |
| 99 |
bc.push_back(asl::generateBCConstantValue(c1Field, 1, {asl::XE})); |
| 100 |
bc.push_back(asl::generateBCConstantGradient(c2Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE})); |
| 101 |
bc.push_back(asl::generateBCConstantValue(c2Field, 0.1, {asl::XE})); |
| 102 |
bc.push_back(asl::generateBCConstantValue(c2Field, 1, {asl::X0})); |
| 103 |
initAll(bc); |
| 104 |
bcPhi.push_back(asl::generateBCConstantGradient(phiField, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE})); |
| 105 |
bcPhi.push_back(asl::generateBCConstantValue(phiField, 1, {asl::XE})); |
| 106 |
bcPhi.push_back(asl::generateBCConstantValue(phiField, 0, {asl::X0})); |
| 107 |
initAll(bcPhi); |
| 108 |
|
| 109 |
std::cout << "Finished" << endl; |
| 110 |
std::cout << "Computing..." << flush; |
| 111 |
asl::Timer timer; |
| 112 |
|
| 113 |
asl::WriterVTKXML writer(appParamsManager.getDir() + "testSMPhi"); |
| 114 |
writer.addScalars("c1", *c1Field); |
| 115 |
writer.addScalars("c2", *c2Field); |
| 116 |
writer.addScalars("phi", *phiField); |
| 117 |
|
| 118 |
executeAll(bc); |
| 119 |
executeAll(bcPhi); |
| 120 |
writer.write(); |
| 121 |
|
| 122 |
timer.start(); |
| 123 |
for(unsigned int i(1); i < 401; ++i) |
| 124 |
{ |
| 125 |
for(unsigned int j(0); j<50; ++j) |
| 126 |
{ |
| 127 |
nmPhi->execute(); |
| 128 |
executeAll(bcPhi); |
| 129 |
} |
| 130 |
nm->execute(); |
| 131 |
executeAll(bc); |
| 132 |
if (!(i%40)) |
| 133 |
{ |
| 134 |
cout << i << endl; |
| 135 |
writer.write(); |
| 136 |
} |
| 137 |
} |
| 138 |
timer.stop(); |
| 139 |
|
| 140 |
cout << "Finished" << endl; |
| 141 |
|
| 142 |
cout << "Computation statistic:" << endl; |
| 143 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 144 |
<< timer.processorTime() << "; Processor Load = " |
| 145 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 146 |
|
| 147 |
return 0; |
| 148 |
} |