ParticleIO.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 "Particle.H"
00028 #include "IOstreams.H"
00029 #include "IOPosition.H"
00030
00031
00032
00033 template<class ParticleType>
00034 Foam::string Foam::Particle<ParticleType>::propHeader =
00035 "(Px Py Pz) cellI origProc origId";
00036
00037
00038
00039 template<class ParticleType>
00040 Foam::Particle<ParticleType>::Particle
00041 (
00042 const Cloud<ParticleType>& cloud,
00043 Istream& is,
00044 bool readFields
00045 )
00046 :
00047 cloud_(cloud),
00048 facei_(-1),
00049 stepFraction_(0.0),
00050 origProc_(Pstream::myProcNo()),
00051 origId_(-1)
00052 {
00053
00054
00055
00056 if (is.format() == IOstream::ASCII)
00057 {
00058 is >> position_ >> celli_;
00059 if (readFields)
00060 {
00061 is >> origProc_ >> origId_;
00062 }
00063 else
00064 {
00065 origId_ = cloud_.getNewParticleID();
00066 }
00067 }
00068 else
00069 {
00070
00071 if (readFields)
00072 {
00073 is.read
00074 (
00075 reinterpret_cast<char*>(&position_),
00076 sizeof(position_)
00077 + sizeof(celli_)
00078 + sizeof(facei_)
00079 + sizeof(stepFraction_)
00080 + sizeof(origProc_)
00081 + sizeof(origId_)
00082 );
00083 }
00084 else
00085 {
00086 is.read
00087 (
00088 reinterpret_cast<char*>(&position_),
00089 sizeof(position_)
00090 + sizeof(celli_)
00091 + sizeof(facei_)
00092 + sizeof(stepFraction_)
00093 );
00094 origId_ = cloud_.getNewParticleID();
00095 }
00096 }
00097
00098 if (celli_ == -1)
00099 {
00100 celli_ = cloud_.pMesh().findCell(position_);
00101 }
00102
00103
00104 is.check("Particle<ParticleType>::Particle(Istream&)");
00105 }
00106
00107
00108 template<class ParticleType>
00109 void Foam::Particle<ParticleType>::readFields
00110 (
00111 Cloud<ParticleType>& c
00112 )
00113 {
00114 if (!c.size())
00115 {
00116 return;
00117 }
00118
00119 IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
00120
00121 if (procIO.headerOk())
00122 {
00123 IOField<label> origProcId(procIO);
00124 c.checkFieldIOobject(c, origProcId);
00125 IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
00126 c.checkFieldIOobject(c, origId);
00127
00128 label i = 0;
00129 forAllIter(typename Cloud<ParticleType>, c, iter)
00130 {
00131 ParticleType& p = iter();
00132
00133 p.origProc_ = origProcId[i];
00134 p.origId_ = origId[i];
00135 i++;
00136 }
00137 }
00138 }
00139
00140
00141 template<class ParticleType>
00142 void Foam::Particle<ParticleType>::writeFields
00143 (
00144 const Cloud<ParticleType>& c
00145 )
00146 {
00147
00148 IOPosition<ParticleType> ioP(c);
00149 ioP.write();
00150
00151 label np = c.size();
00152
00153 IOField<label> origProc
00154 (
00155 c.fieldIOobject
00156 (
00157 "origProcId",
00158 IOobject::NO_READ
00159 ),
00160 np
00161 );
00162 IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
00163
00164 label i = 0;
00165 forAllConstIter(typename Cloud<ParticleType>, c, iter)
00166 {
00167 origProc[i] = iter().origProc_;
00168 origId[i] = iter().origId_;
00169 i++;
00170 }
00171
00172 origProc.write();
00173 origId.write();
00174 }
00175
00176
00177 template<class ParticleType>
00178 void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
00179 {
00180 if (os.format() == IOstream::ASCII)
00181 {
00182 if (writeFields)
00183 {
00184
00185 os << position_
00186 << token::SPACE << celli_
00187 << token::SPACE << origProc_
00188 << token::SPACE << origId_;
00189 }
00190 else
00191 {
00192 os << position_
00193 << token::SPACE << celli_;
00194 }
00195 }
00196 else
00197 {
00198
00199 if (writeFields)
00200 {
00201 os.write
00202 (
00203 reinterpret_cast<const char*>(&position_),
00204 sizeof(position_)
00205 + sizeof(celli_)
00206 + sizeof(facei_)
00207 + sizeof(stepFraction_)
00208 + sizeof(origProc_)
00209 + sizeof(origId_)
00210 );
00211 }
00212 else
00213 {
00214 os.write
00215 (
00216 reinterpret_cast<const char*>(&position_),
00217 sizeof(position_)
00218 + sizeof(celli_)
00219 + sizeof(facei_)
00220 + sizeof(stepFraction_)
00221 );
00222 }
00223 }
00224
00225
00226 os.check("Particle<ParticleType>::write(Ostream& os, bool) const");
00227 }
00228
00229
00230 template<class ParticleType>
00231 Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
00232 {
00233
00234 p.write(os, true);
00235
00236 return os;
00237 }
00238
00239
00240
Copyright © 2000-2009 OpenCFD Ltd