Skip to content
Snippets Groups Projects
Commit c537e4e8 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Updated output to use the writer class

parent b7d09394
Branches
Tags
No related merge requests found
...@@ -47,28 +47,6 @@ namespace functionObjects ...@@ -47,28 +47,6 @@ namespace functionObjects
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::particleDistribution::writeFileHeader
(
Ostream& os
) const
{
writeHeader(os, "Particle distribution");
writeHeaderValue(os, "Cloud", cloudName_);
forAll(nameVsBinWidth_, i)
{
writeHeaderValue
(
os,
"Field:" + nameVsBinWidth_[i].first(),
nameVsBinWidth_[i].second()
);
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::particleDistribution::particleDistribution Foam::functionObjects::particleDistribution::particleDistribution
...@@ -79,14 +57,14 @@ Foam::functionObjects::particleDistribution::particleDistribution ...@@ -79,14 +57,14 @@ Foam::functionObjects::particleDistribution::particleDistribution
) )
: :
fvMeshFunctionObject(name, runTime, dict), fvMeshFunctionObject(name, runTime, dict),
writeFile(runTime, name, typeName, dict), writeFile(runTime, name),
cloudName_("unknown-cloudName"), cloudName_("unknown-cloudName"),
nameVsBinWidth_(), nameVsBinWidth_(),
tagFieldName_("none"), tagFieldName_("none"),
rndGen_(1234, -1) rndGen_(1234, -1),
writerPtr_(nullptr)
{ {
read(dict); read(dict);
writeFileHeader(file());
} }
...@@ -105,6 +83,8 @@ bool Foam::functionObjects::particleDistribution::read(const dictionary& dict) ...@@ -105,6 +83,8 @@ bool Foam::functionObjects::particleDistribution::read(const dictionary& dict)
dict.lookup("cloud") >> cloudName_; dict.lookup("cloud") >> cloudName_;
dict.lookup("nameVsBinWidth") >> nameVsBinWidth_; dict.lookup("nameVsBinWidth") >> nameVsBinWidth_;
dict.readIfPresent("tagField", tagFieldName_); dict.readIfPresent("tagField", tagFieldName_);
word format(dict.lookup("setFormat"));
writerPtr_ = writer<scalar>::New(format);
Info<< type() << " " << name() << " output:" << nl Info<< type() << " " << name() << " output:" << nl
<< " Processing cloud : " << cloudName_ << nl << " Processing cloud : " << cloudName_ << nl
...@@ -177,7 +157,6 @@ bool Foam::functionObjects::particleDistribution::write() ...@@ -177,7 +157,6 @@ bool Foam::functionObjects::particleDistribution::write()
} }
} }
file() << "# Time: " << mesh_.time().timeName() << nl;
bool ok = false; bool ok = false;
forAll(nameVsBinWidth_, i) forAll(nameVsBinWidth_, i)
...@@ -198,11 +177,6 @@ bool Foam::functionObjects::particleDistribution::write() ...@@ -198,11 +177,6 @@ bool Foam::functionObjects::particleDistribution::write()
} }
} }
if (ok)
{
file() << nl;
}
return true; return true;
} }
...@@ -220,11 +194,10 @@ void Foam::functionObjects::particleDistribution::generateDistribution ...@@ -220,11 +194,10 @@ void Foam::functionObjects::particleDistribution::generateDistribution
return; return;
} }
Ostream& os = file(); word fName(fieldName);
if (tag != -1) if (tag != -1)
{ {
os << tag << token::TAB; fName = fName + '_' + Foam::name(tag);
} }
distributionModels::general distribution distributionModels::general distribution
...@@ -234,7 +207,31 @@ void Foam::functionObjects::particleDistribution::generateDistribution ...@@ -234,7 +207,31 @@ void Foam::functionObjects::particleDistribution::generateDistribution
rndGen_ rndGen_
); );
os << fieldName << distribution.writeDict(mesh_.time().timeName()); const Field<scalar> distX(distribution.x());
const Field<scalar> distY(distribution.y());
pointField xBin(distX.size(), Zero);
xBin.replace(0, distX);
const coordSet coords
(
fName,
"x",
xBin,
distX
);
const wordList fieldNames(1, fName);
fileName outputPath(baseTimeDir());
mkDir(outputPath);
OFstream graphFile(outputPath/writerPtr_->getFileName(coords, fieldNames));
Log << " Writing distribution of " << fieldName
<< " to " << graphFile.name() << endl;
List<const scalarField*> yPtrs(1);
yPtrs[0] = &distY;
writerPtr_->write(coords, fieldNames, yPtrs, graphFile);
} }
......
...@@ -28,7 +28,7 @@ Group ...@@ -28,7 +28,7 @@ Group
grpFieldFunctionObjects grpFieldFunctionObjects
Description Description
Generates a particle distrbution for lagrangian data at a given time. Generates a particle distribution for lagrangian data at a given time.
Usage Usage
\verbatim \verbatim
...@@ -43,6 +43,7 @@ Usage ...@@ -43,6 +43,7 @@ Usage
(d 0.1) (d 0.1)
(U 10) (U 10)
); );
setFormat raw;
} }
\endverbatim \endverbatim
...@@ -53,6 +54,7 @@ Usage ...@@ -53,6 +54,7 @@ Usage
cloud | Name of cloud to process | Yes | cloud | Name of cloud to process | Yes |
nameVsBinWidth | List of cloud field vs bin width | Yes | nameVsBinWidth | List of cloud field vs bin width | Yes |
tagField | Name of cloud field to use to group particles | no | none tagField | Name of cloud field to use to group particles | no | none
setFormat | Output format | yes |
\endtable \endtable
See also See also
...@@ -73,6 +75,7 @@ SourceFiles ...@@ -73,6 +75,7 @@ SourceFiles
#include "scalarField.H" #include "scalarField.H"
#include "cachedRandom.H" #include "cachedRandom.H"
#include "Tuple2.H" #include "Tuple2.H"
#include "writer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -106,6 +109,9 @@ protected: ...@@ -106,6 +109,9 @@ protected:
//- Random number generator - used by distribution models //- Random number generator - used by distribution models
cachedRandom rndGen_; cachedRandom rndGen_;
//- Writer
autoPtr<writer<scalar>> writerPtr_;
// Protected Member Functions // Protected Member Functions
...@@ -133,9 +139,6 @@ protected: ...@@ -133,9 +139,6 @@ protected:
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const particleDistribution&) = delete; void operator=(const particleDistribution&) = delete;
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public: public:
......
...@@ -247,17 +247,8 @@ Foam::dictionary Foam::distributionModels::general::writeDict ...@@ -247,17 +247,8 @@ Foam::dictionary Foam::distributionModels::general::writeDict
{ {
// dictionary dict = distributionModel::writeDict(dictName); // dictionary dict = distributionModel::writeDict(dictName);
dictionary dict(dictName); dictionary dict(dictName);
List<scalar> data(xy_.size()); dict.add("x", x());
forAll(data, i) dict.add("y", y());
{
data[i] = xy_[i][0];
}
dict.add("x", data);
forAll(data, i)
{
data[i] = xy_[i][1];
}
dict.add("y", data);
return dict; return dict;
} }
...@@ -280,6 +271,34 @@ void Foam::distributionModels::general::readDict(const dictionary& dict) ...@@ -280,6 +271,34 @@ void Foam::distributionModels::general::readDict(const dictionary& dict)
} }
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::distributionModels::general::x() const
{
tmp<Field<scalar>> tx(new Field<scalar>(xy_.size()));
scalarField& xi = tx.ref();
forAll(xy_, i)
{
xi[i] = xy_[i][0];
}
return tx;
}
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::distributionModels::general::y() const
{
tmp<Field<scalar>> ty(new Field<scalar>(xy_.size()));
scalarField& yi = ty.ref();
forAll(xy_, i)
{
yi[i] = xy_[i][1];
}
return ty;
}
Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<<
( (
Ostream& os, Ostream& os,
......
...@@ -38,6 +38,7 @@ SourceFiles ...@@ -38,6 +38,7 @@ SourceFiles
#include "distributionModel.H" #include "distributionModel.H"
#include "Vector.H" #include "Vector.H"
#include "VectorSpace.H" #include "VectorSpace.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -121,6 +122,12 @@ public: ...@@ -121,6 +122,12 @@ public:
// Member Functions // Member Functions
//- Bin boundaries
virtual tmp<Field<scalar>> x() const;
//- Probabilities
virtual tmp<Field<scalar>> y() const;
//- Sample the distributionModel //- Sample the distributionModel
virtual scalar sample() const; virtual scalar sample() const;
......
...@@ -62,7 +62,7 @@ functions ...@@ -62,7 +62,7 @@ functions
(d 1e-5) (d 1e-5)
(U 10) (U 10)
); );
distributionBinWidth 1e-5; setFormat raw;
} }
} }
......
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