diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H index 79f3ab3127..0a6680c93b 100644 --- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H +++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,6 +30,7 @@ InClass #define vtkOpenFOAMTupleRemap_H // OpenFOAM includes +#include "StaticAssert.H" #include "Swap.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -38,6 +39,17 @@ template inline void vtkOpenFOAMTupleRemap(float vec[]); +// a symmTensor specialization to remap OpenFOAM -> ParaView naming order +// Qt/Core/pqScalarBarRepresentation.cxx defines this order +// { "XX", "YY", "ZZ", "XY", "YZ", "XZ" } +// in pqScalarBarRepresentation::getDefaultComponentLabel() +// whereas OpenFOAM uses this order +// { XX, XY, XZ, YY, YZ, ZZ } +// +// for extra safety, assert that symmTensor indeed has 6 components +StaticAssert(Foam::symmTensor::nComponents == 6); + + // Template specialization for symmTensor template<> inline void vtkOpenFOAMTupleRemap(float vec[]) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H index d18bc79b33..610eac4f34 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H @@ -30,6 +30,7 @@ InClass #define vtkOpenFOAMTupleRemap_H // OpenFOAM includes +#include "StaticAssert.H" #include "Swap.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -38,6 +39,17 @@ template inline void vtkOpenFOAMTupleRemap(float vec[]); +// a symmTensor specialization to remap OpenFOAM -> ParaView naming order +// Qt/Core/pqScalarBarRepresentation.cxx defines this order +// { "XX", "YY", "ZZ", "XY", "YZ", "XZ" } +// in pqScalarBarRepresentation::getDefaultComponentLabel() +// whereas OpenFOAM uses this order +// { XX, XY, XZ, YY, YZ, ZZ } +// +// for extra safety, assert that symmTensor indeed has 6 components +StaticAssert(Foam::symmTensor::nComponents == 6); + + // Template specialization for symmTensor template<> inline void vtkOpenFOAMTupleRemap(float vec[]) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 913e726f41..f62ba3a41a 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -44,7 +44,7 @@ SourceFiles #define DynamicList_H #include "List.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -79,11 +79,8 @@ class DynamicList : public List { - static_assert - ( - (SizeInc || SizeMult) && SizeDiv, - "Invalid sizing parameters" - ); + //- Avoid invalid sizing parameters + StaticAssert((SizeInc || SizeMult) && SizeDiv); // Private data diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 43d97eead2..c7974940c5 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -42,7 +42,7 @@ SourceFiles #include "uLabel.H" #include "Hash.H" #include "autoPtr.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -70,11 +70,8 @@ template class SLList; template class FixedList { - static_assert - ( - Size && Size <= INT_MAX, - "Size must be positive (non-zero) and also fit as a signed value" - ); + //- Size must be positive (non-zero) and also fit as a signed value + StaticAssert(Size && Size <= INT_MAX); // Private data diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 8af97000ff..078a4dde9f 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -103,7 +103,7 @@ SourceFiles #include "labelList.H" #include "UIndirectList.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -174,11 +174,7 @@ private: // it is more efficient to use a normal list. // Thus max nBits is 1/2 of the base storage size. // For simplicity, assume 8-bit bytes in the assert. - static_assert - ( - nBits && nBits <= (sizeof(StorageType) << 2), - "nBits must be positive (non-zero) and fit within the storage" - ); + StaticAssert(nBits && nBits <= (sizeof(StorageType) << 2)); // Private data diff --git a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H index 32cb603022..f4af06792c 100644 --- a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H +++ b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H @@ -36,9 +36,9 @@ SourceFiles #define NamedEnum_H #include "HashTable.H" +#include "StaticAssert.H" #include "stringList.H" #include "wordList.H" -#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -55,7 +55,7 @@ class NamedEnum public HashTable { //- nEnum must be positive (non-zero) - static_assert(nEnum > 0, "nEnum must be positive (non-zero)"); + StaticAssert(nEnum > 0); // Private Member Functions diff --git a/src/OpenFOAM/db/error/StaticAssert.H b/src/OpenFOAM/db/error/StaticAssert.H new file mode 100644 index 0000000000..58fa86c170 --- /dev/null +++ b/src/OpenFOAM/db/error/StaticAssert.H @@ -0,0 +1,87 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::StaticAssertionFailed + +Description + Macros and classes to provide static (compile-time) assertions. + + Ideas from various sources + (http://www.ddj.com/cpp/184401547, http://www.boost.org) + +\*---------------------------------------------------------------------------*/ + +#ifndef StaticAssert_H +#define StaticAssert_H + +namespace Foam +{ + +//- Forward declaration of StaticAssertionFailed. +// Leave as an incomplete class so that sizeof(..) fails +template class StaticAssertionFailed; + +/*---------------------------------------------------------------------------*\ + Class StaticAssertionFailed Declaration +\*---------------------------------------------------------------------------*/ + +//- Specialization for successful assertions +template<> +class StaticAssertionFailed +{}; + + +//- Helper class for handling static assertions +template +class StaticAssertionTest {}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Paste together strings, even if an argument is itself a macro +#define StaticAssertMacro(X,Y) StaticAssertMacro1(X,Y) +#define StaticAssertMacro1(X,Y) StaticAssertMacro2(X,Y) +#define StaticAssertMacro2(X,Y) X##Y + +#ifdef __GNUC__ + #define StaticAssertUnusedTypedef __attribute__((unused)) +#else + #define StaticAssertUnusedTypedef +#endif + +//- Assert that some test is true at compile-time +#define StaticAssert(Test) \ + typedef ::Foam::StaticAssertionTest \ + < \ + sizeof( ::Foam::StaticAssertionFailed<((Test) ? true : false)>) \ + > StaticAssertMacro(StaticAssertionTest, __LINE__) StaticAssertUnusedTypedef + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H index e575ddf282..60cff25b94 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H @@ -37,7 +37,7 @@ SourceFiles #define DynamicField_H #include "Field.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -73,11 +73,8 @@ class DynamicField : public Field { - static_assert - ( - (SizeInc || SizeMult) && SizeDiv, - "Avoid invalid sizing parameters" - ); + //- Avoid invalid sizing parameters + StaticAssert((SizeInc || SizeMult) && SizeDiv); // Private data diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H index 207162b2c5..ff636aa933 100644 --- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H +++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -90,16 +90,8 @@ ConstBlock(const msType& matrix) : matrix_(matrix) { - static_assert - ( - msType::mRows >= BRowStart + mRows, - "Rows in block > rows in matrix" - ); - static_assert - ( - msType::nCols >= BColStart + nCols, - "Columns in block > columns in matrix" - ); + StaticAssert(msType::mRows >= BRowStart + mRows); + StaticAssert(msType::nCols >= BColStart + nCols); } @@ -111,16 +103,8 @@ Block(msType& matrix) : matrix_(matrix) { - static_assert - ( - msType::mRows >= BRowStart + mRows, - "Rows in block > rows in matrix" - ); - static_assert - ( - msType::nCols >= BColStart + nCols, - "Columns in block > columns in matrix" - ); + StaticAssert(msType::mRows >= BRowStart + mRows); + StaticAssert(msType::nCols >= BColStart + nCols); } @@ -130,7 +114,7 @@ template template inline const Cmpt& Foam::MatrixSpace::elmt() const { - static_assert(Row < Mrows && Col < Ncols, "Address outside matrix"); + StaticAssert(Row < Mrows && Col < Ncols); return this->v_[Row*Ncols + Col]; } @@ -139,7 +123,7 @@ template template inline Cmpt& Foam::MatrixSpace::elmt() { - static_assert(Row < Mrows && Col < Ncols, "Address outside matrix"); + StaticAssert(Row < Mrows && Col < Ncols); return this->v_[Row*Ncols + Col]; } @@ -272,7 +256,7 @@ template inline Foam::MatrixSpace Foam::MatrixSpace::identity() { - static_assert(Mrows == Ncols, "Matrix is not square"); + StaticAssert(Mrows == Ncols); msType result(Zero); for (direction i=0; i& v ) { - static_assert(nCols == 1, "Matrix must have a single column"); + StaticAssert(nCols == 1); for (direction i=0; i::type operator& const MatrixSpace& matrix2 ) { - static_assert - ( - Ncols1 == Mrows2, - "Number of columns in matrix 1 != number of rows in matrix 2" - ); + StaticAssert(Ncols1 == Mrows2); typename typeOfInnerProduct::type result(Zero); diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H index f90adbb0ff..3b545a43e6 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H @@ -27,7 +27,7 @@ License #include "products.H" #include "VectorSpaceOps.H" #include "ops.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -79,11 +79,7 @@ VectorSpace::ConstBlock::ConstBlock : vs_(vs) { - static_assert - ( - vsType::nComponents >= BStart + nComponents, - "Requested block size > VectorSpace size" - ); + StaticAssert(vsType::nComponents >= BStart + nComponents); } diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H index 2d8f11d3af..b6f20330d8 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H @@ -52,7 +52,7 @@ SourceFiles #include "scalar.H" #include "Ostream.H" #include "VectorSpace.H" -#include +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -81,7 +81,8 @@ class Polynomial : public VectorSpace, scalar, PolySize> { - static_assert(PolySize > 0, "Size must be positive (non-zero)"); + //- Size must be positive (non-zero) + StaticAssert(PolySize > 0); // Private data diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index 75464c4013..24a3e5b599 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -46,4 +46,7 @@ surfaceInterpolateFields/surfaceInterpolateFieldsFunctionObject.C regionSizeDistribution/regionSizeDistribution.C regionSizeDistribution/regionSizeDistributionFunctionObject.C +histogram/histogram.C +histogram/histogramFunctionObject.C + LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects