particleTracks.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
00028
00029
00030
00031
00032
00033
00034 #include "argList.H"
00035 #include "Cloud.H"
00036 #include "IOdictionary.H"
00037 #include "fvMesh.H"
00038 #include "Time.H"
00039 #include "timeSelector.H"
00040 #include "OFstream.H"
00041 #include "passiveParticleCloud.H"
00042
00043 using namespace Foam;
00044
00045
00046
00047 int main(int argc, char *argv[])
00048 {
00049 timeSelector::addOptions();
00050 #include "addRegionOption.H"
00051
00052 #include "setRootCase.H"
00053
00054 #include "createTime.H"
00055 instantList timeDirs = timeSelector::select0(runTime, args);
00056 #include "createNamedMesh.H"
00057 #include "createFields.H"
00058
00059
00060
00061 fileName vtkPath(runTime.path()/"VTK");
00062 mkDir(vtkPath);
00063
00064 Info<< "Scanning times to determine track data for cloud " << cloudName
00065 << nl << endl;
00066
00067 labelList maxIds(Pstream::nProcs(), -1);
00068 forAll(timeDirs, timeI)
00069 {
00070 runTime.setTime(timeDirs[timeI], timeI);
00071 Info<< "Time = " << runTime.timeName() << endl;
00072
00073 Info<< " Reading particle positions" << endl;
00074 passiveParticleCloud myCloud(mesh, cloudName);
00075 Info<< " Read " << returnReduce(myCloud.size(), sumOp<label>())
00076 << " particles" << endl;
00077
00078 forAllConstIter(passiveParticleCloud, myCloud, iter)
00079 {
00080 label origId = iter().origId();
00081 label origProc = iter().origProc();
00082
00083 maxIds[origProc] = max(maxIds[origProc], origId);
00084 }
00085 }
00086 Pstream::listCombineGather(maxIds, maxEqOp<label>());
00087 Pstream::listCombineScatter(maxIds);
00088
00089 labelList numIds = maxIds + 1;
00090
00091 Info<< nl << "Particle statistics:" << endl;
00092 forAll(maxIds, procI)
00093 {
00094 Info<< " Found " << numIds[procI] << " particles originating"
00095 << " from processor " << procI << endl;
00096 }
00097 Info<< nl << endl;
00098
00099
00100
00101 List<label> startIds(numIds.size(), 0);
00102 for (label i = 0; i < numIds.size()-1; i++)
00103 {
00104 startIds[i+1] += startIds[i] + numIds[i];
00105 }
00106 label nParticle = startIds[startIds.size()-1] + numIds[startIds.size()-1];
00107
00108
00109
00110
00111 label nTracks = nParticle/sampleFrequency;
00112
00113
00114 List<DynamicList<vector> > allTracks(nTracks);
00115
00116 Info<< "\nGenerating " << nTracks << " particle tracks for cloud "
00117 << cloudName << nl << endl;
00118
00119 forAll(timeDirs, timeI)
00120 {
00121 runTime.setTime(timeDirs[timeI], timeI);
00122 Info<< "Time = " << runTime.timeName() << endl;
00123
00124 List<pointField> allPositions(Pstream::nProcs());
00125 List<labelField> allOrigIds(Pstream::nProcs());
00126 List<labelField> allOrigProcs(Pstream::nProcs());
00127
00128
00129 Info<< " Reading particle positions" << endl;
00130 passiveParticleCloud myCloud(mesh, cloudName);
00131
00132
00133 allPositions[Pstream::myProcNo()].setSize
00134 (
00135 myCloud.size(),
00136 point::zero
00137 );
00138 allOrigIds[Pstream::myProcNo()].setSize(myCloud.size(), 0);
00139 allOrigProcs[Pstream::myProcNo()].setSize(myCloud.size(), 0);
00140
00141 label i = 0;
00142 forAllConstIter(passiveParticleCloud, myCloud, iter)
00143 {
00144 allPositions[Pstream::myProcNo()][i] = iter().position();
00145 allOrigIds[Pstream::myProcNo()][i] = iter().origId();
00146 allOrigProcs[Pstream::myProcNo()][i] = iter().origProc();
00147 i++;
00148 }
00149
00150
00151 Pstream::gatherList(allPositions);
00152 Pstream::gatherList(allOrigIds);
00153 Pstream::gatherList(allOrigProcs);
00154
00155 Info<< " Constructing tracks" << nl << endl;
00156 if (Pstream::master())
00157 {
00158 forAll(allPositions, procI)
00159 {
00160 forAll(allPositions[procI], i)
00161 {
00162 label globalId =
00163 startIds[allOrigProcs[procI][i]]
00164 + allOrigIds[procI][i];
00165
00166 if (globalId % sampleFrequency == 0)
00167 {
00168 label trackId = globalId/sampleFrequency;
00169 if (allTracks[trackId].size() < maxPositions)
00170 {
00171 allTracks[trackId].append
00172 (
00173 allPositions[procI][i]
00174 );
00175 }
00176 }
00177 }
00178 }
00179 }
00180 }
00181
00182 if (Pstream::master())
00183 {
00184 OFstream vtkTracks(vtkPath/"particleTracks.vtk");
00185
00186 Info<< "\nWriting particle tracks to " << vtkTracks.name()
00187 << nl << endl;
00188
00189
00190 label nPoints = 0;
00191 forAll(allTracks, trackI)
00192 {
00193 nPoints += allTracks[trackI].size();
00194 }
00195
00196 vtkTracks
00197 << "# vtk DataFile Version 2.0" << nl
00198 << "particleTracks" << nl
00199 << "ASCII" << nl
00200 << "DATASET POLYDATA" << nl
00201 << "POINTS " << nPoints << " float" << nl;
00202
00203
00204 forAll(allTracks, trackI)
00205 {
00206 forAll(allTracks[trackI], i)
00207 {
00208 const vector& pt = allTracks[trackI][i];
00209 vtkTracks << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
00210 }
00211 }
00212
00213
00214 vtkTracks << "LINES " << nTracks << ' ' << nPoints+nTracks << nl;
00215
00216
00217 label globalPtI = 0;
00218 forAll(allTracks, trackI)
00219 {
00220 vtkTracks << allTracks[trackI].size();
00221
00222 forAll(allTracks[trackI], i)
00223 {
00224 vtkTracks << ' ' << globalPtI;
00225 globalPtI++;
00226 }
00227
00228 vtkTracks << nl;
00229 }
00230
00231 Info<< "end" << endl;
00232 }
00233
00234 return 0;
00235 }
00236
00237
00238
Copyright © 2000-2009 OpenCFD Ltd