$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

offLatticeBoundaryProcessor3D.hh

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #ifndef OFF_LATTICE_BOUNDARY_PROCESSOR_3D_HH
00026 #define OFF_LATTICE_BOUNDARY_PROCESSOR_3D_HH
00027 
00028 #include "offLattice/offLatticeBoundaryProcessor3D.h"
00029 #include "offLattice/nextNeighbors3D.h"
00030 #include <algorithm>
00031 #include <cmath>
00032 
00033 namespace plb {
00034 
00035 template<typename T>
00036 CheckVoxelizationFunctional3D<T>::
00037     CheckVoxelizationFunctional3D (
00038             BoundaryShape3D<T,Array<T,3> >* shape_, int flowType_ )
00039   : numErrorsId(this->getStatistics().subscribeIntSum()),
00040     shape(shape_),
00041     flowType(flowType_)
00042 { }
00043 
00044 template<typename T>
00045 CheckVoxelizationFunctional3D<T>::~CheckVoxelizationFunctional3D()
00046 {
00047     delete shape;
00048 }
00049 
00050 template<typename T>
00051 CheckVoxelizationFunctional3D<T>::
00052     CheckVoxelizationFunctional3D (
00053             CheckVoxelizationFunctional3D<T> const& rhs)
00054     : PlainReductiveBoxProcessingFunctional3D(rhs),
00055       numErrorsId(rhs.numErrorsId),
00056       shape(rhs.shape->clone()),
00057       flowType(rhs.flowType)
00058 { }
00059 
00060 template<typename T>
00061 CheckVoxelizationFunctional3D<T>&
00062     CheckVoxelizationFunctional3D<T>::operator= (
00063             CheckVoxelizationFunctional3D<T> const& rhs )
00064 {
00065     PlainReductiveBoxProcessingFunctional3D::operator=(rhs);
00066     numErrorsId = rhs.numErrorsId;
00067     shape = rhs.shape->clone();
00068     flowType = rhs.flowType;
00069     return *this;
00070 }
00071 
00072 
00073 template<typename T>
00074 CheckVoxelizationFunctional3D<T>*
00075     CheckVoxelizationFunctional3D<T>::clone() const
00076 {
00077     return new CheckVoxelizationFunctional3D<T>(*this);
00078 }
00079 
00080 template<typename T>
00081 void CheckVoxelizationFunctional3D<T>::getTypeOfModification (
00082         std::vector<modif::ModifT>& modified) const
00083 {
00084     modified[0] = modif::staticVariables;  // Flag matrix.
00085     // Possible additional parameters for the shape function are read-only.
00086     for (pluint i=1; i<modified.size(); ++i) {
00087         modified[i] = modif::nothing;
00088     }
00089 }
00090 
00091 template<typename T>
00092 BlockDomain::DomainT CheckVoxelizationFunctional3D<T>::appliesTo() const
00093 {
00094     return BlockDomain::bulk;
00095 }
00096 
00097 template<typename T>
00098 bool CheckVoxelizationFunctional3D<T>::isFluid(Dot3D const& location) const
00099 {
00100     if (flowType==voxelFlag::inside) {
00101         return shape->isInside(location);
00102     }
00103     else {
00104         return !shape->isInside(location);
00105     }
00106 }
00107 
00108 template<typename T>
00109 void CheckVoxelizationFunctional3D<T>::processGenericBlocks (
00110         Box3D domain, std::vector<AtomicBlock3D*> fields )
00111 {
00112     PLB_PRECONDITION( fields.size() >= 1 );
00113     ScalarField3D<int>* flagMatrix =
00114         dynamic_cast<ScalarField3D<int>*>(fields[0]);
00115     PLB_ASSERT( flagMatrix );
00116     Dot3D absoluteOffset = flagMatrix->getLocation();
00117 
00118     BoundaryShape3D<T,Array<T,3> >* newShape=0;
00119     if (fields.size()>1) {
00120         std::vector<AtomicBlock3D*> shapeParameters(fields.size()-1);
00121         for (pluint i=0; i<shapeParameters.size(); ++i) {
00122             shapeParameters[i] = fields[i+1];
00123         }
00124         newShape=shape->clone(shapeParameters);
00125         std::swap(shape,newShape);
00126     }
00127 
00128     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00129         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00130             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00131                 computeCell(Dot3D(iX,iY,iZ), *flagMatrix, absoluteOffset);
00132             }
00133         }
00134     }
00135 
00136     if (newShape) {
00137         std::swap(shape,newShape);
00138         delete newShape;
00139     }
00140 }
00141 
00142 
00143 template<typename T>
00144 void CheckVoxelizationFunctional3D<T>::computeCell (
00145         Dot3D const& cellLocation,
00146         ScalarField3D<int>& flagMatrix,
00147         Dot3D const& offset)
00148 {
00149     //  Non-Fluid nodes.
00150     if (!isFluid(cellLocation+offset)) {
00151         plint numNeighbors=0;
00152         plint numShallow=0;
00153         plint numFailures=0;
00154         for (int iNeighbor=0; iNeighbor<NextNeighbor<T>::numNeighbors; ++iNeighbor) {
00155             int const* c = NextNeighbor<T>::c[iNeighbor];
00156             Dot3D neighbor(cellLocation.x+c[0], cellLocation.y+c[1], cellLocation.z+c[2]);
00157             Dot3D nextNeighbor(cellLocation.x+2*c[0], cellLocation.y+2*c[1], cellLocation.z+2*c[2]);
00158             // If the non-fluid node has a fluid neighbor ...
00159             if (isFluid(neighbor+offset)) {
00160                 ++numNeighbors;
00161                 Array<T,3> wallNode;
00162                 T wallDistance;
00163                 Array<T,3> wall_u, wallNormal;
00164                 OffBoundary::Type bdType;
00165                 plint id=-1; // No optimization.
00166                 bool ok = shape->pointOnSurface(cellLocation+offset, Dot3D(c[0],c[1],c[2]),
00167                                                 wallNode, wallDistance, wallNormal,
00168                                                 wall_u, bdType, id);
00169                 if (!ok) {
00170                     ++numFailures;
00171                 }
00172                 if (!isFluid(nextNeighbor+offset)) {
00173                     ++numShallow;
00174                 }
00175             }
00176         }
00177         if (numFailures>0) {
00178             this->getStatistics().gatherIntSum(numErrorsId, 1);
00179             flagMatrix.get(cellLocation.x,cellLocation.y,cellLocation.z) = 1;
00180         }
00181         if (numNeighbors>0 && numNeighbors==numShallow) {
00182             flagMatrix.get(cellLocation.x,cellLocation.y,cellLocation.z) = 2;
00183         }
00184     }
00185 }
00186 
00187 template<typename T>
00188 plint CheckVoxelizationFunctional3D<T>::getNumErrors() const {
00189     return this->getStatistics().getIntSum(numErrorsId);
00190 }
00191 
00192 }  // namespace plb
00193 
00194 #endif  // OFF_LATTICE_BOUNDARY_PROCESSOR_3D_H