1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "coordinateSystem.H"
29 #include "coordinateSystems.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(coordinateSystem, 0);
37 defineRunTimeSelectionTable(coordinateSystem, dictionary);
38 defineRunTimeSelectionTable(coordinateSystem, origRotation);
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 Foam::coordinateSystem::coordinateSystem()
49 Rtr_(sphericalTensor::I)
53 Foam::coordinateSystem::coordinateSystem
56 const coordinateSystem& cs
67 Foam::coordinateSystem::coordinateSystem
71 const coordinateRotation& cr
82 Foam::coordinateSystem::coordinateSystem
98 Foam::coordinateSystem::coordinateSystem
101 const dictionary& dict
106 origin_(point::zero),
108 Rtr_(sphericalTensor::I)
114 Foam::coordinateSystem::coordinateSystem
116 const dictionary& dict
121 origin_(point::zero),
123 Rtr_(sphericalTensor::I)
129 Foam::coordinateSystem::coordinateSystem
131 const dictionary& dict,
132 const objectRegistry& obr
137 origin_(point::zero),
139 Rtr_(sphericalTensor::I)
141 const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
143 // a simple entry is a lookup into global coordinateSystems
144 if (entryPtr && !entryPtr->isDict())
147 entryPtr->stream() >> csName;
149 const coordinateSystems& csLst = coordinateSystems::New(obr);
151 label csId = csLst.find(csName);
154 Info<< "coordinateSystem::coordinateSystem"
155 "(const dictionary&, const objectRegistry&):"
156 << nl << "using global coordinate system: "
157 << csName << "=" << csId << endl;
164 "coordinateSystem::coordinateSystem"
165 "(const dictionary&, const objectRegistry&)"
166 ) << "could not find coordinate system: " << csName << nl
167 << "available coordinate systems: " << csLst.toc() << nl << nl
171 // copy coordinateSystem, but assign the name as the typeName
172 // to avoid strange things in writeDict()
173 operator=(csLst[csId]);
183 Foam::coordinateSystem::coordinateSystem(Istream& is)
187 origin_(point::zero),
189 Rtr_(sphericalTensor::I)
196 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 Foam::coordinateSystem::~coordinateSystem()
202 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
208 dict.add("name", name_);
210 // only write type for derived types
211 if (!ignoreType && type() != typeName_())
213 dict.add("type", type());
216 // The note entry is optional
219 dict.add("note", note_);
222 dict.add("origin", origin_);
223 dict.add("e1", e1());
224 dict.add("e3", e3());
230 Foam::vector Foam::coordinateSystem::localToGlobal
238 return (R_ & local) + origin_;
247 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
249 const vectorField& local,
255 return (R_ & local) + origin_;
264 Foam::vector Foam::coordinateSystem::globalToLocal
266 const vector& global,
272 return (Rtr_ & (global - origin_));
276 return (Rtr_ & global);
281 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
283 const vectorField& global,
289 return (Rtr_ & (global - origin_));
293 return (Rtr_ & global);
298 void Foam::coordinateSystem::write(Ostream& os) const
301 << " origin: " << origin()
302 << " e1: " << e1() << " e3: " << e3();
306 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
310 os << indent << name_ << nl
311 << indent << token::BEGIN_BLOCK << incrIndent << nl;
314 // only write type for derived types
315 if (type() != typeName_())
317 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
320 // The note entry is optional
323 os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
326 os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
327 os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
328 os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
332 os << decrIndent << indent << token::END_BLOCK << endl;
336 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
338 void Foam::coordinateSystem::operator=(const dictionary& rhs)
342 Pout<< "coordinateSystem::operator=(const dictionary&) : "
343 << "assign from " << rhs << endl;
346 // allow as embedded sub-dictionary "coordinateSystem"
347 const dictionary& dict =
349 rhs.found(typeName_())
350 ? rhs.subDict(typeName_())
354 // unspecified origin is (0 0 0)
355 origin_ = point::zero;
356 dict.readIfPresent("origin", origin_);
358 // The note entry is optional
360 rhs.readIfPresent("note", note_);
362 // specify via coordinateRotation sub-dictionary
363 if (dict.found("coordinateRotation"))
365 R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
369 // let coordinateRotation constructor extract the axes specification
370 R_ = coordinateRotation(dict);
377 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
379 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
381 return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
385 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
387 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
390 os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
395 // ************************************************************************* //