foam to Tecplot360 converter
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecplotWriterTemplates.C
blobf9a01d57a4ba31bd3aef10148a75ac0efb8554f9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "tecplotWriter.H"
29 //extern "C"
30 //{
31     #include "MASTER.h"
32     #include "GLOBAL.h"
33 //}
35 #include "fvc.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 template<class Type>
40 void Foam::tecplotWriter::writeField(const Field<Type>& fld) const
42     for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
43     {
44         scalarField cmptFld(fld.component(cmpt));
46         // Convert to float
47         Field<float> floats(cmptFld.size());
48         forAll(cmptFld, i)
49         {
50             floats[i] = float(cmptFld[i]);
51         }
53         INTEGER4 size = INTEGER4(floats.size());
54         INTEGER4 IsDouble = 0;  //float
56         //Pout<< "Writing component:" << cmpt << " of size:" << size
57         //    << " floats." << endl;
59         if (!TECDAT112(&size, floats.begin(), &IsDouble))
60         {
61 //            FatalErrorIn("tecplotWriter::writeField(..) const")
62 //                << "Error in TECDAT112." << exit(FatalError);
63         }
64     }
68 template<class Type>
69 Foam::tmp<Field<Type> > Foam::tecplotWriter::getPatchField
71     const bool nearCellValue,
72     const GeometricField<Type, fvPatchField, volMesh>& vfld,
73     const label patchI
74 ) const
76     if (nearCellValue)
77     {
78         return vfld.boundaryField()[patchI].patchInternalField();
79     }
80     else
81     {
82         return vfld.boundaryField()[patchI];
83     }
87 template<class Type>
88 Foam::tmp<Field<Type> > Foam::tecplotWriter::getFaceField
90     const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld,
91     const labelList& faceLabels
92 ) const
94     const polyBoundaryMesh& patches = sfld.mesh().boundaryMesh();
96     tmp<Field<Type> > tfld(new Field<Type>(faceLabels.size()));
97     Field<Type>& fld = tfld();
99     forAll(faceLabels, i)
100     {
101         label faceI = faceLabels[i];
103         label patchI = patches.whichPatch(faceI);
105         if (patchI == -1)
106         {
107             fld[i] = sfld[faceI];
108         }
109         else
110         {
111             label localFaceI = faceI - patches[patchI].start();
112             fld[i] = sfld.boundaryField()[patchI][localFaceI];
113         }
114     }
116     return tfld;
120 template<class GeoField>
121 Foam::wordList Foam::tecplotWriter::getNames
123     const PtrList<GeoField>& flds
126     wordList names(flds.size());
127     forAll(flds, i)
128     {
129         names[i] = flds[i].name();
130     }
131     return names;
135 template<class Type>
136 void Foam::tecplotWriter::getTecplotNames
138     const wordList& names,
139     const INTEGER4 loc,
140     string& varNames,
141     DynamicList<INTEGER4>& varLocation
144     forAll(names, i)
145     {
146         if (!varNames.empty())
147         {
148             varNames += " ";
149         }
151         label nCmpts = pTraits<Type>::nComponents;
153         if (nCmpts == 1)
154         {
155             varNames += names[i];
156             varLocation.append(loc);
157         }
158         else
159         {
160             for
161             (
162                 direction cmpt = 0;
163                 cmpt < nCmpts;
164                 cmpt++
165             )
166             {
167                 string fldName =
168                     (cmpt != 0 ? " " : string::null)
169                   + names[i]
170                   + "_"
171                   + pTraits<Type>::componentNames[cmpt];
172                 varNames += fldName;
173                 varLocation.append(loc);
174             }
175         }
176     }
180 template<class GeoField>
181 void Foam::tecplotWriter::getTecplotNames
183     const PtrList<GeoField>& flds,
184     const INTEGER4 loc,
185     string& varNames,
186     DynamicList<INTEGER4>& varLocation
189     getTecplotNames<typename GeoField::value_type>
190     (
191         getNames(flds),
192         loc,
193         varNames,
194         varLocation
195     );
199 // ************************************************************************* //