Commit 07ff2a28 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Added new scalarFixedValue boundary condition

This condition applies a scalar multiplier to the value of another
boundary condition.

Usage
    Property     | Description             | Required    | Default value
    scale        | Time varing scale       | yes         |
    patch        | patchField providing the raw patch value | yes |

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:

    <patchName>
    {
        type            scaledFixedValue;

        scale table
        (
            (    0   0)
            (  1.0 1.0)
            (100.0 1.0)
        );

        patch
        {
            type            fixedValue;
            value           uniform (15 0 0);
        }
    }
parent 5d7d24df
......@@ -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
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "scaledFixedValueFvPatchField.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::scaledFixedValueFvPatchField<Type>::scaledFixedValueFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
fixedValueFvPatchField<Type>(p, iF),
scalePtr_(),
refValuePtr_(fvPatchField<Type>::New("refValue", p, iF))
{}
template<class Type>
Foam::scaledFixedValueFvPatchField<Type>::scaledFixedValueFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchField<Type>(p, iF, dict, false),
scalePtr_(PatchFunction1<scalar>::New(p.patch(), "scale", dict)),
refValuePtr_(fvPatchField<Type>::New(p, iF, dict.subDict("refValue")))
{
if (!isA<fixedValueFvPatchField<Type>>(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<class Type>
Foam::scaledFixedValueFvPatchField<Type>::scaledFixedValueFvPatchField
(
const scaledFixedValueFvPatchField& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
scalePtr_(ptf.scalePtr_.clone(p.patch())),
refValuePtr_(fvPatchField<Type>::New(ptf.refValue(), p, iF, mapper))
{}
template<class Type>
Foam::scaledFixedValueFvPatchField<Type>::scaledFixedValueFvPatchField
(
const scaledFixedValueFvPatchField& spf
)
:
fixedValueFvPatchField<Type>(spf),
scalePtr_(spf.scalePtr_.clone(spf.patch().patch())),
refValuePtr_(spf.refValue().clone())
{}
template<class Type>
Foam::scaledFixedValueFvPatchField<Type>::scaledFixedValueFvPatchField
(
const scaledFixedValueFvPatchField& spf,
const DimensionedField<Type, volMesh>& iF
)
:
fixedValueFvPatchField<Type>(spf, iF),
scalePtr_(spf.scalePtr_.clone(spf.patch().patch())),
refValuePtr_(spf.refValue().clone())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::autoMap
(
const fvPatchFieldMapper& m
)
{
fixedValueFvPatchField<Type>::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<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::rmap
(
const fvPatchField<Type>& ptf,
const labelList& addr
)
{
fixedValueFvPatchField<Type>::rmap(ptf, addr);
const scaledFixedValueFvPatchField& sptf =
refCast<const scaledFixedValueFvPatchField>(ptf);
refValuePtr_->rmap(sptf.refValue(), addr);
scalePtr_().rmap(sptf.scalePtr_(), addr);
}
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::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<Type>::operator=(s*refValuePtr_());
fixedValueFvPatchField<Type>::updateCoeffs();
}
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::write(Ostream& os) const
{
fvPatchField<Type>::write(os);
scalePtr_->writeData(os);
os.beginBlock("refValue");
refValuePtr_->write(os);
os.endBlock();
}
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::operator==
(
const fvPatchField<Type>& 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<Type>::operator=(ptf);
}
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::operator==(const Field<Type>& 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<Type>::operator=(tf);
}
template<class Type>
void Foam::scaledFixedValueFvPatchField<Type>::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<Type>::operator=(t);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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
<patchName>
{
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 Type>
class scaledFixedValueFvPatchField
:
public fixedValueFvPatchField<Type>
{
protected:
// Protected data
//- Scalar scale factor
autoPtr<PatchFunction1<scalar>> scalePtr_;
//- Condition to supply the reference value
tmp<fvPatchField<Type>> refValuePtr_;
public:
//- Runtime type information
TypeName("scaledFixedValue");
// Constructors
//- Construct from patch and internal field
scaledFixedValueFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&
);
//- Construct from patch, internal field and dictionary
scaledFixedValueFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const dictionary&
);
//- Construct by mapping given a scaledFixedValueFvPatchField onto
//- a new patch
scaledFixedValueFvPatchField
(
const scaledFixedValueFvPatchField&,
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
scaledFixedValueFvPatchField(const scaledFixedValueFvPatchField&);
//- Construct and return a clone
virtual tmp<fvPatchField<Type>> clone() const
{
return tmp<fvPatchField<Type>>
(
new scaledFixedValueFvPatchField(*this)
);
}
//- Construct as copy setting internal field reference
scaledFixedValueFvPatchField
(
const scaledFixedValueFvPatchField&,
const DimensionedField<Type, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<Type>> clone
(
const DimensionedField<Type, volMesh>& iF
) const
{
return tmp<fvPatchField<Type>>
(
new scaledFixedValueFvPatchField(*this, iF)
);
}
// Member functions
// Access
//- Return the reference value condition
const fvPatchField<Type>& 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<Type>& 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<Type>& ptf);
virtual void operator==(const Field<Type>& tf);
virtual void operator==(const Type& t);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "scaledFixedValueFvPatchField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "scaledFixedValueFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFields(scaledFixedValue);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#ifndef scaledFvPatchFields_H
#define scaledFvPatchFields_H
#include "scaledFixedValueFvPatchField.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeFieldTypedefs(scaledFixedValue);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com