Commit e4727a48 authored by Andrew Heather's avatar Andrew Heather
Browse files

refactoring

parent ac74494b
......@@ -57,7 +57,7 @@ Foam::faceZonesIntegration::faceZonesIntegration
log_(false),
faceZonesSet_(),
fItems_(),
faceZonesIntegrationFilePtr_(NULL)
filePtr_(NULL)
{
// Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_))
......@@ -104,7 +104,7 @@ void Foam::faceZonesIntegration::read(const dictionary& dict)
void Foam::faceZonesIntegration::makeFile()
{
// Create the face Zone file if not already created
if (faceZonesIntegrationFilePtr_.empty())
if (filePtr_.empty())
{
if (debug)
{
......@@ -132,7 +132,7 @@ void Foam::faceZonesIntegration::makeFile()
mkDir(faceZonesIntegrationDir);
// Open new file at start up
faceZonesIntegrationFilePtr_.resize(fItems_.size());
filePtr_.resize(fItems_.size());
forAll(fItems_, Ifields)
{
......@@ -143,7 +143,7 @@ void Foam::faceZonesIntegration::makeFile()
faceZonesIntegrationDir/fieldName
);
faceZonesIntegrationFilePtr_.insert(fieldName, sPtr);
filePtr_.insert(fieldName, sPtr);
}
// Add headers to output data
......@@ -155,11 +155,11 @@ void Foam::faceZonesIntegration::makeFile()
void Foam::faceZonesIntegration::writeFileHeader()
{
forAllIter(HashPtrTable<OFstream>, faceZonesIntegrationFilePtr_, iter)
forAllIter(HashPtrTable<OFstream>, filePtr_, iter)
{
unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& os = *faceZonesIntegrationFilePtr_[iter.key()];
OFstream& os = *filePtr_[iter.key()];
os << "#Time " << setw(w);
......@@ -196,10 +196,10 @@ void Foam::faceZonesIntegration::write()
{
const word& fieldName = fItems_[fieldI];
const surfaceScalarField& fD =
const surfaceScalarField& sField =
obr_.lookupObject<surfaceScalarField>(fieldName);
const fvMesh& mesh = fD.mesh();
const fvMesh& mesh = sField.mesh();
// 1. integrate over all face zones
......@@ -211,11 +211,11 @@ void Foam::faceZonesIntegration::write()
label zoneID = mesh.faceZones().findZoneID(name);
const faceZone& fz = mesh.faceZones()[zoneID];
const faceZone& fZone = mesh.faceZones()[zoneID];
integralVals[setI] = returnReduce
(
calcFaceZonesIntegral(fD, fz),
calcIntegral(sField, fZone),
sumOp<scalar>()
);
}
......@@ -225,13 +225,9 @@ void Foam::faceZonesIntegration::write()
// 2. Write only on master
if
(
Pstream::master()
&& faceZonesIntegrationFilePtr_.found(fieldName)
)
if (Pstream::master() && filePtr_.found(fieldName))
{
OFstream& os = *faceZonesIntegrationFilePtr_(fieldName);
OFstream& os = *filePtr_(fieldName);
os << obr_.time().value();
......@@ -242,7 +238,8 @@ void Foam::faceZonesIntegration::write()
if (log_)
{
Info<< "faceZonesIntegration output:" << nl
<< " Integration" << integralVals[setI] << endl;
<< " Integration[" << setI << "] "
<< integralVals[setI] << endl;
}
}
......@@ -253,45 +250,47 @@ void Foam::faceZonesIntegration::write()
}
Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral
Foam::scalar Foam::faceZonesIntegration::calcIntegral
(
const surfaceScalarField& fD,
const faceZone& fz
const surfaceScalarField& sField,
const faceZone& fZone
) const
{
scalar dm = 0.0;
const fvMesh& mesh = fD.mesh();
scalar sum = 0.0;
const fvMesh& mesh = sField.mesh();
forAll (fz, i)
forAll (fZone, i)
{
label faceI = fz[i];
label faceI = fZone[i];
if (mesh.isInternalFace(faceI))
{
if (fz.flipMap()[i])
if (fZone.flipMap()[i])
{
dm -= fD[faceI];
sum -= sField[faceI];
}
else
{
dm += fD[faceI];
sum += sField[faceI];
}
}
else
{
label patchI = mesh.boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh.boundaryMesh()[patchI];
const fvsPatchScalarField& bField = sField.boundaryField()[patchI];
if (isA<processorPolyPatch>(pp))
{
if (refCast<const processorPolyPatch>(pp).owner())
{
if (fz.flipMap()[i])
label patchFaceI = pp.whichFace(faceI);
if (fZone.flipMap()[i])
{
dm -= fD.boundaryField()[patchI][pp.whichFace(faceI)];
sum -= bField[patchFaceI];
}
else
{
dm += fD.boundaryField()[patchI][pp.whichFace(faceI)];
sum += bField[patchFaceI];
}
}
}
......@@ -300,32 +299,32 @@ Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral
label patchFaceI = faceI - pp.start();
if (patchFaceI < pp.size()/2)
{
if (fz.flipMap()[i])
if (fZone.flipMap()[i])
{
dm -= fD.boundaryField()[patchI][patchFaceI];
sum -= bField[patchFaceI];
}
else
{
dm += fD.boundaryField()[patchI][patchFaceI];
sum += bField[patchFaceI];
}
}
}
else if (!isA<emptyPolyPatch>(pp))
{
label patchFaceI = faceI - pp.start();
if (fz.flipMap()[i])
if (fZone.flipMap()[i])
{
dm -= fD.boundaryField()[patchI][patchFaceI];
sum -= bField[patchFaceI];
}
else
{
dm += fD.boundaryField()[patchI][patchFaceI];
sum += bField[patchFaceI];
}
}
}
}
return dm;
return sum;
}
......
......@@ -57,7 +57,7 @@ class dictionary;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class faceZonesIntegration Declaration
Class faceZonesIntegration Declaration
\*---------------------------------------------------------------------------*/
class faceZonesIntegration
......@@ -65,17 +65,18 @@ class faceZonesIntegration
protected:
// Private data
// Protected data
//- Name of this set of face zone integration,
// Also used as the name of the probes directory.
// Also used as the name of the output directory.
word name_;
const objectRegistry& obr_;
// Read from dictionary
//- on/off switch
//- On/off switch
bool active_;
//- Switch to send output to Info as well as to file
......@@ -89,19 +90,19 @@ protected:
//- Current open files
HashPtrTable<OFstream> faceZonesIntegrationFilePtr_;
HashPtrTable<OFstream> filePtr_;
// Private Member Functions
// Protected Member Functions
//- If the integration file has not been created create it
void makeFile();
scalar calcFaceZonesIntegral
scalar calcIntegral
(
const surfaceScalarField& fD,
const faceZone& fz
const surfaceScalarField& sField,
const faceZone& fZone
) const;
......@@ -134,9 +135,8 @@ public:
);
// Destructor
virtual ~faceZonesIntegration();
//- Destructor
virtual ~faceZonesIntegration();
// Member Functions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment