From 0271344d3e210bd97b3e17d1c120d82bfed2859a Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 6 Sep 2010 17:31:30 +0100 Subject: [PATCH] outletMappedUniformInletFvPatchField: New BC which maps the average field value from outlet to inlet --- src/finiteVolume/Make/files | 1 + .../outletMappedUniformInletFvPatchField.C | 190 ++++++++++++++++++ .../outletMappedUniformInletFvPatchField.H | 169 ++++++++++++++++ .../outletMappedUniformInletFvPatchFields.C | 43 ++++ .../outletMappedUniformInletFvPatchFields.H | 49 +++++ ...outletMappedUniformInletFvPatchFieldsFwd.H | 50 +++++ 6 files changed, 502 insertions(+) create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.H create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.H create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFieldsFwd.H diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 126669d56a..9c280f9288 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -158,6 +158,7 @@ $(derivedFvPatchFields)/waveTransmissive/waveTransmissiveFvPatchFields.C $(derivedFvPatchFields)/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C $(derivedFvPatchFields)/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C +$(derivedFvPatchFields)/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C fvsPatchFields = fields/fvsPatchFields diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C new file mode 100644 index 0000000000..c3f2d89451 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C @@ -0,0 +1,190 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 . + +\*---------------------------------------------------------------------------*/ + +#include "outletMappedUniformInletFvPatchField.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +outletMappedUniformInletFvPatchField:: +outletMappedUniformInletFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + outletPatchName_(), + phiName_("phi") +{} + + +template +outletMappedUniformInletFvPatchField:: +outletMappedUniformInletFvPatchField +( + const outletMappedUniformInletFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + outletPatchName_(ptf.outletPatchName_), + phiName_(ptf.phiName_) +{} + + +template +outletMappedUniformInletFvPatchField:: +outletMappedUniformInletFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF, dict), + outletPatchName_(dict.lookup("outletPatchName")), + phiName_(dict.lookupOrDefault("phi", "phi")) +{} + + +template +outletMappedUniformInletFvPatchField:: +outletMappedUniformInletFvPatchField +( + const outletMappedUniformInletFvPatchField& ptf +) +: + fixedValueFvPatchField(ptf), + outletPatchName_(ptf.outletPatchName_), + phiName_(ptf.phiName_) +{} + + + +template +outletMappedUniformInletFvPatchField:: +outletMappedUniformInletFvPatchField +( + const outletMappedUniformInletFvPatchField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + outletPatchName_(ptf.outletPatchName_), + phiName_(ptf.phiName_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void outletMappedUniformInletFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const GeometricField& f + ( + dynamic_cast&> + ( + this->dimensionedInternalField() + ) + ); + + const fvPatch& p = this->patch(); + label outletPatchID = + p.patch().boundaryMesh().findPatchID(outletPatchName_); + + if (outletPatchID < 0) + { + FatalErrorIn + ( + "void outletMappedUniformInletFvPatchField::updateCoeffs()" + ) << "Unable to find outlet patch " << outletPatchName_ + << abort(FatalError); + } + + const fvPatch& outletPatch = p.boundaryMesh()[outletPatchID]; + + const fvPatchField& outletPatchField = + f.boundaryField()[outletPatchID]; + + const surfaceScalarField& phi = + this->db().objectRegistry::lookupObject(phiName_); + const scalarField& outletPatchPhi = phi.boundaryField()[outletPatchID]; + scalar sumOutletPatchPhi = gSum(outletPatchPhi); + + if (sumOutletPatchPhi > SMALL) + { + Type averageOutletField = + gSum(outletPatchPhi*outletPatchField) + /sumOutletPatchPhi; + + this->operator==(averageOutletField); + } + else + { + Type averageOutletField = + gSum(outletPatch.magSf()*outletPatchField) + /gSum(outletPatch.magSf()); + + this->operator==(averageOutletField); + } + + fixedValueFvPatchField::updateCoeffs(); +} + + +template +void outletMappedUniformInletFvPatchField::write(Ostream& os) const +{ + fvPatchField::write(os); + os.writeKeyword("outletPatchName") + << outletPatchName_ << token::END_STATEMENT << nl; + if (phiName_ != "phi") + { + os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; + } + this->writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.H new file mode 100644 index 0000000000..1dee089380 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.H @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 . + +Class + Foam::outletMappedUniformInletFvPatchField + +Description + Averages the field over the "outlet" patch specified by name + "outletPatchName" and applies this as the uniform value of the field + over this patch. + +SourceFiles + outletMappedUniformInletFvPatchField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef outletMappedUniformInletFvPatchField_H +#define outletMappedUniformInletFvPatchField_H + +#include "fixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class outletMappedUniformInletFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +template +class outletMappedUniformInletFvPatchField +: + public fixedValueFvPatchField +{ + // Private data + + //- Name of the outlet patch to be mapped + word outletPatchName_; + + //- Name of the flux transporting the field + word phiName_; + + +public: + + //- Runtime type information + TypeName("outletMappedUniformInlet"); + + + // Constructors + + //- Construct from patch and internal field + outletMappedUniformInletFvPatchField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + outletMappedUniformInletFvPatchField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given outletMappedUniformInletFvPatchField + // onto a new patch + outletMappedUniformInletFvPatchField + ( + const outletMappedUniformInletFvPatchField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + outletMappedUniformInletFvPatchField + ( + const outletMappedUniformInletFvPatchField& + ); + + //- Construct and return a clone + virtual tmp > clone() const + { + return tmp > + ( + new outletMappedUniformInletFvPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + outletMappedUniformInletFvPatchField + ( + const outletMappedUniformInletFvPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp > clone + ( + const DimensionedField& iF + ) const + { + return tmp > + ( + new outletMappedUniformInletFvPatchField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Name of the outlet patch to be mapped + const word& outletPatchName() const + { + return outletPatchName_; + } + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "outletMappedUniformInletFvPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C new file mode 100644 index 0000000000..a932dca978 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 . + +\*---------------------------------------------------------------------------*/ + +#include "outletMappedUniformInletFvPatchFields.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +makePatchFields(outletMappedUniformInlet); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.H new file mode 100644 index 0000000000..17e96617df --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.H @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 . + +\*---------------------------------------------------------------------------*/ + +#ifndef outletMappedUniformInletFvPatchFields_H +#define outletMappedUniformInletFvPatchFields_H + +#include "outletMappedUniformInletFvPatchField.H" +#include "fieldTypes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makePatchTypeFieldTypedefs(outletMappedUniformInlet) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFieldsFwd.H new file mode 100644 index 0000000000..76033b9923 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchFieldsFwd.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 . + +\*---------------------------------------------------------------------------*/ + +#ifndef outletMappedUniformInletFvPatchFieldsFwd_H +#define outletMappedUniformInletFvPatchFieldsFwd_H + +#include "fieldTypes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template class outletMappedUniformInletFvPatchField; + +makePatchTypeFieldTypedefs(outletMappedUniformInlet) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //