FreeFOAM The Cross-Platform CFD Toolkit
toroidalCS.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 \*---------------------------------------------------------------------------*/
25 
26 #include "toroidalCS.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(toroidalCS, 0);
35  addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
36 }
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
40 
42 (
43  const word& name,
44  const point& origin,
45  const coordinateRotation& cr,
46  const scalar radius
47 )
48 :
49  coordinateSystem(name, origin, cr),
50  radius_(radius)
51 {}
52 
53 
55 (
56  const word& name,
57  const dictionary& dict
58 )
59 :
60  coordinateSystem(name, dict),
61  radius_(readScalar(dict.lookup("radius")))
62 {}
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
67 Foam::vector Foam::toroidalCS::localToGlobal
68 (
69  const vector& local,
70  bool translate
71 ) const
72 {
73  // Notation: r = local.x()
74  scalar theta = local.y()*mathematicalConstant::pi/180.0;
75  scalar phi = local.z()*mathematicalConstant::pi/180.0;
76 
77  scalar rprime = radius_ + local.x()*sin(phi);
78 
79  if ((local.x()*sin(phi)) > (radius_))
80  {
81  FatalErrorIn("toroidalCS::toGlobal(vector) const")
82  << "Badly defined toroidal coordinates"
83  << abort(FatalError);
84  }
85 
87  (
88  vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
89  translate
90  );
91 }
92 
93 
94 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
95 (
96  const vectorField& local,
97  bool translate
98 ) const
99 {
100  const scalarField r = local.component(vector::X);
101 
102  const scalarField theta =
104 
105  const scalarField phi =
107 
108  const scalarField rprime = radius_ + r*sin(phi);
109 
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));
114 
115  return coordinateSystem::localToGlobal(lc, translate);
116 }
117 
118 
119 Foam::vector Foam::toroidalCS::globalToLocal
120 (
121  const vector& global,
122  bool translate
123 ) const
124 {
126  (
127  "toroidalCS::globalToLocal(const vector&, bool) const"
128  );
129 
130  return vector::zero;
131 }
132 
133 
134 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
135 (
136  const vectorField& global,
137  bool translate
138 ) const
139 {
141  (
142  "toroidalCS::globalToLocal(const vectorField&, bool) const"
143  );
144 
145  return tmp<vectorField>(vectorField::null());
146 }
147 
148 
150 {
152  os << "radius: " << radius() << endl;
153 }
154 
155 
156 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
157 {
158  if (subDict)
159  {
160  os << indent << name() << nl
162  }
163 
164  coordinateSystem::writeDict(os, false);
165  os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
166 
167  if (subDict)
168  {
169  os << decrIndent << indent << token::END_BLOCK << endl;
170  }
171 }
172 
173 // ************************ vim: set sw=4 sts=4 et: ************************ //