| 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 |
#ifndef ASLTEMPLATES_H |
| 25 |
#define ASLTEMPLATES_H |
| 26 |
|
| 27 |
#include "aslVectors.h" |
| 28 |
//#include "aslSVectors.h" |
| 29 |
|
| 30 |
namespace asl { |
| 31 |
|
| 32 |
/** |
| 33 |
\defgroup Templates Vector Templates |
| 34 |
*/ |
| 35 |
|
| 36 |
/** |
| 37 |
\defgroup TemplatesNN Vector Templates: Nearest Neighbours |
| 38 |
\ingroup Templates |
| 39 |
*/ |
| 40 |
|
| 41 |
/** |
| 42 |
\defgroup TemplatesNNP Vector Templates: Nearest Neighbours Plus |
| 43 |
\ingroup Templates |
| 44 |
*/ |
| 45 |
|
| 46 |
/** |
| 47 |
\defgroup TemplatesEC Vector Templates: Elementary Cells |
| 48 |
\ingroup Templates |
| 49 |
*/ |
| 50 |
|
| 51 |
/** |
| 52 |
\defgroup TemplatesNN0 Vector Templates: Nearest Neighbours without center |
| 53 |
\ingroup Templates |
| 54 |
*/ |
| 55 |
|
| 56 |
/** |
| 57 |
\defgroup TemplatesNNP0 Vector Templates: Nearest Neighbours Plus without center |
| 58 |
\ingroup Templates |
| 59 |
*/ |
| 60 |
|
| 61 |
/// list of implemented names of VectorTemplate |
| 62 |
enum VTName |
| 63 |
{ |
| 64 |
VTN_D1Q2EC, |
| 65 |
VTN_D2Q4EC, |
| 66 |
VTN_D3Q8EC, |
| 67 |
VTN_D1Q3, |
| 68 |
VTN_D2Q5, |
| 69 |
VTN_D2Q9, |
| 70 |
VTN_D3Q7, |
| 71 |
VTN_D3Q15, |
| 72 |
VTN_D3Q19, |
| 73 |
VTN_D3Q27, |
| 74 |
VTN_D1Q1UV, |
| 75 |
VTN_D2Q2UV, |
| 76 |
VTN_D3Q3UV, |
| 77 |
VTN_D1Q2, |
| 78 |
VTN_D2Q4, |
| 79 |
VTN_D3Q6, |
| 80 |
VTN_D2Q8, |
| 81 |
VTN_D3Q14, |
| 82 |
VTN_D3Q18 |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
/// Defines set of vectros with several properties \ingroup Templates |
| 87 |
class VectorTemplate |
| 88 |
{ |
| 89 |
private: |
| 90 |
void buildInvertVectorList(); |
| 91 |
public: |
| 92 |
std::vector<AVec<int> > vectors; |
| 93 |
std::vector<double> laplasCoefs; |
| 94 |
std::vector<double> gradientCoefs; |
| 95 |
std::vector<double> quasiparticlesCoefs; |
| 96 |
std::vector<unsigned int> invertVectors; |
| 97 |
double dIdJLapCoef; |
| 98 |
std::vector<std::vector<double>> dxCoefs; |
| 99 |
std::vector<std::vector<std::vector<double>>> dIdJCoefs; |
| 100 |
VectorTemplate(int n, AVec<int>* vec); |
| 101 |
VectorTemplate(int n, AVec<int>* vec, double* lc, double* gc); |
| 102 |
|
| 103 |
inline unsigned int numberOfDimentions() const; |
| 104 |
inline AVec<int> getInverVector(unsigned int i); |
| 105 |
}; |
| 106 |
|
| 107 |
inline unsigned int nD(const VectorTemplate & vt); |
| 108 |
|
| 109 |
///An elementary cell in 1D space |
| 110 |
/** |
| 111 |
\ingroup TemplatesEC |
| 112 |
|
| 113 |
This template defines an elementary cell: vectors and interpolation law |
| 114 |
\image html t2ec.png "1D elementary cell" |
| 115 |
*/ |
| 116 |
const VectorTemplate & d1q2ec(); |
| 117 |
///An elementary cell in 2D space |
| 118 |
/** |
| 119 |
\ingroup TemplatesEC |
| 120 |
|
| 121 |
This template defines an elementary cell: vectors and interpolation law |
| 122 |
\image html t4ec.png "2D elementary cell" |
| 123 |
*/ |
| 124 |
const VectorTemplate & d2q4ec(); |
| 125 |
|
| 126 |
///An elementary cell in 3D space |
| 127 |
/** |
| 128 |
\ingroup TemplatesEC |
| 129 |
|
| 130 |
This template defines an elementary cell: vectors and interpolation law |
| 131 |
\image html t8ec.png "3D elementary cell" |
| 132 |
*/ |
| 133 |
const VectorTemplate & d3q8ec(); |
| 134 |
|
| 135 |
///Vector template |
| 136 |
/** |
| 137 |
\ingroup TemplatesNN |
| 138 |
|
| 139 |
\image html t3.png |
| 140 |
*/ |
| 141 |
const VectorTemplate & d1q3(); |
| 142 |
|
| 143 |
///Vector template |
| 144 |
/** |
| 145 |
\ingroup TemplatesNN |
| 146 |
|
| 147 |
\image html t5.png |
| 148 |
*/ |
| 149 |
const VectorTemplate & d2q5(); |
| 150 |
|
| 151 |
///Vector template |
| 152 |
/** |
| 153 |
\ingroup TemplatesNNP |
| 154 |
|
| 155 |
\image html t9.png |
| 156 |
*/ |
| 157 |
const VectorTemplate & d2q9(); |
| 158 |
|
| 159 |
///Vector template |
| 160 |
/** |
| 161 |
\ingroup TemplatesNN |
| 162 |
|
| 163 |
\image html t7.png |
| 164 |
*/ |
| 165 |
const VectorTemplate & d3q7(); |
| 166 |
|
| 167 |
///Vector template |
| 168 |
/** |
| 169 |
\ingroup TemplatesNNP |
| 170 |
|
| 171 |
\image html t15.png |
| 172 |
*/ |
| 173 |
const VectorTemplate & d3q15(); |
| 174 |
|
| 175 |
///Vector template |
| 176 |
/** |
| 177 |
\ingroup TemplatesNNP |
| 178 |
|
| 179 |
\image html t19.png |
| 180 |
*/ |
| 181 |
const VectorTemplate & d3q19(); |
| 182 |
|
| 183 |
///Vector template |
| 184 |
/** |
| 185 |
\ingroup TemplatesNNP |
| 186 |
|
| 187 |
\image html t27.png |
| 188 |
*/ |
| 189 |
const VectorTemplate & d3q27(); |
| 190 |
|
| 191 |
///An unit vector in 1D space |
| 192 |
/** |
| 193 |
\ingroup TemplatesNNP |
| 194 |
|
| 195 |
This template defines a unit vector |
| 196 |
*/ |
| 197 |
const VectorTemplate & d1q1uv(); |
| 198 |
///An elementary cell in 2D space |
| 199 |
/** |
| 200 |
\ingroup Templates |
| 201 |
|
| 202 |
This template defines unit vectors |
| 203 |
*/ |
| 204 |
const VectorTemplate & d2q2uv(); |
| 205 |
|
| 206 |
///An elementary cell in 3D space |
| 207 |
/** |
| 208 |
\ingroup Templates |
| 209 |
|
| 210 |
This template defines unit vectors |
| 211 |
*/ |
| 212 |
const VectorTemplate & d3q3uv(); |
| 213 |
|
| 214 |
///Vector template |
| 215 |
/** |
| 216 |
\ingroup TemplatesNN0 |
| 217 |
|
| 218 |
\image html t2.png |
| 219 |
*/ |
| 220 |
const VectorTemplate & d1q2(); |
| 221 |
|
| 222 |
///Vector template |
| 223 |
/** |
| 224 |
\ingroup TemplatesNN0 |
| 225 |
|
| 226 |
\image html t4.png |
| 227 |
*/ |
| 228 |
const VectorTemplate & d2q4(); |
| 229 |
|
| 230 |
///Vector template |
| 231 |
/** |
| 232 |
\ingroup TemplatesNN0 |
| 233 |
|
| 234 |
\image html t6.png |
| 235 |
*/ |
| 236 |
const VectorTemplate & d3q6(); |
| 237 |
|
| 238 |
///Vector template |
| 239 |
/** |
| 240 |
\ingroup TemplatesNNP0 |
| 241 |
*/ |
| 242 |
const VectorTemplate & d2q8(); |
| 243 |
|
| 244 |
///Vector template |
| 245 |
/** |
| 246 |
\ingroup TemplatesNNP0 |
| 247 |
*/ |
| 248 |
const VectorTemplate & d3q14(); |
| 249 |
|
| 250 |
///Vector template |
| 251 |
/** |
| 252 |
\ingroup TemplatesNNP0 |
| 253 |
*/ |
| 254 |
const VectorTemplate & d3q18(); |
| 255 |
|
| 256 |
/// returns template corresponding to nearest neighbours \ingroup Templates |
| 257 |
/** asl::d1q3, asl::d2q5, asl::d3q7 |
| 258 |
*/ |
| 259 |
inline const VectorTemplate* nearestNeigboursVT(unsigned int dimNumber); |
| 260 |
|
| 261 |
/// returns template corresponding to nearest neighbours without central point |
| 262 |
/** |
| 263 |
\ingroup Templates |
| 264 |
asl::d1q2, asl::d2q4, asl::d3q6 |
| 265 |
*/ |
| 266 |
inline const VectorTemplate* nearestNeigboursVT0(unsigned int dimNumber); |
| 267 |
|
| 268 |
/// returns template corresponding to nearest neighbours plus \ingroup Templates |
| 269 |
/** asl::d1q3, asl::d2q9, asl::d3q15 |
| 270 |
*/ |
| 271 |
inline const VectorTemplate* nearestNeigboursPVT(unsigned int dimNumber); |
| 272 |
|
| 273 |
|
| 274 |
/// returns template corresponding to all neighbours |
| 275 |
/** |
| 276 |
\ingroup Templates |
| 277 |
asl::d1q3, asl::d2q9, asl::d3q27 |
| 278 |
*/ |
| 279 |
inline const VectorTemplate* allNeigboursVT(unsigned int dimNumber); |
| 280 |
|
| 281 |
/// returns template corresponding to an elementary cell |
| 282 |
/** |
| 283 |
\ingroup Templates |
| 284 |
asl::d1q2ec, asl::d2q4ec, asl::d3q8ec |
| 285 |
*/ |
| 286 |
inline const VectorTemplate* elementaryCellVT(unsigned int dimNumber); |
| 287 |
|
| 288 |
|
| 289 |
// ----------------------------- Implementation ------------------------- |
| 290 |
|
| 291 |
inline unsigned int VectorTemplate::numberOfDimentions() const |
| 292 |
{ |
| 293 |
return vectors[0].getSize(); |
| 294 |
} |
| 295 |
|
| 296 |
inline unsigned int nD(const VectorTemplate & vt) |
| 297 |
{ |
| 298 |
return vt.numberOfDimentions(); |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
inline const VectorTemplate* nearestNeigboursVT(unsigned int dimNumber) |
| 303 |
{ |
| 304 |
static const VectorTemplate* vt[3]={&d1q3(),&d2q5(),&d3q7()}; |
| 305 |
return vt[dimNumber-1]; |
| 306 |
} |
| 307 |
|
| 308 |
inline const VectorTemplate* nearestNeigboursPVT(unsigned int dimNumber) |
| 309 |
{ |
| 310 |
static const VectorTemplate* vt[3]={&d1q3(),&d2q9(),&d3q15()}; |
| 311 |
return vt[dimNumber-1]; |
| 312 |
} |
| 313 |
|
| 314 |
inline const VectorTemplate* allNeigboursVT(unsigned int dimNumber) |
| 315 |
{ |
| 316 |
static const VectorTemplate* vt[3]={&d1q3(),&d2q9(),&d3q27()}; |
| 317 |
return vt[dimNumber-1]; |
| 318 |
} |
| 319 |
|
| 320 |
inline const VectorTemplate* elementaryCellVT(unsigned int dimNumber) |
| 321 |
{ |
| 322 |
static const VectorTemplate* vt[3]={&d1q2ec(),&d2q4ec(),&d3q8ec()}; |
| 323 |
return vt[dimNumber-1]; |
| 324 |
} |
| 325 |
|
| 326 |
inline AVec<int> VectorTemplate::getInverVector(unsigned int i) |
| 327 |
{ |
| 328 |
return vectors[invertVectors[i]]; |
| 329 |
} |
| 330 |
|
| 331 |
/* |
| 332 |
///The templates for the numerical schemas |
| 333 |
namespace templ { |
| 334 |
/// An abstract class for description of point templates for differential operators etc. |
| 335 |
class GrigTemplate{ |
| 336 |
public: |
| 337 |
unsigned const int nDimentions; |
| 338 |
unsigned const int nPoints; |
| 339 |
virtual vector<int> & getVector(unsigned int i)=0; |
| 340 |
protected: |
| 341 |
GridTemplate(unsigned int nD, unsigned int nP); |
| 342 |
} |
| 343 |
*/ |
| 344 |
/** |
| 345 |
This template defines an elementary cell: vectors and interpolation law |
| 346 |
\image html t2ec.png "1D elementary cell" |
| 347 |
\image latex t2ec.png "1D elementary cell" width=8cm |
| 348 |
*/ |
| 349 |
/* class d1q2ec { |
| 350 |
public: |
| 351 |
static const int ND=1; |
| 352 |
static const int NV=2; |
| 353 |
typedef Vec<ND,int> DV; |
| 354 |
public: |
| 355 |
inline static const DV & l(int i) { |
| 356 |
static const DV lat[NV] = {DV(0),DV(1)}; |
| 357 |
return lat[i]; |
| 358 |
} |
| 359 |
///The interpolation procedure |
| 360 |
template <typename T> |
| 361 |
inline static const T interpol(const Vec<NV,T> &d, const Vec<ND,lFl> &e) { |
| 362 |
return d.x()*(1.-e.x())+d.y()*e.x(); |
| 363 |
} |
| 364 |
}; |
| 365 |
*/ |
| 366 |
///An elementary cell in 2D space |
| 367 |
/** |
| 368 |
This template defines an elementary cell: vectors and interpolation law |
| 369 |
\image html t4ec.png "2D elementary cell" |
| 370 |
\image latex t4ec.png "2D elementary cell" width=8cm |
| 371 |
*/ |
| 372 |
/* class d2q4ec { |
| 373 |
public: |
| 374 |
static const int ND=2; |
| 375 |
static const int NV=4; |
| 376 |
typedef Vec<ND,int> DV; |
| 377 |
inline static const DV & l(int i) { |
| 378 |
static const DV lat[NV] = {DV(0,0),DV(1,0),DV(0,1),DV(1,1)}; |
| 379 |
return lat[i]; |
| 380 |
} |
| 381 |
///The interpolation procedure |
| 382 |
template <typename T> |
| 383 |
inline static const T interpol(const Vec<NV,T> &d, const Vec<ND,lFl> &e) { |
| 384 |
return d[0]*(1.-e.x())*(1.-e.y())+d[1]*e.x()*(1.-e.y())+ |
| 385 |
d[2]*(1.-e.x())*e.y() +d[3]*e.x()*e.y(); |
| 386 |
} |
| 387 |
|
| 388 |
}; |
| 389 |
*/ |
| 390 |
///An elementary cell in 2D space |
| 391 |
/** |
| 392 |
This template defines an elementary cell: vectors and interpolation law |
| 393 |
\image html t8ec.png "3D elementary cell" |
| 394 |
\image latex t8ec.png "3D elementary cell" width=8cm |
| 395 |
*/ |
| 396 |
/* class d3q8ec { |
| 397 |
public: |
| 398 |
static const int ND=3; |
| 399 |
static const int NV=8; |
| 400 |
typedef Vec<ND,int> DV; |
| 401 |
inline static const DV & l(int i) { |
| 402 |
static const DV lat[NV] = { |
| 403 |
DV(0,0,0),DV(1,0,0),DV(0,1,0),DV(1,1,0), |
| 404 |
DV(0,0,1),DV(1,0,1),DV(0,1,1),DV(1,1,1) |
| 405 |
}; |
| 406 |
return lat[i]; |
| 407 |
} |
| 408 |
|
| 409 |
///The interpolation procedure |
| 410 |
template <typename T> |
| 411 |
inline static const T interpol(const Vec<NV,T> &d, const Vec<ND,lFl> &e) { |
| 412 |
return d[0]*(1.-e.x())*(1.-e.y())*(1.-e.z()) |
| 413 |
+d[1]* e.x()* (1.-e.y())*(1.-e.z()) |
| 414 |
+d[2]*(1.-e.x())* e.y()* (1.-e.z()) |
| 415 |
+d[3]* e.x()* e.y()* (1.-e.z()) |
| 416 |
+d[4]*(1.-e.x())*(1.-e.y())* e.z() |
| 417 |
+d[5]* e.x()* (1.-e.y())* e.z() |
| 418 |
+d[6]*(1.-e.x())* e.y()* e.z() |
| 419 |
+d[7]* e.x()* e.y()* e.z(); |
| 420 |
} |
| 421 |
}; |
| 422 |
|
| 423 |
*/ |
| 424 |
|
| 425 |
///d2q9 vectorspace |
| 426 |
/** |
| 427 |
The operators are defined on the correspoNDing templates: |
| 428 |
\image html t9.png "9-point templates" |
| 429 |
\image latex t9.png "9-point templates" width=8cm |
| 430 |
*/ |
| 431 |
/* class d2q9 { |
| 432 |
public: |
| 433 |
static const int ND=2; |
| 434 |
static const int NV=9; |
| 435 |
typedef Vec<ND,int> DV; |
| 436 |
// private: |
| 437 |
static const lFl w1=4./9.,w2=1./9.,w3=1./36., as2i=3.; |
| 438 |
static inline const DV & l(int i) { |
| 439 |
static const DV lat[NV] = { |
| 440 |
DV(0,0),DV(1,0),DV(0,1), DV(-1,0),DV(0,-1), |
| 441 |
DV(1,1),DV(-1,1),DV(-1,-1),DV(1,-1) |
| 442 |
}; |
| 443 |
return lat[i]; |
| 444 |
} |
| 445 |
///number of the vector wich has oposite derection |
| 446 |
static inline int io(int i) { |
| 447 |
static const int inv[NV] = {0,3,4,1,2,7,8,5,6}; |
| 448 |
return inv[i]; |
| 449 |
} |
| 450 |
static inline lFl s(const Vec<NV> &p) { |
| 451 |
return (w1*p[0]+w2*(p[1]+p[2]+p[3]+p[4])+w3*(p[5]+p[6]+p[7]+p[8])); |
| 452 |
} |
| 453 |
static inline lFl s(Vec<NV> &p, const lFl &val) { |
| 454 |
return (p[0] =p[1] =p[2] =p[3] =p[4] =p[5] =p[6] =p[7] =p[8] =val); |
| 455 |
} |
| 456 |
|
| 457 |
static inline const Vec<ND> v(const Vec<NV> &p) { |
| 458 |
return Vec<2>(w2*(p[1]-p[3])+w3*(p[5]-p[6]-p[7]+p[8]), |
| 459 |
w2*(p[2]-p[4])+w3*(p[5]+p[6]-p[7]-p[8])); |
| 460 |
} |
| 461 |
static inline const Vec<ND> v(Vec<NV> &p, const Vec<ND> &val) { |
| 462 |
const lFl p0(s(p)); |
| 463 |
for (int i(0); i < NV; ++i) |
| 464 |
p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 465 |
return val; |
| 466 |
} |
| 467 |
|
| 468 |
///coefficient of the lapplace operator |
| 469 |
static inline lFl lc(int i) { |
| 470 |
static const lFl c[NV] = {-10./3.,2./3.,2./3.,2./3.,2./3.,1./6.,1./6.,1./6.,1./6.}; |
| 471 |
return c[i]; |
| 472 |
} |
| 473 |
|
| 474 |
}; |
| 475 |
*/ |
| 476 |
|
| 477 |
///d2q5 vectorspace |
| 478 |
/** |
| 479 |
The operators are defined on the correspoNDing templates: |
| 480 |
\image html t5.png "5-point templates" |
| 481 |
\image latex t5.png "5-point templates" width=8cm |
| 482 |
*/ |
| 483 |
/* class d2q5 { |
| 484 |
public: |
| 485 |
static const int ND=2; |
| 486 |
static const int NV=5; |
| 487 |
typedef Vec<ND,int> DV; |
| 488 |
inline static const DV & l(int i) { |
| 489 |
static const DV lat[NV] = {DV(0,0),DV(1,0),DV(0,1),DV(-1,0), DV(0,-1)}; |
| 490 |
return lat[i]; |
| 491 |
} |
| 492 |
///number of the vector wich has oposite derection |
| 493 |
inline static int io(int i) { |
| 494 |
static const int inv[NV] = {0,3,4,1,2}; |
| 495 |
return inv[i]; |
| 496 |
} |
| 497 |
///coefficient of the lapplace operator |
| 498 |
static inline lFl lc(int i) { |
| 499 |
static const lFl c[NV] = {-4.,1.,1.,1.,1.}; |
| 500 |
return c[i]; |
| 501 |
} |
| 502 |
}; |
| 503 |
*/ |
| 504 |
|
| 505 |
///d2q4 vectorspace |
| 506 |
/** |
| 507 |
The operators are defined on the corresponding templates: |
| 508 |
\image html t4.png "4-point templates" |
| 509 |
\image latex t4.png "4-point templates" width=8cm |
| 510 |
*/ |
| 511 |
/* class d2q4 { |
| 512 |
public: |
| 513 |
static const int ND=2; |
| 514 |
static const int NV=4; |
| 515 |
typedef Vec<ND,int> DV; |
| 516 |
static const lFl w1=1./NV, as2i=ND; |
| 517 |
inline static const DV & l(int i) { |
| 518 |
static const DV lat[NV] = {DV(1,0),DV(0,1),DV(-1,0), DV(0,-1)}; |
| 519 |
return lat[i]; |
| 520 |
} |
| 521 |
///number of the vector wich has oposite derection |
| 522 |
inline static int io(int i) { |
| 523 |
static const int inv[NV] = {2,3,0,1}; |
| 524 |
return inv[i]; |
| 525 |
} |
| 526 |
static inline lFl s(const Vec<NV> &p) {return (w1*(p[0]+p[1]+p[2]+p[3]));} |
| 527 |
static inline lFl s(Vec<NV> &p, const lFl &val) {return (p[0] =p[1] =p[2] =p[3] =val);} |
| 528 |
static inline const Vec<ND> v(const Vec<NV> &p) { |
| 529 |
return Vec<ND>(w1*(p[0]-p[2]),w1*(p[1]-p[3])); |
| 530 |
} |
| 531 |
static inline const Vec<ND> v(Vec<NV> &p, const Vec<ND> &val) { |
| 532 |
const lFl p0(s(p)); |
| 533 |
for (int i(0); i < NV; ++i)p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 534 |
return val; |
| 535 |
} |
| 536 |
|
| 537 |
}; |
| 538 |
|
| 539 |
*/ |
| 540 |
|
| 541 |
///d3q7 vectorspace |
| 542 |
/** |
| 543 |
\image html t7.png "7-point templates" |
| 544 |
\image latex t7.png "7-point templates" width=8cm |
| 545 |
*/ |
| 546 |
/* class d3q7 { |
| 547 |
public: |
| 548 |
static const int ND=3; |
| 549 |
static const int NV=7; |
| 550 |
typedef Vec<ND,int> DV; |
| 551 |
inline static const DV l(int i) { |
| 552 |
static const DV lat[NV] = {DV(SV()[I2T<0>()]),DV(SV()[I2T<1>()]),DV(SV()[I2T<2>()]), |
| 553 |
DV(SV()[I2T<3>()]),DV(SV()[I2T<4>()]),DV(SV()[I2T<5>()]), |
| 554 |
DV(SV()[I2T<6>()])}; |
| 555 |
return lat[i]; |
| 556 |
} |
| 557 |
///number of the vector wich has oposite derection |
| 558 |
inline static int io(int i) { |
| 559 |
static const int inv[NV] = {0,4,5,6,1,2,3}; |
| 560 |
return inv[i]; |
| 561 |
} |
| 562 |
///coefficient of the lapplace operator |
| 563 |
static inline lFl lc(int i) { |
| 564 |
static const lFl c[NV] = {-6.,1.,1.,1.,1.,1.,1.}; |
| 565 |
return c[i]; |
| 566 |
} |
| 567 |
}; |
| 568 |
*/ |
| 569 |
|
| 570 |
///d3q6 vectorspace |
| 571 |
/** |
| 572 |
\image html t6.png "6-point templates" |
| 573 |
\image latex t6.png "6-point templates" width=8cm |
| 574 |
*/ |
| 575 |
/* class d3q6 { |
| 576 |
public: |
| 577 |
static const int ND=3; |
| 578 |
static const int NV=6; |
| 579 |
typedef Vec<ND,int> DV; |
| 580 |
static const lFl w1=1./NV, as2i=ND; |
| 581 |
inline static const DV & l(int i) { |
| 582 |
static const DV lat[NV] = { |
| 583 |
DV(1,0,0), DV(0,1,0),DV(0,0,1), |
| 584 |
DV(-1,0,0), DV(0,-1,0),DV(0,0,-1) |
| 585 |
}; |
| 586 |
return lat[i]; |
| 587 |
} |
| 588 |
///number of the vector wich has oposite derection |
| 589 |
inline static int io(int i) { |
| 590 |
static const int inv[NV] = {3,4,5,0,1,2}; |
| 591 |
return inv[i]; |
| 592 |
} |
| 593 |
static inline lFl s(const Vec<NV> &p) {return (w1*(p[0]+p[1]+p[2]+p[3]+p[4]+p[5]));} |
| 594 |
static inline lFl s(Vec<NV> &p, const lFl &val) { |
| 595 |
return (p[0] =p[1] =p[2] =p[3] =p[4] =p[5] =val); |
| 596 |
} |
| 597 |
static inline const Vec<ND> v(const Vec<NV> &p) { |
| 598 |
return Vec<ND>(w1*(p[0]-p[3]),w1*(p[1]-p[4]),w1*(p[2]-p[5])); |
| 599 |
} |
| 600 |
static inline const Vec<ND> v(Vec<NV> &p, const Vec<ND> &val) { |
| 601 |
const lFl p0(s(p)); |
| 602 |
for (int i(0); i < NV; ++i)p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 603 |
return val; |
| 604 |
} |
| 605 |
}; |
| 606 |
|
| 607 |
*/ |
| 608 |
|
| 609 |
///d3q19 vectorspace |
| 610 |
/** |
| 611 |
\image html t19.png "19-point templates" |
| 612 |
\image latex t19.png "19-point templates" width=8cm |
| 613 |
*/ |
| 614 |
/* class d3q19 { |
| 615 |
public: |
| 616 |
static const int ND=3; |
| 617 |
static const int NV=19; |
| 618 |
typedef Vec<ND,int> DV; |
| 619 |
static const lFl w1=1./3.,w2=1./18.,w3=1./36., as2i=3.; |
| 620 |
inline static const DV & l(int i) { |
| 621 |
static const DV lat[NV] = { |
| 622 |
DV(0,0,0), DV(1,0,0), DV(0,1,0), |
| 623 |
DV(0,0,1), DV(-1,0,0), DV(0,-1,0), |
| 624 |
DV(0,0,-1), DV(1,1,0), DV(1,-1,0), |
| 625 |
DV(-1,-1,0), DV(-1,1,0), DV(0,1,1), |
| 626 |
DV(0,1,-1), DV(0,-1,-1), DV(0,-1,1), |
| 627 |
DV(1,0,1), DV(1,0,-1), DV(-1,0,-1), |
| 628 |
DV(-1,0,1) |
| 629 |
}; |
| 630 |
return lat[i]; |
| 631 |
} |
| 632 |
///numbers of the vector wich has oposite derection |
| 633 |
inline static int io(int i) { |
| 634 |
static const int inv[NV] = {0,4,5,6,1,2,3,9,10,7,8,13,14,11,12,17,18,15,16}; |
| 635 |
return inv[i]; |
| 636 |
} |
| 637 |
static inline lFl s(const Vec<NV> &p) { |
| 638 |
return (w1*p[0]+w2*(p[1]+p[2]+p[3]+p[4]+p[5]+p[6]) |
| 639 |
+w3*(p[7]+p[8]+p[9]+p[10]+p[11]+p[12]+p[13]+p[14]+p[15]+p[16]+p[17]+p[18])); |
| 640 |
} |
| 641 |
static inline lFl s(Vec<NV> &p, const lFl &val) {p=val; return val;} |
| 642 |
|
| 643 |
static inline const Vec<ND> v(const Vec<NV> &p) { |
| 644 |
return |
| 645 |
Vec<ND>(w2*(p[1]-p[4])+w3*( p[7] +p[8]- p[9]-p[10]+p[15]+p[16]-p[17]-p[18]), |
| 646 |
w2*(p[2]-p[5])+w3*( p[7] -p[8]- p[9]+p[10]+p[11]+p[12]-p[13]-p[14]), |
| 647 |
w2*(p[3]-p[6])+w3*(p[11]-p[12]-p[13]+p[14]+p[15]-p[16]-p[17]+p[18])); |
| 648 |
} |
| 649 |
static inline const Vec<ND> v(Vec<NV> &p, const Vec<ND> &val) { |
| 650 |
const lFl p0(s(p)); |
| 651 |
for (int i(0); i < NV; ++i)p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 652 |
return val; |
| 653 |
} |
| 654 |
///coefficient of the lapplace operator |
| 655 |
static inline lFl lc(int i) { |
| 656 |
static const lFl c[NV] = {-4., |
| 657 |
1./3.,1./3.,1./3.,1./3.,1./3.,1./3., |
| 658 |
1./6.,1./6.,1./6.,1./6.,1./6.,1./6., |
| 659 |
1./6.,1./6.,1./6.,1./6.,1./6.,1./6.}; |
| 660 |
return c[i]; |
| 661 |
} |
| 662 |
}; |
| 663 |
*/ |
| 664 |
|
| 665 |
///d3q15 vectorspace |
| 666 |
/** |
| 667 |
\image html t15.png "15-point templates" |
| 668 |
\image latex t15.png "15-point templates" width=8cm |
| 669 |
*/ |
| 670 |
/* class d3q15 { |
| 671 |
public: |
| 672 |
static const int ND=3; |
| 673 |
static const int NV=15; |
| 674 |
typedef Vec<ND,int> DV; |
| 675 |
static const lFl w1=2./9.,w2=1./9.,w3=1./72., as2i=3.; |
| 676 |
static inline const DV & l(int i) { |
| 677 |
static const DV lat[NV] = { |
| 678 |
DV(0,0,0), DV(1,0,0), DV(0,1,0), |
| 679 |
DV(0,0,1), DV(-1,0,0), DV(0,-1,0), |
| 680 |
DV(0,0,-1), DV(1,1,1), DV(1,1,-1), |
| 681 |
DV(1,-1,1), DV(1,-1,-1), DV(-1,1,1), |
| 682 |
DV(-1,1,-1), DV(-1,-1,1), DV(-1,-1,-1) |
| 683 |
}; |
| 684 |
return lat[i]; |
| 685 |
} |
| 686 |
///number of the vector wich has oposite derection |
| 687 |
static inline int io(int i) { |
| 688 |
static const int inv[NV] = {0,4,5,6,1,2,3,14,13,12,11,10,9,8,7}; |
| 689 |
return inv[i]; |
| 690 |
} |
| 691 |
static inline lFl s(const Vec<NV> &p) { |
| 692 |
return (w1*p[0]+w2*(p[1]+p[2]+p[3]+p[4]+p[5]+p[6]) |
| 693 |
+w3*(p[7]+p[8]+p[9]+p[10]+p[11]+p[12]+p[13]+p[14])); |
| 694 |
} |
| 695 |
static inline lFl s(Vec<NV> &p, const lFl &val) {p=val; return val;} |
| 696 |
|
| 697 |
template <typename Td,typename SD> |
| 698 |
static inline const Vec<ND> v(const Vec<NV,Td,SD> &p) |
| 699 |
{ |
| 700 |
return |
| 701 |
Vec<ND>(w2*(p[1]-p[4])+w3*(p[7]+p[8]+p[9]+p[10]-p[11]-p[12]-p[13]-p[14]), |
| 702 |
w2*(p[2]-p[5])+w3*(p[7]+p[8]-p[9]-p[10]+p[11]+p[12]-p[13]-p[14]), |
| 703 |
w2*(p[3]-p[6])+w3*(p[7]-p[8]+p[9]-p[10]+p[11]-p[12]+p[13]-p[14])); |
| 704 |
} |
| 705 |
static inline void v(Vec<NV> &p, const Vec<ND> &val) { |
| 706 |
const lFl p0(s(p)); |
| 707 |
for (int i(0); i < NV; ++i)p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 708 |
} |
| 709 |
template <typename Ty> |
| 710 |
static inline void v(Vec<NV,lFl,Ty> p, const Vec<ND> &val) |
| 711 |
{ |
| 712 |
const lFl p0(s(p)); |
| 713 |
for (int i(0); i < NV; ++i)p[i] =p0+val*Vec<ND>(l(i))*as2i; |
| 714 |
} |
| 715 |
|
| 716 |
///coefficient of the lapplace operator |
| 717 |
static inline lFl lc(int i) { |
| 718 |
static const lFl c[NV] = {-14./3., |
| 719 |
2./3.,2./3.,2./3.,2./3.,2./3.,2./3., |
| 720 |
1./12.,1./12.,1./12.,1./12., |
| 721 |
1./12.,1./12.,1./12.,1./12.}; |
| 722 |
return c[i]; |
| 723 |
} |
| 724 |
}; |
| 725 |
*/ |
| 726 |
|
| 727 |
///D3Q27 vectorspace |
| 728 |
/** |
| 729 |
\image html t27.png "27-point templates" |
| 730 |
\image latex t27.png "27-point templates" width=8cm |
| 731 |
*/ |
| 732 |
/* class d3q27 { |
| 733 |
public: |
| 734 |
static const int ND=3; |
| 735 |
static const int NV=27; |
| 736 |
typedef Vec<ND,int> DV; |
| 737 |
inline static const DV & l(int i) { |
| 738 |
static const DV lat[NV] = { |
| 739 |
DV(0,0,0), DV(1,0,0), DV(0,1,0), |
| 740 |
DV(0,0,1), DV(-1,0,0), DV(0,-1,0), |
| 741 |
DV(0,0,-1), DV(1,1,0), DV(1,-1,0), |
| 742 |
DV(-1,-1,0), DV(-1,1,0), DV(0,1,1), |
| 743 |
DV(0,1,-1), DV(0,-1,-1), DV(0,-1,1), |
| 744 |
DV(1,0,1), DV(1,0,-1), DV(-1,0,-1), |
| 745 |
DV(-1,0,1), DV(1,1,1), DV(1,1,-1), |
| 746 |
DV(1,-1,1), DV(1,-1,-1), DV(-1,1,1), |
| 747 |
DV(-1,1,-1), DV(-1,-1,1), DV(-1,-1,-1) |
| 748 |
}; |
| 749 |
return lat[i]; |
| 750 |
} |
| 751 |
///number of the vector wich has oposite derection |
| 752 |
inline static int io(int i) { |
| 753 |
static const int inv[NV] = {0, |
| 754 |
4,5,6,1,2,3, |
| 755 |
9,10,7,8,13,14,11,12,17,18,15,16, |
| 756 |
26,25,24,23,22,21,20,19}; |
| 757 |
return inv[i]; |
| 758 |
} |
| 759 |
}; |
| 760 |
*/ |
| 761 |
|
| 762 |
///D1Q3 vectorspace |
| 763 |
/** |
| 764 |
\image html t3.png "3-point templates" |
| 765 |
\image latex t3.png "3-point templates" width=8cm |
| 766 |
*/ |
| 767 |
/* class d1q3 { |
| 768 |
public: |
| 769 |
static const int ND=1; ///<number of dimensions |
| 770 |
static const int NV=3; ///<nuber of directions |
| 771 |
typedef Vec<ND,int> DV; ///< type of lattice vector |
| 772 |
inline static const DV & l(int i) { /// Returns value of the lattice vector |
| 773 |
static const DV lat[NV] = {DV(0),DV(1),DV(-1)}; |
| 774 |
return lat[i]; |
| 775 |
} |
| 776 |
///number of the vector wich has oposite derection |
| 777 |
inline static int io(int i) { |
| 778 |
static const int inv[NV] = {0,2,1}; |
| 779 |
return inv[i]; |
| 780 |
} |
| 781 |
}; |
| 782 |
*/ |
| 783 |
|
| 784 |
///D1Q2 vectorspace |
| 785 |
/** |
| 786 |
\image html t2.png "2-point templates" |
| 787 |
\image latex t2.png "2-point templates" width=8cm |
| 788 |
*/ |
| 789 |
/* class d1q2 { |
| 790 |
public: |
| 791 |
static const int ND=1; ///<number of dimensions |
| 792 |
static const int NV=2; ///<nuber of directions |
| 793 |
typedef Vec<1,int> DV; ///< type of lattice vector |
| 794 |
inline static const DV & l(int i) { /// Returns value of the lattice vector |
| 795 |
static const DV lat[NV] = {DV(1),DV(-1)}; |
| 796 |
return lat[i]; |
| 797 |
} |
| 798 |
///number of the vector wich has oposite derection |
| 799 |
inline static int io(int i) { |
| 800 |
static const int inv[NV] = {1,0}; |
| 801 |
return inv[i]; |
| 802 |
} |
| 803 |
}; |
| 804 |
|
| 805 |
///Reflected template vector \f$ lrf(f)_i=f_{\tilde i}, \f$ \f$ \vec a_{\tilde i}=-\vec a_i \f$ |
| 806 |
template <typename Tl> inline Vec<Tl::NV> lrv(const Vec<Tl::NV> &f_) { |
| 807 |
Vec<Tl::NV> a; |
| 808 |
for (int i(0); i < Tl::NV; ++i) {a[i] =f_[Tl::io(i)];} |
| 809 |
return a; |
| 810 |
} |
| 811 |
|
| 812 |
template <typename Tl,int I> inline void _l1f_c(I2T<I>,Tl, const Vec<Tl::ND> &v_,Vec<Tl::NV> &a){ |
| 813 |
typedef typename Tl::SV SV; |
| 814 |
a[I] =SV()[I2T<I>()]*v_; _l1f_c(I2T<I-1>(),Tl(),v_,a); |
| 815 |
} |
| 816 |
template <typename Tl> inline void _l1f_c(I2T<0>,Tl, const Vec<Tl::ND> &v_,Vec<Tl::NV> &a){ |
| 817 |
typedef typename Tl::SV SV; |
| 818 |
a[0] =SV()[I2T<0>()]*v_; |
| 819 |
} |
| 820 |
|
| 821 |
///Creates template vector as scalar product with lattice vectors \f$ \vec a_i \vec v \f$ |
| 822 |
template <typename Tl> inline Vec<Tl::NV> l1f(const Vec<Tl::ND> &v_) { |
| 823 |
typedef Vec<Tl::ND> TV; |
| 824 |
Vec<Tl::NV> a; |
| 825 |
// for (int i(0); i < Tl::NV; ++i) {a[i] =TV(Tl::l(i))*v_;} |
| 826 |
_l1f_c(I2T<Tl::NV-1>(),Tl(),v_,a); |
| 827 |
return a; |
| 828 |
} |
| 829 |
|
| 830 |
template <typename Tl,int I> |
| 831 |
inline void _l2f_c(I2T<I>,Tl, const Vec<Tl::ND> &v1_, const Vec<Tl::ND> &v2_,Vec<Tl::NV> &a){ |
| 832 |
class Tl::SV q; a[I] =(q[I2T<I>()]*v1_)*(q[I2T<I>()]*v2_); _l2f_c(I2T<I-1>(),Tl(),v1_,v2_,a); |
| 833 |
} |
| 834 |
template <typename Tl> |
| 835 |
inline void _l2f_c(I2T<0>,Tl, const Vec<Tl::ND> &v1_, const Vec<Tl::ND> &v2_,Vec<Tl::NV> &a){ |
| 836 |
class Tl::SV q; a[0] =(q[I2T<0>()]*v1_)*(q[I2T<0>()]*v2_); |
| 837 |
} |
| 838 |
|
| 839 |
///Creates template vector as 2 scalar products with lattice vectors \f$ (\vec a_i \vec v_1) (\vec a_i \vec v_2) \f$ |
| 840 |
template <typename Tl> inline Vec<Tl::NV> l2f(const Vec<Tl::ND> &v1_, const Vec<Tl::ND> &v2_) { |
| 841 |
typedef Vec<Tl::ND> TV; |
| 842 |
Vec<Tl::NV> a; |
| 843 |
// for (int i(0); i < Tl::NV; ++i) {a[i] =(TV(Tl::l(i))*v1_)*(TV(Tl::l(i))*v2_);} |
| 844 |
_l2f_c(I2T<Tl::NV-1>(),Tl(),v1_,v2_,a); |
| 845 |
return a; |
| 846 |
} |
| 847 |
|
| 848 |
|
| 849 |
} // templ |
| 850 |
*/ |
| 851 |
}// asl |
| 852 |
|
| 853 |
#endif // TEMPL_H_INCLUDED |