diff --git a/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.C b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.C new file mode 100644 index 0000000000..b7b2b10415 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.C @@ -0,0 +1,327 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "CourantNo.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "dictionary.H" +#include "zeroGradientFvPatchFields.H" +#include "fvcSurfaceIntegrate.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::CourantNo, 0); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::tmp Foam::CourantNo::rho +( + const surfaceScalarField& phi +) const +{ + if (phi.dimensions() == dimMass/dimTime) + { + return (obr_.lookupObject(rhoName_)); + } + else + { + const fvMesh& mesh = refCast(obr_); + + return tmp + ( + new volScalarField + ( + IOobject + ( + "rho", + mesh.time().timeName(), + mesh + ), + mesh, + dimensionedScalar("rho", dimless, 1.0) + ) + ); + } +} + + +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 * * * * * * * * * * * * * * // + +Foam::CourantNo::CourantNo +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + log_(false), + phiName_("phi"), + rhoName_("rho"), + CourantNoFilePtr_(NULL) +{ + // Check if the available mesh is an fvMesh, otherwise deactivate + if (!isA(obr_)) + { + active_ = false; + WarningIn + ( + "CourantNo::CourantNo" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "No fvMesh available, deactivating." << nl + << endl; + } + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::CourantNo::~CourantNo() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::CourantNo::read(const dictionary& dict) +{ + if (active_) + { + phiName_ = dict.lookupOrDefault("phiName", "phi"); + rhoName_ = dict.lookupOrDefault("rhoName", "rho"); + log_ = dict.lookupOrDefault("log", false); + } +} + + +void Foam::CourantNo::execute() +{ + // Do nothing - only valid on write +} + + +void Foam::CourantNo::end() +{ + // Do nothing - only valid on write +} + + +void Foam::CourantNo::write() +{ + if (active_) + { + makeFile(); + + const fvMesh& mesh = refCast(obr_); + + const surfaceScalarField& phi = + mesh.lookupObject(phiName_); + + volScalarField CourantNo + ( + IOobject + ( + "CourantNo", + mesh.time().timeName(), + mesh, + IOobject::NO_READ + ), + mesh, + dimensionedScalar("0", dimless, 0.0), + zeroGradientFvPatchScalarField::typeName + ); + + scalarField& iField = CourantNo.internalField(); + + const scalarField sumPhi + ( + fvc::surfaceSum(mag(phi))().internalField() + /rho(phi)().internalField() + ); + + iField = 0.5*sumPhi/mesh.V().field()*mesh.time().deltaTValue(); + + CourantNo.correctBoundaryConditions(); + + const label procI = Pstream::myProcNo(); + + labelList minIs(Pstream::nProcs()); + scalarList minVs(Pstream::nProcs()); + List 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 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(); + } +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.H b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.H new file mode 100644 index 0000000000..cb80bd5ebf --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.H @@ -0,0 +1,164 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::CourantNo + +Description + Calculates and outputs the Courant number + +SourceFiles + CourantNo.C + IOCourantNo.H + +\*---------------------------------------------------------------------------*/ + +#ifndef CourantNo_H +#define CourantNo_H + +#include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" +#include "pointFieldFwd.H" +#include "OFstream.H" +#include "Switch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; + +/*---------------------------------------------------------------------------*\ + Class CourantNo Declaration +\*---------------------------------------------------------------------------*/ + +class CourantNo +{ + // Private data + + //- Name of this set of CourantNo objects + word name_; + + const objectRegistry& obr_; + + //- on/off switch + bool active_; + + //- Switch to send output to Info as well + Switch log_; + + //- Name of flux field, default is "phi" + word phiName_; + + //- Name of density field (optional) + word rhoName_; + + //- Courant number file ptr + autoPtr CourantNoFilePtr_; + + + // Private Member Functions + + //- Return 1 if the flux field is volumetric, otherwise return rho + // from the database + tmp 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 + CourantNo(const CourantNo&); + + //- Disallow default bitwise assignment + void operator=(const CourantNo&); + + +public: + + //- Runtime type information + TypeName("CourantNo"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + CourantNo + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~CourantNo(); + + + // Member Functions + + //- Return name of the set of CourantNo + virtual const word& name() const + { + return name_; + } + + //- Read the CourantNo data + virtual void read(const dictionary&); + + //- Execute, currently does nothing + virtual void execute(); + + //- Execute at the final time-loop, currently does nothing + virtual void end(); + + //- Calculate the CourantNo and write + virtual void write(); + + //- Update for changes of mesh + virtual void updateMesh(const mapPolyMesh&) + {} + + //- Update for changes of mesh + virtual void movePoints(const pointField&) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.C b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.C new file mode 100644 index 0000000000..af57c73e67 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.C @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "CourantNoFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug(CourantNoFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + CourantNoFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.H b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.H new file mode 100644 index 0000000000..1586e771ab --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.H @@ -0,0 +1,53 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::CourantNoFunctionObject + +Description + FunctionObject wrapper around CourantNo to allow it to be created + via the functions entry within controlDict. + +SourceFiles + CourantNoFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef CourantNoFunctionObject_H +#define CourantNoFunctionObject_H + +#include "CourantNo.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject CourantNoFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/CourantNo/IOCourantNo.H b/src/postProcessing/functionObjects/utilities/CourantNo/IOCourantNo.H new file mode 100644 index 0000000000..5be7eb4eb9 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/CourantNo/IOCourantNo.H @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::IOCourantNo + +Description + Instance of the generic IOOutputFilter for CourantNo. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOCourantNo_H +#define IOCourantNo_H + +#include "CourantNo.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOCourantNo; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/Make/files b/src/postProcessing/functionObjects/utilities/Make/files index e6fcedbb0d..998d91955e 100644 --- a/src/postProcessing/functionObjects/utilities/Make/files +++ b/src/postProcessing/functionObjects/utilities/Make/files @@ -1,5 +1,8 @@ codedFunctionObject/codedFunctionObject.C +CourantNo/CourantNo.C +CourantNo/CourantNoFunctionObject.C + dsmcFields/dsmcFields.C dsmcFields/dsmcFieldsFunctionObject.C