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

writeDX.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 Description
00025     OpenDX format. Both data-only and scalar/vector data.
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include <triSurface/triSurface.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00037 
00038 // Geometry (positions + connections)
00039 // writeSorted: sort acc. to patch
00040 void triSurface::writeDXGeometry
00041 (
00042     const bool writeSorted,
00043     Ostream& os
00044 ) const
00045 {
00046     labelList faceMap;
00047     surfacePatchList myPatches(calcPatches(faceMap));
00048 
00049     // Print patch names as comment
00050     os  << "# Patches:" << endl;
00051     forAll(myPatches, patchI)
00052     {
00053         os  << "#     " << patchI << "    "
00054             << myPatches[patchI].name() << endl;
00055     }
00056     os << endl << endl;
00057 
00058     // Write vertex coordinates
00059 
00060     os  << "# The irregular positions" << endl
00061         << "object 1 class array type float rank 1 shape 3 items "
00062         << nPoints() << " data follows" << endl;
00063     forAll(localPoints(), pointI)
00064     {
00065         const point& pt = localPoints()[pointI];
00066         os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
00067     }
00068     os  << endl;
00069 
00070     os  << "# The irregular connections (triangles)" << endl
00071         << "object 2 class array type int rank 1 shape 3 items "
00072         << size() << " data follows" << endl;
00073 
00074     if (writeSorted)
00075     {
00076         label faceIndex = 0;
00077 
00078         forAll(myPatches, patchI)
00079         {
00080             // Print all faces belonging to this patch
00081 
00082             for
00083             (
00084                 label patchFaceI = 0;
00085                 patchFaceI < myPatches[patchI].size();
00086                 patchFaceI++
00087             )
00088             {
00089                 const label faceI = faceMap[faceIndex++];
00090 
00091                 const labelledTri& f = localFaces()[faceI];
00092 
00093                 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00094             }
00095         }
00096     }
00097     else
00098     {
00099         forAll(*this, faceI)
00100         {
00101             const labelledTri& f = localFaces()[faceI];
00102 
00103             os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00104         }
00105     }
00106     os << "attribute \"element type\" string \"triangles\"" << endl
00107        << "attribute \"ref\" string \"positions\"" << endl << endl;
00108 }
00109 
00110 
00111 // Standard trailer
00112 void triSurface::writeDXTrailer(Ostream& os) const
00113 {
00114     os  << "# the field, with three components: \"positions\", \"connections\""
00115         << ", and \"data\"" << endl
00116         << "object \"irregular positions irregular connections\" class field"
00117         << endl
00118         << "component \"positions\" value 1" << endl
00119         << "component \"connections\" value 2" << endl
00120         << "component \"data\" value 3" << endl;
00121 }
00122 
00123 
00124 // Geometry only (data field is either faceIndex or patchIndex)
00125 void triSurface::writeDX(const bool writeSorted, Ostream& os) const
00126 {
00127     writeDXGeometry(writeSorted, os);
00128 
00129     os  << "object 3 class array type float rank 0 items " << size()
00130         << " data follows" << endl;
00131     if (writeSorted)
00132     {
00133         // Write patch number as data
00134 
00135         labelList faceMap;
00136         surfacePatchList myPatches(calcPatches(faceMap));
00137 
00138         forAll(myPatches, patchI)
00139         {
00140             forAll(myPatches[patchI], patchFaceI)
00141             {
00142                 os << patchI << endl;
00143             }
00144         }
00145     }
00146     else
00147     {
00148         // Write face number as data
00149 
00150         forAll(*this, faceI)
00151         {
00152             os << faceI << endl;
00153         }
00154     }
00155 
00156     os  << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
00157 
00158     writeDXTrailer(os);
00159 
00160     os << "end" << endl;
00161 }
00162 
00163 
00164 // Geometry + scalar data
00165 void triSurface::writeDX(const scalarField& field, Ostream& os) const
00166 {
00167     writeDXGeometry(false, os);
00168 
00169     if (field.size() == size())
00170     {
00171         // Connections dependent data
00172         os  << "object 3 class array type float rank 0 items " << field.size()
00173             << " data follows" << endl;
00174         forAll(field, faceI)
00175         {
00176             os << field[faceI] << endl;
00177         }
00178         os  << endl
00179             << "attribute \"dep\" string \"connections\"" << endl << endl;
00180     }
00181     else if (field.size() == nPoints())
00182     {
00183         // Positions dependent data
00184         os  << "object 3 class array type float rank 0 items " << field.size()
00185             << " data follows" << endl;
00186         forAll(field, pointI)
00187         {
00188             os << field[pointI] << endl;
00189         }
00190         os  << endl
00191             << "attribute \"dep\" string \"positions\"" << endl << endl;
00192     }
00193     else
00194     {
00195         FatalErrorIn
00196         (
00197             "writeDX(const scalarField&, Ostream&)"
00198         )   << "Illegal field size " << field.size() << " is not equal "
00199             << " to number of faces " << size() << " or to number "
00200             << " of points " << nPoints() << exit(FatalError);
00201     }
00202 
00203     writeDXTrailer(os);
00204 
00205     os << "end" << endl;
00206 }
00207 
00208 
00209 // Geometry + vector data
00210 void triSurface::writeDX(const vectorField& field, Ostream& os) const
00211 {
00212     writeDXGeometry(false, os);
00213 
00214     if (field.size() == size())
00215     {
00216         // Connections dependent data
00217         os  << "object 3 class array type float rank 1 shape 3 items "
00218             << field.size() << " data follows" << endl;
00219         forAll(field, faceI)
00220         {
00221             os  << field[faceI].x() << ' '
00222                 << field[faceI].y() << ' '
00223                 << field[faceI].z() << endl;
00224         }
00225         os  << endl
00226             << "attribute \"dep\" string \"connections\"" << endl << endl;
00227     }
00228     else if (field.size() == nPoints())
00229     {
00230         // Positions dependent data
00231         os  << "object 3 class array type float rank 1 shape 3 items "
00232             << field.size() << " data follows" << endl;
00233         forAll(field, pointI)
00234         {
00235             os  << field[pointI].x() << ' '
00236                 << field[pointI].y() << ' '
00237                 << field[pointI].z() << endl;
00238         }
00239         os  << endl
00240             << "attribute \"dep\" string \"positions\"" << endl << endl;
00241     }
00242     else
00243     {
00244         FatalErrorIn
00245         (
00246             "writeDX(const vectorField&, Ostream&)"
00247         )   << "Illegal field size " << field.size() << " is not equal "
00248             << " to number of faces " << size() << " or to number "
00249             << " of points " << nPoints() << exit(FatalError);
00250     }
00251 
00252     writeDXTrailer(os);
00253 
00254     os << "end" << endl;
00255 }
00256 
00257 
00258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00259 
00260 } // End namespace Foam
00261 
00262 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines