From 21656d33475bf34eef38e9332a84a17eeb3fb103 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 19 Sep 2012 16:37:15 +0100 Subject: [PATCH 01/24] ENH: Initial check-in of wallShearStress function object --- .../functionObjects/utilities/Make/files | 3 + .../wallShearStress/IOwallShearStress.H | 49 ++++ .../wallShearStress/wallShearStress.C | 251 ++++++++++++++++++ .../wallShearStress/wallShearStress.H | 163 ++++++++++++ .../wallShearStressFunctionObject.C | 42 +++ .../wallShearStressFunctionObject.H | 53 ++++ 6 files changed, 561 insertions(+) create mode 100644 src/postProcessing/functionObjects/utilities/wallShearStress/IOwallShearStress.H create mode 100644 src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C create mode 100644 src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.H create mode 100644 src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.C create mode 100644 src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.H diff --git a/src/postProcessing/functionObjects/utilities/Make/files b/src/postProcessing/functionObjects/utilities/Make/files index f6e23536e0..e6fcedbb0d 100644 --- a/src/postProcessing/functionObjects/utilities/Make/files +++ b/src/postProcessing/functionObjects/utilities/Make/files @@ -12,6 +12,9 @@ staticPressure/staticPressureFunctionObject.C timeActivatedFileUpdate/timeActivatedFileUpdate.C timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C +wallShearStress/wallShearStress.C +wallShearStress/wallShearStressFunctionObject.C + yPlusLES/yPlusLES.C yPlusLES/yPlusLESFunctionObject.C diff --git a/src/postProcessing/functionObjects/utilities/wallShearStress/IOwallShearStress.H b/src/postProcessing/functionObjects/utilities/wallShearStress/IOwallShearStress.H new file mode 100644 index 0000000000..c7e453b1d8 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/IOwallShearStress.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::IOwallShearStress + +Description + Instance of the generic IOOutputFilter for wallShearStress. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOwallShearStress_H +#define IOwallShearStress_H + +#include "wallShearStress.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOwallShearStress; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C new file mode 100644 index 0000000000..c495cd97d1 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C @@ -0,0 +1,251 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "wallShearStress.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "incompressible/turbulenceModel/turbulenceModel.H" +#include "compressible/turbulenceModel/turbulenceModel.H" +#include "wallPolyPatch.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::wallShearStress, 0); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::wallShearStress::makeFile() +{ + // Create the output file if not already created + if (outputFilePtr_.empty()) + { + if (debug) + { + Info<< "Creating output file." << endl; + } + + // File update + if (Pstream::master()) + { + fileName outputDir; + word startTimeName = + obr_.time().timeName(obr_.time().startTime().value()); + + if (Pstream::parRun()) + { + // Put in undecomposed case (Note: gives problems for + // distributed data running) + outputDir = + obr_.time().path()/".."/name_/startTimeName; + } + else + { + outputDir = obr_.time().path()/name_/startTimeName; + } + + // Create directory if does not exist + mkDir(outputDir); + + // Open new file at start up + outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat"))); + + // Add headers to output data + outputFilePtr_() << "# Wall shear stress" << nl + << "# time " << token::TAB << "patch" << token::TAB + << "min" << token::TAB << "max" << endl; + } + } +} + + +void Foam::wallShearStress::calcShearStress +( + const fvMesh& mesh, + const volSymmTensorField& Reff, + volVectorField& shearStress +) +{ + forAll(shearStress.boundaryField(), patchI) + { + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + + if (isA(pp)) + { + vectorField& ssp = shearStress.boundaryField()[patchI]; + const vectorField& Sfp = mesh.Sf().boundaryField()[patchI]; + const scalarField& magSfp = mesh.magSf().boundaryField()[patchI]; + const symmTensorField& Reffp = Reff.boundaryField()[patchI]; + + ssp = (-Sfp/magSfp) & Reffp; + + vector minSsp = min(ssp); + vector maxSsp = max(ssp); + + outputFilePtr_() << mesh.time().timeName() << token::TAB + << pp.name() << token::TAB << minSsp + << token::TAB << maxSsp << endl; + + if (log_) + { + Info<< " min/max(" << pp.name() << ") = " + << minSsp << ", " << maxSsp << endl; + } + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::wallShearStress::wallShearStress +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + log_(false), + phiName_("phi"), + outputFilePtr_(NULL) +{ + // Check if the available mesh is an fvMesh, otherwise deactivate + if (!isA(obr_)) + { + active_ = false; + WarningIn + ( + "wallShearStress::wallShearStress" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "No fvMesh available, deactivating." << nl + << endl; + } + + makeFile(); + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::wallShearStress::~wallShearStress() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::wallShearStress::read(const dictionary& dict) +{ + if (active_) + { + log_ = dict.lookupOrDefault("log", false); + phiName_ = dict.lookupOrDefault("phiName", "phi"); + } +} + + +void Foam::wallShearStress::execute() +{ + // Do nothing - only valid on write +} + + +void Foam::wallShearStress::end() +{ + // Do nothing - only valid on write +} + + +void Foam::wallShearStress::write() +{ + typedef compressible::turbulenceModel cmpModel; + typedef incompressible::turbulenceModel icoModel; + + if (active_) + { + const fvMesh& mesh = refCast(obr_); + + volVectorField wallShearStress + ( + IOobject + ( + "wallShearStress", + mesh.time().timeName(), + mesh, + IOobject::NO_READ + ), + mesh, + dimensionedVector("0", sqr(dimLength)/sqr(dimTime), vector::zero) + ); + + if (log_) + { + Info<< type() << " output:" << nl; + } + + + const surfaceScalarField& phi = + obr_.lookupObject(phiName_); + + tmp Reff; + if (phi.dimensions() == dimMass/dimTime) + { + const cmpModel& model = + mesh.lookupObject("turbulenceModel"); + + Reff = model.devRhoReff(); + } + else + { + const icoModel& model = + mesh.lookupObject("turbulenceModel"); + + Reff = model.devReff(); + } + + + calcShearStress(mesh, Reff(), wallShearStress); + + if (log_) + { + Info<< endl; + } + + wallShearStress.write(); + } +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.H b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.H new file mode 100644 index 0000000000..b2cff373be --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.H @@ -0,0 +1,163 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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::wallShearStress + +Description + Evaluates and outputs wall shear stress. Values written to time folders + as field 'wallShearStress' + +SourceFiles + wallShearStress.C + IOwallShearStress.H + +\*---------------------------------------------------------------------------*/ + +#ifndef wallShearStress_H +#define wallShearStress_H + +#include "volFieldsFwd.H" +#include "pointFieldFwd.H" +#include "Switch.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; +class fvMesh; + +/*---------------------------------------------------------------------------*\ + Class wallShearStress Declaration +\*---------------------------------------------------------------------------*/ + +class wallShearStress +{ + // Private data + + //- Name of this set of wallShearStress object + word name_; + + const objectRegistry& obr_; + + //- on/off switch + bool active_; + + //- Switch to send output to Info as well as to file + Switch log_; + + //- Name of mass/volume flux field (optional, default = phi) + word phiName_; + + //- Output file pointer + autoPtr outputFilePtr_; + + + // Private Member Functions + + //- Make the output file + virtual void makeFile(); + + //- Calculate the shear stress + void calcShearStress + ( + const fvMesh& mesh, + const volSymmTensorField& Reff, + volVectorField& shearStress + ); + + //- Disallow default bitwise copy construct + wallShearStress(const wallShearStress&); + + //- Disallow default bitwise assignment + void operator=(const wallShearStress&); + + +public: + + //- Runtime type information + TypeName("wallShearStress"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + wallShearStress + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~wallShearStress(); + + + // Member Functions + + //- Return name of the set of wallShearStress + virtual const word& name() const + { + return name_; + } + + //- Read the wallShearStress 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 wallShearStress 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/wallShearStress/wallShearStressFunctionObject.C b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.C new file mode 100644 index 0000000000..871e6b0373 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.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 "wallShearStressFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug(wallShearStressFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + wallShearStressFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.H b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.H new file mode 100644 index 0000000000..75e6eba8b4 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStressFunctionObject.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::wallShearStressFunctionObject + +Description + FunctionObject wrapper around wallShearStress to allow it to be created + via the functions entry within controlDict. + +SourceFiles + wallShearStressFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef wallShearStressFunctionObject_H +#define wallShearStressFunctionObject_H + +#include "wallShearStress.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject wallShearStressFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From 4012ecfd661e0087914a7c074dd4e58417131e55 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 20 Sep 2012 09:26:52 +0100 Subject: [PATCH 02/24] ENH: add site-specific scripts "bin/" to pathi (Mark Olesen) - allow both generic and version-specific. Only added to the path if the directory already exists when the bashrc/cshrc is sourced STYLE: refactor (simplify) site-directory handling --- etc/config/settings.csh | 25 ++++++++++++++++++------- etc/config/settings.sh | 30 ++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/etc/config/settings.csh b/etc/config/settings.csh index 0896420bcc..069624f513 100644 --- a/etc/config/settings.csh +++ b/etc/config/settings.csh @@ -151,15 +151,17 @@ setenv FOAM_LIBBIN $WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib # external (ThirdParty) libraries setenv FOAM_EXT_LIBBIN $WM_THIRD_PARTY_DIR/platforms/$WM_OPTIONS/lib +# site-specific directory +if ( $?WM_PROJECT_SITE ) then + set siteDir=$WM_PROJECT_SITE +else + set siteDir=$WM_PROJECT_INST_DIR/site +endif + # shared site executables/libraries # similar naming convention as ~OpenFOAM expansion -if ( $?WM_PROJECT_SITE ) then - setenv FOAM_SITE_APPBIN $WM_PROJECT_SITE/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin - setenv FOAM_SITE_LIBBIN $WM_PROJECT_SITE/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib -else - setenv FOAM_SITE_APPBIN $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin - setenv FOAM_SITE_LIBBIN $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib -endif +setenv FOAM_SITE_APPBIN $siteDir/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin +setenv FOAM_SITE_LIBBIN $siteDir/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib # user executables/libraries setenv FOAM_USER_APPBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin @@ -182,6 +184,15 @@ if ( -d "${WM_DIR}" ) setenv PATH ${WM_DIR}:${PATH} # add OpenFOAM scripts to the path setenv PATH ${WM_PROJECT_DIR}/bin:${PATH} +# add site-specific scripts to path - only if they exist +if ( -d "$siteDir/bin" ) then # generic + _foamAddPath "$siteDir/bin" +endif +if ( -d "$siteDir/$WM_PROJECT_VERSION/bin" ) then # version-specific + _foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" +endif +unset siteDir + _foamAddPath ${FOAM_USER_APPBIN}:${FOAM_SITE_APPBIN}:${FOAM_APPBIN} # Make sure to pick up dummy versions of external libraries last _foamAddLib ${FOAM_USER_LIBBIN}:${FOAM_SITE_LIBBIN}:${FOAM_LIBBIN}:${FOAM_EXT_LIBBIN}:${FOAM_LIBBIN}/dummy diff --git a/etc/config/settings.sh b/etc/config/settings.sh index 1a7e8237f9..1fc2136530 100644 --- a/etc/config/settings.sh +++ b/etc/config/settings.sh @@ -179,16 +179,13 @@ export FOAM_LIBBIN=$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib # external (ThirdParty) libraries export FOAM_EXT_LIBBIN=$WM_THIRD_PARTY_DIR/platforms/$WM_OPTIONS/lib +# site-specific directory +siteDir="${WM_PROJECT_SITE:-$WM_PROJECT_INST_DIR/site}" + # shared site executables/libraries # similar naming convention as ~OpenFOAM expansion -if [ -n "$WM_PROJECT_SITE" ] -then - export FOAM_SITE_APPBIN=$WM_PROJECT_SITE/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin - export FOAM_SITE_LIBBIN=$WM_PROJECT_SITE/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib -else - export FOAM_SITE_APPBIN=$WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin - export FOAM_SITE_LIBBIN=$WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib -fi +export FOAM_SITE_APPBIN=$siteDir/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin +export FOAM_SITE_LIBBIN=$siteDir/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib # user executables/libraries export FOAM_USER_APPBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin @@ -211,6 +208,17 @@ export FOAM_RUN=$WM_PROJECT_USER_DIR/run # add OpenFOAM scripts to the path export PATH=$WM_PROJECT_DIR/bin:$PATH +# add site-specific scripts to path - only if they exist +if [ -d "$siteDir/bin" ] # generic +then + _foamAddPath "$siteDir/bin" +fi +if [ -d "$siteDir/$WM_PROJECT_VERSION/bin" ] # version-specific +then + _foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" +fi +unset siteDir + _foamAddPath $FOAM_USER_APPBIN:$FOAM_SITE_APPBIN:$FOAM_APPBIN # Make sure to pick up dummy versions of external libraries last _foamAddLib $FOAM_USER_LIBBIN:$FOAM_SITE_LIBBIN:$FOAM_LIBBIN:$FOAM_EXT_LIBBIN:$FOAM_LIBBIN/dummy @@ -232,6 +240,12 @@ fi case "${foamCompiler}" in OpenFOAM | ThirdParty) case "$WM_COMPILER" in + Gcc463) + gcc_version=gcc-4.6.3 + gmp_version=gmp-5.0.2 + mpfr_version=mpfr-3.0.1 + mpc_version=mpc-0.9 + ;; Gcc | Gcc++0x | Gcc46 | Gcc46++0x) gcc_version=gcc-4.6.1 gmp_version=gmp-5.0.4 From 122114042ad8e822153bd9e21160e05181f5af99 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 20 Sep 2012 10:15:20 +0100 Subject: [PATCH 03/24] STYLE: minor coding style changes --- .../functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C | 2 +- .../functionObjects/utilities/wallShearStress/wallShearStress.C | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index cf76cbda0e..cfde197248 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -96,7 +96,7 @@ void Foam::fieldMinMax::calcMinMaxFields } fieldMinMaxFilePtr_() - << token::TAB << maxValue << token::TAB << maxC; + << token::TAB << maxValue << token::TAB << maxC; if (Pstream::parRun()) { diff --git a/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C index c495cd97d1..72244ea4b1 100644 --- a/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C +++ b/src/postProcessing/functionObjects/utilities/wallShearStress/wallShearStress.C @@ -110,7 +110,7 @@ void Foam::wallShearStress::calcShearStress if (log_) { - Info<< " min/max(" << pp.name() << ") = " + Info<< " min/max(" << pp.name() << ") = " << minSsp << ", " << maxSsp << endl; } } From da51ab1062019aa2d585a5ec8c03df9dd5e1cce4 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 20 Sep 2012 10:16:14 +0100 Subject: [PATCH 04/24] Initial check-in of CourantNo function object --- .../utilities/CourantNo/CourantNo.C | 327 ++++++++++++++++++ .../utilities/CourantNo/CourantNo.H | 164 +++++++++ .../CourantNo/CourantNoFunctionObject.C | 42 +++ .../CourantNo/CourantNoFunctionObject.H | 53 +++ .../utilities/CourantNo/IOCourantNo.H | 49 +++ .../functionObjects/utilities/Make/files | 3 + 6 files changed, 638 insertions(+) create mode 100644 src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.C create mode 100644 src/postProcessing/functionObjects/utilities/CourantNo/CourantNo.H create mode 100644 src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.C create mode 100644 src/postProcessing/functionObjects/utilities/CourantNo/CourantNoFunctionObject.H create mode 100644 src/postProcessing/functionObjects/utilities/CourantNo/IOCourantNo.H 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 From b9820bf4e7e43e3c50ead3d096baaed8709a8cf4 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 20 Sep 2012 14:15:15 +0100 Subject: [PATCH 05/24] ENH: enabled writing of faceSource function object values using a surfaceWriter --- .../field/fieldValues/faceSource/faceSource.C | 132 ++++++++++++++++++ .../field/fieldValues/faceSource/faceSource.H | 21 ++- .../faceSource/faceSourceTemplates.C | 51 ++++--- 3 files changed, 182 insertions(+), 22 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 6ce7b3350d..600d3d9ecd 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -29,6 +29,8 @@ License #include "emptyPolyPatch.H" #include "coupledPolyPatch.H" #include "sampledSurface.H" +#include "mergePoints.H" +#include "indirectPrimitivePatch.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -222,6 +224,127 @@ void Foam::fieldValues::faceSource::sampledSurfaceFaces(const dictionary& dict) } +void Foam::fieldValues::faceSource::combineSurfaceGeometry +( + faceList& faces, + pointField& points +) const +{ + List allFaces(Pstream::nProcs()); + List allPoints(Pstream::nProcs()); + + labelList globalFacesIs(faceId_); + forAll(globalFacesIs, i) + { + if (facePatchId_[i] != -1) + { + label patchI = facePatchId_[i]; + globalFacesIs[i] += mesh().boundaryMesh()[patchI].start(); + } + } + + // Add local faces and points to the all* lists + indirectPrimitivePatch pp + ( + IndirectList(mesh().faces(), globalFacesIs), + mesh().points() + ); + allFaces[Pstream::myProcNo()] = pp.localFaces(); + allPoints[Pstream::myProcNo()] = pp.localPoints(); + + Pstream::gatherList(allFaces); + Pstream::gatherList(allPoints); + + // Renumber and flatten + label nFaces = 0; + label nPoints = 0; + forAll(allFaces, procI) + { + nFaces += allFaces[procI].size(); + nPoints += allPoints[procI].size(); + } + + faces.setSize(nFaces); + points.setSize(nPoints); + + nFaces = 0; + nPoints = 0; + + // My own data first + { + const faceList& fcs = allFaces[Pstream::myProcNo()]; + forAll(fcs, i) + { + const face& f = fcs[i]; + face& newF = faces[nFaces++]; + newF.setSize(f.size()); + forAll(f, fp) + { + newF[fp] = f[fp] + nPoints; + } + } + + const pointField& pts = allPoints[Pstream::myProcNo()]; + forAll(pts, i) + { + points[nPoints++] = pts[i]; + } + } + + // Other proc data follows + forAll(allFaces, procI) + { + if (procI != Pstream::myProcNo()) + { + const faceList& fcs = allFaces[procI]; + forAll(fcs, i) + { + const face& f = fcs[i]; + face& newF = faces[nFaces++]; + newF.setSize(f.size()); + forAll(f, fp) + { + newF[fp] = f[fp] + nPoints; + } + } + + const pointField& pts = allPoints[procI]; + forAll(pts, i) + { + points[nPoints++] = pts[i]; + } + } + } + + // Merge + labelList oldToNew; + pointField newPoints; + bool hasMerged = mergePoints + ( + points, + SMALL, + false, + oldToNew, + newPoints + ); + + if (hasMerged) + { + if (debug) + { + Pout<< "Merged from " << points.size() + << " down to " << newPoints.size() << " points" << endl; + } + + points.transfer(newPoints); + forAll(faces, i) + { + inplaceRenumber(oldToNew, faces[i]); + } + } +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::fieldValues::faceSource::initialise(const dictionary& dict) @@ -291,6 +414,14 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) } Info<< nl << endl; + + if (valueOutput_) + { + surfaceWriterPtr_.reset + ( + surfaceWriter::New(dict.lookup("surfaceFormat")).ptr() + ); + } } @@ -355,6 +486,7 @@ Foam::fieldValues::faceSource::faceSource ) : fieldValue(name, obr, dict, loadFromFiles), + surfaceWriterPtr_(NULL), source_(sourceTypeNames_.read(dict.lookup("source"))), operation_(operationTypeNames_.read(dict.lookup("operation"))), weightFieldName_("none"), diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index fd95788894..c4473b352a 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -35,9 +35,10 @@ Description enabled true; outputControl outputTime; log true; // log to screen? - valueOutput true; // Write values at run-time output times? - source faceZone; // Type of face source: - // faceZone,patch,sampledSurface + valueOutput true; // write the output values + surfaceFormat none; // output value format (if valueOutput) + source faceZone; // type of face source: + // faceZone, patch, sampledSurface sourceName f0; // faceZone name, see below operation sum; weightField alpha1; // optional weight field @@ -97,6 +98,7 @@ SourceFiles #include "fieldValue.H" #include "surfaceFieldsFwd.H" #include "volFieldsFwd.H" +#include "surfaceWriter.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -166,11 +168,21 @@ private: //- Set faces according to sampledSurface void sampledSurfaceFaces(const dictionary&); + //- Combine faces and points from multiple processors + void combineSurfaceGeometry + ( + faceList& faces, + pointField& points + ) const; + protected: // Protected data + //- Surface writer + autoPtr surfaceWriterPtr_; + //- Source type sourceType source_; @@ -184,7 +196,7 @@ protected: label nFaces_; - // If operating on mesh faces (faceZone,patch) + // If operating on mesh faces (faceZone, patch) //- Local list of face IDs labelList faceId_; @@ -196,6 +208,7 @@ protected: // (1 use as is, -1 negate) labelList faceSign_; + // If operating on sampledSurface //- underlying sampledSurface diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index 450ac18d91..cfdcc08d4f 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -254,31 +254,46 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) combineFields(Sf); combineFields(weightField); + // Write raw values on surface if specified + if (surfaceWriterPtr_.valid()) + { + faceList faces; + pointField points; + combineSurfaceGeometry(faces, points); + + fileName outputDir; + if (Pstream::parRun()) + { + // Put in undecomposed case (Note: gives problems for + // distributed data running) + outputDir = obr_.time().path()/".."/name_; + } + else + { + outputDir = obr_.time().path()/name_; + } + + outputDir = outputDir/"surface"/obr_.time().timeName(); + + surfaceWriterPtr_->write + ( + outputDir, + word(sourceTypeNames_[source_]) + "_" + sourceName_, + points, + faces, + fieldName, + values, + false + ); + } + // apply weight field values *= weightField; - if (Pstream::master()) { Type result = processValues(values, Sf, weightField); - if (valueOutput_) - { - IOField - ( - IOobject - ( - fieldName + "_" + sourceTypeNames_[source_] + "-" - + sourceName_, - obr_.time().timeName(), - obr_, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - values - ).write(); - } - outputFilePtr_()<< tab << result; if (log_) From 4414a656830153e80ff33b75160ec8201d642702 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Sep 2012 12:37:56 +0100 Subject: [PATCH 06/24] ENH: Added helper function to set 'writer' API --- src/sampling/sampledSet/writers/writer.C | 21 ++++++++++++++++++++- src/sampling/sampledSet/writers/writer.H | 21 +++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/sampling/sampledSet/writers/writer.C b/src/sampling/sampledSet/writers/writer.C index ded4523d1c..69dbdec6fe 100644 --- a/src/sampling/sampledSet/writers/writer.C +++ b/src/sampling/sampledSet/writers/writer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -152,6 +152,25 @@ Foam::writer::~writer() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::writer::write +( + const coordSet& points, + const wordList& valueSetNames, + const List >& valueSets, + Ostream& os +) const +{ + List*> valueSetPtrs(valueSets.size()); + forAll(valueSetPtrs, i) + { + valueSetPtrs[i] = &valueSets[i]; + } + + write(points, valueSetNames, valueSetPtrs, os); +} + + template Foam::Ostream& Foam::writer::write ( diff --git a/src/sampling/sampledSet/writers/writer.H b/src/sampling/sampledSet/writers/writer.H index 6e55a20b6e..8c754bd47b 100644 --- a/src/sampling/sampledSet/writers/writer.H +++ b/src/sampling/sampledSet/writers/writer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,13 +40,7 @@ Description // Output list of points and corresponding values scalarFormatter().write ( - coordSet - ( - points, // sample coordinates - "someLine", // name of coordSet - "distance", // write coordinates as distance to refPoint - points[0] // reference point - ), + coordSet(...) "U.component(0)", // name of values vals // values ); @@ -164,6 +158,17 @@ public: Ostream& ) const = 0; + //- General entry point for writing. + // The data is organized in a set of point with one or more values + // per point + virtual void write + ( + const coordSet&, + const wordList&, + const List >&, + Ostream& + ) const; + //- General entry point for writing of multiple coordSets. // Each coordSet (track) has same data variables. // The data is per variable, per track, per point of track. From d8cb5d97f4a544c8cc80af0f2bbd1a0ef3a989f5 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Sep 2012 12:38:47 +0100 Subject: [PATCH 07/24] ENH: forces function object - added data output into bins --- .../functionObjects/forces/forces/forces.C | 437 ++++++++++++------ .../functionObjects/forces/forces/forces.H | 106 +++-- 2 files changed, 368 insertions(+), 175 deletions(-) diff --git a/src/postProcessing/functionObjects/forces/forces/forces.C b/src/postProcessing/functionObjects/forces/forces/forces.C index cf835d66ef..318e732b31 100644 --- a/src/postProcessing/functionObjects/forces/forces/forces.C +++ b/src/postProcessing/functionObjects/forces/forces/forces.C @@ -43,7 +43,78 @@ License defineTypeNameAndDebug(Foam::forces, 0); -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::fileName Foam::forces::baseFileDir() const +{ + fileName baseDir; + + if (Pstream::parRun()) + { + // Put in undecomposed case (Note: gives problems for + // distributed data running) + baseDir = obr_.time().path()/".."/name_; + } + else + { + baseDir = obr_.time().path()/name_; + } + + return baseDir; +} + + +void Foam::forces::makeFile() +{ + // Create the forces file if not already created + if (forcesFilePtr_.empty()) + { + if (debug) + { + Info<< "Creating forces file" << endl; + } + + // File update + if (Pstream::master()) + { + word startTimeName = + obr_.time().timeName(obr_.time().startTime().value()); + + fileName forcesDir = baseFileDir()/startTimeName; + + // Create directory if does not exist. + mkDir(forcesDir); + + // Open new file at start up + forcesFilePtr_.reset(new OFstream(forcesDir/(type() + ".dat"))); + + // Add headers to output data + writeFileHeader(); + } + } +} + + +void Foam::forces::writeFileHeader() +{ + if (forcesFilePtr_.valid()) + { + forcesFilePtr_() + << "# Time" << tab + << "forces(pressure, viscous) moment(pressure, viscous)"; + + if (localSystem_) + { + forcesFilePtr_() + << tab + << "local forces(pressure, viscous) " + << "local moment(pressure, viscous)"; + } + + forcesFilePtr_()<< endl; + } +} + Foam::tmp Foam::forces::devRhoReff() const { @@ -167,6 +238,85 @@ Foam::scalar Foam::forces::rho(const volScalarField& p) const } +void Foam::forces::applyBins +( + const label patchI, + const vectorField fN, + const vectorField Md, + const vectorField fT +) +{ + if (nBin_ == 1) + { + force_[0][0] = sum(fN); + force_[1][0] = sum(fT); + moment_[0][0] = sum(Md ^ fN); + moment_[1][0] = sum(Md ^ fT); + } + else + { + const fvMesh& mesh = refCast(obr_); + const vectorField& Cf = mesh.C().boundaryField()[patchI]; + scalarField d((Cf & binDir_) - binMin_); + + forAll(d, i) + { + label binI = floor(d[i]/binDx_); + force_[0][binI] += fN[i]; + force_[1][binI] += fT[i]; + moment_[0][binI] += Md[i]^fN[i]; + moment_[1][binI] += Md[i]^fT[i]; + } + } +} + + +void Foam::forces::writeBins() const +{ + if (nBin_ == 1) + { + return; + } + + autoPtr > binWriterPtr(writer::New(binFormat_)); + coordSet axis("forces", "distance", binPoints_, mag(binPoints_)); + + fileName forcesDir = baseFileDir()/"bins"/obr_.time().timeName(); + mkDir(forcesDir); + + if (log_) + { + Info<< " Writing bins to " << forcesDir << endl; + + } + + wordList fieldNames(IStringStream("(pressure viscous)")()); + + OFstream osForce(forcesDir/"force"); + binWriterPtr->write(axis, fieldNames, force_, osForce); + + OFstream osMoment(forcesDir/"moment"); + binWriterPtr->write(axis, fieldNames, moment_, osMoment); + + + if (localSystem_) + { + List > localForce(2); + List > localMoment(2); + localForce[0] = coordSys_.localVector(force_[0]); + localForce[1] = coordSys_.localVector(force_[1]); + localMoment[0] = coordSys_.localVector(moment_[0]); + localMoment[1] = coordSys_.localVector(moment_[1]); + + OFstream osLocalForce(forcesDir/"force_local"); + binWriterPtr->write(axis, fieldNames, localForce, osLocalForce); + + OFstream osLocalMoment(forcesDir/"moment_local"); + binWriterPtr->write(axis, fieldNames, localMoment, osLocalMoment); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::forces::forces @@ -181,6 +331,8 @@ Foam::forces::forces obr_(obr), active_(true), log_(false), + force_(2), + moment_(2), patchSet_(), pName_(word::null), UName_(word::null), @@ -191,6 +343,12 @@ Foam::forces::forces pRef_(0), coordSys_(), localSystem_(false), + nBin_(1), + binDir_(vector::zero), + binDx_(0.0), + binMin_(GREAT), + binPoints_(), + binFormat_("undefined"), forcesFilePtr_(NULL) { // Check if the available mesh is an fvMesh otherise deactivate @@ -231,6 +389,8 @@ Foam::forces::forces obr_(obr), active_(true), log_(false), + force_(2), + moment_(2), patchSet_(patchSet), pName_(pName), UName_(UName), @@ -241,6 +401,12 @@ Foam::forces::forces pRef_(pRef), coordSys_(coordSys), localSystem_(false), + nBin_(1), + binDir_(vector::zero), + binDx_(0.0), + binMin_(GREAT), + binPoints_(), + binFormat_("undefined"), forcesFilePtr_(NULL) {} @@ -261,11 +427,9 @@ void Foam::forces::read(const dictionary& dict) directForceDensity_ = dict.lookupOrDefault("directForceDensity", false); const fvMesh& mesh = refCast(obr_); + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); - patchSet_ = mesh.boundaryMesh().patchSet - ( - wordReList(dict.lookup("patches")) - ); + patchSet_ = pbm.patchSet(wordReList(dict.lookup("patches"))); if (directForceDensity_) { @@ -334,68 +498,77 @@ void Foam::forces::read(const dictionary& dict) coordSys_ = coordinateSystem(dict, obr_); localSystem_ = true; } - } -} - -void Foam::forces::makeFile() -{ - // Create the forces file if not already created - if (forcesFilePtr_.empty()) - { - if (debug) + // read bin information if present + if (dict.readIfPresent