1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
30 #include "OSspecific.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(graph::writer, 0);
37 defineRunTimeSelectionTable(graph::writer, word);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::graph::readCurves(Istream& is)
47 x_.setSize(xyData.size());
48 scalarField y(xyData.size());
56 insert(yName_, new curve(yName_, curve::curveStyle::CONTINUOUS, y));
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 insert(yName, new curve(yName, curve::curveStyle::CONTINUOUS, y));
111 Foam::graph::graph(Istream& is)
121 const Foam::scalarField& Foam::graph::y() const
125 FatalErrorIn("const scalarField& graph::y() const")
126 << "y field requested for graph containing " << size()
127 << "ys" << exit(FatalError);
134 Foam::scalarField& Foam::graph::y()
138 FatalErrorIn("scalarField& graph::y()")
139 << "y field requested for graph containing " << size()
140 << "ys" << exit(FatalError);
147 Foam::autoPtr<Foam::graph::writer> Foam::graph::writer::New
149 const word& graphFormat
152 if (!wordConstructorTablePtr_)
156 "graph::writer::New(const word&)"
157 ) << "Graph writer table is empty"
161 wordConstructorTable::iterator cstrIter =
162 wordConstructorTablePtr_->find(graphFormat);
164 if (cstrIter == wordConstructorTablePtr_->end())
168 "graph::writer::New(const word&)"
169 ) << "Unknown graph format " << graphFormat
171 << "Valid graph formats are : " << endl
172 << wordConstructorTablePtr_->sortedToc()
176 return autoPtr<graph::writer>(cstrIter()());
180 void Foam::graph::writer::writeXY
182 const scalarField& x,
183 const scalarField& y,
189 os << setw(10) << x[xi] << token::SPACE << setw(10) << y[xi]<< endl;
194 void Foam::graph::writeTable(Ostream& os) const
198 os << setw(10) << x_[xi];
200 forAllConstIter(graph, *this, iter)
202 os << token::SPACE << setw(10) << (*iter())[xi];
209 void Foam::graph::write(Ostream& os, const word& format) const
211 writer::New(format)().write(*this, os);
215 void Foam::graph::write(const fileName& pName, const word& format) const
217 autoPtr<writer> graphWriter(writer::New(format));
219 OFstream graphFile(pName + '.' + graphWriter().ext());
221 if (graphFile.good())
223 write(graphFile, format);
227 WarningIn("graph::write(const word& format, const fileName& dir)")
228 << "Could not open graph file " << graphFile.name()
234 void Foam::graph::write
236 const fileName& path,
242 write(path/name, format);
246 Foam::Ostream& Foam::operator<<(Ostream& os, const graph& g)
249 os.check("Ostream& operator<<(Ostream&, const graph&)");
254 // ************************************************************************* //