| 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 "aslBCond.h" |
| 25 |
#include <acl/acl.h> |
| 26 |
#include <acl/DataTypes/aclMemBlock.h> |
| 27 |
#include <acl/aclGenerators.h> |
| 28 |
//#include <agl/aglPointsList.h> |
| 29 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 30 |
#include <math/aslTemplates.h> |
| 31 |
#include <data/aslDataWithGhostNodes.h> |
| 32 |
#include <aslGenerators.h> |
| 33 |
#include <math/aslTemplateVE.h> |
| 34 |
#include <math/aslDistanceFunctionAlg.h> |
| 35 |
|
| 36 |
namespace asl |
| 37 |
{ |
| 38 |
|
| 39 |
BCond::BCond(const Block & b): |
| 40 |
block(b), |
| 41 |
templ(nearestNeigboursVT(nD(b))) |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
BCond::BCond(const Block & b, const VectorTemplate *const t): |
| 46 |
block(b), |
| 47 |
templ(t) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
void BCond::addPoint(AVec<int> a,int d,double fr) |
| 52 |
{ |
| 53 |
indices.push_back(block.c2i(a)); |
| 54 |
directions.push_back(d); |
| 55 |
fractions.push_back(fr); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
void BCond::loadIndicesToACL() |
| 60 |
{ |
| 61 |
indicesACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices.size(),int(0))); |
| 62 |
acl::copy(indices,(*indicesACL)[0]); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
void BCond::loadDirectionsToACL() |
| 67 |
{ |
| 68 |
directionsACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices.size(),int(0))); |
| 69 |
acl::copy(directions,(*directionsACL)[0]); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
void BCond::loadNeighbourIndicesToACL() |
| 74 |
{ |
| 75 |
neighbourIndices.resize(indices.size()); |
| 76 |
for (unsigned int i(0); i < indices.size(); ++i) |
| 77 |
neighbourIndices[i] =indices[i]+block.c2i(templ->vectors[directions[i]]); |
| 78 |
|
| 79 |
neighbourIndicesACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices.size(),int(0))); |
| 80 |
acl::copy(neighbourIndices,(*neighbourIndicesACL)[0]); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
const Block& BCond::getBlock() |
| 85 |
{ |
| 86 |
return block; |
| 87 |
} |
| 88 |
|
| 89 |
BCondWithMap::BCondWithMap(SPAbstractDataWithGhostNodes m, const VectorTemplate * const vt): |
| 90 |
pointsListFlag(false), |
| 91 |
currentPoint(acl::generateVEIndex()), |
| 92 |
templ(vt), |
| 93 |
bl(m->getBlock()), |
| 94 |
map(m) |
| 95 |
{ |
| 96 |
unsigned int numD(nD(bl)); |
| 97 |
if(numD != 2 && numD != 3) |
| 98 |
errorMessage("BCondWithMap : the map has wrong dimensionality"); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
BCondWithMap::BCondWithMap(SPDistanceFunction m, |
| 103 |
const Block & b, |
| 104 |
const VectorTemplate * const vt): |
| 105 |
pointsListFlag(false), |
| 106 |
currentPoint(acl::generateVEIndex()), |
| 107 |
templ(vt), |
| 108 |
bl(b), |
| 109 |
mapDF(m) |
| 110 |
{ |
| 111 |
unsigned int numD(nD(bl)); |
| 112 |
if(numD != 2 && numD != 3) |
| 113 |
errorMessage("BCondWithMap : the map has wrong dimensionality"); |
| 114 |
} |
| 115 |
|
| 116 |
BCondWithMap::BCondWithMap(SPAbstractDataWithGhostNodes m, |
| 117 |
SPAbstractDataWithGhostNodes cd, |
| 118 |
const VectorTemplate * const vt): |
| 119 |
pointsListFlag(false), |
| 120 |
currentPoint(acl::generateVEIndex()), |
| 121 |
templ(vt), |
| 122 |
bl(m->getBlock()), |
| 123 |
map(m), |
| 124 |
computationalDomain(cd) |
| 125 |
{ |
| 126 |
unsigned int numD(nD(bl)); |
| 127 |
unsigned int numDcd(nD(computationalDomain->getBlock())); |
| 128 |
if(numD != numDcd) |
| 129 |
errorMessage("BCondWithMap : the map and computationalDomain has different dimensionality"); |
| 130 |
if(numD != 2 && numD != 3) |
| 131 |
errorMessage("BCondWithMap : the map has wrong dimensionality"); |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
BCondWithMap::BCondWithMap(SPAbstractDataWithGhostNodes m, |
| 136 |
SPDistanceFunction cd, |
| 137 |
const VectorTemplate * const vt): |
| 138 |
pointsListFlag(false), |
| 139 |
currentPoint(acl::generateVEIndex()), |
| 140 |
templ(vt), |
| 141 |
bl(m->getBlock()), |
| 142 |
map(m), |
| 143 |
computationalDomainDF(cd) |
| 144 |
{ |
| 145 |
unsigned int numD(nD(bl)); |
| 146 |
if(numD != 2 && numD != 3) |
| 147 |
errorMessage("BCondWithMap : the map has wrong dimensionality"); |
| 148 |
} |
| 149 |
|
| 150 |
BCondWithMap::BCondWithMap(SPDistanceFunction m, |
| 151 |
SPDistanceFunction cd, |
| 152 |
const Block & b, |
| 153 |
const VectorTemplate * const vt): |
| 154 |
pointsListFlag(false), |
| 155 |
currentPoint(acl::generateVEIndex()), |
| 156 |
templ(vt), |
| 157 |
bl(b), |
| 158 |
mapDF(m), |
| 159 |
computationalDomainDF(cd) |
| 160 |
{ |
| 161 |
unsigned int numD(nD(bl)); |
| 162 |
if(numD != 2 && numD != 3) |
| 163 |
errorMessage("BCondWithMap : the map has wrong dimensionality"); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
void BCondWithMap::initMapInfrastructure(acl::ExpressionContainer & ec) |
| 168 |
{ |
| 169 |
bool isMapDF(mapDF.get()!=0); |
| 170 |
bool isCDDF(computationalDomainDF.get()!=0); |
| 171 |
//todo!!!!!!!!!!!!!!!!!! |
| 172 |
if(isMapDF || isCDDF) |
| 173 |
{ |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
if(isMapDF) |
| 178 |
{ |
| 179 |
// mapTVE.reset(new TemplateVE(*mapDF,, *templ)); |
| 180 |
ec << mapTVE->initValues; |
| 181 |
|
| 182 |
} |
| 183 |
else |
| 184 |
{ |
| 185 |
auto mapX(generateDCFullSafe(map, -.9)); |
| 186 |
mapTVE.reset(new TemplateVE(*mapX, *templ)); |
| 187 |
// mapTVE.reset(new TemplateVE(*map, *templ)); |
| 188 |
ec << mapTVE->initValues; |
| 189 |
} |
| 190 |
bool isCompDom(computationalDomain.get()!=0); |
| 191 |
if(isCompDom) |
| 192 |
{ |
| 193 |
auto compDomX(generateDCFullSafe(computationalDomain, -1)); |
| 194 |
cDomainTVE.reset(new TemplateVE(*compDomX, *templ)); |
| 195 |
ec << cDomainTVE->initValues; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
acl::VectorOfElements BCondWithMap::isGhostNode(unsigned int i) |
| 200 |
{ |
| 201 |
return asl::isGhostNode(*mapTVE,i); |
| 202 |
} |
| 203 |
|
| 204 |
acl::VectorOfElements BCondWithMap::isComputationNode(unsigned int i) |
| 205 |
{ |
| 206 |
auto res(asl::isComputationNode(*mapTVE,i)); |
| 207 |
bool isCompDom(computationalDomain.get()!=0); |
| 208 |
if(isCompDom) |
| 209 |
copy(res && asl::isComputationNode(*cDomainTVE,i), res); |
| 210 |
return res; |
| 211 |
} |
| 212 |
|
| 213 |
acl::VectorOfElements BCondWithMap::isComputationNode(const vector<unsigned int> & ii) |
| 214 |
{ |
| 215 |
auto res(subVE(mapTVE->values,ii[0]) > 0.); |
| 216 |
for(unsigned int i(1); i < ii.size(); ++i) |
| 217 |
copy(res && (subVE(mapTVE->values,ii[i]) > 0.), res); |
| 218 |
bool isCompDom(computationalDomain.get()!=0); |
| 219 |
if(isCompDom) |
| 220 |
for(unsigned int i(0); i < ii.size(); ++i) |
| 221 |
copy(res && (acl::subVE(cDomainTVE->values,ii[i]) > 0.), res); |
| 222 |
return res; |
| 223 |
} |
| 224 |
|
| 225 |
acl::VectorOfElements BCondWithMap::isGhostNode() |
| 226 |
{ |
| 227 |
return (map->getEContainer() <= 0.); |
| 228 |
} |
| 229 |
|
| 230 |
acl::VectorOfElements BCondWithMap::isComputationNode() |
| 231 |
{ |
| 232 |
auto res(map->getEContainer() > 0.); |
| 233 |
bool isCompDom(computationalDomain.get()!=0); |
| 234 |
if(isCompDom) |
| 235 |
copy(res && (computationalDomain->getEContainer() > 0.), res); |
| 236 |
return res; |
| 237 |
} |
| 238 |
|
| 239 |
BCondSlice::BCondSlice(const Block & b): |
| 240 |
block(b), |
| 241 |
templ(NULL) |
| 242 |
{ |
| 243 |
} |
| 244 |
|
| 245 |
BCondSlice::BCondSlice(const Block & b, const VectorTemplate *const t): |
| 246 |
block(b), |
| 247 |
templ(t) |
| 248 |
{ |
| 249 |
} |
| 250 |
|
| 251 |
inline unsigned int count0(const AVec<int> &a) |
| 252 |
{ |
| 253 |
unsigned int n(0); |
| 254 |
for (unsigned int i(0); i < nD(a); ++i) |
| 255 |
n+=a[i] ==0?1:0; |
| 256 |
return n; |
| 257 |
} |
| 258 |
|
| 259 |
void BCondSlice::addGhostSlice(AVec<int> pB,AVec<int> pE,int d) |
| 260 |
{ |
| 261 |
pointB=block.c2i(pB); |
| 262 |
pointE=block.c2i(pE); |
| 263 |
direction=d; |
| 264 |
AVec<int> dif (pE-pB); |
| 265 |
unsigned int n(count0(dif)); |
| 266 |
sliceDimentions.resize(n); |
| 267 |
sliceIncrements.resize(n); |
| 268 |
for (unsigned int i(0),k(0); i < nD(dif); ++i){ |
| 269 |
sliceDimentions[k] =dif[i]; |
| 270 |
sliceIncrements[k] =block.c2iTransformVector[i]; |
| 271 |
k+=dif[i] ==0?0:1; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
const Block& BCondSlice::getBlock() |
| 276 |
{ |
| 277 |
return block; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
BCondConnector::BCondConnector(const Block & b1, const Block & b2): |
| 282 |
block1(b1), |
| 283 |
block2(b2) |
| 284 |
{ |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
void BCondConnector::addGhostPoint(AVec<int> a1,AVec<int> a2) |
| 289 |
{ |
| 290 |
indices1.push_back(block1.c2i(a1)); |
| 291 |
directions1.push_back(0); |
| 292 |
indices2.push_back(block2.c2i(a2)); |
| 293 |
directions2.push_back(0); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
void BCondConnector::addGhostPoint(AVec<int> a1,int d1,AVec<int> a2,int d2) |
| 298 |
{ |
| 299 |
indices1.push_back(block1.c2i(a1)); |
| 300 |
directions1.push_back(d1); |
| 301 |
indices2.push_back(block2.c2i(a2)); |
| 302 |
directions2.push_back(d2); |
| 303 |
} |
| 304 |
|
| 305 |
const Block & BCondConnector::getBlock1() |
| 306 |
{ |
| 307 |
return block1; |
| 308 |
} |
| 309 |
|
| 310 |
const Block & BCondConnector::getBlock2() |
| 311 |
{ |
| 312 |
return block2; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
void BCondConnector::loadIndicesToACL() |
| 317 |
{ |
| 318 |
indices1ACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices1.size(),int(0))); |
| 319 |
acl::copy(indices1,(*indices1ACL)[0]); |
| 320 |
indices2ACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices2.size(),int(0))); |
| 321 |
acl::copy(indices2,(*indices2ACL)[0]); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
void BCondConnector::loadDirectionsToACL() |
| 326 |
{ |
| 327 |
directions1ACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices1.size(),int(0))); |
| 328 |
acl::copy(directions1,(*directions1ACL)[0]); |
| 329 |
directions2ACL=acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,indices2.size(),int(0))); |
| 330 |
acl::copy(directions2,(*directions2ACL)[0]); |
| 331 |
} |
| 332 |
|
| 333 |
BCondConnectorSlice::BCondConnectorSlice(const Block & b1, const Block & b2, const VectorTemplate *const t): |
| 334 |
block1(b1), |
| 335 |
block2(b2), |
| 336 |
templ(t) |
| 337 |
{ |
| 338 |
} |
| 339 |
|
| 340 |
void BCondConnectorSlice::addGhostSlice1(AVec<int> pB,AVec<int> pE,int d) |
| 341 |
{ |
| 342 |
point1B=block1.c2i(pB); |
| 343 |
point1E=block1.c2i(pE); |
| 344 |
direction1=d; |
| 345 |
AVec<int> dif (pE-pB); |
| 346 |
unsigned int n(count0(dif)); |
| 347 |
sliceDimentions1.resize(n); |
| 348 |
sliceIncrements1.resize(n); |
| 349 |
for (unsigned int i(0),k(0); i < nD(dif); ++i){ |
| 350 |
sliceDimentions1[k] =dif[i]; |
| 351 |
sliceIncrements1[k] =block1.c2iTransformVector[i]; |
| 352 |
k+=dif[i] ==0?0:1; |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
void BCondConnectorSlice::addGhostSlice2(AVec<int> pB,AVec<int> pE,int d) |
| 358 |
{ |
| 359 |
point2B=block1.c2i(pB); |
| 360 |
point2E=block1.c2i(pE); |
| 361 |
direction2=d; |
| 362 |
AVec<int> dif (pE-pB); |
| 363 |
unsigned int n(count0(dif)); |
| 364 |
sliceDimentions2.resize(n); |
| 365 |
sliceIncrements2.resize(n); |
| 366 |
for (unsigned int i(0),k(0); i < nD(dif); ++i){ |
| 367 |
sliceDimentions2[k] =dif[i]; |
| 368 |
sliceIncrements2[k] =block2.c2iTransformVector[i]; |
| 369 |
k+=dif[i] ==0?0:1; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
void addSliceX0(BCond & a) |
| 374 |
{ |
| 375 |
const AVec<int> & s(a.getBlock().getSize()); |
| 376 |
const VectorTemplate * vt(a.getVT()); |
| 377 |
if (nD(s)==2){ |
| 378 |
AVec<int> dir(vt->vectors[1]); |
| 379 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 380 |
if(vt->vectors[k]*dir>0) |
| 381 |
for (int i(1); i < s[1]-1; ++i) |
| 382 |
a.addPoint(makeAVec (1,i)-vt->vectors[k],k); |
| 383 |
} |
| 384 |
else |
| 385 |
if (nD(s)==3){ |
| 386 |
AVec<int> dir(vt->vectors[1]); |
| 387 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 388 |
if(vt->vectors[k]*dir>0) |
| 389 |
for (int i(1); i < s[1]-1; ++i) |
| 390 |
for (int j(1);j<s[2]-1;++j) |
| 391 |
a.addPoint(makeAVec (1,i,j)-vt->vectors[k],k); |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
void addSliceXE(BCond & a) |
| 397 |
{ |
| 398 |
const AVec<int> & s(a.getBlock().getSize()); |
| 399 |
const VectorTemplate * vt(a.getVT()); |
| 400 |
if (nD(s)==2){ |
| 401 |
AVec<int> dir(vt->vectors[3]); |
| 402 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 403 |
if(vt->vectors[k]*dir>0) |
| 404 |
for (int i(1); i < s[1]-1; ++i) |
| 405 |
a.addPoint(makeAVec (s[0]-2,i)-vt->vectors[k],k); |
| 406 |
} |
| 407 |
else |
| 408 |
if (nD(s)==3){ |
| 409 |
AVec<int> dir(vt->vectors[4]); |
| 410 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 411 |
if(vt->vectors[k]*dir>0) |
| 412 |
for (int i(1); i < s[1]-1; ++i) |
| 413 |
for (int j(1);j<s[2]-1;++j) |
| 414 |
a.addPoint(makeAVec (s[0]-2,i,j)-vt->vectors[k],k); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
void addSliceY0(BCond & a) |
| 420 |
{ |
| 421 |
const AVec<int> & s(a.getBlock().getSize()); |
| 422 |
const VectorTemplate * vt(a.getVT()); |
| 423 |
if (nD(s)==2){ |
| 424 |
AVec<int> dir(vt->vectors[2]); |
| 425 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 426 |
if(vt->vectors[k]*dir>0) |
| 427 |
for (int i(1); i < s[0]-1; ++i) |
| 428 |
a.addPoint(makeAVec (i,1)-vt->vectors[k],k); |
| 429 |
} |
| 430 |
else |
| 431 |
if (nD(s)==3){ |
| 432 |
AVec<int> dir(vt->vectors[2]); |
| 433 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 434 |
if(vt->vectors[k]*dir>0) |
| 435 |
for (int i(1); i < s[0]-1; ++i) |
| 436 |
for (int j(1);j < s[2]-1;++j) |
| 437 |
a.addPoint(makeAVec (i,1,j)-vt->vectors[k],k); |
| 438 |
} |
| 439 |
|
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
void addSliceYE(BCond & a) |
| 444 |
{ |
| 445 |
const AVec<int> & s(a.getBlock().getSize()); |
| 446 |
const VectorTemplate * vt(a.getVT()); |
| 447 |
if (nD(s)==2){ |
| 448 |
AVec<int> dir(vt->vectors[4]); |
| 449 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 450 |
if(vt->vectors[k]*dir>0) |
| 451 |
for (int i(1); i < s[0]-1; ++i) |
| 452 |
a.addPoint(makeAVec (i,s[1]-2)-vt->vectors[k],k); |
| 453 |
}else |
| 454 |
if (nD(s)==3){ |
| 455 |
AVec<int> dir(vt->vectors[5]); |
| 456 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 457 |
if(vt->vectors[k]*dir>0) |
| 458 |
for (int i(1); i < s[0]-1; ++i) |
| 459 |
for (int j(1); j < s[2]-1; ++j) |
| 460 |
a.addPoint(makeAVec (i,s[1]-2,j)-vt->vectors[k],k); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
void addSliceZ0(BCond & a) |
| 466 |
{ |
| 467 |
const AVec<int> & s(a.getBlock().getSize()); |
| 468 |
const VectorTemplate * vt(a.getVT()); |
| 469 |
if (nD(s)==3){ |
| 470 |
AVec<int> dir(vt->vectors[3]); |
| 471 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 472 |
if(vt->vectors[k]*dir>0) |
| 473 |
for (int i(1); i < s[0]-1; ++i) |
| 474 |
for (int j(1); j < s[1]-1; ++j) |
| 475 |
a.addPoint(makeAVec (i,j,1)-vt->vectors[k],k); |
| 476 |
} |
| 477 |
|
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
void addSliceZE(BCond & a) |
| 482 |
{ |
| 483 |
const AVec<int> & s(a.getBlock().getSize()); |
| 484 |
const VectorTemplate * vt(a.getVT()); |
| 485 |
if (nD(s)==3){ |
| 486 |
AVec<int> dir(vt->vectors[6]); |
| 487 |
for (unsigned int k(1); k<vt->vectors.size(); ++k) |
| 488 |
if(vt->vectors[k]*dir>0) |
| 489 |
for (int i(1); i < s[0]-1; ++i) |
| 490 |
for (int j(1);j<s[1]-1;++j) |
| 491 |
a.addPoint(makeAVec (i,j,s[2]-2)-vt->vectors[k],k); |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
void addSlices(BCond & bc, const vector<SlicesNames> & sl) |
| 496 |
{ |
| 497 |
if(find(sl.begin(), sl.end(), X0) != sl.end()) |
| 498 |
addSliceX0(bc); |
| 499 |
if(find(sl.begin(), sl.end(), XE) != sl.end()) |
| 500 |
addSliceXE(bc); |
| 501 |
if(find(sl.begin(), sl.end(), Y0) != sl.end()) |
| 502 |
addSliceY0(bc); |
| 503 |
if(find(sl.begin(), sl.end(), YE) != sl.end()) |
| 504 |
addSliceYE(bc); |
| 505 |
if(find(sl.begin(), sl.end(), Z0) != sl.end()) |
| 506 |
addSliceZ0(bc); |
| 507 |
if(find(sl.begin(), sl.end(), ZE) != sl.end()) |
| 508 |
addSliceZE(bc); |
| 509 |
|
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
void addSliceX(BCond & a, int x) |
| 514 |
{ |
| 515 |
const AVec<int> & s(a.getBlock().getSize()); |
| 516 |
if (nD(s)==2){ |
| 517 |
for (int i(0); i < s[1]; ++i) |
| 518 |
a.addPoint(makeAVec (x,i)); |
| 519 |
} |
| 520 |
else |
| 521 |
if (nD(s)==3){ |
| 522 |
for (int i(0); i < s[1]; ++i) |
| 523 |
for (int j(0);j<s[2];++j) |
| 524 |
a.addPoint(makeAVec (x,i,j)); |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
void addSliceY(BCond & a, int y) |
| 529 |
{ |
| 530 |
const AVec<int> & s(a.getBlock().getSize()); |
| 531 |
if (nD(s)==2){ |
| 532 |
for (int i(0); i < s[0]; ++i) |
| 533 |
a.addPoint(makeAVec (i,y)); |
| 534 |
} |
| 535 |
else |
| 536 |
if (nD(s)==3){ |
| 537 |
for (int i(0); i < s[0]; ++i) |
| 538 |
for (int j(0);j<s[2];++j) |
| 539 |
a.addPoint(makeAVec (i,y,j)); |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
void addSliceZ(BCond & a, int z) |
| 544 |
{ |
| 545 |
const AVec<int> & s(a.getBlock().getSize()); |
| 546 |
if (nD(s)==2){ |
| 547 |
asl::errorMessage("addSliceZ: The data dimensionality is 2"); |
| 548 |
} |
| 549 |
else |
| 550 |
if (nD(s)==3){ |
| 551 |
for (int i(0); i < s[0]; ++i) |
| 552 |
for (int j(0);j<s[1];++j) |
| 553 |
a.addPoint(makeAVec (i,j,z)); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
void addSliceX0(BCondSlice & a) |
| 559 |
{ |
| 560 |
const AVec<int> & s(a.getBlock().getSize()); |
| 561 |
if (nD(s)==2) |
| 562 |
a.addGhostSlice(makeAVec(0,0),makeAVec(0,s[1]),1); |
| 563 |
else |
| 564 |
if (nD(s)==3) |
| 565 |
a.addGhostSlice(makeAVec(0,0,0),makeAVec(0,s[1],s[2]),1); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
void addSliceXE(BCondSlice & a) |
| 570 |
{ |
| 571 |
const AVec<int> & s(a.getBlock().getSize()); |
| 572 |
if (nD(s)==2) |
| 573 |
a.addGhostSlice(makeAVec(s[0],0),makeAVec(s[0],s[1]),3); |
| 574 |
else |
| 575 |
if (nD(s)==3) |
| 576 |
a.addGhostSlice(makeAVec(s[0],0,0),makeAVec(s[0],s[1],s[2]),4); |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
void addSliceY0(BCondSlice & a) |
| 581 |
{ |
| 582 |
const AVec<int> & s(a.getBlock().getSize()); |
| 583 |
if (nD(s)==2) |
| 584 |
a.addGhostSlice(makeAVec(0,0),makeAVec(s[0],0),2); |
| 585 |
else |
| 586 |
if (nD(s)==3) |
| 587 |
a.addGhostSlice(makeAVec(0,0,0),makeAVec(s[0],0,s[2]),2); |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
void addSliceYE(BCondSlice & a) |
| 592 |
{ |
| 593 |
const AVec<int> & s(a.getBlock().getSize()); |
| 594 |
if (nD(s)==2) |
| 595 |
a.addGhostSlice(makeAVec(0,s[1]),makeAVec(s[0],s[1]),4); |
| 596 |
else |
| 597 |
if (nD(s)==3) |
| 598 |
a.addGhostSlice(makeAVec(0,s[1],0),makeAVec(s[0],s[1],s[2]),5); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
void addSliceZ0(BCondSlice & a) |
| 603 |
{ |
| 604 |
const AVec<int> & s(a.getBlock().getSize()); |
| 605 |
if (nD(s)<3) |
| 606 |
errorMessage ("addSliceZ0: The block dimensionality is less than 3"); |
| 607 |
else |
| 608 |
if (nD(s)==3) |
| 609 |
a.addGhostSlice(makeAVec(0,0,0),makeAVec(s[0],s[1],0),3); |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
void addSliceZE(BCondSlice & a) |
| 614 |
{ |
| 615 |
const AVec<int> & s(a.getBlock().getSize()); |
| 616 |
if (nD(s)<3) |
| 617 |
errorMessage ("addSliceZE: The block dimensionality is less than 3"); |
| 618 |
else |
| 619 |
if (nD(s)==3) |
| 620 |
a.addGhostSlice(makeAVec(0,0,s[2]),makeAVec(s[0],s[1],s[2]),6); |
| 621 |
} |
| 622 |
|
| 623 |
/// checks intersection of a litice vector with a plane |
| 624 |
/** |
| 625 |
\param p0 point on the plane |
| 626 |
\param n plane normal |
| 627 |
\param pn current node |
| 628 |
\param templ the used template |
| 629 |
\param dir number of direction |
| 630 |
*/ |
| 631 |
inline bool checkIntersection(const AVec<> & p0, |
| 632 |
const AVec<> & n, |
| 633 |
const AVec<> & pn, |
| 634 |
const VectorTemplate * templ, |
| 635 |
unsigned int dir) |
| 636 |
{ |
| 637 |
double x(((p0-pn)*n)/(n*AVec<>(templ->vectors[dir]))); |
| 638 |
return x>0 && x<1; |
| 639 |
} |
| 640 |
|
| 641 |
/// adds a point to a BCond object |
| 642 |
/** |
| 643 |
\param p0 point on the plane |
| 644 |
\param n plane normal |
| 645 |
\param pn current node |
| 646 |
\param templ the used template |
| 647 |
\param dir number of direction |
| 648 |
*/ |
| 649 |
inline void addPointToBC(BCond & bc, |
| 650 |
const AVec<> & p0, |
| 651 |
const AVec<> & n, |
| 652 |
const AVec<int> & pn) |
| 653 |
{ |
| 654 |
if (in(bc.getBlock(),pn)) |
| 655 |
{ |
| 656 |
AVec<> r(AVec<>(pn)*bc.getBlock().dx+bc.getBlock().position); |
| 657 |
double dist((r-p0)*n); |
| 658 |
if (dist<=0 && dist>2.) |
| 659 |
for(unsigned int i(0); i<bc.getVT()->vectors.size();++i) |
| 660 |
if (checkIntersection(p0,n,r,bc.getVT(),i)) |
| 661 |
bc.addPoint(pn,i); |
| 662 |
} |
| 663 |
|
| 664 |
} |
| 665 |
|
| 666 |
/* void addAGLObject(BCond & bc, agl::SPPointsList geom) |
| 667 |
{ |
| 668 |
unsigned int maxId(geom->maxId()); |
| 669 |
for (unsigned int i(0); i < maxId; geom->next(i)) |
| 670 |
{ |
| 671 |
AVec<> p0(geom->getPoint(i)); |
| 672 |
AVec<int> pn0(asl::round((p0-bc.getBlock().position)/bc.getBlock().dx)); |
| 673 |
for(unsigned int i(0); i<bc.getVT()->vectors.size(); ++i) |
| 674 |
{ |
| 675 |
AVec<int> pn(pn0+bc.getVT()->vectors[i]); |
| 676 |
addPointToBC(bc, geom->getPoint(i), geom->getSurfaceNormal(i), pn); |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
*/ |
| 681 |
} // asl |
| 682 |
|