Commit 5126a6a4 authored by andy's avatar andy
Browse files

ENH: Function object updates

parent d24bc269
......@@ -335,7 +335,6 @@ void Foam::fieldAverage::write()
{
if (active_)
{
calcAverages();
writeAverages();
writeAveragingProperties();
......
......@@ -96,7 +96,20 @@ void Foam::fieldCoordinateSystemTransform::read(const dictionary& dict)
void Foam::fieldCoordinateSystemTransform::execute()
{
// Do nothing
if (active_)
{
Info<< type() << " " << name_ << " output:" << nl;
forAll(fieldSet_, fieldI)
{
// If necessary load field
transform<scalar>(fieldSet_[fieldI]);
transform<vector>(fieldSet_[fieldI]);
transform<sphericalTensor>(fieldSet_[fieldI]);
transform<symmTensor>(fieldSet_[fieldI]);
transform<tensor>(fieldSet_[fieldI]);
}
}
}
......@@ -114,16 +127,23 @@ void Foam::fieldCoordinateSystemTransform::timeSet()
void Foam::fieldCoordinateSystemTransform::write()
{
Info<< type() << " " << name_ << " output:" << nl;
forAll(fieldSet_, fieldI)
if (active_)
{
// If necessary load field
transform<scalar>(fieldSet_[fieldI]);
transform<vector>(fieldSet_[fieldI]);
transform<sphericalTensor>(fieldSet_[fieldI]);
transform<symmTensor>(fieldSet_[fieldI]);
transform<tensor>(fieldSet_[fieldI]);
Info<< type() << " " << name_ << " output:" << nl;
forAll(fieldSet_, fieldI)
{
const word fieldName = fieldSet_[fieldI] + ":Transformed";
const regIOobject& field =
obr_.lookupObject<regIOobject>(fieldName);
Info<< " writing field " << field.name() << nl;
field.write();
}
Info<< endl;
}
}
......
......@@ -37,7 +37,7 @@ void Foam::fieldCoordinateSystemTransform::transformField
const Type& field
) const
{
const word& fieldName = field.name() + "Transformed";
const word& fieldName = field.name() + ":Transformed";
if (!obr_.foundObject<Type>(fieldName))
{
......
......@@ -328,32 +328,8 @@ void Foam::nearWallFields::execute()
{
Info<< "nearWallFields:execute()" << endl;
}
}
void Foam::nearWallFields::end()
{
if (debug)
{
Info<< "nearWallFields:end()" << endl;
}
}
void Foam::nearWallFields::timeSet()
{
// Do nothing
}
void Foam::nearWallFields::write()
{
if (debug)
{
Info<< "nearWallFields:write()" << endl;
}
// Do nothing
if (active_)
{
if
......@@ -380,7 +356,7 @@ void Foam::nearWallFields::write()
Info<< type() << " " << name_ << " output:" << nl;
Info<< " Writing sampled fields to " << obr_.time().timeName()
Info<< " Sampling fields fields to " << obr_.time().timeName()
<< endl;
sampleFields(vsf_);
......@@ -388,8 +364,37 @@ void Foam::nearWallFields::write()
sampleFields(vSpheretf_);
sampleFields(vSymmtf_);
sampleFields(vtf_);
}
}
void Foam::nearWallFields::end()
{
if (debug)
{
Info<< "nearWallFields:end()" << endl;
}
}
void Foam::nearWallFields::timeSet()
{
// Do nothing
}
void Foam::nearWallFields::write()
{
if (debug)
{
Info<< "nearWallFields:write()" << endl;
}
if (active_)
{
Info<< " Writing sampled fields to " << obr_.time().timeName()
<< endl;
// Write fields
forAll(vsf_, i)
{
vsf_[i].write();
......
......@@ -53,6 +53,27 @@ Foam::processorField::processorField
if (isA<fvMesh>(obr_))
{
read(dict);
const fvMesh& mesh = refCast<const fvMesh>(obr_);
volScalarField* procFieldPtr
(
new volScalarField
(
IOobject
(
"processorID",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("0", dimless, 0.0)
)
);
mesh.objectRegistry::store(procFieldPtr);
}
else
{
......@@ -88,7 +109,14 @@ void Foam::processorField::read(const dictionary& dict)
void Foam::processorField::execute()
{
// Do nothing
if (active_)
{
const volScalarField& procField =
obr_.lookupObject<volScalarField>("processorID");
const_cast<volScalarField&>(procField) ==
dimensionedScalar("procI", dimless, Pstream::myProcNo());
}
}
......@@ -108,20 +136,8 @@ void Foam::processorField::write()
{
if (active_)
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
volScalarField procField
(
IOobject
(
"processorID",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("procI", dimless, Pstream::myProcNo())
);
const volScalarField& procField =
obr_.lookupObject<volScalarField>("processorID");
procField.write();
}
......
......@@ -125,25 +125,42 @@ void Foam::calcFvcDiv::read(const dictionary& dict)
{
dict.lookup("fieldName") >> fieldName_;
dict.lookup("resultName") >> resultName_;
if (resultName_ == "none")
{
resultName_ = "fvc::div(" + fieldName_ + ")";
}
}
}
void Foam::calcFvcDiv::execute()
{
// Do nothing - only valid on write
if (active_)
{
bool processed = false;
calcDiv<surfaceScalarField>(fieldName_, resultName_, processed);
calcDiv<volVectorField>(fieldName_, resultName_, processed);
if (!processed)
{
WarningIn("void Foam::calcFvcDiv::write()")
<< "Unprocessed field " << fieldName_ << endl;
}
}
}
void Foam::calcFvcDiv::end()
{
// Do nothing - only valid on write
// Do nothing
}
void Foam::calcFvcDiv::timeSet()
{
// Do nothing - only valid on write
// Do nothing
}
......@@ -151,15 +168,15 @@ void Foam::calcFvcDiv::write()
{
if (active_)
{
bool processed = false;
if (obr_.foundObject<regIOobject>(resultName_))
{
const regIOobject& field =
obr_.lookupObject<regIOobject>(resultName_);
calcDiv<surfaceScalarField>(fieldName_, resultName_, processed);
calcDiv<volVectorField>(fieldName_, resultName_, processed);
Info<< type() << " " << name_ << " output:" << nl
<< " writing field " << field.name() << nl << endl;
if (!processed)
{
WarningIn("void Foam::calcFvcDiv::write()")
<< "Unprocessed field " << fieldName_ << endl;
field.write();
}
}
}
......
......@@ -38,25 +38,14 @@ void Foam::calcFvcDiv::calcDiv
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
word divName = resultName;
if (divName == "none")
{
divName = "fvc::div(" + fieldName + ")";
}
if (mesh.foundObject<FieldType>(fieldName))
{
const FieldType& vf = mesh.lookupObject<FieldType>(fieldName);
volScalarField& field = divField(divName, vf.dimensions());
volScalarField& field = divField(resultName, vf.dimensions());
field = fvc::div(vf);
Info<< type() << " " << name_ << " output:" << nl
<< " writing field " << field.name() << nl << endl;
field.write();
processed = true;
}
}
......
......@@ -87,25 +87,42 @@ void Foam::calcFvcGrad::read(const dictionary& dict)
{
dict.lookup("fieldName") >> fieldName_;
dict.lookup("resultName") >> resultName_;
if (resultName_ == "none")
{
resultName_ = "fvc::grad(" + fieldName_ + ")";
}
}
}
void Foam::calcFvcGrad::execute()
{
// Do nothing - only valid on write
if (active_)
{
bool processed = false;
calcGrad<scalar>(fieldName_, resultName_, processed);
calcGrad<vector>(fieldName_, resultName_, processed);
if (!processed)
{
WarningIn("void Foam::calcFvcGrad::write()")
<< "Unprocessed field " << fieldName_ << endl;
}
}
}
void Foam::calcFvcGrad::end()
{
// Do nothing - only valid on write
// Do nothing
}
void Foam::calcFvcGrad::timeSet()
{
// Do nothing - only valid on write
// Do nothing
}
......@@ -113,15 +130,15 @@ void Foam::calcFvcGrad::write()
{
if (active_)
{
bool processed = false;
if (obr_.foundObject<regIOobject>(resultName_))
{
const regIOobject& field =
obr_.lookupObject<regIOobject>(resultName_);
calcGrad<scalar>(fieldName_, resultName_, processed);
calcGrad<vector>(fieldName_, resultName_, processed);
Info<< type() << " " << name_ << " output:" << nl
<< " writing field " << field.name() << nl << endl;
if (!processed)
{
WarningIn("void Foam::calcFvcGrad::write()")
<< "Unprocessed field " << fieldName_ << endl;
field.write();
}
}
}
......
......@@ -91,40 +91,25 @@ void Foam::calcFvcGrad::calcGrad
const fvMesh& mesh = refCast<const fvMesh>(obr_);
word gradName = resultName;
if (gradName == "none")
{
gradName = "fvc::grad(" + fieldName + ")";
}
if (mesh.foundObject<vfType>(fieldName))
{
const vfType& vf = mesh.lookupObject<vfType>(fieldName);
vfGradType& field = gradField<Type>(gradName, vf.dimensions());
vfGradType& field = gradField<Type>(resultName, vf.dimensions());
field = fvc::grad(vf);
Info<< type() << " output:" << nl
<< " writing " << field.name() << " field" << nl << endl;
field.write();
processed = true;
}
else if (mesh.foundObject<sfType>(fieldName))
{
const sfType& sf = mesh.lookupObject<sfType>(fieldName);
vfGradType& field = gradField<Type>(gradName, sf.dimensions());
vfGradType& field = gradField<Type>(resultName, sf.dimensions());
field = fvc::grad(sf);
Info<< type() << " " << name_ << " output:" << nl
<< " writing field " << field.name() << nl << endl;
field.write();
processed = true;
}
}
......
......@@ -87,25 +87,45 @@ void Foam::calcMag::read(const dictionary& dict)
{
dict.lookup("fieldName") >> fieldName_;
dict.lookup("resultName") >> resultName_;
if (resultName_ == "none")
{
resultName_ = "mag(" + fieldName_ + ")";
}
}
}
void Foam::calcMag::execute()
{
// Do nothing - only valid on write
if (active_)
{
bool processed = false;
calc<scalar>(fieldName_, resultName_, processed);
calc<vector>(fieldName_, resultName_, processed);
calc<sphericalTensor>(fieldName_, resultName_, processed);
calc<symmTensor>(fieldName_, resultName_, processed);
calc<tensor>(fieldName_, resultName_, processed);
if (!processed)
{
WarningIn("void Foam::calcMag::write()")
<< "Unprocessed field " << fieldName_ << endl;
}
}
}
void Foam::calcMag::end()
{
// Do nothing - only valid on write
// Do nothing
}
void Foam::calcMag::timeSet()
{
// Do nothing - only valid on write
// Do nothing
}
......@@ -113,18 +133,15 @@ void Foam::calcMag::write()
{
if (active_)
{
bool processed = false;
if (obr_.foundObject<regIOobject>(resultName_))
{
const regIOobject& field =
obr_.lookupObject<regIOobject>(resultName_);
calc<scalar>(fieldName_, resultName_, processed);
calc<vector>(fieldName_, resultName_, processed);
calc<sphericalTensor>(fieldName_, resultName_, processed);
calc<symmTensor>(fieldName_, resultName_, processed);
calc<tensor>(fieldName_, resultName_, processed);
Info<< type() << " " << name_ << " output:" << nl
<< " writing field " << field.name() << nl << endl;
if (!processed)
{
WarningIn("void Foam::calcMag::write()")
<< "Unprocessed field " << fieldName_ << endl;
field.write();
}
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -80,26 +80,15 @@ void Foam::calcMag::calc
const fvMesh& mesh = refCast<const fvMesh>(obr_);
word magName = resultName;
if (magName == "none")
{
magName = "mag(" + fieldName + ")";
}
if (mesh.foundObject<vfType>(fieldName))
{
const vfType& vf = mesh.lookupObject<vfType>(fieldName);
volScalarField& field =
magField<volScalarField>(magName, vf.dimensions());
magField<volScalarField>(resultName_, vf.dimensions());
field = mag(vf);
Info<< type() << " output:" << nl
<< " writing " << field.name() << " field" << nl << endl;
field.write();
processed = true;
}
else if (mesh.foundObject<sfType>(fieldName))
......@@ -107,15 +96,10 @@ void Foam::calcMag::calc
const sfType& sf = mesh.lookupObject<sfType>(fieldName);
surfaceScalarField& field =
magField<surfaceScalarField>(magName, sf.dimensions());
magField<surfaceScalarField>(resultName_, sf.dimensions());
field = mag(sf);
Info<< type() << " output:" << nl
<< " writing " << field.name() << " field" << nl << endl;
field.write();
processed = true;
}
}
......
......@@ -154,24 +154,6 @@ void Foam::CourantNo::read(const dictionary& dict)
void Foam::CourantNo::execute()
{
// Do nothing - only valid on write
}
void Foam::CourantNo::end()
{
// Do nothing - only valid on write
}
void Foam::CourantNo::timeSet()
{
// Do nothing - only valid on write
}
void Foam::CourantNo::write()
{
if (active_)
{
......@@ -197,6 +179,28 @@ void Foam::CourantNo::write()
iField = 0.5*sumPhi/mesh.V().field()*mesh.time().deltaTValue();