tecplotWriterTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  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 //extern "C"
27 //{
28  #include "MASTER.h"
29  #include "GLOBAL.h"
30 //}
31 
32 #include "tecplotWriter.H"
33 
34 #include "fvc.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template<class Type>
39 void Foam::tecplotWriter::writeField(const Field<Type>& fld) const
40 {
41  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
42  {
43  scalarField cmptFld(fld.component(cmpt));
44 
45  // Convert to float
46  Field<float> floats(cmptFld.size());
47  forAll(cmptFld, i)
48  {
49  floats[i] = float(cmptFld[i]);
50  }
51 
52  INTEGER4 size = INTEGER4(floats.size());
53  INTEGER4 IsDouble = 0; // float
54 
55  // Pout<< "Writing component:" << cmpt << " of size:" << size
56  // << " floats." << endl;
57 
58  if (!TECDAT112(&size, floats.begin(), &IsDouble))
59  {
60 // FatalErrorInFunction
61 // << "Error in TECDAT112." << exit(FatalError);
62  }
63  }
64 }
65 
66 
67 template<class Type>
69 (
70  const bool nearCellValue,
71  const GeometricField<Type, fvPatchField, volMesh>& vfld,
72  const label patchi
73 ) const
74 {
75  if (nearCellValue)
76  {
77  return vfld.boundaryField()[patchi].patchInternalField();
78  }
79  else
80  {
81  return vfld.boundaryField()[patchi];
82  }
83 }
84 
85 
86 template<class Type>
88 (
89  const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld,
90  const labelList& faceLabels
91 ) const
92 {
93  const polyBoundaryMesh& patches = sfld.mesh().boundaryMesh();
94 
95  tmp<Field<Type>> tfld(new Field<Type>(faceLabels.size()));
96  Field<Type>& fld = tfld.ref();
97 
98  forAll(faceLabels, i)
99  {
100  label facei = faceLabels[i];
101 
102  label patchi = patches.whichPatch(facei);
103 
104  if (patchi == -1)
105  {
106  fld[i] = sfld[facei];
107  }
108  else
109  {
110  label localFacei = facei - patches[patchi].start();
111  fld[i] = sfld.boundaryField()[patchi][localFacei];
112  }
113  }
114 
115  return tfld;
116 }
117 
118 
119 template<class GeoField>
121 (
122  const PtrList<GeoField>& flds
123 )
124 {
125  wordList names(flds.size());
126  forAll(flds, i)
127  {
128  names[i] = flds[i].name();
129  }
130  return names;
131 }
132 
133 
134 template<class Type>
136 (
137  const wordList& names,
138  const INTEGER4 loc,
139  string& varNames,
140  DynamicList<INTEGER4>& varLocation
141 )
142 {
143  forAll(names, i)
144  {
145  if (!varNames.empty())
146  {
147  varNames += " ";
148  }
149 
150  label nCmpts = pTraits<Type>::nComponents;
151 
152  if (nCmpts == 1)
153  {
154  varNames += names[i];
155  varLocation.append(loc);
156  }
157  else
158  {
159  for
160  (
161  direction cmpt = 0;
162  cmpt < nCmpts;
163  cmpt++
164  )
165  {
166  string fldName =
167  (cmpt != 0 ? " " : string::null)
168  + names[i]
169  + "_"
170  + pTraits<Type>::componentNames[cmpt];
171  varNames += fldName;
172  varLocation.append(loc);
173  }
174  }
175  }
176 }
177 
178 
179 template<class GeoField>
181 (
182  const PtrList<GeoField>& flds,
183  const INTEGER4 loc,
184  string& varNames,
185  DynamicList<INTEGER4>& varLocation
186 )
187 {
188  getTecplotNames<typename GeoField::value_type>
189  (
190  getNames(flds),
191  loc,
192  varNames,
193  varLocation
194  );
195 }
196 
197 
198 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
uint8_t direction
Definition: direction.H:45
static wordList getNames(const PtrList< GeoField > &)
static void getTecplotNames(const wordList &names, const INTEGER4 loc, string &varNames, DynamicList< INTEGER4 > &varLocation)
void writeField(const Field< Type > &fld) const
Write generic Field.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
tmp< Field< Type > > getFaceField(const GeometricField< Type, fvsPatchField, surfaceMesh > &, const labelList &faceLabels) const
Get mixed field: fvsPatchField for boundary faces and.
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const string null
An empty string.
Definition: string.H:88
tmp< Field< Type > > getPatchField(const bool nearCellValue, const GeometricField< Type, fvPatchField, volMesh > &vfld, const label patchi) const
Get either fvPatchField or patchInternalField.
List< word > wordList
A List of words.
Definition: fileName.H:54
label patchi
A class for managing temporary objects.
Definition: PtrList.H:53