fieldTypes: Using C++11 __VA_ARGS__ functionality created the FOR_ALL_FIELD_TYPES macro

This supports the abstraction of the set of fields from the field code
generation macros making it easier to change the set of fields supported
by OpenFOAM.  This functionality is demonstrated in the updated
fvPatchFields macros and will be applied to the rest of the field code
generation macros in the future.
This commit is contained in:
Henry Weller 2016-10-03 09:08:01 +01:00
parent 298003f333
commit cc4c2989c3
12 changed files with 129 additions and 94 deletions

View file

@ -31,8 +31,7 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Add to hash-table of functions with typename as the key
// add to hash-table of functions with typename as the key
#define addToRunTimeSelectionTable\ #define addToRunTimeSelectionTable\
(baseType,thisType,argNames) \ (baseType,thisType,argNames) \
\ \
@ -41,7 +40,7 @@ Description
add##thisType##argNames##ConstructorTo##baseType##Table_ add##thisType##argNames##ConstructorTo##baseType##Table_
// add to hash-table of functions with 'lookup' as the key //- Add to hash-table of functions with 'lookup' as the key
#define addNamedToRunTimeSelectionTable\ #define addNamedToRunTimeSelectionTable\
(baseType,thisType,argNames,lookup) \ (baseType,thisType,argNames,lookup) \
\ \
@ -51,7 +50,7 @@ Description
(#lookup) (#lookup)
// add to hash-table of functions with typename as the key //- Add to hash-table of functions with typename as the key
#define addRemovableToRunTimeSelectionTable\ #define addRemovableToRunTimeSelectionTable\
(baseType,thisType,argNames) \ (baseType,thisType,argNames) \
\ \
@ -60,7 +59,7 @@ Description
addRemovable##thisType##argNames##ConstructorTo##baseType##Table_ addRemovable##thisType##argNames##ConstructorTo##baseType##Table_
// add to hash-table of functions with 'lookup' as the key //- Add to hash-table of functions with 'lookup' as the key
#define addRemovableNamedToRunTimeSelectionTable\ #define addRemovableNamedToRunTimeSelectionTable\
(baseType,thisType,argNames,lookup) \ (baseType,thisType,argNames,lookup) \
\ \
@ -72,9 +71,8 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Add to hash-table of functions with typename as the key.
// add to hash-table of functions with typename as the key // Use when baseType doesn't need a template argument (eg, is a typedef)
// use when baseType doesn't need a template argument (eg, is a typedef)
#define addTemplateToRunTimeSelectionTable\ #define addTemplateToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames) \ (baseType,thisType,Targ,argNames) \
\ \
@ -83,8 +81,8 @@ Description
add##thisType##Targ##argNames##ConstructorTo##baseType##Table_ add##thisType##Targ##argNames##ConstructorTo##baseType##Table_
// add to hash-table of functions with 'lookup' as the key //- Add to hash-table of functions with 'lookup' as the key.
// use when baseType doesn't need a template argument (eg, is a typedef) // Use when baseType doesn't need a template argument (eg, is a typedef)
#define addNamedTemplateToRunTimeSelectionTable\ #define addNamedTemplateToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames,lookup) \ (baseType,thisType,Targ,argNames,lookup) \
\ \
@ -96,9 +94,8 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Add to hash-table of functions with typename as the key.
// add to hash-table of functions with typename as the key // Use when baseType requires the Targ template argument as well
// use when baseType requires the Targ template argument as well
#define addTemplatedToRunTimeSelectionTable\ #define addTemplatedToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames) \ (baseType,thisType,Targ,argNames) \
\ \
@ -107,8 +104,8 @@ Description
add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_ add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_
// add to hash-table of functions with 'lookup' as the key //- Add to hash-table of functions with 'lookup' as the key.
// use when baseType requires the Targ template argument as well // Use when baseType requires the Targ template argument as well
#define addNamedTemplatedToRunTimeSelectionTable\ #define addNamedTemplatedToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames,lookup) \ (baseType,thisType,Targ,argNames,lookup) \
\ \

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -37,6 +37,22 @@ Description
#include "symmTensor.H" #include "symmTensor.H"
#include "tensor.H" #include "tensor.H"
#include "triad.H" #include "triad.H"
#include "macros.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define CAPITALIZE_scalar Scalar
#define CAPITALIZE_vector Vector
#define CAPITALIZE_sphericalTensor SphericalTensor
#define CAPITALIZE_symmTensor SymmTensor
#define CAPITALIZE_tensor Tensor
#define FOR_ALL_FIELD_TYPES(Macro, ...) \
Macro(scalar, __VA_ARGS__) \
Macro(vector, __VA_ARGS__) \
Macro(sphericalTensor, __VA_ARGS__) \
Macro(symmTensor, __VA_ARGS__) \
Macro(tensor, __VA_ARGS__)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -34,6 +34,7 @@ Description
#define registerSwitch_H #define registerSwitch_H
#include "simpleRegIOobject.H" #include "simpleRegIOobject.H"
#include "macros.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -85,10 +86,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define CONCAT(x, y) x ## y
#define CONCAT2(x, y) CONCAT(x, y)
#define FILE_UNIQUE(x) CONCAT2(x, __LINE__)
#define registerOptSwitch(Name, Type, Switch) \ #define registerOptSwitch(Name, Type, Switch) \
static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \ static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
(Foam::debug::addOptimisationObject, Name, Switch) (Foam::debug::addOptimisationObject, Name, Switch)

View file

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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 <http://www.gnu.org/licenses/>.
Description
General C-preprocessor macros
\*---------------------------------------------------------------------------*/
#ifndef macros_H
#define macros_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Concatenate two preprocessor tokens
#define CAT_(a, b) a ## b
#define CAT(a, b) CAT_(a, b)
//- Concatenate three preprocessor tokens
#define CAT3_(a, b, c) a ## b ## c
#define CAT3(a, b, c) CAT3_(a, b, c)
//- Concatenate four preprocessor tokens
#define CAT4_(a, b, c, d) a ## b ## c ## d
#define CAT4(a, b, c, d) CAT4_(a, b, c, d)
//- Concatenate five preprocessor tokens
#define CAT5_(a, b, c, d, e) a ## b ## c ## d ## e
#define CAT5(a, b, c, d, e) CAT5_(a, b, c, d, e)
//- Generate an identifier unique within the file in which it is generated
#define FILE_UNIQUE(x) CAT(x, __LINE__)
//- Map 'name' to 'Name' via the predefined macro CAPITALIZE_name
#define CAPITALIZE(name) CAPITALIZE_##name
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(coupled); makePatchFieldTypeNames(coupled);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(transform); makePatchFieldTypeNames(transform);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -31,7 +31,7 @@ License
namespace Foam namespace Foam
{ {
makePatchFieldsTypeName(jumpCyclic); makePatchFieldTypeNames(jumpCyclic);
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View file

@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(jumpCyclicAMI); makePatchFieldTypeNames(jumpCyclicAMI);
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,11 +35,6 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFields(processorCyclic); makePatchFields(processorCyclic);
// makeTemplatePatchTypeField
// (
// fvPatchScalarField,
// processorCyclicFvPatchScalarField
// );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -126,11 +126,7 @@ Foam::fanFvPatchField<Foam::scalar>::fanFvPatchField
namespace Foam namespace Foam
{ {
makeTemplatePatchTypeField makeTemplatePatchTypeField(scalar, fan);
(
fvPatchScalarField,
fanFvPatchScalarField
);
} }

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,16 +34,8 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeTemplatePatchTypeField makeTemplatePatchTypeField(vector, fixedNormalSlip);
( makeTemplatePatchTypeField(tensor, fixedNormalSlip);
fvPatchVectorField,
fixedNormalSlipFvPatchVectorField
);
makeTemplatePatchTypeField
(
fvPatchTensorField,
fixedNormalSlipFvPatchTensorField
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -46,6 +46,7 @@ SourceFiles
#include "fvPatch.H" #include "fvPatch.H"
#include "DimensionedField.H" #include "DimensionedField.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -628,7 +629,7 @@ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
); );
// use with caution // Use with caution
#define addRemovableToPatchFieldRunTimeSelection\ #define addRemovableToPatchFieldRunTimeSelection\
(PatchTypeField, typePatchTypeField) \ (PatchTypeField, typePatchTypeField) \
\ \
@ -652,67 +653,48 @@ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
); );
// for non-templated patch fields // For non-templated patch fields
#define makePatchTypeField(PatchTypeField, typePatchTypeField) \ #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \ defineTypeNameAndDebug(typePatchTypeField, 0); \
addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// for non-templated patch fields - use with caution // For non-templated patch fields - use with caution
#define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \ #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \ defineTypeNameAndDebug(typePatchTypeField, 0); \
addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// For templated patch fields
// for templated patch fields #define makeTemplatePatchTypeField(fieldType, type) \
#define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \ defineNamedTemplateTypeNameAndDebug \
defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \ ( \
addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
0 \
); \
addToPatchFieldRunTimeSelection \
( \
CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
)
#define makePatchFields(type) \ #define makePatchFields(type) \
makeTemplatePatchTypeField \ FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
#define makePatchFieldTypeName(fieldType, type) \
defineNamedTemplateTypeNameAndDebug \
( \ ( \
fvPatchScalarField, \ CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
type##FvPatchScalarField \ 0 \
); \
makeTemplatePatchTypeField \
( \
fvPatchVectorField, \
type##FvPatchVectorField \
); \
makeTemplatePatchTypeField \
( \
fvPatchSphericalTensorField, \
type##FvPatchSphericalTensorField \
); \
makeTemplatePatchTypeField \
( \
fvPatchSymmTensorField, \
type##FvPatchSymmTensorField \
); \
makeTemplatePatchTypeField \
( \
fvPatchTensorField, \
type##FvPatchTensorField \
); );
#define makePatchFieldTypeNames(type) \
FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
#define makePatchFieldsTypeName(type) \ #define makePatchTypeFieldTypedef(fieldType, type) \
defineNamedTemplateTypeNameAndDebug(type##FvPatchScalarField, 0); \ typedef type##FvPatchField<fieldType> \
defineNamedTemplateTypeNameAndDebug(type##FvPatchVectorField, 0); \ CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
defineNamedTemplateTypeNameAndDebug(type##FvPatchSphericalTensorField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchSymmTensorField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchTensorField, 0)
#define makePatchTypeFieldTypedefs(type) \ #define makePatchTypeFieldTypedefs(type) \
typedef type##FvPatchField<scalar> type##FvPatchScalarField; \ FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
typedef type##FvPatchField<vector> type##FvPatchVectorField; \
typedef type##FvPatchField<sphericalTensor> \
type##FvPatchSphericalTensorField; \
typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField; \
typedef type##FvPatchField<tensor> type##FvPatchTensorField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //