1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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(const dictionary& dict)
117 origin_(point::zero),
119 Rtr_(sphericalTensor::I)
125 Foam::coordinateSystem::coordinateSystem
127 const dictionary& dict,
128 const objectRegistry& obr
133 origin_(point::zero),
135 Rtr_(sphericalTensor::I)
137 const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
139 // non-dictionary entry is a lookup into global coordinateSystems
140 if (entryPtr && !entryPtr->isDict())
142 keyType key(entryPtr->stream());
144 const coordinateSystems& lst = coordinateSystems::New(obr);
145 const label index = lst.findIndex(key);
149 Info<< "coordinateSystem::coordinateSystem"
150 "(const dictionary&, const objectRegistry&):"
151 << nl << "using global coordinate system: "
152 << key << "=" << index << endl;
159 "coordinateSystem::coordinateSystem"
160 "(const dictionary&, const objectRegistry&)"
161 ) << "could not find coordinate system: " << key << nl
162 << "available coordinate systems: " << lst.toc() << nl << nl
166 // copy coordinateSystem, but assign the name as the typeName
167 // to avoid strange things in writeDict()
168 operator=(lst[index]);
178 Foam::coordinateSystem::coordinateSystem(Istream& is)
182 origin_(point::zero),
184 Rtr_(sphericalTensor::I)
191 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
193 Foam::coordinateSystem::~coordinateSystem()
197 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
203 dict.add("name", name_);
205 // only write type for derived types
206 if (!ignoreType && type() != typeName_())
208 dict.add("type", type());
211 // The note entry is optional
214 dict.add("note", note_);
217 dict.add("origin", origin_);
218 dict.add("e1", e1());
219 dict.add("e3", e3());
225 Foam::vector Foam::coordinateSystem::localToGlobal
233 return (R_ & local) + origin_;
242 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
244 const vectorField& local,
250 return (R_ & local) + origin_;
259 Foam::vector Foam::coordinateSystem::globalToLocal
261 const vector& global,
267 return (Rtr_ & (global - origin_));
271 return (Rtr_ & global);
276 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
278 const vectorField& global,
284 return (Rtr_ & (global - origin_));
288 return (Rtr_ & global);
293 void Foam::coordinateSystem::clear()
296 origin_ = point::zero;
298 Rtr_ = sphericalTensor::I;
302 void Foam::coordinateSystem::write(Ostream& os) const
305 << " origin: " << origin() << " e1: " << e1() << " e3: " << e3();
309 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
313 os << indent << name_ << nl
314 << indent << token::BEGIN_BLOCK << incrIndent << nl;
317 // only write type for derived types
318 if (type() != typeName_())
320 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
323 // The note entry is optional
326 os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
329 os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
330 os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
331 os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
335 os << decrIndent << indent << token::END_BLOCK << endl;
340 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
342 void Foam::coordinateSystem::operator=(const dictionary& rhs)
346 Pout<< "coordinateSystem::operator=(const dictionary&) : "
347 << "assign from " << rhs << endl;
350 // allow as embedded sub-dictionary "coordinateSystem"
351 const dictionary& dict =
353 rhs.found(typeName_())
354 ? rhs.subDict(typeName_())
358 // unspecified origin is (0 0 0)
359 origin_ = point::zero;
360 dict.readIfPresent("origin", origin_);
362 // The note entry is optional
364 rhs.readIfPresent("note", note_);
366 // specify via coordinateRotation sub-dictionary
367 if (dict.found("coordinateRotation"))
369 R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
373 // let coordinateRotation constructor extract the axes specification
374 R_ = coordinateRotation(dict);
381 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
383 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
385 return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
389 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
391 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
394 os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
399 // ************************************************************************* //