Debian Codegraph @

src/num/aslFDElasticity.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 "aslFDElasticity.h"
25 #include <aslDataInc.h>
26 #include <acl/aclGenerators.h>
27 #include <acl/acl.h>
28 #include <acl/aclMath/aclVectorOfElements.h>
29 #include <acl/Kernels/aclKernel.h>
30 #include <math/aslTemplateVE.h>
31 #include <math/aslTemplates.h>
32 #include <data/aslDataWithGhostNodes.h>
33
34 #include <acl/Kernels/aclKernelConfigurationTemplates.h>
35
36 namespace asl
37 {
38
39 ElasticityCommonA::ElasticityCommonA():
40 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
41 displacementData(),
42 displacementInternalData(),
43 vectorTemplate(NULL)
44 {
45 }
46
47 ElasticityCommonA::~ElasticityCommonA()
48 {
49 }
50
51 ElasticityCommonA::ElasticityCommonA(Data d,
52 Param bM,
53 Param sM,
54 const VectorTemplate* vT):
55 kernel(new acl::Kernel(acl::KERNEL_SIMDUA)),
56 displacementData(d),
57 displacementInternalData(),
58 bulkModulus(bM),
59 shearModulus(sM),
60 vectorTemplate(vT)
61 {
62 }
63
64 void ElasticityCommonA::setForce(FDElasticityIncompressibleStatic::Param f)
65 {
66 acl::copy(f,force);
67 }
68
69 unsigned int nD(const ElasticityCommonA & e)
70 {
71 return nD(e.getDisplacementData()->getBlock());
72 }
73
74 FDElasticityIncompressibleStatic::FDElasticityIncompressibleStatic():
75 ElasticityCommonA(),
76 pressure(),
77 pressureInternalData()
78 {
79 }
80
81 FDElasticityIncompressibleStatic::~FDElasticityIncompressibleStatic()
82 {
83 }
84
85 FDElasticityIncompressibleStatic::FDElasticityIncompressibleStatic(Data d,
86 Param bM,
87 Param sM,
88 const VectorTemplate* vT):
89 ElasticityCommonA(d,bM,sM,vT),
90 pressure(),
91 pressureInternalData()
92 {
93 }
94
95
96 void FDElasticityIncompressibleStatic::init(){
97 unsigned int nD(displacementData->getDContainer().size());
98 displacementInternalData = clone(displacementData);
99 pressure = clone(displacementData, 1u);
100 pressureInternalData = clone(pressure);
101 acl::initData(displacementInternalData->getDContainer(),
102 displacementData->getEContainer());
103 asl::initData(pressure, 0.);
104 asl::initData(pressureInternalData, 0.);
105
106 acl::TypeID type(getElementType(displacementData->getDContainer()));
107
108 acl::VectorOfElements dnew(acl::generateVEPrivateVariable(3,type));
109 acl::VectorOfElements pnew(acl::generateVEPrivateVariable(1,type));
110 acl::VectorOfElements coef1(acl::generateVEPrivateVariable(1,type));
111 acl::VectorOfElements coef2(acl::generateVEPrivateVariable(1,type));
112
113 static const double w(.5);
114 acl::VectorOfElements wC(acl::generateVEConstant(w));
115 acl::VectorOfElements wm1C(acl::generateVEConstant(1.-w));
116 (*kernel)<<(coef1 = shearModulus);
117 (*kernel)<<(coef2 = (bulkModulus+shearModulus/3.));
118
119 TemplateVE du;
120 du.init(*pressure,*vectorTemplate);
121 (*kernel)<< du.initValues << (pnew=du.getValue(0)*wm1C);
122 (*kernel)<<(dnew=displacementData->getSubContainer()-gradient(du));
123
124 auto lap(acl::generateVEPrivateVariable(nD,type));
125
126 for (unsigned int i(0); i<nD; ++i)
127 {
128 du.init(*displacementData,*vectorTemplate,i);
129 (*kernel)<< du.initValues << (subVE(lap,i) = laplas(du));
130 (*kernel)<< (pnew -= coef2*subVE(gradient(du),i)*wC);
131 (*kernel)<< (subVE(dnew,i) += coef1 * subVE(lap,i));
132 // for (unsigned int k(0); k<nD; ++k)
133 // (*kernel)<<(subVE(dnew,k) += coef1 * dIdJ(k,i,du)); //this commment improoves efficiency
134 // kernel->addExpression(acl::elementOperators::barrier());
135 }
136
137 if(force.size()>0)
138 (*kernel)<<(dnew+= force);
139
140 (*kernel)<<(assignmentSafe (displacementInternalData->getSubContainer(),dnew));
141 (*kernel)<<(assignmentSafe (pressureInternalData->getSubContainer(),pnew));
142
143 kernel->setup();
144 }
145
146
147 void FDElasticityIncompressibleStatic::execute()
148 {
149 kernel->compute();
150 swapBuffers(displacementData->getDContainer(),
151 displacementInternalData->getDContainer());
152 swapBuffers(pressure->getDContainer(),
153 pressureInternalData->getDContainer());
154 }
155
156 FDElasticityRelaxation::FDElasticityRelaxation():
157 ElasticityCommonA(),
158 pressure(),
159 pressureInternalData()
160 {
161 }
162
163 FDElasticityRelaxation::~FDElasticityRelaxation()
164 {
165 }
166
167 FDElasticityRelaxation::FDElasticityRelaxation(Data d,
168 Param bM,
169 Param sM,
170 Param dt,
171 const VectorTemplate* vT):
172 ElasticityCommonA(d,bM,sM,vT),
173 pressure(),
174 pressureInternalData(),
175 deltat(dt)
176 {
177 }
178
179
180 void FDElasticityRelaxation::init(){
181 unsigned int nD(displacementData->getDContainer().size());
182 displacementInternalData = clone(displacementData);
183 pressure = clone(displacementData, 1u);
184 pressureInternalData = clone(pressure);
185 acl::initData(displacementInternalData->getDContainer(),
186 displacementData->getEContainer());
187 asl::initData(pressure, 0.);
188 asl::initData(pressureInternalData, 0.);
189
190 acl::TypeID type(getElementType(displacementData->getDContainer()));
191
192 acl::VectorOfElements dnew(acl::generateVEPrivateVariable(3,type));
193 acl::VectorOfElements pnew(acl::generateVEPrivateVariable(1,type));
194 acl::VectorOfElements coef1(acl::generateVEPrivateVariable(1,type));
195 acl::VectorOfElements coef2(acl::generateVEPrivateVariable(1,type));
196
197 static const double w(.5);
198 acl::VectorOfElements wC(acl::generateVEConstant(w));
199 acl::VectorOfElements wm1C(acl::generateVEConstant(1.-w));
200 (*kernel)<<(coef1=deltat*deltat*shearModulus);
201 (*kernel)<<(coef2=(deltat*deltat)*(bulkModulus+shearModulus/3.));
202
203 TemplateVE du;
204 du.init(*pressure,*vectorTemplate);
205 (*kernel)<< du.initValues << (pnew=du.getValue(0)*wm1C);
206 if(dumpingFactor.size()==0)
207 (*kernel)<<(dnew=2. * displacementData->getSubContainer()
208 - displacementInternalData->getSubContainer());
209 else
210 (*kernel)<<(dnew=(1.+dumpingFactor) * displacementData->getSubContainer()
211 -dumpingFactor*displacementInternalData->getSubContainer());
212 // (*kernel)<<(dnew+=.2* gradient(du)); //!!! should be -
213
214 auto lap(acl::generateVEPrivateVariable(nD,type));
215
216 for (unsigned int i(0); i<nD; ++i)
217 {
218 du.init(*displacementData,*vectorTemplate,i);
219 (*kernel)<< du.initValues << (subVE(lap,i) = laplas(du));
220 (*kernel)<< (pnew -= coef2*subVE(gradient(du),i)*wC);
221 (*kernel)<< (subVE(dnew,i) += coef1 * subVE(lap,i));
222 for (unsigned int k(0); k<nD; ++k)
223 (*kernel)<<(subVE(dnew,k) += coef2 * dIdJ(k,i,du)); //!!!should be commentent
224 kernel->addExpression(acl::elementOperators::barrier());
225 }
226
227 if(force.size()>0)
228 (*kernel)<<(dnew+= force);
229
230 (*kernel)<<(assignmentSafe (displacementInternalData->getSubContainer(),dnew));
231 (*kernel)<<(assignmentSafe (pressureInternalData->getSubContainer(),pnew));
232
233 kernel->setup();
234 }
235
236
237 void FDElasticityRelaxation::execute()
238 {
239 kernel->compute();
240 swapBuffers(displacementData->getDContainer(),
241 displacementInternalData->getDContainer());
242 swapBuffers(pressure->getDContainer(),
243 pressureInternalData->getDContainer());
244 }
245
246 void FDElasticityRelaxation::setDumpingFactor(FDElasticity2::Param dumpF)
247 {
248 acl::copy(dumpF,dumpingFactor);
249 }
250
251
252 FDElasticity2::FDElasticity2():
253 ElasticityCommonA()
254 // velocityData(),
255 {
256 }
257
258 FDElasticity2::FDElasticity2(Data d, Param bM,
259 Param sM, Param dt,
260 const VectorTemplate* vT):
261 ElasticityCommonA(d,bM,sM,vT),
262 deltat(dt)
263 {
264 }
265
266 FDElasticity2::~FDElasticity2()
267 {
268 }
269
270 void FDElasticity2::init()
271 {
272 unsigned int nD(displacementData->getDContainer().size());
273 displacementInternalData=clone(displacementData);
274 acl::initData(displacementInternalData->getDContainer(),
275 displacementData->getEContainer());
276
277 acl::TypeID type(getElementType(displacementData->getDContainer()));
278
279 acl::VectorOfElements dnew(acl::generateVEPrivateVariable(3,type));
280 acl::VectorOfElements coef1(acl::generateVEPrivateVariable(1,type));
281 acl::VectorOfElements coef2(acl::generateVEPrivateVariable(1,type));
282 (*kernel)<<(coef1=deltat*deltat*shearModulus);
283 (*kernel)<<(coef2=(deltat*deltat)*(bulkModulus+shearModulus/3.));
284 if(dumpingFactor.size()==0)
285 (*kernel)<<(dnew=2. * displacementData->getSubContainer()
286 - displacementInternalData->getSubContainer());
287 else
288 (*kernel)<<(dnew=(1.+dumpingFactor) * displacementData->getSubContainer()
289 -dumpingFactor*displacementInternalData->getSubContainer()
290 );
291
292 TemplateVE du;
293 auto lap(acl::generateVEPrivateVariable(nD,type));
294
295 for (unsigned int i(0); i<nD; ++i)
296 {
297 du.init(*displacementData,*vectorTemplate,i);
298 (*kernel)<< du.initValues << (subVE(lap,i) = laplas(du));
299 (*kernel)<< (subVE(dnew,i) += coef1 * subVE(lap,i));
300 for (unsigned int k(0); k<nD; ++k)
301 (*kernel)<<(subVE(dnew,k) += coef2 * dIdJ(k,i,du));
302 // kernel->addExpression(acl::elementOperators::barrier());
303 }
304
305 if(force.size()>0)
306 (*kernel)<<(dnew+= deltat * deltat * force);
307
308 (*kernel)<<(assignmentSafe (displacementInternalData->getSubContainer(),dnew));
309
310 kernel->setup();
311 }
312
313
314 void FDElasticity2::execute()
315 {
316 kernel->compute();
317 swapBuffers(displacementData->getDContainer(),displacementInternalData->getDContainer());
318 }
319
320 void FDElasticity2::setDumpingFactor(FDElasticity2::Param dumpF)
321 {
322 acl::copy(dumpF,dumpingFactor);
323 }
324
325 SPFDElasticity2 generateFDElasticity(SPDataWithGhostNodesACLData d,
326 double bM,
327 double sM,
328 double dt,
329 const VectorTemplate* vT)
330 {
331 auto nm(make_shared<FDElasticity2> (d,
332 acl::generateVEConstant(bM),
333 acl::generateVEConstant(sM),
334 acl::generateVEConstant(dt),
335 vT));
336 return nm;
337 }
338
339 SPFDElasticityIncompressibleStatic generateFDElasticityStatic(SPDataWithGhostNodesACLData d,
340 double bM,
341 double sM,
342 const VectorTemplate* vT)
343 {
344 auto nm(make_shared<FDElasticityIncompressibleStatic> (d,
345 acl::generateVEConstant(bM),
346 acl::generateVEConstant(sM),
347 vT));
348 return nm;
349 }
350
351 SPFDElasticityRelaxation generateFDElasticityRelax(SPDataWithGhostNodesACLData d,
352 double bM,
353 double sM,
354 double dt,
355 const VectorTemplate* vT)
356 {
357 auto nm(make_shared<FDElasticityRelaxation> (d,
358 acl::generateVEConstant(bM),
359 acl::generateVEConstant(sM),
360 acl::generateVEConstant(dt),
361 vT));
362 return nm;
363 }
364
365 } //asl