write gradP to time/uniform for restarts

This commit is contained in:
andy
2008-11-10 11:55:16 +00:00
parent be3d701bb6
commit a367abb756
2 changed files with 64 additions and 16 deletions

View File

@ -26,29 +26,55 @@ License
#include "pressureGradientExplicitSource.H" #include "pressureGradientExplicitSource.H"
#include "volFields.H" #include "volFields.H"
#include "IFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::pressureGradientExplicitSource::writeGradP() const
{
// Only write on output time
if (mesh_.time().outputTime())
{
IOdictionary propsDict
(
IOobject
(
sourceName_ + "Properties",
mesh_.time().timeName(),
"uniform",
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
)
);
propsDict.add("gradient", gradP_);
propsDict.regIOobject::write();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pressureGradientExplicitSource::pressureGradientExplicitSource Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
( (
const word& sourceName, const word& sourceName,
const fvMesh& mesh,
volVectorField& U volVectorField& U
) )
: :
sourceName_(sourceName),
mesh_(U.mesh()),
U_(U),
dict_ dict_
( (
IOobject IOobject
( (
sourceName + "Properties", sourceName + "Properties",
mesh.time().constant(), mesh_.time().constant(),
mesh, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
) )
), ),
mesh_(mesh),
U_(U),
Ubar_(dict_.lookup("Ubar")), Ubar_(dict_.lookup("Ubar")),
gradPini_(readScalar(dict_.lookup("gradPini"))), gradPini_(readScalar(dict_.lookup("gradPini"))),
gradP_(gradPini_), gradP_(gradPini_),
@ -59,15 +85,15 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
topoSetSource::New topoSetSource::New
( (
cellSource_, cellSource_,
mesh, mesh_,
dict_.subDict(cellSource_ + "Coeffs") dict_.subDict(cellSource_ + "Coeffs")
) )
), ),
selectedCellSet_ selectedCellSet_
( (
mesh, mesh_,
"pressureGradientExplicitSourceCellSet", sourceName_ + "CellSet",
mesh.nCells()/10 + 1 // Reasonable size estimate. mesh_.nCells()/10 + 1 // Reasonable size estimate.
) )
{ {
// Create the cell set // Create the cell set
@ -78,9 +104,24 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
); );
// Give some feedback // Give some feedback
Info<< "pressureGradientExplicitSource(" << sourceName << ")" << nl Info<< " Selected "
<< "Selected " << returnReduce(selectedCellSet_.size(), sumOp<label>()) << returnReduce(selectedCellSet_.size(), sumOp<label>())
<< " cells." << endl; << " cells" << endl;
// Read the initial pressure gradient from file if it exists
IFstream propsFile
(
mesh_.time().timeName()/"uniform"/(sourceName_ + "Properties")
);
if (propsFile.good())
{
Info<< " Reading pressure gradient from file" << endl;
dictionary propsDict(dictionary::null, propsFile);
propsDict.lookup("gradient") >> gradP_;
}
Info<< " Initial pressure gradient = " << gradP_ << endl;
} }
@ -95,7 +136,7 @@ Foam::pressureGradientExplicitSource::Su() const
( (
IOobject IOobject
( (
"pressureGradientExplicitSource", sourceName_,
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
@ -164,6 +205,8 @@ void Foam::pressureGradientExplicitSource::update()
Info<< "Uncorrected Ubar = " << magUbarAve << tab Info<< "Uncorrected Ubar = " << magUbarAve << tab
<< "Pressure gradient = " << gradP_ << endl; << "Pressure gradient = " << gradP_ << endl;
writeGradP();
} }

View File

@ -57,8 +57,8 @@ class pressureGradientExplicitSource
{ {
// Private data // Private data
//- Properties dictionary //- Name of the source
IOdictionary dict_; const word sourceName_;
//- Reference to the mesh //- Reference to the mesh
const fvMesh& mesh_; const fvMesh& mesh_;
@ -66,6 +66,9 @@ class pressureGradientExplicitSource
//- Reference to the velocity field //- Reference to the velocity field
volVectorField& U_; volVectorField& U_;
//- Properties dictionary
IOdictionary dict_;
//- Average velocity //- Average velocity
vector Ubar_; vector Ubar_;
@ -90,6 +93,9 @@ class pressureGradientExplicitSource
// Private Member Functions // Private Member Functions
//- Write the pressure gradient to file (for restarts etc)
void writeGradP() const;
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
pressureGradientExplicitSource(const pressureGradientExplicitSource&); pressureGradientExplicitSource(const pressureGradientExplicitSource&);
@ -105,7 +111,6 @@ public:
pressureGradientExplicitSource pressureGradientExplicitSource
( (
const word& sourceName, const word& sourceName,
const fvMesh& mesh,
volVectorField& U volVectorField& U
); );