pointZone.C 5.82 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6
7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
9
    Copyright (C) 2011-2016 OpenFOAM Foundation
    Copyright (C) 2017-2018 OpenCFD Ltd.
10
11
12
13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14
15
16
17
    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.
18
19
20
21
22
23
24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26
27
28
29
30
31
32
33
34

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

#include "pointZone.H"
#include "addToRunTimeSelectionTable.H"
#include "pointZoneMesh.H"
#include "polyMesh.H"
#include "primitiveMesh.H"
#include "demandDrivenData.H"
35
#include "syncTools.H"
36
37
38
39
40
41
42
43
44
45

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

namespace Foam
{
    defineTypeNameAndDebug(pointZone, 0);
    defineRunTimeSelectionTable(pointZone, dictionary);
    addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
}

46
const char* const Foam::pointZone::labelsName = "pointLabels";
47

48

49
50
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Mark Olesen's avatar
Mark Olesen committed
51
52
53
54
55
56
57
58
59
60
61
62
Foam::pointZone::pointZone
(
    const word& name,
    const label index,
    const pointZoneMesh& zm
)
:
    zone(name, index),
    zoneMesh_(zm)
{}


63
64
65
Foam::pointZone::pointZone
(
    const word& name,
66
    const labelUList& addr,
67
68
69
70
    const label index,
    const pointZoneMesh& zm
)
:
71
72
    zone(name, addr, index),
    zoneMesh_(zm)
73
74
75
{}


Mark Olesen's avatar
Mark Olesen committed
76
77
78
79
80
81
82
83
84
85
86
87
88
Foam::pointZone::pointZone
(
    const word& name,
    labelList&& addr,
    const label index,
    const pointZoneMesh& zm
)
:
    zone(name, std::move(addr), index),
    zoneMesh_(zm)
{}


89
90
91
92
93
94
95
96
Foam::pointZone::pointZone
(
    const word& name,
    const dictionary& dict,
    const label index,
    const pointZoneMesh& zm
)
:
97
    zone(name, dict, this->labelsName, index),
98
    zoneMesh_(zm)
99
100
101
102
103
{}


Foam::pointZone::pointZone
(
Mark Olesen's avatar
Mark Olesen committed
104
    const pointZone& origZone,
105
    const labelUList& addr,
106
107
108
109
    const label index,
    const pointZoneMesh& zm
)
:
Mark Olesen's avatar
Mark Olesen committed
110
    zone(origZone, addr, index),
111
    zoneMesh_(zm)
112
113
114
{}


115
116
Foam::pointZone::pointZone
(
Mark Olesen's avatar
Mark Olesen committed
117
118
119
120
121
122
123
124
125
126
127
    const pointZone& origZone,
    labelList&& addr,
    const label index,
    const pointZoneMesh& zm
)
:
    zone(origZone, std::move(addr), index),
    zoneMesh_(zm)
{}


128
129
130
131
132
133
134
135
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
{
    return zoneMesh_;
}


136
Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
137
{
138
    return zone::localID(globalPointID);
139
140
141
142
143
}


bool Foam::pointZone::checkDefinition(const bool report) const
{
144
    return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
145
146
147
}


148
149
150
151
152
153
bool Foam::pointZone::checkParallelSync(const bool report) const
{
    const polyMesh& mesh = zoneMesh().mesh();

    labelList maxZone(mesh.nPoints(), -1);
    labelList minZone(mesh.nPoints(), labelMax);
Mark Olesen's avatar
Mark Olesen committed
154
155
156
157

    const labelList& addr = *this;

    for (const label pointi : addr)
158
    {
159
160
        maxZone[pointi] = index();
        minZone[pointi] = index();
161
    }
mattijs's avatar
mattijs committed
162
    syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
163
164
165
166
    syncTools::syncPointList(mesh, minZone, minEqOp<label>(), labelMax);

    bool error = false;

167
    forAll(maxZone, pointi)
168
    {
169
170
171
172
        // Check point in same (or no) zone on all processors
        if
        (
            (
173
174
                maxZone[pointi] != -1
             || minZone[pointi] != labelMax
175
            )
176
         && (maxZone[pointi] != minZone[pointi])
177
        )
178
179
180
181
182
        {
            if (report && !error)
            {
                Info<< " ***Problem with pointZone " << index()
                    << " named " << name()
183
184
                    << ". Point " << pointi
                    << " at " << mesh.points()[pointi]
185
                    << " is in zone "
186
                    << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
187
                    << " on some processors and in zone "
188
                    << maxZone[pointi]
189
190
                    << " on some other processors." << nl
                    << "(suppressing further warnings)"
191
192
193
194
195
196
197
198
199
200
                    << endl;
            }
            error = true;
        }
    }

    return error;
}


201
202
void Foam::pointZone::writeDict(Ostream& os) const
{
203
    os  << nl << name_ << nl << token::BEGIN_BLOCK << nl
204
205
        << "    type " << type() << token::END_STATEMENT << nl;

206
    writeEntry(this->labelsName, os);
207
208
209
210
211
212
213

    os  << token::END_BLOCK << endl;
}


// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

214
void Foam::pointZone::operator=(const pointZone& zn)
215
216
{
    clearAddressing();
217
    labelList::operator=(zn);
218
219
220
}


221
void Foam::pointZone::operator=(const labelUList& addr)
222
223
224
225
226
227
{
    clearAddressing();
    labelList::operator=(addr);
}


228
void Foam::pointZone::operator=(labelList&& addr)
229
230
{
    clearAddressing();
231
    labelList::transfer(addr);
232
233
234
235
236
}


// * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //

237
Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& zn)
238
{
239
    zn.write(os);
240
    os.check(FUNCTION_NAME);
241
242
243
244
245
    return os;
}


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