DsmcParcelIO.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 "DsmcParcel.H"
00028 #include "IOstreams.H"
00029 #include "IOField.H"
00030 #include "Cloud.H"
00031
00032
00033
00034 template <class ParcelType>
00035 Foam::DsmcParcel<ParcelType>::DsmcParcel
00036 (
00037 const Cloud<ParcelType>& cloud,
00038 Istream& is,
00039 bool readFields
00040 )
00041 :
00042 Particle<ParcelType>(cloud, is, readFields),
00043 U_(vector::zero),
00044 Ei_(0.0),
00045 typeId_(-1)
00046 {
00047 if (readFields)
00048 {
00049 if (is.format() == IOstream::ASCII)
00050 {
00051 is >> U_;
00052 Ei_ = readScalar(is);
00053 typeId_ = readLabel(is);
00054 }
00055 else
00056 {
00057 is.read
00058 (
00059 reinterpret_cast<char*>(&U_),
00060 sizeof(U_)
00061 + sizeof(Ei_)
00062 + sizeof(typeId_)
00063 );
00064 }
00065 }
00066
00067
00068 is.check
00069 (
00070 "DsmcParcel<ParcelType>::DsmcParcel"
00071 "(const Cloud<ParcelType>&, Istream&, bool)"
00072 );
00073 }
00074
00075
00076 template<class ParcelType>
00077 void Foam::DsmcParcel<ParcelType>::readFields
00078 (
00079 DsmcCloud<ParcelType>& c
00080 )
00081 {
00082 if (!c.size())
00083 {
00084 return;
00085 }
00086
00087 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00088 c.checkFieldIOobject(c, U);
00089
00090 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::MUST_READ));
00091 c.checkFieldIOobject(c, Ei);
00092
00093 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
00094 c.checkFieldIOobject(c, typeId);
00095
00096 label i = 0;
00097 forAllIter(typename Cloud<ParcelType>, c, iter)
00098 {
00099 ParcelType& p = iter();
00100
00101 p.U_ = U[i];
00102 p.Ei_ = Ei[i];
00103 p.typeId_ = typeId[i];
00104 i++;
00105 }
00106 }
00107
00108
00109 template<class ParcelType>
00110 void Foam::DsmcParcel<ParcelType>::writeFields
00111 (
00112 const DsmcCloud<ParcelType>& c
00113 )
00114 {
00115 Particle<ParcelType>::writeFields(c);
00116
00117 label np = c.size();
00118
00119 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00120 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::NO_READ), np);
00121 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
00122
00123 label i = 0;
00124 forAllConstIter(typename Cloud<ParcelType>, c, iter)
00125 {
00126 const DsmcParcel<ParcelType>& p = iter();
00127
00128 U[i] = p.U();
00129 Ei[i] = p.Ei();
00130 typeId[i] = p.typeId();
00131 i++;
00132 }
00133
00134 U.write();
00135 Ei.write();
00136 typeId.write();
00137 }
00138
00139
00140
00141
00142 template<class ParcelType>
00143 Foam::Ostream& Foam::operator<<
00144 (
00145 Ostream& os,
00146 const DsmcParcel<ParcelType>& p
00147 )
00148 {
00149 if (os.format() == IOstream::ASCII)
00150 {
00151 os << static_cast<const Particle<ParcelType>& >(p)
00152 << token::SPACE << p.U()
00153 << token::SPACE << p.Ei()
00154 << token::SPACE << p.typeId();
00155 }
00156 else
00157 {
00158 os << static_cast<const Particle<ParcelType>& >(p);
00159 os.write
00160 (
00161 reinterpret_cast<const char*>(&p.U_),
00162 sizeof(p.U())
00163 + sizeof(p.Ei())
00164 + sizeof(p.typeId())
00165 );
00166 }
00167
00168
00169 os.check
00170 (
00171 "Ostream& operator<<(Ostream&, const DsmcParcel<ParcelType>&)"
00172 );
00173
00174 return os;
00175 }
00176
00177
00178
Copyright © 2000-2009 OpenCFD Ltd