Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecplotWriterTemplates.C
blobe620892e8a694ffcd03ab742cc48b8338c055213
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 //extern "C"
27 //{
28     #include "MASTER.h"
29     #include "GLOBAL.h"
30 //}
32 #include "tecplotWriter.H"
34 #include "fvc.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 template<class Type>
39 void Foam::tecplotWriter::writeField(const Field<Type>& fld) const
41     for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
42     {
43         scalarField cmptFld(fld.component(cmpt));
45         // Convert to float
46         Field<float> floats(cmptFld.size());
47         forAll(cmptFld, i)
48         {
49             floats[i] = float(cmptFld[i]);
50         }
52         INTEGER4 size = INTEGER4(floats.size());
53         INTEGER4 IsDouble = 0;  //float
55         //Pout<< "Writing component:" << cmpt << " of size:" << size
56         //    << " floats." << endl;
58         if (!TECDAT112(&size, floats.begin(), &IsDouble))
59         {
60 //            FatalErrorIn("tecplotWriter::writeField(..) const")
61 //                << "Error in TECDAT112." << exit(FatalError);
62         }
63     }
67 template<class Type>
68 Foam::tmp<Field<Type> > Foam::tecplotWriter::getPatchField
70     const bool nearCellValue,
71     const GeometricField<Type, fvPatchField, volMesh>& vfld,
72     const label patchI
73 ) const
75     if (nearCellValue)
76     {
77         return vfld.boundaryField()[patchI].patchInternalField();
78     }
79     else
80     {
81         return vfld.boundaryField()[patchI];
82     }
86 template<class Type>
87 Foam::tmp<Field<Type> > Foam::tecplotWriter::getFaceField
89     const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld,
90     const labelList& faceLabels
91 ) const
93     const polyBoundaryMesh& patches = sfld.mesh().boundaryMesh();
95     tmp<Field<Type> > tfld(new Field<Type>(faceLabels.size()));
96     Field<Type>& fld = tfld();
98     forAll(faceLabels, i)
99     {
100         label faceI = faceLabels[i];
102         label patchI = patches.whichPatch(faceI);
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     }
115     return tfld;
119 template<class GeoField>
120 Foam::wordList Foam::tecplotWriter::getNames
122     const PtrList<GeoField>& flds
125     wordList names(flds.size());
126     forAll(flds, i)
127     {
128         names[i] = flds[i].name();
129     }
130     return names;
134 template<class Type>
135 void Foam::tecplotWriter::getTecplotNames
137     const wordList& names,
138     const INTEGER4 loc,
139     string& varNames,
140     DynamicList<INTEGER4>& varLocation
143     forAll(names, i)
144     {
145         if (!varNames.empty())
146         {
147             varNames += " ";
148         }
150         direction nCmpts = pTraits<Type>::nComponents;
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     }
179 template<class GeoField>
180 void Foam::tecplotWriter::getTecplotNames
182     const PtrList<GeoField>& flds,
183     const INTEGER4 loc,
184     string& varNames,
185     DynamicList<INTEGER4>& varLocation
188     getTecplotNames<typename GeoField::value_type>
189     (
190         getNames(flds),
191         loc,
192         varNames,
193         varLocation
194     );
198 // ************************************************************************* //