Commit 8d7b8043 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add time ramping to surfaceNormalFixedValue (#1407)

- alternatively can use uniformNormalFixedValue with PatchFunction1
  specification and temporal ramping.

TUT: add ramped example for simpleCar
parent de487f0f
......@@ -209,6 +209,7 @@ $(derivedFvPatchFields)/uniformFixedValue/uniformFixedValueFvPatchFields.C
$(derivedFvPatchFields)/uniformInletOutlet/uniformInletOutletFvPatchFields.C
$(derivedFvPatchFields)/uniformJump/uniformJumpFvPatchFields.C
$(derivedFvPatchFields)/uniformJumpAMI/uniformJumpAMIFvPatchFields.C
$(derivedFvPatchFields)/uniformNormalFixedValue/uniformNormalFixedValueFvPatchVectorField.C
$(derivedFvPatchFields)/uniformTotalPressure/uniformTotalPressureFvPatchScalarField.C
$(derivedFvPatchFields)/variableHeightFlowRate/variableHeightFlowRateFvPatchField.C
$(derivedFvPatchFields)/variableHeightFlowRateInletVelocity/variableHeightFlowRateInletVelocityFvPatchVectorField.C
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -40,7 +40,8 @@ surfaceNormalFixedValueFvPatchVectorField
)
:
fixedValueFvPatchVectorField(p, iF),
refValue_(p.size())
refValue_(p.size()),
ramp_(nullptr)
{}
......@@ -53,9 +54,22 @@ surfaceNormalFixedValueFvPatchVectorField
)
:
fixedValueFvPatchVectorField(p, iF, dict, false),
refValue_("refValue", dict, p.size())
refValue_("refValue", dict, p.size()),
ramp_(nullptr)
{
fvPatchVectorField::operator=(refValue_*patch().nf());
if (dict.found("ramp"))
{
ramp_ = Function1<scalar>::New("ramp", dict);
}
tmp<vectorField> tvalues(refValue_*patch().nf());
if (ramp_)
{
tvalues.ref() *= ramp_->value(this->db().time().timeOutputValue());
}
fvPatchVectorField::operator=(tvalues);
}
......@@ -69,36 +83,47 @@ surfaceNormalFixedValueFvPatchVectorField
)
:
fixedValueFvPatchVectorField(p, iF),
refValue_(ptf.refValue_, mapper, pTraits<scalar>::zero)
refValue_(ptf.refValue_, mapper, pTraits<scalar>::zero),
ramp_(ptf.ramp_.clone())
{
// Note: refValue_ will have default value of 0 for unmapped faces. This
// can temporarily happen during e.g. redistributePar. We should not
// access ptf.patch() instead since redistributePar has destroyed this
// at the time of mapping.
fvPatchVectorField::operator=(refValue_*patch().nf());
tmp<vectorField> tvalues(refValue_*patch().nf());
if (ramp_)
{
tvalues.ref() *= ramp_->value(this->db().time().timeOutputValue());
}
fvPatchVectorField::operator=(tvalues);
}
Foam::surfaceNormalFixedValueFvPatchVectorField::
surfaceNormalFixedValueFvPatchVectorField
(
const surfaceNormalFixedValueFvPatchVectorField& pivpvf
const surfaceNormalFixedValueFvPatchVectorField& ptf
)
:
fixedValueFvPatchVectorField(pivpvf),
refValue_(pivpvf.refValue_)
fixedValueFvPatchVectorField(ptf),
refValue_(ptf.refValue_),
ramp_(ptf.ramp_.clone())
{}
Foam::surfaceNormalFixedValueFvPatchVectorField::
surfaceNormalFixedValueFvPatchVectorField
(
const surfaceNormalFixedValueFvPatchVectorField& pivpvf,
const surfaceNormalFixedValueFvPatchVectorField& ptf,
const DimensionedField<vector, volMesh>& iF
)
:
fixedValueFvPatchVectorField(pivpvf, iF),
refValue_(pivpvf.refValue_)
fixedValueFvPatchVectorField(ptf, iF),
refValue_(ptf.refValue_),
ramp_(ptf.ramp_.clone())
{}
......@@ -106,11 +131,11 @@ surfaceNormalFixedValueFvPatchVectorField
void Foam::surfaceNormalFixedValueFvPatchVectorField::autoMap
(
const fvPatchFieldMapper& m
const fvPatchFieldMapper& mapper
)
{
fixedValueFvPatchVectorField::autoMap(m);
refValue_.autoMap(m);
fixedValueFvPatchVectorField::autoMap(mapper);
refValue_.autoMap(mapper);
}
......@@ -136,7 +161,14 @@ void Foam::surfaceNormalFixedValueFvPatchVectorField::updateCoeffs()
return;
}
fvPatchVectorField::operator=(refValue_*patch().nf());
tmp<vectorField> tvalues(refValue_*patch().nf());
if (ramp_)
{
tvalues.ref() *= ramp_->value(this->db().time().timeOutputValue());
}
fvPatchVectorField::operator=(tvalues);
fvPatchVectorField::updateCoeffs();
}
......@@ -145,6 +177,10 @@ void Foam::surfaceNormalFixedValueFvPatchVectorField::write(Ostream& os) const
{
fvPatchVectorField::write(os);
refValue_.writeEntry("refValue", os);
if (ramp_)
{
ramp_->writeData(os);
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -35,8 +35,9 @@ Description
Usage
\table
Property | Description | Required | Default value
refValue | reference value | yes |
Property | Description | Required | Default
refValue | reference value | yes |
ramp | time-based ramping | no |
\endtable
Example of the boundary condition specification:
......@@ -65,6 +66,7 @@ SourceFiles
#include "fvPatchFields.H"
#include "fixedValueFvPatchFields.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -79,10 +81,13 @@ class surfaceNormalFixedValueFvPatchVectorField
:
public fixedValueFvPatchVectorField
{
// Private data
// Private Data
scalarField refValue_;
//- Optional time ramping
autoPtr<Function1<scalar>> ramp_;
public:
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "uniformNormalFixedValueFvPatchVectorField.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
#include "fvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::uniformNormalFixedValueFvPatchVectorField::
uniformNormalFixedValueFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF
)
:
fixedValueFvPatchVectorField(p, iF),
uniformValue_(nullptr),
ramp_(nullptr)
{}
Foam::uniformNormalFixedValueFvPatchVectorField::
uniformNormalFixedValueFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchVectorField(p, iF, dict, false),
uniformValue_(PatchFunction1<scalar>::New(p.patch(), "uniformValue", dict)),
ramp_(nullptr)
{
if (dict.found("ramp"))
{
ramp_ = Function1<scalar>::New("ramp", dict);
}
if (dict.found("value"))
{
fvPatchVectorField::operator=
(
vectorField("value", dict, p.size())
);
}
else
{
this->evaluate();
}
}
Foam::uniformNormalFixedValueFvPatchVectorField::
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField& ptf,
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchVectorField(p, iF), // Don't map
uniformValue_(ptf.uniformValue_.clone(p.patch())),
ramp_(ptf.ramp_.clone())
{
if (mapper.direct() && !mapper.hasUnmapped())
{
// Use mapping instead of re-evaluation
this->map(ptf, mapper);
}
else
{
// Evaluate since value not mapped
this->evaluate();
}
}
Foam::uniformNormalFixedValueFvPatchVectorField::
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField& ptf
)
:
fixedValueFvPatchVectorField(ptf),
uniformValue_(ptf.uniformValue_.clone(this->patch().patch())),
ramp_(ptf.ramp_.clone())
{}
Foam::uniformNormalFixedValueFvPatchVectorField::
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField& ptf,
const DimensionedField<vector, volMesh>& iF
)
:
fixedValueFvPatchVectorField(ptf, iF),
uniformValue_(ptf.uniformValue_.clone(this->patch().patch())),
ramp_(ptf.ramp_.clone())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::uniformNormalFixedValueFvPatchVectorField::autoMap
(
const fvPatchFieldMapper& mapper
)
{
fixedValueFvPatchVectorField::autoMap(mapper);
uniformValue_().autoMap(mapper);
if (uniformValue_().constant())
{
// If mapper is not dependent on time we're ok to evaluate
this->evaluate();
}
}
void Foam::uniformNormalFixedValueFvPatchVectorField::rmap
(
const fvPatchVectorField& ptf,
const labelList& addr
)
{
fixedValueFvPatchVectorField::rmap(ptf, addr);
const uniformNormalFixedValueFvPatchVectorField& tiptf =
refCast<const uniformNormalFixedValueFvPatchVectorField>(ptf);
uniformValue_().rmap(tiptf.uniformValue_(), addr);
}
void Foam::uniformNormalFixedValueFvPatchVectorField::updateCoeffs()
{
if (updated())
{
return;
}
const scalar t = this->db().time().timeOutputValue();
tmp<vectorField> tvalues(uniformValue_->value(t)*patch().nf());
if (ramp_)
{
tvalues.ref() *= ramp_->value(t);
}
fvPatchVectorField::operator=(tvalues);
fvPatchVectorField::updateCoeffs();
}
void Foam::uniformNormalFixedValueFvPatchVectorField::write(Ostream& os) const
{
fvPatchVectorField::write(os);
uniformValue_->writeData(os);
if (ramp_)
{
ramp_->writeData(os);
}
this->writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchVectorField,
uniformNormalFixedValueFvPatchVectorField
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
Class
Foam::uniformNormalFixedValueFvPatchVectorField
Group
grpGenericBoundaryConditions grpInletBoundaryConditions
Description
This boundary condition provides a uniform surface-normal
vector boundary condition by its magnitude.
Usage
\table
Property | Description | Required | Default
uniformValue | uniform value | yes |
ramp | time-based ramping | no |
\endtable
Example of the boundary condition specification:
\verbatim
<patchName>
{
type uniformNormalFixedValue;
uniformValue constant -10; // 10 INTO the domain
}
\endverbatim
Note
Sign conventions:
- the value is positive for outward-pointing vectors
See also
Foam::Function1Types
Foam::fixedValueFvPatchField
Foam::surfaceNormalFixedValueFvPatchVectorField
Foam::uniformFixedValueFvPatchVectorField
SourceFiles
uniformNormalFixedValueFvPatchVectorField.C
\*---------------------------------------------------------------------------*/
#ifndef uniformNormalFixedValueFvPatchVectorField_H
#define uniformNormalFixedValueFvPatchVectorField_H
#include "fvPatchFields.H"
#include "fixedValueFvPatchFields.H"
#include "PatchFunction1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class uniformNormalFixedValueFvPatchVectorField Declaration
\*---------------------------------------------------------------------------*/
class uniformNormalFixedValueFvPatchVectorField
:
public fixedValueFvPatchVectorField
{
// Private Data
autoPtr<PatchFunction1<scalar>> uniformValue_;
//- Optional time ramping
autoPtr<Function1<scalar>> ramp_;
public:
//- Runtime type information
TypeName("uniformNormalFixedValue");
// Constructors
//- Construct from patch and internal field
uniformNormalFixedValueFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&
);
//- Construct from patch, internal field and dictionary
uniformNormalFixedValueFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// uniformNormalFixedValueFvPatchVectorField
// onto a new patch
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField&,
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField&
);
//- Construct and return a clone
virtual tmp<fvPatchVectorField> clone() const
{
return tmp<fvPatchVectorField>
(
new uniformNormalFixedValueFvPatchVectorField(*this)
);
}
//- Construct as copy setting internal field reference
uniformNormalFixedValueFvPatchVectorField
(
const uniformNormalFixedValueFvPatchVectorField&,
const DimensionedField<vector, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchVectorField> clone
(
const DimensionedField<vector, volMesh>& iF
) const
{
return tmp<fvPatchVectorField>
(
new uniformNormalFixedValueFvPatchVectorField
(
*this,
iF
)
);
}
// Member Functions