findRefCell: Corrected the type of the reduction function.
[OpenFOAM-1.6.x.git] / src / surfMesh / surfaceFormats / surfaceFormatsCore.C
blob497901609fa1d21e542a769839e8d29cc89b32c1
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 "surfaceFormatsCore.H"
29 #include "Time.H"
30 #include "IFstream.H"
31 #include "OFstream.H"
32 #include "SortableList.H"
33 #include "surfMesh.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
39 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
41 Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment
43     IFstream& is
46     string line;
47     do
48     {
49         is.getLine(line);
50     }
51     while ((line.empty() || line[0] == '#') && is.good());
53     return line;
57 #if 0
58 Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName
60     const word& surfName
63     const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
65     return fileName
66     (
67         surfaceRegistry::prefix/name/surfMesh::meshSubDir
68       / name + "." + nativeExt
69     );
73 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance
75     const Time& t,
76     const word& surfName
79     fileName localName = localMeshFileName(surfName);
81     // Search back through the time directories list to find the time
82     // closest to and lower than current time
84     instantList ts = t.times();
85     label instanceI;
87     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
88     {
89         if (ts[instanceI].value() <= t.timeOutputValue())
90         {
91             break;
92         }
93     }
95     // Noting that the current directory has already been searched
96     // for mesh data, start searching from the previously stored time directory
98     if (instanceI >= 0)
99     {
100         for (label i = instanceI; i >= 0; --i)
101         {
102             if (isFile(t.path()/ts[i].name()/localName))
103             {
104                 return ts[i].name();
105             }
106         }
107     }
109     return "constant";
113 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
115     const Time& t,
116     const word& surfName
119     fileName localName = localMeshFileName(surfName);
121     // Search back through the time directories list to find the time
122     // closest to and lower than current time
124     instantList ts = t.times();
125     label instanceI;
127     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
128     {
129         if (ts[instanceI].value() <= t.timeOutputValue())
130         {
131             break;
132         }
133     }
135     // Noting that the current directory has already been searched
136     // for mesh data, start searching from the previously stored time directory
138     if (instanceI >= 0)
139     {
140         for (label i = instanceI; i >= 0; --i)
141         {
142             fileName testName(t.path()/ts[i].name()/localName);
144             if (isFile(testName))
145             {
146                 return testName;
147             }
148         }
149     }
151     // fallback to "constant"
152     return t.path()/"constant"/localName;
154 #endif
157 bool Foam::fileFormats::surfaceFormatsCore::checkSupport
159     const wordHashSet& available,
160     const word& ext,
161     const bool verbose,
162     const word& functionName
165     if (available.found(ext))
166     {
167         return true;
168     }
169     else if (verbose)
170     {
171         wordList toc = available.toc();
172         SortableList<word> known(toc.xfer());
174         Info<<"Unknown file extension for " << functionName
175             << " : " << ext << nl
176             <<"Valid types: (";
177         // compact output:
178         forAll(known, i)
179         {
180             Info<<" " << known[i];
181         }
182         Info<<" )" << endl;
183     }
185     return false;
189 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
191 Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
195 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
197 Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore()
201 // ************************************************************************* //