Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
sergio
2019-04-05 09:23:04 -07:00
committed by Andrew Heather
116 changed files with 2980 additions and 2289 deletions

View File

@ -1,6 +1,6 @@
#include "stream.h"
#include <unistd.h>
#include <stdlib.h>
#include <cstdlib>
main()
{

View File

@ -1,4 +1,4 @@
#include <stdlib.h>
#include <cstdlib>
class Int
{

View File

@ -30,6 +30,8 @@ Description
#include "argList.H"
#include "complexFields.H"
#include "ops.H"
#include "ListOps.H"
using namespace Foam;
@ -97,9 +99,6 @@ int main(int argc, char *argv[])
}
Info<< "sum = " << sum(fld1) << nl;
// Not yet Info<< "min = " << min(fld1) << nl;
fld1 *= 10;
Info<< "scalar multiply: " << flatOutput(fld1) << nl;
@ -120,6 +119,36 @@ int main(int argc, char *argv[])
// Info<< "pow(2) : " << pow(fld1, 2) << nl;
// Make some changes
{
label i = 1;
for (complex& c : fld1)
{
c.Re() += i;
c.Im() -= 10 - i;
++i;
}
}
Info<< nl
<< "field = " << fld1 << nl;
Info<< "magSqr = "
<< ListOps::create<scalar>
(
fld1,
[](const complex& c) { return magSqr(c); }
)
<< nl;
Info
<< "sum = " << sum(fld1) << nl
<< "min = " << min(fld1) << nl
<< "max = " << max(fld1) << nl;
// MinMax fails since there is no less comparison operator
// Info<< "min/max = " << MinMax<complex>(fld1) << nl;
Info<< "\nEnd\n" << endl;
return 0;
}

View File

@ -0,0 +1,3 @@
Test-fileNameOS.C
EXE = $(FOAM_USER_APPBIN)/Test-fileNameOS

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-fileNameOS
Description
Test fileName behaviour, potential OS capabilities etc.
In the distant future could possibly replace parts with C++ filesystem
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "fileName.H"
#include "OSspecific.H"
#include "Switch.H"
#include <csignal>
#include <cstdlib>
#include <iostream>
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void testDirname(const std::string& rawInput)
{
fileName input(fileName::validate(rawInput));
Info<< nl
<< "input: " << rawInput << nl
<< "fileName:" << input << nl
<< " path:" << input.path()
<< " name:\"" << input.name() << '"'
<< " ext:\"" << input.ext() << '"'
<< " components: " << flatOutput(input.components()) << nl;
if (rawInput.size() != input.size())
{
Info<< " This would be Fatal with debug > 1" << nl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addBoolOption("no-space", "allowSpaceInFileName = false");
argList::addBoolOption("with-space", "set allowSpaceInFileName = true");
#include "setRootCase.H"
if (args.found("with-space"))
{
fileName::allowSpaceInFileName = true;
}
if (args.found("no-space"))
{
fileName::allowSpaceInFileName = false;
}
Info<<"fileName with spaces? : "
<< Switch(bool(fileName::allowSpaceInFileName)) << nl << nl;
{
testDirname("/abc");
testDirname("/abc/with space/name");
testDirname("/abc/with space/more space");
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -1,5 +1,6 @@
#include <iostream>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])

View File

@ -32,6 +32,7 @@ Description
#include "HashOps.H"
#include "ListOps.H"
#include "scalarField.H"
#include "complexField.H"
#include "MinMax.H"
#include "dimensionedScalar.H"
@ -47,6 +48,19 @@ Ostream& printInfo(const MinMax<T>& range)
}
template<class T>
void testUniformField(const T& val)
{
constexpr label N = 10;
// Field<T> fld(N, val);
List<T> fld(N, val);
Info<< "field: " << fld << nl
<< "min/max: " << minMaxMag(fld) << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -225,6 +239,15 @@ int main(int argc, char *argv[])
Info<< "filtered: " << hashed << nl;
}
// Min/max of uniform fields
{
testUniformField<scalar>(100);
// testUniformField<complex>(complex(100, 0));
}
Info<< "\nEnd\n" << nl;
return 0;
}

View File

@ -0,0 +1,3 @@
Test-readDir.C
EXE = $(FOAM_USER_APPBIN)/Test-readDir

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
/* EXE_LIBS = -lfiniteVolume */

View File

@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Test functionality of Foam::readDir
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "OSspecific.H"
#include "fileNameList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noBanner();
argList::noParallel();
argList::addBoolOption("dir", "list directories instead of files");
#include "setRootCase.H"
fileName::Type listType = fileName::FILE;
if (args.found("dir"))
{
Info<< "Listing directories" << nl;
listType = fileName::DIRECTORY;
}
else
{
Info<< "Listing files" << nl;
}
{
Info<< nl;
for (const word& item : readDir(".", listType))
{
Info<< " " << item << nl;
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -31,6 +31,7 @@ Description
#include "vector.H"
#include "IOstreams.H"
#include <algorithm>
using namespace Foam;
@ -74,6 +75,18 @@ void doTest(vector& vec1, vector& vec2)
}
template<class VecSpace>
void testIterator(const VecSpace& vs)
{
Info<< "size: " << vs.size() << " for:";
for (const auto& val : vs)
{
Info<< " " << val;
}
Info<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -89,8 +102,21 @@ int main(int argc, char *argv[])
vector vec2(0.5, 0.51, -0.5);
doTest(vec1, vec2);
testIterator(vec1);
testIterator(vec2);
// Use STL algorithm(s)
std::sort(vec2.begin(), vec2.end());
Info<< "sorted: " << vec2 << nl;
std::random_shuffle(vec2.begin(), vec2.end());
Info<< "shuffled: " << vec2 << nl;
}
Info<< "\nEnd\n" << nl;
return 0;
}

View File

@ -0,0 +1,10 @@
Test-wmake1.C
/* #if OPENFOAM == 1812 */
#if OPENFOAM > 1812
newStub.C
#else
oldStub.C
#endif
EXE = $(FOAM_APPBIN)/Test-wmake1

View File

@ -0,0 +1,2 @@
EXE_INC =
EXE_LIBS =

View File

@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-wmake1
Description
Some tests for wmake features.
For example, testing how robust or fragile version-dependent conditional
compilation works.
\*---------------------------------------------------------------------------*/
#include "argList.H"
namespace Foam
{
void printTest();
}
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
printTest();
Info<< "\nEnd\n" << nl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,13 @@
// Some test code
#include "foamVersion.H"
#include "IOstreams.H"
namespace Foam
{
void printTest()
{
Info<< nl;
foamVersion::printBuildInfo();
}
}

View File

@ -0,0 +1,17 @@
// Some test code
#include "IOstreams.H"
namespace Foam
{
void printTest()
{
Info<< nl << "Using old stub" << nl;
#if OPENFOAM
Info<< "OPENFOAM=" << OPENFOAM << nl;
#else
Info<< "OPENFOAM is undefined" << nl;
#endif
}
}

View File

@ -121,14 +121,14 @@ void usage()
std::cout
<< "usage: addr2line [-e filename|--exe=filename]"
" address [address...]\n" << std::endl;
::exit(1);
std::exit(1);
}
void version()
{
std::cout<< "OpenFOAM addr2line emulator\n" << std::endl;
::exit(0);
std::exit(0);
}

View File

@ -64,6 +64,9 @@ InfoSwitches
// Allow case-supplied C++ code (#codeStream, codedFixedValue)
allowSystemOperations 1;
// Allow space character in fileName (use with caution)
allowSpaceInFileName 0;
}

View File

@ -1,18 +1,20 @@
clockTime/clockTime.C
clockValue/clockValue.C
cpuInfo/cpuInfo.C
cpuTime/cpuTime.C
memInfo/memInfo.C
signals/sigFpe.C
signals/sigSegv.C
signals/sigInt.C
signals/sigQuit.C
signals/sigStopAtWriteNow.C
signals/sigWriteNow.C
signals/timer.C
regExpPosix.C
timer.C
fileStat.C
POSIX.C
cpuTime/cpuTime.C
clockTime/clockTime.C
clockValue/clockValue.C
cpuInfo/cpuInfo.C
memInfo/memInfo.C
/*
* Note: fileMonitor assumes inotify by default. Compile with -DFOAM_USE_STAT

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
@ -34,14 +34,11 @@ Description
#include "OSspecific.H"
#include "POSIX.H"
#include "foamVersion.H"
#include "fileName.H"
#include "fileStat.H"
#include "timer.H"
#include "IFstream.H"
#include "DynamicList.H"
#include "CStringList.H"
#include "SubList.H"
#include "IOstreams.H"
#include "Pstream.H"
@ -49,7 +46,7 @@ Description
#include <cstdlib>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <unistd.h>
#include <dirent.h>
#include <pwd.h>
@ -87,44 +84,6 @@ static bool cwdPreference_(Foam::debug::optimisationSwitch("cwd", 0));
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
// Like fileName "/" global operator, but retain any invalid characters
static inline Foam::fileName fileNameConcat
(
const std::string& a,
const std::string& b
)
{
if (a.size())
{
if (b.size())
{
// Two non-empty strings: can concatenate
if (a.back() == '/' || b.front() == '/')
{
return Foam::fileName(a + b, false);
}
else
{
return Foam::fileName(a + '/' + b, false);
}
}
// The second string was empty
return Foam::fileName(a, false);
}
if (b.size())
{
// The first string is empty
return Foam::fileName(b, false);
}
// Both strings are empty
return Foam::fileName();
}
// After a fork in system(), before the exec() do the following
// - close stdin when executing in background (daemon-like)
// - redirect stdout to stderr when infoDetailLevel == 0
@ -145,6 +104,141 @@ static inline void redirects(const bool bg)
}
// * * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * //
namespace Foam
{
namespace POSIX
{
//- A simple directory contents iterator
class directoryIterator
{
DIR* dirptr_;
bool exists_;
bool hidden_;
std::string item_;
//- Accept file/dir name
inline bool accept() const
{
return
(
item_.size() && item_ != "." && item_ != ".."
&& (hidden_ || item_[0] != '.')
);
}
public:
// Constructors
//- Construct for dirName, optionally allowing hidden files/dirs
directoryIterator(const fileName& dirName, bool allowHidden = false)
:
dirptr_(nullptr),
exists_(false),
hidden_(allowHidden),
item_()
{
if (!dirName.empty())
{
dirptr_ = ::opendir(dirName.c_str());
exists_ = (dirptr_ != nullptr);
next(); // Move to first element
}
}
//- Destructor
~directoryIterator()
{
close();
}
// Member Functions
//- Directory open succeeded
bool exists() const
{
return exists_;
}
//- Directory pointer is valid
bool good() const
{
return dirptr_;
}
//- Close directory
void close()
{
if (dirptr_)
{
::closedir(dirptr_);
dirptr_ = nullptr;
}
}
//- The current item
const std::string& val() const
{
return item_;
}
//- Read next item, always ignoring "." and ".." entries.
// Normally also ignore hidden files/dirs (beginning with '.')
// Automatically close when there are no more items
bool next()
{
struct dirent *list;
while (dirptr_ && (list = ::readdir(dirptr_)) != nullptr)
{
item_ = list->d_name;
if (accept())
{
return true;
}
}
close(); // No more items
return false;
}
// Member Operators
//- Same as good()
operator bool() const
{
return good();
}
//- Same as val()
const std::string& operator*() const
{
return val();
}
//- Same as next()
directoryIterator& operator++()
{
next();
return *this;
}
};
} // End namespace POSIX
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
pid_t Foam::pid()
@ -455,8 +549,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
// Directory made OK so return true
return true;
}
else
{
switch (errno)
{
case EPERM:
@ -465,8 +558,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "The filesystem containing " << pathName
<< " does not support the creation of directories."
<< exit(FatalError);
return false;
break;
}
case EEXIST:
@ -481,8 +573,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "" << pathName
<< " points outside your accessible address space."
<< exit(FatalError);
return false;
break;
}
case EACCES:
@ -493,8 +584,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< " or one of the directories in " << pathName
<< " did not allow search (execute) permission."
<< exit(FatalError);
return false;
break;
}
case ENAMETOOLONG:
@ -502,8 +592,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
FatalErrorInFunction
<< "" << pathName << " is too long."
<< exit(FatalError);
return false;
break;
}
case ENOENT:
@ -513,14 +602,11 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
{
return mkDir(pathName, mode);
}
else
{
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
return false;
}
break;
}
case ENOTDIR:
@ -529,18 +615,16 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "A component used as a directory in " << pathName
<< " is not, in fact, a directory."
<< exit(FatalError);
return false;
break;
}
case ENOMEM:
{
FatalErrorInFunction
<< "Insufficient kernel memory was available to make "
"directory " << pathName << '.'
<< "Insufficient kernel memory was available to make directory "
<< pathName << '.'
<< exit(FatalError);
return false;
break;
}
case EROFS:
@ -549,8 +633,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "" << pathName
<< " refers to a file on a read-only filesystem."
<< exit(FatalError);
return false;
break;
}
case ELOOP:
@ -559,8 +642,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "Too many symbolic links were encountered in resolving "
<< pathName << '.'
<< exit(FatalError);
return false;
break;
}
case ENOSPC:
@ -570,8 +652,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< " has no room for the new directory or "
<< "the user's disk quota is exhausted."
<< exit(FatalError);
return false;
break;
}
default:
@ -579,12 +660,12 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
break;
}
}
return false;
}
}
}
}
bool Foam::chMod(const fileName& name, const mode_t m)
@ -797,7 +878,7 @@ Foam::fileNameList Foam::readDir
)
{
// Initial filename list size and the increment when resizing the list
static const int maxNnames = 100;
constexpr int maxNnames = 100;
// Basic sanity: cannot strip '.gz' from directory names
const bool stripgz = filtergz && (type != fileName::DIRECTORY);
@ -805,14 +886,10 @@ Foam::fileNameList Foam::readDir
fileNameList dirEntries;
// Open directory and set the structure pointer
// Do not attempt to open an empty directory name
DIR *source;
if
(
directory.empty()
|| (source = ::opendir(directory.c_str())) == nullptr
)
// Iterate contents (ignores an empty directory name)
POSIX::directoryIterator dirIter(directory);
if (!dirIter.exists())
{
if (POSIX::debug)
{
@ -835,19 +912,12 @@ Foam::fileNameList Foam::readDir
label nFailed = 0; // Entries with invalid characters
label nEntries = 0; // Number of selected entries
dirEntries.setSize(maxNnames);
dirEntries.resize(maxNnames);
// Read and parse all the entries in the directory
for (struct dirent *list; (list = ::readdir(source)) != nullptr; /*nil*/)
// Process the directory entries
for (/*nil*/; dirIter; ++dirIter)
{
const std::string item(list->d_name);
// Ignore files/directories beginning with "."
// These are the ".", ".." directories and any hidden files/dirs
if (item.empty() || item[0] == '.')
{
continue;
}
const std::string& item = *dirIter;
// Validate filename without spaces, quotes, etc in the name.
// No duplicate slashes to strip - dirent will not have them anyhow.
@ -867,7 +937,7 @@ Foam::fileNameList Foam::readDir
{
if (nEntries >= dirEntries.size())
{
dirEntries.setSize(dirEntries.size() + maxNnames);
dirEntries.resize(dirEntries.size() + maxNnames);
}
if (stripgz && name.hasExt(extgz))
@ -881,10 +951,9 @@ Foam::fileNameList Foam::readDir
}
}
}
::closedir(source);
// Finalize the length of the entries list
dirEntries.setSize(nEntries);
dirEntries.resize(nEntries);
if (nFailed && POSIX::debug)
{
@ -934,14 +1003,14 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
return false;
}
// Open and check streams.
std::ifstream srcStream(src);
// Open and check streams. Enforce binary for extra safety
std::ifstream srcStream(src, ios_base::in | ios_base::binary);
if (!srcStream)
{
return false;
}
std::ofstream destStream(destFile);
std::ofstream destStream(destFile, ios_base::out | ios_base::binary);
if (!destStream)
{
return false;
@ -1141,12 +1210,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
{
const fileName dstName(dst/src.name());
return ::rename(src.c_str(), dstName.c_str()) == 0;
}
else
{
return ::rename(src.c_str(), dst.c_str()) == 0;
return (0 == ::rename(src.c_str(), dstName.c_str()));
}
return (0 == ::rename(src.c_str(), dst.c_str()));
}
@ -1187,7 +1254,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
// possible index where we have no choice
if (!exists(dstName, false) || n == maxIndex)
{
return ::rename(src.c_str(), dstName.c_str()) == 0;
return (0 == ::rename(src.c_str(), dstName.c_str()));
}
}
}
@ -1215,28 +1282,23 @@ bool Foam::rm(const fileName& file)
return false;
}
// Try returning plain file name; if not there, try with .gz
if (::remove(file.c_str()) == 0)
{
return true;
}
else
{
return ::remove(string(file + ".gz").c_str()) == 0;
}
// If removal of plain file name fails, try with .gz
return
(
0 == ::remove(file.c_str())
|| 0 == ::remove((file + ".gz").c_str())
);
}
bool Foam::rmDir(const fileName& directory, const bool silent)
{
// Open directory and set the structure pointer
// Do not attempt to open an empty directory name
DIR *source;
if
(
directory.empty()
|| (source = ::opendir(directory.c_str())) == nullptr
)
// Iterate contents (ignores an empty directory name)
// Also retain hidden files/dirs for removal
POSIX::directoryIterator dirIter(directory, true);
if (!dirIter.exists())
{
if (!silent)
{
@ -1259,21 +1321,16 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
// Process each directory entry, counting any errors encountered
label nErrors = 0;
for (struct dirent *list; (list = ::readdir(source)) != nullptr; /*nil*/)
{
const std::string item(list->d_name);
// Ignore "." and ".." directories
if (item.empty() || item == "." || item == "..")
for (/*nil*/; dirIter; ++dirIter)
{
continue;
}
const std::string& item = *dirIter;
// Allow invalid characters (spaces, quotes, etc),
// otherwise we cannot subdirs with these types of names.
// otherwise we cannot remove subdirs with these types of names.
// -> const fileName path = directory/name; <-
const fileName path(fileNameConcat(directory, item));
const fileName path(fileName::concat(directory, item));
if (path.type(false) == fileName::DIRECTORY)
{
@ -1314,7 +1371,6 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
}
// clean up
::closedir(source);
return !nErrors;
}

View File

@ -51,8 +51,8 @@ namespace POSIX
//- Declare namespace and its debug switch
NamespaceName("POSIX");
const label pathLengthChunk = 256;
const label pathLengthMax = 4096;
constexpr label pathLengthChunk = 256;
constexpr label pathLengthMax = 4096;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,7 +41,7 @@ SourceFiles
#define cpuTime_H
#include <string>
#include <time.h>
#include <ctime>
#include <sys/times.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -54,6 +54,7 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class fileMonitor;
class fileMonitorWatcher;
@ -63,7 +64,6 @@ class fileMonitorWatcher;
class fileMonitor
{
public:
// Public data types
@ -79,6 +79,7 @@ public:
static const Enum<fileState> fileStateNames_;
private:
// Private data
//- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
@ -120,7 +121,7 @@ public:
// Constructors
//- Construct null
fileMonitor(const bool useInotify);
explicit fileMonitor(const bool useInotify);
//- Destructor

View File

@ -29,7 +29,6 @@ License
#include "IOstreams.H"
#include "timer.H"
#include <signal.h>
#include <unistd.h>
#ifndef darwin
#include <sys/sysmacros.h>

View File

@ -111,7 +111,7 @@ public:
);
//- Construct from Istream
fileStat(Istream& is);
explicit fileStat(Istream& is);
// Member Functions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -33,6 +33,8 @@ License
#include "Switch.H"
#include "UList.H"
#include <limits>
#if defined(__linux__) && defined(__GNUC__)
#ifndef __USE_GNU
#define __USE_GNU // To use feenableexcept()
@ -47,7 +49,9 @@ License
#include "feexceptErsatz.H"
#endif
#include <limits>
// File-local functions
#include "signalMacros.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -57,8 +61,6 @@ bool Foam::sigFpe::switchNan_(Foam::debug::optimisationSwitch("setNaN", 0));
bool Foam::sigFpe::sigActive_ = false;
bool Foam::sigFpe::nanActive_ = false;
struct sigaction Foam::sigFpe::oldAction_;
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
@ -123,17 +125,11 @@ void Foam::sigFpe::sigHandler(int)
{
#if (defined(__linux__) && defined(__GNUC__)) || defined(darwin)
// Reset old handling
if (sigaction(SIGFPE, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset SIGFPE trapping"
<< abort(FatalError);
}
resetHandler("SIGFPE", SIGFPE);
jobInfo.signalEnd(); // Update jobInfo file
error::printStack(Perr);
raise(SIGFPE); // Throw signal (to old handler)
::raise(SIGFPE); // Throw signal (to old handler)
#endif // (__linux__ && __GNUC__) || darwin
}
@ -203,17 +199,7 @@ void Foam::sigFpe::set(bool verbose)
| FE_OVERFLOW
);
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot set SIGFPE trapping"
<< abort(FatalError);
}
setHandler("SIGFPE", SIGFPE, sigHandler);
sigActive_ = true;
@ -293,12 +279,7 @@ void Foam::sigFpe::unset(bool verbose)
<< endl;
}
if (sigaction(SIGFPE, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset SIGFPE trapping"
<< abort(FatalError);
}
resetHandler("SIGFPE", SIGFPE);
// Reset exception raising
const int oldExcept = fedisableexcept

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -56,7 +56,6 @@ SourceFiles
#ifndef sigFpe_H
#define sigFpe_H
#include <signal.h>
#include "scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,7 +63,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
template<class T> class UList;
/*---------------------------------------------------------------------------*\
@ -73,7 +72,7 @@ template<class T> class UList;
class sigFpe
{
// Private data
// Private Data
//- Flag that floating point trapping should be used.
// Can override with FOAM_SIGFPE env variable
@ -83,20 +82,16 @@ class sigFpe
// Can override with FOAM_SETNAN env variable
static bool switchNan_;
//- Flag to indicate floating point trapping is currently active
//- Floating point trapping currently active?
static bool sigActive_;
//- Flag to indicate mallocNan is currently active
static bool nanActive_;
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
//- Handler for caught signals.
// Ends job and prints stack
//- Handler for caught signals - ends job and prints stack
static void sigHandler(int);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -30,9 +30,11 @@ License
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// File-local functions
#include "signalMacros.C"
struct sigaction Foam::sigInt::oldAction_;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::sigInt::sigActive_ = false;
@ -41,16 +43,10 @@ bool Foam::sigInt::sigActive_ = false;
void Foam::sigInt::sigHandler(int)
{
// Reset old handling
if (sigaction(SIGINT, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset SIGINT trapping"
<< abort(FatalError);
}
resetHandler("SIGINT", SIGINT);
jobInfo.signalEnd(); // Update jobInfo file
raise(SIGINT); // Throw signal (to old handler)
::raise(SIGINT); // Throw signal (to old handler)
}
@ -74,35 +70,25 @@ Foam::sigInt::~sigInt()
void Foam::sigInt::set(bool)
{
if (!sigActive_)
if (sigActive_)
{
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot call sigInt::set() more than once"
<< abort(FatalError);
return;
}
sigActive_ = true;
}
setHandler("SIGINT", SIGINT, sigHandler);
}
void Foam::sigInt::unset(bool)
{
if (sigActive_)
if (!sigActive_)
{
if (sigaction(SIGINT, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot set SIGINT trapping"
<< abort(FatalError);
return;
}
sigActive_ = false;
}
resetHandler("SIGINT", SIGINT);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -47,8 +47,6 @@ SourceFiles
#ifndef sigInt_H
#define sigInt_H
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -62,10 +60,7 @@ class sigInt
{
// Private data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
//- Flag to indicate signal trapping is enabled
//- Signal trapping enabled?
static bool sigActive_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -30,9 +30,11 @@ License
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// File-local functions
#include "signalMacros.C"
struct sigaction Foam::sigQuit::oldAction_;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::sigQuit::sigActive_ = false;
@ -41,17 +43,11 @@ bool Foam::sigQuit::sigActive_ = false;
void Foam::sigQuit::sigHandler(int)
{
// Reset old handling
if (sigaction(SIGQUIT, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset SIGQUIT trapping"
<< abort(FatalError);
}
resetHandler("SIGQUIT", SIGQUIT);
jobInfo.signalEnd(); // Update jobInfo file
error::printStack(Perr);
raise(SIGQUIT); // Throw signal (to old handler)
::raise(SIGQUIT); // Throw signal (to old handler)
}
@ -75,35 +71,25 @@ Foam::sigQuit::~sigQuit()
void Foam::sigQuit::set(bool)
{
if (!sigActive_)
if (sigActive_)
{
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot call more than once"
<< abort(FatalError);
return;
}
sigActive_ = true;
}
setHandler("SIGQUIT", SIGQUIT, sigHandler);
}
void Foam::sigQuit::unset(bool)
{
if (sigActive_)
if (!sigActive_)
{
if (sigaction(SIGQUIT, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot unset SIGQUIT trapping"
<< abort(FatalError);
return;
}
sigActive_ = false;
}
resetHandler("SIGQUIT", SIGQUIT);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -46,8 +46,6 @@ SourceFiles
#ifndef sigQuit_H
#define sigQuit_H
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -59,12 +57,9 @@ namespace Foam
class sigQuit
{
// Private data
// Private Data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
//- Flag to indicate signal trapping is enabled
//- Signal trapping enabled?
static bool sigActive_;
@ -86,7 +81,7 @@ public:
~sigQuit();
// Member functions
// Member Functions
//- Activate SIGQUIT signal handler
static void set(bool verbose=false);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -30,9 +30,11 @@ License
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// File-local functions
#include "signalMacros.C"
struct sigaction Foam::sigSegv::oldAction_;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::sigSegv::sigActive_ = false;
@ -41,17 +43,11 @@ bool Foam::sigSegv::sigActive_ = false;
void Foam::sigSegv::sigHandler(int)
{
// Reset old handling
if (sigaction(SIGSEGV, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset SIGSEGV trapping"
<< abort(FatalError);
}
resetHandler("SIGSEGV", SIGSEGV);
jobInfo.signalEnd(); // Update jobInfo file
error::printStack(Perr);
raise(SIGSEGV); // Throw signal (to old handler)
::raise(SIGSEGV); // Throw signal (to old handler)
}
@ -75,35 +71,25 @@ Foam::sigSegv::~sigSegv()
void Foam::sigSegv::set(bool)
{
if (!sigActive_)
if (sigActive_)
{
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot call more than once"
<< abort(FatalError);
return;
}
sigActive_ = true;
}
setHandler("SIGSEGV", SIGSEGV, sigHandler);
}
void Foam::sigSegv::unset(bool)
{
if (sigActive_)
if (!sigActive_)
{
if (sigaction(SIGSEGV, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot unset SIGSEGV trapping"
<< abort(FatalError);
return;
}
sigActive_ = false;
}
resetHandler("SIGSEGV", SIGSEGV);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -46,8 +46,6 @@ SourceFiles
#ifndef sigSegv_H
#define sigSegv_H
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -59,12 +57,9 @@ namespace Foam
class sigSegv
{
// Private data
// Private Data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
//- Flag to indicate signal trapping is enabled
//- Signal trapping enabled?
static bool sigActive_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -25,12 +25,17 @@ License
\*---------------------------------------------------------------------------*/
#include "sigWriteNow.H"
#include "sigStopAtWriteNow.H"
#include "error.H"
#include "JobInfo.H"
#include "IOstreams.H"
#include "Time.H"
// File-local functions
#include "signalMacros.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Signal number to catch
@ -39,21 +44,19 @@ int Foam::sigStopAtWriteNow::signal_
Foam::debug::optimisationSwitch("stopAtWriteNowSignal", -1)
);
Foam::Time const* Foam::sigStopAtWriteNow::runTimePtr_ = nullptr;
// Pointer to Time (file-local variable)
static Foam::Time const* runTimePtr_ = nullptr;
struct sigaction Foam::sigStopAtWriteNow::oldAction_;
// * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * * //
namespace Foam
{
// Register re-reader
class addstopAtWriteNowSignalToOpt
struct addstopAtWriteNowSignalToOpt
:
public ::Foam::simpleRegIOobject
{
public:
addstopAtWriteNowSignalToOpt(const char* name)
:
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
@ -85,13 +88,7 @@ addstopAtWriteNowSignalToOpt addstopAtWriteNowSignalToOpt_
void Foam::sigStopAtWriteNow::sigHandler(int)
{
// Reset old handling
if (sigaction(signal_, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset " << signal_ << " trapping"
<< abort(FatalError);
}
resetHandler("stopAtWriteNow", signal_);
jobInfo.signalEnd(); // Update jobInfo file
@ -122,27 +119,38 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow(const Time& runTime, bool verbose)
Foam::sigStopAtWriteNow::~sigStopAtWriteNow()
{
// Reset old handling
if (signal_ > 0)
if (!active())
{
if (sigaction(signal_, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset " << signal_ << " trapping"
<< abort(FatalError);
}
return;
}
resetHandler("stopAtWriteNow", signal_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::sigStopAtWriteNow::active()
{
return signal_ > 0;
}
int Foam::sigStopAtWriteNow::signalNumber()
{
return signal_;
}
void Foam::sigStopAtWriteNow::set(bool verbose)
{
if (signal_ > 0)
if (!active())
{
return;
}
// Check that the signal is different from the writeNowSignal
if (sigWriteNow::signal_ == signal_)
if (sigWriteNow::signalNumber() == signal_)
{
FatalErrorInFunction
<< "stopAtWriteNowSignal : " << signal_
@ -151,31 +159,14 @@ void Foam::sigStopAtWriteNow::set(bool verbose)
<< exit(FatalError);
}
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(signal_, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot set " << signal_ << " trapping"
<< abort(FatalError);
}
if (verbose)
{
Info<< "sigStopAtWriteNow :"
<< " Enabling writing and stopping upon signal " << signal_
<< endl;
}
}
}
bool Foam::sigStopAtWriteNow::active() const
{
return signal_ > 0;
setHandler("stopAtWriteNow", signal_, sigHandler);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -27,10 +27,8 @@ Class
Foam::sigStopAtWriteNow
Description
Signal handler for interupt defined by
OptimisationSwitches::stopAtWriteNowSignal
Write and stop the job.
Signal handler to write and stop the job.
The interrupt is defined by OptimisationSwitches::stopAtWriteNowSignal
SourceFiles
sigStopAtWriteNow.C
@ -40,13 +38,12 @@ SourceFiles
#ifndef sigStopAtWriteNow_H
#define sigStopAtWriteNow_H
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class Time;
/*---------------------------------------------------------------------------*\
@ -55,17 +52,11 @@ class Time;
class sigStopAtWriteNow
{
// Private data
// Private Data
//- Number of signal to use
//- Signal number to use
static int signal_;
//- Pointer to Time
static Time const* runTimePtr_;
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
@ -92,13 +83,16 @@ public:
~sigStopAtWriteNow();
// Member functions
//- (re)set signal catcher
static void set(bool verbose=false);
// Member Functions
//- Is active?
bool active() const;
static bool active();
//- Signal number being used
static int signalNumber();
//- Set/reset signal handler
static void set(bool verbose=false);
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -31,6 +31,10 @@ License
#include "IOstreams.H"
#include "Time.H"
// File-local functions
#include "signalMacros.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Signal number to catch
@ -39,22 +43,20 @@ int Foam::sigWriteNow::signal_
Foam::debug::optimisationSwitch("writeNowSignal", -1)
);
Foam::Time* Foam::sigWriteNow::runTimePtr_ = nullptr;
// Pointer to Time (file-local variable)
static Foam::Time* runTimePtr_ = nullptr;
struct sigaction Foam::sigWriteNow::oldAction_;
// * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * * //
namespace Foam
{
// Register re-reader
class addwriteNowSignalToOpt
struct addwriteNowSignalToOpt
:
public ::Foam::simpleRegIOobject
{
public:
addwriteNowSignalToOpt(const char* name)
:
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
@ -109,50 +111,44 @@ Foam::sigWriteNow::sigWriteNow(Time& runTime, bool verbose)
Foam::sigWriteNow::~sigWriteNow()
{
// Reset old handling
if (signal_ > 0)
if (!active())
{
if (sigaction(signal_, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "Cannot reset " << signal_ << " trapping"
<< abort(FatalError);
}
return;
}
resetHandler("writeNow", signal_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigWriteNow::set(bool verbose)
{
if (signal_ >= 0)
{
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(signal_, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "Cannot set " << signal_ << " trapping"
<< abort(FatalError);
}
if (verbose)
{
Info<< "sigWriteNow :"
<< " Enabling writing upon signal " << signal_
<< endl;
}
}
}
bool Foam::sigWriteNow::active() const
bool Foam::sigWriteNow::active()
{
return signal_ > 0;
}
int Foam::sigWriteNow::signalNumber()
{
return signal_;
}
void Foam::sigWriteNow::set(bool verbose)
{
if (!active())
{
return;
}
if (verbose)
{
Info<< "sigWriteNow :"
<< " Enabling writing upon signal " << signal_ << nl;
}
setHandler("writeNow", signal_, sigHandler);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -27,9 +27,8 @@ Class
Foam::sigWriteNow
Description
Signal handler for interupt defined by OptimisationSwitches::writeNowSignal
Write once and continue.
Signal handler to write once and continue.
The interrupt is defined by OptimisationSwitches::writeNowSignal
SourceFiles
sigWriteNow.C
@ -39,13 +38,12 @@ SourceFiles
#ifndef sigWriteNow_H
#define sigWriteNow_H
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class Time;
/*---------------------------------------------------------------------------*\
@ -54,17 +52,11 @@ class Time;
class sigWriteNow
{
// Private data
// Private Data
//- Number of signal to use
//- Signal number to use
static int signal_;
//- Pointer to Time
static Time* runTimePtr_;
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
@ -74,8 +66,6 @@ class sigWriteNow
public:
friend class sigStopAtWriteNow;
//- Allow setter access to signal_
friend class addwriteNowSignalToOpt;
@ -96,9 +86,12 @@ public:
// Member Functions
//- Is active?
bool active() const;
static bool active();
//- (re)set signal catcher
//- The signal number being used
static int signalNumber();
//- Set/reset signal handler
static void set(bool verbose=false);
};

View File

@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
File-local code for setting/resetting signal handlers.
SourceFiles
signalMacros.C
\*---------------------------------------------------------------------------*/
#include "error.H"
#include <csignal>
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Saved old signal trapping setting (file-local variable)
static struct sigaction oldAction_;
static void resetHandler(const char *what, int sigNum)
{
if (sigaction(sigNum, &oldAction_, nullptr) < 0)
{
FatalError
<< "Cannot unset " << what << " signal (" << sigNum
<< ") trapping" << endl
<< abort(FatalError);
}
}
static void setHandler(const char *what, int sigNum, void (*handler)(int))
{
struct sigaction newAction;
newAction.sa_handler = handler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(sigNum, &newAction, &oldAction_) < 0)
{
FatalError
<< "Could not set " << what << " signal (" << sigNum
<< ") trapping" << endl
<< abort(FatalError);
}
}
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "timer.H"
#include <unistd.h>
// File-local functions
#include "signalMacros.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(timer, 0);
}
jmp_buf Foam::timer::envAlarm;
unsigned int Foam::timer::oldTimeOut_ = 0;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::timer::sigHandler(int)
{
DebugInFunction<< "Timed out. Jumping." << endl;
longjmp(envAlarm, 1);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::timer::timer(unsigned int seconds)
:
timeOut_(seconds)
{
if (!timeOut_)
{
return;
}
// Singleton since handler is static function
if (oldTimeOut_)
{
FatalErrorInFunction
<< "timer already used."
<< abort(FatalError);
}
// Set alarm signal handler
// - do not block any signals while in it
// - clear list of signals to mask
setHandler("SIGALRM", SIGALRM, sigHandler);
// Set alarm timer
oldTimeOut_ = ::alarm(timeOut_);
DebugInFunction
<< "Installing timeout " << int(timeOut_) << " seconds"
<< " (overriding old timeout " << int(oldTimeOut_) << ")." << endl;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::timer::~timer()
{
if (!timeOut_)
{
return;
}
DebugInFunction
<< "timeOut=" << int(timeOut_)
<< " : resetting timeOut to " << int(oldTimeOut_) << endl;
// Reset alarm timer
::alarm(oldTimeOut_);
oldTimeOut_ = 0;
resetHandler("SIGALRM", SIGALRM);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
@ -46,14 +46,15 @@ Description
Constructor set signal handler on sigalarm and alarm(). Destructor
clears these.
timedOut is macro because setjmp can't be in member function of timer.
?something to do with stack frames.
Warning
The setjmp restores complete register state so including local vars
held in regs. So if in blocking part something gets calced in a stack
based variable make sure it is declared 'volatile'.
Note
timedOut is macro because setjmp can't be in member function of timer.
?something to do with stack frames.
SourceFiles
timer.C
@ -63,16 +64,14 @@ SourceFiles
#define timer_H
#include "className.H"
#include <signal.h>
#include <setjmp.h>
#include <csetjmp>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Check it a timeout has occured
//- Check if timeout has occurred
// keep setjmp in same stack frame so no function calls
#define timedOut(x) \
(((x).newTimeOut_ > 0) ? setjmp(Foam::timer::envAlarm) : false)
((x).timeOut_ ? setjmp(Foam::timer::envAlarm) : false)
namespace Foam
{
@ -83,10 +82,7 @@ namespace Foam
class timer
{
// Private data
//- Old signal masks
static struct sigaction oldAction_;
// Private Data
//- Old alarm() value
static unsigned int oldTimeOut_;
@ -95,18 +91,18 @@ class timer
// Private Member Functions
//- Alarm handler
static void signalHandler(int);
static void sigHandler(int);
public:
// Public data
// Public Data
//- Declare name of the class and its debug switch
ClassName("timer");
//- Current time out value. Needed by macro timedOut
unsigned int newTimeOut_;
//- The time-out value (seconds). Needed by macro timedOut
unsigned int timeOut_;
//- State for setjmp. Needed by macro timedOut
static jmp_buf envAlarm;
@ -114,12 +110,11 @@ public:
// Constructors
//- Construct from components.
// newTimeOut=0 makes it do nothing.
timer(const unsigned int newTimeOut);
//- Construct with specified time-out, a value of 0 makes it a no-op.
explicit timer(unsigned int seconds);
//- Destructor
//- Destructor. Restores the alarm and signal handler as required.
~timer();
};

View File

@ -1,133 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include <unistd.h>
#include "error.H"
#include "timer.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(timer, 0);
jmp_buf timer::envAlarm;
struct sigaction timer::oldAction_;
unsigned int timer::oldTimeOut_ = 0;
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::timer::signalHandler(int)
{
if (debug)
{
InfoInFunction<< "Timed out. Jumping."
<< endl;
}
longjmp(envAlarm, 1);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::timer::timer(const unsigned int newTimeOut)
:
newTimeOut_(newTimeOut)
{
if (newTimeOut > 0)
{
// Is singleton since handler is static function
if (oldTimeOut_ != 0)
{
FatalErrorInFunction
<< "timer already used."
<< abort(FatalError);
}
// Install alarm signal handler:
// - do not block any signals while in it
// - clear list of signals to mask
struct sigaction newAction;
newAction.sa_handler = timer::signalHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGALRM, &newAction, &oldAction_) < 0)
{
FatalErrorInFunction
<< "sigaction(SIGALRM) error"
<< abort(FatalError);
}
oldTimeOut_ = ::alarm(newTimeOut);
if (debug)
{
InfoInFunction
<< "Installing timeout " << int(newTimeOut_)
<< " seconds"
<< " (overriding old timeout " << int(oldTimeOut_)
<< ")." << endl;
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::timer::~timer()
{
if (newTimeOut_ > 0)
{
if (debug)
{
InfoInFunction
<< "timeOut=" << int(newTimeOut_)
<< " : resetting timeOut to " << int(oldTimeOut_) << endl;
}
// Reset timer
::alarm(oldTimeOut_);
oldTimeOut_ = 0;
// Restore signal handler
if (sigaction(SIGALRM, &oldAction_, nullptr) < 0)
{
FatalErrorInFunction
<< "sigaction(SIGALRM) error"
<< abort(FatalError);
}
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -52,7 +52,9 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
}
}
allocatedPtr_ = new std::ifstream(pathname);
const std::ios_base::openmode mode(std::ios_base::in|std::ios_base::binary);
allocatedPtr_ = new std::ifstream(pathname, mode);
// If the file is compressed, decompress it before reading.
if (!allocatedPtr_->good() && isFile(pathname + ".gz", false))
@ -63,7 +65,7 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
}
delete allocatedPtr_;
allocatedPtr_ = new igzstream((pathname + ".gz").c_str());
allocatedPtr_ = new igzstream((pathname + ".gz").c_str(), mode);
if (allocatedPtr_->good())
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
@ -55,7 +55,7 @@ Foam::Detail::OFstreamAllocator::OFstreamAllocator
}
}
std::ios_base::openmode mode(std::ios_base::out);
std::ios_base::openmode mode(std::ios_base::out|std::ios_base::binary);
if (append)
{
mode |= std::ios_base::app;

View File

@ -272,7 +272,7 @@ void Foam::dictionary::checkITstream
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
std::exit(1);
}
}
else if (!is.size())
@ -305,7 +305,7 @@ void Foam::dictionary::checkITstream
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
std::exit(1);
}
}
}

View File

@ -116,7 +116,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
std::exit(1);
}
}
else if (!is.size())
@ -149,7 +149,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
std::exit(1);
}
}
}

View File

@ -153,7 +153,7 @@ void Foam::IOerror::SafeFatalIOError
<< " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << '.'
<< std::endl;
::exit(1);
std::exit(1);
}
}
@ -210,7 +210,7 @@ void Foam::IOerror::exit(const int)
{
Perr<< endl << *this << endl
<< "\nFOAM exiting\n" << endl;
::exit(1);
std::exit(1);
}
}
}
@ -229,7 +229,7 @@ void Foam::IOerror::abort()
Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
::abort();
std::abort();
}
if (Pstream::parRun())
@ -256,7 +256,7 @@ void Foam::IOerror::abort()
Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
::abort();
std::abort();
}
}
}

View File

@ -244,7 +244,7 @@ void Foam::error::exit(const int errNo)
{
Perr<< endl << *this << endl
<< "\nFOAM exiting\n" << endl;
::exit(errNo);
std::exit(errNo);
}
}
@ -262,7 +262,7 @@ void Foam::error::abort()
Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
::abort();
std::abort();
}
if (throwExceptions_)
@ -287,7 +287,7 @@ void Foam::error::abort()
Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
::abort();
std::abort();
}
}

View File

@ -887,7 +887,7 @@ bool Foam::functionObjectList::read()
catch (const Foam::IOerror& ioErr)
{
Info<< ioErr << nl << endl;
::exit(1);
std::exit(1);
}
catch (const Foam::error& err)
{

View File

@ -648,7 +648,7 @@ void Foam::argList::setCasePaths()
if (optIter.found())
{
caseDir = optIter.val();
caseDir = fileName::validate(optIter.val());
caseDir.clean();
if (caseDir.empty() || caseDir == ".")
@ -906,7 +906,7 @@ void Foam::argList::parse
if (quickExit)
{
::exit(0);
std::exit(0);
}
}

View File

@ -147,7 +147,7 @@ Foam::dictionary& Foam::debug::switchSet
<< controlDict().name().c_str()
<< std::endl << std::endl;
::exit(1);
std::exit(1);
}
subDictPtr = &(eptr->dict());

View File

@ -82,7 +82,7 @@ static inline void errorMandatoryNotFound
<< locationToString(location) << ")\n '"
<< name << "'\n"
<< std::endl;
::exit(1);
std::exit(1);
}

View File

@ -46,7 +46,7 @@ void newError()
"by e.g. bad use of pointers or an out of date shared library"
<< std::endl;
::abort();
std::abort();
}
void (*old_new_handler)() = std::set_new_handler(newError);

View File

@ -63,7 +63,7 @@ public:
// Member constants
//- Rank of Barycentric is 1
static const direction rank = 1;
static constexpr direction rank = 1;
//- Component labeling enumeration

View File

@ -67,7 +67,7 @@ public:
// Member constants
//- Rank of BarycentricTensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
//- Component labeling enumeration

View File

@ -63,7 +63,7 @@ public:
// Member constants
//- Rank of Barycentric2D is 1
static const direction rank = 1;
static constexpr direction rank = 1;
//- Component labeling enumeration

View File

@ -67,7 +67,7 @@ public:
// Member constants
//- Rank of DiagTensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
//- Component labeling enumeration

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2016 OpenFOAM Foundation
@ -68,20 +68,20 @@ public:
// Member constants
static const direction mRows = Mrows;
static const direction nCols = Ncols;
static constexpr direction mRows = Mrows;
static constexpr direction nCols = Ncols;
// Static member functions
//- Return the number of rows
static direction m()
static direction m() noexcept
{
return Mrows;
}
//- Return the number of columns
static direction n()
static direction n() noexcept
{
return Ncols;
}

View File

@ -345,7 +345,7 @@ inline const Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
) const
{
#ifdef FULLDEBUG
if (i > Mrows-1 || j > Ncols-1)
if (i >= Mrows || j >= Ncols)
{
FatalErrorInFunction
<< "indices out of range"
@ -365,7 +365,7 @@ inline Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
)
{
#ifdef FULLDEBUG
if (i > Mrows-1 || j > Ncols-1)
if (i >= Mrows || j >= Ncols)
{
FatalErrorInFunction
<< "indices out of range"

View File

@ -59,13 +59,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of Scalar is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in Scalar is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -65,7 +65,7 @@ public:
// Member constants
//- Rank of SphericalTensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -61,7 +61,7 @@ public:
// Member constants
//- Rank of SphericalTensor2D is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -67,7 +67,7 @@ public:
// Member constants
//- Rank of SymmTensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -67,7 +67,7 @@ public:
// Member constants
//- Rank of SymmTensor2D is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -53,8 +53,9 @@ See also
namespace Foam
{
template<class Cmpt>
class SymmTensor;
// Forward Declarations
template<class Cmpt> class SymmTensor;
/*---------------------------------------------------------------------------*\
Class Tensor Declaration
@ -75,7 +76,7 @@ public:
// Member constants
//- Rank of Tensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -70,7 +70,7 @@ public:
// Member constants
//- Rank of Tensor2D is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -72,7 +72,7 @@ public:
// Member constants
//- Rank of Vector is 1
static const direction rank = 1;
static constexpr direction rank = 1;
//- Component labeling enumeration

View File

@ -65,7 +65,7 @@ public:
// Member constants
//- Rank of Vector2D is 1
static const direction rank = 1;
static constexpr direction rank = 1;
//- Component labeling enumeration

View File

@ -38,18 +38,15 @@ Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
Istream& is
)
{
// Read beginning of VectorSpace<Cmpt>
is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
is.readBegin("VectorSpace");
for (direction i=0; i<Ncmpts; i++)
{
is >> v_[i];
}
// Read end of VectorSpace<Cmpt>
is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
is.readEnd("VectorSpace");
// Check state of Istream
is.check(FUNCTION_NAME);
}
@ -64,7 +61,7 @@ Foam::word Foam::name
buf << '(' << vs.v_[0];
for (direction i=1; i<Ncmpts; i++)
for (direction i=1; i<Ncmpts; ++i)
{
buf << ',' << vs.v_[i];
}
@ -84,18 +81,15 @@ Foam::Istream& Foam::operator>>
VectorSpace<Form, Cmpt, Ncmpts>& vs
)
{
// Read beginning of VectorSpace<Cmpt, Ncmpts>
is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
is.readBegin("VectorSpace");
for (direction i=0; i<Ncmpts; i++)
{
is >> vs.v_[i];
}
// Read end of VectorSpace<Cmpt, Ncmpts>
is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
is.readEnd("VectorSpace");
// Check state of Istream
is.check(FUNCTION_NAME);
return is;
@ -111,7 +105,7 @@ Foam::Ostream& Foam::operator<<
{
os << token::BEGIN_LIST << vs.v_[0];
for (direction i=1; i<Ncmpts; i++)
for (direction i=1; i<Ncmpts; ++i)
{
os << token::SPACE << vs.v_[i];
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -89,23 +89,23 @@ public:
typedef Cmpt cmptType;
// Static constants
// Static Constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Number of components in this vector space
static const direction nComponents = Ncmpts;
static constexpr direction nComponents = Ncmpts;
// VectorSpace currently defaults to a column-vector
// This will be removed when column-vector is introduced
// as a specialization
static const direction mRows = Ncmpts;
static const direction nCols = 1;
static constexpr direction mRows = Ncmpts;
static constexpr direction nCols = 1;
// Static data members
// Static Data Members
static const char* const typeName;
static const char* const componentNames[];
@ -120,11 +120,7 @@ public:
// Sub-Block Classes
//- Const sub-block type
template
<
class SubVector,
direction BStart
>
template<class SubVector, direction BStart>
class ConstBlock
{
const vsType& vs_;
@ -158,12 +154,12 @@ public:
inline VectorSpace(const Foam::zero);
//- Construct from Istream
VectorSpace(Istream&);
VectorSpace(Istream& is);
//- Construct as copy
inline VectorSpace(const VectorSpace<Form, Cmpt, Ncmpts>&);
//- Copy construct
inline VectorSpace(const VectorSpace<Form, Cmpt, Ncmpts>& vs);
//- Construct as copy of a VectorSpace with the same size
//- Copy construct of a VectorSpace with the same size
template<class Form2, class Cmpt2>
inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
@ -171,7 +167,7 @@ public:
// Member Functions
//- Return the number of elements in the VectorSpace = Ncmpts.
inline static direction size();
inline static constexpr direction size();
inline const Cmpt& component(const direction) const;
inline Cmpt& component(const direction);
@ -200,6 +196,39 @@ public:
inline void operator/=(const scalar);
// Iterators
//- Random access iterator for traversing VectorSpace
typedef Cmpt* iterator;
//- Random access iterator for traversing VectorSpace
typedef const Cmpt* const_iterator;
// Random access iterator (non-const)
//- Return an iterator to begin of VectorSpace
inline iterator begin();
//- Return an iterator to end of UListVectorSpace
inline iterator end();
// Random access iterator (const)
//- Return const_iterator to begin of VectorSpace
inline const_iterator cbegin() const;
//- Return const_iterator to end of VectorSpace
inline const_iterator cend() const;
//- Return const_iterator to begin of VectorSpace
inline const_iterator begin() const;
//- Return const_iterator to end of VectorSpace
inline const_iterator end() const;
// IOstream Operators
friend Istream& operator>> <Form, Cmpt, Ncmpts>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -31,27 +31,23 @@ License
#include "ops.H"
#include <type_traits>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Form, class Cmpt, direction Ncmpts>
inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace()
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace()
{}
template<class Form, class Cmpt, direction Ncmpts>
inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(const Foam::zero)
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(const Foam::zero)
{
VectorSpaceOps<Ncmpts,0>::eqOpS(*this, Zero, eqOp<Cmpt>());
}
template<class Form, class Cmpt, direction Ncmpts>
inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
(
const VectorSpace<Form, Cmpt, Ncmpts>& vs
)
@ -60,9 +56,9 @@ inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
}
template<class Form, class Cmpt, direction Ncmpts>
template<class Form, class Cmpt, Foam::direction Ncmpts>
template<class Form2, class Cmpt2>
inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
(
const VectorSpace<Form2, Cmpt2, Ncmpts>& vs
)
@ -71,10 +67,10 @@ inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
}
template<class Form, class Cmpt, direction Ncmpts>
template<class SubVector, direction BStart>
inline
VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>::ConstBlock
template<class Form, class Cmpt, Foam::direction Ncmpts>
template<class SubVector, Foam::direction BStart>
inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>
::ConstBlock
(
const vsType& vs
)
@ -91,15 +87,15 @@ VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>::ConstBlock
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Form, class Cmpt, direction Ncmpts>
inline direction VectorSpace<Form, Cmpt, Ncmpts>::size()
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline constexpr Foam::direction Foam::VectorSpace<Form, Cmpt, Ncmpts>::size()
{
return Ncmpts;
}
template<class Form, class Cmpt, direction Ncmpts>
inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
(
const direction d
) const
@ -117,8 +113,8 @@ inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
}
template<class Form, class Cmpt, direction Ncmpts>
inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
(
const direction d
)
@ -136,8 +132,8 @@ inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::component
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
(
Cmpt& c,
const direction d
@ -156,8 +152,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::component
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::replace
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::replace
(
const direction d,
const Cmpt& c
@ -176,8 +172,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::replace
}
template<class Form, class Cmpt, direction Ncmpts>
inline Form VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Form Foam::VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
{
Form v;
VectorSpaceOps<Ncmpts,0>::eqOpS(v, s, eqOp<Cmpt>());
@ -185,20 +181,64 @@ inline Form VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
}
template<class Form, class Cmpt, direction Ncmpts>
template<class SubVector, direction BStart>
inline const typename VectorSpace<Form, Cmpt, Ncmpts>::template
template<class Form, class Cmpt, Foam::direction Ncmpts>
template<class SubVector, Foam::direction BStart>
inline const typename Foam::VectorSpace<Form, Cmpt, Ncmpts>::template
ConstBlock<SubVector, BStart>
VectorSpace<Form, Cmpt, Ncmpts>::block() const
Foam::VectorSpace<Form, Cmpt, Ncmpts>::block() const
{
return *this;
}
// * * * * * * * * * * * * * * * * Iterator * * * * * * * * * * * * * * * * //
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::begin()
{
return v_;
}
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::end()
{
return (v_ + Ncmpts);
}
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::cbegin() const
{
return v_;
}
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::cend() const
{
return (v_ + Ncmpts);
}
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::begin() const
{
return v_;
}
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::end() const
{
return (v_ + Ncmpts);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Form, class Cmpt, direction Ncmpts>
inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline const Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator[]
(
const direction d
) const
@ -216,8 +256,8 @@ inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
}
template<class Form, class Cmpt, direction Ncmpts>
inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator[]
(
const direction d
)
@ -235,10 +275,10 @@ inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
}
template<class Form, class Cmpt, direction Ncmpts>
template<class SubVector, direction BStart>
template<class Form, class Cmpt, Foam::direction Ncmpts>
template<class SubVector, Foam::direction BStart>
inline const Cmpt&
VectorSpace<Form, Cmpt, Ncmpts>::
Foam::VectorSpace<Form, Cmpt, Ncmpts>::
ConstBlock<SubVector, BStart>::operator[]
(
const direction d
@ -257,10 +297,10 @@ ConstBlock<SubVector, BStart>::operator[]
}
template<class Form, class Cmpt, direction Ncmpts>
template<class SubVector, direction BStart>
template<class Form, class Cmpt, Foam::direction Ncmpts>
template<class SubVector, Foam::direction BStart>
inline const Cmpt&
VectorSpace<Form, Cmpt, Ncmpts>::
Foam::VectorSpace<Form, Cmpt, Ncmpts>::
ConstBlock<SubVector, BStart>::operator()
(
const direction i,
@ -275,7 +315,7 @@ ConstBlock<SubVector, BStart>::operator()
<< abort(FatalError);
}
if (j != 0)
if (j)
{
FatalErrorInFunction
<< "index " << j << " != 0"
@ -287,8 +327,8 @@ ConstBlock<SubVector, BStart>::operator()
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator=
(
const VectorSpace<Form, Cmpt, Ncmpts>& vs
)
@ -297,8 +337,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator+=
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator+=
(
const VectorSpace<Form, Cmpt, Ncmpts>& vs
)
@ -307,8 +347,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator+=
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator-=
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator-=
(
const VectorSpace<Form, Cmpt, Ncmpts>& vs
)
@ -317,15 +357,15 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator-=
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=(const Foam::zero)
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator=(const Foam::zero)
{
VectorSpaceOps<Ncmpts,0>::eqOpS(*this, 0, eqOp<Cmpt>());
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator*=
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator*=
(
const scalar s
)
@ -334,8 +374,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator*=
}
template<class Form, class Cmpt, direction Ncmpts>
inline void VectorSpace<Form, Cmpt, Ncmpts>::operator/=
template<class Form, class Cmpt, Foam::direction Ncmpts>
inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator/=
(
const scalar s
)
@ -344,6 +384,11 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator/=
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Form, class Cmpt, direction Ncmpts>

View File

@ -77,13 +77,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of bool is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in bool is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -47,11 +47,19 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
char readChar(Istream&);
Istream& operator>>(Istream&, char&);
Ostream& operator<<(Ostream&, const char);
Ostream& operator<<(Ostream&, const char*);
//- Read single character
char readChar(Istream& is);
//- Read single character
Istream& operator>>(Istream& is, char& c);
//- Write single character
Ostream& operator<<(Ostream& os, const char c);
//- Write a nul-terminated C-string
Ostream& operator<<(Ostream& os, const char* str);
//- Test for \em horizontal whitespace
inline bool isspace(char c)
{
return
@ -63,6 +71,7 @@ inline bool isspace(char c)
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -54,9 +54,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const char c)
}
Foam::Ostream& Foam::operator<<(Ostream& os, const char* s)
Foam::Ostream& Foam::operator<<(Ostream& os, const char* str)
{
os.write(s);
os.write(str);
os.check(FUNCTION_NAME);
return os;
}

View File

@ -35,6 +35,41 @@ const Foam::complex Foam::complex::zero(0, 0);
const Foam::complex Foam::complex::one(1, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const char* const Foam::pTraits<Foam::complex>::typeName = "complex";
const char* const Foam::pTraits<Foam::complex>::componentNames[] = {"re", "im"};
const Foam::complex Foam::pTraits<Foam::complex>::zero(0, 0);
const Foam::complex Foam::pTraits<Foam::complex>::one(1, 0);
const Foam::complex Foam::pTraits<Foam::complex>::min(-VGREAT, -VGREAT);
const Foam::complex Foam::pTraits<Foam::complex>::max(VGREAT, VGREAT);
const Foam::complex Foam::pTraits<Foam::complex>::rootMin
(
-ROOTVGREAT, -ROOTVGREAT
);
const Foam::complex Foam::pTraits<Foam::complex>::rootMax
(
ROOTVGREAT, ROOTVGREAT
);
Foam::pTraits<Foam::complex>::pTraits(const complex& val)
:
p_(val)
{}
Foam::pTraits<Foam::complex>::pTraits(Istream& is)
{
is >> p_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::complex::complex(Istream& is)

View File

@ -232,6 +232,70 @@ public:
};
// Template specialisation for pTraits<complex>
template<>
class pTraits<complex>
{
complex p_;
public:
//- Component type
typedef complex cmptType;
//- Equivalent type of labels used for valid component indexing
typedef label labelType;
// Member constants
//- Dimensionality of space
static constexpr direction dim = 3;
//- Rank of complex is 0
static constexpr direction rank = 0;
//- Number of components in complex is 2
static constexpr direction nComponents = 2;
// Static Data Members
static const char* const typeName;
static const char* const componentNames[];
static const complex zero;
static const complex one;
static const complex max;
static const complex min;
static const complex rootMax;
static const complex rootMin;
// Constructors
//- Construct from primitive
explicit pTraits(const complex& val);
//- Construct from Istream
pTraits(Istream& is);
// Member Functions
//- Access to the value
operator complex() const
{
return p_;
}
//- Access to the value
operator complex&()
{
return p_;
}
};
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
Istream& operator>>(Istream& is, complex& c);

View File

@ -350,6 +350,7 @@ inline complex operator/(const scalar s, const complex& c)
return complex(s/c.re, s/c.im);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -142,13 +142,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of int32_t is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in int32_t is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -143,13 +143,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of int64_t is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in int64_t is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -133,13 +133,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of uint32_t is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in uint32_t is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -141,13 +141,13 @@ public:
// Member constants
//- Dimensionality of space
static const direction dim = 3;
static constexpr direction dim = 3;
//- Rank of uint64_t is 0
static const direction rank = 0;
static constexpr direction rank = 0;
//- Number of components in uint64_t is 1
static const direction nComponents = 1;
static constexpr direction nComponents = 1;
// Static data members

View File

@ -110,7 +110,7 @@ public:
// Member constants
//- Rank of quaternion is 1
static const direction rank = 1;
static constexpr direction rank = 1;
// Static data members

View File

@ -74,7 +74,7 @@ public:
// Member constants
//- Rank of Tensor is 2
static const direction rank = 2;
static constexpr direction rank = 2;
// Static data members

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
@ -36,7 +36,11 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* const Foam::fileName::typeName = "fileName";
int Foam::fileName::debug(debug::debugSwitch(fileName::typeName, 0));
int Foam::fileName::debug(Foam::debug::debugSwitch(fileName::typeName, 0));
int Foam::fileName::allowSpaceInFileName
(
Foam::debug::infoSwitch("allowSpaceInFileName", 0)
);
const Foam::fileName Foam::fileName::null;
@ -48,16 +52,27 @@ Foam::fileName Foam::fileName::validate
const bool doClean
)
{
fileName out;
out.resize(s.size());
// The logic is very similar to stripInvalid,
// but silently removes bad characters
fileName out;
out.resize(s.length());
char prev = 0;
std::string::size_type len = 0;
// Largely as per stripInvalid
char prev = 0;
for (auto iter = s.cbegin(); iter != s.cend(); ++iter)
{
const char c = *iter;
char c = *iter;
// Treat raw backslash like a path separator. There is no "normal"
// way for these to be there (except for an OS that uses them), but
// could also cause issues when writing strings, shell commands etc.
if (c == '\\')
{
c = '/';
}
if (fileName::valid(c))
{
@ -84,6 +99,33 @@ Foam::fileName Foam::fileName::validate
}
Foam::fileName Foam::fileName::concat
(
const std::string& s1,
const std::string& s2
)
{
const auto n1 = s1.length();
const auto n2 = s2.length();
fileName out;
out.reserve(n1 + n2 + 1);
out += s1;
if (n1 && n2 && s1.back() != '/' && s2.front() != '/')
{
// Add separator
out += '/';
}
out += s2;
// Could also remove trailing '/', if desired.
return out;
}
bool Foam::fileName::equals(const std::string& s1, const std::string& s2)
{
// Do not use (s1 == s2) or s1.compare(s2) first since this would
@ -92,8 +134,8 @@ bool Foam::fileName::equals(const std::string& s1, const std::string& s2)
std::string::size_type i1 = 0;
std::string::size_type i2 = 0;
const auto n1 = s1.size();
const auto n2 = s2.size();
const auto n1 = s1.length();
const auto n2 = s2.length();
//Info<< "compare " << s1 << " == " << s2 << endl;
while (i1 < n1 && i2 < n2)
@ -249,7 +291,7 @@ bool Foam::fileName::clean(std::string& str)
// Number of output characters
auto nChar = top+1;
const auto maxLen = str.size();
const auto maxLen = str.length();
for (auto src = nChar; src < maxLen; /*nil*/)
{
@ -462,7 +504,7 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
s += '/';
}
s.append(other);
s += other;
}
}
else if (other.size())
@ -477,32 +519,32 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
Foam::fileName Foam::operator/(const string& a, const string& b)
Foam::fileName Foam::operator/(const string& s1, const string& s2)
{
if (a.size())
if (s1.length())
{
if (b.size())
if (s2.length())
{
// Two non-empty strings: can concatenate
if (a.back() == '/' || b.front() == '/')
if (s1.back() == '/' || s2.front() == '/')
{
return fileName(a + b);
return fileName(s1 + s2);
}
else
{
return fileName(a + '/' + b);
return fileName(s1 + '/' + s2);
}
}
// The second string was empty
return a;
return s1;
}
if (b.size())
if (s2.length())
{
// The first string is empty
return b;
return s2;
}
// Both strings are empty

View File

@ -82,7 +82,7 @@ public:
};
// Static data members
// Static Data Members
//- The typeName
static const char* const typeName;
@ -90,6 +90,9 @@ public:
//- Debugging
static int debug;
//- Allow space character in fileName. To be used with caution.
static int allowSpaceInFileName;
//- An empty fileName
static const fileName null;
@ -141,14 +144,16 @@ public:
//- Is this character valid for a fileName?
inline static bool valid(char c);
//- Construct validated fileName (no invalid characters).
// Optionally perform some additional cleanup such as removing
// duplicate or trailing slashes.
static fileName validate
(
const std::string& s,
const bool doClean=false
);
//- Construct fileName with no invalid characters, possibly applying
//- other transformations such as changing the path separator,
//- removing duplicate or trailing slashes, etc.
static fileName validate(const std::string& s, const bool doClean=true);
//- Join two strings with '/' as a path separator.
// No '/' separator is added if either argument is an empty string or
// if the arguments already had the path separator at the junction.
// Invalid characters are \em not stripped (ie, retained).
static fileName concat(const std::string& s1, const std::string& s2);
//- This is a specialized (possibly slower) version of compare()
//- that ignores duplicate or trailing slashes.
@ -403,7 +408,7 @@ Ostream& operator<<(Ostream& os, const fileName& val);
//- Assemble words and fileNames as pathnames by adding a '/' separator.
// No '/' separator is added if either argument is an empty string.
fileName operator/(const string& a, const string& b);
fileName operator/(const string& s1, const string& s2);
//- Recursively search the given directory for the file

View File

@ -102,9 +102,9 @@ inline bool Foam::fileName::valid(char c)
{
return
(
!isspace(c)
&& c != '"' // string quote
c != '"' // string quote
&& c != '\'' // string quote
&& (!isspace(c) || (allowSpaceInFileName && c == ' '))
);
}
@ -134,7 +134,10 @@ inline void Foam::fileName::stripInvalid()
inline bool Foam::fileName::isAbsolute(const std::string& str)
{
return !str.empty() && str[0] == '/';
return
(
!str.empty() && str[0] == '/'
);
}

View File

@ -58,14 +58,14 @@ bool Foam::UPstream::init(int& argc, char**& argv, const bool needsThread)
void Foam::UPstream::exit(int errnum)
{
// No MPI - just exit
::exit(errnum);
std::exit(errnum);
}
void Foam::UPstream::abort()
{
// No MPI - just abort
::abort();
std::abort();
}

View File

@ -213,7 +213,7 @@ void Foam::UPstream::exit(int errnum)
if (!flag)
{
// Not initialized - just exit
::exit(errnum);
std::exit(errnum);
return;
}
@ -224,7 +224,7 @@ void Foam::UPstream::exit(int errnum)
WarningInFunction
<< "MPI was already finalized (perhaps by a connected program)"
<< endl;
::exit(1);
std::exit(1);
return;
}
@ -271,7 +271,7 @@ void Foam::UPstream::exit(int errnum)
if (errnum == 0)
{
MPI_Finalize();
::exit(errnum);
std::exit(errnum);
}
else
{

View File

@ -118,7 +118,7 @@ bool Foam::ccm::ccmGlobalState::assertNoError
<< "\n libccmio reports -> " << errorMsg(err) << " <-\n"
<< endl;
::exit(1);
std::exit(1);
}
return (err == kCCMIONoErr);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -59,19 +59,20 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
if (!dict.found("value"))
{
FatalIOErrorInFunction(dict)
<< "\n Cannot find 'value' entry"
<< nl << " Cannot find 'value' entry"
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl
<< " in file " << this->internalField().objectPath() << nl
<< " which is required to set the"
" values of the generic patch field." << nl
<< " (Actual type " << actualTypeName_ << ")" << nl
<< "\n Please add the 'value' entry to the write function "
"of the user-defined boundary-condition\n"
<< " (Actual type " << actualTypeName_ << ')' << nl << nl
<< " Please add the 'value' entry to the write function"
" of the user-defined boundary-condition" << nl
<< exit(FatalIOError);
}
@ -79,14 +80,17 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
@ -108,11 +112,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
key,
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
@ -123,7 +123,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -143,18 +143,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -176,18 +176,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -203,27 +203,24 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -239,27 +236,24 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -281,18 +275,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -307,7 +301,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -326,7 +320,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<scalarField>::New
(
this->size(),
patchSize,
fieldToken.number()
)
);
@ -347,7 +341,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<vectorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -361,7 +355,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<sphericalTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -375,7 +369,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<symmTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -394,7 +388,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<tensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -407,15 +401,13 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}
}
}
}
template<class Type>
@ -707,9 +699,11 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
if (key == "type" || key == "value")
{
if
continue;
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
@ -719,28 +713,23 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
{
if (scalarFields_.found(key))
{
scalarFields_.find(key)()
->writeEntry(key, os);
scalarFields_.cfind(key)()->writeEntry(key, os);
}
else if (vectorFields_.found(key))
{
vectorFields_.find(key)()
->writeEntry(key, os);
vectorFields_.cfind(key)()->writeEntry(key, os);
}
else if (sphTensorFields_.found(key))
{
sphTensorFields_.find(key)()
->writeEntry(key, os);
sphTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (symmTensorFields_.found(key))
{
symmTensorFields_.find(key)()
->writeEntry(key, os);
symmTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (tensorFields_.found(key))
{
tensorFields_.find(key)()
->writeEntry(key, os);
tensorFields_.cfind(key)()->writeEntry(key, os);
}
}
else
@ -748,7 +737,6 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
dEntry.write(os);
}
}
}
this->writeEntry("value", os);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -56,22 +56,23 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
:
calculatedFvPatchField<Type>(p, iF, dict),
actualTypeName_(dict.lookup("type")),
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
if (!dict.found("value"))
{
FatalIOErrorInFunction(dict)
<< "\n Cannot find 'value' entry"
<< nl << " Cannot find 'value' entry"
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl
<< " in file " << this->internalField().objectPath() << nl
<< " which is required to set the"
" values of the generic patch field." << nl
<< " (Actual type " << actualTypeName_ << ")" << nl
<< "\n Please add the 'value' entry to the write function "
"of the user-defined boundary-condition\n"
<< " (Actual type " << actualTypeName_ << ')' << nl << nl
<< " Please add the 'value' entry to the write function"
" of the user-defined boundary-condition" << nl
<< exit(FatalIOError);
}
@ -79,14 +80,17 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
@ -108,11 +112,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
dEntry.keyword(),
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
@ -123,7 +123,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -143,18 +143,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -176,18 +176,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -203,27 +203,24 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -239,27 +236,24 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -281,18 +275,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -307,7 +301,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -326,7 +320,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<scalarField>::New
(
this->size(),
patchSize,
fieldToken.number()
)
);
@ -347,7 +341,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<vectorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -361,7 +355,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<sphericalTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -375,7 +369,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<symmTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -394,7 +388,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<tensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -407,15 +401,13 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}
}
}
}
template<class Type>
@ -707,9 +699,11 @@ void Foam::genericFvPatchField<Type>::write(Ostream& os) const
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
if (key == "type" || key == "value")
{
if
continue;
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
@ -719,28 +713,23 @@ void Foam::genericFvPatchField<Type>::write(Ostream& os) const
{
if (scalarFields_.found(key))
{
scalarFields_.find(key)()
->writeEntry(key, os);
scalarFields_.cfind(key)()->writeEntry(key, os);
}
else if (vectorFields_.found(key))
{
vectorFields_.find(key)()
->writeEntry(key, os);
vectorFields_.cfind(key)()->writeEntry(key, os);
}
else if (sphTensorFields_.found(key))
{
sphTensorFields_.find(key)()
->writeEntry(key, os);
sphTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (symmTensorFields_.found(key))
{
symmTensorFields_.find(key)()
->writeEntry(key, os);
symmTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (tensorFields_.found(key))
{
tensorFields_.find(key)()
->writeEntry(key, os);
tensorFields_.cfind(key)()->writeEntry(key, os);
}
}
else
@ -748,7 +737,6 @@ void Foam::genericFvPatchField<Type>::write(Ostream& os) const
dEntry.write(os);
}
}
}
this->writeEntry("value", os);
}

View File

@ -54,22 +54,23 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
)
:
calculatedFvsPatchField<Type>(p, iF, dict),
actualTypeName_(dict.lookup("type")),
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
if (!dict.found("value"))
{
FatalIOErrorInFunction(dict)
<< "\n Cannot find 'value' entry"
<< nl << " Cannot find 'value' entry"
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl
<< " in file " << this->internalField().objectPath() << nl
<< " which is required to set the"
" values of the generic patch field." << nl
<< " (Actual type " << actualTypeName_ << ")" << nl
<< "\n Please add the 'value' entry to the write function "
"of the user-defined boundary-condition\n"
<< " (Actual type " << actualTypeName_ << ')' << nl << nl
<< " Please add the 'value' entry to the write function"
" of the user-defined boundary-condition" << nl
<< exit(FatalIOError);
}
@ -77,14 +78,17 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
@ -106,11 +110,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
dEntry.keyword(),
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
@ -121,7 +121,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -141,18 +141,18 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -174,18 +174,18 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -201,27 +201,24 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -237,27 +234,24 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -279,18 +273,18 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -305,7 +299,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -324,7 +318,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
key,
autoPtr<scalarField>::New
(
this->size(),
patchSize,
fieldToken.number()
)
);
@ -345,7 +339,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
key,
autoPtr<vectorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -359,7 +353,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
key,
autoPtr<sphericalTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -373,7 +367,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
key,
autoPtr<symmTensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -392,7 +386,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
key,
autoPtr<tensorField>::New
(
this->size(),
patchSize,
vs
)
);
@ -405,15 +399,13 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}
}
}
}
template<class Type>
@ -705,9 +697,11 @@ void Foam::genericFvsPatchField<Type>::write(Ostream& os) const
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
if (key == "type" || key == "value")
{
if
continue;
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
@ -717,28 +711,23 @@ void Foam::genericFvsPatchField<Type>::write(Ostream& os) const
{
if (scalarFields_.found(key))
{
scalarFields_.find(key)()
->writeEntry(key, os);
scalarFields_.cfind(key)()->writeEntry(key, os);
}
else if (vectorFields_.found(key))
{
vectorFields_.find(key)()
->writeEntry(key, os);
vectorFields_.cfind(key)()->writeEntry(key, os);
}
else if (sphTensorFields_.found(key))
{
sphTensorFields_.find(key)()
->writeEntry(key, os);
sphTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (symmTensorFields_.found(key))
{
symmTensorFields_.find(key)()
->writeEntry(key, os);
symmTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (tensorFields_.found(key))
{
tensorFields_.find(key)()
->writeEntry(key, os);
tensorFields_.cfind(key)()->writeEntry(key, os);
}
}
else
@ -746,7 +735,6 @@ void Foam::genericFvsPatchField<Type>::write(Ostream& os) const
dEntry.write(os);
}
}
}
this->writeEntry("value", os);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -55,18 +55,22 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
for (const entry& dEntry : dict_)
{
const keyType& key = dEntry.keyword();
if (key != "type")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
@ -88,11 +92,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
key,
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
@ -103,7 +103,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
@ -123,18 +123,18 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -156,18 +156,18 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -183,27 +183,24 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -219,27 +216,24 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -261,18 +255,18 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
@ -287,14 +281,12 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}
}
}
template<class Type>
@ -488,9 +480,11 @@ void Foam::genericPointPatchField<Type>::write(Ostream& os) const
{
const keyType& key = dEntry.keyword();
if (key != "type")
if (key == "type" || key == "value")
{
if
continue;
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
@ -500,23 +494,23 @@ void Foam::genericPointPatchField<Type>::write(Ostream& os) const
{
if (scalarFields_.found(key))
{
scalarFields_.find(key)()->writeEntry(key, os);
scalarFields_.cfind(key)()->writeEntry(key, os);
}
else if (vectorFields_.found(key))
{
vectorFields_.find(key)()->writeEntry(key, os);
vectorFields_.cfind(key)()->writeEntry(key, os);
}
else if (sphTensorFields_.found(key))
{
sphTensorFields_.find(key)()->writeEntry(key, os);
sphTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (symmTensorFields_.found(key))
{
symmTensorFields_.find(key)()->writeEntry(key, os);
symmTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (tensorFields_.found(key))
{
tensorFields_.find(key)()->writeEntry(key, os);
tensorFields_.cfind(key)()->writeEntry(key, os);
}
}
else
@ -525,7 +519,6 @@ void Foam::genericPointPatchField<Type>::write(Ostream& os) const
}
}
}
}
// ************************************************************************* //

View File

@ -3916,7 +3916,7 @@ void Foam::snappyLayerDriver::addLayers
else
{
Perr<< "\nFOAM exiting\n" << endl;
::exit(0);
std::exit(0);
}
}
}

View File

@ -253,9 +253,18 @@ void Foam::PatchFunction1Types::ConstantField<Type>::writeData
) const
{
PatchFunction1<Type>::writeData(os);
//os << token::SPACE << value_ << token::END_STATEMENT << nl;
if (isUniform_)
{
os.writeKeyword(this->name_)
<< "constant " << uniformValue_
<< token::END_STATEMENT << nl;
}
else
{
value_.writeEntry(this->name_, os);
}
}
// ************************************************************************* //

View File

@ -41,7 +41,8 @@ wmakeLnInclude -u decompositionMethods
if have_scotch
then
wmake $targetType scotchDecomp
if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
if have_ptscotch
then
wmakeMpiLib "$SCOTCH_VERSION" ptscotchDecomp
fi

View File

@ -1,13 +1,12 @@
/*
* NB: mplib PINC must appear after the SCOTCH_ARCH_PATH/include/FOAM_MPI
* to ensure we do not accidentally get a ptscotch header from the
* mpi distribution.
* NB: mplib PINC must appear after PTSCOTCH_INC_DIR to ensure we
* do not accidentally get a ptscotch header from the MPI distribution.
*/
sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB)
sinclude $(DEFAULT_RULES)/mplib$(WM_MPLIB)
EXE_INC = \
-I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \
-I$(PTSCOTCH_INC_DIR) \
-I$(SCOTCH_INC_DIR) \
$(PFLAGS) $(PINC) \
-I../decompositionMethods/lnInclude
@ -17,9 +16,8 @@ EXE_INC = \
* ptscotch 6 requires scotch linked in, but does not declare the dependency
*/
LIB_LIBS = \
-L$(PTSCOTCH_LIB_DIR) \
-L$(SCOTCH_LIB_DIR) \
-L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) \
-L$(FOAM_EXT_LIBBIN) \
-lptscotch -lptscotcherrexit \
-lscotch

View File

@ -384,9 +384,11 @@ bool Foam::surfaceWriter::expire()
upToDate_ = false;
wroteGeom_ = false;
nFields_ = 0;
merged_.clear();
// Field count (nFields_) is a different type of accounting
// and is unaffected by geometry changes
return changed;
}

View File

@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Make sure all preprocessing tools know about the 'overset' bc
libs ("liboverset.so");
libs ("liboverset.so" "libfvMotionSolvers.so");
application overLaplacianDyMFoam;

Some files were not shown because too many files have changed in this diff Show More