Commit 73b9f50b authored by andy's avatar andy
Browse files

ENH: Added new externalCoupledTemperature BC

parent 126c6fa4
......@@ -10,4 +10,6 @@ derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRad
derivedFvPatchFields/externalWallHeatFluxTemperature/externalWallHeatFluxTemperatureFvPatchScalarField.C
derivedFvPatchFields/wallHeatTransfer/wallHeatTransferFvPatchScalarField.C
derivedFvPatchFields/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
LIB = $(FOAM_LIBBIN)/libcompressibleTurbulenceModel
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "externalCoupledTemperatureMixedFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "OFstream.H"
#include "turbulenceModel.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeHeader
(
OFstream& os
) const
{
os << "# Values: magSf value qDot htc" << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
externalCoupledMixedFvPatchField<scalar>(p, iF)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
externalCoupledMixedFvPatchField<scalar>(ptf, p, iF, mapper)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
externalCoupledMixedFvPatchField<scalar>(p, iF, dict)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf
)
:
externalCoupledMixedFvPatchField<scalar>(ecmpf)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf,
const DimensionedField<scalar, volMesh>& iF
)
:
externalCoupledMixedFvPatchField<scalar>(ecmpf, iF)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
~externalCoupledTemperatureMixedFvPatchScalarField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::transferData
(
OFstream& os
) const
{
if (log())
{
Info<< type() << ": writing data to " << os.name() << endl;
}
const label patchI = patch().index();
// heat flux [W/m2]
scalarField qDot(this->patch().size(), 0.0);
typedef compressible::turbulenceModel cmpTurbModelType;
static word turbName("turbulenceModel");
static word thermoName("thermophysicalProperties");
if (db().foundObject<cmpTurbModelType>(turbName))
{
const cmpTurbModelType& turbModel =
db().lookupObject<cmpTurbModelType>(turbName);
const basicThermo& thermo = turbModel.thermo();
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchI];
qDot = turbModel.alphaEff(patchI)*hep.snGrad();
}
else if (db().foundObject<basicThermo>(thermoName))
{
const basicThermo& thermo = db().lookupObject<basicThermo>(thermoName);
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchI];
qDot = thermo.alpha().boundaryField()[patchI]*hep.snGrad();
}
else
{
FatalErrorIn
(
"void Foam::externalCoupledTemperatureMixedFvPatchScalarField::"
"writeData"
"("
"const fileName& transferFile"
") const"
) << "Condition requires either compressibke turbulence and/or "
<< "thermo model to be available" << exit(FatalError);
}
// patch temperature [K]
const scalarField Tp(*this);
// near wall cell temperature [K]
const scalarField Tc(patchInternalField());
// heat transfer coefficient [W/m2/K]
const scalarField htc(qDot/(Tp - Tc + ROOTVSMALL));
if (Pstream::parRun())
{
int tag = Pstream::msgType() + 1;
List<Field<scalar> > magSfs(Pstream::nProcs());
magSfs[Pstream::myProcNo()].setSize(this->patch().size());
magSfs[Pstream::myProcNo()] = this->patch().magSf();
Pstream::gatherList(magSfs, tag);
List<Field<scalar> > values(Pstream::nProcs());
values[Pstream::myProcNo()].setSize(this->patch().size());
values[Pstream::myProcNo()] = Tp;
Pstream::gatherList(values, tag);
List<Field<scalar> > qDots(Pstream::nProcs());
qDots[Pstream::myProcNo()].setSize(this->patch().size());
qDots[Pstream::myProcNo()] = qDot;
Pstream::gatherList(qDots, tag);
List<Field<scalar> > htcs(Pstream::nProcs());
htcs[Pstream::myProcNo()].setSize(this->patch().size());
htcs[Pstream::myProcNo()] = htc;
Pstream::gatherList(htcs, tag);
if (Pstream::master())
{
forAll(values, procI)
{
const Field<scalar>& magSf = magSfs[procI];
const Field<scalar>& value = values[procI];
const Field& qDot = qDots[procI];
const Field& htc = htcs[procI];
forAll(magSf, faceI)
{
os << magSf[faceI] << token::SPACE
<< value[faceI] << token::SPACE
<< qDot[faceI] << token::SPACE
<< htc[faceI] << token::SPACE
<< nl;
}
}
os.flush();
}
}
else
{
const Field<scalar>& magSf(this->patch().magSf());
forAll(patch(), faceI)
{
os << magSf[faceI] << token::SPACE
<< Tp[faceI] << token::SPACE
<< qDot[faceI] << token::SPACE
<< htc[faceI] << token::SPACE
<< nl;
}
os.flush();
}
}
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::updateCoeffs()
{
externalCoupledMixedFvPatchField<scalar>::updateCoeffs();
}
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::write
(
Ostream& os
) const
{
externalCoupledMixedFvPatchField<scalar>::write(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
externalCoupledTemperatureMixedFvPatchScalarField
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
Class
Foam::externalCoupledTemperatureMixedFvPatchScalarField
Group
grpCoupledBoundaryConditions
Description
This boundary condition provides a temperatue interface to an external
application. Values are transferred as plain text files, where OperFOAM
data is written as:
<value1> <surfaceNormalGradient1>
<value2> <surfaceNormalGradient2>
<value3> <surfaceNormalGradient3>
...
<valueN> <surfaceNormalGradientN>
and received as the constituent pieces of the `mixed' condition, i.e.
<value1> <gradient1> <valueFracion1>
<value2> <gradient2> <valueFracion2>
<value3> <gradient3> <valueFracion3>
...
<valueN> <gradientN> <valueFracionN>
At start-up, the boundary creates a lock file, e.g.
$FOAM_CASE/comms/patchName/OpenFOAM.lock
... to signal the external source to wait. During the boundary condition
update, boundary values are written to file, e.g.
$FOAM_CASE/comms/patchName/data.out
The lock file is then removed, instructing the external source to take
control of the program execution. When ready, the external program
should create the return values, e.g. to file
$FOAM_CASE/comms/patchName/data.in
... and then re-instate the lock file. The boundary condition will then
read the return values, and pass program execution back to OpenFOAM.
\heading Patch usage
\table
Property | Description | Required | Default value
commsDir | communications folder | yes |
fileName | transfer file name | yes |
collate | collate all patch data into single file | yes |
waitInterval | interval [s] between file checks | no | 1
timeOut | time after which error invoked [s] |no |100*waitInterval
calcFrequency | calculation frequency | no | 1
log | log program control | no | no
\endtable
Example of the boundary condition specification:
\verbatim
myPatch
{
type externalCoupledTemperature;
commsDir "$FOAM_CASE/comms";
fileName data;
collate yes;
calcFrequency 1;
}
\endverbatim
SeeAlso
mixedFvPatchField
externalCoupledMixedFvPatchField
SourceFiles
externalCoupledTemperatureMixedFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#ifndef externalCoupledTemperatureMixedFvPatchScalarField_H
#define externalCoupledTemperatureMixedFvPatchScalarField_H
#include "externalCoupledMixedFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class IFstream;
/*---------------------------------------------------------------------------*\
Class externalCoupledTemperatureMixedFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class externalCoupledTemperatureMixedFvPatchScalarField
:
public externalCoupledMixedFvPatchField<scalar>
{
protected:
// Protected Member Functions
//- Write header to transfer file
virtual void writeHeader(OFstream& os) const;
public:
//- Runtime type information
TypeName("externalCoupledTemperature");
// Constructors
//- Construct from patch and internal field
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// externalCoupledTemperatureMixedFvPatchScalarField onto a new patch
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchField<scalar> > clone() const
{
return tmp<fvPatchField<scalar> >
(
new externalCoupledTemperatureMixedFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<scalar> > clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchField<scalar> >
(
new externalCoupledTemperatureMixedFvPatchScalarField
(
*this,
iF
)
);
}
//- Destructor
virtual ~externalCoupledTemperatureMixedFvPatchScalarField();
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Transfer data for external source
virtual void transferData(OFstream& os) const;
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment