/usr/include/palabos/finiteDifference/interpolations2D.hh is in libplb-dev 1.5~r1+repack1-2build2.
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 | /* 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 INTERPOLATIONS_2D_HH
#define INTERPOLATIONS_2D_HH
#include "core/globalDefs.h"
#include "core/util.h"
#include "finiteDifference/interpolations2D.h"
#include <vector>
namespace plb {
/* ******** Function linearInterpolationCoefficients ********************* */
template<typename T>
void linearInterpolationCoefficients (
AtomicBlock2D const& block, Array<T,2> const& position,
std::vector<Dot2D>& cellPos, std::vector<T>& weights )
{
cellPos.resize(4);
cellPos[0] = Dot2D( (plint) position[0], (plint) position[1] );
cellPos[1] = Dot2D( (plint) position[0], (plint)(position[1]+(T)1.0));
cellPos[2] = Dot2D( (plint)(position[0]+(T)1.0), (plint) position[1] );
cellPos[3] = Dot2D( (plint)(position[0]+(T)1.0), (plint)(position[1]+(T)1.0));
T u = position[0] - (T)cellPos[0].x;
T v = position[1] - (T)cellPos[0].y;
weights.resize(4);
weights[0] = (1.-u) * (1.-v);
weights[1] = (1.-u) * ( v);
weights[2] = ( u) * (1.-v);
weights[3] = ( u) * ( v);
// Convert cell position to local coordinates.
for (plint iPos=0; iPos<4; ++iPos) {
cellPos[iPos] -= block.getLocation();
}
}
template<typename T, plint nDim>
Array<T,nDim> linearInterpolateTensorField (
TensorField2D<T,nDim>& tensorField, Array<T,2> const& position )
{
std::vector<Dot2D> pos(4);
std::vector<T> weights(4);
linearInterpolationCoefficients(tensorField, position, pos, weights);
Array<T,nDim> vector;
vector.resetToZero();
for (plint iCell=0; iCell<4; ++iCell) {
vector += weights[iCell]*tensorField.get(pos[iCell].x,pos[iCell].y);
}
return vector;
}
template<typename T, plint nDim>
Array<T,nDim> predictorCorrectorTensorField (
TensorField2D<T,nDim>& tensorField, Array<T,2> const& position, T scaling )
{
Array<T,2> position1(position);
std::vector<Dot2D> pos(4);
std::vector<T> weights(4);
linearInterpolationCoefficients(tensorField, position1, pos, weights);
Array<T,nDim> vector1;
vector1.resetToZero();
for (plint iCell=0; iCell<4; ++iCell) {
vector1 += weights[iCell]*tensorField.get(pos[iCell].x,pos[iCell].y)*scaling;
}
Array<T,2> position2(position1+vector1);
linearInterpolationCoefficients(tensorField, position2, pos, weights);
Array<T,nDim> vector2;
vector2.resetToZero();
for (plint iCell=0; iCell<4; ++iCell) {
vector2 += weights[iCell]*tensorField.get(pos[iCell].x,pos[iCell].y)*scaling;
}
return (vector1+vector2)/(T)2;
}
//// ADDED BY ANDREA
template<typename T>
void predictorCorrectorRhoBarJ (
NTensorField2D<T>& rhoBarJ, Array<T,2> const& position,
bool velIsJ, Array<T,2>& j, T& rhoBar )
{
PLB_ASSERT( rhoBarJ.getNdim()==3 );
Array<T,2> position1(position);
std::vector<Dot2D> pos(4);
std::vector<T> weights(4);
linearInterpolationCoefficients(rhoBarJ, position1, pos, weights);
Array<T,2> j1;
j1.resetToZero();
T rhoBar1 = T();
for (plint iCell=0; iCell<4; ++iCell) {
T const* data = rhoBarJ.get(pos[iCell].x,pos[iCell].y);
j1.add_from_cArray(data+1, weights[iCell]);
rhoBar1 += weights[iCell]*(*data);
}
Array<T,2> position2(position1+j1);
linearInterpolationCoefficients(rhoBarJ, position2, pos, weights);
Array<T,2> j2;
j2.resetToZero();
T rhoBar2 = T();
for (plint iCell=0; iCell<4; ++iCell) {
T const* data = rhoBarJ.get(pos[iCell].x,pos[iCell].y);
j2.add_from_cArray(data+1, weights[iCell]);
rhoBar2 += weights[iCell]*(*data);
}
j= (j1+j2)/(T)2;
rhoBar = (rhoBar1+rhoBar2)/(T)2;
}
template<typename T>
T linearInterpolateScalarField (
ScalarField2D<T>& scalarField, Array<T,2> const& position )
{
std::vector<Dot2D> pos(4);
std::vector<T> weights(4);
linearInterpolationCoefficients(scalarField, position, pos, weights);
T scalar = T();
for (plint iCell=0; iCell<4; ++iCell) {
scalar += weights[iCell]*scalarField.get(pos[iCell].x,pos[iCell].y);
}
return scalar;
}
} // namespace plb
#endif // INTERPOLATIONS_2D_HH
|