ENH: add finiteArea outletInlet patch type

STYLE: use readValueEntry and Field assign to simplify code
This commit is contained in:
Mark Olesen 2023-03-03 18:12:29 +01:00
parent 2ef89bf9d3
commit 94df19a93a
12 changed files with 483 additions and 69 deletions

View File

@ -62,6 +62,7 @@ $(constraintFaPatchFields)/symmetry/symmetryFaPatchFields.C
derivedFaPatchFields = $(faPatchFields)/derived
$(derivedFaPatchFields)/fixedValueOutflow/fixedValueOutflowFaPatchFields.C
$(derivedFaPatchFields)/inletOutlet/inletOutletFaPatchFields.C
$(derivedFaPatchFields)/outletInlet/outletInletFaPatchFields.C
$(derivedFaPatchFields)/slip/slipFaPatchFields.C
$(derivedFaPatchFields)/edgeNormalFixedValue/edgeNormalFixedValueFaPatchVectorField.C
$(derivedFaPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchFields.C

View File

@ -40,8 +40,8 @@ Foam::inletOutletFaPatchField<Type>::inletOutletFaPatchField
mixedFaPatchField<Type>(p, iF),
phiName_("phi")
{
this->refValue() = pTraits<Type>::zero;
this->refGrad() = pTraits<Type>::zero;
this->refValue() = Zero;
this->refGrad() = Zero;
this->valueFraction() = 0.0;
}
@ -71,21 +71,16 @@ Foam::inletOutletFaPatchField<Type>::inletOutletFaPatchField
mixedFaPatchField<Type>(p, iF),
phiName_(dict.getOrDefault<word>("phi", "phi"))
{
this->refValue() = Field<Type>("inletValue", dict, p.size());
faPatchFieldBase::readDict(dict);
if (dict.found("value"))
{
faPatchField<Type>::operator=
(
Field<Type>("value", dict, p.size())
);
}
else
this->refValue().assign("inletValue", dict, p.size());
if (!this->readValueEntry(dict))
{
faPatchField<Type>::operator=(this->refValue());
}
this->refGrad() = pTraits<Type>::zero;
this->refGrad() = Zero;
this->valueFraction() = 0.0;
}

View File

@ -27,19 +27,52 @@ License
Class
Foam::inletOutletFaPatchField
Description
Group
grpOutletBoundaryConditions
Author
Zeljko Tukovic, FMENA
Hrvoje Jasak, Wikki Ltd.
Description
This boundary condition provides a generic outflow condition, with
specified inflow for the case of return flow.
Usage
\table
Property | Description | Required | Default value
phi | Flux field name | no | phi
inletValue | Inlet value for reverse flow | yes |
\endtable
Example of the boundary condition specification:
\verbatim
<patchName>
{
type inletOutlet;
phi phi;
inletValue uniform 0;
value uniform 0;
}
\endverbatim
The mode of operation is determined by the sign of the flux across the
patch edges.
Note
Sign conventions:
- Positive flux (out of domain): apply zero-gradient condition
- Negative flux (into domain): apply the "inletValue" fixed-value
See also
Foam::mixedFaPatchField
Foam::zeroGradientFaPatchField
Foam::outletInletFaPatchField
SourceFiles
inletOutletFaPatchField.C
\*---------------------------------------------------------------------------*/
#ifndef inletOutletFaPatchField_H
#define inletOutletFaPatchField_H
#ifndef Foam_inletOutletFaPatchField_H
#define Foam_inletOutletFaPatchField_H
#include "mixedFaPatchField.H"
@ -57,11 +90,11 @@ class inletOutletFaPatchField
:
public mixedFaPatchField<Type>
{
protected:
// Protected data
// Protected Data
//- Name of flux field
word phiName_;
@ -136,22 +169,7 @@ public:
virtual ~inletOutletFaPatchField() = default;
// Member functions
// Access
//- Return the name of phi
const word& phiName() const
{
return phiName_;
}
//- Return reference to the name of phi to allow adjustment
word& phiName()
{
return phiName_;
}
// Member Functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();

View File

@ -30,17 +30,11 @@ License
#include "inletOutletFaPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeFaPatchFields(inletOutlet);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
makeFaPatchFields(inletOutlet);
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 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 "outletInletFaPatchField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::outletInletFaPatchField<Type>::outletInletFaPatchField
(
const faPatch& p,
const DimensionedField<Type, areaMesh>& iF
)
:
mixedFaPatchField<Type>(p, iF),
phiName_("phi")
{
this->refValue() = *this;
this->refGrad() = Zero;
this->valueFraction() = 0.0;
}
template<class Type>
Foam::outletInletFaPatchField<Type>::outletInletFaPatchField
(
const outletInletFaPatchField<Type>& ptf,
const faPatch& p,
const DimensionedField<Type, areaMesh>& iF,
const faPatchFieldMapper& mapper
)
:
mixedFaPatchField<Type>(ptf, p, iF, mapper),
phiName_(ptf.phiName_)
{}
template<class Type>
Foam::outletInletFaPatchField<Type>::outletInletFaPatchField
(
const faPatch& p,
const DimensionedField<Type, areaMesh>& iF,
const dictionary& dict
)
:
mixedFaPatchField<Type>(p, iF),
phiName_(dict.getOrDefault<word>("phi", "phi"))
{
faPatchFieldBase::readDict(dict);
this->refValue().assign("outletValue", dict, p.size());
if (!this->readValueEntry(dict))
{
faPatchField<Type>::operator=(this->refValue());
}
this->refGrad() = Zero;
this->valueFraction() = 0.0;
}
template<class Type>
Foam::outletInletFaPatchField<Type>::outletInletFaPatchField
(
const outletInletFaPatchField<Type>& ptf
)
:
mixedFaPatchField<Type>(ptf),
phiName_(ptf.phiName_)
{}
template<class Type>
Foam::outletInletFaPatchField<Type>::outletInletFaPatchField
(
const outletInletFaPatchField<Type>& ptf,
const DimensionedField<Type, areaMesh>& iF
)
:
mixedFaPatchField<Type>(ptf, iF),
phiName_(ptf.phiName_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::outletInletFaPatchField<Type>::updateCoeffs()
{
if (this->updated())
{
return;
}
const Field<scalar>& phip =
this->patch().template lookupPatchField<edgeScalarField>(phiName_);
this->valueFraction() = pos0(phip);
mixedFaPatchField<Type>::updateCoeffs();
}
template<class Type>
void Foam::outletInletFaPatchField<Type>::write(Ostream& os) const
{
faPatchField<Type>::write(os);
os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
this->refValue().writeEntry("outletValue", os);
faPatchField<Type>::writeValueEntry(os);
}
// ************************************************************************* //

View File

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 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::outletInletFaPatchField
Group
grpInletBoundaryConditions
Description
This boundary condition provides a generic inflow condition, with
specified outflow for the case of reverse flow.
Usage
\table
Property | Description | Required | Default value
phi | Flux field name | no | phi
outletValue | Outlet value for reverse flow | yes |
\endtable
Example of the boundary condition specification:
\verbatim
<patchName>
{
type outletInlet;
phi phi;
outletValue uniform 0;
value uniform 0;
}
\endverbatim
The mode of operation is determined by the sign of the flux across the
patch edges.
Note
Sign conventions:
- Positive flux (out of domain): apply the "outletValue" fixed-value
- Negative flux (into domain): apply zero-gradient condition
See also
Foam::mixedFaPatchField
Foam::zeroGradientFaPatchField
Foam::inletOutletFaPatchField
SourceFiles
outletInletFaPatchField.C
\*---------------------------------------------------------------------------*/
#ifndef Foam_outletInletFaPatchField_H
#define Foam_outletInletFaPatchField_H
#include "mixedFaPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class outletInletFaPatch Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class outletInletFaPatchField
:
public mixedFaPatchField<Type>
{
protected:
// Protected Data
//- Name of flux field
word phiName_;
public:
//- Runtime type information
TypeName("outletInlet");
// Constructors
//- Construct from patch and internal field
outletInletFaPatchField
(
const faPatch&,
const DimensionedField<Type, areaMesh>&
);
//- Construct from patch, internal field and dictionary
outletInletFaPatchField
(
const faPatch&,
const DimensionedField<Type, areaMesh>&,
const dictionary&
);
//- Construct by mapping given outletInletFaPatchField onto a new patch
outletInletFaPatchField
(
const outletInletFaPatchField<Type>&,
const faPatch&,
const DimensionedField<Type, areaMesh>&,
const faPatchFieldMapper&
);
//- Construct as copy
outletInletFaPatchField
(
const outletInletFaPatchField<Type>&
);
//- Construct and return a clone
virtual tmp<faPatchField<Type>> clone() const
{
return tmp<faPatchField<Type>>
(
new outletInletFaPatchField<Type>(*this)
);
}
//- Construct as copy setting internal field reference
outletInletFaPatchField
(
const outletInletFaPatchField<Type>&,
const DimensionedField<Type, areaMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<faPatchField<Type>> clone
(
const DimensionedField<Type, areaMesh>& iF
) const
{
return tmp<faPatchField<Type>>
(
new outletInletFaPatchField<Type>(*this, iF)
);
}
// Member Functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "outletInletFaPatchField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 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 "areaFields.H"
#include "edgeFields.H"
#include "outletInletFaPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeFaPatchFields(outletInlet);
}
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 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 Foam_outletInletFaPatchFields_H
#define Foam_outletInletFaPatchFields_H
#include "outletInletFaPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makeFaPatchTypeFieldTypedefs(outletInlet);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -73,16 +73,9 @@ Foam::inletOutletFvPatchField<Type>::inletOutletFvPatchField
{
fvPatchFieldBase::readDict(dict);
this->refValue() = Field<Type>("inletValue", dict, p.size());
this->refValue().assign("inletValue", dict, p.size());
if (dict.found("value"))
{
fvPatchField<Type>::operator=
(
Field<Type>("value", dict, p.size())
);
}
else
if (!this->readValueEntry(dict))
{
fvPatchField<Type>::operator=(this->refValue());
}

View File

@ -57,7 +57,7 @@ Usage
Note
Sign conventions:
- Positive flux (out of domain): apply zero-gradient condition
- Negative flux (into of domain): apply the "inletValue" fixed-value
- Negative flux (into domain): apply the "inletValue" fixed-value
See also
Foam::mixedFvPatchField
@ -69,8 +69,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef inletOutletFvPatchField_H
#define inletOutletFvPatchField_H
#ifndef Foam_inletOutletFvPatchField_H
#define Foam_inletOutletFvPatchField_H
#include "mixedFvPatchField.H"

View File

@ -73,16 +73,9 @@ Foam::outletInletFvPatchField<Type>::outletInletFvPatchField
{
fvPatchFieldBase::readDict(dict);
this->refValue() = Field<Type>("outletValue", dict, p.size());
this->refValue().assign("outletValue", dict, p.size());
if (dict.found("value"))
{
fvPatchField<Type>::operator=
(
Field<Type>("value", dict, p.size())
);
}
else
if (!this->readValueEntry(dict))
{
fvPatchField<Type>::operator=(this->refValue());
}

View File

@ -57,7 +57,7 @@ Usage
Note
Sign conventions:
- Positive flux (out of domain): apply the "outletValue" fixed-value
- Negative flux (into of domain): apply zero-gradient condition
- Negative flux (into domain): apply zero-gradient condition
See also
Foam::mixedFvPatchField
@ -69,8 +69,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef outletInletFvPatchField_H
#define outletInletFvPatchField_H
#ifndef Foam_outletInletFvPatchField_H
#define Foam_outletInletFvPatchField_H
#include "mixedFvPatchField.H"