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

interpolations2D.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 INTERPOLATIONS_2D_HH
00026 #define INTERPOLATIONS_2D_HH
00027 
00028 #include "core/globalDefs.h"
00029 #include "core/util.h"
00030 #include "finiteDifference/interpolations2D.h"
00031 #include <vector>
00032 
00033 namespace plb {
00034 
00035 /* ******** Function linearInterpolationCoefficients ********************* */
00036 
00037 template<typename T>
00038 void linearInterpolationCoefficients (
00039         AtomicBlock2D const& block, Array<T,2> const& position,
00040         std::vector<Dot2D>& cellPos, std::vector<T>& weights )
00041 {
00042     cellPos.resize(4);
00043     cellPos[0] = Dot2D( (plint) position[0],         (plint) position[1]        );
00044     cellPos[1] = Dot2D( (plint) position[0],         (plint)(position[1]+(T)1.0));
00045     cellPos[2] = Dot2D( (plint)(position[0]+(T)1.0), (plint) position[1]        );
00046     cellPos[3] = Dot2D( (plint)(position[0]+(T)1.0), (plint)(position[1]+(T)1.0));
00047 
00048     T u = position[0] - (T)cellPos[0].x;
00049     T v = position[1] - (T)cellPos[0].y;
00050 
00051     weights.resize(4);
00052     weights[0] = (1.-u) * (1.-v);
00053     weights[1] = (1.-u) * (   v);
00054     weights[2] = (   u) * (1.-v);
00055     weights[3] = (   u) * (   v);
00056 
00057     PLB_ASSERT( util::fpequal(
00058                     weights[0] + weights[1] + weights[2] + weights[3],
00059                     (T)1., 1.e-6) );
00060 
00061     // Convert cell position to local coordinates.
00062     for (plint iPos=0; iPos<4; ++iPos) {
00063         cellPos[iPos] -= block.getLocation();
00064     }
00065 }
00066 
00067 }  // namespace plb
00068 
00069 #endif  // INTERPOLATIONS_2D_HH