ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / src / meshTools / coordinateSystems / toroidalCS.C
blob23b27bd0a8fe46147b63dd1d99e54acd99e042c4
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.
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.
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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "toroidalCS.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(toroidalCS, 0);
35     addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 Foam::toroidalCS::toroidalCS
43     const word& name,
44     const point& origin,
45     const coordinateRotation& cr,
46     const scalar radius
49     coordinateSystem(name, origin, cr),
50     radius_(radius)
54 Foam::toroidalCS::toroidalCS
56     const word& name,
57     const dictionary& dict
60     coordinateSystem(name, dict),
61     radius_(readScalar(dict.lookup("radius")))
65 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
67 Foam::vector Foam::toroidalCS::localToGlobal
69     const vector& local,
70     bool translate
71 ) const
73     // Notation: r = local.x()
74     scalar theta = local.y()*mathematicalConstant::pi/180.0;
75     scalar phi = local.z()*mathematicalConstant::pi/180.0;
77     scalar rprime = radius_ + local.x()*sin(phi);
79     if ((local.x()*sin(phi)) > (radius_))
80     {
81         FatalErrorIn("toroidalCS::toGlobal(vector) const")
82             << "Badly defined toroidal coordinates"
83             << abort(FatalError);
84     }
86     return coordinateSystem::localToGlobal
87     (
88         vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
89         translate
90     );
94 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
96     const vectorField& local,
97     bool translate
98 ) const
100     const scalarField r = local.component(vector::X);
102     const scalarField theta =
103         local.component(vector::Y)*mathematicalConstant::pi/180.0;
105     const scalarField phi =
106         local.component(vector::Z)*mathematicalConstant::pi/180.0;
108     const scalarField rprime = radius_ + r*sin(phi);
110     vectorField lc(local.size());
111     lc.replace(vector::X, rprime*cos(theta));
112     lc.replace(vector::Y, rprime*sin(theta));
113     lc.replace(vector::Z, r*cos(phi));
115     return coordinateSystem::localToGlobal(lc, translate);
119 Foam::vector Foam::toroidalCS::globalToLocal
121     const vector& global,
122     bool translate
123 ) const
125     notImplemented
126     (
127         "toroidalCS::globalToLocal(const vector&, bool) const"
128     );
130     return vector::zero;
134 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
136     const vectorField& global,
137     bool translate
138 ) const
140     notImplemented
141     (
142         "toroidalCS::globalToLocal(const vectorField&, bool) const"
143     );
145     return tmp<vectorField>(vectorField::null());
149 void Foam::toroidalCS::write(Ostream& os) const
151     coordinateSystem::write(os);
152     os << "radius: " << radius() << endl;
156 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
158     if (subDict)
159     {
160         os  << indent << name() << nl
161             << indent << token::BEGIN_BLOCK << incrIndent << nl;
162     }
164     coordinateSystem::writeDict(os, false);
165     os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
167     if (subDict)
168     {
169         os << decrIndent << indent << token::END_BLOCK << endl;
170     }
173 // ************************************************************************* //