From 42158324e1ece1164004e21e822ec137bfbdd3e1 Mon Sep 17 00:00:00 2001 From: ignis Date: Thu, 6 Sep 2018 14:26:42 +0900 Subject: [PATCH] copy of flowRateInletVelocity BC --- Make/files | 3 + Make/options | 9 + ...ateTiltedInletVelocityFvPatchVectorField.C | 222 ++++++++++++++++++ ...ateTiltedInletVelocityFvPatchVectorField.H | 214 +++++++++++++++++ 4 files changed, 448 insertions(+) create mode 100644 Make/files create mode 100644 Make/options create mode 100644 flowRateTiltedInletVelocityFvPatchVectorField.C create mode 100644 flowRateTiltedInletVelocityFvPatchVectorField.H diff --git a/Make/files b/Make/files new file mode 100644 index 0000000..3188a82 --- /dev/null +++ b/Make/files @@ -0,0 +1,3 @@ +flowRateTiltedInletVelocityFvPatchVectorField.C + +LIB = $(FOAM_USER_LIBBIN)/libSKGASBC diff --git a/Make/options b/Make/options new file mode 100644 index 0000000..97dc674 --- /dev/null +++ b/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/triSurface/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + +LIB_LIBS = \ + -lOpenFOAM \ + -ltriSurface \ + -lmeshTools diff --git a/flowRateTiltedInletVelocityFvPatchVectorField.C b/flowRateTiltedInletVelocityFvPatchVectorField.C new file mode 100644 index 0000000..bb3fcbf --- /dev/null +++ b/flowRateTiltedInletVelocityFvPatchVectorField.C @@ -0,0 +1,222 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 "flowRateTiltedInletVelocityFvPatchVectorField.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::flowRateTiltedInletVelocityFvPatchVectorField:: +flowRateTiltedInletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + flowRate_(), + volumetric_(false), + rhoName_("rho"), + rhoInlet_(0.0) +{} + + +Foam::flowRateTiltedInletVelocityFvPatchVectorField:: +flowRateTiltedInletVelocityFvPatchVectorField +( + const flowRateTiltedInletVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + flowRate_(ptf.flowRate_().clone().ptr()), + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) +{} + + +Foam::flowRateTiltedInletVelocityFvPatchVectorField:: +flowRateTiltedInletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF), + rhoInlet_(dict.lookupOrDefault("rhoInlet", -VGREAT)) +{ + if (dict.found("volumetricFlowRate")) + { + volumetric_ = true; + flowRate_ = DataEntry::New("volumetricFlowRate", dict); + rhoName_ = "rho"; + } + else if (dict.found("massFlowRate")) + { + volumetric_ = false; + flowRate_ = DataEntry::New("massFlowRate", dict); + rhoName_ = word(dict.lookupOrDefault("rho", "rho")); + } + else + { + FatalIOErrorIn + ( + "flowRateTiltedInletVelocityFvPatchVectorField::" + "flowRateTiltedInletVelocityFvPatchVectorField" + "(const fvPatch&, const DimensionedField&," + " const dictionary&)", + dict + ) << "Please supply either 'volumetricFlowRate' or" + << " 'massFlowRate' and 'rho'" << exit(FatalIOError); + } + + // Value field require if mass based + if (dict.found("value")) + { + fvPatchField::operator= + ( + vectorField("value", dict, p.size()) + ); + } + else + { + evaluate(Pstream::blocking); + } +} + + +Foam::flowRateTiltedInletVelocityFvPatchVectorField:: +flowRateTiltedInletVelocityFvPatchVectorField +( + const flowRateTiltedInletVelocityFvPatchVectorField& ptf +) +: + fixedValueFvPatchField(ptf), + flowRate_(ptf.flowRate_().clone().ptr()), + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) +{} + + +Foam::flowRateTiltedInletVelocityFvPatchVectorField:: +flowRateTiltedInletVelocityFvPatchVectorField +( + const flowRateTiltedInletVelocityFvPatchVectorField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + flowRate_(ptf.flowRate_().clone().ptr()), + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::flowRateTiltedInletVelocityFvPatchVectorField::updateCoeffs() +{ + if (updated()) + { + return; + } + + const scalar t = db().time().timeOutputValue(); + + // a simpler way of doing this would be nice + const scalar avgU = -flowRate_->value(t)/gSum(patch().magSf()); + + tmp n = patch().nf(); + + if (volumetric_ || rhoName_ == "none") + { + // volumetric flow-rate or density not given + operator==(n*avgU); + } + else + { + // mass flow-rate + if (db().foundObject(rhoName_)) + { + const fvPatchField& rhop = + patch().lookupPatchField(rhoName_); + + operator==(n*avgU/rhop); + } + else + { + // Use constant density + if (rhoInlet_ < 0) + { + FatalErrorIn + ( + "flowRateTiltedInletVelocityFvPatchVectorField::updateCoeffs()" + ) << "Did not find registered density field " << rhoName_ + << " and no constant density 'rhoInlet' specified" + << exit(FatalError); + } + operator==(n*avgU/rhoInlet_); + } + } + + fixedValueFvPatchVectorField::updateCoeffs(); +} + + +void Foam::flowRateTiltedInletVelocityFvPatchVectorField::write(Ostream& os) const +{ + fvPatchField::write(os); + flowRate_->writeData(os); + if (!volumetric_) + { + writeEntryIfDifferent(os, "rho", "rho", rhoName_); + writeEntryIfDifferent(os, "rhoInlet", -VGREAT, rhoInlet_); + } + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchVectorField, + flowRateTiltedInletVelocityFvPatchVectorField + ); +} + + +// ************************************************************************* // diff --git a/flowRateTiltedInletVelocityFvPatchVectorField.H b/flowRateTiltedInletVelocityFvPatchVectorField.H new file mode 100644 index 0000000..684f0a8 --- /dev/null +++ b/flowRateTiltedInletVelocityFvPatchVectorField.H @@ -0,0 +1,214 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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::flowRateTiltedInletVelocityFvPatchVectorField + +Group + grpInletBoundaryConditions + +Description + This boundary condition provides a velocity boundary condition, derived + from the flux (volumetric or mass-based), whose direction is assumed + to be normal to the patch. + + For a mass-based flux: + - the flow rate should be provided in kg/s + - if \c rhoName is "none" the flow rate is in m3/s + - otherwise \c rhoName should correspond to the name of the density field + - if the density field cannot be found in the database, the user must + specify the inlet density using the \c rhoInlet entry + + For a volumetric-based flux: + - the flow rate is in m3/s + + \heading Patch usage + + \table + Property | Description | Required | Default value + massFlowRate | mass flow rate [kg/s] | no | + volumetricFlowRate | volumetric flow rate [m3/s]| no | + rhoInlet | inlet density | no | + \endtable + + Example of the boundary condition specification for a volumetric flow rate: + \verbatim + myPatch + { + type flowRateTiltedInletVelocity; + volumetricFlowRate 0.2; + value uniform (0 0 0); // placeholder + } + \endverbatim + + Example of the boundary condition specification for a mass flow rate: + \verbatim + myPatch + { + type flowRateTiltedInletVelocity; + massFlowRate 0.2; + rho rho; + rhoInlet 1.0; + } + \endverbatim + + The \c flowRate entry is a \c DataEntry type, meaning that it can be + specified as constant, a polynomial fuction of time, and ... + +Note + - \c rhoInlet is required for the case of a mass flow rate, where the + density field is not available at start-up + - the value is positive into the domain (as an inlet) + - may not work correctly for transonic inlets + - strange behaviour with potentialFoam since the U equation is not solved + +SeeAlso + Foam::DataEntry + Foam::fixedValueFvPatchField + +SourceFiles + flowRateTiltedInletVelocityFvPatchVectorField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef flowRateTiltedInletVelocityFvPatchVectorField_H +#define flowRateTiltedInletVelocityFvPatchVectorField_H + +#include "fixedValueFvPatchFields.H" +#include "DataEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +/*---------------------------------------------------------------------------*\ + Class flowRateTiltedInletVelocityFvPatchVectorField Declaration +\*---------------------------------------------------------------------------*/ + +class flowRateTiltedInletVelocityFvPatchVectorField +: + public fixedValueFvPatchVectorField +{ + // Private data + + //- Inlet integral flow rate + autoPtr > flowRate_; + + //- Is volumetric? + bool volumetric_; + + //- Name of the density field used to normalize the mass flux + word rhoName_; + + //- Rho initialisation value (for start; if value not supplied) + scalar rhoInlet_; + + +public: + + //- Runtime type information + TypeName("flowRateTiltedInletVelocity"); + + + // Constructors + + //- Construct from patch and internal field + flowRateTiltedInletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + flowRateTiltedInletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given + // flowRateTiltedInletVelocityFvPatchVectorField + // onto a new patch + flowRateTiltedInletVelocityFvPatchVectorField + ( + const flowRateTiltedInletVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + flowRateTiltedInletVelocityFvPatchVectorField + ( + const flowRateTiltedInletVelocityFvPatchVectorField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new flowRateTiltedInletVelocityFvPatchVectorField(*this) + ); + } + + //- Construct as copy setting internal field reference + flowRateTiltedInletVelocityFvPatchVectorField + ( + const flowRateTiltedInletVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new flowRateTiltedInletVelocityFvPatchVectorField(*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 + +// ************************************************************************* //