00001
00002
00003
00004
00005
00006 #ifndef LBM_FIXUP_OPS_H
00007 #define LBM_FIXUP_OPS_H
00008
00016 template <class LBMType, int dim> class LBMFixupOps;
00017
00018 template <class LBMType>
00019 class LBMFixupOps<LBMType,1> {
00020 typedef typename LBMType::MicroType MicroType;
00021 typedef typename MicroType::InternalDataType DataType;
00022 public:
00023 LBMFixupOps() {}
00024
00025 void average_indices(GridData<MicroType,1> &target, const GridData<MicroType,1> &source,
00026 const BBox &where, const int Index[], const int NIndex) {
00027
00028 #ifdef DEBUG_PRINT_FIXUP
00029 ( comm_service::log() << "average_indices " << target.bbox() << " from " << source.bbox()
00030 << " using " << where << " " ).flush();
00031 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00032 ( comm_service::log() << "\n" ).flush();
00033 #endif
00034
00035 BeginFastIndex1(src, source.bbox(), source.data(), const MicroType);
00036 BeginFastIndex1(tgt, target.bbox(), target.data(), MicroType);
00037
00038 BBox bb = where*target.bbox();
00039 for_1 (i,bb,bb.stepsize())
00040 for (register int n=0; n<NIndex; n++)
00041 FastIndex1(tgt,i)(Index[n]) = DataType(0.);
00042 BBox bbadd(1,i,i,bb.stepsize(0));
00043 bbadd.refine(bb.stepsize(0)/source.bbox().stepsize(0));
00044 bbadd*=source.bbox();
00045 for_1 (ii,bbadd,bbadd.stepsize())
00046 for (register int n=0; n<NIndex; n++)
00047 FastIndex1(tgt,i)(Index[n]) += FastIndex1(src,ii)(Index[n]);
00048 end_for
00049 for (register int n=0; n<NIndex; n++)
00050 FastIndex1(tgt,i)(Index[n]) /= bbadd.size();
00051 end_for
00052
00053 EndFastIndex1(src);
00054 EndFastIndex1(tgt);
00055 }
00056
00057 void copy_indices(GridData<MicroType,1> &target, const GridData<MicroType,1> &source,
00058 const BBox &where, const int Index[], const int NIndex) {
00059
00060 #ifdef DEBUG_PRINT_FIXUP
00061 ( comm_service::log() << "copy_indices " << target.bbox() << " from " << source.bbox()
00062 << " using " << where << " " ).flush();
00063 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00064 ( comm_service::log() << "\n" ).flush();
00065 #endif
00066
00067 BeginFastIndex1(src, source.bbox(), source.data(), const MicroType);
00068 BeginFastIndex1(tgt, target.bbox(), target.data(), MicroType);
00069
00070 BBox bb = where*target.bbox();
00071 for_1 (i,bb,bb.stepsize())
00072 for (register int n=0; n<NIndex; n++)
00073 FastIndex1(tgt,i)(Index[n]) = FastIndex1(src,i)(Index[n]);
00074 end_for
00075
00076 EndFastIndex1(src);
00077 EndFastIndex1(tgt);
00078 }
00079
00080 void scale_indices(GridData<MicroType,1> &target, const GridData<MicroType,1> &source,
00081 const BBox &where, const int Index[], const int NIndex, const DataType& fac) {
00082
00083 #ifdef DEBUG_PRINT_FIXUP
00084 ( comm_service::log() << "scale_indices " << target.bbox() << " from " << source.bbox()
00085 << " using " << where << " " ).flush();
00086 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00087 ( comm_service::log() << " fac=" << fac << "\n" ).flush();
00088 #endif
00089
00090 BeginFastIndex1(src, source.bbox(), source.data(), const MicroType);
00091 BeginFastIndex1(tgt, target.bbox(), target.data(), MicroType);
00092
00093 BBox bb = where*target.bbox();
00094 for_1 (i,bb,bb.stepsize())
00095 for (register int n=0; n<NIndex; n++)
00096 FastIndex1(tgt,i)(Index[n]) += (FastIndex1(src,i)(Index[n])-FastIndex1(tgt,i)(Index[n]))*fac;
00097 end_for
00098
00099 EndFastIndex1(src);
00100 EndFastIndex1(tgt);
00101 }
00102
00103 void equilibrium(const LBMType& lbm, GridData<MicroType,1> &target, const BBox &where,
00104 const int Index[], const int NIndex) {
00105
00106 #ifdef DEBUG_PRINT_FIXUP
00107 ( comm_service::log() << "equilibrium " << target.bbox() << " using " << where << " " ).flush();
00108 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00109 ( comm_service::log() << "\n" ).flush();
00110 #endif
00111
00112 BeginFastIndex1(tgt, target.bbox(), target.data(), MicroType);
00113 BBox bb = where*target.bbox();
00114 for_1 (i,bb,bb.stepsize())
00115 MicroType feq = lbm.Equilibrium(lbm.MacroVariables(FastIndex1(tgt,i)));
00116 for (register int n=0; n<NIndex; n++)
00117 FastIndex1(tgt,i)(Index[n]) = feq(Index[n]);
00118 end_for
00119 EndFastIndex1(tgt);
00120 }
00121 };
00122
00123 template <class LBMType>
00124 class LBMFixupOps<LBMType,2> {
00125 typedef typename LBMType::MicroType MicroType;
00126 typedef typename MicroType::InternalDataType DataType;
00127 public:
00128 LBMFixupOps() {}
00129
00130 void average_indices(GridData<MicroType,2> &target, const GridData<MicroType,2> &source,
00131 const BBox &where, const int Index[], const int NIndex) {
00132
00133 #ifdef DEBUG_PRINT_FIXUP
00134 ( comm_service::log() << "average_indices " << target.bbox() << " from " << source.bbox()
00135 << " using " << where << " " ).flush();
00136 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00137 ( comm_service::log() << "\n" ).flush();
00138 #endif
00139
00140 BeginFastIndex2(src, source.bbox(), source.data(), const MicroType);
00141 BeginFastIndex2(tgt, target.bbox(), target.data(), MicroType);
00142
00143 BBox bb = where*target.bbox();
00144 for_2 (i,j,bb,bb.stepsize())
00145 for (register int n=0; n<NIndex; n++)
00146 FastIndex2(tgt,i,j)(Index[n]) = DataType(0.);
00147 BBox bbadd(2,i,j,i,j,bb.stepsize(0),bb.stepsize(1));
00148 bbadd.refine(bb.stepsize(0)/source.bbox().stepsize(0));
00149 bbadd*=source.bbox();
00150 for_2 (ii,jj,bbadd,bbadd.stepsize())
00151 for (register int n=0; n<NIndex; n++)
00152 FastIndex2(tgt,i,j)(Index[n]) += FastIndex2(src,ii,jj)(Index[n]);
00153 end_for
00154 for (register int n=0; n<NIndex; n++)
00155 FastIndex2(tgt,i,j)(Index[n]) /= bbadd.size();
00156 end_for
00157
00158 EndFastIndex2(src);
00159 EndFastIndex2(tgt);
00160 }
00161
00162 void copy_indices(GridData<MicroType,2> &target, const GridData<MicroType,2> &source,
00163 const BBox &where, const int Index[], const int NIndex) {
00164
00165 #ifdef DEBUG_PRINT_FIXUP
00166 ( comm_service::log() << "copy_indices " << target.bbox() << " from " << source.bbox()
00167 << " using " << where << " " ).flush();
00168 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00169 ( comm_service::log() << "\n" ).flush();
00170 #endif
00171
00172 BeginFastIndex2(src, source.bbox(), source.data(), const MicroType);
00173 BeginFastIndex2(tgt, target.bbox(), target.data(), MicroType);
00174
00175 BBox bb = where*target.bbox();
00176 for_2 (i,j,bb,bb.stepsize())
00177 for (register int n=0; n<NIndex; n++)
00178 FastIndex2(tgt,i,j)(Index[n]) = FastIndex2(src,i,j)(Index[n]);
00179 end_for
00180
00181 EndFastIndex2(src);
00182 EndFastIndex2(tgt);
00183 }
00184
00185 void scale_indices(GridData<MicroType,2> &target, const GridData<MicroType,2> &source,
00186 const BBox &where, const int Index[], const int NIndex, const DataType& fac) {
00187
00188 #ifdef DEBUG_PRINT_FIXUP
00189 ( comm_service::log() << "scale_indices " << target.bbox() << " from " << source.bbox()
00190 << " using " << where << " " ).flush();
00191 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00192 ( comm_service::log() << " fac=" << fac << "\n" ).flush();
00193 #endif
00194
00195 BeginFastIndex2(src, source.bbox(), source.data(), const MicroType);
00196 BeginFastIndex2(tgt, target.bbox(), target.data(), MicroType);
00197
00198 BBox bb = where*target.bbox();
00199 for_2 (i,j,bb,bb.stepsize())
00200 for (register int n=0; n<NIndex; n++)
00201 FastIndex2(tgt,i,j)(Index[n]) += (FastIndex2(src,i,j)(Index[n])-FastIndex2(tgt,i,j)(Index[n]))*fac;
00202 end_for
00203
00204 EndFastIndex2(src);
00205 EndFastIndex2(tgt);
00206 }
00207
00208 void equilibrium(const LBMType& lbm, GridData<MicroType,2> &target, const BBox &where,
00209 const int Index[], const int NIndex) {
00210
00211 #ifdef DEBUG_PRINT_FIXUP
00212 ( comm_service::log() << "equilibrium " << target.bbox() << " using " << where << " " ).flush();
00213 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00214 ( comm_service::log() << "\n" ).flush();
00215 #endif
00216
00217 BeginFastIndex2(tgt, target.bbox(), target.data(), MicroType);
00218 BBox bb = where*target.bbox();
00219 for_2 (i,j,bb,bb.stepsize())
00220 MicroType feq = lbm.Equilibrium(lbm.MacroVariables(FastIndex2(tgt,i,j)));
00221 for (register int n=0; n<NIndex; n++)
00222 FastIndex2(tgt,i,j)(Index[n]) = feq(Index[n]);
00223 end_for
00224 EndFastIndex2(tgt);
00225 }
00226 };
00227
00228 template <class LBMType>
00229 class LBMFixupOps<LBMType,3> {
00230 typedef typename LBMType::MicroType MicroType;
00231 typedef typename MicroType::InternalDataType DataType;
00232 public:
00233 LBMFixupOps() {}
00234
00235 void average_indices(GridData<MicroType,3> &target, const GridData<MicroType,3> &source,
00236 const BBox &where, const int Index[], const int NIndex) {
00237
00238 #ifdef DEBUG_PRINT_FIXUP
00239 ( comm_service::log() << "average_indices " << target.bbox() << " from " << source.bbox()
00240 << " using " << where << " " ).flush();
00241 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00242 ( comm_service::log() << "\n" ).flush();
00243 #endif
00244
00245 BeginFastIndex3(src, source.bbox(), source.data(), const MicroType);
00246 BeginFastIndex3(tgt, target.bbox(), target.data(), MicroType);
00247
00248 BBox bb = where*target.bbox();
00249 for_3 (i,j,k,bb,bb.stepsize())
00250 for (register int n=0; n<NIndex; n++)
00251 FastIndex3(tgt,i,j,k)(Index[n]) = DataType(0.);
00252 BBox bbadd(3,i,j,k,i,j,k,bb.stepsize(0),bb.stepsize(1),bb.stepsize(2));
00253 bbadd.refine(bb.stepsize(0)/source.bbox().stepsize(0));
00254 bbadd*=source.bbox();
00255 for_3 (ii,jj,kk,bbadd,bbadd.stepsize())
00256 for (register int n=0; n<NIndex; n++)
00257 FastIndex3(tgt,i,j,k)(Index[n]) += FastIndex3(src,ii,jj,kk)(Index[n]);
00258 end_for
00259 for (register int n=0; n<NIndex; n++)
00260 FastIndex3(tgt,i,j,k)(Index[n]) /= bbadd.size();
00261 end_for
00262
00263 EndFastIndex3(src);
00264 EndFastIndex3(tgt);
00265 }
00266
00267 void copy_indices(GridData<MicroType,3> &target, const GridData<MicroType,3> &source,
00268 const BBox &where, const int Index[], const int NIndex) {
00269
00270 #ifdef DEBUG_PRINT_FIXUP
00271 ( comm_service::log() << "copy_indices " << target.bbox() << " from " << source.bbox()
00272 << " using " << where << " " ).flush();
00273 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00274 ( comm_service::log() << "\n" ).flush();
00275 #endif
00276
00277 BeginFastIndex3(src, source.bbox(), source.data(), const MicroType);
00278 BeginFastIndex3(tgt, target.bbox(), target.data(), MicroType);
00279
00280 BBox bb = where*target.bbox();
00281 for_3 (i,j,k,bb,bb.stepsize())
00282 for (register int n=0; n<NIndex; n++)
00283 FastIndex3(tgt,i,j,k)(Index[n]) = FastIndex3(src,i,j,k)(Index[n]);
00284 end_for
00285
00286 EndFastIndex3(src);
00287 EndFastIndex3(tgt);
00288 }
00289
00290 void scale_indices(GridData<MicroType,3> &target, const GridData<MicroType,3> &source,
00291 const BBox &where, const int Index[], const int NIndex, const DataType& fac) {
00292
00293 #ifdef DEBUG_PRINT_FIXUP
00294 ( comm_service::log() << "scale_indices " << target.bbox() << " from " << source.bbox()
00295 << " using " << where << " " ).flush();
00296 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00297 ( comm_service::log() << " fac=" << fac << "\n" ).flush();
00298 #endif
00299
00300 BeginFastIndex3(src, source.bbox(), source.data(), const MicroType);
00301 BeginFastIndex3(tgt, target.bbox(), target.data(), MicroType);
00302
00303 BBox bb = where*target.bbox();
00304 for_3 (i,j,k,bb,bb.stepsize())
00305 for (register int n=0; n<NIndex; n++)
00306 FastIndex3(tgt,i,j,k)(Index[n]) += (FastIndex3(src,i,j,k)(Index[n])-FastIndex3(tgt,i,j,k)(Index[n]))*fac;
00307 end_for
00308
00309 EndFastIndex3(src);
00310 EndFastIndex3(tgt);
00311 }
00312
00313 void equilibrium(const LBMType& lbm, GridData<MicroType,3> &target, const BBox &where,
00314 const int Index[], const int NIndex) {
00315
00316 #ifdef DEBUG_PRINT_FIXUP
00317 ( comm_service::log() << "equilibrium " << target.bbox() << " using " << where << " " ).flush();
00318 for (register int n=0; n<NIndex; n++) ( comm_service::log() << "," << Index[n] ).flush();
00319 ( comm_service::log() << "\n" ).flush();
00320 #endif
00321
00322 BeginFastIndex3(tgt, target.bbox(), target.data(), MicroType);
00323 BBox bb = where*target.bbox();
00324 for_3 (i,j,k,bb,bb.stepsize())
00325 MicroType feq = lbm.Equilibrium(lbm.MacroVariables(FastIndex3(tgt,i,j,k)));
00326 for (register int n=0; n<NIndex; n++)
00327 FastIndex3(tgt,i,j,k)(Index[n]) = feq(Index[n]);
00328 end_for
00329 EndFastIndex3(tgt);
00330 }
00331 };
00332
00333 #endif