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

toroidalCS.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "toroidalCS.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/mathematicalConstants.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(toroidalCS, 0);
00035     addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
00036 }
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 
00041 Foam::toroidalCS::toroidalCS
00042 (
00043     const word& name,
00044     const point& origin,
00045     const coordinateRotation& cr,
00046     const scalar radius
00047 )
00048 :
00049     coordinateSystem(name, origin, cr),
00050     radius_(radius)
00051 {}
00052 
00053 
00054 Foam::toroidalCS::toroidalCS
00055 (
00056     const word& name,
00057     const dictionary& dict
00058 )
00059 :
00060     coordinateSystem(name, dict),
00061     radius_(readScalar(dict.lookup("radius")))
00062 {}
00063 
00064 
00065 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00066 
00067 Foam::vector Foam::toroidalCS::localToGlobal
00068 (
00069     const vector& local,
00070     bool translate
00071 ) const
00072 {
00073     // Notation: r = local.x()
00074     scalar theta = local.y()*mathematicalConstant::pi/180.0;
00075     scalar phi = local.z()*mathematicalConstant::pi/180.0;
00076 
00077     scalar rprime = radius_ + local.x()*sin(phi);
00078 
00079     if ((local.x()*sin(phi)) > (radius_))
00080     {
00081         FatalErrorIn("toroidalCS::toGlobal(vector) const")
00082             << "Badly defined toroidal coordinates"
00083             << abort(FatalError);
00084     }
00085 
00086     return coordinateSystem::localToGlobal
00087     (
00088         vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
00089         translate
00090     );
00091 }
00092 
00093 
00094 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
00095 (
00096     const vectorField& local,
00097     bool translate
00098 ) const
00099 {
00100     const scalarField r = local.component(vector::X);
00101 
00102     const scalarField theta =
00103         local.component(vector::Y)*mathematicalConstant::pi/180.0;
00104 
00105     const scalarField phi =
00106         local.component(vector::Z)*mathematicalConstant::pi/180.0;
00107 
00108     const scalarField rprime = radius_ + r*sin(phi);
00109 
00110     vectorField lc(local.size());
00111     lc.replace(vector::X, rprime*cos(theta));
00112     lc.replace(vector::Y, rprime*sin(theta));
00113     lc.replace(vector::Z, r*cos(phi));
00114 
00115     return coordinateSystem::localToGlobal(lc, translate);
00116 }
00117 
00118 
00119 Foam::vector Foam::toroidalCS::globalToLocal
00120 (
00121     const vector& global,
00122     bool translate
00123 ) const
00124 {
00125     notImplemented
00126     (
00127         "toroidalCS::globalToLocal(const vector&, bool) const"
00128     );
00129 
00130     return vector::zero;
00131 }
00132 
00133 
00134 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
00135 (
00136     const vectorField& global,
00137     bool translate
00138 ) const
00139 {
00140     notImplemented
00141     (
00142         "toroidalCS::globalToLocal(const vectorField&, bool) const"
00143     );
00144 
00145     return tmp<vectorField>(vectorField::null());
00146 }
00147 
00148 
00149 void Foam::toroidalCS::write(Ostream& os) const
00150 {
00151     coordinateSystem::write(os);
00152     os << "radius: " << radius() << endl;
00153 }
00154 
00155 
00156 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
00157 {
00158     if (subDict)
00159     {
00160     os  << indent << name() << nl
00161         << indent << token::BEGIN_BLOCK << incrIndent << nl;
00162     }
00163 
00164     coordinateSystem::writeDict(os, false);
00165     os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
00166 
00167     if (subDict)
00168     {
00169     os << decrIndent << indent << token::END_BLOCK << endl;
00170     }
00171 }
00172 
00173 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines