00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 \*---------------------------------------------------------------------------*/ 00025 00026 #include "surfaceFormatsCore.H" 00027 00028 #include <OpenFOAM/Time.H> 00029 #include <OpenFOAM/IFstream.H> 00030 #include <OpenFOAM/OFstream.H> 00031 #include <OpenFOAM/SortableList.H> 00032 #include <surfMesh/surfMesh.H> 00033 00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // 00035 00036 Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs"); 00037 00038 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // 00039 00040 Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment 00041 ( 00042 IFstream& is 00043 ) 00044 { 00045 string line; 00046 do 00047 { 00048 is.getLine(line); 00049 } 00050 while ((line.empty() || line[0] == '#') && is.good()); 00051 00052 return line; 00053 } 00054 00055 00056 #if 0 00057 Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName 00058 ( 00059 const word& surfName 00060 ) 00061 { 00062 const word name(surfName.size() ? surfName : surfaceRegistry::defaultName); 00063 00064 return fileName 00065 ( 00066 surfaceRegistry::prefix/name/surfMesh::meshSubDir 00067 / name + "." + nativeExt 00068 ); 00069 } 00070 00071 00072 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance 00073 ( 00074 const Time& t, 00075 const word& surfName 00076 ) 00077 { 00078 fileName localName = localMeshFileName(surfName); 00079 00080 // Search back through the time directories list to find the time 00081 // closest to and lower than current time 00082 00083 instantList ts = t.times(); 00084 label instanceI; 00085 00086 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI) 00087 { 00088 if (ts[instanceI].value() <= t.timeOutputValue()) 00089 { 00090 break; 00091 } 00092 } 00093 00094 // Noting that the current directory has already been searched 00095 // for mesh data, start searching from the previously stored time directory 00096 00097 if (instanceI >= 0) 00098 { 00099 for (label i = instanceI; i >= 0; --i) 00100 { 00101 if (isFile(t.path()/ts[i].name()/localName)) 00102 { 00103 return ts[i].name(); 00104 } 00105 } 00106 } 00107 00108 return "constant"; 00109 } 00110 00111 00112 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile 00113 ( 00114 const Time& t, 00115 const word& surfName 00116 ) 00117 { 00118 fileName localName = localMeshFileName(surfName); 00119 00120 // Search back through the time directories list to find the time 00121 // closest to and lower than current time 00122 00123 instantList ts = t.times(); 00124 label instanceI; 00125 00126 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI) 00127 { 00128 if (ts[instanceI].value() <= t.timeOutputValue()) 00129 { 00130 break; 00131 } 00132 } 00133 00134 // Noting that the current directory has already been searched 00135 // for mesh data, start searching from the previously stored time directory 00136 00137 if (instanceI >= 0) 00138 { 00139 for (label i = instanceI; i >= 0; --i) 00140 { 00141 fileName testName(t.path()/ts[i].name()/localName); 00142 00143 if (isFile(testName)) 00144 { 00145 return testName; 00146 } 00147 } 00148 } 00149 00150 // fallback to "constant" 00151 return t.path()/"constant"/localName; 00152 } 00153 #endif 00154 00155 00156 bool Foam::fileFormats::surfaceFormatsCore::checkSupport 00157 ( 00158 const wordHashSet& available, 00159 const word& ext, 00160 const bool verbose, 00161 const word& functionName 00162 ) 00163 { 00164 if (available.found(ext)) 00165 { 00166 return true; 00167 } 00168 else if (verbose) 00169 { 00170 wordList toc = available.toc(); 00171 SortableList<word> known(toc.xfer()); 00172 00173 Info<<"Unknown file extension for " << functionName 00174 << " : " << ext << nl 00175 <<"Valid types: ("; 00176 // compact output: 00177 forAll(known, i) 00178 { 00179 Info<<" " << known[i]; 00180 } 00181 Info<<" )" << endl; 00182 } 00183 00184 return false; 00185 } 00186 00187 00188 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00189 00190 Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore() 00191 {} 00192 00193 00194 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // 00195 00196 Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore() 00197 {} 00198 00199 00200 // ************************ vim: set sw=4 sts=4 et: ************************ //