diff --git a/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/files b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..dfa118ab003350d41ce64ecd738596b3506d3dcc --- /dev/null +++ b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/files @@ -0,0 +1,3 @@ +temporalInterpolate.C + +EXE = $(FOAM_APPBIN)/temporalInterpolate diff --git a/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/options b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..89e52b6d520dc088e6516df08f0f521f188a6353 --- /dev/null +++ b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/Make/options @@ -0,0 +1,6 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude + +EXE_LIBS = \ + -lfiniteVolume + diff --git a/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C new file mode 100644 index 0000000000000000000000000000000000000000..f7526c0628d59dc2d699d46611a8bc54947b8e67 --- /dev/null +++ b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C @@ -0,0 +1,253 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. + \\/ 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 <http://www.gnu.org/licenses/>. + +Description + Interpolate fields between time-steps e.g. for animation. + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "timeSelector.H" + +#include "fvMesh.H" +#include "Time.H" +#include "volMesh.H" +#include "surfaceMesh.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "pointFields.H" +#include "ReadFields.H" + +using namespace Foam; + +class fieldInterpolator +{ + Time& runTime_; + const fvMesh& mesh_; + const IOobjectList& objects_; + const HashSet<word>& selectedFields_; + instant ti_; + instant ti1_; + int divisions_; + +public: + + fieldInterpolator + ( + Time& runTime, + const fvMesh& mesh, + const IOobjectList& objects, + const HashSet<word>& selectedFields, + const instant& ti, + const instant& ti1, + int divisions + ) + : + runTime_(runTime), + mesh_(mesh), + objects_(objects), + selectedFields_(selectedFields), + ti_(ti), + ti1_(ti1), + divisions_(divisions) + {} + + template<class GeoFieldType> + void interpolate(); +}; + + +template<class GeoFieldType> +void fieldInterpolator::interpolate() +{ + const word& fieldClassName = GeoFieldType::typeName; + + IOobjectList fields = objects_.lookupClass(fieldClassName); + + if (fields.size()) + { + Info<< " " << fieldClassName << "s:"; + + forAllConstIter(IOobjectList, fields, fieldIter) + { + if + ( + selectedFields_.empty() + || selectedFields_.found(fieldIter()->name()) + ) + { + Info<< " " << fieldIter()->name() << '('; + + GeoFieldType fieldi + ( + IOobject + ( + fieldIter()->name(), + ti_.name(), + fieldIter()->db(), + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + mesh_ + ); + + GeoFieldType fieldi1 + ( + IOobject + ( + fieldIter()->name(), + ti1_.name(), + fieldIter()->db(), + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + mesh_ + ); + + scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1); + + for (int j=0; j<divisions_; j++) + { + instant timej = instant(ti_.value() + (j + 1)*deltaT); + + runTime_.setTime(timej.name(), 0); + + Info<< timej.name(); + + if (j < divisions_-1) + { + Info<< " "; + } + + scalar lambda = scalar(j + 1)/scalar(divisions_ + 1); + + GeoFieldType fieldj + ( + IOobject + ( + fieldIter()->name(), + timej.name(), + fieldIter()->db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + (1.0 - lambda)*fieldi + lambda*fieldi1 + ); + + fieldj.write(); + } + + Info<< ')'; + } + } + + Info<< endl; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Main program: +int main(int argc, char *argv[]) +{ + timeSelector::addOptions(); + argList::addOption + ( + "fields", + "list", + "specify a list of fields to be interpolated. Eg, '(U T p)' - " + "regular expressions not currently supported" + ); + argList::addOption + ( + "divisions", + "integer", + "specify number of temporal sub-divisions to create (default = 1)." + ); + + #include "setRootCase.H" + #include "createTime.H" + runTime.functionObjects().off(); + + HashSet<word> selectedFields; + if (args.optionFound("fields")) + { + args.optionLookup("fields")() >> selectedFields; + } + + int divisions = 1; + if (args.optionFound("divisions")) + { + args.optionLookup("divisions")() >> divisions; + } + + instantList timeDirs = timeSelector::select0(runTime, args); + + #include "createMesh.H" + + Info<< "Interpolating fields for times:" << endl; + + for (label timei = 0; timei < timeDirs.size() - 1; timei++) + { + runTime.setTime(timeDirs[timei], timei); + + // Read objects in time directory + IOobjectList objects(mesh, runTime.timeName()); + + fieldInterpolator interpolator + ( + runTime, + mesh, + objects, + selectedFields, + timeDirs[timei], + timeDirs[timei+1], + divisions + ); + + // Interpolate vol fields + interpolator.interpolate<volScalarField>(); + interpolator.interpolate<volVectorField>(); + interpolator.interpolate<volSphericalTensorField>(); + interpolator.interpolate<volSymmTensorField>(); + interpolator.interpolate<volTensorField>(); + + // Interpolate surface fields + interpolator.interpolate<surfaceScalarField>(); + interpolator.interpolate<surfaceVectorField>(); + interpolator.interpolate<surfaceSphericalTensorField>(); + interpolator.interpolate<surfaceSymmTensorField>(); + interpolator.interpolate<surfaceTensorField>(); + } + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 52de21702b5abea64dc1e5780b974c74bb5c6440..1f1e25341e29af8378811777a05d651a3e491be5 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -160,6 +160,7 @@ $(dictionaryEntry)/dictionaryEntry.C $(dictionaryEntry)/dictionaryEntryIO.C functionEntries = $(dictionary)/functionEntries +$(functionEntries)/calcEntry/calcEntry.C $(functionEntries)/codeStream/codeStream.C $(functionEntries)/functionEntry/functionEntry.C $(functionEntries)/includeEntry/includeEntry.C diff --git a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C index a35b62474b93a655c98c0964ffecb999fafe0e43..0bd6828ed78509d0a592f8032bee866eb20f8618 100644 --- a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C +++ b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C @@ -2520,7 +2520,7 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest { scalar nearestDistSqr = startDistSqr; label nearestShapeI = -1; - point nearestPoint; + point nearestPoint = vector::zero; if (nodes_.size()) { @@ -2534,10 +2534,6 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest nearestPoint ); } - else - { - nearestPoint = vector::zero; - } return pointIndexHit(nearestShapeI != -1, nearestPoint, nearestShapeI); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C new file mode 100644 index 0000000000000000000000000000000000000000..fceccc4d3549b64e2f4d59b589ae11686a33b4c1 --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "calcEntry.H" +#include "addToMemberFunctionSelectionTable.H" +#include "dictionary.H" +#include "dynamicCode.H" +#include "codeStream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + defineTypeNameAndDebug(calcEntry, 0); + + addToMemberFunctionSelectionTable + ( + functionEntry, + calcEntry, + execute, + primitiveEntryIstream + ); + +} +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionEntries::calcEntry::execute +( + const dictionary& parentDict, + primitiveEntry& thisEntry, + Istream& is +) +{ + Info<< "Using #calcEntry at line " << is.lineNumber() + << " in file " << parentDict.name() << endl; + + dynamicCode::checkSecurity + ( + "functionEntries::calcEntry::execute(..)", + parentDict + ); + + // Read string + string s(is); + // Make sure we stop this entry + //is.putBack(token(token::END_STATEMENT, is.lineNumber())); + + // Construct codeDict for codeStream + // must reference parent for stringOps::expand to work nicely. + dictionary codeSubDict; + codeSubDict.add("code", "os << (" + s + ");"); + dictionary codeDict(parentDict, codeSubDict); + + codeStream::streamingFunctionType function = codeStream::getFunction + ( + parentDict, + codeDict + ); + + // use function to write stream + OStringStream os(is.format()); + (*function)(os, parentDict); + + // get the entry from this stream + IStringStream resultStream(os.str()); + thisEntry.read(parentDict, resultStream); + + return true; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H new file mode 100644 index 0000000000000000000000000000000000000000..235210e798dc14163adf928d0c11323d8d6c3522 --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 <http://www.gnu.org/licenses/>. + +Class + Foam::functionEntries::calcEntry + +Description + Uses dynamic compilation to provide calculating functionality + for entering dictionary entries. + + E.g. + + \verbatim + a 1.0; + b 3; + c #calc "$a/$b"; + \endverbatim + + Note the explicit trailing 0 ('1.0') to force a to be read (and written) + as a floating point number. + +Note + Internally this is just a wrapper around codeStream functionality - the + #calc string gets used to construct a dictionary for codeStream. + +SourceFiles + calcEntry.C + +\*---------------------------------------------------------------------------*/ + +#ifndef calcEntry_H +#define calcEntry_H + +#include "functionEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +class dlLibraryTable; + +namespace functionEntries +{ + +/*---------------------------------------------------------------------------*\ + Class calcEntry Declaration +\*---------------------------------------------------------------------------*/ + +class calcEntry +: + public functionEntry +{ + + // Private Member Functions + + //- Disallow default bitwise copy construct + calcEntry(const calcEntry&); + + //- Disallow default bitwise assignment + void operator=(const calcEntry&); + + +public: + + //- Runtime type information + ClassName("calc"); + + + // Member Functions + + //- Execute the functionEntry in a sub-dict context + static bool execute + ( + const dictionary& parentDict, + primitiveEntry&, + Istream& + ); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionEntries +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 8eefcb86d92675ace7715e9f9ec4c3cafd6bedc6..bab7ac3901bf310109ef158857078a0b9dd53b6d 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -92,28 +92,13 @@ Foam::dlLibraryTable& Foam::functionEntries::codeStream::libs } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::functionEntries::codeStream::execute +Foam::functionEntries::codeStream::streamingFunctionType +Foam::functionEntries::codeStream::getFunction ( const dictionary& parentDict, - primitiveEntry& entry, - Istream& is + const dictionary& codeDict ) { - Info<< "Using #codeStream at line " << is.lineNumber() - << " in file " << parentDict.name() << endl; - - dynamicCode::checkSecurity - ( - "functionEntries::codeStream::execute(..)", - parentDict - ); - - // get code dictionary - // must reference parent for stringOps::expand to work nicely - dictionary codeDict("#codeStream", parentDict, is); - // get code, codeInclude, codeOptions dynamicCodeContext context(codeDict); @@ -260,6 +245,34 @@ bool Foam::functionEntries::codeStream::execute << " in library " << lib << exit(FatalIOError); } + return function; +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionEntries::codeStream::execute +( + const dictionary& parentDict, + primitiveEntry& entry, + Istream& is +) +{ + Info<< "Using #codeStream at line " << is.lineNumber() + << " in file " << parentDict.name() << endl; + + dynamicCode::checkSecurity + ( + "functionEntries::codeStream::execute(..)", + parentDict + ); + + // get code dictionary + // must reference parent for stringOps::expand to work nicely + dictionary codeDict("#codeStream", parentDict, is); + + streamingFunctionType function = getFunction(parentDict, codeDict); + // use function to write stream OStringStream os(is.format()); (*function)(os, parentDict); @@ -268,6 +281,7 @@ bool Foam::functionEntries::codeStream::execute IStringStream resultStream(os.str()); entry.read(parentDict, resultStream); + return true; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index 4da11839f13ec5bc2f9c880b5e8fa4986bc4531e..6c93af869041a1ab2491d93616163bb24a62d2a0 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -103,6 +103,9 @@ class dlLibraryTable; namespace functionEntries { +// Forward declaration of friend classes +class calcEntry; + /*---------------------------------------------------------------------------*\ Class codeStream Declaration \*---------------------------------------------------------------------------*/ @@ -123,6 +126,14 @@ class codeStream //- Helper function: access to dlLibraryTable of Time static dlLibraryTable& libs(const dictionary& dict); + //- Construct, compile, load and return streaming function + static streamingFunctionType getFunction + ( + const dictionary& parentDict, + const dictionary& codeDict + ); + + //- Disallow default bitwise copy construct codeStream(const codeStream&); @@ -137,6 +148,11 @@ public: //- Name of the C code template to be used static const word codeTemplateC; + // Related types + + //- Declare friendship with the calcEntry class + friend class calcEntry; + //- Runtime type information ClassName("codeStream"); diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index ebbc47ca3b1cf1e94a6d3ef858e370286cb464d4..bd0ae2c3341e464667f25808760eeb044314c88a 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -328,6 +328,10 @@ Foam::string& Foam::stringOps::inplaceExpand if (ePtr) { OStringStream buf; + // Force floating point numbers to be printed with at least + // some decimal digits. + buf << fixed; + buf.precision(IOstream::defaultPrecision()); if (ePtr->isDict()) { ePtr->dict().write(buf, false); diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 783518dfe5b2270c070740679422a93f3c8c4779..360ecc6b0725713a59f2992301b63e074f183fec 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -122,6 +122,7 @@ $(derivedFvPatchFields)/directMappedFixedValue/directMappedFixedValueFvPatchFiel $(derivedFvPatchFields)/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C $(derivedFvPatchFields)/directMappedFlowRate/directMappedFlowRateFvPatchVectorField.C $(derivedFvPatchFields)/fan/fanFvPatchFields.C +$(derivedFvPatchFields)/fanPressure/fanPressureFvPatchScalarField.C $(derivedFvPatchFields)/buoyantPressure/buoyantPressureFvPatchScalarField.C $(derivedFvPatchFields)/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C $(derivedFvPatchFields)/fixedInternalValueFvPatchField/fixedInternalValueFvPatchFields.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C new file mode 100644 index 0000000000000000000000000000000000000000..db585345f17f85c048ae0468cd21073a11ee0a33 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C @@ -0,0 +1,237 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "fanPressureFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + template<> + const char* Foam::NamedEnum + < + Foam::fanPressureFvPatchScalarField::fanFlowDirection, + 2 + >::names[] = + { + "in", + "out" + }; +} + +const Foam::NamedEnum +< + Foam::fanPressureFvPatchScalarField::fanFlowDirection, + 2 +> Foam::fanPressureFvPatchScalarField::fanFlowDirectionNames_; + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF +) +: + fixedValueFvPatchScalarField(p, iF), + phiName_("phi"), + rhoName_("rho"), + p0_(p.size(), 0.0), + fanCurve_(), + direction_(ffdOut) +{} + + +Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField +( + const fanPressureFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchScalarField(ptf, p, iF, mapper), + phiName_(ptf.phiName_), + rhoName_(ptf.rhoName_), + p0_(ptf.p0_, mapper), + fanCurve_(ptf.fanCurve_), + direction_(ptf.direction_) +{} + + +Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF), + phiName_(dict.lookupOrDefault<word>("phi", "phi")), + rhoName_(dict.lookupOrDefault<word>("rho", "rho")), + p0_("p0", dict, p.size()), + fanCurve_(dict), + direction_(fanFlowDirectionNames_.read(dict.lookup("direction"))) +{ + // Assign initial pressure by "value" + fvPatchField<scalar>::operator==(scalarField("value", dict, p.size())); +} + + +Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField +( + const fanPressureFvPatchScalarField& pfopsf +) +: + fixedValueFvPatchScalarField(pfopsf), + phiName_(pfopsf.phiName_), + rhoName_(pfopsf.rhoName_), + p0_(pfopsf.p0_), + fanCurve_(pfopsf.fanCurve_), + direction_(pfopsf.direction_) +{} + + +Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField +( + const fanPressureFvPatchScalarField& pfopsf, + const DimensionedField<scalar, volMesh>& iF +) +: + fixedValueFvPatchScalarField(pfopsf, iF), + phiName_(pfopsf.phiName_), + rhoName_(pfopsf.rhoName_), + p0_(pfopsf.p0_), + fanCurve_(pfopsf.fanCurve_), + direction_(pfopsf.direction_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fanPressureFvPatchScalarField::updateCoeffs() +{ + if (updated()) + { + return; + } + + // Retrieve flux field + const surfaceScalarField& phi = + db().lookupObject<surfaceScalarField>(phiName_); + + const fvsPatchField<scalar>& phip = + patch().patchField<surfaceScalarField, scalar>(phi); + + int dir = 2*direction_ - 1; + + // Average volumetric flow rate + scalar aveFlowRate = 0; + + if (phi.dimensions() == dimVelocity*dimArea) + { + aveFlowRate = dir*gSum(phip)/gSum(patch().magSf()); + } + else if (phi.dimensions() == dimVelocity*dimArea*dimDensity) + { + const scalarField& rhop = + patch().lookupPatchField<volScalarField, scalar>(rhoName_); + aveFlowRate = dir*gSum(phip/rhop)/gSum(patch().magSf()); + } + else + { + FatalErrorIn("fanPressureFvPatchScalarField::updateCoeffs()") + << "dimensions of phi are not correct" + << "\n on patch " << patch().name() + << " of field " << dimensionedInternalField().name() + << " in file " << dimensionedInternalField().objectPath() << nl + << exit(FatalError); + } + + // Normal flow through fan + if (aveFlowRate >= 0.0) + { + // Pressure drop for this flow rate + const scalar pdFan = fanCurve_(aveFlowRate); + + operator==(p0_ - dir*pdFan); + } + // Reverse flow + else + { + // Assume that fan has stalled if flow reversed + // i.e. apply dp for zero flow rate + const scalar pdFan = fanCurve_(0); + + // Flow speed across patch + scalarField Up = phip/(patch().magSf()); + + // Pressure drop associated withback flow = dynamic pressure + scalarField pdBackFlow = 0.5*magSqr(Up); + + if (phi.dimensions() == dimVelocity*dimArea*dimDensity) + { + const scalarField& rhop = + patch().lookupPatchField<volScalarField, scalar>(rhoName_); + pdBackFlow /= rhop; + } + + operator==(p0_ - dir*(pdBackFlow + pdFan)); + } + + fixedValueFvPatchScalarField::updateCoeffs(); +} + + +void Foam::fanPressureFvPatchScalarField::write(Ostream& os) const +{ + fvPatchScalarField::write(os); + os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; + os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; + fanCurve_.write(os); + os.writeKeyword("direction") + << fanFlowDirectionNames_[direction_] << token::END_STATEMENT << nl; + p0_.writeEntry("p0", os); + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + fanPressureFvPatchScalarField + ); +}; + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H new file mode 100644 index 0000000000000000000000000000000000000000..7c3d9ff4116cf48f9fe98017a9ea6e0737e334b2 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H @@ -0,0 +1,205 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 <http://www.gnu.org/licenses/>. + +Class + Foam::fanPressureFvPatchScalarField + +Description + Assigns pressure inlet or outlet condition for a fan. + + User specifies: + - pressure drop vs volumetric flow rate table (fan curve) file name; + - direction of normal flow through the fan, in or out; + - total pressure of the environment. + + Example of the boundary condition specification: + \verbatim + inlet + { + type fanPressure; + fileName "fanCurve"; // Fan curve file name + outOfBounds clamp; // (error|warn|clamp|repeat) + direction in; // Direction of flow through fan + p0 uniform 0; // Environmental total pressure + value uniform 0; // Initial pressure + } + + outlet + { + type fanPressure; + fileName "fanCurve"; // Fan curve file name + outOfBounds clamp; // (error|warn|clamp|repeat) + direction out; // Direction of flow through fan + p0 uniform 0; // Environmental total pressure + value uniform 0; // Initial pressure + } + \endverbatim + +See Also + Foam::interpolationTable and + Foam::timeVaryingFlowRateInletVelocityFvPatchVectorField + +SourceFiles + fanPressureFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fanPressureFvPatchScalarField_H +#define fanPressureFvPatchScalarField_H + +#include "fvPatchFields.H" +#include "fixedValueFvPatchFields.H" +#include "interpolationTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class fanPressureFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class fanPressureFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + // Private data + + //- Name of the flux transporting the field + word phiName_; + + //- Name of the density field + word rhoName_; + + //- Total pressure + scalarField p0_; + + //- Tabulated fan curve + interpolationTable<scalar> fanCurve_; + + //- Fan flow direction + enum fanFlowDirection + { + ffdIn, + ffdOut + }; + + static const NamedEnum<fanFlowDirection, 2> fanFlowDirectionNames_; + + //- Direction of flow through the fan relative to patch + fanFlowDirection direction_; + + +public: + + //- Runtime type information + TypeName("fanPressure"); + + + // Constructors + + //- Construct from patch and internal field + fanPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct from patch, internal field and dictionary + fanPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const dictionary& + ); + + //- Construct by mapping given + // fanPressureFvPatchScalarField + // onto a new patch + fanPressureFvPatchScalarField + ( + const fanPressureFvPatchScalarField&, + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + fanPressureFvPatchScalarField + ( + const fanPressureFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp<fvPatchScalarField> clone() const + { + return tmp<fvPatchScalarField> + ( + new fanPressureFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + fanPressureFvPatchScalarField + ( + const fanPressureFvPatchScalarField&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp<fvPatchScalarField> clone + ( + const DimensionedField<scalar, volMesh>& iF + ) const + { + return tmp<fvPatchScalarField> + ( + new fanPressureFvPatchScalarField + ( + *this, + iF + ) + ); + } + + + // Member functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/limiterBlended/limiterBlended.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/limiterBlended/limiterBlended.H index 9717c0a32695e98da1dd83455e022281a8628451..fd8f3269bbb86a53b965eef8de79d3a65f95694e 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/limiterBlended/limiterBlended.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/limiterBlended/limiterBlended.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,9 @@ Description limitedSurfaceInterpolationScheme. The limited scheme is specified first followed by the scheme to be scaled - by the limiter and then the scheme scaled by 1 - limiter. + by the limiter and then the scheme scaled by 1 - limiter e.g. + + div(phi,U) Gauss limiterBlended vanLeer linear linearUpwind grad(U); SourceFiles limiterBlended.C diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index c532ac3d399754382004951df214177767d82208..aa117c27942c4e90fc6b8521faaa170075dd7093 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -738,7 +738,6 @@ void Foam::triSurfaceMesh::findLineAll // we need something bigger since we're doing calculations) // - if the start-end vector is zero we still progress const vectorField dirVec(end-start); - const scalarField magSqrDirVec(magSqr(dirVec)); const vectorField smallVec ( indexedOctree<treeDataTriSurface>::perturbTol()*dirVec diff --git a/src/meshTools/triSurface/orientedSurface/orientedSurface.C b/src/meshTools/triSurface/orientedSurface/orientedSurface.C index 2b32604972cd4ebc5013cdd25310bd21d468cfd3..d72eba5f92041dc7e5d19546a998ee36a57c6a53 100644 --- a/src/meshTools/triSurface/orientedSurface/orientedSurface.C +++ b/src/meshTools/triSurface/orientedSurface/orientedSurface.C @@ -255,7 +255,6 @@ void Foam::orientedSurface::findZoneSide zoneFaceI = -1; isOutside = false; - List<pointIndexHit> hits; forAll(faceZone, faceI) @@ -305,7 +304,6 @@ void Foam::orientedSurface::findZoneSide { isOutside = ((n & d) > 0); } - break; } } @@ -354,6 +352,50 @@ bool Foam::orientedSurface::flipSurface } +bool Foam::orientedSurface::orientConsistent(triSurface& s) +{ + bool anyFlipped = false; + + // Do initial flipping to make triangles consistent. Otherwise if the + // nearest is e.g. on an edge inbetween inconsistent triangles it might + // make the wrong decision. + if (s.size() > 0) + { + // Whether face has to be flipped. + // UNVISITED: unvisited + // NOFLIP: no need to flip + // FLIP: need to flip + labelList flipState(s.size(), UNVISITED); + + label faceI = 0; + while (true) + { + label startFaceI = -1; + while (faceI < s.size()) + { + if (flipState[faceI] == UNVISITED) + { + startFaceI = faceI; + break; + } + faceI++; + } + + if (startFaceI == -1) + { + break; + } + + flipState[startFaceI] = NOFLIP; + walkSurface(s, startFaceI, flipState); + } + + anyFlipped = flipSurface(s, flipState); + } + return anyFlipped; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Null constructor @@ -404,44 +446,10 @@ bool Foam::orientedSurface::orient const bool orientOutside ) { - bool anyFlipped = false; - // Do initial flipping to make triangles consistent. Otherwise if the // nearest is e.g. on an edge inbetween inconsistent triangles it might // make the wrong decision. - if (s.size() > 0) - { - // Whether face has to be flipped. - // UNVISITED: unvisited - // NOFLIP: no need to flip - // FLIP: need to flip - labelList flipState(s.size(), UNVISITED); - - label faceI = 0; - while (true) - { - label startFaceI = -1; - while (faceI < s.size()) - { - if (flipState[faceI] == UNVISITED) - { - startFaceI = faceI; - break; - } - faceI++; - } - - if (startFaceI == -1) - { - break; - } - - flipState[startFaceI] = NOFLIP; - walkSurface(s, startFaceI, flipState); - } - - anyFlipped = flipSurface(s, flipState); - } + bool topoFlipped = orientConsistent(s); // Whether face has to be flipped. @@ -497,7 +505,7 @@ bool Foam::orientedSurface::orient // Now finally flip triangles according to flipState. bool geomFlipped = flipSurface(s, flipState); - return anyFlipped || geomFlipped; + return topoFlipped || geomFlipped; } @@ -509,6 +517,11 @@ bool Foam::orientedSurface::orient const bool orientOutside ) { + // Do initial flipping to make triangles consistent. Otherwise if the + // nearest is e.g. on an edge inbetween inconsistent triangles it might + // make the wrong decision. + bool topoFlipped = orientConsistent(s); + // Determine disconnected parts of surface boolList borderEdge(s.nEdges(), false); forAll(s.edgeFaces(), edgeI) @@ -549,7 +562,11 @@ bool Foam::orientedSurface::orient } walkSurface(s, zoneFaceI, flipState); } - return flipSurface(s, flipState); + + // Now finally flip triangles according to flipState. + bool geomFlipped = flipSurface(s, flipState); + + return topoFlipped || geomFlipped; } diff --git a/src/meshTools/triSurface/orientedSurface/orientedSurface.H b/src/meshTools/triSurface/orientedSurface/orientedSurface.H index 209673a1877671d5dac558d1df246479eb72d25b..ea69ca1ebbc13bb7b779c1147727d0009fb2dc49 100644 --- a/src/meshTools/triSurface/orientedSurface/orientedSurface.H +++ b/src/meshTools/triSurface/orientedSurface/orientedSurface.H @@ -128,6 +128,9 @@ class orientedSurface // anything flipped. static bool flipSurface(triSurface& s, const labelList& flipState); + //- Make surface surface has consistent orientation across connected + // triangles. + static bool orientConsistent(triSurface& s); public: ClassName("orientedSurface"); diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C index b24c482b251a3ce3b0e58b42fa66b03e3def386e..0f695cb1d8595740c33c8af6eb469f4062354a23 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C @@ -201,9 +201,8 @@ const if (inter.hit()) { - label sz = hits.size(); - hits.setSize(sz+1); - hits[sz] = inter; + hits.setSize(1); + hits[0] = inter; const vector dirVec(end-start); const scalar magSqrDirVec(magSqr(dirVec)); diff --git a/src/turbulenceModels/incompressible/LES/kOmegaSSTSAS/kOmegaSSTSAS.H b/src/turbulenceModels/incompressible/LES/kOmegaSSTSAS/kOmegaSSTSAS.H index 37d82f4ccb0509214ca598a884fb43a5f42dad9e..9fea19fe8ef2b86ad0fb612a26260a396da631bd 100644 --- a/src/turbulenceModels/incompressible/LES/kOmegaSSTSAS/kOmegaSSTSAS.H +++ b/src/turbulenceModels/incompressible/LES/kOmegaSSTSAS/kOmegaSSTSAS.H @@ -25,14 +25,23 @@ Class Foam::incompressible::LESModels::kOmegaSSTSAS Description - kOmegaSSTSAS LES turbulence model for incompressible flows + kOmegaSSTSAS LES turbulence model for incompressible flows + based on: + "Evaluation of the SST-SAS model: channel flow, asymmetric diffuser + and axi-symmetric hill". + European Conference on Computational Fluid Dynamics ECCOMAS CFD 2006. + Lars Davidson + + + The first term of the Qsas expression is corrected following: DESider A European Effort on Hybrid RANS-LES Modelling: Results of the European-Union Funded Project, 2004 - 2007 (Notes on Numerical Fluid Mechanics and Multidisciplinary Design). - Chapter 8 Formulation of the Scale-Adaptive Simulation (SAS) Model during - the DESIDER Project. Published in Springer-Verlag Berlin Heidelberg 2009. + Chapter 2, section 8 Formulation of the Scale-Adaptive Simulation (SAS) + Model during the DESIDER Project. Published in Springer-Verlag Berlin + Heidelberg 2009. F. R. Menter and Y. Egorov. SourceFiles