volRegion.C 4.72 KB
Newer Older
1
2
3
4
5
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-------------------------------------------------------------------------------
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 "volRegion.H"
#include "volMesh.H"
#include "globalMeshData.H"

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

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(volRegion, 0);
}
}

template<>
const char*
Foam::NamedEnum
<
    Foam::functionObjects::volRegion::regionTypes,
    2
>::names[] = {"cellZone", "all"};

const Foam::NamedEnum
<
    Foam::functionObjects::volRegion::regionTypes,
    2
> Foam::functionObjects::volRegion::regionTypeNames_;


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

void Foam::functionObjects::volRegion::writeFileHeader
(
    const writeFile& wf,
    Ostream& file
61
) const
62
{
63
64
65
66
67
    wf.writeCommented(file, "Region");
    file<< setw(1) << ':' << setw(1) << ' '
        << regionTypeNames_[regionType_] << " " << regionName_ << endl;
    wf.writeHeaderValue(file, "Cells", nCells_);
    wf.writeHeaderValue(file, "Volume", V_);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
}


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

Foam::functionObjects::volRegion::volRegion
(
    const fvMesh& mesh,
    const dictionary& dict
)
:
    mesh_(mesh),
    regionType_
    (
        dict.found("regionType")
      ? regionTypeNames_.read(dict.lookup("regionType"))
      : vrtAll
    ),
86
    regionName_(polyMesh::defaultRegion),
87
88
89
    regionID_(-1)
{
    read(dict);
90
91
92
93

    // Cache integral properties of the region for writeFileHeader
    nCells_ = nCells();
    V_ = V();
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::functionObjects::volRegion::~volRegion()
{}


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

bool Foam::functionObjects::volRegion::read
(
    const dictionary& dict
)
{
    switch (regionType_)
    {
        case vrtCellZone:
        {
            dict.lookup("name") >> regionName_;

            regionID_ = mesh_.cellZones().findZoneID(regionName_);

            if (regionID_ < 0)
            {
                FatalIOErrorInFunction(dict)
                    << "Unknown cell zone name: " << regionName_
                    << ". Valid cell zones are: " << mesh_.cellZones().names()
                    << exit(FatalIOError);
            }

            if (nCells() == 0)
            {
                FatalIOErrorInFunction(dict)
                    << regionTypeNames_[regionType_]
                    << "(" << regionName_ << "):" << nl
                    << "    Region has no cells"
                    << exit(FatalIOError);
            }

            break;
        }

        case vrtAll:
        {
            break;
        }

        default:
        {
            FatalIOErrorInFunction(dict)
                << "Unknown region type. Valid region types are:"
                << regionTypeNames_
                << exit(FatalIOError);
        }
    }

    return true;
}


const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
{
    if (regionType_ == vrtAll)
    {
        return labelList::null();
    }
    else
    {
        return mesh_.cellZones()[regionID_];
    }
}


Foam::label Foam::functionObjects::volRegion::nCells() const
{
    if (regionType_ == vrtAll)
    {
        return mesh_.globalData().nTotalCells();
    }
    else
    {
        return returnReduce(cellIDs().size(), sumOp<label>());
    }
}


Foam::scalar Foam::functionObjects::volRegion::V() const
{
    if (regionType_ == vrtAll)
    {
        return gSum(mesh_.V());
    }
    else
    {
        return gSum(scalarField(mesh_.V(), cellIDs()));
    }
}


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