FreeFOAM The Cross-Platform CFD Toolkit
coordSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include <sampling/coordSet.H>
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 //- Construct from components
34 (
35  const word& name,
36  const word& axis
37 )
38 :
39  pointField(0),
40  name_(name),
41  axis_(axis),
42  refPoint_(vector::zero)
43 {}
44 
45 
46 //- Construct from components
48 (
49  const word& name,
50  const word& axis,
51  const List<point>& points,
52  const point& refPoint
53 )
54 :
55  pointField(points),
56  name_(name),
57  axis_(axis),
58  refPoint_(refPoint)
59 {}
60 
61 
62 //- Construct from components
64 (
65  const word& name,
66  const word& axis,
67  const scalarField& points,
68  const scalar refPoint
69 )
70 :
71  pointField(points.size(), point::zero),
72  name_(name),
73  axis_(axis),
74  refPoint_(point::zero)
75 {
76  if (axis_ == "x" || axis_ == "distance")
77  {
78  refPoint_.x() = refPoint;
79  replace(point::X, points);
80  }
81  else if (axis_ == "y")
82  {
83  replace(point::Y, points);
84  }
85  else if (axis_ == "z")
86  {
87  replace(point::Z, points);
88  }
89  else
90  {
92  (
93  "coordSet::coordSet(const word& name,"
94  "const word& axis, const List<scalar>& points,"
95  "const scalar refPoint)"
96  ) << "Illegal axis specification " << axis_
97  << " for sampling line " << name_
98  << exit(FatalError);
99  }
100 }
101 
102 
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 
106 {
107  return axis_ == "xyz";
108 }
109 
110 
111 Foam::scalar Foam::coordSet::scalarCoord
112 (
113  const label index
114 ) const
115 {
116  const point& p = operator[](index);
117 
118  if (axis_ == "x")
119  {
120  return p.x();
121  }
122  else if (axis_ == "y")
123  {
124  return p.y();
125  }
126  else if (axis_ == "z")
127  {
128  return p.z();
129  }
130  else if (axis_ == "distance")
131  {
132  // Use distance to reference point
133  return mag(p - refPoint_);
134  }
135  else
136  {
138  (
139  "coordSet::scalarCoord(const label)"
140  ) << "Illegal axis specification " << axis_
141  << " for sampling line " << name_
142  << exit(FatalError);
143 
144  return 0;
145  }
146 }
147 
148 
149 Foam::point Foam::coordSet::vectorCoord(const label index) const
150 {
151  const point& p = operator[](index);
152 
153  return p;
154 }
155 
156 
158 {
159  os << "name:" << name_ << " axis:" << axis_ << " reference:" << refPoint_
160  << endl
161  << endl << "\t(coord)"
162  << endl;
163 
164  forAll(*this, sampleI)
165  {
166  os << '\t' << operator[](sampleI) << endl;
167  }
168 
169  return os;
170 }
171 
172 
173 // ************************ vim: set sw=4 sts=4 et: ************************ //