diff --git a/Allwmake b/Allwmake index 0f69c87181b11004af7fabdbcedaf759fef8c531..de7a288ec875893f761e459094ac0415d1af658f 100755 --- a/Allwmake +++ b/Allwmake @@ -15,6 +15,12 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR" 2>/dev/null || { . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments #------------------------------------------------------------------------------ +echo "========================================" +date "+%Y-%m-%d %H:%M:%S %z" 2>/dev/null || echo "date is unknown" +echo "Starting ${WM_PROJECT_DIR##*/} ${0##*}" +echo " $WM_COMPILER $WM_COMPILER_TYPE compiler" +echo " ${WM_OPTIONS}, with ${WM_MPLIB} ${FOAM_MPI}" +echo # Compile wmake support applications (cd wmake/src && make) diff --git a/applications/test/ListOps/Test-ListOps.C b/applications/test/ListOps/Test-ListOps.C index fbbe90deb963440fa9d75a69665145771b4c535b..e722ced197b38ec8757abf8b0e37977c345ca0af 100644 --- a/applications/test/ListOps/Test-ListOps.C +++ b/applications/test/ListOps/Test-ListOps.C @@ -109,7 +109,31 @@ int main(int argc, char *argv[]) SubList<label> test5SubList(test5, 4, 3); Info<< "List : " << test5 << endl; inplaceReverseList(test5SubList); - Info<< "Reverse Sublist between 3 and 6 : " << test5 << endl; + Info<< "Reverse Sublist between 3 and 6 : " << test5 << nl << endl; + + Info<< nl << "Test lambda predicates:" << nl << endl; + + List<label> test6(identity(11)); + // shift range for general testing + std::for_each(test6.begin(), test6.end(), [](label& x){ x -= 4; }); + + Info<< "Subset of non-zero, even values: " + << subsetList + ( + test6, + [](const label& x){ return x && !(x % 2); } + ) << nl + << endl; + + + test6.append(identity(13)); + + // Randomize the list + std::random_shuffle(test6.begin(), test6.end()); + + Info<< "Randomized: " << flatOutput(test6) << endl; + inplaceUniqueSort(test6); + Info<< "Unique : " << flatOutput(test6) << endl; Info<< "\nEnd\n" << endl; diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index cb6333b3d4dbd07b9396339e81b6251836945d65..208e1c297f615aa3a4632d3c67072a67c5935836 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -69,6 +69,16 @@ int main(int argc, char *argv[]) Info<<"trimRight: " << stringOps::trimRight(test) << endl; Info<<"trim: " << stringOps::trim(test) << endl; + { + fileName test1("libFooBar.so"); + + Info<< nl; + Info<< "trim filename: " << test1 << nl; + + test1.removeStart("lib"); + Info<<"without leading 'lib': " << test1 << nl; + } + Info<< nl; Info<<"camel-case => " << (word("camel") & "case") << nl; for (const auto& s : { " text with \"spaces'", "08/15 value" }) diff --git a/applications/test/wordRe/Test-wordRe.C b/applications/test/wordRe/Test-wordRe.C index e3fae58cc579f48e6614bcad8d5fd67a244c7810..f5dfcda831f617efd6acace0e04d94a324035102 100644 --- a/applications/test/wordRe/Test-wordRe.C +++ b/applications/test/wordRe/Test-wordRe.C @@ -75,8 +75,8 @@ int main(int argc, char *argv[]) wre.info(Info) << " after DETECT" << endl; wre.uncompile(); wre.info(Info) << " uncompiled" << endl; - wre.recompile(); - wre.info(Info) << " recompiled" << endl; + wre.compile(); + wre.info(Info) << " re-compiled" << endl; wre.set("something .* value", wordRe::LITERAL); wre.info(Info) << " set as LITERAL" << endl; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C index 9b69ae120e1234a2170a23ab638d88a1e39f9c26..ccaff192aa74e77970da77659c09278c2e4c584d 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C @@ -288,7 +288,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load() vtkSurfaceWriter().write ( surface_.searchableSurface::time().constant()/"triSurface", - surfaceName_.lessExt().name(), + surfaceName_.nameLessExt(), meshedSurfRef ( surface_.points(), diff --git a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C index ff91e32e15dc054b4d99801677233a97aee31eaa..e21ca9b8577fa19c15f4b4f8dfcfb1273568c553 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C +++ b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C @@ -193,12 +193,9 @@ void writeRays } str.flush(); - DynamicList<string> cmd(3); - cmd.append("objToVTK"); - cmd.append(fName); - cmd.append(fName.lessExt() + ".vtk"); - Pout<< "cmd: objToVTK " << fName.c_str() << endl; + + stringList cmd{"objToVTK", fName, fName.lessExt().ext("vtk")}; Foam::system(cmd); } diff --git a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C index e4d09ce7799a4b8294d444be4b174797875204f2..abc3d321d2b8a9e2662ec2d65a7dbb3571c7e963 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C @@ -1657,9 +1657,9 @@ int main(int argc, char *argv[]) const fileName sFeatFileName ( - fileName(surf1Name).lessExt().name() + fileName(surf1Name).nameLessExt() + "_" - + fileName(surf2Name).lessExt().name() + + fileName(surf2Name).nameLessExt() + "_" + action ); diff --git a/bin/tools/foamConfigurePaths b/bin/tools/foamConfigurePaths index 442eaf83e178b0f2826e3dd7d5cbe02e6e113927..98f7c55c94d0fc9fc12b1e54ef0c9b578aa30027 100755 --- a/bin/tools/foamConfigurePaths +++ b/bin/tools/foamConfigurePaths @@ -4,7 +4,7 @@ # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. +# \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -55,6 +55,7 @@ usage: ${0##*/} -metis-path dir specify 'METIS_ARCH_PATH' -paraview ver specify 'ParaView_VERSION' (eg, 5.0.1) -paraview-path dir specify 'ParaView_DIR' (eg, /opt/paraviewopenfoam3120) + -mpi name specify type for 'WM_MPLIB' (eg, FJMPI, INTELMPI, etc) -openmpi ver specify ThirdParty openmpi version for 'FOAM_MPI' -openmpi-system activate system openmpi -openmpi-third activate ThirdParty openmpi (using default version) @@ -338,6 +339,15 @@ do shift ;; + -mpi) + # Explicitly set WM_MPLIB=... + [ "$#" -ge 2 ] || die "'$1' option requires an argument" + replace etc/bashrc WM_MPLIB "$2" + optMpi=system + adjusted=true + shift + ;; + -openmpi) # Replace FOAM_MPI=openmpi-<digits>.. and set to use third-party # The edit is slightly fragile, but works diff --git a/etc/bashrc b/etc/bashrc index 91da6b9e1b57963608db52410989dabc0884c782..cc8b0a87d32d759568465224c7e9df4dd656e903 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -57,18 +57,19 @@ export FOAM_INST_DIR # $FOAM_INST_DIR/site/$WM_PROJECT_VERSION or $FOAM_INST_DIR/site #- Compiler location: -# WM_COMPILER_TYPE= system | ThirdParty +# WM_COMPILER_TYPE = system | ThirdParty export WM_COMPILER_TYPE=system #- Compiler: -# WM_COMPILER= Gcc | Gcc4[8-9] | Gcc5[1-4] | Gcc6[1-3] | Clang | Icc | IccKNL +# WM_COMPILER = Gcc | Gcc4[8-9] | Gcc5[1-4] | Gcc6[1-3] | GccKNL +# | Clang | Clang3[8-9] | Icc | IccKNL export WM_COMPILER=Gcc unset WM_COMPILER_ARCH WM_COMPILER_LIB_ARCH #- Memory addressing: -# On a 64bit OS this can be 32bit or 64bit -# On a 32bit OS addressing is 32bit and this option is not used # WM_ARCH_OPTION = 32 | 64 +# - on a 64-bit OS this can be 32 or 64 +# - on a 32-bit OS addressing is 32-bit and this option is not used export WM_ARCH_OPTION=64 #- Precision: diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H index c27641936281c1e34da7dd2989b1412f735230c1..a30727ccb6d4a3cbc170247aa805be7fd43a583b 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H @@ -39,11 +39,11 @@ Description setValue ( fvMatrix<Type}>& eqn, - const label fieldi + const label fieldi ) where : - fld is the field in fieldNames + fieldi is the index in the fields entry eqn is the fvMatrix energySource @@ -55,7 +55,7 @@ Description scalarCodedSourceCoeffs { - fieldNames (h); + fields (h); name sourceTime; codeInclude diff --git a/etc/config.csh/compiler b/etc/config.csh/compiler index 18b2f226c89dd40baeecffd6eda0aba346706361..61b560e5a26db68a4f37c759a069c298849b4f34 100644 --- a/etc/config.csh/compiler +++ b/etc/config.csh/compiler @@ -31,6 +31,7 @@ #------------------------------------------------------------------------------ switch ("$WM_COMPILER_TYPE") +case OpenFOAM: case ThirdParty: # Default versions of GMP, MPFR and MPC, override as necessary set gmp_version=gmp-system @@ -67,22 +68,36 @@ case ThirdParty: set gcc_version=gcc-6.3.0 breaksw case Clang: - set clang_version=llvm-3.7.0 - # set clang_version=llvm-3.8.0 + set clang_version=llvm-3.7.1 + breaksw + case Clang38: + set clang_version=llvm-3.8.1 + breaksw + case Clang39: + set clang_version=llvm-3.9.1 + breaksw + case Clang40: + set clang_version=llvm-4.0.0 breaksw default: - echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/compiler:" - echo " Unknown OpenFOAM compiler type '$WM_COMPILER'" - echo " Please check your settings" - echo + /bin/cat << UNKNOWN_COMPILER +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.csh/compiler: +Unknown ThirdParty compiler type/version - '$WM_COMPILER' + +Please check your settings +=============================================================================== +UNKNOWN_COMPILER breaksw endsw + + setenv WM_COMPILER_TYPE ThirdParty # Canonical name + breaksw endsw -# common settings (system or ThirdParty) +# Common settings (system or ThirdParty) switch ("$WM_COMPILER") -case Clang: +case Clang*: # Using clang - not gcc setenv WM_CC 'clang' setenv WM_CXX 'clang++' diff --git a/etc/config.csh/mpi b/etc/config.csh/mpi index dca6ff23f7c2afa34e4629124f218e096423cab1..ac3f3788cd689bcdaba4775de19d8df87e369b68 100644 --- a/etc/config.csh/mpi +++ b/etc/config.csh/mpi @@ -76,7 +76,7 @@ case SYSTEMMPI: if ( ! ($?MPI_ROOT) ) then echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " Please set the environment variable MPI_ROOT to point to" \ " the base folder for the system MPI in use." echo " Example:" @@ -88,7 +88,7 @@ case SYSTEMMPI: if ( ! ($?MPI_ARCH_FLAGS) ) then echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " MPI_ARCH_FLAGS is not set. Example:" echo echo ' setenv MPI_ARCH_FLAGS "-DOMPI_SKIP_MPICXX"' @@ -97,7 +97,7 @@ case SYSTEMMPI: if ( ! ($?MPI_ARCH_INC) ) then echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " MPI_ARCH_INC is not set. Example:" echo echo ' setenv MPI_ARCH_INC "-isystem $MPI_ROOT/include"' @@ -106,7 +106,7 @@ case SYSTEMMPI: if ( ! ($?MPI_ARCH_LIBS) ) then echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " MPI_ARCH_LIBS is not set. Example:" echo echo ' setenv MPI_ARCH_LIBS "-L$MPI_ROOT/lib -lmpi"' @@ -194,7 +194,7 @@ case SGIMPI: if ( ! $?MPI_ROOT) setenv MPI_ROOT /dummy if ( ! -d "$MPI_ROOT" ) then - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " MPI_ROOT not a valid mpt installation directory." echo " Please set MPI_ROOT to the mpt installation directory." echo " (usually done by loading the mpt module)" @@ -208,14 +208,12 @@ case SGIMPI: setenv FOAM_MPI ${MPI_ROOT:t} setenv MPI_ARCH_PATH $MPI_ROOT - if ($?FOAM_VERBOSE && $?prompt) then echo "Using SGI MPT:" echo " MPI_ROOT : $MPI_ROOT" echo " FOAM_MPI : $FOAM_MPI" endif - _foamAddPath $MPI_ARCH_PATH/bin _foamAddLib $MPI_ARCH_PATH/lib breaksw @@ -224,7 +222,7 @@ case INTELMPI: if ( ! $?MPI_ROOT) setenv MPI_ROOT /dummy if ( ! -d "$MPI_ROOT" ) then - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" + echo "Warning in $WM_PROJECT_DIR/etc/config.csh/mpi:" echo " MPI_ROOT not a valid mpt installation directory." echo " Please set MPI_ROOT to the mpt installation directory." echo " (usually done by loading the mpt module)" @@ -238,14 +236,12 @@ case INTELMPI: setenv FOAM_MPI ${MPI_ROOT:t} setenv MPI_ARCH_PATH $MPI_ROOT - if ($?FOAM_VERBOSE && $?prompt) then echo "Using INTEL MPT:" echo " MPI_ROOT : $MPI_ROOT" echo " FOAM_MPI : $FOAM_MPI" endif - _foamAddPath $MPI_ARCH_PATH/bin64 _foamAddLib $MPI_ARCH_PATH/lib64 breaksw diff --git a/etc/config.csh/settings b/etc/config.csh/settings index 3a668acf2d15930f7634ba498aad213c72bd3eea..8e048e2323f4e9f03aa7dab44d89ae836b6461af 100644 --- a/etc/config.csh/settings +++ b/etc/config.csh/settings @@ -54,13 +54,14 @@ case Linux: breaksw case x86_64: + if ( ! $?WM_ARCH_OPTION ) setenv WM_ARCH_OPTION 64 # Default to 64-bit switch ($WM_ARCH_OPTION) case 32: setenv WM_COMPILER_ARCH 64 setenv WM_CC 'gcc' setenv WM_CXX 'g++' setenv WM_CFLAGS '-m32 -fPIC' - setenv WM_CXXFLAGS '-m32 -fPIC -std=c++0x' + setenv WM_CXXFLAGS '-m32 -fPIC -std=c++11' setenv WM_LDFLAGS '-m32' breaksw @@ -70,7 +71,7 @@ case Linux: setenv WM_CC 'gcc' setenv WM_CXX 'g++' setenv WM_CFLAGS '-m64 -fPIC' - setenv WM_CXXFLAGS '-m64 -fPIC -std=c++0x' + setenv WM_CXXFLAGS '-m64 -fPIC -std=c++11' setenv WM_LDFLAGS '-m64' breaksw @@ -92,7 +93,7 @@ case Linux: setenv WM_CC 'gcc' setenv WM_CXX 'g++' setenv WM_CFLAGS '-m64 -fPIC' - setenv WM_CXXFLAGS '-m64 -fPIC -std=c++0x' + setenv WM_CXXFLAGS '-m64 -fPIC -std=c++11' setenv WM_LDFLAGS '-m64' breaksw @@ -102,7 +103,7 @@ case Linux: setenv WM_CC 'gcc' setenv WM_CXX 'g++' setenv WM_CFLAGS '-m64 -fPIC' - setenv WM_CXXFLAGS '-m64 -fPIC -std=c++0x' + setenv WM_CXXFLAGS '-m64 -fPIC -std=c++11' setenv WM_LDFLAGS '-m64' breaksw @@ -120,17 +121,17 @@ case SunOS: setenv WM_CC 'gcc' setenv WM_CXX 'g++' setenv WM_CFLAGS '-mabi=64 -fPIC' - setenv WM_CXXFLAGS '-mabi=64 -fPIC -std=c++0x' + setenv WM_CXXFLAGS '-mabi=64 -fPIC -std=c++11' setenv WM_LDFLAGS '-mabi=64 -G0' breaksw -default: # An unsupported operating system - /bin/cat <<USAGE - -Your "$WM_ARCH" operating system is unsupported by this OpenFOAM release. +default: + /bin/cat << UNSUPPORTED_OS +=============================================================================== +Your '$WM_ARCH' operating system is unsupported by this OpenFOAM release. For further assistance, please contact www.OpenFOAM.com - -USAGE +=============================================================================== +UNSUPPORTED_OS breaksw endsw @@ -219,7 +220,6 @@ case system: # Use system compiler breaksw -case OpenFOAM: case ThirdParty: if ( $?gcc_version ) then if ( ! $?gmp_version ) set gmp_version=gmp-system @@ -301,9 +301,15 @@ CLANG_NOT_FOUND breaksw default: - echo "Warn: WM_COMPILER_TYPE='$WM_COMPILER_TYPE' is unsupported" - echo " treating as 'system' instead" + /bin/cat << UNKNOWN_TYPE +=============================================================================== +Unknown WM_COMPILER_TYPE="$WM_COMPILER_TYPE" - treating as 'system' +Please check your settings +=============================================================================== +UNKNOWN_TYPE + setenv WM_COMPILER_TYPE system breaksw + endsw diff --git a/etc/config.sh/compiler b/etc/config.sh/compiler index 1f9907710b31a7925b89dbf650790ccf0049064a..78f8c42b1bd8cde341a0b72fb6a4992de85ce4d3 100644 --- a/etc/config.sh/compiler +++ b/etc/config.sh/compiler @@ -31,7 +31,7 @@ #------------------------------------------------------------------------------ case "$WM_COMPILER_TYPE" in -ThirdParty) +OpenFOAM | ThirdParty) # Default versions of GMP, MPFR and MPC, override as necessary gmp_version=gmp-system mpfr_version=mpfr-system @@ -66,23 +66,35 @@ ThirdParty) gcc_version=gcc-6.3.0 ;; Clang) - clang_version=llvm-3.7.0 - # clang_version=llvm-3.8.0 + clang_version=llvm-3.7.1 + ;; + Clang38) + clang_version=llvm-3.8.1 + ;; + Clang39) + clang_version=llvm-3.9.1 + ;; + Clang40) + clang_version=llvm-4.0.0 ;; *) - echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/compiler:" 1>&2 - echo " Unknown OpenFOAM compiler type '$WM_COMPILER'" 1>&2 - echo " Please check your settings" 1>&2 - echo 1>&2 + /bin/cat << UNKNOWN_COMPILER 1>&2 +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.sh/compiler: +Unknown ThirdParty compiler type/version - '$WM_COMPILER' + +Please check your settings +=============================================================================== +UNKNOWN_COMPILER ;; esac + WM_COMPILER_TYPE=ThirdParty # Canonical name ;; esac -# common settings (system or ThirdParty) +# Common settings (system or ThirdParty) case "$WM_COMPILER" in -Clang) +Clang*) # Using clang - not gcc export WM_CC='clang' export WM_CXX='clang++' diff --git a/etc/config.sh/mpi b/etc/config.sh/mpi index d26e5eefb02abefe56570f7fcbe841592dc36862..dd64a8649b0d4a6e4141d7c9866ee10a2eb8c238 100644 --- a/etc/config.sh/mpi +++ b/etc/config.sh/mpi @@ -81,7 +81,7 @@ SYSTEMMPI) if [ -z "$MPI_ROOT" ] then echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " Please set the environment variable MPI_ROOT to point to" \ " the base folder for the system MPI in use." 1>&2 echo " Example:" 1>&2 @@ -94,7 +94,7 @@ SYSTEMMPI) if [ -z "$MPI_ARCH_FLAGS" ] then echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " MPI_ARCH_FLAGS is not set. Example:" 1>&2 echo 1>&2 echo " export MPI_ARCH_FLAGS=\"-DOMPI_SKIP_MPICXX\"" 1>&2 @@ -104,7 +104,7 @@ SYSTEMMPI) if [ -z "$MPI_ARCH_INC" ] then echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " MPI_ARCH_INC is not set. Example:" 1>&2 echo 1>&2 echo " export MPI_ARCH_INC=\"-isystem \$MPI_ROOT/include\"" 1>&2 @@ -114,7 +114,7 @@ SYSTEMMPI) if [ -z "$MPI_ARCH_LIBS" ] then echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " MPI_ARCH_LIBS is not set. Example:" 1>&2 echo 1>&2 echo " export MPI_ARCH_LIBS=\"-L\$MPI_ROOT/lib -lmpi\"" 1>&2 @@ -208,7 +208,7 @@ SGIMPI) if [ ! -d "$MPI_ROOT" -o -z "$MPI_ARCH_PATH" ] then - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " MPI_ROOT not a valid mpt installation directory or ending" \ " in a '/'." 1>&2 echo " Please set MPI_ROOT to the mpt installation directory." 1>&2 @@ -235,7 +235,7 @@ INTELMPI) if [ ! -d "$MPI_ROOT" -o -z "$MPI_ARCH_PATH" ] then - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 + echo "Warning in $WM_PROJECT_DIR/etc/config.sh/mpi:" 1>&2 echo " MPI_ROOT not a valid mpt installation directory or ending" \ " in a '/'." 1>&2 echo " Please set MPI_ROOT to the mpt installation directory." 1>&2 diff --git a/etc/config.sh/settings b/etc/config.sh/settings index d342ed47e43d490db631436436273d90ae475480..259d61ace9f14e0f2364cea4de83af658ca655f3 100644 --- a/etc/config.sh/settings +++ b/etc/config.sh/settings @@ -44,18 +44,19 @@ Linux) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-fPIC' - export WM_CXXFLAGS='-fPIC -std=c++0x' + export WM_CXXFLAGS='-fPIC -std=c++11' export WM_LDFLAGS= ;; x86_64) + : ${WM_ARCH_OPTION:=64}; export WM_ARCH_OPTION # Default to 64-bit case "$WM_ARCH_OPTION" in 32) export WM_COMPILER_ARCH=64 export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-m32 -fPIC' - export WM_CXXFLAGS='-m32 -fPIC -std=c++0x' + export WM_CXXFLAGS='-m32 -fPIC -std=c++11' export WM_LDFLAGS='-m32' ;; 64) @@ -64,7 +65,7 @@ Linux) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-m64 -fPIC' - export WM_CXXFLAGS='-m64 -fPIC -std=c++0x' + export WM_CXXFLAGS='-m64 -fPIC -std=c++11' export WM_LDFLAGS='-m64' ;; *) @@ -85,7 +86,7 @@ Linux) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-fPIC' - export WM_CXXFLAGS='-fPIC -std=c++0x' + export WM_CXXFLAGS='-fPIC -std=c++11' export WM_LDFLAGS= ;; @@ -95,7 +96,7 @@ Linux) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-m64 -fPIC' - export WM_CXXFLAGS='-m64 -fPIC -std=c++0x' + export WM_CXXFLAGS='-m64 -fPIC -std=c++11' export WM_LDFLAGS='-m64' ;; @@ -105,7 +106,7 @@ Linux) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-m64 -fPIC' - export WM_CXXFLAGS='-m64 -fPIC -std=c++0x' + export WM_CXXFLAGS='-m64 -fPIC -std=c++11' export WM_LDFLAGS='-m64' ;; @@ -122,17 +123,17 @@ SunOS) export WM_CC='gcc' export WM_CXX='g++' export WM_CFLAGS='-mabi=64 -fPIC' - export WM_CXXFLAGS='-mabi=64 -fPIC -std=c++0x' + export WM_CXXFLAGS='-mabi=64 -fPIC -std=c++11' export WM_LDFLAGS='-mabi=64 -G0' ;; *) # An unsupported operating system - /bin/cat <<USAGE 1>&2 - -Your "$WM_ARCH" operating system is unsupported by this OpenFOAM release. + /bin/cat << UNSUPPORTED_OS 1>&2 +=============================================================================== +Your '$WM_ARCH' operating system is unsupported by this OpenFOAM release. For further assistance, please contact www.OpenFOAM.com - -USAGE +=============================================================================== +UNSUPPORTED_OS ;; esac @@ -217,7 +218,8 @@ case "$WM_COMPILER_TYPE" in system) # Use system compiler ;; -OpenFOAM | ThirdParty) + +ThirdParty) if [ -n "$gcc_version" ] then gccDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$gcc_version @@ -297,9 +299,15 @@ CLANG_NOT_FOUND unset clang_version clangDir ;; *) - echo "Warn: WM_COMPILER_TYPE='$WM_COMPILER_TYPE' is unsupported" 1>&2 - echo " treating as 'system' instead" 1>&2 + /bin/cat << UNKNOWN_TYPE 1>&2 +=============================================================================== +Unknown WM_COMPILER_TYPE="$WM_COMPILER_TYPE" - treating as 'system' +Please check your settings +=============================================================================== +UNKNOWN_TYPE + export WM_COMPILER_TYPE=system ;; + esac #------------------------------------------------------------------------------ diff --git a/etc/cshrc b/etc/cshrc index e8319d258cf5147f164d66d5ecf5c38841368e58..10165e0964e5f9491231cb8a34949b13018722e2 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -60,15 +60,16 @@ setenv FOAM_INST_DIR `lsof +p $$ |& grep -oE '/.*'$WM_PROJECT'[^/]*/etc/cshrc' | setenv WM_COMPILER_TYPE system #- Compiler: -# WM_COMPILER= Gcc | Gcc4[8-9] | Gcc5[1-4] | Gcc6[1-3] | Clang | Icc | IccKNL +# WM_COMPILER = Gcc | Gcc4[8-9] | Gcc5[1-4] | Gcc6[1-3] | GccKNL +# | Clang | Clang3[8-9] | Icc | IccKNL setenv WM_COMPILER Gcc setenv WM_COMPILER_ARCH # defined but empty unsetenv WM_COMPILER_LIB_ARCH #- Memory addressing: -# On a 64bit OS this can be 32bit or 64bit -# On a 32bit OS addressing is 32bit and this option is not used # WM_ARCH_OPTION = 32 | 64 +# - on a 64-bit OS this can be 32 or 64 +# - on a 32-bit OS addressing is 32-bit and this option is not used setenv WM_ARCH_OPTION 64 #- Precision: diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 790170941b9dd8029156ba8e47b1908338e7d471..3c8a2b255393f0ee09709771026639a94af9c16e 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -96,13 +96,13 @@ pid_t Foam::pgid() } -bool Foam::env(const word& envName) +bool Foam::env(const std::string& envName) { return ::getenv(envName.c_str()) != nullptr; } -Foam::string Foam::getEnv(const word& envName) +Foam::string Foam::getEnv(const std::string& envName) { char* env = ::getenv(envName.c_str()); @@ -126,7 +126,7 @@ bool Foam::setEnv const bool overwrite ) { - return setenv(envName.c_str(), value.c_str(), overwrite) == 0; + return ::setenv(envName.c_str(), value.c_str(), overwrite) == 0; } @@ -215,7 +215,7 @@ Foam::fileName Foam::home() } -Foam::fileName Foam::home(const string& userName) +Foam::fileName Foam::home(const std::string& userName) { struct passwd* pw; @@ -252,13 +252,13 @@ Foam::fileName Foam::cwd() List<char> path(pathLengthLimit); // Resize path if getcwd fails with an ERANGE error - while(pathLengthLimit == path.size()) + while (pathLengthLimit == path.size()) { if (::getcwd(path.data(), path.size())) { return path.data(); } - else if(errno == ERANGE) + else if (errno == ERANGE) { // Increment path length upto the pathLengthMax limit if @@ -888,7 +888,7 @@ bool Foam::rm(const fileName& file) } // Try returning plain file name; if not there, try with .gz - if (remove(file.c_str()) == 0) + if (::remove(file.c_str()) == 0) { return true; } @@ -998,7 +998,7 @@ void Foam::fdClose(const int fd) bool Foam::ping ( - const string& destName, + const std::string& destName, const label destPort, const label timeOut ) @@ -1074,9 +1074,9 @@ bool Foam::ping } -bool Foam::ping(const string& hostname, const label timeOut) +bool Foam::ping(const std::string& host, const label timeOut) { - return ping(hostname, 222, timeOut) || ping(hostname, 22, timeOut); + return ping(host, 222, timeOut) || ping(host, 22, timeOut); } diff --git a/src/OSspecific/POSIX/regExp.C b/src/OSspecific/POSIX/regExp.C index 0d7b6e80ed2903a088d826d84c21fd8efc5bf2d1..15d0ea2ba205595ac91aa308cbe5a885311370cb 100644 --- a/src/OSspecific/POSIX/regExp.C +++ b/src/OSspecific/POSIX/regExp.C @@ -32,11 +32,11 @@ License template<class StringType> bool Foam::regExp::matchGrouping ( - const std::string& str, + const std::string& text, List<StringType>& groups ) const { - if (preg_ && str.size()) + if (preg_ && !text.empty()) { size_t nmatch = ngroups() + 1; regmatch_t pmatch[nmatch]; @@ -46,8 +46,8 @@ bool Foam::regExp::matchGrouping // pmatch[1..] are the (...) sub-groups if ( - regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0 - && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(str.size())) + regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0 + && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(text.size())) ) { groups.setSize(ngroups()); @@ -57,7 +57,7 @@ bool Foam::regExp::matchGrouping { if (pmatch[matchI].rm_so != -1 && pmatch[matchI].rm_eo != -1) { - groups[groupI] = str.substr + groups[groupI] = text.substr ( pmatch[matchI].rm_so, pmatch[matchI].rm_eo - pmatch[matchI].rm_so @@ -83,21 +83,21 @@ bool Foam::regExp::matchGrouping Foam::regExp::regExp() : - preg_(0) + preg_(nullptr) {} -Foam::regExp::regExp(const char* pattern, const bool ignoreCase) +Foam::regExp::regExp(const char* pattern, bool ignoreCase) : - preg_(0) + preg_(nullptr) { set(pattern, ignoreCase); } -Foam::regExp::regExp(const std::string& pattern, const bool ignoreCase) +Foam::regExp::regExp(const std::string& pattern, bool ignoreCase) : - preg_(0) + preg_(nullptr) { set(pattern.c_str(), ignoreCase); } @@ -113,7 +113,7 @@ Foam::regExp::~regExp() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -void Foam::regExp::set(const char* pattern, const bool ignoreCase) const +void Foam::regExp::set(const char* pattern, bool ignoreCase) { clear(); @@ -160,19 +160,19 @@ void Foam::regExp::set(const char* pattern, const bool ignoreCase) const } -void Foam::regExp::set(const std::string& pattern, const bool ignoreCase) const +void Foam::regExp::set(const std::string& pattern, bool ignoreCase) { return set(pattern.c_str(), ignoreCase); } -bool Foam::regExp::clear() const +bool Foam::regExp::clear() { if (preg_) { regfree(preg_); delete preg_; - preg_ = 0; + preg_ = nullptr; return true; } @@ -181,14 +181,14 @@ bool Foam::regExp::clear() const } -std::string::size_type Foam::regExp::find(const std::string& str) const +std::string::size_type Foam::regExp::find(const std::string& text) const { - if (preg_ && str.size()) + if (preg_ && !text.empty()) { size_t nmatch = 1; regmatch_t pmatch[1]; - if (regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0) + if (regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0) { return pmatch[0].rm_so; } @@ -198,9 +198,9 @@ std::string::size_type Foam::regExp::find(const std::string& str) const } -bool Foam::regExp::match(const std::string& str) const +bool Foam::regExp::match(const std::string& text) const { - if (preg_ && str.size()) + if (preg_ && !text.empty()) { size_t nmatch = 1; regmatch_t pmatch[1]; @@ -209,8 +209,8 @@ bool Foam::regExp::match(const std::string& str) const // pmatch[0] is the entire match if ( - regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0 - && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(str.size())) + regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0 + && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(text.size())) ) { return true; @@ -223,35 +223,35 @@ bool Foam::regExp::match(const std::string& str) const bool Foam::regExp::match ( - const std::string& str, + const std::string& text, List<std::string>& groups ) const { - return matchGrouping(str, groups); + return matchGrouping(text, groups); } bool Foam::regExp::match ( - const std::string& str, + const std::string& text, List<Foam::string>& groups ) const { - return matchGrouping(str, groups); + return matchGrouping(text, groups); } // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // -void Foam::regExp::operator=(const char* pat) +void Foam::regExp::operator=(const char* pattern) { - set(pat); + set(pattern); } -void Foam::regExp::operator=(const std::string& pat) +void Foam::regExp::operator=(const std::string& pattern) { - set(pat); + set(pattern); } diff --git a/src/OSspecific/POSIX/regExp.H b/src/OSspecific/POSIX/regExp.H index ae91c5df8b34c89522346d7d0b4bab678d2fc4cf..03ce52b39ec6ca7eacf66e4ebcdd94eed4a20c00 100644 --- a/src/OSspecific/POSIX/regExp.H +++ b/src/OSspecific/POSIX/regExp.H @@ -64,16 +64,16 @@ class regExp // Private data //- Precompiled regular expression - mutable regex_t* preg_; + regex_t* preg_; // Private Member Functions //- Disallow default bitwise copy construct - regExp(const regExp&); + regExp(const regExp&) = delete; //- Disallow default bitwise assignment - void operator=(const regExp&); + void operator=(const regExp&) = delete; //- Return true if it matches and sets the sub-groups matched. // Templated to support both std::string and Foam::string @@ -96,7 +96,7 @@ public: // range: '[', ']' \n // // Don't bother checking for '{digit}' bounds - inline static bool meta(char c) + inline static bool meta(const char c) { return ( @@ -113,11 +113,11 @@ public: //- Construct null regExp(); - //- Construct from character array, optionally ignoring case - regExp(const char*, const bool ignoreCase=false); + //- Construct from character array, optionally ignore case + regExp(const char* pattern, bool ignoreCase=false); - //- Construct from std::string (or string), optionally ignoring case - regExp(const std::string&, const bool ignoreCase=false); + //- Construct from string, optionally ignore case + regExp(const std::string& pattern, bool ignoreCase=false); //- Destructor @@ -126,76 +126,73 @@ public: // Member functions - // Access + // Access - //- Return true if a precompiled expression does not exist - inline bool empty() const - { - return !preg_; - } + //- Return true if a precompiled expression does not exist + inline bool empty() const + { + return !preg_; + } - //- Does a precompiled expression exist? - inline bool exists() const - { - return preg_ ? true : false; - } + //- Does a precompiled expression exist? + inline bool exists() const + { + return preg_ ? true : false; + } - //- Return the number of (groups) - inline int ngroups() const - { - return preg_ ? preg_->re_nsub : 0; - } + //- The number of capture groups for a non-empty expression + inline unsigned ngroups() const + { + return preg_ ? preg_->re_nsub : 0; + } - // Editing + // Editing - //- Compile pattern into a regular expression, - // optionally ignoring case - void set(const char*, const bool ignoreCase=false) const; + //- Compile pattern into a regular expression, optionally ignore case + void set(const char* pattern, bool ignoreCase=false); - //- Compile pattern into a regular expression, - // optionally ignoring case - void set(const std::string&, const bool ignoreCase=false) const; + //- Compile pattern into a regular expression, optionally ignore case + void set(const std::string& pattern, bool ignoreCase=false); - //- Release precompiled expression. - // Returns true if precompiled expression existed before clear - bool clear() const; + //- Clear expression, return true if expression had existed. + bool clear(); - // Searching + // Matching/Searching - //- Find position within string. - // Returns the index where it begins or string::npos if not found - std::string::size_type find(const std::string& str) const; + //- Find position within string. + // Returns the index where it begins or string::npos if not found + std::string::size_type find(const std::string& text) const; - //- Return true if it matches the entire string - // The begin-of-line (^) and end-of-line ($) anchors are implicit - bool match(const std::string&) const; + //- Return true if it matches the entire string + // The begin-of-line (^) and end-of-line ($) anchors are implicit + bool match(const std::string& text) const; - //- Return true if it matches and sets the sub-groups matched - // The begin-of-line (^) and end-of-line ($) anchors are implicit - bool match(const std::string&, List<std::string>& groups) const; + //- Return true if it matches and sets the sub-groups matched + // The begin-of-line (^) and end-of-line ($) anchors are implicit + bool match(const std::string& text, List<std::string>& groups) const; - //- Return true if it matches and sets the sub-groups matched - // The begin-of-line (^) and end-of-line ($) anchors are implicit - bool match(const std::string&, List<string>& groups) const; + //- Return true if it matches and sets the sub-groups matched + // The begin-of-line (^) and end-of-line ($) anchors are implicit + bool match(const std::string& text, List<string>& groups) const; - //- Return true if the regex was found within string - bool search(const std::string& str) const - { - return std::string::npos != find(str); - } + //- Return true if the regex was found within string + bool search(const std::string& text) const + { + return std::string::npos != find(text); + } // Member Operators //- Assign and compile pattern from a character array // Always case sensitive - void operator=(const char*); + void operator=(const char* pattern); //- Assign and compile pattern from string // Always case sensitive - void operator=(const std::string&); + void operator=(const std::string& pattern); }; diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.C b/src/OpenFOAM/containers/Lists/ListOps/ListOps.C index 78c9cbbf3ee0b4db10d01d6e5ba7bff3ade35e62..762b7fe8d6b598163f135b28861c3d09a64d3159 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.C @@ -28,7 +28,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::labelList Foam::emptyLabelList = Foam::labelList(0); +const Foam::labelList Foam::emptyLabelList; // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // @@ -43,7 +43,7 @@ Foam::labelList Foam::invert forAll(map, i) { - label newPos = map[i]; + const label newPos = map[i]; if (newPos >= 0) { @@ -89,7 +89,7 @@ Foam::labelListList Foam::invertOneToMany forAll(map, i) { - label newI = map[i]; + const label newI = map[i]; if (newI >= 0) { @@ -105,10 +105,11 @@ Foam::labelList Foam::identity(const label len) { labelList map(len); - forAll(map, i) + for (label i = 0; i < len; ++i) { map[i] = i; } + return map; } diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index faacc501b40be174968eaeef411c5f5ee38a04e0..441c7854086da239ab2783efff10b2b78a64e62e 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -55,26 +55,27 @@ static const List<Type>& emptyList() return *reinterpret_cast<const List<Type>*>(&emptyLabelList); } + //- Renumber the values (not the indices) of a list. // Negative ListType elements are left as is. template<class ListType> -ListType renumber(const labelUList& oldToNew, const ListType&); +ListType renumber(const labelUList& oldToNew, const ListType& lst); //- Inplace renumber the values of a list. // Negative ListType elements are left as is. template<class ListType> -void inplaceRenumber(const labelUList& oldToNew, ListType&); +void inplaceRenumber(const labelUList& oldToNew, ListType& lst); //- Reorder the elements (indices, not values) of a list. // Negative ListType elements are left as is. template<class ListType> -ListType reorder(const labelUList& oldToNew, const ListType&); +ListType reorder(const labelUList& oldToNew, const ListType& lst); //- Inplace reorder the elements of a list. // Negative ListType elements are left as is. template<class ListType> -void inplaceReorder(const labelUList& oldToNew, ListType&); +void inplaceReorder(const labelUList& oldToNew, ListType& lst); // Variants to work with iterators and sparse tables. @@ -82,65 +83,92 @@ void inplaceReorder(const labelUList& oldToNew, ListType&); //- Map values. Do not map negative values. template<class Container> -void inplaceMapValue(const labelUList& oldToNew, Container&); +void inplaceMapValue(const labelUList& oldToNew, Container& lst); //- Recreate with mapped keys. Do not map elements with negative key. template<class Container> -void inplaceMapKey(const labelUList& oldToNew, Container&); +void inplaceMapKey(const labelUList& oldToNew, Container& lst); //- Generate the (stable) sort order for the list template<class T> -void sortedOrder(const UList<T>&, labelList& order); +void sortedOrder(const UList<T>& lst, labelList& order); template<class T, class Cmp> -void sortedOrder(const UList<T>&, labelList& order, const Cmp& cmp); +void sortedOrder(const UList<T>& lst, labelList& order, const Cmp& cmp); + //- Generate (sorted) indices corresponding to duplicate list values template<class T> -void duplicateOrder(const UList<T>&, labelList& order); +void duplicateOrder(const UList<T>& lst, labelList& order); template<class T, class Cmp> -void duplicateOrder(const UList<T>&, labelList& order, const Cmp& cmp); +void duplicateOrder(const UList<T>& lst, labelList& order, const Cmp& cmp); + //- Generate (sorted) indices corresponding to unique list values template<class T> -void uniqueOrder(const UList<T>&, labelList& order); +void uniqueOrder(const UList<T>& lst, labelList& order); template<class T, class Cmp> -void uniqueOrder(const UList<T>&, labelList& order, const Cmp& cmp); +void uniqueOrder(const UList<T>& lst, labelList& order, const Cmp& cmp); + + +//- Inplace sorting and removal of duplicates. +// Do not use FixedList for the input list, since it doesn't resize. +template<class ListType> +void inplaceUniqueSort(ListType& lst); + +//- Inplace sorting and removal of duplicates. +// Do not use FixedList for the input list, since it doesn't resize. +template<class ListType, class Cmp> +void inplaceUniqueSort(ListType& lst, const Cmp& cmp); + //- Extract elements of List when select is a certain value. -// eg, to extract all selected elements: -// subset<bool, labelList>(selectedElems, true, lst); +// \deprecated use subsetList instead (deprecated Mar 2017) template<class T, class ListType> ListType subset(const UList<T>& select, const T& value, const ListType&); //- Inplace extract elements of List when select is a certain value. -// eg, to extract all selected elements: -// inplaceSubset<bool, labelList>(selectedElems, true, lst); +// \deprecated use inplaceSubsetList instead (deprecated Mar 2017) template<class T, class ListType> void inplaceSubset(const UList<T>& select, const T& value, ListType&); + //- Extract elements of List when select is true // eg, to extract all selected elements: // subset<boolList, labelList>(selectedElems, lst); -// Note a labelHashSet could also be used for the bool-list +// Note a labelHashSet can also be used as the bool-list. +// Do not use FixedList for the input list, since it doesn't resize. template<class BoolListType, class ListType> -ListType subset(const BoolListType& select, const ListType&); +ListType subset(const BoolListType& select, const ListType& lst); //- Inplace extract elements of List when select is true // eg, to extract all selected elements: // inplaceSubset<boolList, labelList>(selectedElems, lst); -// Note a labelHashSet could also be used for the bool-list +// Note a labelHashSet can also be used as the bool-list. +// Do not use FixedList for the input list, since it doesn't resize. template<class BoolListType, class ListType> -void inplaceSubset(const BoolListType& select, ListType&); +void inplaceSubset(const BoolListType& select, ListType& lst); + + +//- Copy a subset of the input list when predicate is true. +// Do not use FixedList for the input list, since it doesn't resize. +template<class ListType, class UnaryPredicate> +ListType subsetList(const ListType& input, UnaryPredicate pred); + +//- Inplace subset of the list when predicate is true. +// Do not use FixedList for the input list, since it doesn't resize. +template<class ListType, class UnaryPredicate> +void inplaceSubsetList(ListType& input, UnaryPredicate pred); + //- Invert one-to-one map. Unmapped elements will be -1. -labelList invert(const label len, const labelUList&); +labelList invert(const label len, const labelUList& map); //- Invert one-to-many map. Unmapped elements will be size 0. -labelListList invertOneToMany(const label len, const labelUList&); +labelListList invertOneToMany(const label len, const labelUList& map); //- Invert many-to-many. // Input and output types need to be inherited from List. @@ -156,7 +184,7 @@ List<OutList> invertManyToMany(const label len, const UList<InList>& in) return out; } -//- Create identity map (map[i] == i) of given length +//- Create identity map of the given length with (map[i] == i) labelList identity(const label len); //- Find first occurence of given element and return index, @@ -173,8 +201,8 @@ label findIndex template<class ListType> labelList findIndices ( - const ListType&, - typename ListType::const_reference, + const ListType& l, + typename ListType::const_reference t, const label start=0 ); @@ -182,9 +210,9 @@ labelList findIndices template<class ListType> void setValues ( - ListType&, + ListType& l, const labelUList& indices, - typename ListType::const_reference + typename ListType::const_reference t ); //- Opposite of findIndices: set values at indices to given value @@ -200,13 +228,13 @@ ListType createWithValues //- Find index of max element (and larger than given element). // return -1 if not found. Linear search. template<class ListType> -label findMax(const ListType&, const label start=0); +label findMax(const ListType& l, const label start=0); //- Find index of min element (and less than given element). // return -1 if not found. Linear search. template<class ListType> -label findMin(const ListType&, const label start=0); +label findMin(const ListType& l, const label start=0); //- Find first occurrence of given element in sorted list and return index, @@ -214,8 +242,8 @@ label findMin(const ListType&, const label start=0); template<class ListType> label findSortedIndex ( - const ListType&, - typename ListType::const_reference, + const ListType& l, + typename ListType::const_reference t, const label start=0 ); @@ -225,8 +253,8 @@ label findSortedIndex template<class ListType, class BinaryOp> label findLower ( - const ListType&, - typename ListType::const_reference, + const ListType& l, + typename ListType::const_reference t, const label start, const BinaryOp& bop ); @@ -237,20 +265,24 @@ label findLower template<class ListType> label findLower ( - const ListType&, - typename ListType::const_reference, + const ListType& l, + typename ListType::const_reference t, const label start=0 ); //- To construct a List from a C array. Has extra Container type // to initialise e.g. wordList from arrays of char*. +// +// \deprecated can often use initializer_list instead (deprecated Mar 2017) template<class Container, class T, int mRows> List<Container> initList(const T[mRows]); //- To construct a (square) ListList from a C array. Has extra Container type // to initialise e.g. faceList from arrays of labels. +// +// \deprecated can often use initializer_list instead (deprecated Mar 2017) template<class Container, class T, int mRows, int nColumns> List<Container> initListList(const T[mRows][nColumns]); diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index c0e055a271d8494e08ec01a6ae2d36c663d5689d..9267221e99cbae5345f015f56c5feb8c18f368b8 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,11 +34,8 @@ ListType Foam::renumber const ListType& lst ) { - // Create copy ListType newLst(lst.size()); - - // ensure consistent addressable size (eg, DynamicList) - newLst.setSize(lst.size()); + newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList) forAll(lst, elemI) { @@ -76,11 +73,8 @@ ListType Foam::reorder const ListType& lst ) { - // Create copy ListType newLst(lst.size()); - - // ensure consistent addressable size (eg, DynamicList) - newLst.setSize(lst.size()); + newLst.setSize(lst.size()); // Consistent sizes (eg, DynamicList) forAll(lst, elemI) { @@ -104,11 +98,8 @@ void Foam::inplaceReorder ListType& lst ) { - // Create copy ListType newLst(lst.size()); - - // ensure consistent addressable size (eg, DynamicList) - newLst.setSize(lst.size()); + newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList) forAll(lst, elemI) { @@ -236,8 +227,9 @@ void Foam::duplicateOrder sortedOrder(lst, order, cmp); + const label last = (order.size()-1); label n = 0; - for (label i = 0; i < order.size() - 1; ++i) + for (label i = 0; i < last; ++i) { if (lst[order[i]] == lst[order[i+1]]) { @@ -271,20 +263,50 @@ void Foam::uniqueOrder if (order.size() > 1) { + const label last = (order.size()-1); label n = 0; - for (label i = 0; i < order.size() - 1; ++i) + for (label i = 0; i < last; ++i) { if (lst[order[i]] != lst[order[i+1]]) { order[n++] = order[i]; } } - order[n++] = order[order.size()-1]; + order[n++] = order[last]; order.setSize(n); } } +template<class ListType> +void Foam::inplaceUniqueSort(ListType& lst) +{ + inplaceUniqueSort + ( + lst, + typename UList<typename ListType::value_type>::less(lst) + ); +} + + +template<class ListType, class Cmp> +void Foam::inplaceUniqueSort(ListType& lst, const Cmp& cmp) +{ + labelList order; + uniqueOrder(lst, order, cmp); + + ListType newLst(order.size()); + newLst.setSize(order.size()); // Consistent sizing (eg, DynamicList) + + forAll(order, elemI) + { + newLst[elemI] = lst[order[elemI]]; + } + + lst.transfer(newLst); +} + + template<class T, class ListType> ListType Foam::subset ( @@ -303,9 +325,7 @@ ListType Foam::subset } ListType newLst(lst.size()); - - // ensure consistent addressable size (eg, DynamicList) - newLst.setSize(lst.size()); + newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList) label nElem = 0; forAll(lst, elemI) @@ -366,9 +386,7 @@ ListType Foam::subset // eg, when it is a PackedBoolList or a labelHashSet ListType newLst(lst.size()); - - // ensure consistent addressable size (eg, DynamicList) - newLst.setSize(lst.size()); + newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList) label nElem = 0; forAll(lst, elemI) @@ -411,6 +429,54 @@ void Foam::inplaceSubset } +template<class ListType, class UnaryPredicate> +ListType Foam::subsetList +( + const ListType& lst, + UnaryPredicate pred +) +{ + ListType newLst(lst.size()); + newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList) + + label nElem = 0; + forAll(lst, elemI) + { + if (pred(lst[elemI])) + { + newLst[nElem++] = lst[elemI]; + } + } + newLst.setSize(nElem); + + return newLst; +} + + +template<class ListType, class UnaryPredicate> +void Foam::inplaceSubsetList +( + ListType& lst, + UnaryPredicate pred +) +{ + label nElem = 0; + forAll(lst, elemI) + { + if (pred(lst[elemI])) + { + if (nElem != elemI) + { + lst[nElem] = lst[elemI]; + } + ++nElem; + } + } + + lst.setSize(nElem); +} + + template<class InList, class OutList> void Foam::invertManyToMany ( diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 12e62219c033adf6d38714298bdce98d64089c78..6aabf93eabea0809280c6969484807012cf90118 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -515,7 +515,9 @@ Foam::Time::Time *this, argList::validOptions.found("withFunctionObjects") ? args.optionFound("withFunctionObjects") - : !args.optionFound("noFunctionObjects") + : argList::validOptions.found("noFunctionObjects") + ? !args.optionFound("noFunctionObjects") + : false ) { libs_.open(controlDict_, "libs"); @@ -590,7 +592,6 @@ Foam::Time::Time { libs_.open(controlDict_, "libs"); - // Explicitly set read flags on objectRegistry so anything constructed // from it reads as well (e.g. fvSolution). readOpt() = IOobject::MUST_READ_IF_MODIFIED; diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index 6d969d61f959a9c0f9fe97664c6d18626240c607..836f47500eec2d6214576d21173e78982b065e4b 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -92,13 +92,12 @@ void Foam::dynamicCode::checkSecurity Foam::word Foam::dynamicCode::libraryBaseName(const fileName& libPath) { - word libName(libPath.name(true)); - libName.erase(0, 3); // Remove leading 'lib' from name + word libName(libPath.nameLessExt()); + libName.removeStart("lib"); // Remove leading 'lib' from name return libName; } - // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::dynamicCode::copyAndFilter @@ -494,11 +493,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const bool Foam::dynamicCode::wmakeLibso() const { - DynamicList<string> cmd(4); - cmd.append("wmake"); - cmd.append("-s"); - cmd.append("libso"); - cmd.append(this->codePath()); + stringList cmd{"wmake", "-s", "libso", this->codePath()}; // NOTE: could also resolve wmake command explicitly // cmd[0] = stringOps::expand("$WM_PROJECT_DIR/wmake/wmake"); diff --git a/src/OpenFOAM/fields/Fields/Field/FieldMapper.H b/src/OpenFOAM/fields/Fields/Field/FieldMapper.H index 4714e7a173239470555a6a2da514ac5c32a9049c..c09b3ad56324cc5bd7c978f5b3b39ad3d5053f95 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldMapper.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldMapper.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,13 +32,14 @@ Description #ifndef FieldMapper_H #define FieldMapper_H +#include "mapDistributeBase.H" +#include "nullObject.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -class mapDistributeBase; - /*---------------------------------------------------------------------------*\ Class FieldMapper Declaration \*---------------------------------------------------------------------------*/ @@ -76,7 +77,8 @@ public: FatalErrorInFunction << "attempt to access null distributeMap" << abort(FatalError); - return *static_cast<mapDistributeBase*>(nullptr); + + return NullObjectRef<mapDistributeBase>(); } //- Are there unmapped values? I.e. do all size() elements get diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index b93aabd0a61fcdc50a18b91f373c68faab72954c..11643ce1153b806b5e17e8b0b9b794dbda905e2f 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -489,7 +489,8 @@ Foam::argList::argList argListStr_ += ' '; argListStr_ += args_[argI]; - options_.insert(optionName, args_[argI]); + // Handle duplicates by taking the last -option specified + options_.set(optionName, args_[argI]); } else { @@ -584,8 +585,8 @@ void Foam::argList::parse if (initialise) { - string dateString = clock::date(); - string timeString = clock::clockTime(); + const string dateString = clock::date(); + const string timeString = clock::clockTime(); // Print the banner once only for parallel runs if (Pstream::master() && bannerEnabled) @@ -1248,11 +1249,12 @@ bool Foam::argList::check(bool checkArgs, bool checkOpts) const if (Pstream::master()) { - if (checkArgs && args_.size() - 1 != validArgs.size()) + const label nargs = args_.size()-1; + if (checkArgs && nargs != validArgs.size()) { FatalError << "Wrong number of arguments, expected " << validArgs.size() - << " found " << args_.size() - 1 << endl; + << " found " << nargs << endl; ok = false; } @@ -1260,14 +1262,15 @@ bool Foam::argList::check(bool checkArgs, bool checkOpts) const { forAllConstIter(HashTable<string>, options_, iter) { + const word& optionName = iter.key(); if ( - !validOptions.found(iter.key()) - && !validParOptions.found(iter.key()) + !validOptions.found(optionName) + && !validParOptions.found(optionName) ) { FatalError - << "Invalid option: -" << iter.key() << endl; + << "Invalid option: -" << optionName << endl; ok = false; } } @@ -1295,7 +1298,7 @@ bool Foam::argList::checkRootCase() const return false; } - if (!isDir(path()) && Pstream::master()) + if (Pstream::master() && !isDir(path())) { // Allow slaves on non-existing processor directories, created later FatalError diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 4b47e344258060a68671a6b0f347d503de972b1a..3c76a141931f5b3005596cb1aad2b2e553419d46 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,11 +58,11 @@ pid_t ppid(); pid_t pgid(); //- Return true if environment variable of given name is defined -bool env(const word&); +bool env(const std::string& envName); //- Return environment variable of given name // Return string() if the environment is undefined -string getEnv(const word&); +string getEnv(const std::string& envName); //- Set an environment variable bool setEnv(const word& name, const std::string& value, const bool overwrite); @@ -84,7 +84,7 @@ bool isAdministrator(); fileName home(); //- Return home directory path name for a particular user -fileName home(const string& userName); +fileName home(const std::string& userName); //- Return current working directory path name fileName cwd(); @@ -176,10 +176,10 @@ unsigned int sleep(const unsigned int); void fdClose(const int); //- Check if machine is up by pinging given port -bool ping(const string&, const label port, const label timeOut); +bool ping(const std::string& destName, const label port, const label timeOut); //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh) -bool ping(const string&, const label timeOut=10); +bool ping(const std::string& host, const label timeOut=10); //- Execute the specified command via the shell. // Uses vfork/execl internally. diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 70e925ea010e13c9beed06e77470afcc3c925b0a..258167fc1e0d29464d478221a536f56cf8ce4c3a 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -215,7 +215,7 @@ Foam::fileName Foam::fileName::clean() const Foam::word Foam::fileName::name() const { - size_type i = rfind('/'); + const size_type i = rfind('/'); if (i == npos) { @@ -223,69 +223,44 @@ Foam::word Foam::fileName::name() const } else { - return substr(i+1, npos); + return substr(i+1); } } -Foam::string Foam::fileName::caseName() const +Foam::word Foam::fileName::nameLessExt() const { - string cName = *this; - - const string caseStr(getEnv("FOAM_CASE")); + size_type beg = rfind('/'); - const size_type i = find(caseStr); - - if (i == npos) + if (beg == npos) { - return cName; + beg = 0; } else { - return cName.replace(i, caseStr.size(), string("$FOAM_CASE")); + ++beg; } -} - -Foam::word Foam::fileName::name(const bool noExt) const -{ - if (noExt) + size_type dot = rfind('.'); + if (dot != npos && dot <= beg) { - size_type beg = rfind('/'); - if (beg == npos) - { - beg = 0; - } - else - { - ++beg; - } - - size_type dot = rfind('.'); - if (dot != npos && dot <= beg) - { - dot = npos; - } + dot = npos; + } - if (dot == npos) - { - return substr(beg, npos); - } - else - { - return substr(beg, dot - beg); - } + if (dot == npos) + { + return substr(beg, npos); } else { - return this->name(); + return substr(beg, dot - beg); } } Foam::fileName Foam::fileName::path() const { - size_type i = rfind('/'); + const size_type i = rfind('/'); if (i == npos) { @@ -304,7 +279,7 @@ Foam::fileName Foam::fileName::path() const Foam::fileName Foam::fileName::lessExt() const { - size_type i = find_ext(); + const size_type i = find_ext(); if (i == npos) { @@ -319,7 +294,7 @@ Foam::fileName Foam::fileName::lessExt() const Foam::word Foam::fileName::ext() const { - size_type i = find_ext(); + const size_type i = find_ext(); if (i == npos) { @@ -370,7 +345,7 @@ bool Foam::fileName::hasExt(const word& ending) const bool Foam::fileName::hasExt(const wordRe& ending) const { - size_type i = find_ext(); + const size_type i = find_ext(); if (i == npos) { return false; diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 4195077d819587ccd59d73d475fe4c1b19b905fc..a8f17cf6b0414e989100d2faef12a01c743bd63e 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -161,95 +161,104 @@ public: fileName clean() const; - // Interrogation - - //- Return the file type: FILE, DIRECTORY, UNDEFINED or - // LINK (only if followLink=false) - Type type(const bool followLink = true) const; - - //- Return true if file name is absolute - bool isAbsolute() const; - - //- Convert from relative to absolute - fileName& toAbsolute(); - - - // Decomposition - - //- Return file name (part beyond last /) - // - // Behaviour compared to /usr/bin/basename: - // Input name() basename - // ----- ------ -------- - // "foo" "foo" "foo" - // "/foo" "foo" "foo" - // "foo/bar" "bar" "bar" - // "/foo/bar" "bar" "bar" - // "/foo/bar/" "" "bar" - // - word name() const; - - //- Return file name (part beyond last /), subsitute for FOAM_CASE - string caseName() const; - - //- Return file name, optionally without extension - word name(const bool noExt) const; - - //- Return directory path name (part before last /) - // - // Behaviour compared to /usr/bin/dirname: - // input path() dirname - // ----- ------ ------- - // "foo" "." "." - // "/foo" "/" "foo" - // "foo/bar" "foo" "foo" - // "/foo/bar" "/foo" "/foo" - // "/foo/bar/" "/foo/bar/" "/foo" - // - fileName path() const; - - //- Return file name without extension (part before last .) - fileName lessExt() const; - - //- Return file name extension (part after last .) - word ext() const; - - //- Append a '.' and the ending, and return the object. - // The '.' and ending will not be added when the ending is empty, - // or when the file name is empty or ended with a '/'. - fileName& ext(const word& ending); - - //- Return true if it has an extension or simply ends with a '.' - bool hasExt() const; - - //- Return true if the extension is the same as the given ending. - bool hasExt(const word& ending) const; - - //- Return true if the extension matches the given ending. - bool hasExt(const wordRe& ending) const; - - //- Remove extension, returning true if string changed. - bool removeExt(); - - - //- Return path components as wordList - // - // Behaviour: - // Input components() - // ----- ------ - // "foo" 1("foo") - // "/foo" 1("foo") - // "foo/bar" 2("foo", "bar") - // "/foo/bar" 2("foo", "bar") - // "/foo/bar/" 2("foo", "bar") - wordList components(const char delimiter = '/') const; - - //- Return a single component of the path - word component - ( - const size_type cmpt, - const char delimiter = '/' - ) const; + // Interrogation + + //- Return the file type: FILE, DIRECTORY, UNDEFINED or + // LINK (only if followLink=false) + Type type(const bool followLink = true) const; + + //- Return true if file name is absolute + bool isAbsolute() const; + + //- Convert from relative to absolute + fileName& toAbsolute(); + + + // Decomposition + + //- Return basename (part beyond last /), including its extension + // + // Behaviour compared to /usr/bin/basename: + // \verbatim + // input name() basename + // ----- ------ -------- + // "foo" "foo" "foo" + // "/foo" "foo" "foo" + // "foo/bar" "bar" "bar" + // "/foo/bar" "bar" "bar" + // "/foo/bar/" "" "bar" + // \endverbatim + word name() const; + + //- Return basename, without extension + word nameLessExt() const; + + //- Return basename, optionally without extension + // \deprecated in favour of name() or nameLessExt() which more + // explicitly describe their behaviour (MAR-2017). + word name(const bool noExt) const + { + return noExt ? this->nameLessExt() : this->name(); + } + + //- Return directory path name (part before last /) + // + // Behaviour compared to /usr/bin/dirname: + // \verbatim + // input path() dirname + // ----- ------ ------- + // "foo" "." "." + // "/foo" "/" "foo" + // "foo/bar" "foo" "foo" + // "/foo/bar" "/foo" "/foo" + // "/foo/bar/" "/foo/bar/" "/foo" + // \endverbatim + fileName path() const; + + //- Return file name without extension (part before last .) + fileName lessExt() const; + + //- Return file name extension (part after last .) + word ext() const; + + //- Append a '.' and the ending, and return the object. + // The '.' and ending will not be added when the ending is empty, + // or when the file name is empty or ended with a '/'. + fileName& ext(const word& ending); + + //- Return true if it has an extension or simply ends with a '.' + bool hasExt() const; + + //- Return true if the extension is the same as the given ending. + bool hasExt(const word& ending) const; + + //- Return true if the extension matches the given ending. + bool hasExt(const wordRe& ending) const; + + //- Remove extension, returning true if string changed. + bool removeExt(); + + + //- Return path components as wordList + // + // Behaviour: + // \verbatim + // Input components() + // ----- ------ + // "foo" 1("foo") + // "/foo" 1("foo") + // "foo/bar" 2("foo", "bar") + // "/foo/bar" 2("foo", "bar") + // "/foo/bar/" 2("foo", "bar") + // \endverbatim + wordList components(const char delimiter = '/') const; + + //- Return a single component of the path + word component + ( + const size_type cmpt, + const char delimiter = '/' + ) const; // Member operators diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.C b/src/OpenFOAM/primitives/strings/keyType/keyType.C index 3df927921e3fd10d4ce3a5bf67fdcb071aa6ae6c..5b27421414fe57d3ddfebe9927d3f134ebbfea99 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.C +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.C @@ -48,21 +48,17 @@ Foam::keyType::keyType(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::keyType::match -( - const std::string& str, - bool literalMatch -) const +bool Foam::keyType::match(const std::string& text, bool literal) const { - if (literalMatch || !isPattern_) + if (literal || !isPattern_) { // check as string - return (str == *this); + return (text == *this); } else { // check as regex - return regExp(*this).match(str); + return regExp(*this).match(text); } } diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index f79332ff5e0b98b4917d4ea69882dc9a2b4034e6..3f342e0e2232967658349a1b6f71274bed65e00b 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -28,7 +28,9 @@ Description A class for handling keywords in dictionaries. A keyType is the keyword of a dictionary. - It differs from word in that it accepts patterns (regular expressions). + It differs from word in that it also accepts patterns (regular expressions). + It is very similar to wordRe, but doesn't store the regular expression + separately. SourceFiles keyType.C @@ -49,13 +51,10 @@ namespace Foam class Istream; class Ostream; - // Forward declaration of friend functions and operators - class keyType; - -Istream& operator>>(Istream&, keyType&); -Ostream& operator<<(Ostream&, const keyType&); +Istream& operator>>(Istream& is, keyType& kw); +Ostream& operator<<(Ostream& os, const keyType& kw); /*---------------------------------------------------------------------------*\ @@ -74,7 +73,7 @@ class keyType // Private Member Functions //- Disallow assignments where we cannot determine string/word type - void operator=(const std::string&); + void operator=(const std::string&) = delete; public: @@ -89,57 +88,58 @@ public: //- Construct null inline keyType(); - //- Construct as copy - inline keyType(const keyType&); + //- Construct as copy, retaining type (literal or regex) + inline keyType(const keyType& s); //- Construct as copy of word. Not treated as a regular expression - inline keyType(const word&); + inline keyType(const word& s); //- Construct as copy of string. Treat as regular expression. - inline keyType(const string&); + inline keyType(const string& s); //- Construct as copy of character array. // Not treated as a regular expression - inline keyType(const char*); + inline keyType(const char* s); //- Construct as copy of std::string with specified treatment - inline keyType(const std::string&, const bool isPattern); + inline keyType(const std::string& s, const bool isPattern); //- Construct from Istream // Treat as regular expression if surrounded by quotation marks. - keyType(Istream&); + keyType(Istream& is); // Member functions - //- Should be treated as a match rather than a literal string + //- Treat as a pattern rather than a literal string? inline bool isPattern() const; - //- Smart match as regular expression or as a string + //- Smart match as regular expression or as a string. // Optionally force a literal match only - bool match(const std::string&, bool literalMatch=false) const; + bool match(const std::string& text, bool literal = false) const; + // Member operators // Assignment - //- Assignment operator - inline void operator=(const keyType&); + //- Assignment operator, retaining type (literal or regex) + inline void operator=(const keyType& s); - //- Assign as word, not as non regular expression - inline void operator=(const word&); + //- Assign as word, not treated as a regular expression. + inline void operator=(const word& s); //- Assign as regular expression - inline void operator=(const string&); + inline void operator=(const string& s); - //- Assign as word, not as non regular expression - inline void operator=(const char*); + //- Assign as word, not treated as a regular expression. + inline void operator=(const char* s); // IOstream operators - friend Istream& operator>>(Istream&, keyType&); - friend Ostream& operator<<(Ostream&, const keyType&); + friend Istream& operator>>(Istream& is, keyType& kw); + friend Ostream& operator<<(Ostream& os, const keyType& kw); }; diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H index 0f2b8fc3a381cb96ebd6f4e5e6994e50c0fba836..99b73ac10908a2a6be9464822170e786a4a73ce6 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H @@ -83,31 +83,28 @@ inline bool Foam::keyType::isPattern() const inline void Foam::keyType::operator=(const keyType& s) { - // Bypass checking - string::operator=(s); + string::operator=(s); // Bypass checking isPattern_ = s.isPattern_; } inline void Foam::keyType::operator=(const word& s) { - word::operator=(s); + string::operator=(s); // Bypass checking isPattern_ = false; } inline void Foam::keyType::operator=(const string& s) { - // Bypass checking - string::operator=(s); + string::operator=(s); // Bypass checking isPattern_ = true; } inline void Foam::keyType::operator=(const char* s) { - // Bypass checking - string::operator=(s); + string::operator=(s); // Bypass checking isPattern_ = false; } diff --git a/src/OpenFOAM/primitives/strings/lists/stringListOps.H b/src/OpenFOAM/primitives/strings/lists/stringListOps.H index 927118e87f67f5f3fb6949d4f0c9284242c8bbac..677d4e8a07190445b490687c79e0fa292e71ed8e 100644 --- a/src/OpenFOAM/primitives/strings/lists/stringListOps.H +++ b/src/OpenFOAM/primitives/strings/lists/stringListOps.H @@ -45,7 +45,7 @@ SourceFiles namespace Foam { - // single-string matches: + // Single-string matches: //- Return true if string matches one of the regular expressions inline bool findStrings @@ -57,14 +57,14 @@ namespace Foam return matcher.match(str); } - // multi-string matches: + // Multi-string matches: //- Return list indices for matching strings template<class Matcher, class StringType> labelList findMatchingStrings ( - const Matcher&, - const UList<StringType>&, + const Matcher& matcher, + const UList<StringType>& lst, const bool invert=false ); @@ -92,7 +92,7 @@ namespace Foam ) { const regExp re(rePattern); - return findStrings(re, lst, invert); + return findMatchingStrings(re, lst, invert); } //- Return list indices for strings matching the regular expression diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C index 3b0d6acfbf6eb1f157b72f1d491bbb945093f4d4..5f03edeba1c97c0168e8cb149e4b31d3c9582906 100644 --- a/src/OpenFOAM/primitives/strings/string/string.C +++ b/src/OpenFOAM/primitives/strings/string/string.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -167,6 +167,48 @@ Foam::string Foam::string::removeTrailing(const char character) const } +bool Foam::string::removeStart(const std::string& text) +{ + const size_type txtLen = text.size(); + if (!txtLen) + { + return true; + } + + const size_type strLen = this->size(); + if (strLen >= txtLen && !compare(0, txtLen, text)) + { + this->erase(0, txtLen); + return true; + } + else + { + return false; + } +} + + +bool Foam::string::removeEnd(const std::string& text) +{ + const size_type txtLen = text.size(); + if (!txtLen) + { + return true; + } + + const size_type strLen = this->size(); + if (strLen >= txtLen && !compare(strLen - txtLen, npos, text)) + { + this->resize(strLen - txtLen); + return true; + } + else + { + return false; + } +} + + bool Foam::string::startsWith(const std::string& text) const { const size_type strLen = this->size(); diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 0b05a868b3d3e3f9766512b0a66a509094dbe889..7010427059effe434f7dd4f30494ef5c286c4915 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -201,6 +201,14 @@ public: //- Return string with trailing character removed string removeTrailing(const char character) const; + //- Remove the given text from the start of the string. + // Always true if the removal occurred or the given text is empty. + bool removeStart(const std::string& text); + + //- Remove the given text from the end of the string. + // Always true if the removal occurred or the given text is empty. + bool removeEnd(const std::string& text); + //- True if the string starts with the given text. // Always true if the given text is empty or if the string // is identical to the given text. diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index 4dc7c08f0fe5962b9470e3d85daae2930a644b76..9b7f73a4f2d4c0c68ed42b417ddcc41633cf0226 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,7 +34,6 @@ License //! \cond fileScope // Find the type/position of the ":-" or ":+" alternative values -// static inline int findParameterAlternative ( const std::string& s, @@ -132,7 +131,7 @@ Foam::string& Foam::stringOps::inplaceExpand iter != s.end() && ( - isalnum(*iter) + std::isalnum(*iter) || *iter == '.' || *iter == ':' || *iter == '_' @@ -285,6 +284,30 @@ Foam::string Foam::stringOps::getVariable { value = getEnv(name); + if (value.empty() && !name.empty()) + { + // The type/position of the ":-" or ":+" alternative values + string::size_type altPos = 0; + + // check for parameter:-word or parameter:+word + int altType = findParameterAlternative(name, altPos, name.size()-1); + if (altType) + { + value = getEnv + ( + // var-name + word(name.substr(0, altPos), false) + ); + + // ":-" or ":+" alternative value + if (value.empty() ? (altType == '-') : (altType == '+')) + { + // alternative + value = name.substr(altPos + 2); + } + } + } + if (value.empty()) { FatalIOErrorInFunction @@ -391,15 +414,15 @@ Foam::string& Foam::stringOps::inplaceExpand else { string::iterator iter = s.begin() + begVar + 1; + string::size_type endVar = begVar; // more generous in accepting keywords than for env variables - string::size_type endVar = begVar; while ( iter != s.end() && ( - isalnum(*iter) + std::isalnum(*iter) || *iter == '.' || *iter == ':' || *iter == '_' @@ -536,7 +559,7 @@ Foam::string& Foam::stringOps::inplaceExpand iter != s.end() && ( - isalnum(*iter) + std::isalnum(*iter) || *iter == '.' || *iter == ':' || *iter == '_' @@ -681,7 +704,7 @@ Foam::string& Foam::stringOps::inplaceExpand while ( iter != s.end() - && (isalnum(*iter) || *iter == '_') + && (std::isalnum(*iter) || *iter == '_') ) { ++iter; @@ -843,12 +866,38 @@ Foam::string& Foam::stringOps::inplaceExpand } +bool Foam::stringOps::inplaceReplaceVar(string& s, const word& varName) +{ + if (s.empty() || varName.empty()) + { + return false; + } + + const string content(getEnv(varName)); + if (content.empty()) + { + return false; + } + + const std::string::size_type i = s.find(content); + if (i == std::string::npos) + { + return false; + } + else + { + s.replace(i, content.size(), string("${" + varName + "}")); + return true; + } +} + + Foam::string Foam::stringOps::trimLeft(const string& s) { if (!s.empty()) { string::size_type beg = 0; - while (beg < s.size() && isspace(s[beg])) + while (beg < s.size() && std::isspace(s[beg])) { ++beg; } @@ -868,7 +917,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s) if (!s.empty()) { string::size_type beg = 0; - while (beg < s.size() && isspace(s[beg])) + while (beg < s.size() && std::isspace(s[beg])) { ++beg; } @@ -888,7 +937,7 @@ Foam::string Foam::stringOps::trimRight(const string& s) if (!s.empty()) { string::size_type sz = s.size(); - while (sz && isspace(s[sz-1])) + while (sz && std::isspace(s[sz-1])) { --sz; } @@ -908,7 +957,7 @@ Foam::string& Foam::stringOps::inplaceTrimRight(string& s) if (!s.empty()) { string::size_type sz = s.size(); - while (sz && isspace(s[sz-1])) + while (sz && std::isspace(s[sz-1])) { --sz; } diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index fb408455f610d09d8165e88769fa69f564605197..66e87623e50dba05a396a8faf191143059c8746d 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,30 +56,26 @@ namespace stringOps // -# variables // - "$VAR", "${VAR}" // - // Supports default values as per the Bourne/Korn shell. + // Supports default and alternative values as per the POSIX shell. // \code - // "${parameter:-defValue}" + // a) "${parameter:-defValue}" + // b) "${parameter:+altValue}" // \endcode - // If parameter is unset or null, the \c defValue is substituted. + // a) If parameter is unset or null, the \c defValue is substituted. // Otherwise, the value of parameter is substituted. // - // Supports alternative values as per the Bourne/Korn shell. - // \code - // "${parameter:+altValue}" - // \endcode - // If parameter is unset or null, nothing is substituted. + // b) If parameter is unset or null, nothing is substituted. // Otherwise the \c altValue is substituted. // - // Any unknown entries are removed silently. - // - // Malformed entries (eg, brace mismatch, sigil followed by bad character) + // - Any unknown entries are removed silently. + // - Malformed entries (eg, brace mismatch, sigil followed by bad chars) // are left as is. // // \note the leading sigil can be changed to avoid conflicts with other // string expansions string expand ( - const string&, + const string& original, const HashTable<string, word, string::hash>& mapping, const char sigil = '$' ); @@ -90,30 +86,26 @@ namespace stringOps // -# variables // - "$VAR", "${VAR}" // - // Supports default values as per the Bourne/Korn shell. + // Supports default and alternative values as per the POSIX shell. // \code - // "${parameter:-defValue}" + // a) "${parameter:-defValue}" + // b) "${parameter:+altValue}" // \endcode - // If parameter is unset or null, the \c defValue is substituted. + // a) If parameter is unset or null, the \c defValue is substituted. // Otherwise, the value of parameter is substituted. // - // Supports alternative values as per the Bourne/Korn shell. - // \code - // "${parameter:+altValue}" - // \endcode - // If parameter is unset or null, nothing is substituted. + // b) If parameter is unset or null, nothing is substituted. // Otherwise the \c altValue is substituted. // - // Any unknown entries are removed silently. - // - // Malformed entries (eg, brace mismatch, sigil followed by bad character) + // - Any unknown entries are removed silently. + // - Malformed entries (eg, brace mismatch, sigil followed by bad chars) // are left as is. // // \note the leading sigil can be changed to avoid conflicts with other // string expansions string& inplaceExpand ( - string&, + string& s, const HashTable<string, word, string::hash>& mapping, const char sigil = '$' ); @@ -129,13 +121,20 @@ namespace stringOps // string expansions string expand ( - const string&, + const string& original, const dictionary& dict, const char sigil = '$' ); //- Get dictionary or (optionally) environment variable + // + // The environment variable lookup supports default and alternative + // values as per the POSIX shell. + // \code + // ${parameter:-defValue} + // ${parameter:+altValue} + // \endcode string getVariable ( const word& name, @@ -189,7 +188,7 @@ namespace stringOps // string expansions string& inplaceExpand ( - string&, + string& s, const dictionary& dict, const char sigil = '$' ); @@ -206,30 +205,26 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - // Supports default values as per the Bourne/Korn shell. + // Supports default and alternative values as per the POSIX shell. // \code - // "${parameter:-defValue}" + // a) "${parameter:-defValue}" + // b) "${parameter:+altValue}" // \endcode - // If parameter is unset or null, the \c defValue is substituted. + // a) If parameter is unset or null, the \c defValue is substituted. // Otherwise, the value of parameter is substituted. // - // Supports alternative values as per the Bourne/Korn shell. - // \code - // "${parameter:+altValue}" - // \endcode - // If parameter is unset or null, nothing is substituted. + // b) If parameter is unset or null, nothing is substituted. // Otherwise the \c altValue is substituted. // - // Any unknown entries are removed silently, if allowEmpty is true. - // - // Malformed entries (eg, brace mismatch, sigil followed by bad character) + // - Any unknown entries are removed silently, if allowEmpty is true. + // - Malformed entries (eg, brace mismatch, sigil followed by bad chars) // are left as is. // // \sa // Foam::findEtcFile string expand ( - const string&, + const string& original, const bool allowEmpty = false ); @@ -245,63 +240,62 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - // Supports default values as per the Bourne/Korn shell. + // Supports default and alternative values as per the POSIX shell. // \code - // "${parameter:-defValue}" + // a) "${parameter:-defValue}" + // b) "${parameter:+altValue}" // \endcode - // If parameter is unset or null, the \c defValue is substituted. + // a) If parameter is unset or null, the \c defValue is substituted. // Otherwise, the value of parameter is substituted. // - // Supports alternative values as per the Bourne/Korn shell. - // \code - // "${parameter:+altValue}" - // \endcode - // If parameter is unset or null, nothing is substituted. + // b) If parameter is unset or null, nothing is substituted. // Otherwise the \c altValue is substituted. // - // Any unknown entries are removed silently, if allowEmpty is true. - // - // Malformed entries (eg, brace mismatch, sigil followed by bad character) + // - Any unknown entries are removed silently if allowEmpty is true. + // - Malformed entries (eg, brace mismatch, sigil followed by bad chars) // are left as is. // - // Any unknown entries are removed silently if allowEmpty is true. // \sa // Foam::findEtcFile string& inplaceExpand ( - string&, + string& s, const bool allowEmpty = false ); + //- Replace environment variable contents with its name. + // This is essentially the inverse operation for inplaceExpand. + // Return true if a replacement was successful. + bool inplaceReplaceVar(string& s, const word& varName); + + //- Return string trimmed of leading whitespace - string trimLeft(const string&); + string trimLeft(const string& s); //- Trim leading whitespace inplace - string& inplaceTrimLeft(string&); + string& inplaceTrimLeft(string& s); //- Return string trimmed of trailing whitespace - string trimRight(const string&); + string trimRight(const string& s); //- Trim trailing whitespace inplace - string& inplaceTrimRight(string&); + string& inplaceTrimRight(string& s); //- Return string trimmed of leading and trailing whitespace - string trim(const string&); + string trim(const string& original); //- Trim leading and trailing whitespace inplace - string& inplaceTrim(string&); + string& inplaceTrim(string& s); - //- Return a word representation of the primitive, - // using printf-style formatter. + //- Using printf-formatter for a word representation of the primitive. // The representation is not checked for valid word characters - // it is assumed that the caller knows what they are doing template<class PrimitiveType> Foam::word name(const char* fmt, const PrimitiveType& val); - //- Return a word representation of the primitive, - // using printf-style formatter. + //- Using printf-formatter for a word representation of the primitive. // The representation is not checked for valid word characters - // it is assumed that the caller knows what they are doing template<class PrimitiveType> diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C b/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C index a3874aa88ee30aac71a845e8b774458036ac6ae3..a8f70303006ca95985ac0b837c9f97a14a3e92f6 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C @@ -40,15 +40,14 @@ Foam::word Foam::stringOps::name // same concept as GNU/BSD asprintf() // use snprintf with zero to determine the number of characters required - int n = ::snprintf(0, 0, fmt, val); + const int n = ::snprintf(nullptr, 0, fmt, val); if (n > 0) { char buf[n+1]; ::snprintf(buf, n+1, fmt, val); buf[n] = 0; - // no stripping desired - return word(buf, false); + return word(buf, false); // no stripping desired } return word::null; diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C index c2ab7daec0d4936d2db25253dba456e001ea738a..d7725323ca7ed787902cfc3cebd5c744c67060a3 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C @@ -110,7 +110,6 @@ Foam::Ostream& Foam::wordRe::info(Ostream& os) const { os << "wordRe(plain) \"" << *this << '"'; } - os.flush(); return os; } diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index c5a0a3b95ed820bc2ee292bd78dda34fabad4f11..21eba6421d09bb86c913cc208e34b699af607b1a 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,8 +39,8 @@ Description Note If the string contents are changed - eg, by the operator+=() or by - string::replace(), etc - it will be necessary to use compile() or - recompile() to synchronize the regular expression. + string::replace(), etc - it will be necessary to use compile() to + synchronize the regular expression. SourceFiles wordRe.C @@ -64,8 +64,8 @@ class wordRe; class Istream; class Ostream; -Istream& operator>>(Istream&, wordRe&); -Ostream& operator<<(Ostream&, const wordRe&); +Istream& operator>>(Istream& is, wordRe& w); +Ostream& operator<<(Ostream& os, const wordRe& w); /*---------------------------------------------------------------------------*\ @@ -105,10 +105,10 @@ public: //- Is this a meta character? - static inline bool meta(char); + inline static bool meta(const char c); //- Test string for regular expression meta characters - static inline bool isPattern(const string&); + inline static bool isPattern(const std::string& str); // Constructors @@ -117,122 +117,119 @@ public: inline wordRe(); //- Construct as copy - inline wordRe(const wordRe&); + inline wordRe(const wordRe& str); //- Construct from keyType - inline explicit wordRe(const keyType&); + inline explicit wordRe(const keyType& str); - //- Construct from keyType - inline wordRe(const keyType&, const compOption); + //- Construct from keyType, use specified compile option + inline wordRe(const keyType& str, const compOption); //- Construct as copy of word - inline explicit wordRe(const word&); + inline explicit wordRe(const word& str); //- Construct as copy of character array // Optionally specify how it should be treated. - inline explicit wordRe(const char*, const compOption = LITERAL); + inline explicit wordRe(const char* str, const compOption = LITERAL); //- Construct as copy of string. // Optionally specify how it should be treated. - inline explicit wordRe(const string&, const compOption = LITERAL); + inline explicit wordRe(const string& str, const compOption = LITERAL); //- Construct as copy of std::string // Optionally specify how it should be treated. - inline explicit wordRe(const std::string&, const compOption = LITERAL); + inline explicit wordRe + ( + const std::string& str, + const compOption = LITERAL + ); //- Construct from Istream // Words are treated as literals, strings with an auto-test - wordRe(Istream&); + wordRe(Istream& is); // Member functions - // Access - - //- Should be treated as a match rather than a literal string? - inline bool isPattern() const; + // Access + //- Treat as a pattern rather than a literal string? + inline bool isPattern() const; - // Infrastructure - //- Compile the regular expression - inline bool compile() const; + // Infrastructure - //- Possibly compile the regular expression, with greater control - inline bool compile(const compOption) const; + //- Compile the regular expression + inline bool compile() const; - //- Recompile an existing regular expression - inline bool recompile() const; + //- Possibly compile the regular expression, with greater control + inline bool compile(const compOption) const; - //- Frees precompiled regular expression, making wordRe a literal. - // Optionally strips invalid word characters - inline void uncompile(const bool doStripInvalid = false) const; + //- Make wordRe a literal again, instead of a regular expression. + // Optionally strip invalid word characters. + inline void uncompile(const bool doStripInvalid = false) const; - // Editing + // Editing - //- Copy string, auto-test for regular expression or other options - inline void set(const std::string&, const compOption = DETECT); + //- Copy string, auto-test for regular expression or other options + inline void set(const std::string& str, const compOption = DETECT); - //- Copy string, auto-test for regular expression or other options - inline void set(const char*, const compOption = DETECT); + //- Copy string, auto-test for regular expression or other options + inline void set(const char* str, const compOption = DETECT); - //- Clear string and precompiled regular expression - inline void clear(); + //- Clear string and regular expression + inline void clear(); - // Searching + // Matching/Searching - //- Smart match as regular expression or as a string - // Optionally force a literal match only - inline bool match - ( - const std::string&, - bool literalMatch = false - ) const; + //- Smart match as regular expression or as a string. + // Optionally force a literal match only + inline bool match(const std::string& text, bool literal = false) const; - // Miscellaneous + // Miscellaneous - //- Return a string with quoted meta-characters - inline string quotemeta() const; + //- Return a string with quoted meta-characters + inline string quotemeta() const; - //- Output some basic info - Ostream& info(Ostream&) const; + //- Output some basic info + Ostream& info(Ostream& os) const; // Member operators - // Assignment + // Assignment - //- Assign copy - // Always case sensitive - inline void operator=(const wordRe&); + //- Copy wordRe and its type (literal or regex) + // Always case sensitive + inline void operator=(const wordRe& str); - //- Copy word, never a regular expression - inline void operator=(const word&); + //- Copy word, never a regular expression + inline void operator=(const word& str); - //- Copy keyType, auto-test for regular expression - // Always case sensitive - inline void operator=(const keyType&); + //- Copy keyType and its type (literal or regex) + // Always case sensitive + inline void operator=(const keyType& str); - //- Copy string, auto-test for regular expression - // Always case sensitive - inline void operator=(const string&); + //- Copy string, auto-test for regular expression + // Always case sensitive + inline void operator=(const string& str); - //- Copy string, auto-test for regular expression - // Always case sensitive - inline void operator=(const std::string&); + //- Copy string, auto-test for regular expression + // Always case sensitive + inline void operator=(const std::string& str); - //- Copy string, auto-test for regular expression - // Always case sensitive - inline void operator=(const char*); + //- Copy string, auto-test for regular expression + // Always case sensitive + inline void operator=(const char* str); // IOstream operators - friend Istream& operator>>(Istream&, wordRe&); - friend Ostream& operator<<(Ostream&, const wordRe&); + friend Istream& operator>>(Istream& is, wordRe& w); + friend Ostream& operator<<(Ostream& os, const wordRe& w); }; diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H index d35a8134b7c4c06d5648ece5feec6e9ebc9d698a..78de818e3afac02ee387498bf1a111ead2f9ac71 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H @@ -25,13 +25,13 @@ License // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // -inline bool Foam::wordRe::meta(char c) +inline bool Foam::wordRe::meta(const char c) { return regExp::meta(c); } -inline bool Foam::wordRe::isPattern(const string& str) +inline bool Foam::wordRe::isPattern(const std::string& str) { return string::meta<regExp>(str); } @@ -165,23 +165,12 @@ inline bool Foam::wordRe::compile() const } -inline bool Foam::wordRe::recompile() const -{ - if (re_.exists()) - { - re_ = *this; - } - - return re_.exists(); -} - - inline void Foam::wordRe::uncompile(const bool doStripInvalid) const { - if (re_.clear()) + if (re_.clear() && doStripInvalid) { // skip stripping unless debug is active to avoid costly operations - if (word::debug && doStripInvalid) + if (word::debug) { string::stripInvalid<word> ( @@ -199,17 +188,17 @@ inline void Foam::wordRe::clear() } -inline bool Foam::wordRe::match(const std::string& str, bool literalMatch) const +inline bool Foam::wordRe::match(const std::string& text, bool literal) const { - if (literalMatch || !re_.exists()) + if (literal || !re_.exists()) { // check as string - return (str == *this); + return (text == *this); } else { // check as regex - return re_.match(str); + return re_.match(text); } } @@ -239,7 +228,6 @@ inline void Foam::wordRe::set(const char* str, const compOption opt) inline void Foam::wordRe::operator=(const wordRe& str) { string::operator=(str); - if (str.isPattern()) { compile(); @@ -253,7 +241,7 @@ inline void Foam::wordRe::operator=(const wordRe& str) inline void Foam::wordRe::operator=(const word& str) { - word::operator=(str); + string::operator=(str); re_.clear(); } @@ -265,27 +253,31 @@ inline void Foam::wordRe::operator=(const keyType& str) { compile(); } + else + { + re_.clear(); + } } inline void Foam::wordRe::operator=(const string& str) { string::operator=(str); - compile(DETECT); // auto-detect regex + compile(wordRe::DETECT); // auto-detect regex } inline void Foam::wordRe::operator=(const std::string& str) { string::operator=(str); - compile(DETECT); // auto-detect regex + compile(wordRe::DETECT); // auto-detect regex } inline void Foam::wordRe::operator=(const char* str) { string::operator=(str); - compile(DETECT); // auto-detect regex + compile(wordRe::DETECT); // auto-detect regex } diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/temperatureCoupledBase/temperatureCoupledBase.C b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/temperatureCoupledBase/temperatureCoupledBase.C index be069684f361db58f9657d4bcb246015a89312ab..8a7027a59c9e8bb2a0595a00f0d0510cd9f048ca 100644 --- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/temperatureCoupledBase/temperatureCoupledBase.C +++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/temperatureCoupledBase/temperatureCoupledBase.C @@ -78,7 +78,7 @@ Foam::temperatureCoupledBase::temperatureCoupledBase patch_(patch), method_(KMethodTypeNames_.read(dict.lookup("kappaMethod"))), kappaName_(dict.lookupOrDefault<word>("kappa", "none")), - alphaAniName_(dict.lookupOrDefault<word>("alphaAni","Anialpha")) + alphaAniName_(dict.lookupOrDefault<word>("alphaAni","none")) {} diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C index d69c96ee2c8e92989daa7f93ab8d5d710d067240..f2629e6f4057ff873d8d42c7b6967db96c872ad4 100644 --- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C +++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,7 @@ License #include "fvPatchFieldMapper.H" #include "volFields.H" #include "mappedPatchBase.H" +#include "basicThermo.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,7 +53,8 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField QrName_("undefined-Qr"), thicknessLayers_(0), kappaLayers_(0), - contactRes_(0) + contactRes_(0), + thermalInertia_(false) { this->refValue() = 0.0; this->refGrad() = 0.0; @@ -76,7 +78,8 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField QrName_(psf.QrName_), thicknessLayers_(psf.thicknessLayers_), kappaLayers_(psf.kappaLayers_), - contactRes_(psf.contactRes_) + contactRes_(psf.contactRes_), + thermalInertia_(psf.thermalInertia_) {} @@ -95,7 +98,8 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField QrName_(dict.lookupOrDefault<word>("Qr", "none")), thicknessLayers_(0), kappaLayers_(0), - contactRes_(0.0) + contactRes_(0.0), + thermalInertia_(dict.lookupOrDefault<Switch>("thermalInertia", false)) { if (!isA<mappedPatchBase>(this->patch().patch())) { @@ -156,7 +160,8 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField QrName_(psf.QrName_), thicknessLayers_(psf.thicknessLayers_), kappaLayers_(psf.kappaLayers_), - contactRes_(psf.contactRes_) + contactRes_(psf.contactRes_), + thermalInertia_(psf.thermalInertia_) {} @@ -169,6 +174,8 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs() return; } + const polyMesh& mesh = patch().boundaryMesh().mesh(); + // Since we're inside initEvaluate/evaluate there might be processor // comms underway. Change the tag we use. int oldTag = UPstream::msgType(); @@ -225,9 +232,78 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs() mpp.distribute(QrNbr); } - valueFraction() = KDeltaNbr/(KDeltaNbr + KDelta); - refValue() = TcNbr; - refGrad() = (Qr + QrNbr)/kappa(Tp); + // inertia therm + if (thermalInertia_) + { + const scalar dt = mesh.time().deltaTValue(); + scalarField mCpDtNbr; + + { + const basicThermo* thermo = + nbrMesh.lookupObjectPtr<basicThermo>(basicThermo::dictName); + + if (thermo) + { + mCpDtNbr = + ( + thermo->Cp()().boundaryField()[nbrPatch.index()] + * thermo->rho()().boundaryField()[nbrPatch.index()] + / nbrPatch.deltaCoeffs()/dt + ); + + mpp.distribute(mCpDtNbr); + } + else + { + mCpDtNbr.setSize(Tp.size(), 0.0); + } + } + + scalarField mCpDt; + + // Local inertia therm + { + const basicThermo* thermo = + mesh.lookupObjectPtr<basicThermo>(basicThermo::dictName); + + if (thermo) + { + mCpDt = + ( + thermo->rho()().boundaryField()[patch().index()] + * thermo->Cp()().boundaryField()[patch().index()] + / patch().deltaCoeffs()/dt + ); + } + else + { + // Issue warning? + mCpDt.setSize(Tp.size(), 0.0); + } + } + + const volScalarField& T = + this->db().lookupObject<volScalarField> + ( + this->internalField().name() + ); + + const fvPatchField<scalar>& TpOld = + T.oldTime().boundaryField()[patch().index()]; + + scalarField alpha(KDeltaNbr + mCpDt + mCpDtNbr); + + valueFraction() = alpha/(alpha + KDelta); + scalarField c(KDeltaNbr*TcNbr + (mCpDt + mCpDtNbr)*TpOld); + refValue() = c/alpha; + refGrad() = (Qr + QrNbr)/kappa(Tp); + } + else + { + valueFraction() = KDeltaNbr/(KDeltaNbr + KDelta); + refValue() = TcNbr; + refGrad() = (Qr + QrNbr)/kappa(Tp); + } mixedFvPatchScalarField::updateCoeffs(); @@ -263,6 +339,8 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::write os.writeKeyword("Tnbr")<< TnbrName_ << token::END_STATEMENT << nl; os.writeKeyword("QrNbr")<< QrNbrName_ << token::END_STATEMENT << nl; os.writeKeyword("Qr")<< QrName_ << token::END_STATEMENT << nl; + os.writeEntry("thermalInertia", thermalInertia_); + thicknessLayers_.writeEntry("thicknessLayers", os); kappaLayers_.writeEntry("kappaLayers", os); diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.H b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.H index 275362096544acfca545d5a7ba1100dc49f338de..1efecea9d02923d5f4dcdcc5403e2b3aac4d8458 100644 --- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.H +++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,6 +44,7 @@ Usage kappaLayers | list of thermal conductivites per layer [W/m/K] | no | kappaMethod | inherited from temperatureCoupledBase | inherited | kappa | inherited from temperatureCoupledBase | inherited | + thermalInertia | Add thermal inertia to wall node | no | false \endtable Example of the boundary condition specification: @@ -56,6 +57,7 @@ Usage Qr Qr; // or none. Name of Qr field on local region thicknessLayers (0.1 0.2 0.3 0.4); kappaLayers (1 2 3 4); + thermalInertia false/true; kappaMethod lookup; kappa kappa; value uniform 300; @@ -115,6 +117,9 @@ class turbulentTemperatureRadCoupledMixedFvPatchScalarField //- Total contact resistance scalar contactRes_; + //- Thermal inertia term + Switch thermalInertia_; + public: diff --git a/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C b/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C index af52b56c59f2b8ffa84dab752998c47339f35bc1..9f423b0e6b296ce638bd048445fe3404c98fa8dd 100644 --- a/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C +++ b/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C @@ -245,7 +245,7 @@ void Foam::fileFormats::OBJedgeFormat::write os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl - << "o " << os.name().lessExt().name() << nl + << "o " << os.name().nameLessExt() << nl << nl << "# points : " << pointLst.size() << nl << "# lines : " << edgeLst.size() << nl; diff --git a/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C b/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C index 2d6e658d88afe46e4961f670088b84f0d8f9a263..f575a60a2a4f08a6bdb3e04e47239725d44728d6 100644 --- a/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C +++ b/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C @@ -65,7 +65,7 @@ void Foam::fileFormats::STARCDedgeFormat::writeCase const label nEdges ) { - word caseName = os.name().lessExt().name(); + const word caseName = os.name().nameLessExt(); os << "! STAR-CD file written " << clock::dateTime().c_str() << nl << "! " << pointLst.size() << " points, " << nEdges << " lines" << nl diff --git a/src/fileFormats/stl/STLCore.C b/src/fileFormats/stl/STLCore.C index 9b7c0c2e1c17f98a2a45c0a77819dd4549e35672..bdfae0c02556f3387b9aa3a75ed979b519071cec 100644 --- a/src/fileFormats/stl/STLCore.C +++ b/src/fileFormats/stl/STLCore.C @@ -32,9 +32,30 @@ License //! \cond fileScope -// The number of bytes in the STL binary header +// The number of bytes in the STL binary header static const unsigned STLHeaderSize = 80; +// Check if "SOLID" or "solid" appears as the first non-space content. +// Assume that any leading space is less than 75 chars or so, otherwise +// it is really bad input. +static bool startsWithSolid(const char header[STLHeaderSize]) +{ + unsigned pos = 0; + while (std::isspace(header[pos]) && pos < STLHeaderSize) + { + ++pos; + } + + return + ( + pos < (STLHeaderSize-5) // At least 5 chars remaining + && std::toupper(header[pos+0]) == 'S' + && std::toupper(header[pos+1]) == 'O' + && std::toupper(header[pos+2]) == 'L' + && std::toupper(header[pos+3]) == 'I' + && std::toupper(header[pos+4]) == 'D' + ); +} //! \endcond @@ -58,10 +79,10 @@ bool Foam::fileFormats::STLCore::isBinaryName // Check binary by getting the header and number of facets // this seems to work better than the old token-based method -// - some programs (eg, pro-STAR) have 'solid' as the first word in -// the binary header. // - using wordToken can cause an abort if non-word (binary) content // is detected ... this is not exactly what we want. +// - some programs (eg, pro-STAR) have 'solid' as the first word in +// the binary header. This is just wrong and not our fault. int Foam::fileFormats::STLCore::detectBinaryHeader ( const fileName& filename @@ -93,27 +114,24 @@ int Foam::fileFormats::STLCore::detectBinaryHeader char header[STLHeaderSize]; is.read(header, STLHeaderSize); - // Check that stream is OK, if not this may be an ASCII file - if (!is.good()) + // If the stream is bad, it can't be a binary STL + if (!is.good() || startsWithSolid(header)) { return 0; } + // Read the number of triangles in the STL file - // (note: read as int so we can check whether >2^31) - int nTris; - is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); + // (note: read as signed so we can check whether >2^31) + int32_t nTris; + is.read(reinterpret_cast<char*>(&nTris), sizeof(int32_t)); // Check that stream is OK and number of triangles is positive, // if not this may be an ASCII file // // Also compare the file size with that expected from the number of tris - // If the comparison is not sensible then it may be an ASCII file - if - ( - !is - || nTris < 0 - ) + // If the comparison is still not sensible then it may be an ASCII file + if (!is || nTris < 0) { return 0; } @@ -176,7 +194,7 @@ Foam::fileFormats::STLCore::readBinaryHeader is.read(header, STLHeaderSize); // Check that stream is OK, if not this may be an ASCII file - if (!is.good()) + if (!is.good()) // could check again: startsWithSolid(header) { streamPtr.clear(); @@ -187,8 +205,8 @@ Foam::fileFormats::STLCore::readBinaryHeader // Read the number of triangles in the STl file // (note: read as int so we can check whether >2^31) - int nTris; - is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); + int32_t nTris; + is.read(reinterpret_cast<char*>(&nTris), sizeof(int32_t)); // Check that stream is OK and number of triangles is positive, // if not this maybe an ASCII file @@ -230,7 +248,7 @@ Foam::fileFormats::STLCore::readBinaryHeader void Foam::fileFormats::STLCore::writeBinaryHeader ( ostream& os, - unsigned int nTris + uint32_t nTris ) { // STL header with extra information about nTris @@ -244,7 +262,7 @@ void Foam::fileFormats::STLCore::writeBinaryHeader } os.write(header, STLHeaderSize); - os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); + os.write(reinterpret_cast<char*>(&nTris), sizeof(uint32_t)); } diff --git a/src/fileFormats/stl/STLCore.H b/src/fileFormats/stl/STLCore.H index fede83b850eb6eeb59c9fca34aa110d8aca16d63..6e8928d3c1c5908bd5cf5a2cd4a8294fd542dd14 100644 --- a/src/fileFormats/stl/STLCore.H +++ b/src/fileFormats/stl/STLCore.H @@ -79,7 +79,7 @@ protected: //- Check contents to detect if the file is a binary STL. // Return the estimated number of triangles or 0 on error. - static int detectBinaryHeader(const fileName&); + static int detectBinaryHeader(const fileName& filename); //- Read STL binary file header. @@ -92,7 +92,7 @@ protected: ); //- Write STL binary file and number of triangles to stream - static void writeBinaryHeader(ostream&, unsigned int); + static void writeBinaryHeader(ostream& os, uint32_t nTris); // Constructors diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C index ba0dd92f091745d82449017571c14e3612e2dc77..74898ee00fbbc45d13ac3b0609a2e1921616f98f 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -159,13 +159,6 @@ Foam::tmp<Foam::Field<Type>> Foam::slicedFvPatchField<Type>::snGrad() const } -template<class Type> -void Foam::slicedFvPatchField<Type>::updateCoeffs() -{ - NotImplemented; -} - - template<class Type> Foam::tmp<Foam::Field<Type>> Foam::slicedFvPatchField<Type>::patchInternalField() const diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H index 75fe58719720c02f0039ea293314fb266d6713e0..5b29aa77b57a5cfa40c06bba59eba7300a123fa2 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -153,10 +153,6 @@ public: //- Return patch-normal gradient virtual tmp<Field<Type>> snGrad() const; - //- Update the coefficients associated with the patch field - // Sets Updated to true - virtual void updateCoeffs(); - //- Return internal field next to patch as patch field virtual tmp<Field<Type>> patchInternalField() const; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C index 24714aaf46ee9ca605ca68aa7e77675013500cdd..e22d979213da147e8dcc874cf3ce2182d4003394 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C @@ -64,7 +64,7 @@ Foam::fanFvPatchField<Type>::fanFvPatchField uniformJumpFvPatchField<Type>(p, iF, dict), phiName_(dict.lookupOrDefault<word>("phi", "phi")), rhoName_(dict.lookupOrDefault<word>("rho", "rho")), - uniformJump_(dict.lookupOrDefault<bool>("uniformJump", "false")) + uniformJump_(dict.lookupOrDefault<bool>("uniformJump", false)) {} diff --git a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C index 48504de23d74eb317d493b6ae58719f18b6b07ee..8ae33b507f48aa30796f6932e9f8f19dfff7ae37 100644 --- a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C +++ b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C @@ -42,24 +42,6 @@ namespace Foam dictionary ); } - - //- Plus op for FixedList<scalar> - template<class T, unsigned Size> - class ListPlusEqOp - { - public: - void operator() - ( - FixedList<T, Size>& x, - const FixedList<T, Size>& y - ) const - { - forAll(x, i) - { - x[i] += y[i]; - } - } - }; } diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.C b/src/functionObjects/solvers/scalarTransport/scalarTransport.C index 641241b91e6cbb2a7e6fd8c64bf966aa0e53eb28..ebee2bc436ae70c55327903028a4a9495a625929 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.C +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.C @@ -277,13 +277,13 @@ bool Foam::functionObjects::scalarTransport::execute() const volScalarField& alpha = mesh_.lookupObject<volScalarField>(phaseName_); - const surfaceScalarField& limitedPhiAlpa = + const surfaceScalarField& limitedPhiAlpha = mesh_.lookupObject<surfaceScalarField>(phasePhiCompressedName_); D *= pos(alpha - 0.99); - // Reset D dimensions consistent with limitedPhiAlpa - D.dimensions().reset(limitedPhiAlpa.dimensions()/dimLength); + // Reset D dimensions consistent with limitedPhiAlpha + D.dimensions().reset(limitedPhiAlpha.dimensions()/dimLength); // Solve tmp<surfaceScalarField> tTPhiUD; @@ -292,7 +292,7 @@ bool Foam::functionObjects::scalarTransport::execute() fvScalarMatrix sEqn ( fvm::ddt(s) - + fvm::div(limitedPhiAlpa, s, divScheme) + + fvm::div(limitedPhiAlpha, s, divScheme) - fvm::laplacian(D, s, laplacianScheme) == alpha*fvOptions_(s) diff --git a/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.C b/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.C index 273e91e5dec469d46476ad7c2bf50b81eca71ad1..d628d09563df40f00612cf0d83562d0a97990713 100644 --- a/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.C +++ b/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,7 @@ License #include "HashSet.H" #include "surfaceInterpolate.H" #include "zeroGradientFvPatchFields.H" +#include "wallDist.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -68,42 +69,18 @@ Foam::inverseDistanceDiffusivity::~inverseDistanceDiffusivity() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::tmp<Foam::scalarField> Foam::inverseDistanceDiffusivity::y() const -{ - labelHashSet patchSet(mesh().boundaryMesh().patchSet(patchNames_)); - - if (patchSet.size()) - { - return tmp<scalarField> - ( - new scalarField(patchWave(mesh(), patchSet, false).distance()) - ); - } - else - { - return tmp<scalarField>(new scalarField(mesh().nCells(), 1.0)); - } -} - - void Foam::inverseDistanceDiffusivity::correct() { - volScalarField y_ - ( - IOobject + faceDiffusivity_ = + 1.0 + /fvc::interpolate ( - "y", - mesh().time().timeName(), - mesh() - ), - mesh(), - dimless, - zeroGradientFvPatchScalarField::typeName - ); - y_.primitiveFieldRef() = y(); - y_.correctBoundaryConditions(); - - faceDiffusivity_ = 1.0/fvc::interpolate(y_); + wallDist::New + ( + mesh(), + mesh().boundaryMesh().patchSet(patchNames_) + ).y() + ); } diff --git a/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.H b/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.H index e5f6f3c9a56003b64d5b5efaa74ee752bf68be8e..05e5439479a1bf5bf98a9190cde70ca62f86d14d 100644 --- a/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.H +++ b/src/fvMotionSolver/motionDiffusivity/inverseDistance/inverseDistanceDiffusivity.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,8 +60,6 @@ class inverseDistanceDiffusivity // Private Member Functions - //- Return patch-cell-centre distance field - tmp<scalarField> y() const; //- Disallow default bitwise copy construct inverseDistanceDiffusivity(const inverseDistanceDiffusivity&); diff --git a/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C b/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C index f57e7d2aac540d6451eb3c92b0c3fc3b6fa639ac..c459252e1cd1f3ae8d2a8004f48147b2e84233d3 100644 --- a/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C +++ b/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C @@ -207,13 +207,11 @@ License #include "globalIndex.H" #include "SubField.H" -extern "C" -{ - #include <stdio.h> - #include <mpi.h> - #include "ptscotch.h" -} +#pragma GCC diagnostic ignored "-Wold-style-cast" +#include <cstdio> +#include <mpi.h> +#include "ptscotch.h" // Hack: scotch generates floating point errors so need to switch of error // trapping! diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C index b711a55bac82a9c5ccc60e3b361aa141ecf0260e..88b245b62c4773cef598789803d9f1265750297c 100644 --- a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C @@ -70,7 +70,7 @@ void pointNoise::processData(const Function1Types::CSV<scalar>& data) { Info<< "Reading data file " << data.fName() << endl; - const fileName fNameBase = data.fName().name(true); + const word fNameBase = data.fName().nameLessExt(); // Time and pressure history data scalarField t, p; diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index faed14eea6d9cb10253b93b666237274a2446954..051f016969b456a30aacf80c15e9b4e436ad4206 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -572,7 +572,7 @@ void surfaceNoise::calculate() } } - const word& fNameBase = fName.name(true); + const word fNameBase = fName.nameLessExt(); // Output directory for graphs fileName outDir diff --git a/src/renumber/zoltanRenumber/zoltanRenumber.C b/src/renumber/zoltanRenumber/zoltanRenumber.C index da7a2957b535fc198f3600ba8330bdca0328cf0a..2d7a744debb90f875dceacfdd5e4f6f5fabeb066 100644 --- a/src/renumber/zoltanRenumber/zoltanRenumber.C +++ b/src/renumber/zoltanRenumber/zoltanRenumber.C @@ -57,6 +57,7 @@ SourceFiles #include "globalIndex.H" #include "uint.H" +#pragma GCC diagnostic ignored "-Wold-style-cast" #include "zoltan.h" #include <mpi.h> diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 04274c775a65bdf23581c7434914d0a3ebeb60f6..395e2bacb73f18c19564946eb17cda5bbf9eb625 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -237,7 +237,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl - << "o " << os.name().lessExt().name() << nl + << "o " << os.name().nameLessExt() << nl << nl << "# points : " << pointLst.size() << nl << "# faces : " << faceLst.size() << nl diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C index 8200a5b58be44a9e66b7d1c07e0dcf00bbf1fac6..1894f293af4f2e887425125f7df3d5b4568ec9f2 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C @@ -87,7 +87,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase const UList<surfZone>& zoneLst ) { - word caseName = os.name().lessExt().name(); + const word caseName = os.name().nameLessExt(); os << "! STAR-CD file written " << clock::dateTime().c_str() << nl << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C index b522df0e561f703e95a67712f92a8e775cdbe1e7..4480ea67dde74bab43dff9131d141fc33abf220e 100644 --- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C +++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C @@ -64,12 +64,9 @@ void Foam::faceShading::writeRays } str.flush(); - DynamicList<string> cmd(3); - cmd.append("objToVTK"); - cmd.append(fName); - cmd.append(fName.lessExt() + ".vtk"); - Pout<< "cmd: objToVTK " << fName.c_str() << endl; + + stringList cmd{"objToVTK", fName, fName.lessExt().ext("vtk")}; Foam::system(cmd); } diff --git a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C index d887867658482fd608c4b63ded7f47791ec48f1e..dea53edd9195d98168676ae6492853348a212918 100644 --- a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C +++ b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C @@ -206,6 +206,12 @@ void Foam::solarCalculator::init() } case mSunLoadFairWeatherConditions: { + dict_.readIfPresent + ( + "skyCloudCoverFraction", + skyCloudCoverFraction_ + ); + A_ = readScalar(dict_.lookup("A")); B_ = readScalar(dict_.lookup("B")); @@ -218,7 +224,9 @@ void Foam::solarCalculator::init() calculateBetaTetha(); } - directSolarRad_ = A_/exp(B_/sin(beta_)); + directSolarRad_ = + (1.0 - 0.75*pow(skyCloudCoverFraction_, 3.0)) + * A_/exp(B_/sin(beta_)); groundReflectivity_ = readScalar(dict_.lookup("groundReflectivity")); @@ -257,6 +265,7 @@ Foam::solarCalculator::solarCalculator B_(0.0), beta_(0.0), tetha_(0.0), + skyCloudCoverFraction_(0.0), Setrn_(0.0), SunPrime_(0.0), C_(readScalar(dict.lookup("C"))), diff --git a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.H b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.H index 6d3b13c12ba2641ef3d35e17f5a16c8cb0e4a4c8..9eeb5bfc4db695f0a463b17d8bc68c8797ed6f5a 100644 --- a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.H +++ b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,6 +52,7 @@ Description 2) SunLoadFairWeatherConditions: The solar fluxes are calculated following the Fair Weather Conditions Method from the ASHRAE Handbook. The entries are: + skyCloudCoverFraction: Fraction of sky covered by clouds (0-1) A : Apparent solar irradiation at air mass m = 0 B : Atmospheric extinction coefficient beta: Solar altitude (in degrees) above the horizontal. This @@ -61,7 +62,8 @@ Description In this model the flux is calculated as: - directSolarRad = A/exp(B/sin(beta)); + directSolarRad = + (1 - 0.75*skyCloudCoverFraction^3)*A/exp(B/sin(beta)); 3) SunLoadTheoreticalMaximum: The entries are: Setrn @@ -158,6 +160,9 @@ private: scalar beta_; scalar tetha_; + //- Sky cloud cover fraction [0-1] + scalar skyCloudCoverFraction_; + //- Maximum theoretical direct solar load model parameters scalar Setrn_; diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index 2ea0e6eea8559c835c8ad3cdb512d95c1e5d8319..d1ff1919c58515a85e360f933aa521c0fb7b4191 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -32,6 +32,7 @@ License #include "SortableList.H" #include "PackedBoolList.H" #include "surfZoneList.H" +#include "surfaceFormatsCore.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -41,6 +42,69 @@ namespace Foam } +// Note that these lists are a stop-gap measure until the read/write handling +// gets properly updated +const Foam::wordHashSet Foam::triSurface::readTypes_ +{ + "ftr", "stl", "stlb", "gts", "obj", "off", "tri", "ac", "nas", "vtk" +}; + + +const Foam::wordHashSet Foam::triSurface::writeTypes_ +{ + "ftr", "stl", "stlb", "gts", "obj", "off", "tri", "ac", "smesh", "vtk" +}; + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +bool Foam::triSurface::canReadType(const word& ext, const bool verbose) +{ + return fileFormats::surfaceFormatsCore::checkSupport + ( + readTypes(), + ext, + verbose, + "reading" + ); +} + + +bool Foam::triSurface::canWriteType(const word& ext, const bool verbose) +{ + return fileFormats::surfaceFormatsCore::checkSupport + ( + writeTypes(), + ext, + verbose, + "writing" + ); +} + + +bool Foam::triSurface::canRead(const fileName& name, const bool verbose) +{ + word ext = name.ext(); + if (ext == "gz") + { + ext = name.lessExt().ext(); + } + return canReadType(ext, verbose); +} + + +const Foam::wordHashSet& Foam::triSurface::readTypes() +{ + return readTypes_; +} + + +const Foam::wordHashSet& Foam::triSurface::writeTypes() +{ + return writeTypes_; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::fileName Foam::triSurface::triSurfInstance(const Time& d) @@ -854,6 +918,16 @@ void Foam::triSurface::triFaceFaces(List<face>& plainFaces) const } +Foam::Xfer<Foam::List<Foam::labelledTri>> +Foam::triSurface::xferFaces() +{ + // Topology changed because of transfer + clearOut(); + + return this->storedFaces().xfer(); +} + + Foam::Xfer<Foam::List<Foam::point>> Foam::triSurface::xferPoints() { diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index e320bbfdfdcab97bb3ea82041f59b4f7cdd6ea52..fa10f875578efc18023617b69c2278845ee8c10d 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -90,6 +90,9 @@ class triSurface // during reading and writing) geometricSurfacePatchList patches_; + static const wordHashSet readTypes_; + static const wordHashSet writeTypes_; + // Demand driven private data. @@ -240,6 +243,18 @@ public: //- Name of triSurface directory to use. static fileName triSurfInstance(const Time&); + //- Can we read this file format? + static bool canRead(const fileName& name, const bool verbose=false); + + //- Can we read this file format? + static bool canReadType(const word& ext, const bool verbose=false); + + //- Can we write this file format? + static bool canWriteType(const word& ext, const bool verbose=false); + + static const wordHashSet& readTypes(); + static const wordHashSet& writeTypes(); + // Constructors @@ -416,6 +431,9 @@ public: ) const; + //- Transfer stored faces to an Xfer container + Xfer<List<labelledTri>> xferFaces(); + //- Transfer stored points to an Xfer container Xfer<List<point>> xferPoints(); diff --git a/tutorials/combustion/fireFoam/LES/simplePMMApanel/constant/boundaryRadiationProperties b/tutorials/combustion/fireFoam/LES/simplePMMApanel/constant/boundaryRadiationProperties index 20a028ae6676de7a583a1dbbb6b08b886a68e9c1..36db108b2d49fe14f474bd40c9a4cdcb7759f782 100644 --- a/tutorials/combustion/fireFoam/LES/simplePMMApanel/constant/boundaryRadiationProperties +++ b/tutorials/combustion/fireFoam/LES/simplePMMApanel/constant/boundaryRadiationProperties @@ -9,25 +9,16 @@ FoamFile { version 2.0; format ascii; - class volScalarField; + class dictionary; + location "constant"; object boundaryRadiationProperties; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -dimensions [0 0 0 0 0 0 0]; - -internalField uniform 0; - -boundaryField +".*" { - ".*" - { - type boundaryRadiation; - mode lookup; - emissivity uniform 1.0; - absorptivity uniform 0.0; - value uniform 0.0; - } + mode lookup; + emissivity 1.0; } // ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/Allrun.pre b/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/Allrun.pre index a7367af14af6584018741d8bb9216cd1cbd15e35..37a630197599f4e696c7b42ec2acf6e8625d9ead 100755 --- a/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/Allrun.pre +++ b/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/Allrun.pre @@ -21,7 +21,7 @@ done for i in air solid floor do - changeDictionary -region $i > log.changeDictionary.$i 2>&1 + runApplication -s $i changeDictionary -region $i -subDict dictionaryReplacement done # ----------------------------------------------------------------------------- diff --git a/tutorials/multiphase/interDyMFoam/RAS/motorBike/constant/dynamicMeshDict b/tutorials/multiphase/interDyMFoam/RAS/motorBike/constant/dynamicMeshDict index 444d6103916323d34cf9a3d27d143847a3bc2b37..e8ee89cf0e1d355ee63a82335a377d7433dcba75 100644 --- a/tutorials/multiphase/interDyMFoam/RAS/motorBike/constant/dynamicMeshDict +++ b/tutorials/multiphase/interDyMFoam/RAS/motorBike/constant/dynamicMeshDict @@ -29,7 +29,7 @@ dynamicRefineFvMeshCoeffs // Have slower than 2:1 refinement nBufferLayers 1; // Refine cells only up to maxRefinement levels - maxRefinement 3; + maxRefinement 4; // Stop refinement if maxCells reached maxCells 2000000; // Flux field and corresponding velocity field. Fluxes on changed diff --git a/tutorials/multiphase/interDyMFoam/RAS/motorBike/system/snappyHexMeshDict b/tutorials/multiphase/interDyMFoam/RAS/motorBike/system/snappyHexMeshDict index 3dac7f631f3f67f995691add79bceb4d8bd5dcfd..b7ce19ef33b579e3ddeaab051d7a5f1718d6e3e3 100644 --- a/tutorials/multiphase/interDyMFoam/RAS/motorBike/system/snappyHexMeshDict +++ b/tutorials/multiphase/interDyMFoam/RAS/motorBike/system/snappyHexMeshDict @@ -38,7 +38,7 @@ geometry //// Optional: avoid patch-face merging. Allows mesh to be used for //// refinement/unrefinement -//mergePatchFaces off; // default on +mergePatchFaces on; // default on diff --git a/tutorials/preProcessing/createZeroDirectory/snappyMultiRegionHeater/Allrun b/tutorials/preProcessing/createZeroDirectory/snappyMultiRegionHeater/Allrun index cd9d35d580f72613f6a84dbe5a30bc4d1bd4f1ce..6b946fe298eec30d120a49638c81621b3a281087 100755 --- a/tutorials/preProcessing/createZeroDirectory/snappyMultiRegionHeater/Allrun +++ b/tutorials/preProcessing/createZeroDirectory/snappyMultiRegionHeater/Allrun @@ -15,8 +15,7 @@ runApplication splitMeshRegions -cellZones -overwrite for i in bottomAir topAir heater leftSolid rightSolid do - runApplication changeDictionary -region $i - mv log.changeDictionary log.changeDictionary.$i 2>&1 + runApplication -s $i changeDictionary -region $i -subDict dictionaryReplacement done runApplication decomposePar -allRegions diff --git a/wmake/rules/linux64Clang/c++ b/wmake/rules/linux64Clang/c++ index 1b5156617971b8312a5fb1bc608fe6fdcd7d856a..014eff3461fae216b0201f0cb3016f3154a7fa22 100644 --- a/wmake/rules/linux64Clang/c++ +++ b/wmake/rules/linux64Clang/c++ @@ -1,6 +1,6 @@ SUFFIXES += .C -c++WARN = -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-c++11-extensions +c++WARN = -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-undefined-var-template # Suppress some warnings for flex++ and CGAL c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-tautological-undefined-compare -Wno-shift-negative-value diff --git a/wmake/rules/linuxClang/c++ b/wmake/rules/linuxClang/c++ index b2001baf2e492dd45521de43ae2598080509b59e..746cdb13bb6ae08d8b12f9b88893469935ca7779 100644 --- a/wmake/rules/linuxClang/c++ +++ b/wmake/rules/linuxClang/c++ @@ -1,9 +1,9 @@ SUFFIXES += .C -c++WARN = -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-c++11-extensions +c++WARN = -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-undefined-var-template # Suppress some warnings for flex++ and CGAL -c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedef -Wno-tautological-undefined-compare -Wno-shift-negative-value +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-tautological-undefined-compare -Wno-shift-negative-value CC = clang++ -std=c++11 -m32 diff --git a/wmake/src/Makefile b/wmake/src/Makefile index 9ced8251c991ca5e467e8d9761200126966e2f24..cc679c9482addfa2e413a35d9c4948190d8d9ef4 100644 --- a/wmake/src/Makefile +++ b/wmake/src/Makefile @@ -1,4 +1,4 @@ -#------------------------------------------------------------------------------ +#----------------------------*- makefile-gmake -*------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | @@ -57,22 +57,26 @@ include $(GENERAL_RULES)/general # Targets #------------------------------------------------------------------------------ +.PHONY: all clean + all: $(WMAKE_BIN)/dirToString $(WMAKE_BIN)/wmkdep + @echo built wmake-bin for $(WM_ARCH)$(WM_COMPILER) clean: - @E rm -f $(WMAKE_BIN)/* 2>/dev/null + @echo clean wmake-bin for $(WM_ARCH)$(WM_COMPILER) + @rm -rf $(WMAKE_BIN) 2>/dev/null + @rmdir $(shell dirname $(WMAKE_BIN)) 2>/dev/null || true $(WMAKE_BIN)/dirToString: dirToString.c @mkdir -p $(WMAKE_BIN) - $(call QUIET_MESSAGE,compile,$<) - $E $(cc) $(cFLAGS) dirToString.c -o $(WMAKE_BIN)/dirToString + $(call QUIET_MESSAGE,compile,$(<F)) + $E $(cc) $(cFLAGS) $(<F) -o $@ $(WMAKE_BIN)/wmkdep: wmkdep.l @mkdir -p $(WMAKE_BIN) - $(call QUIET_MESSAGE,lex,$<) - $E flex wmkdep.l; \ - $(cc) $(cFLAGS) lex.yy.c -o $(WMAKE_BIN)/wmkdep - @rm -f lex.yy.c 2>/dev/null + $(call QUIET_MESSAGE,flex,$(<F)) + $E flex -o $@.c $(<F) && $(cc) $(cFLAGS) $@.c -o $@ + @rm -f $@.c 2>/dev/null #------------------------------------------------------------------------------ diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l index 4b0aeaa85a6180c4050245a69174f440cbd51433..6e198bab4c2c7cc99c3015fe932a6127386c1a1f 100644 --- a/wmake/src/wmkdep.l +++ b/wmake/src/wmkdep.l @@ -42,18 +42,22 @@ Usage #define FILE_STACK_SIZE 300 #define HASH_TABLE_SIZE 500 +#include <errno.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> -#include <sys/types.h> -#include <dirent.h> -#include <errno.h> - -void nextFile(const char* fileName); -void importFile(const char* fileName); -void importDir(const char* dirName); +#include <sys/types.h> /* POSIX */ +#include <dirent.h> /* POSIX */ +/* The executable name (for messages), without requiring access to argv[] */ +#define EXENAME "wmkdep" #undef yywrap /* sometimes a macro by default */ +#define YY_NO_INPUT /* no input(), yyinput() required */ +#pragma GCC diagnostic ignored "-Wunused-function" + +void nextFile(const char* fileName); +/*---------------------------------------------------------------------------*/ %} %x CMNT CFNAME SCFNAME JFNAME FFNAME @@ -75,6 +79,8 @@ void importDir(const char* dirName); %% +/*---------------------------------------------------------------------------*/ + /* char* entry in hash table */ struct HashEntry @@ -145,28 +151,23 @@ const char* bufferPaths[FILE_STACK_SIZE]; int main(int argc, char* argv[]) { char *basePos, *dotPos; - int i, silent; + int i; if (argc < 2) { - fprintf(stderr, "input file not supplied\n"); + fputs(EXENAME ": input file not supplied\n", stderr); return 1; } else if (!strncmp(argv[1], "-h", 2)) /* -h, -help */ { - fprintf - ( - stderr, - "\nUsage: %s [-Idir ... -Idir] [-iheader .. -iheader] filename\n\n", - "wmkdep" - ); - - fprintf + fputs ( - stderr, + "\nUsage: " EXENAME + " [-Idir ... -Idir] [-iheader .. -iheader] filename\n\n" " -Idir Directories to be searched for headers.\n" " -iheader Headers to be ignored.\n\n" - "Dependency list generator, similar to 'cpp -M'\n\n" + "Dependency list generator, similar to 'cpp -M'\n\n", + stderr ); return 0; @@ -192,7 +193,7 @@ int main(int argc, char* argv[]) fprintf ( stderr, - "cannot find extension in source file name %s\n", + EXENAME ": cannot find extension in source file name '%s'\n", sourceFile ); return 1; @@ -306,8 +307,8 @@ void nextFile(const char* fileName) fprintf ( stderr, - "depth of file search exceeds stack size %d " - "while opening %s for file %s\n", + EXENAME ": depth of file search exceeds stack size %d " + "while opening '%s' for file '%s'\n", FILE_STACK_SIZE, fileName, sourceFile ); exit(1); @@ -341,7 +342,7 @@ void nextFile(const char* fileName) if (!(newyyin = fopen(fileName, "r"))) { int d; - for (d=0; d<nDirectories; d++) + for (d=0; d<nDirectories; ++d) { char* pathName = addDirectoryName(directories[d], fileName); @@ -362,24 +363,17 @@ void nextFile(const char* fileName) free(pathName); } - if (nDirectories == 0) - { - fprintf - ( - stderr, - "could not open file %s for source file %s\n", - fileName, sourceFile - ); - } - else + fprintf + ( + stderr, + EXENAME ": could not open file '%s' for source file '%s'", + fileName, sourceFile + ); + if (nDirectories) { - fprintf - ( - stderr, - "could not open file %s for source file %s due to %s\n", - fileName, sourceFile, strerror(errno) - ); + fprintf(stderr, ": %s", strerror(errno)); } + fputs("\n", stderr); fflush(stdout); fflush(stderr); @@ -405,10 +399,10 @@ void nextFile(const char* fileName) */ void dotToSlash(char* fileName) { - int i, len; - len = strlen(fileName); + const size_t len = strlen(fileName); + size_t i; - for (i=0; i<len; i++) + for (i=0; i<len; ++i) { if (fileName[i] == '.') fileName[i] = '/'; }