writeFluentScalarField.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 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
26Description
27 Given a volScalarField and Fluent field identifier, write the field in
28 Fluent data format
29
30
31\*---------------------------------------------------------------------------*/
32
33#include "writeFluentFields.H"
34#include "emptyFvPatchFields.H"
35
36// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37
38namespace Foam
39{
40
41// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42
44(
45 const volScalarField& phi,
46 const label fluentFieldIdentifier,
47 Ostream& stream
48)
49{
50 const scalarField& phiInternal = phi;
51
52 // Writing cells
53 stream
54 << "(300 ("
55 << fluentFieldIdentifier << " " // Field identifier
56 << "1 " // Zone ID: (cells=1, internal faces=2,
57 // patch faces=patchi+10)
58 << "1 " // Number of components (scalar=1, vector=3)
59 << "0 0 " // Unused
60 << "1 " << phiInternal.size() // Start and end of list
61 << ")(" << endl;
62
63 forAll(phiInternal, celli)
64 {
65 stream << phiInternal[celli] << endl;
66 }
67
68 stream
69 << "))" << endl;
70
71 label nWrittenFaces = phiInternal.size();
72
73 // Writing boundary faces
74 forAll(phi.boundaryField(), patchi)
75 {
76 if (isType<emptyFvPatchScalarField>(phi.boundaryField()[patchi]))
77 {
78 // Form empty patch field repeat the internal field to
79 // allow for the node interpolation in Fluent
80 const scalarField& phiInternal = phi;
81
82 // Get reference to internal cells
83 const labelList emptyFaceCells =
84 phi.boundaryField()[patchi].patch().patch().faceCells();
85
86 // Writing cells for empty patch
87 stream
88 << "(300 ("
89 << fluentFieldIdentifier << " " // Field identifier
90 << patchi + 10 << " " // Zone ID: patchi+10
91 << "1 " // Number of components (scalar=1, vector=3)
92 << "0 0 " // Unused
93 << nWrittenFaces + 1 << " "
94 << nWrittenFaces + emptyFaceCells.size()// Start and end of list
95 << ")(" << endl;
96
97 nWrittenFaces += emptyFaceCells.size();
98
99 forAll(emptyFaceCells, facei)
100 {
101 stream << phiInternal[emptyFaceCells[facei]] << endl;
102 }
103
104 stream
105 << "))" << endl;
106 }
107 else
108 {
109 // Regular patch
110 label nWrittenFaces = phiInternal.size();
111
112 const scalarField& patchPhi = phi.boundaryField()[patchi];
113
114 // Write header
115 stream
116 << "(300 ("
117 << fluentFieldIdentifier << " " // Field identifier
118 << patchi + 10 << " " // Zone ID: patchi+10
119 << "1 " // Number of components (scalar=1, vector=3)
120 << "0 0 " // Unused
121 << nWrittenFaces + 1 << " " << nWrittenFaces + patchPhi.size()
122 // Start and end of list
123 << ")(" << endl;
124
125 nWrittenFaces += patchPhi.size();
126
127 forAll(patchPhi, facei)
128 {
129 stream << patchPhi[facei] << endl;
130 }
131
132 stream
133 << "))" << endl;
134 }
135 }
136}
137
138
139// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140
141} // End namespace Foam
142
143// ************************************************************************* //
surfaceScalarField & phi
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Namespace for OpenFOAM.
void writeFluentField(const volScalarField &phi, const label fluentFieldIdentifier, Ostream &stream)
List< label > labelList
A List of labels.
Definition: List.H:66
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333