00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "fvMeshSubset.H"
00028 #include "emptyFvsPatchField.H"
00029 #include "emptyPointPatchField.H"
00030 #include "emptyFvPatchFields.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039 template<class Type>
00040 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
00041 (
00042 const GeometricField<Type, fvPatchField, volMesh>& vf,
00043 const fvMesh& sMesh,
00044 const labelList& patchMap,
00045 const labelList& cellMap,
00046 const labelList& faceMap
00047 )
00048 {
00049
00050 Field<Type> internalField(vf.internalField(), cellMap);
00051
00052
00053 PtrList<fvPatchField<Type> > patchFields(patchMap.size());
00054
00055 forAll (patchFields, patchI)
00056 {
00057
00058
00059
00060 if (patchMap[patchI] == -1)
00061 {
00062 patchFields.set
00063 (
00064 patchI,
00065 new emptyFvPatchField<Type>
00066 (
00067 sMesh.boundary()[patchI],
00068 DimensionedField<Type, volMesh>::null()
00069 )
00070 );
00071 }
00072 else
00073 {
00074
00075 const fvPatch& subPatch = sMesh.boundary()[patchI];
00076 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
00077 label baseStart = basePatch.patch().start();
00078 label baseSize = basePatch.size();
00079
00080 labelList directAddressing(subPatch.size());
00081
00082 forAll(directAddressing, i)
00083 {
00084 label baseFaceI = faceMap[subPatch.patch().start()+i];
00085
00086 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
00087 {
00088 directAddressing[i] = baseFaceI-baseStart;
00089 }
00090 else
00091 {
00092
00093
00094 directAddressing[i] = 0;
00095 }
00096 }
00097
00098 patchFields.set
00099 (
00100 patchI,
00101 fvPatchField<Type>::New
00102 (
00103 vf.boundaryField()[patchMap[patchI]],
00104 sMesh.boundary()[patchI],
00105 DimensionedField<Type, volMesh>::null(),
00106 patchFieldSubset(directAddressing)
00107 )
00108 );
00109
00110
00111 }
00112 }
00113
00114
00115
00116 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
00117 (
00118 new GeometricField<Type, fvPatchField, volMesh>
00119 (
00120 IOobject
00121 (
00122 "subset"+vf.name(),
00123 sMesh.time().timeName(),
00124 sMesh,
00125 IOobject::NO_READ,
00126 IOobject::NO_WRITE
00127 ),
00128 sMesh,
00129 vf.dimensions(),
00130 internalField,
00131 patchFields
00132 )
00133 );
00134
00135 return tresF;
00136 }
00137
00138
00139 template<class Type>
00140 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
00141 (
00142 const GeometricField<Type, fvPatchField, volMesh>& vf
00143 ) const
00144 {
00145 return interpolate
00146 (
00147 vf,
00148 subMesh(),
00149 patchMap(),
00150 cellMap(),
00151 faceMap()
00152 );
00153 }
00154
00155
00156 template<class Type>
00157 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
00158 (
00159 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
00160 const fvMesh& sMesh,
00161 const labelList& patchMap,
00162 const labelList& faceMap
00163 )
00164 {
00165
00166 Field<Type> internalField
00167 (
00168 vf.internalField(),
00169 SubList<label>
00170 (
00171 faceMap,
00172 sMesh.nInternalFaces()
00173 )
00174 );
00175
00176
00177 PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
00178
00179 forAll (patchFields, patchI)
00180 {
00181
00182
00183
00184 if (patchMap[patchI] == -1)
00185 {
00186 patchFields.set
00187 (
00188 patchI,
00189 new emptyFvsPatchField<Type>
00190 (
00191 sMesh.boundary()[patchI],
00192 DimensionedField<Type, surfaceMesh>::null()
00193 )
00194 );
00195 }
00196 else
00197 {
00198
00199 const fvPatch& subPatch = sMesh.boundary()[patchI];
00200 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
00201 label baseStart = basePatch.patch().start();
00202 label baseSize = basePatch.size();
00203
00204 labelList directAddressing(subPatch.size());
00205
00206 forAll(directAddressing, i)
00207 {
00208 label baseFaceI = faceMap[subPatch.patch().start()+i];
00209
00210 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
00211 {
00212 directAddressing[i] = baseFaceI-baseStart;
00213 }
00214 else
00215 {
00216
00217
00218 directAddressing[i] = 0;
00219 }
00220 }
00221
00222 patchFields.set
00223 (
00224 patchI,
00225 fvsPatchField<Type>::New
00226 (
00227 vf.boundaryField()[patchMap[patchI]],
00228 sMesh.boundary()[patchI],
00229 DimensionedField<Type, surfaceMesh>::null(),
00230 patchFieldSubset(directAddressing)
00231 )
00232 );
00233 }
00234 }
00235
00236
00237
00238
00239 forAll(patchFields, patchI)
00240 {
00241 fvsPatchField<Type>& pfld = patchFields[patchI];
00242
00243 label meshFaceI = pfld.patch().patch().start();
00244
00245 forAll(pfld, i)
00246 {
00247 label oldFaceI = faceMap[meshFaceI++];
00248
00249 if (oldFaceI < vf.internalField().size())
00250 {
00251 pfld[i] = vf.internalField()[oldFaceI];
00252 }
00253 }
00254 }
00255
00256
00257 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
00258 (
00259 new GeometricField<Type, fvsPatchField, surfaceMesh>
00260 (
00261 IOobject
00262 (
00263 "subset"+vf.name(),
00264 sMesh.time().timeName(),
00265 sMesh,
00266 IOobject::NO_READ,
00267 IOobject::NO_WRITE
00268 ),
00269 sMesh,
00270 vf.dimensions(),
00271 internalField,
00272 patchFields
00273 )
00274 );
00275
00276 return tresF;
00277 }
00278
00279
00280 template<class Type>
00281 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
00282 (
00283 const GeometricField<Type, fvsPatchField, surfaceMesh>& sf
00284 ) const
00285 {
00286 return interpolate
00287 (
00288 sf,
00289 subMesh(),
00290 patchMap(),
00291 faceMap()
00292 );
00293 }
00294
00295
00296 template<class Type>
00297 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00298 fvMeshSubset::interpolate
00299 (
00300 const GeometricField<Type, pointPatchField, pointMesh>& vf,
00301 const pointMesh& sMesh,
00302 const labelList& patchMap,
00303 const labelList& pointMap
00304 )
00305 {
00306
00307 Field<Type> internalField(vf.internalField(), pointMap);
00308
00309
00310 PtrList<pointPatchField<Type> > patchFields(patchMap.size());
00311
00312 forAll (patchFields, patchI)
00313 {
00314
00315
00316
00317 if (patchMap[patchI] == -1)
00318 {
00319 patchFields.set
00320 (
00321 patchI,
00322 new emptyPointPatchField<Type>
00323 (
00324 sMesh.boundary()[patchI],
00325 DimensionedField<Type, pointMesh>::null()
00326 )
00327 );
00328 }
00329 else
00330 {
00331
00332 const pointPatch& basePatch =
00333 vf.mesh().boundary()[patchMap[patchI]];
00334
00335 const labelList& meshPoints = basePatch.meshPoints();
00336
00337
00338 Map<label> meshPointMap(2*meshPoints.size());
00339 forAll(meshPoints, localI)
00340 {
00341 meshPointMap.insert(meshPoints[localI], localI);
00342 }
00343
00344
00345 const pointPatch& subPatch = sMesh.boundary()[patchI];
00346 const labelList& subMeshPoints = subPatch.meshPoints();
00347
00348
00349 labelList directAddressing(subPatch.size(), 0);
00350
00351 forAll(subMeshPoints, localI)
00352 {
00353
00354 label meshPointI = pointMap[subMeshPoints[localI]];
00355
00356 Map<label>::const_iterator iter = meshPointMap.find(meshPointI);
00357
00358 if (iter != meshPointMap.end())
00359 {
00360 directAddressing[localI] = iter();
00361 }
00362 }
00363
00364 patchFields.set
00365 (
00366 patchI,
00367 pointPatchField<Type>::New
00368 (
00369 vf.boundaryField()[patchMap[patchI]],
00370 subPatch,
00371 DimensionedField<Type, pointMesh>::null(),
00372 pointPatchFieldSubset(directAddressing)
00373 )
00374 );
00375 }
00376 }
00377
00378
00379 tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
00380 (
00381 new GeometricField<Type, pointPatchField, pointMesh>
00382 (
00383 IOobject
00384 (
00385 "subset"+vf.name(),
00386 vf.time().timeName(),
00387 sMesh.thisDb(),
00388 IOobject::NO_READ,
00389 IOobject::NO_WRITE
00390 ),
00391 sMesh,
00392 vf.dimensions(),
00393 internalField,
00394 patchFields
00395 )
00396 );
00397
00398 return tresF;
00399 }
00400
00401
00402 template<class Type>
00403 tmp<GeometricField<Type, pointPatchField, pointMesh> > fvMeshSubset::interpolate
00404 (
00405 const GeometricField<Type, pointPatchField, pointMesh>& sf
00406 ) const
00407 {
00408 return interpolate
00409 (
00410 sf,
00411 pointMesh::New(subMesh()),
00412 patchMap(),
00413 pointMap()
00414 );
00415 }
00416
00417
00418
00419
00420 }
00421
00422