ASL  0.1.7
Advanced Simulation Library
testSMDiff.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 
29 #include <math/aslTemplates.h>
30 #include <aslGeomInc.h>
31 #include <aslDataInc.h>
32 #include <acl/aclGenerators.h>
34 #include <num/aslFDStefanMaxwell.h>
35 #include <num/aslBasicBC.h>
36 #include <utilities/aslTimer.h>
37 
38 
39 typedef float FlT;
40 //typedef double FlT;
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("testSMDiff",
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 
66  std::cout << "Data initialization... ";
67 
68  asl::Block block(size,dx.v());
69 
70  auto c1Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
71  asl::initData(c1Field, 0.5);
72  auto c2Field(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
73  asl::initData(c2Field, 0.5);
74 
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->init();
85 
86  std::vector<asl::SPNumMethod> bc;
87 
88  bc.push_back(asl::generateBCConstantGradient(c1Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE}));
89  bc.push_back(asl::generateBCConstantValue(c1Field, 0, {asl::X0}));
90  bc.push_back(asl::generateBCConstantValue(c1Field, 1, {asl::XE}));
91  bc.push_back(asl::generateBCConstantGradient(c2Field, 0, templ, {asl::Y0,asl::YE,asl::Z0,asl::ZE}));
92  bc.push_back(asl::generateBCConstantValue(c2Field, 0, {asl::XE}));
93  bc.push_back(asl::generateBCConstantValue(c2Field, 1, {asl::X0}));
94  initAll(bc);
95 
96  std::cout << "Finished" << endl;
97  std::cout << "Computing..." << flush;
98  asl::Timer timer;
99 
100  asl::WriterVTKXML writer(appParamsManager.getDir() + "testSMDiff");
101  writer.addScalars("c1", *c1Field);
102  writer.addScalars("c2", *c2Field);
103 
104  executeAll(bc);
105  writer.write();
106 
107  timer.start();
108  for(unsigned int i(1); i < 401; ++i)
109  {
110  nm->execute();
111  executeAll(bc);
112  if(!(i%40))
113  {
114  cout << i << endl;
115  writer.write();
116  }
117  }
118  timer.stop();
119 
120  cout << "Finished" << endl;
121 
122  cout << "Computation statistic:" << endl;
123  cout << "Real Time = " << timer.realTime() << "; Processor Time = "
124  << timer.processorTime() << "; Processor Load = "
125  << timer.processorLoad() * 100 << "%" << endl;
126 
127  return 0;
128 }
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
asl::UValue< double > Param
Definition: testSMDiff.cc:41
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
std::string getDir()
cl_int flush(void)
Definition: cl.hpp:7042
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
int main(int argc, char *argv[])
Definition: testSMDiff.cc:47
void initData(SPAbstractData d, double a)
float FlT
Definition: testSMDiff.cc:39
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
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