Debian Codegraph @

src/num/aslFDAdvectionDiffusion2.cxx

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 #include "aslFDAdvectionDiffusion2.h"
25 #include "aslGenerators.h"
26 #include <acl/aclGenerators.h>
27 #include "acl/acl.h"
28 #include "math/aslTemplateVE.h"
29
30 #include <data/aslDataWithGhostNodes.h>
31 #include <acl/Kernels/aclKernel.h>
32 #include <math/aslTemplates.h>
33
34 #include <acl/Kernels/aclKernelConfigurationTemplates.h>
35
36 namespace asl
37 {
38 FDAdvectionDiffusion2::FDAdvectionDiffusion2():
39 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
40 cData(0),
41 cInternalData(0),
42 electricField(false),
43 efChargeAnd(0),
44 vectorTemplate(NULL),
45 diffusionCoefficient(0)
46 {
47 }
48
49 FDAdvectionDiffusion2::FDAdvectionDiffusion2(Data c, double dC, const VectorTemplate* vT):
50 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
51 cData(1u,c),
52 cInternalData(0u),
53 electricField(false),
54 efChargeAnd(0u),
55 vectorTemplate(vT),
56 diffusionCoefficient(1u,dC)
57 {
58 }
59
60
61 void FDAdvectionDiffusion2::setElectricFieldParameters(ScalarField phi, ScalarField f1, ScalarField f2, ScalarField qAnd)
62 {
63 electricField=true;
64 efPhi=phi;
65 efFactor1=f1;
66 efFactor2=f2;
67 efChargeAnd.resize(1);
68 efChargeAnd[0] =qAnd;
69 }
70
71 void FDAdvectionDiffusion2::init(){
72 if (electricField)
73 {
74 if (cData.size() != diffusionCoefficient.size() || cData.size() != efChargeAnd.size())
75 errorMessage("FDAdvectionDiffusion2::init: some of compenents are underdefined");
76 }
77 else
78 {
79 if (cData.size() != diffusionCoefficient.size())
80 errorMessage("FDAdvectionDiffusion2::init: some of compenents are underdefined");
81 }
82
83 acl::TypeID type(getElementType(cData[0]->getDContainer()));
84
85 cInternalData.resize(cData.size());
86 for (unsigned int i(0); i < cData.size(); ++i)
87 cInternalData[i] =clone(cData[i]);
88 acl::VectorOfElements cnew(acl::generateVEPrivateVariable(1,type));
89 std::unique_ptr<TemplateVE> f1;
90 std::unique_ptr<TemplateVE> f2;
91 std::unique_ptr<TemplateVE> phi;
92 if (electricField)
93 {
94 f1.reset(new TemplateVE(*efFactor1,d2q5()));
95 f2.reset(new TemplateVE(*efFactor2,d2q5()));
96 phi.reset(new TemplateVE(*efPhi,d2q5()));
97 (*kernel)<<f1->initValues;
98 (*kernel)<<f2->initValues;
99 (*kernel)<<phi->initValues;
100 }
101
102 TemplateVE cT;
103 for (unsigned int i(0); i < cData.size(); ++i){
104 cT.init(*cData[i],d2q5());
105 (*kernel)<<cT.initValues;
106 (*kernel)<<(cnew=
107 acl::generateVEVariableR(diffusionCoefficient[i])*laplas(cT));
108 if (electricField)
109 {
110 TemplateVE q(*efChargeAnd[i],d2q5());
111 (*kernel)<<q.initValues;
112 (*kernel)<<(cnew-=divAgradB(cT*q/(*f1),(*phi)/*+(*f2)*/));
113 }
114 (*kernel)<<(assignmentSafe (cInternalData[i]->getSubContainer(),cInternalData[i]->getSubContainer()+acl::generateVEConstant(2.)*cnew));
115 }
116 kernel->setup();
117 }
118
119
120 void FDAdvectionDiffusion2::execute()
121 {
122 kernel->compute();
123 for (unsigned int i(0); i < cData.size(); ++i)
124 swapBuffers(cData[i]->getDContainer(),cInternalData[i]->getDContainer());
125 }
126
127
128 void FDAdvectionDiffusion2::setDiffusionCoefficient (double dC, unsigned int i)
129 {
130 diffusionCoefficient[i] =dC;
131 }
132
133 void FDAdvectionDiffusion2::addComponent (Data c, double dC)
134 {
135 if (electricField)
136 errorMessage("FDAdvectionDiffusion2::addComponent: \"Electric field\" is swiched on \n therefore \"qAnd\" value should be specified");
137 diffusionCoefficient.push_back (dC);
138 cData.push_back (c);
139 }
140 void FDAdvectionDiffusion2::addComponent (Data c, double dC,ScalarField qAnd)
141 {
142 diffusionCoefficient.push_back (dC);
143 cData.push_back (c);
144 efChargeAnd.push_back (qAnd);
145 }
146 } //asl