Debian Codegraph @

src/numExtend/aslFDAdvectionDiffusionExtended.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 "aslFDAdvectionDiffusionExtended.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 FDAdvectionDiffusionExtended::FDAdvectionDiffusionExtended():
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 FDAdvectionDiffusionExtended::FDAdvectionDiffusionExtended(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 FDAdvectionDiffusionExtended::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 FDAdvectionDiffusionExtended::init(){
72 if (electricField)
73 {
74 if (cData.size() != diffusionCoefficient.size() || cData.size() != efChargeAnd.size())
75 errorMessage("FDAdvectionDiffusion::init: some of compenents are underdefined");
76 }
77 else
78 {
79 if (cData.size() != diffusionCoefficient.size())
80 errorMessage("FDAdvectionDiffusion::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 for (unsigned int i(0); i < cData.size(); ++i){
102 TemplateVE cT(*cData[i],d2q5());
103 (*kernel)<<cT.initValues;
104 (*kernel)<<(cnew=
105 acl::generateVEVariableR(diffusionCoefficient[i])*laplas(cT)+
106 cT.getValue(0));
107 if (electricField)
108 {
109 TemplateVE q(*efChargeAnd[i],d2q5());
110 (*kernel)<<q.initValues;
111 (*kernel)<<(cnew-=divAgradB(cT*q/(*f1),(*phi)/*+(*f2)*/));
112 }
113 (*kernel)<<(assignmentSafe (cInternalData[i]->getSubContainer(),cnew));
114 }
115 kernel->setup();
116 }
117
118
119 void FDAdvectionDiffusionExtended::execute()
120 {
121 kernel->compute();
122 for (unsigned int i(0); i < cData.size(); ++i)
123 swapBuffers(cData[i]->getDContainer(),cInternalData[i]->getDContainer());
124 }
125
126
127 void FDAdvectionDiffusionExtended::setDiffusionCoefficient (double dC, unsigned int i)
128 {
129 diffusionCoefficient[i] =dC;
130 }
131
132 void FDAdvectionDiffusionExtended::addComponent (Data c, double dC)
133 {
134 if (electricField)
135 errorMessage("FDAdvectionDiffusion::addComponent: \"Electric field\" is swiched on \n therefore \"qAnd\" value should be specified");
136 diffusionCoefficient.push_back (dC);
137 cData.push_back (c);
138 }
139 void FDAdvectionDiffusionExtended::addComponent (Data c, double dC,ScalarField qAnd)
140 {
141 diffusionCoefficient.push_back (dC);
142 cData.push_back (c);
143 efChargeAnd.push_back (qAnd);
144 }
145 } //asl