/* This file is part of the OpenLB library * * Copyright (C) 2008 Orestis Malaspinas, Andrea Parmigiani * E-mail contact: info@openlb.net * The most recent release of OpenLB can be downloaded at * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef ADVECTION_DIFFUSION_BOUNDARY_INSTANTIATOR_3D_HH #define ADVECTION_DIFFUSION_BOUNDARY_INSTANTIATOR_3D_HH #include "advectionDiffusionBoundaryInstantiator3D.h" #include "advectionDiffusionBoundaryCondition3D.h" #include "advectionDiffusionBoundaryCondition3D.hh" #include "advectionDiffusionBoundaryPostProcessor3D.hh" #include "functors/lattice/indicator/blockIndicatorF3D.h" #include "dynamics/rtlbmDescriptors.h" namespace olb { ///////// class AdvectionDiffusionBoundaryConditionInstantiator3D //////////////////////// template AdvectionDiffusionBoundaryConditionInstantiator3D:: AdvectionDiffusionBoundaryConditionInstantiator3D(BlockLatticeStructure3D& block) : _block(block) { } template AdvectionDiffusionBoundaryConditionInstantiator3D:: ~AdvectionDiffusionBoundaryConditionInstantiator3D() { for (auto &iDynamics : dynamicsVector) { delete iDynamics; } for (auto &iMomenta : momentaVector) { delete iMomenta; } } // ---- flat ------------- template template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addTemperatureBoundary(int x0, int x1, int y0, int y1, int z0, int z1, T omega) { OLB_PRECONDITION(x0==x1 || y0==y1 || z0==z1); for (int iX=x0; iX<=x1; ++iX) { for (int iY=y0; iY<=y1; ++iY) { for (int iZ=z0; iZ<=z1; ++iZ) { Momenta* momenta = BoundaryManager::template getTemperatureBoundaryMomenta(); Dynamics* dynamics = BoundaryManager::template getTemperatureBoundaryDynamics(omega, *momenta); _block.defineDynamics(iX,iX,iY,iY,iZ,iZ, dynamics); momentaVector.push_back(momenta); dynamicsVector.push_back(dynamics); } } } PostProcessorGenerator3D* postProcessor = BoundaryManager::template getTemperatureBoundaryProcessor(x0,x1, y0,y1, z0,z1); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } // ---- edges ------------- template template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addTemperatureBoundaryEdge(int x0, int x1, int y0, int y1, int z0, int z1, T omega) { OLB_PRECONDITION( ( x0==x1 && y0==y1 ) || ( x0==x1 && z0==z1 ) || ( y0==y1 && z0==z1 ) ); for (int iX=x0; iX<=x1; ++iX) { for (int iY=y0; iY<=y1; ++iY) { for (int iZ=z0; iZ<=z1; ++iZ) { Momenta* momenta = BoundaryManager::template getTemperatureBoundaryEdgeMomenta(); Dynamics* dynamics = BoundaryManager::template getTemperatureBoundaryEdgeDynamics(omega, *momenta); _block.defineDynamics(iX,iX,iY,iY,iZ,iZ, dynamics); momentaVector.push_back(momenta); dynamicsVector.push_back(dynamics); } } } PostProcessorGenerator3D* postProcessor = BoundaryManager::template getTemperatureBoundaryEdgeProcessor(x0,x1, y0,y1, z0,z1); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } // ---- corner ------------- template template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addTemperatureBoundaryCorner(int x, int y, int z, T omega) { Momenta* momenta = BoundaryManager::template getTemperatureBoundaryCornerMomenta(); Dynamics* dynamics = BoundaryManager::template getTemperatureBoundaryCornerDynamics(omega, *momenta); _block.defineDynamics(x,x,y,y,z,z, dynamics); PostProcessorGenerator3D* postProcessor = BoundaryManager::template getTemperatureBoundaryCornerProcessor(x, y, z); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addTemperatureBoundary(BlockIndicatorF3D& indicator, int x0, int x1, int y0, int y1, int z0, int z1, T omega) { auto& blockGeometryStructure = indicator.getBlockGeometryStructure(); std::vector discreteNormal(4,0); for (int iX = x0; iX <= x1; ++iX) { for (int iY = y0; iY <= y1; ++iY) { for (int iZ = z0; iZ <= z1; ++iZ) { if (indicator(iX, iY, iZ)) { discreteNormal = blockGeometryStructure.getStatistics().getType(iX, iY, iZ); if (discreteNormal[0] == 0) { // flat if (discreteNormal[1] != 0 && discreteNormal[1] == -1) { addTemperatureBoundary<0,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] != 0 && discreteNormal[1] == 1) { addTemperatureBoundary<0,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[2] != 0 && discreteNormal[2] == -1) { addTemperatureBoundary<1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[2] != 0 && discreteNormal[2] == 1) { addTemperatureBoundary<1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[3] != 0 && discreteNormal[3] == -1) { addTemperatureBoundary<2,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[3] != 0 && discreteNormal[3] == 1) { addTemperatureBoundary<2,1>(iX,iX,iY,iY,iZ,iZ, omega); } } else if (discreteNormal[0] == 1) { // corner if (discreteNormal[1] == 1 && discreteNormal[2] == 1 && discreteNormal[3] == 1) { addTemperatureBoundaryCorner<1,1,1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == -1 && discreteNormal[3] == 1) { addTemperatureBoundaryCorner<1,-1,1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == 1 && discreteNormal[3] == -1) { addTemperatureBoundaryCorner<1,1,-1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == -1 && discreteNormal[3] == -1) { addTemperatureBoundaryCorner<1,-1,-1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == 1 && discreteNormal[3] == 1) { addTemperatureBoundaryCorner<-1,1,1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == -1 && discreteNormal[3] == 1) { addTemperatureBoundaryCorner<-1,-1,1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == 1 && discreteNormal[3] == -1) { addTemperatureBoundaryCorner<-1,1,-1>(iX,iY,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == -1 && discreteNormal[3] == -1) { addTemperatureBoundaryCorner<-1,-1,-1>(iX,iY,iZ, omega); } } else if (discreteNormal[0] == 3) { // edge if (discreteNormal[1] == 0 && discreteNormal[2] == 1 && discreteNormal[3] == 1) { addTemperatureBoundaryEdge<0,1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 0 && discreteNormal[2] == -1 && discreteNormal[3] == 1) { addTemperatureBoundaryEdge<0,-1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 0 && discreteNormal[2] == 1 && discreteNormal[3] == -1) { addTemperatureBoundaryEdge<0,1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 0 && discreteNormal[2] == -1 && discreteNormal[3] == -1) { addTemperatureBoundaryEdge<0,-1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == 0 && discreteNormal[3] == 1) { addTemperatureBoundaryEdge<1,1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == 0 && discreteNormal[3] == 1) { addTemperatureBoundaryEdge<1,1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == 0 && discreteNormal[3] == -1) { addTemperatureBoundaryEdge<1,-1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == 0 && discreteNormal[3] == -1) { addTemperatureBoundaryEdge<1,-1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == 1 && discreteNormal[3] == 0) { addTemperatureBoundaryEdge<2,1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == 1 && discreteNormal[3] == 0) { addTemperatureBoundaryEdge<2,-1,1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == 1 && discreteNormal[2] == -1 && discreteNormal[3] == 0) { addTemperatureBoundaryEdge<2,1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } else if (discreteNormal[1] == -1 && discreteNormal[2] == -1 && discreteNormal[3] == 0) { addTemperatureBoundaryEdge<2,-1,-1>(iX,iX,iY,iY,iZ,iZ, omega); } } } } } } } template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addConvectionBoundary(BlockIndicatorF3D& indicator, int x0, int x1, int y0, int y1, int z0, int z1) { std::vector discreteNormal(4, 0); for (int iX = x0; iX <= x1; ++iX) { for (int iY = y0; iY <= y1; ++iY) { for (int iZ = z0; iZ <= z1; ++iZ) { if (indicator(iX, iY, iZ)) { discreteNormal = indicator.getBlockGeometryStructure().getStatistics().getType(iX, iY, iZ); if (discreteNormal[1]!=0 || discreteNormal[2]!=0 || discreteNormal[3]!=0) { PostProcessorGenerator3D* postProcessor = new ConvectionBoundaryProcessorGenerator3D(iX, iX, iY, iY, iZ, iZ, -discreteNormal[1], -discreteNormal[2], -discreteNormal[3]); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } else { // cout << "Warning: Could not addConvectionBoundary (" << iX << ", " << iY << ", " << iZ << "), discreteNormal=(" << discreteNormal[0] <<","<< discreteNormal[1] <<","<< discreteNormal[2] << ", " << discreteNormal[3] << "), set to bounceBack" << std::endl; } } } } } } template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addZeroDistributionBoundary(BlockIndicatorF3D& indicator, int x0, int x1, int y0, int y1, int z0, int z1) { auto& blockGeometryStructure = indicator.getBlockGeometryStructure(); std::vector discreteNormal(4, 0); for (int iX = x0; iX <= x1; ++iX) { for (int iY = y0; iY <= y1; ++iY) { for (int iZ = z0; iZ <= z1; ++iZ) { if (indicator(iX, iY, iZ)) { discreteNormal = blockGeometryStructure.getStatistics().getType(iX, iY, iZ); if (discreteNormal[1]!=0 || discreteNormal[2]!=0 || discreteNormal[3]!=0) { PostProcessorGenerator3D* postProcessor = new ZeroDistributionBoundaryProcessorGenerator3D(iX, iX, iY, iY, iZ, iZ, -discreteNormal[1], -discreteNormal[2], -discreteNormal[3]); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } else { // cout << "Warning: Could not addZeroDistributionBoundary (" << iX << ", " << iY << ", " << iZ << "), discreteNormal=(" << discreteNormal[0] <<","<< discreteNormal[1] <<","<< discreteNormal[2] << "," << discreteNormal[3] << ")" << std::endl; } } } } } } template void AdvectionDiffusionBoundaryConditionInstantiator3D:: addExtFieldBoundary(BlockIndicatorF3D& indicator, int offset, int x0, int x1, int y0, int y1, int z0, int z1) { auto& blockGeometryStructure = indicator.getBlockGeometryStructure(); std::vector discreteNormal(4, 0); for (int iX = x0; iX <= x1; ++iX) { for (int iY = y0; iY <= y1; ++iY) { for (int iZ = z0; iZ <= z1; ++iZ) { if (indicator(iX, iY, iZ)) { discreteNormal = blockGeometryStructure.getStatistics().getType(iX, iY, iZ); if (discreteNormal[1]!=0 || discreteNormal[2]!=0 || discreteNormal[3]!=0) { PostProcessorGenerator3D* postProcessor = new ExtFieldBoundaryProcessorGenerator3D(iX, iX, iY, iY, iZ, iZ, -discreteNormal[1], -discreteNormal[2], -discreteNormal[3], offset); if (postProcessor) { _block.addPostProcessor(*postProcessor); } } else { // cout << "Warning: Could not addZeroDistributionBoundary (" << iX << ", " << iY << ", " << iZ << "), discreteNormal=(" << discreteNormal[0] <<","<< discreteNormal[1] <<","<< discreteNormal[2] << "," << discreteNormal[3] << ")" << std::endl; } } } } } } } #endif