OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

rawSurfaceWriter.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "rawSurfaceWriter.H"
00028 
00029 #include "OFstream.H"
00030 #include "OSspecific.H"
00031 #include "IOmanip.H"
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 template<class Type>
00036 void Foam::rawSurfaceWriter<Type>::writeGeometry
00037 (
00038     const pointField& points,
00039     const label pointI,
00040     Ostream& os
00041 )
00042 {
00043     const point& pt = points[pointI];
00044 
00045     os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
00046 }
00047 
00048 
00049 template<class Type>
00050 void Foam::rawSurfaceWriter<Type>::writeGeometry
00051 (
00052     const pointField& points,
00053     const faceList& faces,
00054     const label faceI,
00055     Ostream& os
00056 )
00057 {
00058     const point& ct = faces[faceI].centre(points);
00059 
00060     os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
00061 }
00062 
00063 
00064 // Write scalarField in raw format
00065 template<class Type>
00066 void Foam::rawSurfaceWriter<Type>::writeData
00067 (
00068     const fileName& fieldName,
00069     const pointField& points,
00070     const faceList& faces,
00071     const scalarField& values,
00072     Ostream& os
00073 )
00074 {
00075     // header
00076     os  << "#  x  y  z  " << fieldName << endl;
00077 
00078     // Write data
00079     if (values.size() == points.size())
00080     {
00081         forAll(values, elemI)
00082         {
00083             writeGeometry(points, elemI, os);
00084             os << values[elemI] << nl;
00085         }
00086     }
00087     else
00088     {
00089         forAll(values, elemI)
00090         {
00091             writeGeometry(points, faces, elemI, os);
00092             os << values[elemI] << nl;
00093         }
00094     }
00095 
00096     os << nl;
00097 }
00098 
00099 
00100 // Write vectorField in raw format
00101 template<class Type>
00102 void Foam::rawSurfaceWriter<Type>::writeData
00103 (
00104     const fileName& fieldName,
00105     const pointField& points,
00106     const faceList& faces,
00107     const vectorField& values,
00108     Ostream& os
00109 )
00110 {
00111     // header
00112     os  << "#  x  y  z  "
00113         << fieldName << "_x  "
00114         << fieldName << "_y  "
00115         << fieldName << "_z  "
00116         << endl;
00117 
00118     // Write data
00119     if (values.size() == points.size())
00120     {
00121         forAll(values, elemI)
00122         {
00123             writeGeometry(points, elemI, os);
00124 
00125             const vector& v = values[elemI];
00126             os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
00127         }
00128     }
00129     else
00130     {
00131         forAll(values, elemI)
00132         {
00133             writeGeometry(points, faces, elemI, os);
00134 
00135             const vector& v = values[elemI];
00136             os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
00137         }
00138     }
00139 
00140 }
00141 
00142 
00143 // Write sphericalTensorField in raw format
00144 template<class Type>
00145 void Foam::rawSurfaceWriter<Type>::writeData
00146 (
00147     const fileName& fieldName,
00148     const pointField& points,
00149     const faceList& faces,
00150     const sphericalTensorField& values,
00151     Ostream& os
00152 )
00153 {
00154     // header
00155     os  << "#  ii  ";
00156     os << fieldName << "_ii" << endl;
00157 
00158     // Write data
00159     if (values.size() == points.size())
00160     {
00161         forAll(values, elemI)
00162         {
00163             writeGeometry(points, elemI, os);
00164 
00165             const sphericalTensor& v = values[elemI];
00166             os  << v[0] << nl;
00167         }
00168     }
00169     else
00170     {
00171         forAll(values, elemI)
00172         {
00173             writeGeometry(points, faces, elemI, os);
00174 
00175             const sphericalTensor& v = values[elemI];
00176             os  << v[0] << nl;
00177         }
00178     }
00179 }
00180 
00181 
00182 // Write symmTensorField in raw format
00183 template<class Type>
00184 void Foam::rawSurfaceWriter<Type>::writeData
00185 (
00186     const fileName& fieldName,
00187     const pointField& points,
00188     const faceList& faces,
00189     const symmTensorField& values,
00190     Ostream& os
00191 )
00192 {
00193     // header
00194     os  << "#  xx  xy  xz  yy  yz ";
00195     for(int i=0; i<6; i++)
00196     {
00197         os << fieldName << "_" << i << "  ";
00198     }
00199     os << endl;
00200 
00201     // Write data
00202     if (values.size() == points.size())
00203     {
00204         forAll(values, elemI)
00205         {
00206             writeGeometry(points, elemI, os);
00207 
00208             const symmTensor& v = values[elemI];
00209 
00210             os  << v[0] << ' ' << v[1] << ' ' << v[2]
00211                 << v[3] << ' ' << v[4] << ' ' << v[5]
00212                 << nl;
00213         }
00214     }
00215     else
00216     {
00217         forAll(values, elemI)
00218         {
00219             writeGeometry(points, faces, elemI, os);
00220 
00221             const symmTensor& v = values[elemI];
00222 
00223             os  << v[0] << ' ' << v[1] << ' ' << v[2]
00224                 << v[3] << ' ' << v[4] << ' ' << v[5]
00225                 << nl;
00226         }
00227     }
00228 }
00229 
00230 
00231 // Write tensorField in raw format
00232 template<class Type>
00233 void Foam::rawSurfaceWriter<Type>::writeData
00234 (
00235     const fileName& fieldName,
00236     const pointField& points,
00237     const faceList& faces,
00238     const tensorField& values,
00239     Ostream& os
00240 )
00241 {
00242     // header
00243     os  << "#  xx  xy  xz  yx  yy  yz  zx  zy  zz";
00244     for (int i=0; i<9; ++i)
00245     {
00246         os << fieldName << "_" << i << "  ";
00247     }
00248     os << endl;
00249 
00250     // Write data
00251     if (values.size() == points.size())
00252     {
00253         forAll(values, elemI)
00254         {
00255             writeGeometry(points, elemI, os);
00256 
00257             const tensor& v = values[elemI];
00258             os  << v[0] << ' ' << v[1] << ' ' << v[2]
00259                 << v[3] << ' ' << v[4] << ' ' << v[5]
00260                 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
00261         }
00262     }
00263     else
00264     {
00265         forAll(values, elemI)
00266         {
00267             writeGeometry(points, faces, elemI, os);
00268 
00269             const tensor& v = values[elemI];
00270             os  << v[0] << ' ' << v[1] << ' ' << v[2]
00271                 << v[3] << ' ' << v[4] << ' ' << v[5]
00272                 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
00273         }
00274     }
00275 }
00276 
00277 
00278 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00279 
00280 template<class Type>
00281 Foam::rawSurfaceWriter<Type>::rawSurfaceWriter()
00282 :
00283     surfaceWriter<Type>()
00284 {}
00285 
00286 
00287 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00288 
00289 template<class Type>
00290 Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter()
00291 {}
00292 
00293 
00294 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00295 
00296 template<class Type>
00297 void Foam::rawSurfaceWriter<Type>::write
00298 (
00299     const fileName& outputDir,
00300     const fileName& surfaceName,
00301     const pointField& points,
00302     const faceList& faces,
00303     const bool verbose
00304 ) const
00305 {
00306     if (!isDir(outputDir))
00307     {
00308         mkDir(outputDir);
00309     }
00310 
00311     OFstream os
00312     (
00313         outputDir/surfaceName + ".raw"
00314     );
00315 
00316     if (verbose)
00317     {
00318         Info<< "Writing geometry to " << os.name() << endl;
00319     }
00320 
00321 
00322     // header
00323     os  << "# geometry NO_DATA " << faces.size() << nl
00324         << "#  x  y  z" << endl;
00325 
00326     // Write faces
00327     forAll(faces, elemI)
00328     {
00329         writeGeometry(points, faces, elemI, os);
00330         os << nl;
00331     }
00332 
00333     os << nl;
00334 }
00335 
00336 
00337 namespace Foam
00338 {
00339     // bool fields aren't supported
00340     template<>
00341     void Foam::rawSurfaceWriter<bool>::write
00342     (
00343         const fileName& outputDir,
00344         const fileName& surfaceName,
00345         const pointField& points,
00346         const faceList& faces,
00347         const fileName& fieldName,
00348         const Field<bool>& values,
00349         const bool verbose
00350     ) const
00351     {}
00352 }
00353 
00354 
00355 template<class Type>
00356 void Foam::rawSurfaceWriter<Type>::write
00357 (
00358     const fileName& outputDir,
00359     const fileName& surfaceName,
00360     const pointField& points,
00361     const faceList& faces,
00362     const fileName& fieldName,
00363     const Field<Type>& values,
00364     const bool verbose
00365 ) const
00366 {
00367     if (!isDir(outputDir))
00368     {
00369         mkDir(outputDir);
00370     }
00371 
00372     OFstream os
00373     (
00374         outputDir/fieldName + '_' + surfaceName + ".raw"
00375     );
00376 
00377     if (verbose)
00378     {
00379         Info<< "Writing field " << fieldName << " to " << os.name() << endl;
00380     }
00381 
00382 
00383     // header
00384     os  << "# " << fieldName;
00385     if (values.size() == points.size())
00386     {
00387         os  << "  POINT_DATA ";
00388     }
00389     else
00390     {
00391         os  << "  FACE_DATA ";
00392     }
00393 
00394     os  << values.size() << nl;
00395 
00396     writeData(fieldName, points, faces, values, os);
00397 }
00398 
00399 
00400 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd