1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
27 #include "coordinateSystem.H"
28 #include "coordinateSystems.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(coordinateSystem, 0);
36 defineRunTimeSelectionTable(coordinateSystem, dictionary);
37 defineRunTimeSelectionTable(coordinateSystem, origRotation);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::coordinateSystem::coordinateSystem()
48 Rtr_(sphericalTensor::I)
52 Foam::coordinateSystem::coordinateSystem
55 const coordinateSystem& cs
66 Foam::coordinateSystem::coordinateSystem
70 const coordinateRotation& cr
81 Foam::coordinateSystem::coordinateSystem
97 Foam::coordinateSystem::coordinateSystem
100 const dictionary& dict
105 origin_(point::zero),
107 Rtr_(sphericalTensor::I)
113 Foam::coordinateSystem::coordinateSystem
115 const dictionary& dict
120 origin_(point::zero),
122 Rtr_(sphericalTensor::I)
128 Foam::coordinateSystem::coordinateSystem
130 const dictionary& dict,
131 const objectRegistry& obr
136 origin_(point::zero),
138 Rtr_(sphericalTensor::I)
140 const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
142 // a simple entry is a lookup into global coordinateSystems
143 if (entryPtr && !entryPtr->isDict())
146 entryPtr->stream() >> csName;
148 const coordinateSystems& csLst = coordinateSystems::New(obr);
150 label csId = csLst.find(csName);
153 Info<< "coordinateSystem::coordinateSystem"
154 "(const dictionary&, const objectRegistry&):"
155 << nl << "using global coordinate system: "
156 << csName << "=" << csId << endl;
163 "coordinateSystem::coordinateSystem"
164 "(const dictionary&, const objectRegistry&)"
165 ) << "could not find coordinate system: " << csName << nl
166 << "available coordinate systems: " << csLst.toc() << nl << nl
170 // copy coordinateSystem, but assign the name as the typeName
171 // to avoid strange things in writeDict()
172 operator=(csLst[csId]);
182 Foam::coordinateSystem::coordinateSystem(Istream& is)
186 origin_(point::zero),
188 Rtr_(sphericalTensor::I)
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
197 Foam::coordinateSystem::~coordinateSystem()
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
207 dict.add("name", name_);
209 // only write type for derived types
210 if (!ignoreType && type() != typeName_())
212 dict.add("type", type());
215 // The note entry is optional
218 dict.add("note", note_);
221 dict.add("origin", origin_);
222 dict.add("e1", e1());
223 dict.add("e3", e3());
229 Foam::vector Foam::coordinateSystem::localToGlobal
237 return (R_ & local) + origin_;
246 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
248 const vectorField& local,
254 return (R_ & local) + origin_;
263 Foam::vector Foam::coordinateSystem::globalToLocal
265 const vector& global,
271 return (Rtr_ & (global - origin_));
275 return (Rtr_ & global);
280 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
282 const vectorField& global,
288 return (Rtr_ & (global - origin_));
292 return (Rtr_ & global);
297 void Foam::coordinateSystem::write(Ostream& os) const
300 << " origin: " << origin() << " e1: " << e1() << " e3: " << e3();
304 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
308 os << indent << name_ << nl
309 << indent << token::BEGIN_BLOCK << incrIndent << nl;
312 // only write type for derived types
313 if (type() != typeName_())
315 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
318 // The note entry is optional
321 os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
324 os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
325 os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
326 os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
330 os << decrIndent << indent << token::END_BLOCK << endl;
334 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
336 void Foam::coordinateSystem::operator=(const dictionary& rhs)
340 Pout<< "coordinateSystem::operator=(const dictionary&) : "
341 << "assign from " << rhs << endl;
344 // allow as embedded sub-dictionary "coordinateSystem"
345 const dictionary& dict =
347 rhs.found(typeName_())
348 ? rhs.subDict(typeName_())
352 // unspecified origin is (0 0 0)
353 origin_ = point::zero;
354 dict.readIfPresent("origin", origin_);
356 // The note entry is optional
358 rhs.readIfPresent("note", note_);
360 // specify via coordinateRotation sub-dictionary
361 if (dict.found("coordinateRotation"))
363 R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
367 // let coordinateRotation constructor extract the axes specification
368 R_ = coordinateRotation(dict);
375 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
377 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
379 return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
383 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
385 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
388 os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
393 // ************************************************************************* //