ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / coordinateSystems / coordinateSystem.C
bloba9153daa85dea9472d1a9197add3f2513e780a14
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
26 #include "IOstream.H"
27 #include "coordinateSystem.H"
28 #include "coordinateSystems.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(coordinateSystem, 0);
36     defineRunTimeSelectionTable(coordinateSystem, dictionary);
37     defineRunTimeSelectionTable(coordinateSystem, origRotation);
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 Foam::coordinateSystem::coordinateSystem()
44     name_(type()),
45     note_(),
46     origin_(point::zero),
47     R_(),
48     Rtr_(sphericalTensor::I)
52 Foam::coordinateSystem::coordinateSystem
54     const word& name,
55     const coordinateSystem& cs
58     name_(name),
59     note_(),
60     origin_(cs.origin_),
61     R_(cs.R_),
62     Rtr_(R_.T())
66 Foam::coordinateSystem::coordinateSystem
68     const word& name,
69     const point& origin,
70     const coordinateRotation& cr
73     name_(name),
74     note_(),
75     origin_(origin),
76     R_(cr),
77     Rtr_(R_.T())
81 Foam::coordinateSystem::coordinateSystem
83     const word& name,
84     const point& origin,
85     const vector& axis,
86     const vector& dirn
89     name_(name),
90     note_(),
91     origin_(origin),
92     R_(axis, dirn),
93     Rtr_(R_.T())
97 Foam::coordinateSystem::coordinateSystem
99     const word& name,
100     const dictionary& dict
103     name_(name),
104     note_(),
105     origin_(point::zero),
106     R_(),
107     Rtr_(sphericalTensor::I)
109     operator=(dict);
113 Foam::coordinateSystem::coordinateSystem(const dictionary& dict)
115     name_(type()),
116     note_(),
117     origin_(point::zero),
118     R_(),
119     Rtr_(sphericalTensor::I)
121     operator=(dict);
125 Foam::coordinateSystem::coordinateSystem
127     const dictionary& dict,
128     const objectRegistry& obr
131     name_(type()),
132     note_(),
133     origin_(point::zero),
134     R_(),
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())
141     {
142         keyType key(entryPtr->stream());
144         const coordinateSystems& lst = coordinateSystems::New(obr);
145         const label index = lst.findIndex(key);
147         if (debug)
148         {
149             Info<< "coordinateSystem::coordinateSystem"
150                 "(const dictionary&, const objectRegistry&):"
151                 << nl << "using global coordinate system: "
152                 << key << "=" << index << endl;
153         }
155         if (index < 0)
156         {
157             FatalErrorIn
158             (
159                 "coordinateSystem::coordinateSystem"
160                 "(const dictionary&, const objectRegistry&)"
161             )   << "could not find coordinate system: " << key << nl
162                 << "available coordinate systems: " << lst.toc() << nl << nl
163                 << exit(FatalError);
164         }
166         // copy coordinateSystem, but assign the name as the typeName
167         // to avoid strange things in writeDict()
168         operator=(lst[index]);
169         name_ = typeName_();
170     }
171     else
172     {
173         operator=(dict);
174     }
178 Foam::coordinateSystem::coordinateSystem(Istream& is)
180     name_(is),
181     note_(),
182     origin_(point::zero),
183     R_(),
184     Rtr_(sphericalTensor::I)
186     dictionary dict(is);
187     operator=(dict);
191 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
193 Foam::coordinateSystem::~coordinateSystem()
197 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
199 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
201     dictionary dict;
203     dict.add("name", name_);
205     // only write type for derived types
206     if (!ignoreType && type() != typeName_())
207     {
208         dict.add("type", type());
209     }
211     // The note entry is optional
212     if (note_.size())
213     {
214         dict.add("note", note_);
215     }
217     dict.add("origin", origin_);
218     dict.add("e1", e1());
219     dict.add("e3", e3());
221     return dict;
225 Foam::vector Foam::coordinateSystem::localToGlobal
227     const vector& local,
228     bool translate
229 ) const
231     if (translate)
232     {
233         return (R_ & local) + origin_;
234     }
235     else
236     {
237         return (R_ & local);
238     }
242 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
244     const vectorField& local,
245     bool translate
246 ) const
248     if (translate)
249     {
250         return (R_ & local) + origin_;
251     }
252     else
253     {
254         return (R_ & local);
255     }
259 Foam::vector Foam::coordinateSystem::globalToLocal
261     const vector& global,
262     bool translate
263 ) const
265     if (translate)
266     {
267         return (Rtr_ & (global - origin_));
268     }
269     else
270     {
271         return (Rtr_ & global);
272     }
276 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
278     const vectorField& global,
279     bool translate
280 ) const
282     if (translate)
283     {
284         return (Rtr_ & (global - origin_));
285     }
286     else
287     {
288         return (Rtr_ & global);
289     }
293 void Foam::coordinateSystem::clear()
295     note_.clear();
296     origin_ = point::zero;
297     R_.clear();
298     Rtr_ = sphericalTensor::I;
302 void Foam::coordinateSystem::write(Ostream& os) const
304     os  << type()
305         << " origin: " << origin() << " e1: " << e1() << " e3: " << e3();
309 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
311     if (subDict)
312     {
313         os  << indent << name_ << nl
314             << indent << token::BEGIN_BLOCK << incrIndent << nl;
315     }
317     // only write type for derived types
318     if (type() != typeName_())
319     {
320         os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
321     }
323     // The note entry is optional
324     if (note_.size())
325     {
326         os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
327     }
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;
333     if (subDict)
334     {
335         os  << decrIndent << indent << token::END_BLOCK << endl;
336     }
340 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
342 void Foam::coordinateSystem::operator=(const dictionary& rhs)
344     if (debug)
345     {
346         Pout<< "coordinateSystem::operator=(const dictionary&) : "
347             << "assign from " << rhs << endl;
348     }
350     // allow as embedded sub-dictionary "coordinateSystem"
351     const dictionary& dict =
352     (
353         rhs.found(typeName_())
354       ? rhs.subDict(typeName_())
355       : rhs
356     );
358     // unspecified origin is (0 0 0)
359     origin_ = point::zero;
360     dict.readIfPresent("origin", origin_);
362     // The note entry is optional
363     note_.clear();
364     rhs.readIfPresent("note", note_);
366     // specify via coordinateRotation sub-dictionary
367     if (dict.found("coordinateRotation"))
368     {
369         R_  = coordinateRotation::New(dict.subDict("coordinateRotation"))();
370     }
371     else
372     {
373         // let coordinateRotation constructor extract the axes specification
374         R_ = coordinateRotation(dict);
375     }
377     Rtr_ = R_.T();
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)
393     cs.write(os);
394     os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
395     return os;
399 // ************************************************************************* //