sampledSurfacesTemplates.C 6.48 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
     \\/     M anipulation  | Copyright (C) 2015-2019 OpenCFD Ltd.
7
8
9
10
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    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.
15
16
17
18
19
20
21

    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
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23
24
25
26
27

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

#include "sampledSurfaces.H"
#include "volFields.H"
28
#include "surfaceFields.H"
29
#include "globalIndex.H"
andy's avatar
andy committed
30
#include "stringListOps.H"
31
32
33

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

34
35
36
37
template<class Type>
void Foam::sampledSurfaces::writeSurface
(
    const Field<Type>& values,
38
    const label surfi,
39
40
41
42
    const word& fieldName,
    const fileName& outputDir
)
{
43
    const sampledSurface& s = operator[](surfi);
44

45
46
47
48
49
50
51
    if (changedGeom_[surfi])
    {
        // Trigger any changes
        formatter_->updateMesh(outputDir, s.name());
        changedGeom_[surfi] = false;
    }

52
53
    if (Pstream::parRun())
    {
54
55
56
57
        // Gather all values into single field
        Field<Type> allValues;

        globalIndex::gatherOp(values, allValues);
58

59
        fileName sampleFile;
60
61
62
        if (Pstream::master())
        {
            // Renumber (point data) to correspond to merged points
63
            if (mergedList_[surfi].pointsMap().size() == allValues.size())
64
            {
65
                inplaceReorder(mergedList_[surfi].pointsMap(), allValues);
66
                allValues.resize(mergedList_[surfi].points().size());
67
68
69
70
            }

            // Write to time directory under outputPath_
            // skip surface without faces (eg, a failed cut-plane)
71
            if (mergedList_[surfi].size())
72
            {
73
                sampleFile = formatter_->write
74
75
76
                (
                    outputDir,
                    s.name(),
77
                    mergedList_[surfi],
78
79
80
81
82
83
                    fieldName,
                    allValues,
                    s.interpolate()
                );
            }
        }
84
85
86
87

        Pstream::scatter(sampleFile);
        if (sampleFile.size())
        {
88
            // Case-local file name with "<case>" to make relocatable
89

90
            dictionary propsDict;
91
92
93
            propsDict.add
            (
                "file",
94
                time_.relativePath(sampleFile, true)
95
            );
96
97
            setProperty(fieldName, propsDict);
        }
98
99
100
101
102
103
104
    }
    else
    {
        // Write to time directory under outputPath_
        // skip surface without faces (eg, a failed cut-plane)
        if (s.faces().size())
        {
105
            fileName fName = formatter_->write
106
107
108
            (
                outputDir,
                s.name(),
109
                s,
110
111
112
113
                fieldName,
                values,
                s.interpolate()
            );
114

115
            // Case-local file name with "<case>" to make relocatable
116

117
            dictionary propsDict;
118
119
120
            propsDict.add
            (
                "file",
121
                time_.relativePath(fName, true)
122
            );
123
            setProperty(fieldName, propsDict);
124
125
126
127
128
        }
    }
}


129
130
131
template<class Type>
void Foam::sampledSurfaces::sampleAndWrite
(
132
    const GeometricField<Type, fvPatchField, volMesh>& vField
133
134
)
{
135
136
    // sampler/interpolator for this field
    autoPtr<interpolation<Type>> interpPtr;
137

andy's avatar
andy committed
138
    const word& fieldName = vField.name();
Mark Olesen's avatar
Mark Olesen committed
139
    const fileName outputDir = outputPath_/vField.time().timeName();
140

141
    forAll(*this, surfi)
142
    {
143
        const sampledSurface& s = operator[](surfi);
144
145
146
147
148

        Field<Type> values;

        if (s.interpolate())
        {
149
            if (interpPtr.empty())
150
            {
151
                interpPtr = interpolation<Type>::New
152
                (
153
                    sampleNodeScheme_,
154
155
                    vField
                );
156
157
            }

158
            values = s.interpolate(*interpPtr);
159
160
161
        }
        else
        {
162
163
164
165
166
167
168
169
170
171
            if (interpPtr.empty())
            {
                interpPtr = interpolation<Type>::New
                (
                    sampleFaceScheme_,
                    vField
                );
            }

            values = s.sample(*interpPtr);
172
173
        }

174
        writeSurface<Type>(values, surfi, fieldName, outputDir);
175
176
177
178
    }
}


179
template<class Type>
180
181
void Foam::sampledSurfaces::sampleAndWrite
(
182
    const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
183
184
)
{
185
    const word& fieldName = sField.name();
186
187
    const fileName outputDir = outputPath_/sField.time().timeName();

188
    forAll(*this, surfi)
189
    {
190
        const sampledSurface& s = operator[](surfi);
191
        Field<Type> values(s.sample(sField));
192
        writeSurface<Type>(values, surfi, fieldName, outputDir);
193
194
195
196
197
    }
}


template<class GeoField>
198
void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects)
199
{
200
    wordList fieldNames;
201
    if (loadFromFiles_)
202
    {
203
        fieldNames = objects.sortedNames(GeoField::typeName, fieldSelection_);
204
205
206
    }
    else
    {
207
        fieldNames = mesh_.thisDb().sortedNames<GeoField>(fieldSelection_);
208

209
210
        writeOriginalIds();
    }
211

212
    for (const word& fieldName : fieldNames)
213
    {
214
        if (verbose_)
andy's avatar
andy committed
215
        {
216
            Info<< "sampleAndWrite: " << fieldName << endl;
217
        }
218

219
220
        if (loadFromFiles_)
        {
andy's avatar
andy committed
221
222
223
224
225
            const GeoField fld
            (
                IOobject
                (
                    fieldName,
226
                    time_.timeName(),
andy's avatar
andy committed
227
228
229
230
231
                    mesh_,
                    IOobject::MUST_READ
                ),
                mesh_
            );
232

andy's avatar
andy committed
233
            sampleAndWrite(fld);
234
        }
235
        else
andy's avatar
andy committed
236
237
238
239
240
        {
            sampleAndWrite
            (
                mesh_.thisDb().lookupObject<GeoField>(fieldName)
            );
241
242
243
244
245
246
        }
    }
}


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