Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
3019f30b
Commit
3019f30b
authored
Jan 10, 2019
by
Mark OLESEN
Browse files
STYLE: modernize code for FieldFunctions (
#1160
)
- use forwarding tmp factory methods, auto types
parent
35fc2d1b
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/fields/Fields/Field/Field.C
View file @
3019f30b
...
...
@@ -560,9 +560,9 @@ Foam::Field<Type>::component
const
direction
d
)
const
{
tmp
<
Field
<
cmptType
>>
Component
(
new
Field
<
cmptType
>
(
this
->
size
())
)
;
::
Foam
::
component
(
Component
.
ref
(),
*
this
,
d
);
return
Component
;
auto
tres
=
tmp
<
Field
<
cmptType
>>
::
New
(
this
->
size
());
::
Foam
::
component
(
tres
.
ref
(),
*
this
,
d
);
return
tres
;
}
...
...
@@ -618,9 +618,9 @@ VSForm Foam::Field<Type>::block(const label start) const
template
<
class
Type
>
Foam
::
tmp
<
Foam
::
Field
<
Type
>>
Foam
::
Field
<
Type
>::
T
()
const
{
tmp
<
Field
<
Type
>>
transpose
(
new
Field
<
Type
>
(
this
->
size
())
)
;
::
Foam
::
T
(
tr
anspos
e
.
ref
(),
*
this
);
return
tr
anspos
e
;
auto
tres
=
tmp
<
Field
<
cmpt
Type
>>
::
New
(
this
->
size
());
::
Foam
::
T
(
tre
s
.
ref
(),
*
this
);
return
tre
s
;
}
...
...
src/OpenFOAM/fields/Fields/Field/FieldFunctions.C
View file @
3019f30b
...
...
@@ -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.
...
...
@@ -83,12 +83,12 @@ pow
)
{
typedef
typename
powProduct
<
Type
,
r
>::
type
powProductType
;
tmp
<
Field
<
powProductType
>>
t
R
es
auto
t
r
es
(
new
Field
<
powProductType
>
(
f
.
size
())
tmp
<
Field
<
powProductType
>
>::
New
(
f
.
size
())
);
pow
<
Type
,
r
>
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
pow
<
Type
,
r
>
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
,
direction
r
>
...
...
@@ -100,10 +100,10 @@ pow
)
{
typedef
typename
powProduct
<
Type
,
r
>::
type
powProductType
;
tmp
<
Field
<
powProductType
>>
t
R
es
=
reuseTmp
<
powProductType
,
Type
>::
New
(
tf
);
pow
<
Type
,
r
>
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
powProductType
,
Type
>::
New
(
tf
);
pow
<
Type
,
r
>
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -123,12 +123,12 @@ tmp<Field<typename outerProduct<Type, Type>::type>>
sqr
(
const
UList
<
Type
>&
f
)
{
typedef
typename
outerProduct
<
Type
,
Type
>::
type
outerProductType
;
tmp
<
Field
<
outerProductType
>>
t
R
es
auto
t
r
es
(
new
Field
<
outerProductType
>
(
f
.
size
())
tmp
<
Field
<
outerProductType
>
>::
New
(
f
.
size
())
);
sqr
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
sqr
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
...
...
@@ -136,11 +136,10 @@ tmp<Field<typename outerProduct<Type, Type>::type>>
sqr
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
typedef
typename
outerProduct
<
Type
,
Type
>::
type
outerProductType
;
tmp
<
Field
<
outerProductType
>>
tRes
=
reuseTmp
<
outerProductType
,
Type
>::
New
(
tf
);
sqr
(
tRes
.
ref
(),
tf
());
auto
tres
=
reuseTmp
<
outerProductType
,
Type
>::
New
(
tf
);
sqr
(
tres
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -153,18 +152,18 @@ void magSqr(Field<scalar>& res, const UList<Type>& f)
template
<
class
Type
>
tmp
<
Field
<
scalar
>>
magSqr
(
const
UList
<
Type
>&
f
)
{
tmp
<
Field
<
scalar
>>
tRes
(
new
Field
<
scalar
>
(
f
.
size
())
)
;
magSqr
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
scalar
>>
::
New
(
f
.
size
());
magSqr
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
scalar
>>
magSqr
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
tmp
<
Field
<
scalar
>>
t
R
es
=
reuseTmp
<
scalar
,
Type
>::
New
(
tf
);
magSqr
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
scalar
,
Type
>::
New
(
tf
);
magSqr
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -177,18 +176,18 @@ void mag(Field<scalar>& res, const UList<Type>& f)
template
<
class
Type
>
tmp
<
Field
<
scalar
>>
mag
(
const
UList
<
Type
>&
f
)
{
tmp
<
Field
<
scalar
>>
tRes
(
new
Field
<
scalar
>
(
f
.
size
())
)
;
mag
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
scalar
>>
::
New
(
f
.
size
());
mag
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
scalar
>>
mag
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
tmp
<
Field
<
scalar
>>
t
R
es
=
reuseTmp
<
scalar
,
Type
>::
New
(
tf
);
mag
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
scalar
,
Type
>::
New
(
tf
);
mag
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -203,19 +202,19 @@ template<class Type>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptMax
(
const
UList
<
Type
>&
f
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
tRes
(
new
Field
<
cmptType
>
(
f
.
size
())
)
;
cmptMax
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
cmptType
>>
::
New
(
f
.
size
());
cmptMax
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptMax
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
t
R
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptMax
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptMax
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -230,19 +229,19 @@ template<class Type>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptMin
(
const
UList
<
Type
>&
f
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
tRes
(
new
Field
<
cmptType
>
(
f
.
size
())
)
;
cmptMin
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
cmptType
>>
::
New
(
f
.
size
());
cmptMin
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptMin
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
t
R
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptMin
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptMin
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -257,19 +256,19 @@ template<class Type>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptAv
(
const
UList
<
Type
>&
f
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
tRes
(
new
Field
<
cmptType
>
(
f
.
size
())
)
;
cmptAv
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
cmptType
>>
::
New
(
f
.
size
());
cmptAv
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
typename
Field
<
Type
>::
cmptType
>>
cmptAv
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
typedef
typename
Field
<
Type
>::
cmptType
cmptType
;
tmp
<
Field
<
cmptType
>>
t
R
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptAv
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
reuseTmp
<
cmptType
,
Type
>::
New
(
tf
);
cmptAv
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -282,18 +281,18 @@ void cmptMag(Field<Type>& res, const UList<Type>& f)
template
<
class
Type
>
tmp
<
Field
<
Type
>>
cmptMag
(
const
UList
<
Type
>&
f
)
{
tmp
<
Field
<
Type
>>
tRes
(
new
Field
<
Type
>
(
f
.
size
())
)
;
cmptMag
(
t
R
es
.
ref
(),
f
);
return
t
R
es
;
auto
tres
=
tmp
<
Field
<
Type
>>
::
New
(
f
.
size
());
cmptMag
(
t
r
es
.
ref
(),
f
);
return
t
r
es
;
}
template
<
class
Type
>
tmp
<
Field
<
Type
>>
cmptMag
(
const
tmp
<
Field
<
Type
>>&
tf
)
{
tmp
<
Field
<
Type
>>
t
R
es
=
New
(
tf
);
cmptMag
(
t
R
es
.
ref
(),
tf
());
auto
t
r
es
=
New
(
tf
);
cmptMag
(
t
r
es
.
ref
(),
tf
());
tf
.
clear
();
return
t
R
es
;
return
t
r
es
;
}
...
...
@@ -652,9 +651,9 @@ tmp<Field<typename product<Type1, Type2>::type>> \
operator Op(const UList<Type1>& f1, const UList<Type2>& f2) \
{ \
typedef typename product<Type1, Type2>::type productType; \
tmp<Field<productType>>
t
R
es
(new
Field<productType>(f1.size())
)
; \
OpFunc(t
R
es.ref(), f1, f2); \
return t
R
es; \
auto
t
r
es
= tmp<
Field<productType>
>::New
(f1.size());
\
OpFunc(t
r
es.ref(), f1, f2); \
return t
r
es; \
} \
\
template<class Type1, class Type2> \
...
...
@@ -662,10 +661,10 @@ tmp<Field<typename product<Type1, Type2>::type>> \
operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2) \
{ \
typedef typename product<Type1, Type2>::type productType; \
tmp<Field<productType>>
t
R
es = reuseTmp<productType, Type2>::New(tf2); \
OpFunc(t
R
es.ref(), f1, tf2()); \
auto
t
r
es = reuseTmp<productType, Type2>::New(tf2); \
OpFunc(t
r
es.ref(), f1, tf2()); \
tf2.clear(); \
return t
R
es; \
return t
r
es; \
} \
\
template<class Type1, class Type2> \
...
...
@@ -673,10 +672,10 @@ tmp<Field<typename product<Type1, Type2>::type>> \
operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2) \
{ \
typedef typename product<Type1, Type2>::type productType; \
tmp<Field<productType>>
t
R
es = reuseTmp<productType, Type1>::New(tf1); \
OpFunc(t
R
es.ref(), tf1(), f2); \
auto
t
r
es = reuseTmp<productType, Type1>::New(tf1); \
OpFunc(t
r
es.ref(), tf1(), f2); \
tf1.clear(); \
return t
R
es; \
return t
r
es; \
} \
\
template<class Type1, class Type2> \
...
...
@@ -684,12 +683,11 @@ tmp<Field<typename product<Type1, Type2>::type>> \
operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2) \
{ \
typedef typename product<Type1, Type2>::type productType; \
tmp<Field<productType>> tRes = \
reuseTmpTmp<productType, Type1, Type1, Type2>::New(tf1, tf2); \
OpFunc(tRes.ref(), tf1(), tf2()); \
auto tres = reuseTmpTmp<productType, Type1, Type1, Type2>::New(tf1, tf2); \
OpFunc(tres.ref(), tf1(), tf2()); \
tf1.clear(); \
tf2.clear(); \
return t
R
es; \
return t
r
es; \
} \
\
template<class Type, class Form, class Cmpt, direction nCmpt> \
...
...
@@ -710,9 +708,9 @@ tmp<Field<typename product<Type, Form>::type>> \
operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs) \
{ \
typedef typename product<Type, Form>::type productType; \
tmp<Field<productType>>
t
R
es
(new
Field<productType>(f1.size())
)
; \
OpFunc(t
R
es.ref(), f1, static_cast<const Form&>(vs)); \
return t
R
es; \
auto
t
r
es
= tmp<
Field<productType>
>::New
(f1.size());
\
OpFunc(t
r
es.ref(), f1, static_cast<const Form&>(vs)); \
return t
r
es; \
} \
\
template<class Type, class Form, class Cmpt, direction nCmpt> \
...
...
@@ -724,10 +722,10 @@ operator Op \
) \
{ \
typedef typename product<Type, Form>::type productType; \
tmp<Field<productType>>
t
R
es = reuseTmp<productType, Type>::New(tf1); \
OpFunc(t
R
es.ref(), tf1(), static_cast<const Form&>(vs)); \
auto
t
r
es = reuseTmp<productType, Type>::New(tf1);
\
OpFunc(t
r
es.ref(), tf1(), static_cast<const Form&>(vs)); \
tf1.clear(); \
return t
R
es; \
return t
r
es; \
} \
\
template<class Form, class Cmpt, direction nCmpt, class Type> \
...
...
@@ -748,9 +746,9 @@ tmp<Field<typename product<Form, Type>::type>> \
operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1) \
{ \
typedef typename product<Form, Type>::type productType; \
tmp<Field<productType>>
t
R
es
(new
Field<productType>(f1.size())
)
; \
OpFunc(t
R
es.ref(), static_cast<const Form&>(vs), f1); \
return t
R
es; \
auto
t
r
es
= tmp<
Field<productType>
>::New
(f1.size());
\
OpFunc(t
r
es.ref(), static_cast<const Form&>(vs), f1); \
return t
r
es; \
} \
\
template<class Form, class Cmpt, direction nCmpt, class Type> \
...
...
@@ -761,10 +759,10 @@ operator Op \
) \
{ \
typedef typename product<Form, Type>::type productType; \
tmp<Field<productType>>
t
R
es = reuseTmp<productType, Type>::New(tf1); \
OpFunc(t
R
es.ref(), static_cast<const Form&>(vs), tf1()); \
auto
t
r
es = reuseTmp<productType, Type>::New(tf1);
\
OpFunc(t
r
es.ref(), static_cast<const Form&>(vs), tf1()); \
tf1.clear(); \
return t
R
es; \
return t
r
es; \
}
PRODUCT_OPERATOR
(
typeOfSum
,
+
,
add
)
...
...
src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C
View file @
3019f30b
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment