View Issue Details

IDProjectCategoryView StatusLast Update
0001440OpenFOAMBugpublic2014-11-13 14:35
Reporterfabian_roesler Assigned Touser4 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinuxOSCentOSOS Version6.5
Summary0001440: major bug in turbulentTemperatureRadCoupledMixedFvPatchScalarField
DescriptionI found two bugs in turbulentTemperatureRadCoupledMixedFvPatchScalarField.C:

The first is a major bug concerning the calculation of the contact resistance when defining thickness and kappa layers. When defining two or more layers - some with large conductivity and some with small conductivity - the resulting total thermal transmissivity is wrong. the kappa values are just summed instead of inverting the layer kappas and inverting their sum again.
k_tot = 1/(1/k1 + 1/k2 + 1/k3 ...)

The second bug is concerning cases with more then one ami interface in one region. The vectors defining the kappaNbr value have a wrong dimension.

I attached a test case and a fixed turbulentTemperatureRadCoupledMixedFvPatchScalarField.C
Steps To ReproduceRun the test case
TagsNo tags attached.

Activities

fabian_roesler

2014-11-11 16:21

reporter  

testCase.tar.gz (9,946 bytes)

user4

2014-11-12 09:12

 

turbulentTemperatureRadCoupledMixedFvPatchScalarField.C (9,708 bytes)   
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2014 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 "turbulentTemperatureRadCoupledMixedFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "mappedPatchBase.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace compressible
{

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

turbulentTemperatureRadCoupledMixedFvPatchScalarField::
turbulentTemperatureRadCoupledMixedFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF
)
:
    mixedFvPatchScalarField(p, iF),
    temperatureCoupledBase(patch(), "undefined", "undefined", "undefined-K"),
    TnbrName_("undefined-Tnbr"),
    QrNbrName_("undefined-QrNbr"),
    QrName_("undefined-Qr"),
    thicknessLayers_(0),
    kappaLayers_(0),
    contactRes_(0)
{
    this->refValue() = 0.0;
    this->refGrad() = 0.0;
    this->valueFraction() = 1.0;
}


turbulentTemperatureRadCoupledMixedFvPatchScalarField::
turbulentTemperatureRadCoupledMixedFvPatchScalarField
(
    const turbulentTemperatureRadCoupledMixedFvPatchScalarField& psf,
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    mixedFvPatchScalarField(psf, p, iF, mapper),
    temperatureCoupledBase(patch(), psf),
    TnbrName_(psf.TnbrName_),
    QrNbrName_(psf.QrNbrName_),
    QrName_(psf.QrName_),
    thicknessLayers_(psf.thicknessLayers_),
    kappaLayers_(psf.kappaLayers_),
    contactRes_(psf.contactRes_)
{}


turbulentTemperatureRadCoupledMixedFvPatchScalarField::
turbulentTemperatureRadCoupledMixedFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    mixedFvPatchScalarField(p, iF),
    temperatureCoupledBase(patch(), dict),
    TnbrName_(dict.lookupOrDefault<word>("Tnbr", "T")),
    QrNbrName_(dict.lookupOrDefault<word>("QrNbr", "none")),
    QrName_(dict.lookupOrDefault<word>("Qr", "none")),
    thicknessLayers_(0),
    kappaLayers_(0),
    contactRes_(0.0)
{
    if (!isA<mappedPatchBase>(this->patch().patch()))
    {
        FatalErrorIn
        (
            "turbulentTemperatureRadCoupledMixedFvPatchScalarField::"
            "turbulentTemperatureRadCoupledMixedFvPatchScalarField\n"
            "(\n"
            "    const fvPatch& p,\n"
            "    const DimensionedField<scalar, volMesh>& iF,\n"
            "    const dictionary& dict\n"
            ")\n"
        )   << "\n    patch type '" << p.type()
            << "' not type '" << mappedPatchBase::typeName << "'"
            << "\n    for patch " << p.name()
            << " of field " << dimensionedInternalField().name()
            << " in file " << dimensionedInternalField().objectPath()
            << exit(FatalError);
    }

    if (dict.found("thicknessLayers"))
    {
        dict.lookup("thicknessLayers") >> thicknessLayers_;
        dict.lookup("kappaLayers") >> kappaLayers_;

        if (thicknessLayers_.size() > 0)
        {
// --- Bug Fix - total contactRes is the inverse sum of all inverse kappa/l ----
//     k_tot = 1/(1/k1 + 1/k2 + 1/k3...)
//     moreover, contactRes is missleading. It's a thermal transmittance
            forAll (thicknessLayers_, iLayer)
            {
                const scalar l = thicknessLayers_[iLayer];
                if (l > 0.0)
                {
                    contactRes_ += l/kappaLayers_[iLayer]; // inverse sum
//                  contactRes_ += kappaLayers_[iLayer]/l; // old               
                }
            }
            contactRes_ = 1.0/contactRes_; // new total inverse
// -----------------------------------------------------------------------------
        }
    }

    fvPatchScalarField::operator=(scalarField("value", dict, p.size()));

    if (dict.found("refValue"))
    {
        // Full restart
        refValue() = scalarField("refValue", dict, p.size());
        refGrad() = scalarField("refGradient", dict, p.size());
        valueFraction() = scalarField("valueFraction", dict, p.size());
    }
    else
    {
        // Start from user entered data. Assume fixedValue.
        refValue() = *this;
        refGrad() = 0.0;
        valueFraction() = 1.0;
    }
}


turbulentTemperatureRadCoupledMixedFvPatchScalarField::
turbulentTemperatureRadCoupledMixedFvPatchScalarField
(
    const turbulentTemperatureRadCoupledMixedFvPatchScalarField& psf,
    const DimensionedField<scalar, volMesh>& iF
)
:
    mixedFvPatchScalarField(psf, iF),
    temperatureCoupledBase(patch(), psf),
    TnbrName_(psf.TnbrName_),
    QrNbrName_(psf.QrNbrName_),
    QrName_(psf.QrName_),
    thicknessLayers_(psf.thicknessLayers_),
    kappaLayers_(psf.kappaLayers_),
    contactRes_(psf.contactRes_)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    // Since we're inside initEvaluate/evaluate there might be processor
    // comms underway. Change the tag we use.
    int oldTag = UPstream::msgType();
    UPstream::msgType() = oldTag+1;

    // Get the coupling information from the mappedPatchBase
    const mappedPatchBase& mpp =
        refCast<const mappedPatchBase>(patch().patch());
    const polyMesh& nbrMesh = mpp.sampleMesh();
    const label samplePatchI = mpp.samplePolyPatch().index();
    const fvPatch& nbrPatch =
        refCast<const fvMesh>(nbrMesh).boundary()[samplePatchI];


    scalarField Tc(patchInternalField());
    scalarField& Tp = *this;

    const turbulentTemperatureRadCoupledMixedFvPatchScalarField&
        nbrField = refCast
            <const turbulentTemperatureRadCoupledMixedFvPatchScalarField>
            (
                nbrPatch.lookupPatchField<volScalarField, scalar>(TnbrName_)
            );

    // Swap to obtain full local values of neighbour internal field
    scalarField TcNbr(nbrField.patchInternalField());
    mpp.distribute(TcNbr);


    // Swap to obtain full local values of neighbour K*delta
    scalarField KDeltaNbr(nbrField.size());
    if (contactRes_ == 0.0)
    {
        // Swap to obtain full local values of neighbour K*delta
        KDeltaNbr = nbrField.kappa(nbrField)*nbrPatch.deltaCoeffs();
    }
    else
    {
        KDeltaNbr = contactRes_;
    }
    mpp.distribute(KDeltaNbr);

    scalarField KDelta(kappa(*this)*patch().deltaCoeffs());

    scalarField Qr(Tp.size(), 0.0);
    if (QrName_ != "none")
    {
        Qr = patch().lookupPatchField<volScalarField, scalar>(QrName_);
    }

    scalarField QrNbr(Tp.size(), 0.0);
    if (QrNbrName_ != "none")
    {
        QrNbr = nbrPatch.lookupPatchField<volScalarField, scalar>(QrNbrName_);
        mpp.distribute(QrNbr);
    }

    scalarField alpha(KDeltaNbr - (Qr + QrNbr)/Tp);

    valueFraction() = alpha/(alpha + KDelta);

    refValue() = (KDeltaNbr*TcNbr)/alpha;

    mixedFvPatchScalarField::updateCoeffs();

    if (debug)
    {
        scalar Q = gSum(kappa(*this)*patch().magSf()*snGrad());

        Info<< patch().boundaryMesh().mesh().name() << ':'
            << patch().name() << ':'
            << this->dimensionedInternalField().name() << " <- "
            << nbrMesh.name() << ':'
            << nbrPatch.name() << ':'
            << this->dimensionedInternalField().name() << " :"
            << " heat transfer rate:" << Q
            << " walltemperature "
            << " min:" << gMin(*this)
            << " max:" << gMax(*this)
            << " avg:" << gAverage(*this)
            << endl;
    }

    // Restore tag
    UPstream::msgType() = oldTag;
}


void turbulentTemperatureRadCoupledMixedFvPatchScalarField::write
(
    Ostream& os
) const
{
    mixedFvPatchScalarField::write(os);
    os.writeKeyword("Tnbr")<< TnbrName_ << token::END_STATEMENT << nl;
    os.writeKeyword("QrNbr")<< QrNbrName_ << token::END_STATEMENT << nl;
    os.writeKeyword("Qr")<< QrName_ << token::END_STATEMENT << nl;
    thicknessLayers_.writeEntry("thicknessLayers", os);
    kappaLayers_.writeEntry("kappaLayers", os);

    temperatureCoupledBase::write(os);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

makePatchTypeField
(
    fvPatchScalarField,
    turbulentTemperatureRadCoupledMixedFvPatchScalarField
);


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace compressible
} // End namespace Foam


// ************************************************************************* //

user4

2014-11-12 09:14

  ~0003284

Dear Fabian,

I was trying to run your case but there is no mesh in the water region. Or maybe you can test uploaded turbulentTemperatureRadCoupledMixedFvPatchScalarField.C?

fabian_roesler

2014-11-12 12:27

reporter   ~0003286

Hi,

I'm sorry. When cleaning the case I accidentally deleted the water region blockMeshDict. Here is the upload for the water mesh. This afternoon I will have a look inside your turbulentTemperatureRadCoupledMixedFvPatchScalarField.C file.

Cheers

fabian_roesler

2014-11-12 12:28

reporter  

blockMeshDict (1,785 bytes)   
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.1;

vertices
(
    (-1 0 0)
    (0 0 0)
    (0 1 0)
    (-1 1 0)
    (-1 0 0.1)
    (0 0 0.1)
    (0 1 0.1)
    (-1 1 0.1)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
    water_to_air
    {
        sampleRegion air;
        samplePatch air_to_water;
        type mappedWall;
        sampleMode nearestPatchFaceAMI;
        offsetMode uniform; offset (0 0 0);
        faces
        (
            (2 6 5 1)
        );
    }
    inlet
    {
        type wall;
        faces
        (
            (3 7 6 2)
        );
    }
    outlet
    {
        type wall;
        faces
        (
            (1 5 4 0)
        );
    }
    fixedWalls
    {
        type wall;
        faces
        (
            (0 4 7 3)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
        );
    }
);

mergePatchPairs
(
);

// ************************************************************************* //
blockMeshDict (1,785 bytes)   

fabian_roesler

2014-11-12 13:03

reporter   ~0003287

Hi,

I had time to look inside turbulentTemperatureRadCoupledMixedFvPatchScalarField.C. Indeed the more elegant solution to the second bug. Thanks for fixing. I also did a test with the testCase and everything works fine now. So only the first bug with the wrong calculation of total kappa to go.

Cheers

user4

2014-11-13 14:34

  ~0003288

Thanks for reporting&fix - fixed in c5944c539043440b6c3ac607a359dd6ddddf3184

Issue History

Date Modified Username Field Change
2014-11-11 16:21 fabian_roesler New Issue
2014-11-11 16:21 fabian_roesler File Added: testCase.tar.gz
2014-11-12 09:12 user4 File Added: turbulentTemperatureRadCoupledMixedFvPatchScalarField.C
2014-11-12 09:14 user4 Note Added: 0003284
2014-11-12 12:27 fabian_roesler Note Added: 0003286
2014-11-12 12:28 fabian_roesler File Added: blockMeshDict
2014-11-12 13:03 fabian_roesler Note Added: 0003287
2014-11-13 14:34 user4 Note Added: 0003288
2014-11-13 14:34 user4 Status new => resolved
2014-11-13 14:34 user4 Fixed in Version => 2.3.x
2014-11-13 14:34 user4 Resolution open => fixed
2014-11-13 14:34 user4 Assigned To => user4