Debian Codegraph @

src/num/aslBasicBC2.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 "aslBasicBC2.h"
25 #include "acl/aclMath/aclVectorOfElements.h"
26 #include "acl/acl.h"
27 #include "acl/aclGenerators.h"
28 #include <acl/Kernels/aclKernel.h>
29 #include "acl/Kernels/aclKernelConfigurationTemplates.h"
30 #include <aslGenerators.h>
31 #include <math/aslTemplateVE.h>
32 #include "acl/aclMath/aclMathAlg.h"
33 #include <math/aslIndex2Position.h>
34 #include <math/aslPositionFunction.h>
35 #include <utilities/aslUValue.h>
36 #include <math/aslDistanceFunctionAlg.h>
37
38
39 namespace asl
40 {
41
42 /* BCConstantValueMap::BCConstantValueMap(Data d,
43 const acl::VectorOfElements & v,
44 Data map):
45 BCondWithMap(map, nearestNeigboursVT(nD(d->getBlock()))),
46 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
47 data(d),
48 value(v)
49 {
50 }
51
52 BCConstantValueMap::~BCConstantValueMap()
53 {
54 }
55
56
57 void BCConstantValueMap::init()
58 {
59 acl::ExpressionContainer kk;
60
61 acl::TypeID type(getElementType(data->getEContainer()));
62
63 auto vGhost(data->getEContainer());
64 kk << (acl::assignmentSafe(vGhost,
65 select(vGhost, value, isGhostNode(), type)));
66
67 kernel->addExpression(acl::elementOperators::
68 ifElse(acl::elementOperators::any((map->getEContainer() <= 0 &&
69 map->getEContainer() > -.9999)[0]),
70 kk.expression,
71 {} ));
72
73 kernel->setup();
74 }
75
76 void BCConstantValueMap::execute()
77 {
78 kernel->compute();
79 }
80 */
81 /*
82 BCValuePFMap::BCValuePFMap(Data d,
83 SPPositionFunction v,
84 Data map):
85 BCondWithMap(map, nearestNeigboursVT(nD(d->getBlock()))),
86 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
87 data(d),
88 value(v)
89 {
90 }
91
92 BCValuePFMap::~BCValuePFMap()
93 {
94 }
95
96 void BCValuePFMap::init()
97 {
98 acl::ExpressionContainer kk;
99
100 acl::TypeID type(getElementType(data->getEContainer()));
101
102 auto vGhost(data->getEContainer());
103 asl::Index2PositionACL i2p(data->getBlock(),type);
104
105 kk << i2p.initPosition;
106 auto val(value->value(i2p.position));
107 kk << (acl::assignmentSafe(vGhost,
108 select(vGhost, val, isGhostNode(), type)));
109
110 kernel->addExpression(acl::elementOperators::
111 ifElse(acl::elementOperators::any((map->getEContainer() <= 0 &&
112 map->getEContainer() > -.9999)[0]),
113 kk.expression,
114 {} ));
115
116 kernel->setup();
117 }
118
119 void BCValuePFMap::execute()
120 {
121 kernel->compute();
122 }
123 */
124
125 BCConstantGradientMap2::BCConstantGradientMap2(Data d,
126 const acl::VectorOfElements & v,
127 Data map,
128 const VectorTemplate *const t):
129 BCondWithMap(map, t),
130 // kernelCN(new acl::Kernel(acl::KERNEL_SIMDUA)),
131 // kernelGN(new acl::Kernel(acl::KERNEL_SIMDUA)),
132 kernelCN(new acl::Kernel(acl::KERNEL_BASIC)),
133 kernelGN(new acl::Kernel(acl::KERNEL_BASIC)),
134 data(d),
135 value(v)
136 {
137 }
138
139 BCConstantGradientMap2::BCConstantGradientMap2(Data d,
140 const acl::VectorOfElements & v,
141 Data map,
142 Data computationalDomain,
143 const VectorTemplate *const t):
144 BCondWithMap(map, computationalDomain, t),
145 // kernelCN(new acl::Kernel(acl::KERNEL_SIMDUA)),
146 // kernelGN(new acl::Kernel(acl::KERNEL_SIMDUA)),
147 kernelCN(new acl::Kernel(acl::KERNEL_BASIC)),
148 kernelGN(new acl::Kernel(acl::KERNEL_BASIC)),
149 data(d),
150 value(v)
151 {
152 }
153
154 BCConstantGradientMap2::~BCConstantGradientMap2()
155 {
156 }
157
158
159 void BCConstantGradientMap2::init()
160 {
161 unsigned int nd(nD(data->getBlock()));
162 unsigned int nc(data->getEContainer().size()); // number of components
163 unsigned int nDir(templ->vectors.size());
164 acl::TypeID type(getElementType(data->getEContainer()));
165
166 auto counter(generateVEPrivateVariable(1,type));
167 auto vLocal(generateVEPrivateVariable(1,type));
168 auto normal(generateVEPrivateVariable(nd,type));
169 auto dirCoef(generateVEPrivateVariable(1,type));
170 auto xx(generateVEPrivateVariable(1,type));
171
172 auto dataX(generateDCFullSafe(data));
173 TemplateVE dataTVE;
174
175 acl::ExpressionContainer kkCN;
176 initMapInfrastructure(kkCN);
177 kkCN << (normal = gradient(*mapTVE));
178 kkCN << (gcNormalize(normal));
179 kkCN << (counter = acl::generateVEConstant(0.));
180 kkCN << (xx = acl::generateVEConstant(0.));
181
182 for(unsigned int i(1); i < nDir; ++i)
183 {
184 kkCN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.);
185 kkCN << (dirCoef *= dirCoef );
186 kkCN << (counter+= select(dirCoef, isGhostNode(templ->invertVectors[i]), type));
187 kkCN << (xx+= select(dirCoef * exBoundaryX(*mapTVE,templ->invertVectors[i]),
188 isGhostNode(templ->invertVectors[i]), type));
189 }
190 kkCN << (xx=select(acl::generateVEConstant(1.),xx/counter,counter>0.001,type));
191 kkCN << (counter = max(counter,acl::generateVEConstant(.001), type));
192
193
194 for(unsigned int ii(0); ii < nc; ++ii)
195 {
196 dataTVE.init(*dataX, *templ, ii,false);
197 kkCN << (vLocal = acl::generateVEConstant(0.));
198 for(unsigned int i(1); i < nDir; ++i)
199 {
200 kkCN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.);
201 kkCN << (dirCoef *= dirCoef );
202 kkCN << (vLocal += select((dataTVE.getValue(i) -
203 (normal*templ->vectors[i])*subVE(value, ii)) *
204 dirCoef,
205 isGhostNode(templ->invertVectors[i]),
206 type));
207 }
208 kkCN << (acl::assignmentSafe(subVE(data->getEContainer(),ii),
209 select(dataTVE.getValue(0),
210 xx*dataTVE.getValue(0) + (1.-xx)*vLocal/counter,
211 isComputationNode(0),
212 type)));
213 }
214 kernelCN->addExpression(acl::elementOperators::
215 ifElse(acl::elementOperators::any((isComputationNode() &&
216 map->getEContainer() < .9999)[0]),
217 kkCN.expression,
218 {} ));
219 kernelCN->setup();
220
221
222 acl::ExpressionContainer kkGN;
223 initMapInfrastructure(kkGN);
224 kkGN << (normal = gradient(*mapTVE));
225 kkGN << (gcNormalize(normal));
226 kkGN << (counter = acl::generateVEConstant(0.));
227
228
229 for(unsigned int i(1); i < nDir; ++i)
230 {
231 kkGN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.);
232 kkGN << (dirCoef *= dirCoef );
233 kkGN << (counter+= select(dirCoef, isComputationNode(i), type));
234 }
235 kkGN << (counter = max(counter,acl::generateVEConstant(.001), type));
236
237 for(unsigned int ii(0); ii < nc; ++ii)
238 {
239 dataTVE.init(*dataX, *templ, ii,false);
240 kkGN << (vLocal = acl::generateVEConstant(0.));
241 for(unsigned int i(1); i < nDir; ++i)
242 {
243 kkGN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.);
244 kkGN << (dirCoef *= dirCoef );
245 kkGN << (vLocal += select((dataTVE.getValue(i) -
246 (normal*templ->vectors[i])*subVE(value, ii)) *
247 dirCoef,
248 isComputationNode(i),
249 type));
250 }
251 kkGN << (acl::assignmentSafe(subVE(data->getEContainer(),ii),
252 select(subVE(dataTVE.values,0),
253 vLocal/counter,
254 isGhostNode(0),
255 type)));
256 }
257 kernelGN->addExpression(acl::elementOperators::
258 ifElse(acl::elementOperators::any((isGhostNode() &&
259 map->getEContainer() > -.9999)[0]),
260 kkGN.expression,
261 {} ));
262 kernelGN->setup();
263 }
264
265 void BCConstantGradientMap2::execute()
266 {
267 kernelCN->compute();
268 kernelGN->compute();
269 }
270
271
272 } // asl
273