solidParticleIO.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 "solidParticle.H"
00028 #include "IOstreams.H"
00029
00030
00031
00032 Foam::solidParticle::solidParticle
00033 (
00034 const Cloud<solidParticle>& cloud,
00035 Istream& is,
00036 bool readFields
00037 )
00038 :
00039 Particle<solidParticle>(cloud, is, readFields)
00040 {
00041 if (readFields)
00042 {
00043 if (is.format() == IOstream::ASCII)
00044 {
00045 d_ = readScalar(is);
00046 is >> U_;
00047 }
00048 else
00049 {
00050 is.read
00051 (
00052 reinterpret_cast<char*>(&d_),
00053 sizeof(d_) + sizeof(U_)
00054 );
00055 }
00056 }
00057
00058
00059 is.check("solidParticle::solidParticle(Istream&)");
00060 }
00061
00062
00063 void Foam::solidParticle::readFields(Cloud<solidParticle>& c)
00064 {
00065 if (!c.size())
00066 {
00067 return;
00068 }
00069 IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
00070 c.checkFieldIOobject(c, d);
00071
00072 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00073 c.checkFieldIOobject(c, U);
00074
00075 label i = 0;
00076 forAllIter(Cloud<solidParticle>::iterator, c, iter)
00077 {
00078 solidParticle& p = iter();
00079
00080 p.d_ = d[i];
00081 p.U_ = U[i];
00082 i++;
00083 }
00084 }
00085
00086
00087 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
00088 {
00089 Particle<solidParticle>::writeFields(c);
00090
00091 label np = c.size();
00092
00093 IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
00094 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00095
00096 label i = 0;
00097 forAllConstIter(Cloud<solidParticle>, c, iter)
00098 {
00099 const solidParticle& p = iter();
00100
00101 d[i] = p.d_;
00102 U[i] = p.U_;
00103 i++;
00104 }
00105
00106 d.write();
00107 U.write();
00108 }
00109
00110
00111
00112
00113 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
00114 {
00115 if (os.format() == IOstream::ASCII)
00116 {
00117 os << static_cast<const Particle<solidParticle>&>(p)
00118 << token::SPACE << p.d_
00119 << token::SPACE << p.U_;
00120 }
00121 else
00122 {
00123 os << static_cast<const Particle<solidParticle>&>(p);
00124 os.write
00125 (
00126 reinterpret_cast<const char*>(&p.d_),
00127 sizeof(p.d_) + sizeof(p.U_)
00128 );
00129 }
00130
00131
00132 os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
00133
00134 return os;
00135 }
00136
00137
00138
Copyright © 2000-2009 OpenCFD Ltd