ASL  0.1.7
Advanced Simulation Library
testSMDiff3C.cc
Go to the documentation of this file.
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 
30 #include <math/aslTemplates.h>
31 #include <aslGeomInc.h>
32 #include <aslDataInc.h>
33 #include <acl/aclGenerators.h>
35 #include <num/aslFDStefanMaxwell.h>
36 #include <num/aslBasicBC.h>
37 #include <utilities/aslTimer.h>
39 
40 typedef float FlT;
41 //typedef double FlT;
43 
44 using asl::AVec;
45 using asl::makeAVec;
46 
47 
48 int main(int argc, char* argv[])
49 {
50  // Optionally add appParamsManager to be able to manipulate at least
51  // hardware parameters(platform/device) through command line/parameters file
52  asl::ApplicationParametersManager appParamsManager("testSMDiff3C",
53  "1.0");
54  appParamsManager.load(argc, argv);
55 
56  Param dx(1.);
57  Param dt(1.);
58  Param diffCoef(.15);
59 
60  Param diffCoefNum(diffCoef.v()*dt.v()/dx.v()/dx.v());
61 
62  AVec<int> size(asl::makeAVec(10,20,20));
63 
64  auto gSize(dx.v()*AVec<>(size));
65 
66 
67  std::cout << "Flow: 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.33);
73  auto c2Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
74  asl::initData(c2Field, 0.33);
75  auto c3Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
76  asl::initData(c3Field, 0.33);
77 
78 
79  std::cout << "Finished" << endl;
80 
81  std::cout << "Flow: Numerics initialization... ";
82 
83  auto templ(&asl::d3q7());
84  auto nm(generateFDStefanMaxwell(c1Field, c2Field, diffCoefNum.v(), templ));
85  nm->addComponent(c3Field,acl::generateVEConstant(asl::makeAVec(diffCoefNum.v()*.5,
86  diffCoefNum.v())));
87  nm->setDustDiffusionCoefficient(0,acl::generateVEConstant(diffCoefNum.v()*.5));
88  nm->setDustDiffusionCoefficient(1,acl::generateVEConstant(diffCoefNum.v()*.7));
89  nm->setDustDiffusionCoefficient(2,acl::generateVEConstant(diffCoefNum.v()));
90  nm->init();
91 
92  std::vector<asl::SPNumMethod> bc;
93 
94  bc.push_back(asl::generateBCConstantGradient(c1Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE}));
95  bc.push_back(asl::generateBCConstantValue(c1Field, 0, {asl::X0}));
96  bc.push_back(asl::generateBCConstantValue(c1Field, 1, {asl::XE}));
97  bc.push_back(asl::generateBCConstantGradient(c2Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE}));
98  bc.push_back(asl::generateBCConstantValue(c2Field, 0, {asl::XE}));
99  bc.push_back(asl::generateBCConstantValue(c2Field, 1, {asl::X0}));
100  bc.push_back(asl::generateBCConstantGradient(c3Field, 0, templ, {asl::X0,asl::XE,asl::Z0,asl::ZE}));
101  bc.push_back(asl::generateBCConstantValue(c3Field, 0, {asl::YE}));
102  bc.push_back(asl::generateBCConstantValue(c3Field, 1, {asl::Y0}));
103  initAll(bc);
104 
105  std::cout << "Finished" << endl;
106  std::cout << "Computing..." << flush;
107  asl::Timer timer;
108 
109  asl::WriterVTKXML writer(appParamsManager.getDir() + "testSMDiff3C");
110  writer.addScalars("c1", *c1Field);
111  writer.addScalars("c2", *c2Field);
112  writer.addScalars("c3", *c3Field);
113 
114  executeAll(bc);
115  writer.write();
116 
117  timer.start();
118  for(unsigned int i(1); i < 401; ++i)
119  {
120  nm->execute();
121  executeAll(bc);
122  if(!(i%40))
123  {
124  cout << i << endl;
125  writer.write();
126  }
127  }
128  timer.stop();
129 
130  cout << "Finished" << endl;
131 
132  cout << "Computation statistic:" << endl;
133  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
134  << timer.processorTime() << "; Processor Load = "
135  << timer.processorLoad() * 100 << "%" << endl;
136 
137  return 0;
138 }
const double realTime() const
Definition: aslTimer.h:45
const double processorTime() const
Definition: aslTimer.h:46
AVec< T > makeAVec(T a1)
SPFDStefanMaxwell generateFDStefanMaxwell(SPDataWithGhostNodesACLData c1, SPDataWithGhostNodesACLData c2, double diffustionCoeff, SPAbstractDataWithGhostNodes v, const VectorTemplate *vt)
const T & v() const
Definition: aslUValue.h:43
float FlT
Definition: testSMDiff3C.cc:40
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
std::string getDir()
asl::UValue< double > Param
Definition: testSMDiff3C.cc:42
cl_int flush(void)
Definition: cl.hpp:7042
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
void initData(SPAbstractData d, double a)
SPBCond generateBCConstantGradient(SPAbstractDataWithGhostNodes d, double v, const VectorTemplate *const t, const std::vector< SlicesNames > &sl)
Bondary condition that makes fixed gradient.
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
void addScalars(std::string name, AbstractData &data)
void stop()
Definition: aslTimer.h:44
int main(int argc, char *argv[])
Definition: testSMDiff3C.cc:48
void start()
Definition: aslTimer.h:43
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
SPBCond generateBCConstantValue(SPAbstractDataWithGhostNodes d, double v, const std::vector< SlicesNames > &sl)
Bondary condition that puts fixed value in each point.
const VectorTemplate & d3q7()
Vector template.
void load(int argc, char *argv[])
const double processorLoad() const
Definition: aslTimer.h:47