FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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