Commit 48a23569 authored by Henry Weller's avatar Henry Weller
Browse files

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.
parent 3f4f05b6
......@@ -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\
(baseType,thisType,argNames) \
\
......@@ -41,7 +40,7 @@ Description
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\
(baseType,thisType,argNames,lookup) \
\
......@@ -51,7 +50,7 @@ Description
(#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\
(baseType,thisType,argNames) \
\
......@@ -60,7 +59,7 @@ Description
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\
(baseType,thisType,argNames,lookup) \
\
......@@ -72,9 +71,8 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// add to hash-table of functions with typename as the key
// use when baseType doesn't need a template argument (eg, is a typedef)
//- Add to hash-table of functions with typename as the key.
// Use when baseType doesn't need a template argument (eg, is a typedef)
#define addTemplateToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames) \
\
......@@ -83,8 +81,8 @@ Description
add##thisType##Targ##argNames##ConstructorTo##baseType##Table_
// add to hash-table of functions with 'lookup' as the key
// use when baseType doesn't need a template argument (eg, is a typedef)
//- Add to hash-table of functions with 'lookup' as the key.
// Use when baseType doesn't need a template argument (eg, is a typedef)
#define addNamedTemplateToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames,lookup) \
\
......@@ -96,9 +94,8 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// add to hash-table of functions with typename as the key
// use when baseType requires the Targ template argument as well
//- Add to hash-table of functions with typename as the key.
// Use when baseType requires the Targ template argument as well
#define addTemplatedToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames) \
\
......@@ -107,8 +104,8 @@ Description
add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_
// add to hash-table of functions with 'lookup' as the key
// use when baseType requires the Targ template argument as well
//- Add to hash-table of functions with 'lookup' as the key.
// Use when baseType requires the Targ template argument as well
#define addNamedTemplatedToRunTimeSelectionTable\
(baseType,thisType,Targ,argNames,lookup) \
\
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -37,6 +37,22 @@ Description
#include "symmTensor.H"
#include "tensor.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__)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -34,6 +34,7 @@ Description
#define registerSwitch_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) \
static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
(Foam::debug::addOptimisationObject, Name, Switch)
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(coupled);
makePatchFieldTypeNames(coupled);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(transform);
makePatchFieldTypeNames(transform);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -31,7 +31,7 @@ License
namespace Foam
{
makePatchFieldsTypeName(jumpCyclic);
makePatchFieldTypeNames(jumpCyclic);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -34,7 +34,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFieldsTypeName(jumpCyclicAMI);
makePatchFieldTypeNames(jumpCyclicAMI);
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -35,11 +35,6 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFields(processorCyclic);
// makeTemplatePatchTypeField
// (
// fvPatchScalarField,
// processorCyclicFvPatchScalarField
// );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -126,11 +126,7 @@ Foam::fanFvPatchField<Foam::scalar>::fanFvPatchField
namespace Foam
{
makeTemplatePatchTypeField
(
fvPatchScalarField,
fanFvPatchScalarField
);
makeTemplatePatchTypeField(scalar, fan);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,16 +34,8 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeTemplatePatchTypeField
(
fvPatchVectorField,
fixedNormalSlipFvPatchVectorField
);
makeTemplatePatchTypeField
(
fvPatchTensorField,
fixedNormalSlipFvPatchTensorField
);
makeTemplatePatchTypeField(vector, fixedNormalSlip);
makeTemplatePatchTypeField(tensor, fixedNormalSlip);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -46,6 +46,7 @@ SourceFiles
#include "fvPatch.H"
#include "DimensionedField.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -628,7 +629,7 @@ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
);
// use with caution
// Use with caution
#define addRemovableToPatchFieldRunTimeSelection\
(PatchTypeField, typePatchTypeField) \
\
......@@ -652,67 +653,48 @@ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
);
// for non-templated patch fields
// For non-templated patch fields
#define makePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \
addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// for non-templated patch fields - use with caution
// For non-templated patch fields - use with caution
#define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \
addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// for templated patch fields
#define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \
defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
#define makePatchFields(type) \
makeTemplatePatchTypeField \
( \
fvPatchScalarField, \
type##FvPatchScalarField \
); \
makeTemplatePatchTypeField \
// For templated patch fields
#define makeTemplatePatchTypeField(fieldType, type) \
defineNamedTemplateTypeNameAndDebug \
( \
fvPatchVectorField, \
type##FvPatchVectorField \
CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
0 \
); \
makeTemplatePatchTypeField \
addToPatchFieldRunTimeSelection \
( \
fvPatchSphericalTensorField, \
type##FvPatchSphericalTensorField \
); \
makeTemplatePatchTypeField \
( \
fvPatchSymmTensorField, \
type##FvPatchSymmTensorField \
); \
makeTemplatePatchTypeField \
CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
)
#define makePatchFields(type) \
FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
#define makePatchFieldTypeName(fieldType, type) \
defineNamedTemplateTypeNameAndDebug \
( \
fvPatchTensorField, \
type##FvPatchTensorField \
CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
0 \
);
#define makePatchFieldTypeNames(type) \
FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
#define makePatchFieldsTypeName(type) \
defineNamedTemplateTypeNameAndDebug(type##FvPatchScalarField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchVectorField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchSphericalTensorField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchSymmTensorField, 0); \
defineNamedTemplateTypeNameAndDebug(type##FvPatchTensorField, 0)
#define makePatchTypeFieldTypedef(fieldType, type) \
typedef type##FvPatchField<fieldType> \
CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
#define makePatchTypeFieldTypedefs(type) \
typedef type##FvPatchField<scalar> type##FvPatchScalarField; \
typedef type##FvPatchField<vector> type##FvPatchVectorField; \
typedef type##FvPatchField<sphericalTensor> \
type##FvPatchSphericalTensorField; \
typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField; \
typedef type##FvPatchField<tensor> type##FvPatchTensorField;
FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment