diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 18d5b7c57b..9febff6522 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -184,6 +184,7 @@ $(derivedFvPatchFields)/fixedNormalInletOutletVelocity/fixedNormalInletOutletVel $(derivedFvPatchFields)/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C $(derivedFvPatchFields)/rotatingWallVelocity/rotatingWallVelocityFvPatchVectorField.C +$(derivedFvPatchFields)/scaledFixedValue/scaledFixedValueFvPatchFields.C $(derivedFvPatchFields)/slip/slipFvPatchFields.C $(derivedFvPatchFields)/supersonicFreestream/supersonicFreestreamFvPatchVectorField.C $(derivedFvPatchFields)/surfaceNormalFixedValue/surfaceNormalFixedValueFvPatchVectorField.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.C new file mode 100644 index 0000000000..bd12deb83d --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.C @@ -0,0 +1,240 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 "scaledFixedValueFvPatchField.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + scalePtr_(), + refValuePtr_(fvPatchField::New("refValue", p, iF)) +{} + + +template +Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF, dict, false), + scalePtr_(PatchFunction1::New(p.patch(), "scale", dict)), + refValuePtr_(fvPatchField::New(p, iF, dict.subDict("refValue"))) +{ + if (!isA>(refValuePtr_())) + { + FatalIOErrorInFunction(dict) + << typeName << " condition can only be applied to fixed value " + << "conditions" + << exit(FatalIOError); + } + + const scalarField s(scalePtr_->value(this->db().time().timeOutputValue())); + this->operator==(s*refValuePtr_()); +} + + +template +Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField +( + const scaledFixedValueFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + scalePtr_(ptf.scalePtr_.clone(p.patch())), + refValuePtr_(fvPatchField::New(ptf.refValue(), p, iF, mapper)) +{} + + +template +Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField +( + const scaledFixedValueFvPatchField& spf +) +: + fixedValueFvPatchField(spf), + scalePtr_(spf.scalePtr_.clone(spf.patch().patch())), + refValuePtr_(spf.refValue().clone()) +{} + + +template +Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField +( + const scaledFixedValueFvPatchField& spf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(spf, iF), + scalePtr_(spf.scalePtr_.clone(spf.patch().patch())), + refValuePtr_(spf.refValue().clone()) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::scaledFixedValueFvPatchField::autoMap +( + const fvPatchFieldMapper& m +) +{ + fixedValueFvPatchField::autoMap(m); + refValuePtr_->autoMap(m); + + scalePtr_().autoMap(m); + + if (scalePtr_().constant()) + { + // If mapper is not dependent on time we're ok to evaluate + this->evaluate(); + } +} + + +template +void Foam::scaledFixedValueFvPatchField::rmap +( + const fvPatchField& ptf, + const labelList& addr +) +{ + fixedValueFvPatchField::rmap(ptf, addr); + + const scaledFixedValueFvPatchField& sptf = + refCast(ptf); + + refValuePtr_->rmap(sptf.refValue(), addr); + + scalePtr_().rmap(sptf.scalePtr_(), addr); +} + + +template +void Foam::scaledFixedValueFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + refValuePtr_->evaluate(); + + const scalarField s(scalePtr_->value(this->db().time().timeOutputValue())); + + // Note: setting this field value using = operator (not ==) + Field::operator=(s*refValuePtr_()); + + fixedValueFvPatchField::updateCoeffs(); +} + + +template +void Foam::scaledFixedValueFvPatchField::write(Ostream& os) const +{ + fvPatchField::write(os); + + scalePtr_->writeData(os); + + os.beginBlock("refValue"); + refValuePtr_->write(os); + os.endBlock(); +} + + +template +void Foam::scaledFixedValueFvPatchField::operator== +( + const fvPatchField& ptf +) +{ + const scalarField s(scalePtr_->value(this->db().time().timeOutputValue())); + + forAll(s, facei) + { + const scalar si = s[facei]; + if (mag(si) > ROOTVSMALL) + { + refValuePtr_->operator[](facei) = ptf[facei]/si; + } + } + + Field::operator=(ptf); +} + + +template +void Foam::scaledFixedValueFvPatchField::operator==(const Field& tf) +{ + const scalarField s(scalePtr_->value(this->db().time().timeOutputValue())); + + forAll(s, facei) + { + const scalar si = s[facei]; + if (mag(si) > ROOTVSMALL) + { + refValuePtr_->operator[](facei) = tf[facei]/si; + } + } + + Field::operator=(tf); +} + + +template +void Foam::scaledFixedValueFvPatchField::operator==(const Type& t) +{ + const scalarField s(scalePtr_->value(this->db().time().timeOutputValue())); + + forAll(s, facei) + { + const scalar si = s[facei]; + if (mag(si) > ROOTVSMALL) + { + refValuePtr_->operator[](facei) = t/si; + } + } + + Field::operator=(t); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.H new file mode 100644 index 0000000000..22ca542143 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchField.H @@ -0,0 +1,221 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenCFD Ltd. +------------------------------------------------------------------------------- +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::scaledFixedValueFvPatchField + + +Description + This condition applies a scalar multiplier to the value of another + boundary condition. + +Usage + \table + Property | Description | Required | Default value + scale | Time varing scale | yes | + patch | patchField providing the raw patch value | yes | + \endtable + + Example of the boundary condition specification to scale a reference + velocity of (15 0 0) supplied as a fixedValue by a table of values + that ramps the scale from 0 to 1 over 1 second: + \verbatim + + { + type scaledFixedValue; + + scale table + ( + ( 0 0) + ( 1.0 1.0) + (100.0 1.0) + ); + + patch + { + type fixedValue; + value uniform (15 0 0); + } + } + \endverbatim + +SourceFiles + scaledFixedValueFvPatchField.C + +SeeAlso + PatchFunction1.H + +\*---------------------------------------------------------------------------*/ + +#ifndef scaledFixedValueFvPatchField_H +#define scaledFixedValueFvPatchField_H + +#include "fixedValueFvPatchField.H" +#include "PatchFunction1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class scaledFixedValueFvPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class scaledFixedValueFvPatchField +: + public fixedValueFvPatchField +{ +protected: + + // Protected data + + //- Scalar scale factor + autoPtr> scalePtr_; + + //- Condition to supply the reference value + tmp> refValuePtr_; + + +public: + + //- Runtime type information + TypeName("scaledFixedValue"); + + + // Constructors + + //- Construct from patch and internal field + scaledFixedValueFvPatchField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + scaledFixedValueFvPatchField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given a scaledFixedValueFvPatchField onto + //- a new patch + scaledFixedValueFvPatchField + ( + const scaledFixedValueFvPatchField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + scaledFixedValueFvPatchField(const scaledFixedValueFvPatchField&); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new scaledFixedValueFvPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + scaledFixedValueFvPatchField + ( + const scaledFixedValueFvPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new scaledFixedValueFvPatchField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Return the reference value condition + const fvPatchField& refValue() const + { + return refValuePtr_(); + } + + + // Mapping functions + + //- Map (and resize as needed) from self given a mapping object + virtual void autoMap(const fvPatchFieldMapper& m); + + //- Reverse map the given fvPatchField onto this fvPatchField + virtual void rmap + ( + const fvPatchField& ptf, + const labelList& addr + ); + + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; + + + // Force an assignment irrespective of form of patch + + virtual void operator==(const fvPatchField& ptf); + virtual void operator==(const Field& tf); + virtual void operator==(const Type& t); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "scaledFixedValueFvPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.C new file mode 100644 index 0000000000..5b51fd48b1 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.C @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 "scaledFixedValueFvPatchFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +makePatchFields(scaledFixedValue); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.H new file mode 100644 index 0000000000..b1a2a68bdc --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFields.H @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 scaledFvPatchFields_H +#define scaledFvPatchFields_H + +#include "scaledFixedValueFvPatchField.H" +#include "fieldTypes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makePatchTypeFieldTypedefs(scaledFixedValue); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFieldsFwd.H new file mode 100644 index 0000000000..19b92a34fa --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/scaledFixedValue/scaledFixedValueFvPatchFieldsFwd.H @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 scaledFvPatchFieldsFwd_H +#define scaledFvPatchFieldsFwd_H + +#include "fieldTypes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template class scaledFixedValueFvPatchField; + +makePatchTypeFieldTypedefs(scaledFixedValue); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //