patchProbesTemplates.C 6.92 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
6
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
     \\/     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 "patchProbes.H"
#include "volFields.H"
#include "IOmanip.H"


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

template<class Type>
void Foam::patchProbes::sampleAndWrite
(
    const GeometricField<Type, fvPatchField, volMesh>& vField
)
{
39
    Field<Type> values(sample(vField));
40
41
42
43
44
45

    if (Pstream::master())
    {
        unsigned int w = IOstream::defaultPrecision() + 7;
        OFstream& probeStream = *probeFilePtrs_[vField.name()];

46
47
        probeStream
            << setw(w)
48
            << vField.time().timeOutputValue();
49

50
        forAll(values, probei)
51
        {
52
            probeStream << ' ' << setw(w) << values[probei];
53
54
55
56
57
58
        }
        probeStream << endl;
    }
}


59
60
61
62
63
64
65
66
67
68
69
70
71
template<class Type>
void Foam::patchProbes::sampleAndWrite
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
)
{
    Field<Type> values(sample(sField));

    if (Pstream::master())
    {
        unsigned int w = IOstream::defaultPrecision() + 7;
        OFstream& probeStream = *probeFilePtrs_[sField.name()];

72
73
        probeStream
            << setw(w)
74
            << sField.time().timeOutputValue();
75

76
        forAll(values, probei)
77
        {
78
            probeStream << ' ' << setw(w) << values[probei];
79
80
81
82
83
84
        }
        probeStream << endl;
    }
}


Henry's avatar
Henry committed
85
template<class Type>
86
87
88
89
90
void Foam::patchProbes::sampleAndWrite
(
    const fieldGroup<Type>& fields
)
{
91
    forAll(fields, fieldi)
92
93
94
95
96
97
98
99
100
    {
        if (loadFromFiles_)
        {
            sampleAndWrite
            (
                GeometricField<Type, fvPatchField, volMesh>
                (
                    IOobject
                    (
101
                        fields[fieldi],
102
103
104
105
106
107
108
109
110
111
112
113
                        mesh_.time().timeName(),
                        mesh_,
                        IOobject::MUST_READ,
                        IOobject::NO_WRITE,
                        false
                    ),
                    mesh_
                )
            );
        }
        else
        {
114
            objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
115
116
117

            if
            (
118
                iter.found()
119
120
121
122
123
124
125
             && iter()->type()
             == GeometricField<Type, fvPatchField, volMesh>::typeName
            )
            {
                sampleAndWrite
                (
                    mesh_.lookupObject
126
                    <GeometricField<Type, fvPatchField, volMesh>>
127
                    (
128
                        fields[fieldi]
129
130
131
132
133
134
135
136
                    )
                );
            }
        }
    }
}


137
138
139
140
141
142
template<class Type>
void Foam::patchProbes::sampleAndWriteSurfaceFields
(
    const fieldGroup<Type>& fields
)
{
143
    forAll(fields, fieldi)
144
145
146
147
148
149
150
151
152
    {
        if (loadFromFiles_)
        {
            sampleAndWrite
            (
                GeometricField<Type, fvsPatchField, surfaceMesh>
                (
                    IOobject
                    (
153
                        fields[fieldi],
154
155
156
157
158
159
160
161
162
163
164
165
                        mesh_.time().timeName(),
                        mesh_,
                        IOobject::MUST_READ,
                        IOobject::NO_WRITE,
                        false
                    ),
                    mesh_
                )
            );
        }
        else
        {
166
            objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
167
168
169

            if
            (
170
                iter.found()
171
172
173
174
175
176
177
             && iter()->type()
             == GeometricField<Type, fvsPatchField, surfaceMesh>::typeName
            )
            {
                sampleAndWrite
                (
                    mesh_.lookupObject
178
                    <GeometricField<Type, fvsPatchField, surfaceMesh>>
179
                    (
180
                        fields[fieldi]
181
182
183
184
185
186
187
188
                    )
                );
            }
        }
    }
}


189
190
191
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class Type>
192
Foam::tmp<Foam::Field<Type>>
193
194
195
196
197
198
199
Foam::patchProbes::sample
(
    const GeometricField<Type, fvPatchField, volMesh>& vField
) const
{
    const Type unsetVal(-VGREAT*pTraits<Type>::one);

200
    tmp<Field<Type>> tValues
201
202
203
204
    (
        new Field<Type>(this->size(), unsetVal)
    );

205
    Field<Type>& values = tValues.ref();
206
207
208

    const polyBoundaryMesh& patches = mesh_.boundaryMesh();

209
    forAll(*this, probei)
210
    {
211
        label facei = faceList_[probei];
212

213
        if (facei >= 0)
214
        {
215
            label patchi = patches.whichPatch(facei);
216
            label localFacei = patches[patchi].whichFace(facei);
217
            values[probei] = vField.boundaryField()[patchi][localFacei];
218
219
220
221
222
223
224
225
226
227
228
        }
    }

    Pstream::listCombineGather(values, isNotEqOp<Type>());
    Pstream::listCombineScatter(values);

    return tValues;
}


template<class Type>
229
Foam::tmp<Foam::Field<Type>>
230
231
232
233
Foam::patchProbes::sample(const word& fieldName) const
{
    return sample
    (
234
        mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh>>
235
236
237
238
239
240
241
        (
            fieldName
        )
    );
}


242
template<class Type>
243
Foam::tmp<Foam::Field<Type>>
244
245
246
247
248
249
250
Foam::patchProbes::sample
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
) const
{
    const Type unsetVal(-VGREAT*pTraits<Type>::one);

251
    tmp<Field<Type>> tValues
252
253
254
255
    (
        new Field<Type>(this->size(), unsetVal)
    );

256
    Field<Type>& values = tValues.ref();
257
258
259

    const polyBoundaryMesh& patches = mesh_.boundaryMesh();

260
    forAll(*this, probei)
261
    {
262
        label facei = faceList_[probei];
263

264
        if (facei >= 0)
265
        {
266
            label patchi = patches.whichPatch(facei);
267
            label localFacei = patches[patchi].whichFace(facei);
268
            values[probei] = sField.boundaryField()[patchi][localFacei];
269
270
271
272
273
274
275
276
        }
    }

    Pstream::listCombineGather(values, isNotEqOp<Type>());
    Pstream::listCombineScatter(values);

    return tValues;
}
277
278


279
// ************************************************************************* //