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 #include "Cloud.H"
00027 #include <lagrangian/Particle.H>
00028 #include <OpenFOAM/Time.H>
00029 #include <lagrangian/IOPosition.H>
00030
00031
00032
00033 template<class ParticleType>
00034 Foam::word Foam::Cloud<ParticleType>::cloudPropertiesName("cloudProperties");
00035
00036
00037
00038
00039 template<class ParticleType>
00040 void Foam::Cloud<ParticleType>::readCloudUniformProperties()
00041 {
00042 IOobject uniformPropsDictHeader
00043 (
00044 cloudPropertiesName,
00045 time().timeName(),
00046 "uniform"/cloud::prefix/name(),
00047 db(),
00048 IOobject::MUST_READ,
00049 IOobject::NO_WRITE,
00050 false
00051 );
00052
00053 if (uniformPropsDictHeader.headerOk())
00054 {
00055 const IOdictionary uniformPropsDict(uniformPropsDictHeader);
00056
00057 word procName("processor" + Foam::name(Pstream::myProcNo()));
00058 if (uniformPropsDict.found(procName))
00059 {
00060 uniformPropsDict.subDict(procName).lookup("particleCount")
00061 >> particleCount_;
00062 }
00063 }
00064 else
00065 {
00066 particleCount_ = 0;
00067 }
00068 }
00069
00070
00071 template<class ParticleType>
00072 void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
00073 {
00074 IOdictionary uniformPropsDict
00075 (
00076 IOobject
00077 (
00078 cloudPropertiesName,
00079 time().timeName(),
00080 "uniform"/cloud::prefix/name(),
00081 db(),
00082 IOobject::NO_READ,
00083 IOobject::NO_WRITE,
00084 false
00085 )
00086 );
00087
00088 labelList np(Pstream::nProcs(), 0);
00089 np[Pstream::myProcNo()] = particleCount_;
00090
00091 Pstream::listCombineGather(np, maxEqOp<label>());
00092 Pstream::listCombineScatter(np);
00093
00094 forAll(np, i)
00095 {
00096 word procName("processor" + Foam::name(i));
00097 uniformPropsDict.add(procName, dictionary());
00098 uniformPropsDict.subDict(procName).add("particleCount", np[i]);
00099 }
00100
00101 uniformPropsDict.regIOobject::write();
00102 }
00103
00104
00105 template<class ParticleType>
00106 void Foam::Cloud<ParticleType>::initCloud(const bool checkClass)
00107 {
00108 readCloudUniformProperties();
00109
00110 IOPosition<ParticleType> ioP(*this);
00111
00112 if (ioP.headerOk())
00113 {
00114 ioP.readData(*this, checkClass);
00115 ioP.close();
00116
00117 if (this->size())
00118 {
00119 readFields();
00120 }
00121 }
00122 else
00123 {
00124 if (debug)
00125 {
00126 WarningIn("Cloud<ParticleType>::initCloud(const bool checkClass)")
00127 << "Cannot read particle positions file " << nl
00128 << " " << ioP.objectPath() << nl
00129 << " assuming the initial cloud contains 0 particles."
00130 << endl;
00131 }
00132 }
00133 }
00134
00135
00136
00137
00138 template<class ParticleType>
00139 Foam::Cloud<ParticleType>::Cloud
00140 (
00141 const polyMesh& pMesh,
00142 const bool checkClass
00143 )
00144 :
00145 cloud(pMesh),
00146 polyMesh_(pMesh),
00147 particleCount_(0)
00148 {
00149 initCloud(checkClass);
00150 }
00151
00152
00153 template<class ParticleType>
00154 Foam::Cloud<ParticleType>::Cloud
00155 (
00156 const polyMesh& pMesh,
00157 const word& cloudName,
00158 const bool checkClass
00159 )
00160 :
00161 cloud(pMesh, cloudName),
00162 polyMesh_(pMesh),
00163 particleCount_(0)
00164 {
00165 initCloud(checkClass);
00166 }
00167
00168
00169
00170
00171 template<class ParticleType>
00172 Foam::IOobject Foam::Cloud<ParticleType>::fieldIOobject
00173 (
00174 const word& fieldName,
00175 const IOobject::readOption r
00176 ) const
00177 {
00178 return IOobject
00179 (
00180 fieldName,
00181 time().timeName(),
00182 *this,
00183 r,
00184 IOobject::NO_WRITE,
00185 false
00186 );
00187 }
00188
00189
00190 template<class ParticleType>
00191 template<class DataType>
00192 void Foam::Cloud<ParticleType>::checkFieldIOobject
00193 (
00194 const Cloud<ParticleType>& c,
00195 const IOField<DataType>& data
00196 ) const
00197 {
00198 if (data.size() != c.size())
00199 {
00200 FatalErrorIn
00201 (
00202 "void Cloud<ParticleType>::checkFieldIOobject"
00203 "(const Cloud<ParticleType>&, const IOField<DataType>&) const"
00204 ) << "Size of " << data.name()
00205 << " field " << data.size()
00206 << " does not match the number of particles " << c.size()
00207 << abort(FatalError);
00208 }
00209 }
00210
00211
00212 template<class ParticleType>
00213 void Foam::Cloud<ParticleType>::readFields()
00214 {}
00215
00216
00217 template<class ParticleType>
00218 void Foam::Cloud<ParticleType>::writeFields() const
00219 {
00220 if (this->size())
00221 {
00222 const ParticleType& p = *this->first();
00223 ParticleType::writeFields(p.cloud());
00224 }
00225 }
00226
00227
00228 template<class ParticleType>
00229 bool Foam::Cloud<ParticleType>::writeObject
00230 (
00231 IOstream::streamFormat fmt,
00232 IOstream::versionNumber ver,
00233 IOstream::compressionType cmp
00234 ) const
00235 {
00236 writeCloudUniformProperties();
00237
00238 if (this->size())
00239 {
00240 writeFields();
00241 return cloud::writeObject(fmt, ver, cmp);
00242 }
00243 else
00244 {
00245 return true;
00246 }
00247 }
00248
00249
00250
00251
00252 template<class ParticleType>
00253 Foam::Ostream& Foam::operator<<(Ostream& os, const Cloud<ParticleType>& pc)
00254 {
00255 pc.writeData(os);
00256
00257
00258 os.check("Ostream& operator<<(Ostream&, const Cloud<ParticleType>&)");
00259
00260 return os;
00261 }
00262
00263
00264