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 "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 * * * * * * * * * * * * * * //
Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
(
const word& sourceName,
const fvMesh& mesh,
volVectorField& U
)
:
sourceName_(sourceName),
mesh_(U.mesh()),
U_(U),
dict_
(
IOobject
(
sourceName + "Properties",
mesh.time().constant(),
mesh,
mesh_.time().constant(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
mesh_(mesh),
U_(U),
Ubar_(dict_.lookup("Ubar")),
gradPini_(readScalar(dict_.lookup("gradPini"))),
gradP_(gradPini_),
@ -59,15 +85,15 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
topoSetSource::New
(
cellSource_,
mesh,
mesh_,
dict_.subDict(cellSource_ + "Coeffs")
)
),
selectedCellSet_
(
mesh,
"pressureGradientExplicitSourceCellSet",
mesh.nCells()/10 + 1 // Reasonable size estimate.
mesh_,
sourceName_ + "CellSet",
mesh_.nCells()/10 + 1 // Reasonable size estimate.
)
{
// Create the cell set
@ -78,9 +104,24 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
);
// Give some feedback
Info<< "pressureGradientExplicitSource(" << sourceName << ")" << nl
<< "Selected " << returnReduce(selectedCellSet_.size(), sumOp<label>())
<< " cells." << endl;
Info<< " Selected "
<< returnReduce(selectedCellSet_.size(), sumOp<label>())
<< " 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
(
"pressureGradientExplicitSource",
sourceName_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
@ -164,6 +205,8 @@ void Foam::pressureGradientExplicitSource::update()
Info<< "Uncorrected Ubar = " << magUbarAve << tab
<< "Pressure gradient = " << gradP_ << endl;
writeGradP();
}

View File

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