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

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

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

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

#include "genericPointPatchField.H"
#include "pointPatchFieldMapper.H"

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

template<class Type>
34
Foam::genericPointPatchField<Type>::genericPointPatchField
35
36
37
38
39
40
41
(
    const pointPatch& p,
    const DimensionedField<Type, pointMesh>& iF
)
:
    calculatedPointPatchField<Type>(p, iF)
{
42
    NotImplemented;
43
44
45
46
}


template<class Type>
47
Foam::genericPointPatchField<Type>::genericPointPatchField
48
49
50
51
52
53
54
(
    const pointPatch& p,
    const DimensionedField<Type, pointMesh>& iF,
    const dictionary& dict
)
:
    calculatedPointPatchField<Type>(p, iF, dict),
55
    actualTypeName_(dict.get<word>("type")),
56
57
    dict_(dict)
{
58
59
    const label patchSize = this->size();

60
    for (const entry& dEntry : dict_)
61
    {
62
63
        const keyType& key = dEntry.keyword();

64
65
66
67
68
        if
        (
            key == "type"
         || !dEntry.isStream() || dEntry.stream().empty()
        )
69
        {
70
71
            continue;
        }
72
73


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        ITstream& is = dEntry.stream();

        // Read first token
        token firstToken(is);

        if
        (
            firstToken.isWord()
         && firstToken.wordToken() == "nonuniform"
        )
        {
            token fieldToken(is);

            if (!fieldToken.isCompound())
            {
89
90
                if
                (
91
92
                    fieldToken.isLabel()
                 && fieldToken.labelToken() == 0
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
                    scalarFields_.insert(key, autoPtr<scalarField>::New());
                }
                else
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    token following 'nonuniform' "
                           "is not a compound"
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
                }
            }
            else if
            (
                fieldToken.compoundToken().type()
             == token::Compound<List<scalar>>::typeName
            )
            {
                auto fPtr = autoPtr<scalarField>::New();

                fPtr->transfer
                (
                    dynamicCast<token::Compound<List<scalar>>>
121
                    (
122
                        fieldToken.transferCompoundToken(is)
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
                );

                if (fPtr->size() != patchSize)
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    size of field " << key
                        << " (" << fPtr->size() << ')'
                        << " is not the same size as the patch ("
                        << patchSize << ')'
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
                }

                scalarFields_.insert(key, fPtr);
            }
            else if
            (
                fieldToken.compoundToken().type()
             == token::Compound<List<vector>>::typeName
            )
            {
                auto fPtr = autoPtr<vectorField>::New();

                fPtr->transfer
                (
                    dynamicCast<token::Compound<List<vector>>>
154
                    (
155
                        fieldToken.transferCompoundToken(is)
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
                );

                if (fPtr->size() != patchSize)
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    size of field " << key
                        << " (" << fPtr->size() << ')'
                        << " is not the same size as the patch ("
                        << patchSize << ')'
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
                }

                vectorFields_.insert(key, fPtr);
            }
            else if
            (
                fieldToken.compoundToken().type()
             == token::Compound<List<sphericalTensor>>::typeName
            )
            {
                auto fPtr = autoPtr<sphericalTensorField>::New();

                fPtr->transfer
                (
                    dynamicCast<token::Compound<List<sphericalTensor>>>
187
                    (
188
                        fieldToken.transferCompoundToken(is)
189
                    )
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
                );

                if (fPtr->size() != patchSize)
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    size of field " << key
                        << " (" << fPtr->size() << ')'
                        << " is not the same size as the patch ("
                        << patchSize << ')'
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
                }

                sphTensorFields_.insert(key, fPtr);
            }
            else if
            (
                fieldToken.compoundToken().type()
             == token::Compound<List<symmTensor>>::typeName
            )
            {
                auto fPtr = autoPtr<symmTensorField>::New();

                fPtr->transfer
                (
                    dynamicCast<token::Compound<List<symmTensor>>>
220
                    (
221
                        fieldToken.transferCompoundToken(is)
222
                    )
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                );

                if (fPtr->size() != patchSize)
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    size of field " << key
                        << " (" << fPtr->size() << ')'
                        << " is not the same size as the patch ("
                        << patchSize << ')'
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
                }

                symmTensorFields_.insert(key, fPtr);
            }
            else if
            (
                fieldToken.compoundToken().type()
             == token::Compound<List<tensor>>::typeName
            )
            {
                auto fPtr = autoPtr<tensorField>::New();

                fPtr->transfer
                (
                    dynamicCast<token::Compound<List<tensor>>>
253
                    (
254
                        fieldToken.transferCompoundToken(is)
255
                    )
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
                );

                if (fPtr->size() != patchSize)
                {
                    FatalIOErrorInFunction(dict)
                        << "\n    size of field " << key
                        << " (" << fPtr->size() << ')'
                        << " is not the same size as the patch ("
                        << patchSize << ')'
                        << "\n    on patch " << this->patch().name()
                        << " of field "
                        << this->internalField().name()
                        << " in file "
                        << this->internalField().objectPath() << nl
                        << exit(FatalIOError);
271
                }
272
273
274
275
276
277
278
279
280
281
282
283
284
285

                tensorFields_.insert(key, fPtr);
            }
            else
            {
                FatalIOErrorInFunction(dict)
                    << "\n    compound " << fieldToken.compoundToken()
                    << " not supported"
                    << "\n    on patch " << this->patch().name()
                    << " of field "
                    << this->internalField().name()
                    << " in file "
                    << this->internalField().objectPath() << nl
                    << exit(FatalIOError);
286
287
288
289
290
291
292
            }
        }
    }
}


template<class Type>
293
Foam::genericPointPatchField<Type>::genericPointPatchField
294
295
296
297
298
299
300
301
302
303
304
(
    const genericPointPatchField<Type>& ptf,
    const pointPatch& p,
    const DimensionedField<Type, pointMesh>& iF,
    const pointPatchFieldMapper& mapper
)
:
    calculatedPointPatchField<Type>(ptf, p, iF, mapper),
    actualTypeName_(ptf.actualTypeName_),
    dict_(ptf.dict_)
{
Andrew Heather's avatar
Andrew Heather committed
305
    forAllConstIters(ptf.scalarFields_, iter)
306
    {
307
308
309
        scalarFields_.insert
        (
            iter.key(),
310
            autoPtr<scalarField>::New(*iter(), mapper)
311
        );
312
313
    }

Andrew Heather's avatar
Andrew Heather committed
314
    forAllConstIters(ptf.vectorFields_, iter)
315
    {
316
317
318
        vectorFields_.insert
        (
            iter.key(),
319
            autoPtr<vectorField>::New(*iter(), mapper)
320
        );
321
322
    }

323
    forAllConstIters(ptf.sphTensorFields_, iter)
324
    {
325
        sphTensorFields_.insert
326
327
        (
            iter.key(),
328
            autoPtr<sphericalTensorField>::New(*iter(), mapper)
329
330
331
        );
    }

Andrew Heather's avatar
Andrew Heather committed
332
    forAllConstIters(ptf.symmTensorFields_, iter)
333
334
335
336
    {
        symmTensorFields_.insert
        (
            iter.key(),
337
            autoPtr<symmTensorField>::New(*iter(), mapper)
338
339
340
        );
    }

Andrew Heather's avatar
Andrew Heather committed
341
    forAllConstIters(ptf.tensorFields_, iter)
342
    {
343
344
345
        tensorFields_.insert
        (
            iter.key(),
346
            autoPtr<tensorField>::New(*iter(), mapper)
347
        );
348
349
350
351
352
    }
}


template<class Type>
353
Foam::genericPointPatchField<Type>::genericPointPatchField
354
355
356
357
358
359
360
361
362
363
(
    const genericPointPatchField<Type>& ptf,
    const DimensionedField<Type, pointMesh>& iF
)
:
    calculatedPointPatchField<Type>(ptf, iF),
    actualTypeName_(ptf.actualTypeName_),
    dict_(ptf.dict_),
    scalarFields_(ptf.scalarFields_),
    vectorFields_(ptf.vectorFields_),
364
    sphTensorFields_(ptf.sphTensorFields_),
365
366
367
368
369
370
371
372
    symmTensorFields_(ptf.symmTensorFields_),
    tensorFields_(ptf.tensorFields_)
{}


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

template<class Type>
373
void Foam::genericPointPatchField<Type>::autoMap
374
375
376
377
(
    const pointPatchFieldMapper& m
)
{
Andrew Heather's avatar
Andrew Heather committed
378
    forAllIters(scalarFields_, iter)
379
    {
380
        iter->autoMap(m);
381
382
    }

Andrew Heather's avatar
Andrew Heather committed
383
    forAllIters(vectorFields_, iter)
384
    {
385
        iter->autoMap(m);
386
387
    }

388
    forAllIters(sphTensorFields_, iter)
389
    {
390
        iter->autoMap(m);
391
392
    }

Andrew Heather's avatar
Andrew Heather committed
393
    forAllIters(symmTensorFields_, iter)
394
    {
395
        iter->autoMap(m);
396
397
    }

Andrew Heather's avatar
Andrew Heather committed
398
    forAllIters(tensorFields_, iter)
399
    {
400
        iter->autoMap(m);
401
402
403
404
405
    }
}


template<class Type>
406
void Foam::genericPointPatchField<Type>::rmap
407
408
409
410
411
412
(
    const pointPatchField<Type>& ptf,
    const labelList& addr
)
{
    const genericPointPatchField<Type>& dptf =
413
        refCast<const genericPointPatchField<Type>>(ptf);
414

Andrew Heather's avatar
Andrew Heather committed
415
    forAllIters(scalarFields_, iter)
416
    {
417
        const auto iter2 = dptf.scalarFields_.cfind(iter.key());
418

419
        if (iter2.found())
420
        {
421
            iter->rmap(*iter2(), addr);
422
423
424
        }
    }

Andrew Heather's avatar
Andrew Heather committed
425
    forAllIters(vectorFields_, iter)
426
    {
427
        const auto iter2 = dptf.vectorFields_.cfind(iter.key());
428

429
        if (iter2.found())
430
        {
431
            iter->rmap(*iter2(), addr);
432
433
434
        }
    }

435
    forAllIters(sphTensorFields_, iter)
436
    {
437
        const auto iter2 = dptf.sphTensorFields_.find(iter.key());
438

439
        if (iter2.found())
440
        {
441
            iter->rmap(*iter2(), addr);
442
443
444
        }
    }

Andrew Heather's avatar
Andrew Heather committed
445
    forAllIters(symmTensorFields_, iter)
446
    {
447
        const auto iter2 = dptf.symmTensorFields_.find(iter.key());
448

449
        if (iter2.found())
450
        {
451
            iter->rmap(*iter2(), addr);
452
453
454
        }
    }

Andrew Heather's avatar
Andrew Heather committed
455
    forAllIters(tensorFields_, iter)
456
    {
457
        const auto iter2 = dptf.tensorFields_.find(iter.key());
458

459
        if (iter2.found())
460
        {
461
            iter->rmap(*iter2(), addr);
462
463
464
465
466
        }
    }
}


467
468
469
470
471
472
473
template<class Type>
const Foam::word& Foam::genericPointPatchField<Type>::actualType() const
{
    return actualTypeName_;
}


474
template<class Type>
475
void Foam::genericPointPatchField<Type>::write(Ostream& os) const
476
{
477
    os.writeEntry("type", actualTypeName_);
478

479
    for (const entry& dEntry : dict_)
480
    {
481
482
        const keyType& key = dEntry.keyword();

483
        if (key == "type")
484
        {
485
            // NB: "type" written first, no special treatment for "value"
486
487
488
489
490
491
492
493
494
495
496
            continue;
        }
        else if
        (
            dEntry.isStream()
         && dEntry.stream().size()
         && dEntry.stream()[0].isWord()
         && dEntry.stream()[0].wordToken() == "nonuniform"
        )
        {
            if (scalarFields_.found(key))
497
            {
498
                scalarFields_.cfind(key)->writeEntry(key, os);
499
            }
500
            else if (vectorFields_.found(key))
501
            {
502
                vectorFields_.cfind(key)->writeEntry(key, os);
503
            }
504
505
            else if (sphTensorFields_.found(key))
            {
506
                sphTensorFields_.cfind(key)->writeEntry(key, os);
507
508
509
            }
            else if (symmTensorFields_.found(key))
            {
510
                symmTensorFields_.cfind(key)->writeEntry(key, os);
511
512
513
            }
            else if (tensorFields_.found(key))
            {
514
                tensorFields_.cfind(key)->writeEntry(key, os);
515
516
517
518
519
            }
        }
        else
        {
            dEntry.write(os);
520
521
522
523
524
525
        }
    }
}


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