| 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 "aslDFOptimizer.h" |
| 25 |
#include <aslGenerators.h> |
| 26 |
#include <acl/aclGenerators.h> |
| 27 |
#include <acl/acl.h> |
| 28 |
#include "acl/aclHardware.h" |
| 29 |
#include <math/aslTemplateVE.h> |
| 30 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 31 |
|
| 32 |
#include <data/aslDataWithGhostNodes.h> |
| 33 |
#include <acl/Kernels/aclKernel.h> |
| 34 |
#include <math/aslTemplates.h> |
| 35 |
#include <math/aslDistanceFunctionAlg.h> |
| 36 |
|
| 37 |
#include <acl/Kernels/aclKernelConfigurationTemplates.h> |
| 38 |
|
| 39 |
namespace asl |
| 40 |
{ |
| 41 |
DFOptimizer::DFOptimizer(): |
| 42 |
// SingleKernelNM(acl::KERNEL_SIMDUA), |
| 43 |
SingleKernelNM(acl::KERNEL_BASIC), |
| 44 |
vectorTemplate(NULL) |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
DFOptimizer::DFOptimizer(Data inD, const VectorTemplate* vT): |
| 50 |
// SingleKernelNM(acl::KERNEL_SIMDUA), |
| 51 |
SingleKernelNM(acl::KERNEL_BASIC), |
| 52 |
inData(inD), |
| 53 |
vectorTemplate(vT) |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
void DFOptimizer::init0() |
| 58 |
{ |
| 59 |
unsigned int nDir(vectorTemplate->vectors.size()); |
| 60 |
acl::TypeID type(getElementType(inData->getEContainer())); |
| 61 |
acl::TypeID typeI(acl::TYPE_SELECT[type]); |
| 62 |
|
| 63 |
auto dataX(generateDCFullSafe(inData, -.9)); |
| 64 |
|
| 65 |
acl::VectorOfElements vnew(acl::generateVEPrivateVariable(1, type)); |
| 66 |
acl::VectorOfElements isAnyComp(acl::generateVEPrivateVariable(1, typeI)); |
| 67 |
acl::VectorOfElements isAnyGhost(acl::generateVEPrivateVariable(1, typeI)); |
| 68 |
|
| 69 |
TemplateVE dT; |
| 70 |
dT.init(*dataX, *vectorTemplate); |
| 71 |
(*kernel) << dT.initValues; |
| 72 |
(*kernel) << (isAnyComp = acl::generateVEConstant(0)); |
| 73 |
(*kernel) << (isAnyGhost = acl::generateVEConstant(0)); |
| 74 |
for(unsigned int i(1); i < nDir; ++i) |
| 75 |
{ |
| 76 |
(*kernel) << (isAnyComp = isAnyComp || isComputationNode(dT, i)); |
| 77 |
(*kernel) << (isAnyGhost = isAnyGhost || isGhostNode(dT, i)); |
| 78 |
} |
| 79 |
(*kernel) << (vnew = dT.getValue(0)); |
| 80 |
(*kernel) << (vnew = select(vnew, acl::generateVEConstant(-0.9998), |
| 81 |
(dT.getValue(0)<=-0.9999) && isAnyComp, type)); |
| 82 |
(*kernel) << (vnew = select(vnew, acl::generateVEConstant(0.9998), |
| 83 |
dT.getValue(0)>=0.9999 && isAnyGhost, type)); |
| 84 |
(*kernel) << (vnew = select(vnew, acl::generateVEConstant(-1), |
| 85 |
(dT.getValue(0)<0 && dT.getValue(0)>-0.9999) && !isAnyComp,type)); |
| 86 |
(*kernel) << (vnew = select(vnew, acl::generateVEConstant(1), |
| 87 |
(dT.getValue(0)>0 && dT.getValue(0)<0.9999) && !isAnyGhost,type)); |
| 88 |
|
| 89 |
(*kernel) << (assignmentSafe(inData->getEContainer(), vnew)); |
| 90 |
} |
| 91 |
|
| 92 |
void optimizeMap(SPDataWithGhostNodesACLData c, const VectorTemplate* vt) |
| 93 |
{ |
| 94 |
auto nm(make_shared<DFOptimizer> (c, vt)); |
| 95 |
nm->init(); |
| 96 |
nm->execute(); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
} //asl |