diff --git a/applications/test/copyFile/Test-copyFile.C b/applications/test/copyFile/Test-copyFile.C index 7d6de05d0a304673301cd5c36d195544b41e2409..5747287606dda4844a348350c9c5c3a183d71853 100644 --- a/applications/test/copyFile/Test-copyFile.C +++ b/applications/test/copyFile/Test-copyFile.C @@ -37,42 +37,68 @@ using namespace Foam; #define WIN32_LEAN_AND_MEAN #include <windows.h> -// Prefix '\\?\' for extended-length path -inline std::string longName(const std::string& file) +unsigned maxPath = MAX_PATH; + +// Prefix "\\?\" for extended-length path and widen +// The prefix is only valid with absolute paths +// +// In the future, this code will be relocated in MSwindows.C + +static inline std::wstring longName(const fileName& file) { - std::string longName; - longName.reserve(4 + file.length()); + const auto len = file.length(); - longName.append("\\\\?\\"); - longName.append(file); + std::wstring out; + out.reserve(4 + len); - return longName; -} + if (len > maxPath) + { + if (file.isAbsolute()) + { + out.append(L"\\\\?\\"); + } + else + { + Warning + << "Relative fileName exceeds " << maxPath + << " characters" << nl + << " " << file << nl << nl; + } + } -bool win_cp(const fileName& src, const fileName& dst) -{ - const std::string srcName(longName(src)); - const std::string dstName(longName(dst)); + // Character-wise copy to get widening + for (const auto c : file) + { + out += c; + } - return ::CopyFile(srcName.c_str(), dstName.c_str(), false); + return out; } + bool win_mv(const fileName& src, const fileName& dst) { - const std::string srcName(longName(src)); - const std::string dstName(longName(dst)); - - return ::MoveFile(srcName.c_str(), dstName.c_str()); -} + constexpr const int flags + ( + MOVEFILE_COPY_ALLOWED + | MOVEFILE_REPLACE_EXISTING + | MOVEFILE_WRITE_THROUGH + ); + + if (src.length() > maxPath || dst.length() > maxPath) + { + const std::wstring srcName(longName(src)); + const std::wstring dstName(longName(dst)); -#else + Info<< "Windows mv (wide)" << nl; + return ::MoveFileExW(srcName.c_str(), dstName.c_str(), flags); + } -bool win_cp(const fileName& src, const fileName& dst) -{ - Info<< "No Windows cp, using Foam::cp" << nl; - return Foam::cp(src, dst); + Info<< "Windows mv (ansi)" << nl; + return ::MoveFileExA(src.c_str(), dst.c_str(), flags); } +#else bool win_mv(const fileName& src, const fileName& dst) { @@ -95,8 +121,7 @@ int main(int argc, char *argv[]) #ifdef _WIN32 argList::addBoolOption("win1", "Foam cp, Windows mv"); - argList::addBoolOption("win2", "Windows cp, Foam mv"); - argList::addBoolOption("win3", "Windows cp, Windows mv"); + argList::addOption("maxPath", "length", "Test with shorter MAX_PATH"); #endif argList::addArgument("srcFile"); @@ -104,6 +129,10 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + #ifdef _WIN32 + args.readIfPresent("maxPath", maxPath); + #endif + const fileName srcFile(fileName::validate(args[1])); const fileName dstFile(fileName::validate(args[2])); const fileName tmpFile(dstFile + Foam::name(pid())); @@ -111,11 +140,13 @@ int main(int argc, char *argv[]) Info<< "src : " << srcFile << nl << "tmp : " << tmpFile << nl << "dst : " << dstFile << nl + #ifdef _WIN32 + << "test with max-path: " << maxPath << nl + #endif << nl; bool cpOk = false, mvOk = false; - if (args.found("win1")) { const auto usage = argList::optionUsage.cfind("win1"); @@ -127,28 +158,6 @@ int main(int argc, char *argv[]) cpOk = Foam::cp(srcFile, tmpFile); mvOk = win_mv(tmpFile, dstFile); } - else if (args.found("win2")) - { - const auto usage = argList::optionUsage.cfind("win2"); - if (usage.good()) - { - Info<< " " << (*usage).c_str() << nl; - } - - cpOk = win_cp(srcFile, tmpFile); - mvOk = Foam::mv(tmpFile, dstFile); - } - else if (args.found("win3")) - { - const auto usage = argList::optionUsage.cfind("win3"); - if (usage.good()) - { - Info<< " " << (*usage).c_str() << nl; - } - - cpOk = win_cp(srcFile, tmpFile); - mvOk = win_mv(tmpFile, dstFile); - } else { Info<< " Foam cp, Foam mv" << nl; diff --git a/etc/caseDicts/postProcessing/pressure/staticPressure.cfg b/etc/caseDicts/postProcessing/pressure/staticPressure.cfg index 0651d8cc665e8ff6b71f43817deb3f7bb0da16f6..15df571c5bfd4837783f00ace017a88839955553 100644 --- a/etc/caseDicts/postProcessing/pressure/staticPressure.cfg +++ b/etc/caseDicts/postProcessing/pressure/staticPressure.cfg @@ -8,8 +8,7 @@ #includeEtc "caseDicts/postProcessing/pressure/pressure.cfg" -calcTotal no; -calcCoeff no; +mode static; rho rhoInf; // ************************************************************************* // diff --git a/etc/caseDicts/postProcessing/pressure/totalPressureCompressible.cfg b/etc/caseDicts/postProcessing/pressure/totalPressureCompressible.cfg index 5dcde87af11c1bb2760efac1e2c134b7ffe65dca..6be21f521507f84ceb3bb6b3e0db3afcff204cb3 100644 --- a/etc/caseDicts/postProcessing/pressure/totalPressureCompressible.cfg +++ b/etc/caseDicts/postProcessing/pressure/totalPressureCompressible.cfg @@ -8,7 +8,6 @@ #includeEtc "caseDicts/postProcessing/pressure/pressure.cfg" -calcTotal yes; -calcCoeff no; +mode total; // ************************************************************************* // diff --git a/etc/caseDicts/postProcessing/pressure/totalPressureIncompressible.cfg b/etc/caseDicts/postProcessing/pressure/totalPressureIncompressible.cfg index 3419c267571aaf8bbb2aa7b4806010eece58075d..5515aafe928a638ec4c020fc0a7436ff699ea422 100644 --- a/etc/caseDicts/postProcessing/pressure/totalPressureIncompressible.cfg +++ b/etc/caseDicts/postProcessing/pressure/totalPressureIncompressible.cfg @@ -8,8 +8,7 @@ #includeEtc "caseDicts/postProcessing/pressure/pressure.cfg" -calcTotal yes; -calcCoeff no; +mode total; rho rhoInf; // ************************************************************************* // diff --git a/etc/controlDict b/etc/controlDict index 9a7a85017658a694766ce87a51fbf66b9b723567..5be9a1166468ae191aa9e67e01f47c4351a359a2 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -68,8 +68,8 @@ InfoSwitches allowSystemOperations 1; // Allow space character in fileName (use with caution) - // Default: 0 for non-Windows, 1 for Windows - //// allowSpaceInFileName 0; + // Ignored (always 1) for Windows. + allowSpaceInFileName 0; } diff --git a/src/OSspecific/MSwindows/MSwindows.C b/src/OSspecific/MSwindows/MSwindows.C index 9ea78be68090af92e8c3770e83076232087d2f71..105302d478d3a78cfe1dc7df8c498262ce046bc3 100644 --- a/src/OSspecific/MSwindows/MSwindows.C +++ b/src/OSspecific/MSwindows/MSwindows.C @@ -24,6 +24,9 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. +Description + MS-Windows versions of the functions declared in OSspecific.H + \*---------------------------------------------------------------------------*/ #include "OSspecific.H" @@ -77,6 +80,22 @@ namespace Foam static bool const abortHandlerInstalled = installAbortHandler(); + + // Move file, overwriting existing + static bool renameFile(const fileName& src, const fileName& dst) + { + constexpr const int flags + ( + MOVEFILE_COPY_ALLOWED + | MOVEFILE_REPLACE_EXISTING + | MOVEFILE_WRITE_THROUGH + ); + + // TODO: handle extra-long paths with ::MoveFileExW + + return ::MoveFileExA(src.c_str(), dst.c_str(), flags); + } + } // End namespace Foam @@ -928,10 +947,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink) { const fileName dstName(dst/src.name()); - return 0 == std::rename(src.c_str(), dstName.c_str()); + return renameFile(src, dstName); } - return 0 == std::rename(src.c_str(), dst.c_str()); + return renameFile(src, dst); } @@ -945,10 +964,10 @@ bool Foam::mvBak(const fileName& src, const std::string& ext) if (exists(src, false)) { - const int maxIndex = 99; + constexpr const int maxIndex = 99; char index[3]; - for (int n = 0; n <= maxIndex; n++) + for (int n = 0; n <= maxIndex; ++n) { fileName dstName(src + "." + ext); if (n) @@ -961,7 +980,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 (0 == std::rename(src.c_str(), dstName.c_str())); + return renameFile(src, dstName); } } } diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index e7ad0f456579716dcc4c03cf7681b25f1fd42475..f5bfae1a1f5f9ca9faa586d1e8e64a2978e6edcb 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -1213,10 +1213,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink) { const fileName dstName(dst/src.name()); - return (0 == ::rename(src.c_str(), dstName.c_str())); + return (0 == std::rename(src.c_str(), dstName.c_str())); } - return (0 == ::rename(src.c_str(), dst.c_str())); + return (0 == std::rename(src.c_str(), dst.c_str())); } @@ -1241,7 +1241,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext) if (exists(src, false)) { - const int maxIndex = 99; + constexpr const int maxIndex = 99; char index[3]; for (int n = 0; n <= maxIndex; ++n) @@ -1257,7 +1257,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 (0 == ::rename(src.c_str(), dstName.c_str())); + return (0 == std::rename(src.c_str(), dstName.c_str())); } } } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 0027a6367a070faeffc58ce6b24dcfa3e0b0f709..d43f71853b58c3dd5102836d28be092879bc9068 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -42,7 +42,7 @@ int Foam::fileName::debug(Foam::debug::debugSwitch(fileName::typeName, 0)); int Foam::fileName::allowSpaceInFileName ( #ifdef _WIN32 - Foam::debug::infoSwitch("allowSpaceInFileName", 1) + 1 // Windows: expect spaces to occur #else Foam::debug::infoSwitch("allowSpaceInFileName", 0) #endif diff --git a/src/functionObjects/field/pressure/pressure.C b/src/functionObjects/field/pressure/pressure.C index df050772ae727de451f98f9c0e1152131e0bff40..312dda2f41b7531e4fa1ddc63dd878c525d982d4 100644 --- a/src/functionObjects/field/pressure/pressure.C +++ b/src/functionObjects/field/pressure/pressure.C @@ -146,44 +146,38 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::calcPressure const tmp<volScalarField>& tp ) const { - switch (mode_) + if (mode_ & TOTAL) { - case TOTAL: - { - return - tp - + dimensionedScalar("pRef", dimPressure, pRef_) - + rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_))); - } - case ISENTROPIC: - { - const basicThermo* thermoPtr = - p.mesh().lookupObjectPtr<basicThermo>(basicThermo::dictName); - - if (!thermoPtr) - { - FatalErrorInFunction - << "Isentropic pressure calculation requires a " - << "thermodynamics package" - << exit(FatalError); - } - - const volScalarField gamma(thermoPtr->gamma()); - const volScalarField Mb - ( - mag(lookupObject<volVectorField>(UName_)) - /sqrt(gamma*tp.ref()/thermoPtr->rho()) - ); + return + tp + + dimensionedScalar("pRef", dimPressure, pRef_) + + rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_))); + } - return tp()*(pow(1 + (gamma - 1)/2*sqr(Mb), gamma/(gamma - 1))); - } - default: + if (mode_ & ISENTROPIC) + { + const basicThermo* thermoPtr = + p.mesh().lookupObjectPtr<basicThermo>(basicThermo::dictName); + + if (!thermoPtr) { - return - tp - + dimensionedScalar("pRef", dimPressure, pRef_); + FatalErrorInFunction + << "Isentropic pressure calculation requires a " + << "thermodynamics package" + << exit(FatalError); } + + const volScalarField gamma(thermoPtr->gamma()); + const volScalarField Mb + ( + mag(lookupObject<volVectorField>(UName_)) + /sqrt(gamma*tp.ref()/thermoPtr->rho()) + ); + + return tp()*(pow(1 + (gamma - 1)/2*sqr(Mb), gamma/(gamma - 1))); } + + return tp + dimensionedScalar("pRef", dimPressure, pRef_); } @@ -207,10 +201,8 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::coeff return tpCoeff; } - else - { - return std::move(tp); - } + + return std::move(tp); } diff --git a/src/meshTools/regionSplit/regionSplit.C b/src/meshTools/regionSplit/regionSplit.C index be0e34a8d530f1640c4f07131f4a16c601797916..e8adfa180c52a53463391afbe7913b5cb30f32cf 100644 --- a/src/meshTools/regionSplit/regionSplit.C +++ b/src/meshTools/regionSplit/regionSplit.C @@ -534,6 +534,8 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions // Buffer for swapping boundary information labelList nbrRegion(mesh().nBoundaryFaces()); + bool emitWarning = true; + do { if (debug) @@ -599,9 +601,22 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions const label sent = localToGlobal[orig]; const label recv = patchNbrRegion[patchFacei]; - // Record the minimum value seen - if (recv < sent) + if (recv == UNASSIGNED) + { + if (emitWarning) + { + Pout<<"Warning in regionSplit:" + " received unassigned on " + << pp.name() << " at patchFace " + << patchFacei + << ". Check synchronisation in caller" + << nl; + } + } + else if (recv < sent) { + // Record the minimum value seen + auto fnd = updateLookup.find(sent); if (!fnd.found()) { @@ -646,6 +661,7 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions << " local regions" << endl; } + emitWarning = false; // Continue until there are no further changes } while (returnReduce(!updateLookup.empty(), orOp<bool>()));