1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(graph::writer, 0);
41 defineRunTimeSelectionTable(graph::writer, word);
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void graph::readCurves(Istream& is)
49 x_.setSize(xyData.size());
50 scalarField y(xyData.size());
58 insert(yName_, new curve(yName_, curve::curveStyle::CONTINUOUS, y));
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 insert(yName, new curve(yName, curve::curveStyle::CONTINUOUS, y));
113 graph::graph(Istream& is)
123 const scalarField& graph::y() const
127 FatalErrorIn("const scalarField& graph::y() const")
128 << "y field requested for graph containing " << size()
129 << "ys" << exit(FatalError);
135 scalarField& graph::y()
139 FatalErrorIn("scalarField& graph::y()")
140 << "y field requested for graph containing " << size()
141 << "ys" << exit(FatalError);
148 autoPtr<graph::writer> graph::writer::New(const word& graphFormat)
150 if (!wordConstructorTablePtr_)
154 "graph::writer::New(const word&)"
155 ) << "Graph writer table is empty"
159 wordConstructorTable::iterator cstrIter =
160 wordConstructorTablePtr_->find(graphFormat);
162 if (cstrIter == wordConstructorTablePtr_->end())
166 "graph::writer::New(const word&)"
167 ) << "Unknown graph format " << graphFormat
169 << "Valid graph formats are : " << endl
170 << wordConstructorTablePtr_->sortedToc()
174 return autoPtr<graph::writer>(cstrIter()());
178 void graph::writer::writeXY
180 const scalarField& x,
181 const scalarField& y,
187 os << setw(10) << x[xi] << token::SPACE << setw(10) << y[xi]<< endl;
192 void graph::writeTable(Ostream& os) const
196 os << setw(10) << x_[xi];
200 graph::const_iterator iter = begin();
205 os << token::SPACE << setw(10) << (*iter())[xi];
212 void graph::write(Ostream& os, const word& format) const
214 writer::New(format)().write(*this, os);
218 void graph::write(const fileName& fName, const word& format) const
220 autoPtr<writer> graphWriter(writer::New(format));
222 OFstream graphFile(fName + '.' + graphWriter().ext());
224 if (graphFile.good())
226 write(graphFile, format);
230 WarningIn("graph::write(const word& format, const fileName& dir)")
231 << "Could not open graph file " << graphFile.name()
237 Ostream& operator<<(Ostream& os, const graph& g)
239 // Write size of list and start contents delimiter
240 os << nl << g.x().size() << nl << token::BEGIN_LIST << nl;
244 // Write end of contents delimiter
245 os << token::END_LIST;
247 os.check("Ostream& operator<<(Ostream&, const graph&)");
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 } // End namespace Foam
256 // ************************************************************************* //