mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Simplified CourantNo function object such that field is stored on the mesh database
This commit is contained in:
@ -68,74 +68,6 @@ Foam::tmp<Foam::volScalarField> Foam::CourantNo::rho
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::CourantNo::makeFile()
|
|
||||||
{
|
|
||||||
// Create the CourantNo file if not already created
|
|
||||||
if (CourantNoFilePtr_.empty())
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
{
|
|
||||||
Info<< "Creating CourantNo file." << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// File update
|
|
||||||
if (Pstream::master())
|
|
||||||
{
|
|
||||||
fileName CourantNoDir;
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
// Put in undecomposed case (Note: gives problems for
|
|
||||||
// distributed data running)
|
|
||||||
CourantNoDir =
|
|
||||||
obr_.time().path()/".."/name_/obr_.time().timeName();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CourantNoDir =
|
|
||||||
obr_.time().path()/name_/obr_.time().timeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create directory if does not exist.
|
|
||||||
mkDir(CourantNoDir);
|
|
||||||
|
|
||||||
// Open new file at start up
|
|
||||||
CourantNoFilePtr_.reset
|
|
||||||
(
|
|
||||||
new OFstream(CourantNoDir/(type() + ".dat"))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add headers to output data
|
|
||||||
writeFileHeader();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::CourantNo::writeFileHeader()
|
|
||||||
{
|
|
||||||
if (CourantNoFilePtr_.valid())
|
|
||||||
{
|
|
||||||
CourantNoFilePtr_()
|
|
||||||
<< "# Time" << token::TAB << "min" << token::TAB << "position(min)";
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
CourantNoFilePtr_() << token::TAB << "proc";
|
|
||||||
}
|
|
||||||
|
|
||||||
CourantNoFilePtr_()
|
|
||||||
<< token::TAB << "max" << token::TAB << "position(max)";
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
CourantNoFilePtr_() << token::TAB << "proc";
|
|
||||||
}
|
|
||||||
|
|
||||||
CourantNoFilePtr_() << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::CourantNo::CourantNo
|
Foam::CourantNo::CourantNo
|
||||||
@ -149,10 +81,8 @@ Foam::CourantNo::CourantNo
|
|||||||
name_(name),
|
name_(name),
|
||||||
obr_(obr),
|
obr_(obr),
|
||||||
active_(true),
|
active_(true),
|
||||||
log_(false),
|
|
||||||
phiName_("phi"),
|
phiName_("phi"),
|
||||||
rhoName_("rho"),
|
rhoName_("rho")
|
||||||
CourantNoFilePtr_(NULL)
|
|
||||||
{
|
{
|
||||||
// Check if the available mesh is an fvMesh, otherwise deactivate
|
// Check if the available mesh is an fvMesh, otherwise deactivate
|
||||||
if (!isA<fvMesh>(obr_))
|
if (!isA<fvMesh>(obr_))
|
||||||
@ -172,6 +102,30 @@ Foam::CourantNo::CourantNo
|
|||||||
}
|
}
|
||||||
|
|
||||||
read(dict);
|
read(dict);
|
||||||
|
|
||||||
|
if (active_)
|
||||||
|
{
|
||||||
|
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||||
|
|
||||||
|
volScalarField* CourantNoPtr
|
||||||
|
(
|
||||||
|
new volScalarField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
type(),
|
||||||
|
mesh.time().timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::NO_READ
|
||||||
|
),
|
||||||
|
mesh,
|
||||||
|
dimensionedScalar("0", dimless, 0.0),
|
||||||
|
zeroGradientFvPatchScalarField::typeName
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
mesh.objectRegistry::store(CourantNoPtr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -189,7 +143,6 @@ void Foam::CourantNo::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
|
phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
|
||||||
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho");
|
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho");
|
||||||
log_ = dict.lookupOrDefault<Switch>("log", false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,25 +163,15 @@ void Foam::CourantNo::write()
|
|||||||
{
|
{
|
||||||
if (active_)
|
if (active_)
|
||||||
{
|
{
|
||||||
makeFile();
|
|
||||||
|
|
||||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||||
|
|
||||||
const surfaceScalarField& phi =
|
const surfaceScalarField& phi =
|
||||||
mesh.lookupObject<surfaceScalarField>(phiName_);
|
mesh.lookupObject<surfaceScalarField>(phiName_);
|
||||||
|
|
||||||
volScalarField CourantNo
|
volScalarField& CourantNo =
|
||||||
|
const_cast<volScalarField&>
|
||||||
(
|
(
|
||||||
IOobject
|
mesh.lookupObject<volScalarField>(type())
|
||||||
(
|
|
||||||
"CourantNo",
|
|
||||||
mesh.time().timeName(),
|
|
||||||
mesh,
|
|
||||||
IOobject::NO_READ
|
|
||||||
),
|
|
||||||
mesh,
|
|
||||||
dimensionedScalar("0", dimless, 0.0),
|
|
||||||
zeroGradientFvPatchScalarField::typeName
|
|
||||||
);
|
);
|
||||||
|
|
||||||
scalarField& iField = CourantNo.internalField();
|
scalarField& iField = CourantNo.internalField();
|
||||||
@ -243,83 +186,10 @@ void Foam::CourantNo::write()
|
|||||||
|
|
||||||
CourantNo.correctBoundaryConditions();
|
CourantNo.correctBoundaryConditions();
|
||||||
|
|
||||||
const label procI = Pstream::myProcNo();
|
|
||||||
|
|
||||||
labelList minIs(Pstream::nProcs());
|
|
||||||
scalarList minVs(Pstream::nProcs());
|
|
||||||
List<vector> minCs(Pstream::nProcs());
|
|
||||||
minIs[procI] = findMin(iField);
|
|
||||||
minVs[procI] = iField[minIs[procI]];
|
|
||||||
minCs[procI] = mesh.C()[minIs[procI]];
|
|
||||||
|
|
||||||
Pstream::gatherList(minIs);
|
|
||||||
Pstream::gatherList(minVs);
|
|
||||||
Pstream::gatherList(minCs);
|
|
||||||
|
|
||||||
labelList maxIs(Pstream::nProcs());
|
|
||||||
scalarList maxVs(Pstream::nProcs());
|
|
||||||
List<vector> maxCs(Pstream::nProcs());
|
|
||||||
maxIs[procI] = findMax(iField);
|
|
||||||
maxVs[procI] = iField[maxIs[procI]];
|
|
||||||
maxCs[procI] = mesh.C()[maxIs[procI]];
|
|
||||||
|
|
||||||
Pstream::gatherList(maxIs);
|
|
||||||
Pstream::gatherList(maxVs);
|
|
||||||
Pstream::gatherList(maxCs);
|
|
||||||
|
|
||||||
if (Pstream::master())
|
|
||||||
{
|
|
||||||
label minI = findMin(minVs);
|
|
||||||
scalar minValue = minVs[minI];
|
|
||||||
const vector& minC = minCs[minI];
|
|
||||||
|
|
||||||
label maxI = findMax(maxVs);
|
|
||||||
scalar maxValue = maxVs[maxI];
|
|
||||||
const vector& maxC = maxCs[maxI];
|
|
||||||
|
|
||||||
CourantNoFilePtr_()
|
|
||||||
<< obr_.time().value() << token::TAB
|
|
||||||
<< minValue << token::TAB << minC;
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
CourantNoFilePtr_() << token::TAB << minI;
|
|
||||||
}
|
|
||||||
|
|
||||||
CourantNoFilePtr_()
|
|
||||||
<< token::TAB << maxValue << token::TAB << maxC;
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
CourantNoFilePtr_() << token::TAB << maxI;
|
|
||||||
}
|
|
||||||
|
|
||||||
CourantNoFilePtr_() << endl;
|
|
||||||
|
|
||||||
if (log_)
|
|
||||||
{
|
|
||||||
Info<< type() << " output:" << nl
|
|
||||||
<< " min = " << minValue << " at position " << minC;
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
Info<< " on processor " << minI;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< nl << " max = " << maxValue << " at position "
|
|
||||||
<< maxC;
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
Info<< " on processor " << maxI;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< nl << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CourantNo.write();
|
CourantNo.write();
|
||||||
|
|
||||||
|
Info<< type() << " output:" << nl
|
||||||
|
<< " writing " << CourantNo.name() << "field" << nl << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,9 @@ Class
|
|||||||
Foam::CourantNo
|
Foam::CourantNo
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Calculates and outputs the Courant number
|
This function object calculates and outputs the Courant number as a
|
||||||
|
volScalarField. The field is stored on the mesh database so that it can
|
||||||
|
be retrieved and used for other applications.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
CourantNo.C
|
CourantNo.C
|
||||||
@ -63,23 +65,18 @@ class CourantNo
|
|||||||
//- Name of this set of CourantNo objects
|
//- Name of this set of CourantNo objects
|
||||||
word name_;
|
word name_;
|
||||||
|
|
||||||
|
//- Reference to the database
|
||||||
const objectRegistry& obr_;
|
const objectRegistry& obr_;
|
||||||
|
|
||||||
//- on/off switch
|
//- On/off switch
|
||||||
bool active_;
|
bool active_;
|
||||||
|
|
||||||
//- Switch to send output to Info as well
|
|
||||||
Switch log_;
|
|
||||||
|
|
||||||
//- Name of flux field, default is "phi"
|
//- Name of flux field, default is "phi"
|
||||||
word phiName_;
|
word phiName_;
|
||||||
|
|
||||||
//- Name of density field (optional)
|
//- Name of density field (optional)
|
||||||
word rhoName_;
|
word rhoName_;
|
||||||
|
|
||||||
//- Courant number file ptr
|
|
||||||
autoPtr<OFstream> CourantNoFilePtr_;
|
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
@ -87,12 +84,6 @@ class CourantNo
|
|||||||
// from the database
|
// from the database
|
||||||
tmp<volScalarField> rho(const surfaceScalarField& p) const;
|
tmp<volScalarField> rho(const surfaceScalarField& p) const;
|
||||||
|
|
||||||
//- If the output file has not been created create it
|
|
||||||
void makeFile();
|
|
||||||
|
|
||||||
//- Output file header information
|
|
||||||
virtual void writeFileHeader();
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
CourantNo(const CourantNo&);
|
CourantNo(const CourantNo&);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user