fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / coordinateSystems / coordinateSystem.C
blobbc876ce3f8190f28ede97b72df3f7f97c19254bd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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_(cs.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()
302         << " e1: " << e1() << " e3: " << e3();
306 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
308     if (subDict)
309     {
310         os  << indent << name_ << nl
311             << indent << token::BEGIN_BLOCK << incrIndent << nl;
312     }
314     // only write type for derived types
315     if (type() != typeName_())
316     {
317         os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
318     }
320     // The note entry is optional
321     if (note_.size())
322     {
323         os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
324     }
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;
330     if (subDict)
331     {
332         os << decrIndent << indent << token::END_BLOCK << endl;
333     }
336 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
338 void Foam::coordinateSystem::operator=(const dictionary& rhs)
340     if (debug)
341     {
342         Pout<< "coordinateSystem::operator=(const dictionary&) : "
343             << "assign from " << rhs << endl;
344     }
346     // allow as embedded sub-dictionary "coordinateSystem"
347     const dictionary& dict =
348     (
349         rhs.found(typeName_())
350       ? rhs.subDict(typeName_())
351       : rhs
352     );
354     // unspecified origin is (0 0 0)
355     origin_ = point::zero;
356     dict.readIfPresent("origin", origin_);
358     // The note entry is optional
359     note_.clear();
360     rhs.readIfPresent("note", note_);
362     // specify via coordinateRotation sub-dictionary
363     if (dict.found("coordinateRotation"))
364     {
365         R_  = coordinateRotation::New(dict.subDict("coordinateRotation"))();
366     }
367     else
368     {
369         // let coordinateRotation constructor extract the axes specification
370         R_ = coordinateRotation(dict);
371     }
373     Rtr_ = R_.T();
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)
389     cs.write(os);
390     os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
391     return os;
395 // ************************************************************************* //