Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / coordinateSystems / coordinateSystems.C
bloba23fe1e7dbaefb98054308e70797d3aee7e84a8f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
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 "coordinateSystems.H"
27 #include "IOPtrList.H"
28 #include "Time.H"
29 #include "stringListOps.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(coordinateSystems, 0);
36     defineTemplateTypeNameAndDebug(IOPtrList<coordinateSystem>, 0);
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 Foam::coordinateSystems::coordinateSystems(const IOobject& io)
43     IOPtrList<coordinateSystem>(io)
47 Foam::coordinateSystems::coordinateSystems
49     const IOobject& io,
50     const PtrList<coordinateSystem>& lst
53     IOPtrList<coordinateSystem>(io, lst)
57 Foam::coordinateSystems::coordinateSystems
59     const IOobject& io,
60     const Xfer<PtrList<coordinateSystem> >& lst
63     IOPtrList<coordinateSystem>(io, lst)
67 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
69 // Read construct from registry, or return previously registered
70 const Foam::coordinateSystems& Foam::coordinateSystems::New
72     const objectRegistry& obr
75     if (obr.foundObject<coordinateSystems>(typeName))
76     {
77         return obr.lookupObject<coordinateSystems>(typeName);
78     }
79     else
80     {
81         return obr.store
82         (
83             new coordinateSystems
84             (
85                 IOobject
86                 (
87                     typeName,
88                     "constant",
89                     obr,
90                     IOobject::READ_IF_PRESENT,
91                     IOobject::NO_WRITE
92                 )
93             )
94         );
95     }
99 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
101 Foam::label Foam::coordinateSystems::find(const keyType& key) const
103     return findIndex(key);
107 Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const
109     labelList indices;
110     if (key.isPattern())
111     {
112         indices = findStrings(key, toc());
113     }
114     else
115     {
116         indices.setSize(size());
117         label nFound = 0;
118         forAll(*this, i)
119         {
120             if (key == operator[](i).name())
121             {
122                 indices[nFound++] = i;
123             }
124         }
125         indices.setSize(nFound);
126     }
128     return indices;
132 Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
134     if (key.isPattern())
135     {
136         labelList indices = findIndices(key);
137         // return first element
138         if (!indices.empty())
139         {
140             return indices[0];
141         }
142     }
143     else
144     {
145         forAll(*this, i)
146         {
147             if (key == operator[](i).name())
148             {
149                 return i;
150             }
151         }
152     }
154     return -1;
158 bool Foam::coordinateSystems::found(const keyType& key) const
160     return findIndex(key) != -1;
164 Foam::wordList Foam::coordinateSystems::toc() const
166     wordList keywords(size());
168     forAll(*this, i)
169     {
170         keywords[i] = operator[](i).name();
171     }
173     return keywords;
177 bool Foam::coordinateSystems::writeData(Ostream& os, bool subDict) const
179     os << nl << size() << nl << token::BEGIN_LIST;
181     forAll(*this, i)
182     {
183         os << nl;
184         operator[](i).writeDict(os, subDict);
185     }
187     os << token::END_LIST << nl;
189     return os.good();
193 // ************************************************************************* //