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

writer.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-2011 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 "writer.H"
00027 #include <sampling/coordSet.H>
00028 #include <OpenFOAM/OFstream.H>
00029 #include <OpenFOAM/OSspecific.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 Foam::autoPtr<Foam::writer<Type> > Foam::writer<Type>::New
00035 (
00036     const word& writeType
00037 )
00038 {
00039     typename wordConstructorTable::iterator cstrIter =
00040         wordConstructorTablePtr_
00041             ->find(writeType);
00042 
00043     if (cstrIter == wordConstructorTablePtr_->end())
00044     {
00045         FatalErrorIn
00046         (
00047             "writer::New(const word&)"
00048         )   << "Unknown write type " << writeType
00049             << nl << nl
00050             << "Valid write types : " << nl
00051             << wordConstructorTablePtr_->sortedToc()
00052             << exit(FatalError);
00053     }
00054 
00055     return autoPtr<writer<Type> >(cstrIter()());
00056 }
00057 
00058 
00059 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00060 
00061 template<class Type>
00062 Foam::fileName Foam::writer<Type>::getBaseName
00063 (
00064     const coordSet& points,
00065     const wordList& valueSets
00066 ) const
00067 {
00068     fileName fName(points.name());
00069 
00070     forAll(valueSets, i)
00071     {
00072         fName += '_' + valueSets[i];
00073     }
00074 
00075     return fName;
00076 }
00077 
00078 
00079 template<class Type>
00080 void Foam::writer<Type>::writeCoord
00081 (
00082     const coordSet& points,
00083     const label pointI,
00084     Ostream& os
00085 ) const
00086 {
00087     if (points.hasVectorAxis())
00088     {
00089         write(points.vectorCoord(pointI), os);
00090     }
00091     else
00092     {
00093         write(points.scalarCoord(pointI), os);
00094     }
00095 }
00096 
00097 
00098 template<class Type>
00099 void Foam::writer<Type>::writeTable
00100 (
00101     const coordSet& points,
00102     const List<Type>& values,
00103     Ostream& os
00104 ) const
00105 {
00106     forAll(points, pointI)
00107     {
00108         writeCoord(points, pointI, os);
00109         writeSeparator(os);
00110         write(values[pointI], os);
00111         os << nl;
00112     }
00113 }
00114 
00115 
00116 template<class Type>
00117 void Foam::writer<Type>::writeTable
00118 (
00119     const coordSet& points,
00120     const List<const List<Type>*>& valuesPtrList,
00121     Ostream& os
00122 ) const
00123 {
00124     forAll(points, pointI)
00125     {
00126         writeCoord(points, pointI, os);
00127 
00128         forAll(valuesPtrList, i)
00129         {
00130             writeSeparator(os);
00131 
00132             const List<Type>& values = *valuesPtrList[i];
00133             write(values[pointI], os);
00134         }
00135         os << nl;
00136     }
00137 }
00138 
00139 
00140 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00141 
00142 template<class Type>
00143 Foam::writer<Type>::writer()
00144 {}
00145 
00146 
00147 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00148 
00149 template<class Type>
00150 Foam::writer<Type>::~writer()
00151 {}
00152 
00153 
00154 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00155 
00156 template<class Type>
00157 Foam::Ostream& Foam::writer<Type>::write
00158 (
00159     const scalar value,
00160     Ostream& os
00161 ) const
00162 {
00163     return os << value;
00164 }
00165 
00166 
00167 template<class Type>
00168 template<class VSType>
00169 Foam::Ostream& Foam::writer<Type>::writeVS
00170 (
00171     const VSType& value,
00172     Ostream& os
00173 ) const
00174 {
00175     for (direction d=0; d<VSType::nComponents; d++)
00176     {
00177         if (d > 0)
00178         {
00179             writeSeparator(os);
00180         }
00181 
00182         os << value.component(d);
00183     }
00184     return os;
00185 }
00186 
00187 
00188 template<class Type>
00189 void Foam::writer<Type>::writeSeparator
00190 (
00191     Ostream& os
00192 ) const
00193 {
00194     os << token::SPACE << token::TAB;
00195 }
00196 
00197 
00198 template<class Type>
00199 Foam::Ostream& Foam::writer<Type>::write
00200 (
00201     const vector& value,
00202     Ostream& os
00203 ) const
00204 {
00205     return writeVS(value, os);
00206 }
00207 
00208 
00209 template<class Type>
00210 Foam::Ostream& Foam::writer<Type>::write
00211 (
00212     const sphericalTensor& value,
00213     Ostream& os
00214 ) const
00215 {
00216     return writeVS(value, os);
00217 }
00218 
00219 
00220 template<class Type>
00221 Foam::Ostream& Foam::writer<Type>::write
00222 (
00223     const symmTensor& value,
00224     Ostream& os
00225 ) const
00226 {
00227     return writeVS(value, os);
00228 }
00229 
00230 
00231 template<class Type>
00232 Foam::Ostream& Foam::writer<Type>::write
00233 (
00234     const tensor& value,
00235     Ostream& os
00236 ) const
00237 {
00238     return writeVS(value, os);
00239 }
00240 
00241 
00242 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines