Debian Codegraph @

src/num/aslLSFacetedGrowth.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 "aslLSFacetedGrowth.h"
25 #include <math/aslTemplates.h>
26 #include <data/aslDataWithGhostNodes.h>
27 #include "acl/acl.h"
28 #include "acl/aclHardware.h"
29 #include "acl/Kernels/aclKernel.h"
30 #include "acl/Kernels/aclKernelConfigurationTemplates.h"
31 #include "acl/Kernels/aclKernelMerger.h"
32 #include "acl/aclGenerators.h"
33 #include "acl/aclMath/aclVectorOfElements.h"
34 #include "acl/aclMath/aclBarycentric.h"
35 #include "acl/aclMath/aclMathAlg.h"
36 #include <algorithm>
37 #include <math/aslTemplates.h>
38 #include <math/aslTemplateVE.h>
39 #include <math/aslTemplatesExtras.h>
40 #include <math/aslTemplateVEExtras.h>
41 #include <math/aslDistanceFunction.h>
42
43 #include <writers/aslWriter.h>
44
45 namespace asl
46 {
47
48 using acl::VectorOfElements;
49 using acl::generateVEConstant;
50 using acl::generateVEConstantN;
51
52 inline bool isIn(int i, AVec<int> a)
53 {
54 bool b(false);
55 for(unsigned int j(0); j < a.getSize(); ++j )
56 b|=(a[j]==i);
57 return b;
58 }
59
60 CrystallographicParameters::CrystallographicParameters (const vector<AVec<>> & dir,
61 const vector<double> & bSt,
62 const vector<double> & bDisl,
63 const double bRough):
64 directions(dir),
65 betaSt(bSt),
66 betaDisl(bDisl),
67 betaRough(bRough)
68 {
69 }
70
71 CrystallographicParameters::CrystallographicParameters (const double bRough):
72 betaRough(bRough)
73 {
74 }
75
76 CrystallographicParameters::CrystallographicParameters (){}
77
78
79 void CrystallographicParameters::directionCode(VectorOfElements normal,
80 VectorOfElements direction,
81 VectorOfElements cosTheta,
82 acl::ExpressionContainer & k)
83 {
84 findNearestDirectionCode(directions, normal, direction, cosTheta, k);
85 }
86
87 void CrystallographicParameters::addFacet(const AVec<> normal, double bSt, double bDisl)
88 {
89 directions.push_back(normal);
90 betaSt.push_back(bSt);
91 betaDisl.push_back(bDisl);
92 }
93
94
95 void CrystallographicParameters::init(acl::TypeID type)
96 {
97 copy(acl::generateVEPrivateArray(directions, type), directionsACL);
98 copy(acl::generateVEPrivateArray(betaSt, type), betaStACL);
99 copy(acl::generateVEPrivateArray(betaDisl, type), betaDislACL);
100 }
101
102 acl::VectorOfElements
103 CrystallographicParameters::velocity(acl::VectorOfElements supersaturation,
104 acl::VectorOfElements dir,
105 acl::VectorOfElements sinTheta)
106 {
107 acl::TypeID type(getElementType(supersaturation));
108
109 auto bSt(acl::excerpt(betaStACL,dir));
110 auto bDisl(acl::excerpt(betaDislACL,dir));
111 auto bR(generateVEConstant(betaRough));
112 return supersaturation*acl::min(bR,
113 acl::max(sinTheta * bSt,
114 supersaturation*bDisl,
115 type),
116 type);
117 }
118
119 acl::VectorOfElements
120 CrystallographicParameters::velocity(const acl::VectorOfElements & supersaturation,
121 const acl::VectorOfElements & dir,
122 const acl::VectorOfElements & sinTheta,
123 const acl::VectorOfElements & stepVelocityLimit)
124 {
125 acl::TypeID type(getElementType(supersaturation));
126
127 auto vSt(supersaturation*acl::excerpt(betaStACL,dir)*sinTheta);
128 auto vDisl(supersaturation*supersaturation*acl::excerpt(betaDislACL,dir));
129 auto vR(supersaturation*generateVEConstant(betaRough));
130 return acl::min(vR, acl::max(min(vSt, sign(stepVelocityLimit), type), vDisl, type), type);
131 }
132
133
134 VectorOfElements
135 CrystallographicParameters::stepFactor(const VectorOfElements & dir,
136 const VectorOfElements & position)
137 {
138 auto dirVec(acl::excerpt(directionsACL,dir));
139 return dirVec*position;
140 }
141
142
143
144 LSFacetedGrowth::~LSFacetedGrowth()
145 {}
146
147 LSFacetedGrowth::LSFacetedGrowth()
148 {
149 }
150
151 LSFacetedGrowth::LSFacetedGrowth(Data df, DataGen c):
152 LevelSetLinear(df),
153 superSaturation(c)
154 {
155 // this line is necessery since the kernel is initialized in a perent class by KERNEL_SIMDUA
156 kernel.reset(new acl::Kernel(acl::KERNEL_BASIC));
157 }
158
159 void LSFacetedGrowth::initVelocityComputation()
160 {
161 acl::ExpressionContainer kk;
162 // auto & kk(*kernel);
163 acl::TypeID type(getElementType(distanceField->getEContainer()));
164 acl::TypeID typeI(acl::TYPE_SELECT[type]);
165 unsigned int nd(nD(*vectorTemplate));
166 unsigned int nv(vectorTemplate->vectors.size());
167 //number of crystallographyc directions
168 unsigned int ncd(crystallography.directions.size());
169
170 crystallography.init(type);
171
172 TemplateVE sSatT(*superSaturation, *vectorTemplate);
173 kk << sSatT.initValues;
174
175
176 auto isBoundary(generateVEPrivateVariable(1,typeI));
177 auto normal(generateVEPrivateVariable(nd,type));
178 auto velC(generateVEPrivateVariable(1,type));
179 auto counter(generateVEPrivateVariable(1, type));
180 auto sSatNode(generateVEPrivateVariable(1, type));
181
182 auto vto(distanceTVE->vto);
183 unsigned int nCells(vto->elementaryCells.size());
184
185 vector<int> vectorInit(ncd,0);
186 auto directionsN(generateVEPrivateArray(vectorInit,typeI));
187 auto velocitiesN(generateVEPrivateArray(vectorInit,type));
188
189 vector<acl::VectorOfElements> normalC;
190 kk << gcGradientAllCells(*distanceTVE, normalC);
191 vector<acl::VectorOfElements> directionC(nCells);
192 vector<acl::VectorOfElements> thetaC(nCells);
193 vector<acl::VectorOfElements> stepFactorC(nCells);
194 for(unsigned int j(0); j < nCells; ++j)
195 {
196 kk << gcNormalize(normalC[j]);
197 copy(generateVEPrivateVariable(1,typeI), directionC[j]);
198 copy(generateVEPrivateVariable(1,type), thetaC[j]);
199 crystallography.directionCode(normalC[j], directionC[j], thetaC[j], kk);
200 kk << (thetaC[j] = sqrt(fabs(1.- thetaC[j]*thetaC[j])));
201
202 copy(generateVEPrivateVariable(1,type), stepFactorC[j]);
203 kk<< (stepFactorC[j] = crystallography.stepFactor(directionC[j],
204 getBoundaryCenter(j)));
205 }
206
207 kk << (counter = generateVEConstant(0.));
208 lVelocities.resize(nv);
209 copy(generateVEPrivateVariable(nd,type), lVelocities[0]);
210 kk << (lVelocities[0] = generateVEConstantN(nd,0.));
211
212 for(unsigned int i(1); i < nv; ++i)
213 {
214 copy(generateVEPrivateVariable(nd,type), lVelocities[i]);
215 kk << (normal = generateVEConstantN(nd,0.));
216
217 kk << (sSatNode = getValueOnBoundary(sSatT.values, i));
218 for(unsigned int j(0); j < nCells; ++j)
219 if(isIn(i, vto->elementaryCells[j]))
220 {
221 kk << (velC = crystallography.velocity(sSatNode,
222 directionC[j],
223 thetaC[j],
224 stepFactorC[j] -
225 crystallography.stepFactor(directionC[j],
226 getBoundaryPoint(i))));
227 auto velL(excerpt(velocitiesN,directionC[j]));
228 auto dirL(excerpt(directionsN,directionC[j]));
229 kk << (velL = select(velC, max(velL, velC), dirL));
230 kk << (dirL = generateVEConstant(1));
231 }
232 kk << (normalC[0] = generateVEConstantN(nd,0));
233 for(unsigned int j(0); j < ncd; ++j)
234 {
235 auto ind(generateVEConstant(j));
236 kk << (normalC[0] += select(generateVEConstantN(nd,0),
237 generateVEConstant(crystallography.directions[j]),
238 excerpt(directionsN,ind),
239 type));
240 }
241 kk << (thetaC[0] = max(sqrt(l2(normalC[0])),
242 generateVEConstant(0.1),
243 type));
244 kk << (normalC[0] = normalC[0] / thetaC[0]);
245 //.5 is a large value
246 kk << (velC = generateVEConstant(.5));
247 for(unsigned int j(0); j < ncd; ++j)
248 {
249 auto ind(generateVEConstant(j));
250 auto dirVec(generateVEConstant(crystallography.directions[j]));
251 auto velL(excerpt(velocitiesN,ind));
252 auto dirL(excerpt(directionsN,ind));
253 kk << (velC = select(velC,
254 min (velC,
255 velL /*/ max((normalC[0] * dirVec ),
256 generateVEConstant(0.01),
257 type)*/,
258 type),
259 dirL,
260 type));
261 }
262
263 kk << (isBoundary = isBoundaryDir(i));
264
265 kk << (lVelocities[i] = select(acl::generateVEConstantN(nd,0.),
266 normalC[0] * velC ,
267 isBoundary,
268 type));
269 kk << (counter += select(generateVEConstant(0.),
270 generateVEConstant(1.),
271 isBoundary,
272 type));
273 kk << (lVelocities[0] += lVelocities[i]);
274 }
275 kk << (counter = max(counter, generateVEConstant(1.), type));
276 kk << (lVelocities[0] = lVelocities[0] / counter );
277
278 kernel->addExpression(acl::elementOperators::
279 ifElse(acl::differentSign(distanceTVE->values)[0],
280 kk.expression, {} ));
281 Writer::current->addVector("vel", lVelocities[0], *kernel);
282 }
283 } // asl
284