| 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 "aslPositionFunction.h" |
| 25 |
#include "acl/aclMath/aclVectorOfElements.h" |
| 26 |
#include <acl/aclGenerators.h> |
| 27 |
#include <acl/acl.h> |
| 28 |
#include <data/aslBlocks.h> |
| 29 |
#include <aslGenerators.h> |
| 30 |
#include <math/aslIndex2Position.h> |
| 31 |
#include <acl/Kernels/aclKernelConfigurationTemplates.h> |
| 32 |
#include <acl/Kernels/aclKernel.h> |
| 33 |
#include <data/aslDataWithGhostNodes.h> |
| 34 |
|
| 35 |
namespace asl |
| 36 |
{ |
| 37 |
PositionFunction::PositionFunction() |
| 38 |
{} |
| 39 |
|
| 40 |
PositionFunction::~PositionFunction() |
| 41 |
{} |
| 42 |
|
| 43 |
PFBinaryOperation:: |
| 44 |
PFBinaryOperation(SPPositionFunction a, SPPositionFunction b): |
| 45 |
e1(a), e2(b) |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
PFUnaryOperation:: |
| 50 |
PFUnaryOperation(SPPositionFunction a): |
| 51 |
e1(a) |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
PFOperationPlus:: |
| 56 |
PFOperationPlus(SPPositionFunction a, SPPositionFunction b): |
| 57 |
PFBinaryOperation(a,b) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
acl::VectorOfElements PFOperationPlus::value(acl::VectorOfElements & pos) |
| 62 |
{ |
| 63 |
return e1->value(pos) + e2->value(pos); |
| 64 |
} |
| 65 |
|
| 66 |
PFOperationMinus:: |
| 67 |
PFOperationMinus(SPPositionFunction a, SPPositionFunction b): |
| 68 |
PFBinaryOperation(a,b) |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
acl::VectorOfElements PFOperationMinus::value(acl::VectorOfElements & pos) |
| 73 |
{ |
| 74 |
return e1->value(pos) - e2->value(pos); |
| 75 |
} |
| 76 |
|
| 77 |
PFOperationInversion:: |
| 78 |
PFOperationInversion(SPPositionFunction a): |
| 79 |
PFUnaryOperation(a) |
| 80 |
{ |
| 81 |
} |
| 82 |
|
| 83 |
acl::VectorOfElements PFOperationInversion::value(acl::VectorOfElements & pos) |
| 84 |
{ |
| 85 |
return -(e1->value(pos)); |
| 86 |
} |
| 87 |
|
| 88 |
PFOperationProduct:: |
| 89 |
PFOperationProduct(SPPositionFunction a, SPPositionFunction b): |
| 90 |
PFBinaryOperation(a,b) |
| 91 |
{ |
| 92 |
} |
| 93 |
|
| 94 |
acl::VectorOfElements PFOperationProduct::value(acl::VectorOfElements & pos) |
| 95 |
{ |
| 96 |
return e1->value(pos) * e2->value(pos); |
| 97 |
} |
| 98 |
|
| 99 |
acl::VectorOfElements PFLinear::value(acl::VectorOfElements & pos) |
| 100 |
{ |
| 101 |
return pos * gradient + b; |
| 102 |
} |
| 103 |
|
| 104 |
PFLinear:: |
| 105 |
PFLinear(acl::VectorOfElements g, acl::VectorOfElements a): |
| 106 |
gradient(g), |
| 107 |
b(a) |
| 108 |
{ |
| 109 |
} |
| 110 |
acl::VectorOfElements PFConstant::value(acl::VectorOfElements & pos) |
| 111 |
{ |
| 112 |
return val; |
| 113 |
} |
| 114 |
|
| 115 |
PFConstant:: |
| 116 |
PFConstant(acl::VectorOfElements v): |
| 117 |
val(v) |
| 118 |
{ |
| 119 |
} |
| 120 |
|
| 121 |
PFSign:: |
| 122 |
PFSign(SPPositionFunction a): |
| 123 |
PFUnaryOperation(a) |
| 124 |
{ |
| 125 |
} |
| 126 |
|
| 127 |
acl::VectorOfElements PFSign::value(acl::VectorOfElements & pos) |
| 128 |
{ |
| 129 |
return sign(e1->value(pos)); |
| 130 |
} |
| 131 |
|
| 132 |
SPPositionFunction generatePFLinear(const AVec<double> & g, double p0) |
| 133 |
{ |
| 134 |
return SPPositionFunction(new PFLinear(acl::generateVEConstant(g), acl::generateVEConstant(p0))); |
| 135 |
} |
| 136 |
|
| 137 |
template <typename T> |
| 138 |
SPPositionFunction generatePFLinear(const AVec<double> & g, UValue<T> p0) |
| 139 |
{ |
| 140 |
return SPPositionFunction(new PFLinear(acl::generateVEConstant(g), |
| 141 |
acl::generateVEVariableSP(p0.p))); |
| 142 |
} |
| 143 |
template SPPositionFunction generatePFLinear(const AVec<double> & g, UValue<double> p0); |
| 144 |
template SPPositionFunction generatePFLinear(const AVec<double> & g, UValue<float> p0); |
| 145 |
|
| 146 |
|
| 147 |
SPPositionFunction generatePFConstant(double v) |
| 148 |
{ |
| 149 |
return SPPositionFunction(new PFConstant(acl::generateVEConstant(v))); |
| 150 |
} |
| 151 |
|
| 152 |
SPPositionFunction generatePFConstant(const AVec<double> & v) |
| 153 |
{ |
| 154 |
return SPPositionFunction(new PFConstant(acl::generateVEConstant(v))); |
| 155 |
} |
| 156 |
|
| 157 |
SPAbstractDataWithGhostNodes generateDataContainer_SP(const Block &b, |
| 158 |
SPPositionFunction df, |
| 159 |
unsigned int gN, |
| 160 |
acl::TypeID t) |
| 161 |
{ |
| 162 |
asl::Index2PositionACL i2p(offset(b, gN), t); |
| 163 |
|
| 164 |
return generateDataContainer_SP(b, df->value(i2p.positionWithInit), gN); |
| 165 |
} |
| 166 |
|
| 167 |
void initData(SPAbstractDataWithGhostNodes d, |
| 168 |
SPPositionFunction f) |
| 169 |
{ |
| 170 |
initData(d, f, acl::KERNEL_SIMD); |
| 171 |
} |
| 172 |
|
| 173 |
void initData(SPAbstractDataWithGhostNodes d, |
| 174 |
SPPositionFunction f, |
| 175 |
const acl::KernelConfiguration & kernelConfig) |
| 176 |
{ |
| 177 |
auto type(getElementType(d->getEContainer())); |
| 178 |
asl::Index2PositionACL i2p(d->getBlock(),type); |
| 179 |
|
| 180 |
acl::Kernel k(kernelConfig); |
| 181 |
k << i2p.initPosition; |
| 182 |
k << acl::assignmentSafe(d->getEContainer(), f->value(i2p.position)); |
| 183 |
k.setup(); |
| 184 |
k.compute(); |
| 185 |
} |
| 186 |
|
| 187 |
PFRotationField::PFRotationField(acl::VectorOfElements rotationAxis, |
| 188 |
acl::VectorOfElements center): |
| 189 |
axis(rotationAxis), |
| 190 |
c(center) |
| 191 |
{ |
| 192 |
} |
| 193 |
|
| 194 |
acl::VectorOfElements PFRotationField::value(acl::VectorOfElements & pos) |
| 195 |
{ |
| 196 |
return crossProduct(axis, pos-c); |
| 197 |
} |
| 198 |
|
| 199 |
SPPositionFunction generatePFRotationField(const AVec<> & a, const AVec<> & c) |
| 200 |
{ |
| 201 |
return SPPositionFunction(new PFRotationField(acl::generateVEConstant(a), |
| 202 |
acl::generateVEConstant(c))); |
| 203 |
} |
| 204 |
|
| 205 |
}// asl |