temperatureLimitsConstraint.C 4.28 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2012-2013 OpenFOAM Foundation
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
     \\/     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, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*----------------------------------------------------------------------------*/

27
#include "temperatureLimitsConstraint.H"
28
29
30
31
32
33
34
#include "fvMesh.H"
#include "basicThermo.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
35
36
{
namespace fv
37
{
38
39
40
    defineTypeNameAndDebug(temperatureLimitsConstraint, 0);
    addToRunTimeSelectionTable
    (
41
        option,
42
43
44
        temperatureLimitsConstraint,
        dictionary
    );
45
}
46
}
47
48
49

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

50
Foam::fv::temperatureLimitsConstraint::temperatureLimitsConstraint
51
52
53
54
55
56
57
(
    const word& name,
    const word& modelType,
    const dictionary& dict,
    const fvMesh& mesh
)
:
58
    option(name, modelType, dict, mesh),
59
60
61
62
63
64
65
66
67
68
    Tmin_(readScalar(coeffs_.lookup("Tmin"))),
    Tmax_(readScalar(coeffs_.lookup("Tmax")))
{
    fieldNames_.setSize(1, "energy");
    applied_.setSize(1, false);
}


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

69
bool Foam::fv::temperatureLimitsConstraint::alwaysApply() const
70
71
72
73
74
{
    return true;
}


75
void Foam::fv::temperatureLimitsConstraint::correct(volScalarField& he)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
    const basicThermo& thermo =
        mesh_.lookupObject<basicThermo>("thermophysicalProperties");

    if (he.name() == thermo.he().name())
    {
        scalarField Tmin(cells_.size(), Tmin_);
        scalarField Tmax(cells_.size(), Tmax_);

        scalarField heMin(thermo.he(thermo.p(), Tmin, cells_));
        scalarField heMax(thermo.he(thermo.p(), Tmax, cells_));

        scalarField& hec = he.internalField();

        forAll(cells_, i)
        {
            label cellI = cells_[i];
            hec[cellI]= max(min(hec[cellI], heMax[i]), heMin[i]);
        }

        // handle boundaries in the case of 'all'
        if (selectionMode_ == smAll)
        {
            volScalarField::GeometricBoundaryField& bf = he.boundaryField();

            forAll(bf, patchI)
            {
                fvPatchScalarField& hep = bf[patchI];
                if (hep.fixesValue())
                {
                    // not over-riding fixed conditions
                    continue;
                }

                const scalarField& pp = thermo.p().boundaryField()[patchI];

                scalarField Tminp(pp.size(), Tmin_);
                scalarField Tmaxp(pp.size(), Tmax_);

                scalarField heMinp(thermo.he(pp, Tminp, patchI));
                scalarField heMaxp(thermo.he(pp, Tmaxp, patchI));

                forAll(hep, faceI)
                {
                    hep[faceI] =
                        max(min(hep[faceI], heMaxp[faceI]), heMinp[faceI]);
                }
            }
        }
    }
}


129
void Foam::fv::temperatureLimitsConstraint::writeData(Ostream& os) const
130
131
132
133
134
135
{
    os  << indent << name_ << endl;
    dict_.write(os);
}


136
bool Foam::fv::temperatureLimitsConstraint::read(const dictionary& dict)
137
{
138
    if (option::read(dict))
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    {
        coeffs_.readIfPresent("Tmin", Tmin_);
        coeffs_.readIfPresent("Tmax", Tmax_);

        return true;
    }
    else
    {
        return false;
    }
}


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