/* This file is part of the OpenLB library * * Copyright (C) 2006, 2007, 2008 Jonas Latt * 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. */ /** \file * Dynamics for a generic 2D block lattice view -- generic implementation. */ #ifndef BLOCK_LATTICE_VIEW_2D_HH #define BLOCK_LATTICE_VIEW_2D_HH #include "blockLatticeView2D.h" #include "cell.h" namespace olb { ////////////////////// Class BlockLatticeView2D ///////////////////////// template BlockLatticeView2D::BlockLatticeView2D ( BlockLatticeStructure2D& originalLattice_ ) : BlockLatticeStructure2D(originalLattice_.getNx(),originalLattice_.getNy()), originalLattice(&originalLattice_), x0(0), y0(0) { } template BlockLatticeView2D::BlockLatticeView2D ( BlockLatticeStructure2D& originalLattice_, int x0_, int x1_, int y0_, int y1_ ) : BlockLatticeStructure2D(x1_-x0_+1,y1_-y0_+1), originalLattice(&originalLattice_), x0(x0_), y0(y0_) { OLB_PRECONDITION(x1_ < originalLattice->getNx()); OLB_PRECONDITION(x0_ <= x1_); OLB_PRECONDITION(y1_ < originalLattice->getNy()); OLB_PRECONDITION(y0_ <= y1_); } template BlockLatticeView2D::~BlockLatticeView2D() { } template BlockLatticeView2D::BlockLatticeView2D(BlockLatticeView2D const& rhs) : BlockLatticeStructure2D(rhs._nx,rhs._ny), originalLattice(rhs.originalLattice), x0(rhs.x0), y0(rhs.y0) { } template BlockLatticeView2D& BlockLatticeView2D::operator= ( BlockLatticeView2D const& rhs ) { BlockLatticeView2D tmp(rhs); swap(tmp); return *this; } template void BlockLatticeView2D::swap ( BlockLatticeView2D& rhs) { std::swap(this->_nx, rhs._nx); std::swap(this->_ny, rhs._ny); std::swap(x0, rhs.x0); std::swap(y0, rhs.y0); std::swap(originalLattice, rhs.originalLattice); } template Cell& BlockLatticeView2D::get(int iX, int iY) { return originalLattice->get(iX+x0, iY+y0); } template Cell& BlockLatticeView2D::get(int latticeR[]) { return get(latticeR[0], latticeR[1]); } template Cell const& BlockLatticeView2D::get ( int iX, int iY ) const { return originalLattice->get(iX+x0, iY+y0); } template void BlockLatticeView2D::initialize() { originalLattice->initialize(); } template void BlockLatticeView2D::defineDynamics ( int x0_, int x1_, int y0_, int y1_, Dynamics* dynamics ) { originalLattice->defineDynamics( x0_+x0, x1_+x0, y0_+y0, y1_+y0, dynamics ); } template void BlockLatticeView2D::defineDynamics ( int iX, int iY, Dynamics* dynamics ) { originalLattice->defineDynamics( iX+x0, iY+y0, dynamics ); } template Dynamics* BlockLatticeView2D::getDynamics ( int iX, int iY) { return originalLattice->getDynamics( iX+x0, iY+y0 ); } template void BlockLatticeView2D::collide ( int x0_, int x1_, int y0_, int y1_ ) { originalLattice->collide( x0_+x0, x1_+x0, y0_+y0, y1_+y0 ); } template void BlockLatticeView2D::collide() { originalLattice->collide( x0, x0+this->_nx-1, y0, y0+this->_ny-1); } template void BlockLatticeView2D::stream(int x0_, int x1_, int y0_, int y1_) { originalLattice->stream(x0_+x0, x1_+x0, y0_+y0, y1_+y0); } template void BlockLatticeView2D::stream(bool periodic) { OLB_PRECONDITION(!periodic); originalLattice->stream( x0, x0+this->_nx-1, y0, y0+this->_ny-1); postProcess(); } template void BlockLatticeView2D::collideAndStream(int x0_, int x1_, int y0_, int y1_) { originalLattice->collideAndStream(x0_+x0, x1_+x0, y0_+y0, y1_+y0); } template void BlockLatticeView2D::collideAndStream(bool periodic) { OLB_PRECONDITION(!periodic); originalLattice->collideAndStream( x0, x0+this->_nx-1, y0, y0+this->_ny-1); postProcess(); } template T BlockLatticeView2D::computeAverageDensity ( int x0_, int x1_, int y0_, int y1_ ) const { return originalLattice->computeAverageDensity( x0_+x0, x1_+x0, y0_+y0, y1_+y0 ); } template T BlockLatticeView2D::computeAverageDensity() const { return originalLattice->computeAverageDensity( x0, x0+this->_nx-1, y0, y0+this->_ny-1); } template void BlockLatticeView2D::computeStress(int iX, int iY, T pi[util::TensorVal::n]) { originalLattice->computeStress( iX + x0, iY + y0, pi); } template void BlockLatticeView2D::stripeOffDensityOffset ( int x0_, int x1_, int y0_, int y1_, T offset ) { originalLattice->stripeOffDensityOffset( x0_+x0, x1_+x0, y0_+y0, y1_+y0, offset ); } template void BlockLatticeView2D::stripeOffDensityOffset(T offset) { originalLattice->stripeOffDensityOffset(x0, x0+this->_nx-1, y0, y0+this->_ny-1, offset); } template void BlockLatticeView2D::forAll ( int x0_, int x1_, int y0_, int y1_, WriteCellFunctional const& application ) { originalLattice->forAll( x0_+x0, x1_+x0, y0_+y0, y1_+y0, application ); } template void BlockLatticeView2D::forAll(WriteCellFunctional const& application) { originalLattice->forAll(x0, x0+this->_nx-1, y0, y0+this->_ny-1, application); } template void BlockLatticeView2D::addPostProcessor ( PostProcessorGenerator2D const& ppGen) { PostProcessorGenerator2D* shiftedGen = ppGen.clone(); shiftedGen->shift(x0,y0); originalLattice->addPostProcessor(*shiftedGen); delete shiftedGen; } template void BlockLatticeView2D::resetPostProcessors() { originalLattice->resetPostProcessors(); } template void BlockLatticeView2D::postProcess() { originalLattice -> postProcess(x0, x0+this->_nx-1, y0, y0+this->_ny-1); } template void BlockLatticeView2D::postProcess ( int x0_, int x1_, int y0_, int y1_ ) { originalLattice -> postProcess( x0_+x0, x1_+x0, y0_+y0, y1_+y0 ); } template void BlockLatticeView2D::addLatticeCoupling ( LatticeCouplingGenerator2D const& lcGen, std::vector partners ) { LatticeCouplingGenerator2D* shiftedGen = lcGen.clone(); shiftedGen->shift(x0,y0); originalLattice->addLatticeCoupling(*shiftedGen, partners); delete shiftedGen; } template void BlockLatticeView2D::executeCoupling() { originalLattice -> executeCoupling(x0, x0+this->_nx-1, y0, y0+this->_ny-1); } template void BlockLatticeView2D::executeCoupling ( int x0_, int x1_, int y0_, int y1_ ) { originalLattice -> executeCoupling( x0_+x0, x1_+x0, y0_+y0, y1_+y0 ); } template LatticeStatistics& BlockLatticeView2D::getStatistics() { return originalLattice->getStatistics(); } template LatticeStatistics const& BlockLatticeView2D::getStatistics() const { return originalLattice->getStatistics(); } } // namespace olb #endif