| 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 "aslLSNormalGrowth.h" |
| 25 |
#include <math/aslTemplates.h> |
| 26 |
#include <data/aslDataWithGhostNodes.h> |
| 27 |
#include "acl/acl.h" |
| 28 |
#include "acl/Kernels/aclKernel.h" |
| 29 |
#include "acl/Kernels/aclKernelConfigurationTemplates.h" |
| 30 |
#include "acl/Kernels/aclKernelMerger.h" |
| 31 |
#include "acl/aclHardware.h" |
| 32 |
#include "acl/aclGenerators.h" |
| 33 |
#include "acl/aclMath/aclVectorOfElements.h" |
| 34 |
#include "acl/aclMath/aclBarycentric.h" |
| 35 |
#include <algorithm> |
| 36 |
#include <math/aslTemplates.h> |
| 37 |
#include <math/aslTemplateVE.h> |
| 38 |
#include <math/aslTemplatesExtras.h> |
| 39 |
#include <math/aslTemplateVEExtras.h> |
| 40 |
#include <math/aslDistanceFunction.h> |
| 41 |
|
| 42 |
|
| 43 |
namespace asl |
| 44 |
{ |
| 45 |
using acl::generateVEConstant; |
| 46 |
using acl::generateVEConstantN; |
| 47 |
|
| 48 |
LSNormalGrowth::~LSNormalGrowth() |
| 49 |
{} |
| 50 |
|
| 51 |
LSNormalGrowth::LSNormalGrowth() |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
LSNormalGrowth::LSNormalGrowth(Data df, DataGen c): |
| 56 |
LevelSetLinear(df), |
| 57 |
superSaturation(c) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
inline bool isIn(int i, AVec<int> a) |
| 62 |
{ |
| 63 |
bool b(false); |
| 64 |
for(unsigned int j(0); j < a.getSize(); ++j ) |
| 65 |
b|=(a[j]==i); |
| 66 |
return b; |
| 67 |
} |
| 68 |
|
| 69 |
void LSNormalGrowth::initVelocityComputation() |
| 70 |
{ |
| 71 |
auto & kk(*kernel); |
| 72 |
acl::TypeID type(getElementType(distanceField->getEContainer())); |
| 73 |
unsigned int nd(nD(*vectorTemplate)); |
| 74 |
unsigned int nv(vectorTemplate->vectors.size()); |
| 75 |
auto vto(distanceTVE->vto); |
| 76 |
unsigned int nCells(vto->elementaryCells.size()); |
| 77 |
|
| 78 |
|
| 79 |
TemplateVE sSatT(*superSaturation, *vectorTemplate); |
| 80 |
kk << sSatT.initValues; |
| 81 |
|
| 82 |
lVelocities.resize(nv); |
| 83 |
|
| 84 |
auto isBoundary(generateVEPrivateVariable(1,acl::TYPE_SELECT[type])); |
| 85 |
auto normal(generateVEPrivateVariable(nd,type)); |
| 86 |
// auto invlen(generateVEPrivateVariable(1,type)); |
| 87 |
auto counter(generateVEPrivateVariable(1, type)); |
| 88 |
|
| 89 |
kk << (counter = generateVEConstant(0.)); |
| 90 |
|
| 91 |
for(unsigned int i(0); i < nv; ++i) |
| 92 |
{ |
| 93 |
copy(generateVEPrivateVariable(nd,type), lVelocities[i]); |
| 94 |
kk << (lVelocities[i] = generateVEConstantN(nd,0.)); |
| 95 |
} |
| 96 |
|
| 97 |
/* vector<acl::VectorOfElements> normalC; |
| 98 |
kk << gcGradientAllCells(*distanceTVE, normalC); |
| 99 |
for(unsigned int j(0); j < nCells; ++j) |
| 100 |
kk << gcNormalize(normalC[j]); |
| 101 |
|
| 102 |
for(unsigned int i(1); i < nv; ++i) |
| 103 |
{ |
| 104 |
kk << (normal = generateVEConstantN(nd,0.)); |
| 105 |
for(unsigned int j(0); j < nCells; ++j) |
| 106 |
if(isIn(i, vto->elementaryCells[j])) |
| 107 |
kk << (normal += normalC[j]); |
| 108 |
kk << gcNormalize(normal); |
| 109 |
|
| 110 |
kk << (isBoundary = isBoundaryDir(i)); |
| 111 |
|
| 112 |
kk << (lVelocities[i] = select(generateVEConstantN(nd,0.), |
| 113 |
normal * getValueOnBoundary(sSatT.values, i), |
| 114 |
isBoundary, |
| 115 |
type)); |
| 116 |
kk << (counter += select(generateVEConstant(0.), |
| 117 |
generateVEConstant(1.), |
| 118 |
isBoundary, |
| 119 |
type)); |
| 120 |
kk << (lVelocities[0] += lVelocities[i]); |
| 121 |
} |
| 122 |
kk << (counter = max(counter, generateVEConstant(1.), type)); |
| 123 |
kk << (lVelocities[0] = lVelocities[0] / counter);*/ |
| 124 |
} |
| 125 |
|
| 126 |
} // asl |
| 127 |
|