| 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 "aslTimeContinuations.h" |
| 25 |
#include <aslGenerators.h> |
| 26 |
#include <acl/aclGenerators.h> |
| 27 |
#include <acl/acl.h> |
| 28 |
#include "aslUtilities.h" |
| 29 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 30 |
|
| 31 |
#include <data/aslDataWithGhostNodes.h> |
| 32 |
#include <acl/Kernels/aclKernel.h> |
| 33 |
|
| 34 |
#include <acl/Kernels/aclKernelConfigurationTemplates.h> |
| 35 |
|
| 36 |
namespace asl |
| 37 |
{ |
| 38 |
|
| 39 |
TimeContinuations::TimeContinuations(Data inD, double f): |
| 40 |
inData(inD->getDContainer()), |
| 41 |
factor(f), |
| 42 |
nStorages(0) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
TimeContinuations::TimeContinuations(acl::VectorOfElementsData & inD, double f): |
| 47 |
inData(inD), |
| 48 |
factor(f), |
| 49 |
nStorages(0) |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
void TimeContinuations::addData(acl::VectorOfElementsData & inD) |
| 54 |
{ |
| 55 |
copy(cat(inData,inD),inData); |
| 56 |
} |
| 57 |
|
| 58 |
void TimeContinuations::addData(Data inD) |
| 59 |
{ |
| 60 |
copy(cat(inData,inD->getDContainer()),inData); |
| 61 |
} |
| 62 |
|
| 63 |
void TimeContinuations::reset() |
| 64 |
{ |
| 65 |
nStorages=0; |
| 66 |
} |
| 67 |
|
| 68 |
double polynomRootsLag(double x, int pOrder, int iCoef) |
| 69 |
{ |
| 70 |
double res(1); |
| 71 |
for(int i(0); i<pOrder; ++i) |
| 72 |
{ |
| 73 |
int a= (i>=iCoef) ? 1 : 0; |
| 74 |
res*=x+(pOrder-i-a); |
| 75 |
} |
| 76 |
return res; |
| 77 |
} |
| 78 |
|
| 79 |
double polynomCoefsLag(double f, int pOrder, int iCoef) |
| 80 |
{ |
| 81 |
return polynomRootsLag(f,pOrder,iCoef)/polynomRootsLag(iCoef-pOrder,pOrder,iCoef); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
TimeContinPLagrange::TimeContinPLagrange(Data inD, double f, unsigned int o): |
| 86 |
TimeContinuations(inD,f), |
| 87 |
kernels(o+1), |
| 88 |
order(o), |
| 89 |
coefs(o+1) |
| 90 |
{ |
| 91 |
} |
| 92 |
|
| 93 |
TimeContinPLagrange::TimeContinPLagrange(acl::VectorOfElementsData & inD, |
| 94 |
double f, unsigned int o): |
| 95 |
TimeContinuations(inD,f), |
| 96 |
kernels(o+1), |
| 97 |
order(o), |
| 98 |
coefs(o+1) |
| 99 |
{ |
| 100 |
} |
| 101 |
|
| 102 |
void TimeContinPLagrange::init() |
| 103 |
{ |
| 104 |
unsigned int nC(inData.size()); |
| 105 |
copy(clone(inData),storedData); |
| 106 |
acl::initData(storedData, acl::generateVEConstantN(nC,0.)); |
| 107 |
|
| 108 |
acl::VectorOfElements inDataV(inData); |
| 109 |
|
| 110 |
for(unsigned int i(0); i<=order; ++i) |
| 111 |
coefs[i]=polynomCoefsLag(factor, order, i); |
| 112 |
|
| 113 |
// cout<<factor<<endl; |
| 114 |
// cout<<coefs<<endl; |
| 115 |
|
| 116 |
for(unsigned int i(0); i<=order; ++i) |
| 117 |
kernels[i].reset(new acl::Kernel(acl::KERNEL_SIMD)); |
| 118 |
|
| 119 |
(*kernels[0]) << (assignmentSafe(storedData,coefs[0]*inDataV)); |
| 120 |
for(unsigned int i(1); i<order; ++i) |
| 121 |
(*kernels[i]) << (assignmentSafe(storedData,storedData+coefs[i]*inDataV)); |
| 122 |
|
| 123 |
(*kernels[order])<< (assignmentSafe (inDataV, storedData+coefs[order]*inDataV)); |
| 124 |
|
| 125 |
setupAll(kernels); |
| 126 |
} |
| 127 |
|
| 128 |
void TimeContinPLagrange::execute() |
| 129 |
{ |
| 130 |
kernels[nStorages]->compute(); |
| 131 |
nStorages++; |
| 132 |
nStorages=nStorages % (order+1); |
| 133 |
} |
| 134 |
|
| 135 |
double polynomRootsLagFr(double x, double offset, int pOrder, int iCoef) |
| 136 |
{ |
| 137 |
double res(1); |
| 138 |
for(int i(0); i<pOrder; ++i) |
| 139 |
{ |
| 140 |
int a= (i>=iCoef) ? 1 : 0; |
| 141 |
res*=1./(offset+x)-1./(offset-pOrder+i+a); |
| 142 |
} |
| 143 |
return res; |
| 144 |
} |
| 145 |
|
| 146 |
double polynomCoefsLagFr(double f,double offset, int pOrder, int iCoef) |
| 147 |
{ |
| 148 |
return polynomRootsLagFr(f,offset,pOrder,iCoef)/ |
| 149 |
polynomRootsLagFr(iCoef-pOrder,offset,pOrder,iCoef); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
TimeContinPLagrangeFraction::TimeContinPLagrangeFraction(Data inD, double f, unsigned int o): |
| 154 |
TimeContinuations(inD,f), |
| 155 |
kernels(o+1), |
| 156 |
order(o), |
| 157 |
// offset(.5*factor+o*2), |
| 158 |
offset(1.+o*2), |
| 159 |
coefs(o+1) |
| 160 |
{ |
| 161 |
} |
| 162 |
|
| 163 |
TimeContinPLagrangeFraction::TimeContinPLagrangeFraction(acl::VectorOfElementsData & inD, |
| 164 |
double f, unsigned int o): |
| 165 |
TimeContinuations(inD,f), |
| 166 |
kernels(o+1), |
| 167 |
order(o), |
| 168 |
// offset(.5*factor+o*2), |
| 169 |
offset(1.+o*2), |
| 170 |
coefs(o+1) |
| 171 |
{ |
| 172 |
} |
| 173 |
|
| 174 |
void TimeContinPLagrangeFraction::init() |
| 175 |
{ |
| 176 |
unsigned int nC(inData.size()); |
| 177 |
copy(clone(inData),storedData); |
| 178 |
acl::initData(storedData, acl::generateVEConstantN(nC,0.)); |
| 179 |
acl::VectorOfElements inDataV(inData); |
| 180 |
|
| 181 |
for(unsigned int i(0); i<=order; ++i) |
| 182 |
coefs[i]=polynomCoefsLagFr(factor, offset, order, i); |
| 183 |
|
| 184 |
// cout<<factor<<endl; |
| 185 |
// cout<<coefs<<endl; |
| 186 |
|
| 187 |
for(unsigned int i(0); i<=order; ++i) |
| 188 |
kernels[i].reset(new acl::Kernel(acl::KERNEL_SIMD)); |
| 189 |
|
| 190 |
(*kernels[0]) << (assignmentSafe(storedData,coefs[0]*inDataV)); |
| 191 |
for(unsigned int i(1); i<order; ++i) |
| 192 |
(*kernels[i]) << (assignmentSafe(storedData,storedData+coefs[i]*inDataV)); |
| 193 |
|
| 194 |
(*kernels[order])<< (assignmentSafe (inDataV, storedData+coefs[order]*inDataV)); |
| 195 |
|
| 196 |
setupAll(kernels); |
| 197 |
} |
| 198 |
|
| 199 |
void TimeContinPLagrangeFraction::execute() |
| 200 |
{ |
| 201 |
kernels[nStorages]->compute(); |
| 202 |
nStorages++; |
| 203 |
nStorages=nStorages % (order+1); |
| 204 |
} |
| 205 |
|
| 206 |
} //asl |