initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSet / coordSet / coordSet.C
blob6a81415457c11a990ec93c912d94145d2aef3bd4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "coordSet.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 //- Construct from components
34 Foam::coordSet::coordSet
36     const word& name,
37     const word& axis
40     pointField(0),
41     name_(name),
42     axis_(axis),
43     refPoint_(vector::zero)
47 //- Construct from components
48 Foam::coordSet::coordSet
50     const word& name,
51     const word& axis,
52     const List<point>& points,
53     const point& refPoint
56     pointField(points),
57     name_(name),
58     axis_(axis),
59     refPoint_(refPoint)
63 //- Construct from components
64 Foam::coordSet::coordSet
66     const word& name,
67     const word& axis,
68     const scalarField& points,
69     const scalar refPoint
72     pointField(points.size(), point::zero),
73     name_(name),
74     axis_(axis),
75     refPoint_(point::zero)
77     if (axis_ == "x" || axis_ == "distance")
78     {
79         refPoint_.x() = refPoint;
80         replace(point::X, points);
81     }
82     else if (axis_ == "y")
83     {
84         replace(point::Y, points);
85     }
86     else if (axis_ == "z")
87     {
88         replace(point::Z, points);
89     }
90     else
91     {
92         FatalErrorIn
93         (
94             "coordSet::coordSet(const word& name,"
95             "const word& axis, const List<scalar>& points,"
96             "const scalar refPoint)"
97         )   << "Illegal axis specification " << axis_
98             << " for sampling line " << name_
99             << exit(FatalError);
100     }
104 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
106 bool Foam::coordSet::hasVectorAxis() const
108     return axis_ == "xyz";
112 Foam::scalar Foam::coordSet::scalarCoord
114     const label index
115 )   const
117     const point& p = operator[](index);
119     if (axis_ == "x")
120     {
121         return p.x();
122     }
123     else if (axis_ == "y")
124     {
125         return p.y();
126     }
127     else if (axis_ == "z")
128     {
129         return p.z();
130     }
131     else if (axis_ == "distance")
132     {
133         // Use distance to reference point
134         return mag(p - refPoint_);
135     }
136     else
137     {
138         FatalErrorIn
139         (
140             "coordSet::scalarCoord(const label)"
141         )   << "Illegal axis specification " << axis_
142             << " for sampling line " << name_
143             << exit(FatalError);
145         return 0;
146     }
150 Foam::point Foam::coordSet::vectorCoord(const label index) const
152     const point& p = operator[](index);
154     return p;
158 Foam::Ostream& Foam::coordSet::write(Ostream& os) const
160     os  << "name:" << name_ << " axis:" << axis_ << " reference:" << refPoint_
161         << endl
162         << endl << "\t(coord)"
163         << endl;
165     forAll(*this, sampleI)
166     {
167         os  << '\t' << operator[](sampleI) << endl;
168     }
170     return os;
174 // ************************************************************************* //