FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

ensightOutputFunctions.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "ensightOutputFunctions.H"
00027 
00028 #include <lagrangian/passiveParticle.H>
00029 #include <OpenFOAM/IOField.H>
00030 #include <finiteVolume/volFields.H>
00031 #include <finiteVolume/surfaceFields.H>
00032 
00033 #include <OpenFOAM/OFstream.H>
00034 #include <OpenFOAM/IOmanip.H>
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00040 
00041 void ensightCaseEntry
00042 (
00043     OFstream& caseFile,
00044     const string& ensightType,
00045     const word& fieldName,
00046     const fileName& dataMask,
00047     const fileName& local,
00048     const label cloudNo,
00049     const label timeSet
00050 )
00051 {
00052     caseFile.setf(ios_base::left);
00053 
00054     fileName dirName(dataMask);
00055     if (local.size())
00056     {
00057         dirName = dirName/local;
00058     }
00059 
00060     if (cloudNo >= 0)
00061     {
00062         label ts = 1;
00063         if (timeSet > ts)
00064         {
00065             ts = timeSet;
00066         }
00067 
00068         // prefix variables with 'c' (cloud)
00069         caseFile
00070             << ensightType.c_str()
00071             << " per measured node: " << ts << " "
00072             << setw(15)
00073             << ("c" + Foam::name(cloudNo) + fieldName).c_str()
00074             << " "
00075             << (dirName/fieldName).c_str()
00076             << nl;
00077     }
00078     else
00079     {
00080         caseFile
00081             << ensightType.c_str()
00082             << " per element: "
00083             << setw(15) << fieldName
00084             << " "
00085             << (dirName/fieldName).c_str()
00086             << nl;
00087     }
00088 }
00089 
00090 
00091 void ensightParticlePositions
00092 (
00093     const polyMesh& mesh,
00094     const fileName& dataDir,
00095     const fileName& subDir,
00096     const word& cloudName,
00097     IOstream::streamFormat format
00098 )
00099 {
00100     Cloud<passiveParticle> parcels(mesh, cloudName, false);
00101 
00102     fileName cloudDir = subDir/cloud::prefix/cloudName;
00103     fileName postFileName = cloudDir/"positions";
00104 
00105     // the ITER/lagrangian subdirectory must exist
00106     mkDir(dataDir/cloudDir);
00107     ensightFile os(dataDir/postFileName, format);
00108 
00109     // tag binary format (just like geometry files)
00110     os.writeBinaryHeader();
00111     os.write(postFileName);
00112     os.newline();
00113     os.write("particle coordinates");
00114     os.newline();
00115     os.write(parcels.size(), 8);    // unusual width
00116     os.newline();
00117 
00118     // binary write is Ensight6 - first ids, then positions
00119     if (format == IOstream::BINARY)
00120     {
00121         forAll (parcels, i)
00122         {
00123             os.write(i+1);
00124         }
00125 
00126         forAllIter(Cloud<passiveParticle>, parcels, elmnt)
00127         {
00128             const vector& p = elmnt().position();
00129 
00130             os.write(p.x());
00131             os.write(p.y());
00132             os.write(p.z());
00133         }
00134     }
00135     else
00136     {
00137         label nParcels = 0;
00138 
00139         forAllIter(Cloud<passiveParticle>, parcels, elmnt)
00140         {
00141             const vector& p = elmnt().position();
00142 
00143             os.write(++nParcels, 8);    // unusual width
00144             os.write(p.x());
00145             os.write(p.y());
00146             os.write(p.z());
00147             os.newline();
00148         }
00149     }
00150 }
00151 
00152 
00153 
00154 template<class Type>
00155 void ensightLagrangianField
00156 (
00157     const IOobject& fieldObject,
00158     const fileName& dataDir,
00159     const fileName& subDir,
00160     const word& cloudName,
00161     IOstream::streamFormat format
00162 )
00163 {
00164     Info<< " " << fieldObject.name() << flush;
00165 
00166     fileName cloudDir = subDir/cloud::prefix/cloudName;
00167     fileName postFileName = cloudDir/fieldObject.name();
00168 
00169     string title =
00170         postFileName + " with " + pTraits<Type>::typeName + " values";
00171 
00172     ensightFile os(dataDir/postFileName, format);
00173     os.write(title);
00174     os.newline();
00175 
00176     IOField<Type> field(fieldObject);
00177 
00178     // 6 values per line
00179     label count = 0;
00180 
00181     forAll(field, i)
00182     {
00183         Type val = field[i];
00184 
00185         if (mag(val) < 1.0e-90)
00186         {
00187             val = pTraits<Type>::zero;
00188         }
00189 
00190         for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
00191         {
00192             os.write( component(val, cmpt) );
00193         }
00194 
00195         count += pTraits<Type>::nComponents;
00196 
00197         if (count % 6 == 0)
00198         {
00199             os.newline();
00200         }
00201     }
00202 
00203     // add final newline if required
00204     if (count % 6)
00205     {
00206         os.newline();
00207     }
00208 }
00209 
00210 
00211 //- write generalized field components
00212 template <class Type>
00213 void ensightVolField
00214 (
00215     const ensightParts& partsList,
00216     const IOobject& fieldObject,
00217     const fvMesh& mesh,
00218     const fileName& dataDir,
00219     const fileName& subDir,
00220     IOstream::streamFormat format
00221 )
00222 {
00223     Info<< " " << fieldObject.name() << flush;
00224 
00225     fileName postFileName = subDir/fieldObject.name();
00226 
00227     ensightFile os(dataDir/postFileName, format);
00228     os.write(postFileName);
00229     os.newline();
00230 
00231     // ie, volField<Type>
00232     partsList.writeField
00233     (
00234         os,
00235         GeometricField<Type, fvPatchField, volMesh>
00236         (
00237             fieldObject,
00238             mesh
00239         )
00240     );
00241 }
00242 
00243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00244 
00245 } // namespace Foam
00246 
00247 
00248 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines