Loading...
Searching...
No Matches
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 Copyright (C) 2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 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
27Description
28 Given a volScalarField and Fluent field identifier, write the field in
29 Fluent data format
30
31
32\*---------------------------------------------------------------------------*/
33
34#include "writeFluentFields.H"
35#include "emptyFvPatchFields.H"
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
40(
41 const volScalarField& phi,
42 const label fluentFieldIdentifier,
43 Ostream& stream
44)
45{
46 const scalarField& phiInternal = phi;
47
48 // Writing cells
49 stream
50 << "(300 ("
51 << fluentFieldIdentifier << " " // Field identifier
52 << "1 " // Zone ID: (cells=1, internal faces=2,
53 // patch faces=patchi+10)
54 << "1 " // Number of components (scalar=1, vector=3)
55 << "0 0 " // Unused
56 << "1 " << phiInternal.size() // Start and end of list
57 << ")(" << nl;
58
59 for (const scalar val : phiInternal)
60 {
61 stream << val << nl;
62 }
63
64 stream
65 << "))" << nl;
66
67 label nWrittenFaces = phiInternal.size();
68
69 // Writing boundary faces
70 forAll(phi.boundaryField(), patchi)
71 {
72 if (isType<emptyFvPatchScalarField>(phi.boundaryField()[patchi]))
73 {
74 // Form empty patch field repeat the internal field to
75 // allow for the node interpolation in Fluent
76 const scalarField& phiInternal = phi;
77
78 // Get reference to internal cells
79 const auto& emptyFaceCells =
80 phi.boundaryField()[patchi].patch().patch().faceCells();
81
82 // Writing cells for empty patch
83 stream
84 << "(300 ("
85 << fluentFieldIdentifier << " " // Field identifier
86 << patchi + 10 << " " // Zone ID: patchi+10
87 << "1 " // Number of components (scalar=1, vector=3)
88 << "0 0 " // Unused
89 << nWrittenFaces + 1 << " "
90 << nWrittenFaces + emptyFaceCells.size()// Start and end of list
91 << ")(" << nl;
92
93 nWrittenFaces += emptyFaceCells.size();
94
95 forAll(emptyFaceCells, facei)
96 {
97 stream << phiInternal[emptyFaceCells[facei]] << nl;
98 }
99
100 stream
101 << "))" << endl;
102 }
103 else
104 {
105 // Regular patch
106 label nWrittenFaces = phiInternal.size();
107
108 const scalarField& patchPhi = phi.boundaryField()[patchi];
109
110 // Write header
111 stream
112 << "(300 ("
113 << fluentFieldIdentifier << " " // Field identifier
114 << patchi + 10 << " " // Zone ID: patchi+10
115 << "1 " // Number of components (scalar=1, vector=3)
116 << "0 0 " // Unused
117 << nWrittenFaces + 1 << " " << nWrittenFaces + patchPhi.size()
118 // Start and end of list
119 << ")(" << nl;
120
121 nWrittenFaces += patchPhi.size();
122
123 for (const scalar val : patchPhi)
124 {
125 stream << val << nl;
126 }
127
128 stream
129 << "))" << endl;
130 }
131 }
132}
133
134
135// ************************************************************************* //
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void writeFluentField(const volScalarField &phi, const label fluentFieldIdentifier, Ostream &os)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299