Commit 35fc2d1b authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: modernize code for tmp reuse functions (#1160)

- use forwarding tmp factory methods
parent fcf4c5fb
......@@ -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) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -33,47 +33,9 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class TypeR, class GeoMesh>
tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
const word& name,
const dimensionSet& dimensions
)
{
if (tdf1.isTmp())
{
auto& df1 = tdf1.constCast();
df1.rename(name);
df1.dimensions().reset(dimensions);
return tdf1;
}
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
(
new DimensionedField<TypeR, GeoMesh>
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
);
}
template<class TypeR, class Type1, class GeoMesh>
class reuseTmpDimensionedField
struct reuseTmpDimensionedField
{
public:
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<Type1, GeoMesh>>& tdf1,
......@@ -83,29 +45,24 @@ public:
{
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
template<class TypeR, class GeoMesh>
class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
struct reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
{
public:
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
......@@ -124,29 +81,42 @@ public:
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
class reuseTmpTmpDimensionedField
//- Global function forwards to reuseTmpDimensionedField::New
template<class TypeR, class GeoMesh>
tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
const word& name,
const dimensionSet& dimensions
)
{
public:
return reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>::New
(
tdf1,
name,
dimensions
);
}
template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
struct reuseTmpTmpDimensionedField
{
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<Type1, GeoMesh>>& tdf1,
......@@ -157,29 +127,24 @@ public:
{
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
template<class TypeR, class Type1, class Type12, class GeoMesh>
class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
struct reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
{
public:
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<Type1, GeoMesh>>& tdf1,
......@@ -199,29 +164,24 @@ public:
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
template<class TypeR, class Type2, class GeoMesh>
class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
{
public:
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
......@@ -241,29 +201,24 @@ public:
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
template<class TypeR, class GeoMesh>
class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
{
public:
static tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
......@@ -291,19 +246,16 @@ public:
const auto& df1 = tdf1();
return tmp<DimensionedField<TypeR, GeoMesh>>
return tmp<DimensionedField<TypeR, GeoMesh>>::New
(
new DimensionedField<TypeR, GeoMesh>
IOobject
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
);
}
};
......
......@@ -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) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -33,58 +33,26 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<template<class> class Field, class TypeR>
tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, TypeR>>& tf1,
const bool initRet = false
)
{
if (tf1.isTmp())
{
return tf1;
}
tmp<FieldField<Field, TypeR>> rtf
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
if (initRet)
{
rtf.ref() = tf1();
}
return rtf;
}
template<template<class> class Field, class TypeR, class Type1>
class reuseTmpFieldField
struct reuseTmpFieldField
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, Type1>>& tf1
)
{
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
return FieldField<Field, TypeR>::NewCalculatedType(tf1());
}
};
template<template<class> class Field, class TypeR>
class reuseTmpFieldField<Field, TypeR, TypeR>
struct reuseTmpFieldField<Field, TypeR, TypeR>
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, TypeR>>& tf1
const tmp<FieldField<Field, TypeR>>& tf1,
const bool initCopy = false
)
{
if (tf1.isTmp())
......@@ -92,14 +60,30 @@ public:
return tf1;
}
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
auto rtf = FieldField<Field, TypeR>::NewCalculatedType(tf1());
if (initCopy)
{
rtf.ref() = tf1();
}
return rtf;
}
};
//- Global function forwards to reuseTmpFieldField::New
template<template<class> class Field, class TypeR>
tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, TypeR>>& tf1,
const bool initCopy = false
)
{
return reuseTmpFieldField<Field, TypeR, TypeR>::New(tf1, initCopy);
}
template
<
template<class> class Field,
......@@ -108,29 +92,22 @@ template
class Type12,
class Type2
>
class reuseTmpTmpFieldField
struct reuseTmpTmpFieldField
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, Type1>>& tf1,
const tmp<FieldField<Field, Type2>>& tf2
)
{
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
return FieldField<Field, TypeR>::NewCalculatedType(tf1());
}
};
template<template<class> class Field, class TypeR, class Type1, class Type12>
class reuseTmpTmpFieldField<Field, TypeR, Type1, Type12, TypeR>
struct reuseTmpTmpFieldField<Field, TypeR, Type1, Type12, TypeR>
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, Type1>>& tf1,
......@@ -142,19 +119,14 @@ public:
return tf2;
}
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
return FieldField<Field, TypeR>::NewCalculatedType(tf1());
}
};
template<template<class> class Field, class TypeR, class Type2>
class reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, Type2>
struct reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, Type2>
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, TypeR>>& tf1,
......@@ -166,19 +138,14 @@ public:
return tf1;
}
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
return FieldField<Field, TypeR>::NewCalculatedType(tf1());
}
};
template<template<class> class Field, class TypeR>
class reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, TypeR>
struct reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, TypeR>
{
public:
static tmp<FieldField<Field, TypeR>> New
(
const tmp<FieldField<Field, TypeR>>& tf1,
......@@ -194,10 +161,7 @@ public:
return tf2;
}
return tmp<FieldField<Field, TypeR>>
(
FieldField<Field, TypeR>::NewCalculatedType(tf1())
);
return FieldField<Field, TypeR>::NewCalculatedType(tf1());
}
};
......
......@@ -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) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -33,79 +33,70 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class TypeR>
tmp<Field<TypeR>> New
(
const tmp<Field<TypeR>>& tf1,
const bool initRet = false
)
{
if (tf1.isTmp())
{
return tf1;
}
tmp<Field<TypeR>> rtf(new Field<TypeR>(tf1().size()));
if (initRet)
{
rtf.ref() = tf1();
}
return rtf;
}
template<class TypeR, class Type1>
class reuseTmp
struct reuseTmp
{
public:
static tmp<Field<TypeR>> New(const tmp<Field<Type1>>& tf1)
{
return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
return tmp<Field<TypeR>>::New(tf1().size());
}
};
template<class TypeR>
class reuseTmp<TypeR, TypeR>
struct reuseTmp<TypeR, TypeR>
{
public:
static tmp<Field<TypeR>> New(const tmp<Field<TypeR>>& tf1)
static tmp<Field<TypeR>> New
(
const tmp<Field<TypeR>>& tf1,
const bool initCopy = false
)
{
if (tf1.isTmp())
{
return tf1;
}
return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
auto rtf = tmp<Field<TypeR>>::New(tf1().size());
if (initCopy)
{
rtf.ref() = tf1();
}
return rtf;
}
};
template<class TypeR, class Type1, class Type12, class Type2>
class reuseTmpTmp
//- This global function forwards to reuseTmp::New
template<class TypeR> tmp<Field<TypeR>> New
(
const tmp<Field<TypeR>>& tf1,
const bool initCopy = false
)
{
public:
return reuseTmp<TypeR, TypeR>::New(tf1, initCopy);
}
template<class TypeR, class Type1, class Type12, class Type2>
struct reuseTmpTmp
{
static tmp<Field<TypeR>> New
(
const tmp<Field<Type1>>& tf1,
const tmp<Field<Type2>>& tf2
)
</