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

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