named regIOobject for dictionary
[OpenFOAM-1.6.x.git] / src / meshTools / coordinateSystems / coordinateSystem.C
blob80232ffd8d12c850a5efcc6ae600ed7f8fe6c600
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "IOstream.H"
28 #include "coordinateSystem.H"
29 #include "coordinateSystems.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(coordinateSystem, 0);
37     defineRunTimeSelectionTable(coordinateSystem, dictionary);
38     defineRunTimeSelectionTable(coordinateSystem, origRotation);
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 Foam::coordinateSystem::coordinateSystem()
45     name_(type()),
46     note_(),
47     origin_(point::zero),
48     R_(),
49     Rtr_(sphericalTensor::I)
53 Foam::coordinateSystem::coordinateSystem
55     const word& name,
56     const coordinateSystem& cs
59     name_(name),
60     note_(),
61     origin_(cs.origin_),
62     R_(cs.R_),
63     Rtr_(Rtr_)
67 Foam::coordinateSystem::coordinateSystem
69     const word& name,
70     const point& origin,
71     const coordinateRotation& cr
74     name_(name),
75     note_(),
76     origin_(origin),
77     R_(cr),
78     Rtr_(R_.T())
82 Foam::coordinateSystem::coordinateSystem
84     const word& name,
85     const point& origin,
86     const vector& axis,
87     const vector& dirn
90     name_(name),
91     note_(),
92     origin_(origin),
93     R_(axis, dirn),
94     Rtr_(R_.T())
98 Foam::coordinateSystem::coordinateSystem
100     const word& name,
101     const dictionary& dict
104     name_(name),
105     note_(),
106     origin_(point::zero),
107     R_(),
108     Rtr_(sphericalTensor::I)
110     operator=(dict);
114 Foam::coordinateSystem::coordinateSystem
116     const dictionary& dict
119     name_(type()),
120     note_(),
121     origin_(point::zero),
122     R_(),
123     Rtr_(sphericalTensor::I)
125     operator=(dict);
129 Foam::coordinateSystem::coordinateSystem
131     const dictionary& dict,
132     const objectRegistry& obr
135     name_(type()),
136     note_(),
137     origin_(point::zero),
138     R_(),
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())
145     {
146         word csName;
147         entryPtr->stream() >> csName;
149         const coordinateSystems& csLst = coordinateSystems::New(obr);
151         label csId = csLst.find(csName);
152         if (debug)
153         {
154             Info<< "coordinateSystem::coordinateSystem"
155                 "(const dictionary&, const objectRegistry&):"
156                 << nl << "using global coordinate system: "
157                 << csName << "=" << csId << endl;
158         }
160         if (csId < 0)
161         {
162             FatalErrorIn
163             (
164                 "coordinateSystem::coordinateSystem"
165                 "(const dictionary&, const objectRegistry&)"
166             )   << "could not find coordinate system: " << csName << nl
167                 << "available coordinate systems: " << csLst.toc() << nl << nl
168                 << exit(FatalError);
169         }
171         // copy coordinateSystem, but assign the name as the typeName
172         // to avoid strange things in writeDict()
173         operator=(csLst[csId]);
174         name_ = typeName_();
175     }
176     else
177     {
178         operator=(dict);
179     }
183 Foam::coordinateSystem::coordinateSystem(Istream& is)
185     name_(is),
186     note_(),
187     origin_(point::zero),
188     R_(),
189     Rtr_(sphericalTensor::I)
191     dictionary dict(is);
192     operator=(dict);
196 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
198 Foam::coordinateSystem::~coordinateSystem()
202 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
204 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
206     dictionary dict;
208     dict.add("name", name_);
210     // only write type for derived types
211     if (!ignoreType && type() != typeName_())
212     {
213         dict.add("type", type());
214     }
216     // The note entry is optional
217     if (note_.size())
218     {
219         dict.add("note", note_);
220     }
222     dict.add("origin", origin_);
223     dict.add("e1", e1());
224     dict.add("e3", e3());
226     return dict;
230 Foam::vector Foam::coordinateSystem::localToGlobal
232     const vector& local,
233     bool translate
234 ) const
236     if (translate)
237     {
238         return (R_ & local) + origin_;
239     }
240     else
241     {
242         return (R_ & local);
243     }
247 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
249     const vectorField& local,
250     bool translate
251 ) const
253     if (translate)
254     {
255         return (R_ & local) + origin_;
256     }
257     else
258     {
259         return (R_ & local);
260     }
264 Foam::vector Foam::coordinateSystem::globalToLocal
266     const vector& global,
267     bool translate
268 ) const
270     if (translate)
271     {
272         return (Rtr_ & (global - origin_));
273     }
274     else
275     {
276         return (Rtr_ & global);
277     }
281 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
283     const vectorField& global,
284     bool translate
285 ) const
287     if (translate)
288     {
289         return (Rtr_ & (global - origin_));
290     }
291     else
292     {
293         return (Rtr_ & global);
294     }
298 void Foam::coordinateSystem::write(Ostream& os) const
300     os  << type()
301         << " origin: " << origin() << " e1: " << e1() << " e3: " << e3();
305 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
307     if (subDict)
308     {
309         os  << indent << name_ << nl
310             << indent << token::BEGIN_BLOCK << incrIndent << nl;
311     }
313     // only write type for derived types
314     if (type() != typeName_())
315     {
316         os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
317     }
319     // The note entry is optional
320     if (note_.size())
321     {
322         os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
323     }
325     os.writeKeyword("origin") << origin_  << token::END_STATEMENT << nl;
326     os.writeKeyword("e1")     << e1()     << token::END_STATEMENT << nl;
327     os.writeKeyword("e3")     << e3()     << token::END_STATEMENT << nl;
329     if (subDict)
330     {
331         os << decrIndent << indent << token::END_BLOCK << endl;
332     }
335 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
337 void Foam::coordinateSystem::operator=(const dictionary& rhs)
339     if (debug)
340     {
341         Pout<< "coordinateSystem::operator=(const dictionary&) : "
342             << "assign from " << rhs << endl;
343     }
345     // allow as embedded sub-dictionary "coordinateSystem"
346     const dictionary& dict =
347     (
348         rhs.found(typeName_())
349       ? rhs.subDict(typeName_())
350       : rhs
351     );
353     // unspecified origin is (0 0 0)
354     origin_ = point::zero;
355     dict.readIfPresent("origin", origin_);
357     // The note entry is optional
358     note_.clear();
359     rhs.readIfPresent("note", note_);
361     // specify via coordinateRotation sub-dictionary
362     if (dict.found("coordinateRotation"))
363     {
364         R_  = coordinateRotation::New(dict.subDict("coordinateRotation"))();
365     }
366     else
367     {
368         // let coordinateRotation constructor extract the axes specification
369         R_ = coordinateRotation(dict);
370     }
372     Rtr_ = R_.T();
376 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
378 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
380     return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
384 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
386 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
388     cs.write(os);
389     os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
390     return os;
394 // ************************************************************************* //