faceZonesIntegration.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 "faceZonesIntegration.H"
00028 #include "volFields.H"
00029 #include "dictionary.H"
00030 #include "Time.H"
00031 #include "IOmanip.H"
00032 #include "ListListOps.H"
00033 #include "processorPolyPatch.H"
00034 #include "cyclicPolyPatch.H"
00035
00036
00037
00038 namespace Foam
00039 {
00040 defineTypeNameAndDebug(faceZonesIntegration, 0);
00041 }
00042
00043
00044
00045
00046 Foam::faceZonesIntegration::faceZonesIntegration
00047 (
00048 const word& name,
00049 const objectRegistry& obr,
00050 const dictionary& dict,
00051 const bool loadFromFiles
00052 )
00053 :
00054 name_(name),
00055 obr_(obr),
00056 active_(true),
00057 log_(false),
00058 faceZonesSet_(),
00059 fItems_(),
00060 faceZonesIntegrationFilePtr_(NULL)
00061 {
00062
00063 if (!isA<fvMesh>(obr_))
00064 {
00065 active_ = false;
00066 WarningIn
00067 (
00068 "Foam::faceZonesIntegration::faceZonesIntegration"
00069 "("
00070 "const word&, "
00071 "const objectRegistry&, "
00072 "const dictionary&, "
00073 "const bool"
00074 ")"
00075 ) << "No fvMesh available, deactivating."
00076 << endl;
00077 }
00078
00079 read(dict);
00080 }
00081
00082
00083
00084
00085 Foam::faceZonesIntegration::~faceZonesIntegration()
00086 {}
00087
00088
00089
00090
00091 void Foam::faceZonesIntegration::read(const dictionary& dict)
00092 {
00093 if (active_)
00094 {
00095 log_ = dict.lookupOrDefault<Switch>("log", false);
00096
00097 dict.lookup("fields") >> fItems_;
00098
00099 dict.lookup("faceZones") >> faceZonesSet_;
00100 }
00101 }
00102
00103
00104 void Foam::faceZonesIntegration::makeFile()
00105 {
00106
00107 if (faceZonesIntegrationFilePtr_.empty())
00108 {
00109 if (debug)
00110 {
00111 Info<< "Creating faceZonesIntegration file." << endl;
00112 }
00113
00114
00115 if (Pstream::master())
00116 {
00117 fileName faceZonesIntegrationDir;
00118 if (Pstream::parRun())
00119 {
00120
00121
00122 faceZonesIntegrationDir =
00123 obr_.time().path()/".."/name_/obr_.time().timeName();
00124 }
00125 else
00126 {
00127 faceZonesIntegrationDir =
00128 obr_.time().path()/name_/obr_.time().timeName();
00129 }
00130
00131
00132 mkDir(faceZonesIntegrationDir);
00133
00134
00135 faceZonesIntegrationFilePtr_.resize(fItems_.size());
00136
00137 forAll(fItems_, Ifields)
00138 {
00139 const word& fieldName = fItems_[Ifields];
00140
00141 OFstream* sPtr = new OFstream
00142 (
00143 faceZonesIntegrationDir/fieldName
00144 );
00145
00146 faceZonesIntegrationFilePtr_.insert(fieldName, sPtr);
00147 }
00148
00149
00150 writeFileHeader();
00151 }
00152 }
00153 }
00154
00155
00156 void Foam::faceZonesIntegration::writeFileHeader()
00157 {
00158 forAllIter(HashPtrTable<OFstream>, faceZonesIntegrationFilePtr_, iter)
00159 {
00160 unsigned int w = IOstream::defaultPrecision() + 7;
00161
00162 OFstream& os = *faceZonesIntegrationFilePtr_[iter.key()];
00163
00164 os << "#Time " << setw(w);
00165
00166 forAll (faceZonesSet_, zoneI)
00167 {
00168 const word name = faceZonesSet_[zoneI];
00169 os << name << setw(w);
00170 }
00171
00172 os << nl << endl;
00173 }
00174 }
00175
00176
00177 void Foam::faceZonesIntegration::execute()
00178 {
00179
00180 }
00181
00182
00183 void Foam::faceZonesIntegration::end()
00184 {
00185
00186 }
00187
00188
00189 void Foam::faceZonesIntegration::write()
00190 {
00191 if (active_)
00192 {
00193 makeFile();
00194 scalar dm = 0.0;
00195 forAll(fItems_, fieldI)
00196 {
00197 const word& fieldName = fItems_[fieldI];
00198
00199 const surfaceScalarField& fD =
00200 obr_.lookupObject<surfaceScalarField>(fieldName);
00201
00202 const fvMesh& mesh = fD.mesh();
00203
00204 unsigned int w = IOstream::defaultPrecision() + 7;
00205
00206 if
00207 (
00208 Pstream::master()
00209 && faceZonesIntegrationFilePtr_.found(fieldName)
00210 )
00211 {
00212 OFstream& os = *faceZonesIntegrationFilePtr_(fieldName);
00213
00214 os << obr_.time().value();
00215
00216 const faceZoneMesh& faceZoneList = mesh.faceZones();
00217
00218 forAll(faceZonesSet_, zoneI)
00219 {
00220 const word name = faceZonesSet_[zoneI];
00221
00222 label zoneID = faceZoneList.findZoneID(name);
00223
00224 const faceZone& fz = mesh.faceZones()[zoneID];
00225
00226 dm = calcFaceZonesIntegral(fD, fz);
00227
00228 reduce(dm, sumOp<scalar>());
00229
00230 os << ' ' << setw(w) << dm;
00231
00232 if (log_)
00233 {
00234 Info<< "faceZonesIntegration output:" << nl
00235 << " Integration" << dm << endl;
00236 }
00237 }
00238
00239 os << endl;
00240 }
00241 }
00242 }
00243 }
00244
00245
00246 Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral
00247 (
00248 const surfaceScalarField& fD,
00249 const faceZone& fz
00250 ) const
00251 {
00252 scalar dm = 0.0;
00253 const fvMesh& mesh = fD.mesh();
00254
00255 forAll (fz, i)
00256 {
00257 label faceI = fz[i];
00258
00259 if (mesh.isInternalFace(faceI))
00260 {
00261 if (fz.flipMap()[faceI])
00262 {
00263 dm -= fD[faceI];
00264 }
00265 else
00266 {
00267 dm += fD[faceI];
00268 }
00269 }
00270 else
00271 {
00272 label patchI = mesh.boundaryMesh().whichPatch(faceI);
00273 const polyPatch& pp = mesh.boundaryMesh()[patchI];
00274 if (isA<processorPolyPatch>(pp))
00275 {
00276 if (refCast<const processorPolyPatch>(pp).owner())
00277 {
00278 if (fz.flipMap()[faceI])
00279 {
00280 dm -= fD.boundaryField()[patchI][pp.whichFace(faceI)];
00281 }
00282 else
00283 {
00284 dm += fD.boundaryField()[patchI][pp.whichFace(faceI)];
00285 }
00286 }
00287 }
00288 else if (isA<cyclicPolyPatch>(pp))
00289 {
00290 label patchFaceI = faceI - pp.start();
00291 if (patchFaceI < pp.size()/2)
00292 {
00293 if (fz.flipMap()[patchFaceI])
00294 {
00295 dm -= fD.boundaryField()[patchI][patchFaceI];
00296 }
00297 else
00298 {
00299 dm += fD.boundaryField()[patchI][patchFaceI];
00300 }
00301 }
00302 }
00303 else if (!isA<emptyPolyPatch>(pp))
00304 {
00305 label patchFaceI = faceI - pp.start();
00306 if (fz.flipMap()[patchFaceI])
00307 {
00308 dm -= fD.boundaryField()[patchI][patchFaceI];
00309 }
00310 else
00311 {
00312 dm += fD.boundaryField()[patchI][patchFaceI];
00313 }
00314 }
00315 }
00316 }
00317
00318 return dm;
00319 }
00320
00321
00322
Copyright © 2000-2009 OpenCFD Ltd