OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceFormatsCore.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "surfaceFormatsCore.H"
00028 
00029 #include "Time.H"
00030 #include "IFstream.H"
00031 #include "OFstream.H"
00032 #include "SortableList.H"
00033 #include "surfMesh.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
00038 
00039 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
00040 
00041 Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment
00042 (
00043     IFstream& is
00044 )
00045 {
00046     string line;
00047     do
00048     {
00049         is.getLine(line);
00050     }
00051     while ((line.empty() || line[0] == '#') && is.good());
00052 
00053     return line;
00054 }
00055 
00056 
00057 #if 0
00058 Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName
00059 (
00060     const word& surfName
00061 )
00062 {
00063     const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
00064 
00065     return fileName
00066     (
00067         surfaceRegistry::prefix/name/surfMesh::meshSubDir
00068       / name + "." + nativeExt
00069     );
00070 }
00071 
00072 
00073 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance
00074 (
00075     const Time& t,
00076     const word& surfName
00077 )
00078 {
00079     fileName localName = localMeshFileName(surfName);
00080 
00081     // Search back through the time directories list to find the time
00082     // closest to and lower than current time
00083 
00084     instantList ts = t.times();
00085     label instanceI;
00086 
00087     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
00088     {
00089         if (ts[instanceI].value() <= t.timeOutputValue())
00090         {
00091             break;
00092         }
00093     }
00094 
00095     // Noting that the current directory has already been searched
00096     // for mesh data, start searching from the previously stored time directory
00097 
00098     if (instanceI >= 0)
00099     {
00100         for (label i = instanceI; i >= 0; --i)
00101         {
00102             if (isFile(t.path()/ts[i].name()/localName))
00103             {
00104                 return ts[i].name();
00105             }
00106         }
00107     }
00108 
00109     return "constant";
00110 }
00111 
00112 
00113 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
00114 (
00115     const Time& t,
00116     const word& surfName
00117 )
00118 {
00119     fileName localName = localMeshFileName(surfName);
00120 
00121     // Search back through the time directories list to find the time
00122     // closest to and lower than current time
00123 
00124     instantList ts = t.times();
00125     label instanceI;
00126 
00127     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
00128     {
00129         if (ts[instanceI].value() <= t.timeOutputValue())
00130         {
00131             break;
00132         }
00133     }
00134 
00135     // Noting that the current directory has already been searched
00136     // for mesh data, start searching from the previously stored time directory
00137 
00138     if (instanceI >= 0)
00139     {
00140         for (label i = instanceI; i >= 0; --i)
00141         {
00142             fileName testName(t.path()/ts[i].name()/localName);
00143 
00144             if (isFile(testName))
00145             {
00146                 return testName;
00147             }
00148         }
00149     }
00150 
00151     // fallback to "constant"
00152     return t.path()/"constant"/localName;
00153 }
00154 #endif
00155 
00156 
00157 bool Foam::fileFormats::surfaceFormatsCore::checkSupport
00158 (
00159     const wordHashSet& available,
00160     const word& ext,
00161     const bool verbose,
00162     const word& functionName
00163 )
00164 {
00165     if (available.found(ext))
00166     {
00167         return true;
00168     }
00169     else if (verbose)
00170     {
00171         wordList toc = available.toc();
00172         SortableList<word> known(toc.xfer());
00173 
00174         Info<<"Unknown file extension for " << functionName
00175             << " : " << ext << nl
00176             <<"Valid types: (";
00177         // compact output:
00178         forAll(known, i)
00179         {
00180             Info<<" " << known[i];
00181         }
00182         Info<<" )" << endl;
00183     }
00184 
00185     return false;
00186 }
00187 
00188 
00189 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00190 
00191 Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
00192 {}
00193 
00194 
00195 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00196 
00197 Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore()
00198 {}
00199 
00200 
00201 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd