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

coordSet.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "coordSet.H"
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 //- Construct from components
00034 Foam::coordSet::coordSet
00035 (
00036     const word& name,
00037     const word& axis
00038 )
00039 :
00040     pointField(0),
00041     name_(name),
00042     axis_(axis),
00043     refPoint_(vector::zero)
00044 {}
00045 
00046 
00047 //- Construct from components
00048 Foam::coordSet::coordSet
00049 (
00050     const word& name,
00051     const word& axis,
00052     const List<point>& points,
00053     const point& refPoint
00054 )
00055 :
00056     pointField(points),
00057     name_(name),
00058     axis_(axis),
00059     refPoint_(refPoint)
00060 {}
00061 
00062 
00063 //- Construct from components
00064 Foam::coordSet::coordSet
00065 (
00066     const word& name,
00067     const word& axis,
00068     const scalarField& points,
00069     const scalar refPoint
00070 )
00071 :
00072     pointField(points.size(), point::zero),
00073     name_(name),
00074     axis_(axis),
00075     refPoint_(point::zero)
00076 {
00077     if (axis_ == "x" || axis_ == "distance")
00078     {
00079         refPoint_.x() = refPoint;
00080         replace(point::X, points);
00081     }
00082     else if (axis_ == "y")
00083     {
00084         replace(point::Y, points);
00085     }
00086     else if (axis_ == "z")
00087     {
00088         replace(point::Z, points);
00089     }
00090     else
00091     {
00092         FatalErrorIn
00093         (
00094             "coordSet::coordSet(const word& name,"
00095             "const word& axis, const List<scalar>& points,"
00096             "const scalar refPoint)"
00097         )   << "Illegal axis specification " << axis_
00098             << " for sampling line " << name_
00099             << exit(FatalError);
00100     }
00101 }
00102 
00103 
00104 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00105 
00106 bool Foam::coordSet::hasVectorAxis() const
00107 {
00108     return axis_ == "xyz";
00109 }
00110 
00111 
00112 Foam::scalar Foam::coordSet::scalarCoord
00113 (
00114     const label index
00115 )   const
00116 {
00117     const point& p = operator[](index);
00118 
00119     if (axis_ == "x")
00120     {
00121         return p.x();
00122     }
00123     else if (axis_ == "y")
00124     {
00125         return p.y();
00126     }
00127     else if (axis_ == "z")
00128     {
00129         return p.z();
00130     }
00131     else if (axis_ == "distance")
00132     {
00133         // Use distance to reference point
00134         return mag(p - refPoint_);
00135     }
00136     else
00137     {
00138         FatalErrorIn
00139         (
00140             "coordSet::scalarCoord(const label)"
00141         )   << "Illegal axis specification " << axis_
00142             << " for sampling line " << name_
00143             << exit(FatalError);
00144 
00145         return 0;
00146     }
00147 }
00148 
00149 
00150 Foam::point Foam::coordSet::vectorCoord(const label index) const
00151 {
00152     const point& p = operator[](index);
00153 
00154     return p;
00155 }
00156 
00157 
00158 Foam::Ostream& Foam::coordSet::write(Ostream& os) const
00159 {
00160     os  << "name:" << name_ << " axis:" << axis_ << " reference:" << refPoint_
00161         << endl
00162         << endl << "\t(coord)"
00163         << endl;
00164 
00165     forAll(*this, sampleI)
00166     {
00167         os  << '\t' << operator[](sampleI) << endl;
00168     }
00169 
00170     return os;
00171 }
00172 
00173 
00174 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd