/usr/include/palabos/offLattice/triangleHash.hh is in libplb-dev 1.5~r1+repack1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | /* This file is part of the Palabos library.
*
* Copyright (C) 2011-2015 FlowKit Sarl
* Route d'Oron 2
* 1010 Lausanne, Switzerland
* E-mail contact: contact@flowkit.com
*
* The most recent release of Palabos can be downloaded at
* <http://www.palabos.org/>
*
* The library Palabos is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* The library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRIANGLE_HASH_HH
#define TRIANGLE_HASH_HH
#include "core/globalDefs.h"
#include "offLattice/triangleHash.h"
#include "atomicBlock/reductiveDataProcessingFunctional3D.h"
#include "atomicBlock/atomicContainerBlock3D.h"
#include <algorithm>
namespace plb {
struct TriangleHashData : public ContainerBlockData {
TriangleHashData (
plint nx, plint ny, plint nz,
Dot3D const& location )
: triangles(nx,ny,nz)
{
triangles.setLocation(location);
}
virtual TriangleHashData* clone() const {
return new TriangleHashData(*this);
}
ScalarField3D<std::vector<plint> > triangles;
std::vector<Dot3D> assignedPositions;
};
/* ******** class TriangleHash ********************************************* */
template<typename T>
TriangleHash<T>::TriangleHash(AtomicContainerBlock3D& hashContainer)
: triangles (
dynamic_cast<TriangleHashData*>(hashContainer.getData())->triangles ),
assignedPositions (
dynamic_cast<TriangleHashData*>(hashContainer.getData())->assignedPositions )
{ }
template<typename T>
void TriangleHash<T>::getTriangles (
Array<T,2> const& xRange,
Array<T,2> const& yRange,
Array<T,2> const& zRange,
std::vector<plint>& foundTriangles ) const
{
// Fit onto the grid by making it bigger, to be sure the triangle
// is never missed through round-off errors.
Box3D discreteRange (
(plint)xRange[0], (plint)xRange[1]+1,
(plint)yRange[0], (plint)yRange[1]+1,
(plint)zRange[0], (plint)zRange[1]+1 );
getTriangles(discreteRange, foundTriangles);
}
template<typename T>
void TriangleHash<T>::getTriangles (
Box3D const& domain,
std::vector<plint>& foundTriangles ) const
{
Dot3D location(triangles.getLocation());
// Convert to local coordinates.
Box3D shifted(domain.shift(-location.x,-location.y,-location.z));
foundTriangles.clear();
Box3D inters;
if (intersect(shifted, triangles.getBoundingBox(), inters)) {
for (plint iX=inters.x0; iX<=inters.x1; ++iX) {
for (plint iY=inters.y0; iY<=inters.y1; ++iY) {
for (plint iZ=inters.z0; iZ<=inters.z1; ++iZ) {
std::vector<plint> const& newTriangles = triangles.get(iX,iY,iZ);
foundTriangles.insert(foundTriangles.end(),
newTriangles.begin(), newTriangles.end());
}
}
}
std::sort(foundTriangles.begin(), foundTriangles.end());
foundTriangles.erase( unique(foundTriangles.begin(), foundTriangles.end()),
foundTriangles.end() );
}
}
template<typename T>
void TriangleHash<T>::assignTriangles (
TriangularSurfaceMesh<T> const& mesh )
{
Dot3D location(triangles.getLocation());
assignedPositions.clear();
for (plint iTriangle=0; iTriangle<mesh.getNumTriangles(); ++iTriangle)
{
Array<T,3> const& vertex0 = mesh.getVertex(iTriangle, 0);
Array<T,3> const& vertex1 = mesh.getVertex(iTriangle, 1);
Array<T,3> const& vertex2 = mesh.getVertex(iTriangle, 2);
Array<T,2> xRange (
std::min(vertex0[0], std::min(vertex1[0], vertex2[0])),
std::max(vertex0[0], std::max(vertex1[0], vertex2[0])) );
Array<T,2> yRange (
std::min(vertex0[1], std::min(vertex1[1], vertex2[1])),
std::max(vertex0[1], std::max(vertex1[1], vertex2[1])) );
Array<T,2> zRange (
std::min(vertex0[2], std::min(vertex1[2], vertex2[2])),
std::max(vertex0[2], std::max(vertex1[2], vertex2[2])) );
// Fit onto the grid by making it bigger, to be sure the triangle
// is never missed through round-off errors.
Box3D discreteRange (
(plint)xRange[0], (plint)xRange[1]+1,
(plint)yRange[0], (plint)yRange[1]+1,
(plint)zRange[0], (plint)zRange[1]+1 );
// Convert to local coordinates.
discreteRange = discreteRange.shift (
-location.x, -location.y, -location.z );
Box3D inters;
if (intersect(discreteRange, triangles.getBoundingBox(), inters))
{
for (plint iX=inters.x0; iX<=inters.x1; ++iX) {
for (plint iY=inters.y0; iY<=inters.y1; ++iY) {
for (plint iZ=inters.z0; iZ<=inters.z1; ++iZ) {
if (triangles.get(iX,iY,iZ).empty()) {
assignedPositions.push_back(Dot3D(iX,iY,iZ));
}
triangles.get(iX,iY,iZ).push_back(iTriangle);
}
}
}
}
}
}
template<typename T>
template<class ParticleFieldT>
void TriangleHash<T>::reAssignTriangles (
TriangularSurfaceMesh<T> const& mesh,
ParticleFieldT& particles,
std::vector<plint> const& nonParallelVertices )
{
// Create domain from which particles are going to be retrieved.
Box3D domain(triangles.getBoundingBox());
// First of all, remove old triangles.
/*
for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
triangles.get(iX,iY,iZ).clear();
}
}
}
*/
for (pluint iAssigned=0; iAssigned<assignedPositions.size(); ++iAssigned) {
Dot3D pos(assignedPositions[iAssigned]);
triangles.get(pos.x,pos.y,pos.z).clear();
}
assignedPositions.clear();
// Particles have a bigger envelope than triangles (which have
// envelope with 2 for Guo for example). The domain must now
// be translated into the local coordinates of the particles.
Dot3D offset = computeRelativeDisplacement(triangles, particles);
domain = domain.shift(offset.x,offset.y,offset.z);
// Enlarge by one cell, because triangles belong to the hash of
// a given AtomicBlock even when one of their vertices is out-
// side the AtomicBlock by maximally one cell.
domain.enlarge(1);
std::vector<typename ParticleFieldT::ParticleT*> found;
particles.findParticles(domain, found);
std::set<plint> triangleIds;
for (pluint iParticle=0; iParticle<found.size(); ++iParticle) {
plint vertexId = found[iParticle]->getTag();
std::vector<plint> newTriangles (
mesh.getNeighborTriangleIds(vertexId) );
triangleIds.insert(newTriangles.begin(), newTriangles.end());
}
for (pluint iVertex=0; iVertex<nonParallelVertices.size(); ++iVertex) {
plint vertexId = nonParallelVertices[iVertex];
std::vector<plint> newTriangles (
mesh.getNeighborTriangleIds(vertexId) );
triangleIds.insert(newTriangles.begin(), newTriangles.end());
}
Dot3D location(triangles.getLocation());
std::set<plint>::const_iterator it = triangleIds.begin();
for (; it != triangleIds.end(); ++it) {
plint iTriangle = *it;
Array<T,3> const& vertex0 = mesh.getVertex(iTriangle, 0);
Array<T,3> const& vertex1 = mesh.getVertex(iTriangle, 1);
Array<T,3> const& vertex2 = mesh.getVertex(iTriangle, 2);
Array<T,2> xRange (
std::min(vertex0[0], std::min(vertex1[0], vertex2[0])),
std::max(vertex0[0], std::max(vertex1[0], vertex2[0])) );
Array<T,2> yRange (
std::min(vertex0[1], std::min(vertex1[1], vertex2[1])),
std::max(vertex0[1], std::max(vertex1[1], vertex2[1])) );
Array<T,2> zRange (
std::min(vertex0[2], std::min(vertex1[2], vertex2[2])),
std::max(vertex0[2], std::max(vertex1[2], vertex2[2])) );
// Fit onto the grid by making it bigger, to be sure the triangle
// is never missed through round-off errors.
Box3D discreteRange (
(plint)xRange[0], (plint)xRange[1]+1,
(plint)yRange[0], (plint)yRange[1]+1,
(plint)zRange[0], (plint)zRange[1]+1 );
// Convert to local coordinates.
discreteRange = discreteRange.shift (
-location.x, -location.y, -location.z );
Box3D inters;
if (intersect(discreteRange, triangles.getBoundingBox(), inters))
{
for (plint iX=inters.x0; iX<=inters.x1; ++iX) {
for (plint iY=inters.y0; iY<=inters.y1; ++iY) {
for (plint iZ=inters.z0; iZ<=inters.z1; ++iZ) {
if (triangles.get(iX,iY,iZ).empty()) {
assignedPositions.push_back(Dot3D(iX,iY,iZ));
}
triangles.get(iX,iY,iZ).push_back(iTriangle);
}
}
}
}
}
}
template<typename T>
void TriangleHash<T>::bruteReAssignTriangles (
TriangularSurfaceMesh<T> const& mesh )
{
PLB_ASSERT(false);
// First of all, remove old triangles.
Box3D domain(triangles.getBoundingBox());
for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
triangles.get(iX,iY,iZ).clear();
}
}
}
Dot3D location(triangles.getLocation());
for (plint iTriangle=0; iTriangle<mesh.getNumTriangles(); ++iTriangle)
{
if (mesh.isValidVertex(iTriangle,0) &&
mesh.isValidVertex(iTriangle,1) &&
mesh.isValidVertex(iTriangle,2) )
{
Array<T,3> const& vertex0 = mesh.getVertex(iTriangle, 0);
Array<T,3> const& vertex1 = mesh.getVertex(iTriangle, 1);
Array<T,3> const& vertex2 = mesh.getVertex(iTriangle, 2);
Array<T,2> xRange (
std::min(vertex0[0], std::min(vertex1[0], vertex2[0])),
std::max(vertex0[0], std::max(vertex1[0], vertex2[0])) );
Array<T,2> yRange (
std::min(vertex0[1], std::min(vertex1[1], vertex2[1])),
std::max(vertex0[1], std::max(vertex1[1], vertex2[1])) );
Array<T,2> zRange (
std::min(vertex0[2], std::min(vertex1[2], vertex2[2])),
std::max(vertex0[2], std::max(vertex1[2], vertex2[2])) );
// Fit onto the grid by making it bigger, to be sure the triangle
// is never missed through round-off errors.
Box3D discreteRange (
(plint)xRange[0], (plint)xRange[1]+1,
(plint)yRange[0], (plint)yRange[1]+1,
(plint)zRange[0], (plint)zRange[1]+1 );
// Convert to local coordinates.
discreteRange = discreteRange.shift (
-location.x, -location.y, -location.z );
Box3D inters;
if (intersect(discreteRange, triangles.getBoundingBox(), inters))
{
for (plint iX=inters.x0; iX<=inters.x1; ++iX) {
for (plint iY=inters.y0; iY<=inters.y1; ++iY) {
for (plint iZ=inters.z0; iZ<=inters.z1; ++iZ) {
triangles.get(iX,iY,iZ).push_back(iTriangle);
}
}
}
}
}
}
}
/* ******** CreateTriangleHash ************************************ */
template<typename T>
CreateTriangleHash<T>::CreateTriangleHash (
TriangularSurfaceMesh<T> const& mesh_ )
: mesh(mesh_)
{ }
template<typename T>
void CreateTriangleHash<T>::processGenericBlocks (
Box3D domain, std::vector<AtomicBlock3D*> blocks )
{
PLB_PRECONDITION( blocks.size()==1 );
AtomicContainerBlock3D* container =
dynamic_cast<AtomicContainerBlock3D*>(blocks[0]);
PLB_ASSERT( container );
TriangleHashData* hashData
= new TriangleHashData (
container->getNx(), container->getNy(), container->getNz(),
container->getLocation() );
container->setData(hashData);
TriangleHash<T>(*container).assignTriangles(mesh);
}
template<typename T>
CreateTriangleHash<T>* CreateTriangleHash<T>::clone() const {
return new CreateTriangleHash<T>(*this);
}
template<typename T>
void CreateTriangleHash<T>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
modified[0] = modif::staticVariables; // Container Block with hash data.
}
template<typename T>
BlockDomain::DomainT CreateTriangleHash<T>::appliesTo() const {
return BlockDomain::bulk;
}
/* ******** ReAssignTriangleHash ************************************ */
template<typename T, class ParticleFieldT>
ReAssignTriangleHash<T,ParticleFieldT>::ReAssignTriangleHash (
TriangularSurfaceMesh<T> const& mesh_,
std::vector<plint> const& nonParallelVertices_ )
: mesh(mesh_),
nonParallelVertices(nonParallelVertices_)
{ }
template<typename T, class ParticleFieldT>
void ReAssignTriangleHash<T,ParticleFieldT>::processGenericBlocks (
Box3D domain, std::vector<AtomicBlock3D*> blocks )
{
PLB_PRECONDITION( blocks.size()==2 );
AtomicContainerBlock3D* container =
dynamic_cast<AtomicContainerBlock3D*>(blocks[0]);
PLB_ASSERT( container );
ParticleFieldT* particles =
dynamic_cast<ParticleFieldT*>(blocks[1]);
PLB_ASSERT( particles );
TriangleHash<T>(*container).reAssignTriangles (
mesh,*particles,nonParallelVertices);
}
template<typename T, class ParticleFieldT>
ReAssignTriangleHash<T,ParticleFieldT>* ReAssignTriangleHash<T,ParticleFieldT>::clone() const {
return new ReAssignTriangleHash<T,ParticleFieldT>(*this);
}
template<typename T, class ParticleFieldT>
void ReAssignTriangleHash<T,ParticleFieldT>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
modified[0] = modif::staticVariables; // Container Block with hash data.
modified[1] = modif::nothing; // Vertex-Particles.
}
template<typename T, class ParticleFieldT>
BlockDomain::DomainT ReAssignTriangleHash<T,ParticleFieldT>::appliesTo() const {
return BlockDomain::bulk;
}
/* ******** BruteReAssignTriangleHash ************************************ */
template<typename T>
BruteReAssignTriangleHash<T>::BruteReAssignTriangleHash (
TriangularSurfaceMesh<T> const& mesh_ )
: mesh(mesh_)
{ }
template<typename T>
void BruteReAssignTriangleHash<T>::processGenericBlocks (
Box3D domain, std::vector<AtomicBlock3D*> blocks )
{
PLB_PRECONDITION( blocks.size()==1 );
AtomicContainerBlock3D* container =
dynamic_cast<AtomicContainerBlock3D*>(blocks[0]);
PLB_ASSERT( container );
TriangleHash<T>(*container).bruteReAssignTriangles(mesh);
}
template<typename T>
BruteReAssignTriangleHash<T>* BruteReAssignTriangleHash<T>::clone() const {
return new BruteReAssignTriangleHash<T>(*this);
}
template<typename T>
void BruteReAssignTriangleHash<T>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
modified[0] = modif::staticVariables; // Container Block with hash data.
modified[1] = modif::nothing; // Vertex-Particles.
}
template<typename T>
BlockDomain::DomainT BruteReAssignTriangleHash<T>::appliesTo() const {
return BlockDomain::bulk;
}
} // namespace plb
#endif // TRIANGLE_HASH_HH
|