1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "coordinateSystem.H"
28 #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::coordinateSystem::spanInfo Foam::coordinateSystem::spanLimited() const
206 return spanInfo(Pair<bool>(false, false));
210 Foam::boundBox Foam::coordinateSystem::spanBounds() const
212 return boundBox::greatBox;
216 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
220 dict.add("name", name_);
222 // only write type for derived types
223 if (!ignoreType && type() != typeName_())
225 dict.add("type", type());
228 // The note entry is optional
231 dict.add("note", note_);
234 dict.add("origin", origin_);
235 dict.add("e1", e1());
236 dict.add("e3", e3());
242 Foam::vector Foam::coordinateSystem::localToGlobal
250 return (R_ & local) + origin_;
259 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
261 const vectorField& local,
267 return (R_ & local) + origin_;
276 Foam::vector Foam::coordinateSystem::globalToLocal
278 const vector& global,
284 return (Rtr_ & (global - origin_));
288 return (Rtr_ & global);
293 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
295 const vectorField& global,
301 return (Rtr_ & (global - origin_));
305 return (Rtr_ & global);
310 void Foam::coordinateSystem::write(Ostream& os) const
313 << " origin: " << origin()
314 << " e1: " << e1() << " e3: " << e3();
318 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
323 << indent << token::BEGIN_BLOCK << incrIndent << nl;
326 // only write type for derived types
327 if (type() != typeName_())
329 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
332 // The note entry is optional
335 os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
338 os.writeKeyword("name") << name_ << token::END_STATEMENT << nl;
339 os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
340 os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
341 os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
345 os << decrIndent << indent << token::END_BLOCK << endl;
349 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
351 void Foam::coordinateSystem::operator=(const dictionary& rhs)
355 Pout<< "coordinateSystem::operator=(const dictionary&) : "
356 << "assign from " << rhs << endl;
359 // allow as embedded sub-dictionary "coordinateSystem"
360 const dictionary& dict =
362 rhs.found(typeName_())
363 ? rhs.subDict(typeName_())
367 // unspecified origin is (0 0 0)
368 origin_ = point::zero;
369 dict.readIfPresent("origin", origin_);
371 // The note entry is optional
373 rhs.readIfPresent("note", note_);
375 // specify via coordinateRotation sub-dictionary
376 if (dict.found("coordinateRotation"))
378 R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
382 // let coordinateRotation constructor extract the axes specification
383 R_ = coordinateRotation(dict);
390 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
392 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
394 return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
398 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
400 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
403 os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
408 // ************************************************************************* //