| 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 "aslCrystalGrowthBC.h" |
| 25 |
#include "acl/aclMath/aclVectorOfElements.h" |
| 26 |
#include "acl/acl.h" |
| 27 |
#include "acl/aclHardware.h" |
| 28 |
#include "acl/aclGenerators.h" |
| 29 |
#include <acl/Kernels/aclKernel.h> |
| 30 |
#include "acl/Kernels/aclKernelConfigurationTemplates.h" |
| 31 |
#include <aslGenerators.h> |
| 32 |
#include <math/aslTemplateVE.h> |
| 33 |
#include "acl/aclMath/aclMathAlg.h" |
| 34 |
#include <math/aslIndex2Position.h> |
| 35 |
#include <math/aslPositionFunction.h> |
| 36 |
#include <math/aslDistanceFunctionAlg.h> |
| 37 |
|
| 38 |
namespace asl |
| 39 |
{ |
| 40 |
|
| 41 |
BCLinearGrowthMap::BCLinearGrowthMap(Data d, |
| 42 |
const acl::VectorOfElements & ceq, |
| 43 |
const acl::VectorOfElements & b, |
| 44 |
Data map, |
| 45 |
const VectorTemplate *const t): |
| 46 |
BCondWithMap(map, t), |
| 47 |
kernel(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 48 |
data(d), |
| 49 |
cEq(ceq), |
| 50 |
beta(b) |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
BCLinearGrowthMap::BCLinearGrowthMap(Data d, |
| 55 |
const acl::VectorOfElements & ceq, |
| 56 |
const acl::VectorOfElements & b, |
| 57 |
Data map, |
| 58 |
Data computationalDomain, |
| 59 |
const VectorTemplate *const t): |
| 60 |
BCondWithMap(map, computationalDomain, t), |
| 61 |
kernel(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 62 |
data(d), |
| 63 |
cEq(ceq), |
| 64 |
beta(b) |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
BCLinearGrowthMap::~BCLinearGrowthMap() |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
void BCLinearGrowthMap::init() |
| 73 |
{ |
| 74 |
acl::ExpressionContainer kk; |
| 75 |
|
| 76 |
unsigned int nd(nD(data->getBlock())); |
| 77 |
unsigned int nc(data->getEContainer().size()); |
| 78 |
|
| 79 |
auto dataX(generateDCFullSafe(data)); |
| 80 |
|
| 81 |
initMapInfrastructure(kk); |
| 82 |
|
| 83 |
acl::TypeID type(getElementType(data->getEContainer())); |
| 84 |
|
| 85 |
vector<TemplateVE> dataTVE(nc); |
| 86 |
for(unsigned int ii(0); ii < nc; ++ii) |
| 87 |
{ |
| 88 |
dataTVE[ii].init(*dataX, *templ, ii); |
| 89 |
kk << dataTVE[ii].initValues; |
| 90 |
} |
| 91 |
|
| 92 |
auto normal(generateVEPrivateVariable(nd,type)); |
| 93 |
auto vLocal(generateVEPrivateVariable(nc,type)); |
| 94 |
auto counter(generateVEPrivateVariable(1,type)); |
| 95 |
auto dirCoef(generateVEPrivateVariable(1,type)); |
| 96 |
|
| 97 |
unsigned int nDir(templ->vectors.size()); |
| 98 |
|
| 99 |
kk << (vLocal = acl::generateVEConstantN(nc,0.)); |
| 100 |
kk << (counter = acl::generateVEConstant(0.)); |
| 101 |
kk << (normal = gradient(*mapTVE)); |
| 102 |
kk << (gcNormalize(normal)); |
| 103 |
for(unsigned int i(1); i < nDir; ++i) |
| 104 |
{ |
| 105 |
kk << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.); |
| 106 |
kk << (dirCoef *= dirCoef ); |
| 107 |
auto xx(exBoundaryX(*mapTVE,i)); |
| 108 |
for(unsigned int ii(0); ii < nc; ++ii) |
| 109 |
{ |
| 110 |
auto vBulk(subVE(dataTVE[ii].values,i)); |
| 111 |
auto anv(subVE(beta,ii)*(normal * templ->vectors[i])); |
| 112 |
auto c(subVE(cEq,ii)); |
| 113 |
kk << (subVE(vLocal,ii) += select(acl::generateVEConstant(0.), |
| 114 |
(vBulk * (1.+ anv * xx) - anv*c) / |
| 115 |
(1. - anv*(1. - xx)), |
| 116 |
isComputationNode(i), |
| 117 |
type) * dirCoef); |
| 118 |
} |
| 119 |
kk << (counter+= select(acl::generateVEConstant( 0.), |
| 120 |
dirCoef, |
| 121 |
isComputationNode(i), |
| 122 |
type)); |
| 123 |
} |
| 124 |
kk << (vLocal /= max(counter,acl::generateVEConstant(.01))); |
| 125 |
for(unsigned int ii(0); ii < nc; ++ii) |
| 126 |
{ |
| 127 |
kk << (acl::assignmentSafe(subVE(data->getEContainer(),ii), |
| 128 |
select(subVE(dataTVE[ii].values,0), |
| 129 |
subVE(vLocal,ii), |
| 130 |
isGhostNode(0), |
| 131 |
type))); |
| 132 |
} |
| 133 |
kernel->addExpression(acl::elementOperators:: |
| 134 |
ifElse(acl::elementOperators::any((map->getEContainer() <= 0 && |
| 135 |
map->getEContainer() > -.9999)[0]), |
| 136 |
kk.expression, |
| 137 |
{} )); |
| 138 |
|
| 139 |
kernel->setup(); |
| 140 |
} |
| 141 |
|
| 142 |
void BCLinearGrowthMap::execute() |
| 143 |
{ |
| 144 |
kernel->compute(); |
| 145 |
} |
| 146 |
|
| 147 |
BCLinearGrowthMap1::BCLinearGrowthMap1(Data d, |
| 148 |
const acl::VectorOfElements & ceq, |
| 149 |
const acl::VectorOfElements & b, |
| 150 |
Data map, |
| 151 |
const VectorTemplate *const t): |
| 152 |
BCondWithMap(map, t), |
| 153 |
// kernel(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 154 |
kernel(new acl::Kernel(acl::KERNEL_BASIC)), |
| 155 |
data(d), |
| 156 |
cEq(ceq), |
| 157 |
beta(b) |
| 158 |
{ |
| 159 |
} |
| 160 |
|
| 161 |
BCLinearGrowthMap1::BCLinearGrowthMap1(Data d, |
| 162 |
const acl::VectorOfElements & ceq, |
| 163 |
const acl::VectorOfElements & b, |
| 164 |
Data map, |
| 165 |
Data computationalDomain, |
| 166 |
const VectorTemplate *const t): |
| 167 |
BCondWithMap(map, computationalDomain, t), |
| 168 |
// kernel(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 169 |
kernel(new acl::Kernel(acl::KERNEL_BASIC)), |
| 170 |
data(d), |
| 171 |
cEq(ceq), |
| 172 |
beta(b) |
| 173 |
{ |
| 174 |
} |
| 175 |
|
| 176 |
BCLinearGrowthMap1::~BCLinearGrowthMap1() |
| 177 |
{ |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
void BCLinearGrowthMap1::init() |
| 182 |
{ |
| 183 |
acl::ExpressionContainer kk; |
| 184 |
|
| 185 |
unsigned int nd(nD(data->getBlock())); //< number of dimmentions |
| 186 |
unsigned int nc(data->getEContainer().size()); // number of components |
| 187 |
|
| 188 |
auto dataX(generateDCFullSafe(data)); |
| 189 |
|
| 190 |
initMapInfrastructure(kk); |
| 191 |
|
| 192 |
acl::TypeID type(getElementType(data->getEContainer())); |
| 193 |
acl::TypeID typeI(acl::TYPE_SELECT[type]); |
| 194 |
|
| 195 |
TemplateVE dataTVE(*dataX, *templ); |
| 196 |
kk << dataTVE.initValues; |
| 197 |
|
| 198 |
auto normal(generateVEPrivateVariable(nd,type)); |
| 199 |
auto area(generateVEPrivateVariable(1,type)); |
| 200 |
auto sw(generateVEPrivateVariable(1,type)); |
| 201 |
auto swc(generateVEPrivateVariable(1,type)); |
| 202 |
auto sna(generateVEPrivateVariable(1,type)); |
| 203 |
auto sna1mx(generateVEPrivateVariable(1,type)); |
| 204 |
auto snaxc(generateVEPrivateVariable(nc,type)); |
| 205 |
auto isBoundary(generateVEPrivateVariable(1,typeI)); |
| 206 |
|
| 207 |
unsigned int nDir(templ->vectors.size()); |
| 208 |
|
| 209 |
kk << (sw = acl::generateVEConstant(0.)); |
| 210 |
kk << (swc = acl::generateVEConstant(0.)); |
| 211 |
kk << (sna = acl::generateVEConstant(0.)); |
| 212 |
kk << (sna1mx = acl::generateVEConstant(0.)); |
| 213 |
kk << (snaxc = acl::generateVEConstant(0.)); |
| 214 |
kk << (normal = gradient(*mapTVE)); |
| 215 |
kk << (gcNormalize(normal)); |
| 216 |
kk << gcBoundaryAreaPerGhostPoint(*mapTVE, area); |
| 217 |
|
| 218 |
for(unsigned int i(1); i < nDir; ++i) |
| 219 |
{ |
| 220 |
kk << (isBoundary = isComputationNode(i)); |
| 221 |
kk << (sw += select(acl::generateVEConstant(templ->laplasCoefs[i]), |
| 222 |
isBoundary,type)); |
| 223 |
kk << (swc += select(dataTVE.getValue(i) * templ->laplasCoefs[i], |
| 224 |
isBoundary,type)); |
| 225 |
auto a(normalize(templ->vectors[i])); |
| 226 |
kk << (sna += select(normal * a, |
| 227 |
isBoundary,type)); |
| 228 |
kk << (sna1mx += select((normal * a)*(1.-exBoundaryX(*mapTVE,i)), |
| 229 |
isBoundary,type)); |
| 230 |
kk << (snaxc += select((normal * a)*exBoundaryX(*mapTVE,i)*dataTVE.getValue(i), |
| 231 |
isBoundary,type)); |
| 232 |
|
| 233 |
} |
| 234 |
auto vLocal((swc*sna-area*beta*snaxc+area*beta*cEq*sna)/(area*beta*sna1mx+sw*sna)); |
| 235 |
kk << (acl::assignmentSafe(data->getEContainer(), |
| 236 |
select(dataTVE.getValue(0), vLocal, isGhostNode(0), type))); |
| 237 |
|
| 238 |
kernel->addExpression(acl::elementOperators:: |
| 239 |
ifElse(acl::elementOperators::any((isGhostNode() && |
| 240 |
map->getEContainer() > -.9999)[0]), |
| 241 |
kk.expression, |
| 242 |
{} )); |
| 243 |
|
| 244 |
kernel->setup(); |
| 245 |
} |
| 246 |
|
| 247 |
void BCLinearGrowthMap1::execute() |
| 248 |
{ |
| 249 |
kernel->compute(); |
| 250 |
} |
| 251 |
|
| 252 |
BCLinearGrowthMap2::BCLinearGrowthMap2(Data d, |
| 253 |
const acl::VectorOfElements & ceq, |
| 254 |
const acl::VectorOfElements & b, |
| 255 |
Data map, |
| 256 |
const VectorTemplate *const t): |
| 257 |
BCondWithMap(map, t), |
| 258 |
// kernelCN(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 259 |
// kernelGN(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 260 |
kernelCN(new acl::Kernel(acl::KERNEL_BASIC)), |
| 261 |
kernelGN(new acl::Kernel(acl::KERNEL_BASIC)), |
| 262 |
data(d), |
| 263 |
cEq(ceq), |
| 264 |
beta(b) |
| 265 |
{ |
| 266 |
} |
| 267 |
|
| 268 |
BCLinearGrowthMap2::BCLinearGrowthMap2(Data d, |
| 269 |
const acl::VectorOfElements & ceq, |
| 270 |
const acl::VectorOfElements & b, |
| 271 |
Data map, |
| 272 |
Data computationalDomain, |
| 273 |
const VectorTemplate *const t): |
| 274 |
BCondWithMap(map, computationalDomain, t), |
| 275 |
// kernelCN(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 276 |
// kernelGN(new acl::Kernel(acl::KERNEL_SIMDUA)), |
| 277 |
kernelCN(new acl::Kernel(acl::KERNEL_BASIC)), |
| 278 |
kernelGN(new acl::Kernel(acl::KERNEL_BASIC)), |
| 279 |
data(d), |
| 280 |
cEq(ceq), |
| 281 |
beta(b) |
| 282 |
{ |
| 283 |
} |
| 284 |
|
| 285 |
BCLinearGrowthMap2::~BCLinearGrowthMap2() |
| 286 |
{ |
| 287 |
} |
| 288 |
|
| 289 |
void BCLinearGrowthMap2::init() |
| 290 |
{ |
| 291 |
unsigned int nd(nD(data->getBlock())); |
| 292 |
unsigned int nc(data->getEContainer().size()); |
| 293 |
unsigned int nDir(templ->vectors.size()); |
| 294 |
acl::TypeID type(getElementType(data->getEContainer())); |
| 295 |
|
| 296 |
auto normal(generateVEPrivateVariable(nd,type)); |
| 297 |
auto vLocal(generateVEPrivateVariable(nc,type)); |
| 298 |
auto counter(generateVEPrivateVariable(1,type)); |
| 299 |
auto dirCoef(generateVEPrivateVariable(1,type)); |
| 300 |
auto xx(generateVEPrivateVariable(1,type)); |
| 301 |
|
| 302 |
auto dataX(generateDCFullSafe(data)); |
| 303 |
TemplateVE dataTVE; |
| 304 |
|
| 305 |
|
| 306 |
acl::ExpressionContainer kkCN; |
| 307 |
initMapInfrastructure(kkCN); |
| 308 |
|
| 309 |
kkCN << (vLocal = acl::generateVEConstantN(nc,0.)); |
| 310 |
kkCN << (counter = acl::generateVEConstant(0.)); |
| 311 |
kkCN << (normal = gradient(*mapTVE)); |
| 312 |
kkCN << (gcNormalize(normal)); |
| 313 |
kkCN << (xx = acl::generateVEConstant(0.)); |
| 314 |
for(unsigned int i(1); i < nDir; ++i) |
| 315 |
{ |
| 316 |
kkCN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.); |
| 317 |
kkCN << (dirCoef *= dirCoef ); |
| 318 |
kkCN << (counter+= select(dirCoef, isGhostNode(templ->invertVectors[i]), type)); |
| 319 |
kkCN << (xx+= select(dirCoef * exBoundaryX(*mapTVE,templ->invertVectors[i]), |
| 320 |
isGhostNode(templ->invertVectors[i]), type)); |
| 321 |
} |
| 322 |
kkCN << (xx=select(acl::generateVEConstant(1.),xx/counter,counter>0.001,type)); |
| 323 |
kkCN << (counter = max(counter,acl::generateVEConstant(.001), type)); |
| 324 |
|
| 325 |
for(unsigned int ii(0); ii < nc; ++ii) |
| 326 |
{ |
| 327 |
dataTVE.init(*dataX, *templ, ii,false); |
| 328 |
kkCN << (vLocal = acl::generateVEConstant(0.)); |
| 329 |
for(unsigned int i(1); i < nDir; ++i) |
| 330 |
{ |
| 331 |
kkCN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.); |
| 332 |
kkCN << (dirCoef *= dirCoef); |
| 333 |
auto anv(subVE(beta,ii)*(-normal * templ->vectors[i])); |
| 334 |
kkCN << (vLocal += select((dataTVE.getValue(i)*(1.+anv*xx) + anv*subVE(cEq,ii)) / |
| 335 |
(1.+ anv*(1.+xx)) * dirCoef, |
| 336 |
isGhostNode(templ->invertVectors[i]), |
| 337 |
type)); |
| 338 |
} |
| 339 |
kkCN << (acl::assignmentSafe(subVE(data->getEContainer(),ii), |
| 340 |
select(subVE(dataTVE.values,0), |
| 341 |
xx*dataTVE.getValue(0) + (1.-xx)*vLocal/counter, |
| 342 |
isComputationNode(0), |
| 343 |
type))); |
| 344 |
} |
| 345 |
kernelCN->addExpression(acl::elementOperators:: |
| 346 |
ifElse(acl::elementOperators::any((isGhostNode() && |
| 347 |
map->getEContainer() > -.9999)[0]), |
| 348 |
kkCN.expression, |
| 349 |
{} )); |
| 350 |
|
| 351 |
kernelCN->setup(); |
| 352 |
|
| 353 |
acl::ExpressionContainer kkGN; |
| 354 |
initMapInfrastructure(kkGN); |
| 355 |
|
| 356 |
kkGN << (vLocal = acl::generateVEConstantN(nc,0.)); |
| 357 |
kkGN << (counter = acl::generateVEConstant(0.)); |
| 358 |
kkGN << (normal = gradient(*mapTVE)); |
| 359 |
kkGN << (gcNormalize(normal)); |
| 360 |
kkGN << (xx = acl::generateVEConstant(0.)); |
| 361 |
for(unsigned int i(1); i < nDir; ++i) |
| 362 |
{ |
| 363 |
kkGN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.); |
| 364 |
kkGN << (dirCoef *= dirCoef ); |
| 365 |
kkGN << (counter+= select(dirCoef, isComputationNode(i), type)); |
| 366 |
kkGN << (xx+= select(dirCoef * exBoundaryX(*mapTVE,i), |
| 367 |
isComputationNode(i), type)); |
| 368 |
} |
| 369 |
kkGN << (xx=select(acl::generateVEConstant(1.),xx/counter,counter>0.001,type)); |
| 370 |
kkGN << (counter = max(counter,acl::generateVEConstant(.001), type)); |
| 371 |
|
| 372 |
for(unsigned int ii(0); ii < nc; ++ii) |
| 373 |
{ |
| 374 |
dataTVE.init(*dataX, *templ, ii,false); |
| 375 |
kkGN << (vLocal = acl::generateVEConstant(0.)); |
| 376 |
for(unsigned int i(1); i < nDir; ++i) |
| 377 |
{ |
| 378 |
kkGN << (dirCoef = (normal * normalize(templ->vectors[i])) + 1.); |
| 379 |
kkGN << (dirCoef *= dirCoef ); |
| 380 |
auto anv(subVE(beta,ii)*(-normal * templ->vectors[i])); |
| 381 |
kkGN << (vLocal += select((dataTVE.getValue(i)*(1.-anv*xx) + anv*subVE(cEq,ii)) / |
| 382 |
(1.+ anv*(1.-xx)) * dirCoef, |
| 383 |
isComputationNode(i), |
| 384 |
type)); |
| 385 |
} |
| 386 |
kkGN << (acl::assignmentSafe(subVE(data->getEContainer(),ii), |
| 387 |
select(subVE(dataTVE.values,0), |
| 388 |
vLocal/counter, |
| 389 |
isGhostNode(0), |
| 390 |
type))); |
| 391 |
} |
| 392 |
kernelGN->addExpression(acl::elementOperators:: |
| 393 |
ifElse(acl::elementOperators::any((isGhostNode() && |
| 394 |
map->getEContainer() > -.9999)[0]), |
| 395 |
kkGN.expression, |
| 396 |
{} )); |
| 397 |
|
| 398 |
kernelGN->setup(); |
| 399 |
} |
| 400 |
|
| 401 |
void BCLinearGrowthMap2::execute() |
| 402 |
{ |
| 403 |
kernelCN->compute(); |
| 404 |
kernelGN->compute(); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
SPNumMethod generateBCLinearGrowth(SPAbstractDataWithGhostNodes d, |
| 409 |
double cEq, |
| 410 |
double beta, |
| 411 |
SPAbstractDataWithGhostNodes map, |
| 412 |
const VectorTemplate *const t) |
| 413 |
{ |
| 414 |
return make_shared<BCLinearGrowthMap> |
| 415 |
(d, |
| 416 |
acl::generateVEConstant(cEq), |
| 417 |
acl::generateVEConstant(beta), |
| 418 |
map, |
| 419 |
t); |
| 420 |
} |
| 421 |
|
| 422 |
SPNumMethod generateBCLinearGrowth(SPAbstractDataWithGhostNodes d, |
| 423 |
double cEq, |
| 424 |
double beta, |
| 425 |
SPAbstractDataWithGhostNodes map, |
| 426 |
SPAbstractDataWithGhostNodes computationalDomain, |
| 427 |
const VectorTemplate *const t) |
| 428 |
{ |
| 429 |
return make_shared<BCLinearGrowthMap1> |
| 430 |
(d, |
| 431 |
acl::generateVEConstant(cEq), |
| 432 |
acl::generateVEConstant(beta), |
| 433 |
map, |
| 434 |
computationalDomain, |
| 435 |
t); |
| 436 |
} |
| 437 |
|
| 438 |
SPNumMethod generateBCLinearGrowth2(SPAbstractDataWithGhostNodes d, |
| 439 |
double cEq, |
| 440 |
double beta, |
| 441 |
SPAbstractDataWithGhostNodes map, |
| 442 |
const VectorTemplate *const t) |
| 443 |
{ |
| 444 |
return make_shared<BCLinearGrowthMap2> |
| 445 |
(d, |
| 446 |
acl::generateVEConstant(cEq), |
| 447 |
acl::generateVEConstant(beta), |
| 448 |
map, |
| 449 |
t); |
| 450 |
} |
| 451 |
|
| 452 |
SPNumMethod generateBCLinearGrowth2(SPAbstractDataWithGhostNodes d, |
| 453 |
double cEq, |
| 454 |
double beta, |
| 455 |
SPAbstractDataWithGhostNodes map, |
| 456 |
SPAbstractDataWithGhostNodes computationalDomain, |
| 457 |
const VectorTemplate *const t) |
| 458 |
{ |
| 459 |
return make_shared<BCLinearGrowthMap2> |
| 460 |
(d, |
| 461 |
acl::generateVEConstant(cEq), |
| 462 |
acl::generateVEConstant(beta), |
| 463 |
map, |
| 464 |
computationalDomain, |
| 465 |
t); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
} // asl |
| 470 |
|