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 #include "KinematicParcel.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 #include <OpenFOAM/IOField.H>
00029 #include <lagrangian/Cloud.H>
00030
00031
00032
00033 template <class ParcelType>
00034 Foam::string Foam::KinematicParcel<ParcelType>::propHeader =
00035 Particle<ParcelType>::propHeader
00036 + " active"
00037 + " typeId"
00038 + " nParticle"
00039 + " d"
00040 + " (Ux Uy Uz)"
00041 + " rho"
00042 + " tTurb"
00043 + " (UTurbx UTurby UTurbz)";
00044
00045
00046
00047
00048 template <class ParcelType>
00049 Foam::KinematicParcel<ParcelType>::KinematicParcel
00050 (
00051 const Cloud<ParcelType>& cloud,
00052 Istream& is,
00053 bool readFields
00054 )
00055 :
00056 Particle<ParcelType>(cloud, is, readFields),
00057 active_(false),
00058 typeId_(0),
00059 nParticle_(0.0),
00060 d_(0.0),
00061 U_(vector::zero),
00062 rho_(0.0),
00063 tTurb_(0.0),
00064 UTurb_(vector::zero),
00065 rhoc_(0.0),
00066 Uc_(vector::zero),
00067 muc_(0.0)
00068 {
00069 if (readFields)
00070 {
00071 if (is.format() == IOstream::ASCII)
00072 {
00073 active_ = readBool(is);
00074 typeId_ = readLabel(is);
00075 nParticle_ = readScalar(is);
00076 d_ = readScalar(is);
00077 is >> U_;
00078 rho_ = readScalar(is);
00079 tTurb_ = readScalar(is);
00080 is >> UTurb_;
00081 }
00082 else
00083 {
00084 is.read
00085 (
00086 reinterpret_cast<char*>(&active_),
00087 sizeof(active_)
00088 + sizeof(typeId_)
00089 + sizeof(nParticle_)
00090 + sizeof(d_)
00091 + sizeof(U_)
00092 + sizeof(rho_)
00093 + sizeof(tTurb_)
00094 + sizeof(UTurb_)
00095 );
00096 }
00097 }
00098
00099
00100 is.check
00101 (
00102 "KinematicParcel<ParcelType>::KinematicParcel"
00103 "(const Cloud<ParcelType>&, Istream&, bool)"
00104 );
00105 }
00106
00107
00108 template<class ParcelType>
00109 void Foam::KinematicParcel<ParcelType>::readFields(Cloud<ParcelType>& c)
00110 {
00111 if (!c.size())
00112 {
00113 return;
00114 }
00115
00116 Particle<ParcelType>::readFields(c);
00117
00118 IOField<label> active(c.fieldIOobject("active", IOobject::MUST_READ));
00119 c.checkFieldIOobject(c, active);
00120
00121 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
00122 c.checkFieldIOobject(c, typeId);
00123
00124 IOField<scalar>
00125 nParticle(c.fieldIOobject("nParticle", IOobject::MUST_READ));
00126 c.checkFieldIOobject(c, nParticle);
00127
00128 IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
00129 c.checkFieldIOobject(c, d);
00130
00131 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00132 c.checkFieldIOobject(c, U);
00133
00134 IOField<scalar> rho(c.fieldIOobject("rho", IOobject::MUST_READ));
00135 c.checkFieldIOobject(c, rho);
00136
00137 IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
00138 c.checkFieldIOobject(c, tTurb);
00139
00140 IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::MUST_READ));
00141 c.checkFieldIOobject(c, UTurb);
00142
00143 label i = 0;
00144 forAllIter(typename Cloud<ParcelType>, c, iter)
00145 {
00146 ParcelType& p = iter();
00147
00148 p.active_ = active[i];
00149 p.typeId_ = typeId[i];
00150 p.nParticle_ = nParticle[i];
00151 p.d_ = d[i];
00152 p.U_ = U[i];
00153 p.rho_ = rho[i];
00154 p.tTurb_ = tTurb[i];
00155 p.UTurb_ = UTurb[i];
00156 i++;
00157 }
00158 }
00159
00160
00161 template<class ParcelType>
00162 void Foam::KinematicParcel<ParcelType>::writeFields(const Cloud<ParcelType>& c)
00163 {
00164 Particle<ParcelType>::writeFields(c);
00165
00166 label np = c.size();
00167
00168 IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
00169 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
00170 IOField<scalar> nParticle
00171 (
00172 c.fieldIOobject("nParticle", IOobject::NO_READ),
00173 np
00174 );
00175 IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
00176 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00177 IOField<scalar> rho(c.fieldIOobject("rho", IOobject::NO_READ), np);
00178 IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
00179 IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::NO_READ), np);
00180
00181 label i = 0;
00182 forAllConstIter(typename Cloud<ParcelType>, c, iter)
00183 {
00184 const KinematicParcel<ParcelType>& p = iter();
00185
00186 active[i] = p.active();
00187 typeId[i] = p.typeId();
00188 nParticle[i] = p.nParticle();
00189 d[i] = p.d();
00190 U[i] = p.U();
00191 rho[i] = p.rho();
00192 tTurb[i] = p.tTurb();
00193 UTurb[i] = p.UTurb();
00194 i++;
00195 }
00196
00197 active.write();
00198 typeId.write();
00199 nParticle.write();
00200 d.write();
00201 U.write();
00202 rho.write();
00203 tTurb.write();
00204 UTurb.write();
00205 }
00206
00207
00208
00209
00210 template<class ParcelType>
00211 Foam::Ostream& Foam::operator<<
00212 (
00213 Ostream& os,
00214 const KinematicParcel<ParcelType>& p
00215 )
00216 {
00217 if (os.format() == IOstream::ASCII)
00218 {
00219 os << static_cast<const Particle<ParcelType>&>(p)
00220 << token::SPACE << p.active()
00221 << token::SPACE << p.typeId()
00222 << token::SPACE << p.nParticle()
00223 << token::SPACE << p.d()
00224 << token::SPACE << p.U()
00225 << token::SPACE << p.rho()
00226 << token::SPACE << p.tTurb()
00227 << token::SPACE << p.UTurb();
00228 }
00229 else
00230 {
00231 os << static_cast<const Particle<ParcelType>&>(p);
00232 os.write
00233 (
00234 reinterpret_cast<const char*>(&p.active_),
00235 sizeof(p.active())
00236 + sizeof(p.typeId())
00237 + sizeof(p.nParticle())
00238 + sizeof(p.d())
00239 + sizeof(p.U())
00240 + sizeof(p.rho())
00241 + sizeof(p.tTurb())
00242 + sizeof(p.UTurb())
00243 );
00244 }
00245
00246
00247 os.check
00248 (
00249 "Ostream& operator<<(Ostream&, const KinematicParcel<ParcelType>&)"
00250 );
00251
00252 return os;
00253 }
00254
00255
00256