Debian Codegraph @

src/num/aslFDElChemKinetics.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 "aslFDElChemKinetics.h"
25 #include <aslGenerators.h>
26 #include <acl/aclGenerators.h>
27 #include <acl/acl.h>
28 #include <math/aslTemplateVE.h>
29 #include <acl/aclMath/aclVectorOfElements.h>
30
31 #include <data/aslDataWithGhostNodes.h>
32 #include <acl/Kernels/aclKernel.h>
33 #include <math/aslTemplates.h>
34
35 #include <acl/Kernels/aclKernelConfigurationTemplates.h>
36
37 namespace asl
38 {
39
40 FDBVKinetics::FDBVKinetics(Data a0,
41 double n0,
42 Data aI,
43 double nI,
44 Data phiS,
45 Field phi,
46 const Param & j0,
47 const Param & b,
48 double n):
49 SingleKernelMapNM(acl::KERNEL_SIMD),
50 kernelJ(make_shared<acl::Kernel>(acl::KERNEL_SIMD)),
51 // SingleKernelMapNM(acl::KERNEL_BASIC),
52 // kernelJ(make_shared<acl::Kernel>(acl::KERNEL_BASIC)),
53 aI({a0,aI}),
54 efSPhi(phiS),
55 phi(phi),
56 nI({n0,nI}),
57 j0(j0),
58 beta(b),
59 n(n)
60 {
61 }
62
63 void FDBVKinetics::init0()
64 {
65 acl::TypeID type(getElementType(aI[0]->getDContainer()));
66
67 acl::VectorOfElements j(acl::generateVEPrivateVariable(1, type));
68 auto eta(phi->getEContainer());
69 auto phiSL(efSPhi->getEContainer());
70
71 acl::ExpressionContainer kk;
72 initMapInfrastructure(kk);
73
74 // valid for beta=0.5 only
75 acl::VectorOfElements cProd(aI[0]->getEContainer());
76 for(unsigned int i(1); i<aI.size(); ++i)
77 copy(cProd*aI[i]->getEContainer(),cProd);
78 copy(sqrt(cProd),cProd);
79
80 acl::VectorOfElements jCoef(acl::generateVEConstant(0.));
81 for(unsigned int i(0); i<aI.size(); ++i)
82 {
83 acl::VectorOfElements jCoefI(acl::generateVEConstant(1.));
84 for(unsigned int j(0); j<aI.size()-1; ++j)
85 copy(jCoefI* aI[j+(j>=i?1:0)]->getEContainer() , jCoefI);
86 copy(jCoef+ nI[i]*jCoefI,jCoef);
87 }
88
89
90 kk << (j = j0*cProd*(exp((1.-beta)*n*eta) - exp(-beta*n*eta))/
91 (1./*-j0/cProd*.5*(exp((1.-beta)*n*eta) - exp(-beta*n*eta))/n*jCoef*/ ));
92
93 //no reaction for 0 anount of reactants
94 for(unsigned int i(0); i<aI.size(); ++i)
95 if(nI[i]<0)
96 kk << (j=min(j,-aI[i]->getEContainer()*(n/nI[i]),type));
97
98 kk << (assignmentSafe(phiSL, j));
99
100 (*kernelJ) << kk;
101 (*kernel) << kk;
102 for(unsigned int i(0); i<aI.size(); ++i)
103 (*kernel) << (assignmentSafe(aI[i]->getEContainer(),
104 aI[i]->getEContainer()+nI[i]*j/n));
105
106 }
107
108 void FDBVKinetics::addAI(Data ai, double ni)
109 {
110 aI.push_back(ai);
111 nI.push_back(ni);
112 }
113
114 void FDBVKinetics::executeJ()
115 {
116 kernelJ->compute();
117 };
118
119 SPFDBVKinetics generateFDBVKinetics(SPDataWithGhostNodesACLData a0,
120 double n0,
121 SPDataWithGhostNodesACLData aI,
122 double nI,
123 SPDataWithGhostNodesACLData phiS,
124 SPAbstractDataWithGhostNodes phi,
125 double j0,
126 double beta,
127 double n)
128 {
129 auto nm(make_shared<FDBVKinetics> (a0, n0, aI, nI,
130 phiS, phi,
131 acl::generateVEConstant(j0),
132 acl::generateVEConstant(beta),
133 n));
134 return nm;
135 }
136
137 } //asl