mapLagrangian.C
Go to the documentation of this file.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 "MapLagrangianFields.H"
00028 #include "Cloud.H"
00029 #include "passiveParticle.H"
00030 #include "meshSearch.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037 static const scalar perturbFactor = 1E-6;
00038
00039
00040
00041
00042 static label findCell(const meshSearch& meshSearcher, const point& pt)
00043 {
00044 const polyMesh& mesh = meshSearcher.mesh();
00045
00046
00047 label cellI = meshSearcher.findCell(pt);
00048
00049 if (cellI >= 0)
00050 {
00051 return cellI;
00052 }
00053 else
00054 {
00055
00056
00057
00058 label faceI = meshSearcher.findNearestBoundaryFace(pt);
00059
00060 if (faceI >= 0)
00061 {
00062 const point& cc = mesh.cellCentres()[mesh.faceOwner()[faceI]];
00063 const point perturbPt = (1-perturbFactor)*pt+perturbFactor*cc;
00064
00065 return meshSearcher.findCell(perturbPt);
00066 }
00067 }
00068 return -1;
00069 }
00070
00071
00072 void mapLagrangian(const meshToMesh& meshToMeshInterp)
00073 {
00074
00075
00076
00077
00078 const labelList& cellAddressing = meshToMeshInterp.cellAddressing();
00079
00080
00081
00082
00083 labelListList sourceToTargets
00084 (
00085 invertOneToMany(meshToMeshInterp.fromMesh().nCells(), cellAddressing)
00086 );
00087
00088 const fvMesh& meshSource = meshToMeshInterp.fromMesh();
00089 const fvMesh& meshTarget = meshToMeshInterp.toMesh();
00090 const pointField& targetCc = meshTarget.cellCentres();
00091
00092
00093 fileNameList cloudDirs
00094 (
00095 readDir
00096 (
00097 meshSource.time().timePath()/cloud::prefix,
00098 fileName::DIRECTORY
00099 )
00100 );
00101
00102 forAll(cloudDirs, cloudI)
00103 {
00104
00105 IOobjectList objects
00106 (
00107 meshSource,
00108 meshSource.time().timeName(),
00109 cloud::prefix/cloudDirs[cloudI]
00110 );
00111
00112 IOobject* positionsPtr = objects.lookup("positions");
00113
00114 if (positionsPtr)
00115 {
00116 Info<< nl << " processing cloud " << cloudDirs[cloudI] << endl;
00117
00118
00119 Cloud<passiveParticle> sourceParcels
00120 (
00121 meshSource,
00122 cloudDirs[cloudI],
00123 false
00124 );
00125 Info<< " read " << sourceParcels.size()
00126 << " parcels from source mesh." << endl;
00127
00128
00129 Cloud<passiveParticle> targetParcels
00130 (
00131 meshTarget,
00132 cloudDirs[cloudI],
00133 IDLList<passiveParticle>()
00134 );
00135
00136 label sourceParticleI = 0;
00137
00138
00139 DynamicList<label> addParticles(sourceParcels.size());
00140
00141
00142 labelHashSet unmappedSource(sourceParcels.size());
00143
00144
00145
00146
00147
00148
00149
00150 forAllConstIter(Cloud<passiveParticle>, sourceParcels, iter)
00151 {
00152 bool foundCell = false;
00153
00154
00155 if (iter().cell() >= 0)
00156 {
00157 const labelList& targetCells =
00158 sourceToTargets[iter().cell()];
00159
00160
00161
00162
00163
00164 forAll(targetCells, i)
00165 {
00166
00167 autoPtr<passiveParticle> newPtr
00168 (
00169 new passiveParticle
00170 (
00171 targetParcels,
00172 targetCc[targetCells[i]],
00173 targetCells[i]
00174 )
00175 );
00176 passiveParticle& newP = newPtr();
00177
00178 scalar fraction = 0;
00179 label faceI = newP.track(iter().position(), fraction);
00180
00181 if (faceI < 0 && newP.cell() >= 0)
00182 {
00183
00184 foundCell = true;
00185 addParticles.append(sourceParticleI);
00186 targetParcels.addParticle(newPtr.ptr());
00187 break;
00188 }
00189 }
00190 }
00191
00192 if (!foundCell)
00193 {
00194
00195 unmappedSource.insert(sourceParticleI);
00196 }
00197
00198 sourceParticleI++;
00199 }
00200
00201 Info<< " after meshToMesh addressing found "
00202 << targetParcels.size()
00203 << " parcels in target mesh." << endl;
00204
00205
00206
00207
00208
00209 if (unmappedSource.size())
00210 {
00211 meshSearch targetSearcher(meshTarget, false);
00212
00213 sourceParticleI = 0;
00214
00215 forAllIter(Cloud<passiveParticle>, sourceParcels, iter)
00216 {
00217 if (unmappedSource.found(sourceParticleI))
00218 {
00219 label targetCell =
00220 findCell(targetSearcher, iter().position());
00221
00222 if (targetCell >= 0)
00223 {
00224 unmappedSource.erase(sourceParticleI);
00225 addParticles.append(sourceParticleI);
00226 iter().cell()=targetCell;
00227 targetParcels.addParticle
00228 (
00229 sourceParcels.remove(&iter())
00230 );
00231 }
00232 }
00233 sourceParticleI++;
00234 }
00235 }
00236 addParticles.shrink();
00237
00238 Info<< " after additional mesh searching found "
00239 << targetParcels.size() << " parcels in target mesh." << endl;
00240
00241 if (addParticles.size())
00242 {
00243 IOPosition<passiveParticle>(targetParcels).write();
00244
00245
00246
00247
00248
00249
00250
00251 MapLagrangianFields<label>
00252 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00253 MapLagrangianFields<scalar>
00254 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00255 MapLagrangianFields<vector>
00256 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00257 MapLagrangianFields<sphericalTensor>
00258 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00259 MapLagrangianFields<symmTensor>
00260 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00261 MapLagrangianFields<tensor>
00262 (cloudDirs[cloudI], objects, meshToMeshInterp, addParticles);
00263 }
00264 }
00265 }
00266 }
00267
00268
00269
00270
00271 }
00272
00273
Copyright © 2000-2009 OpenCFD Ltd