Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
e8fa4623
Commit
e8fa4623
authored
5 years ago
by
Mark OLESEN
Committed by
Andrew Heather
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add min/max compare/reduction operators for Tuple2 first()
- min/max ops that only compare the first element
parent
b0c88dff
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
applications/test/Tuple2/Test-Tuple2.C
+38
-0
38 additions, 0 deletions
applications/test/Tuple2/Test-Tuple2.C
src/OpenFOAM/primitives/Tuple2/Tuple2.H
+82
-2
82 additions, 2 deletions
src/OpenFOAM/primitives/Tuple2/Tuple2.H
with
120 additions
and
2 deletions
applications/test/Tuple2/Test-Tuple2.C
+
38
−
0
View file @
e8fa4623
...
@@ -39,6 +39,7 @@ Description
...
@@ -39,6 +39,7 @@ Description
#include
"List.H"
#include
"List.H"
#include
"ListOps.H"
#include
"ListOps.H"
#include
"ops.H"
#include
"ops.H"
#include
"PstreamCombineReduceOps.H"
#include
<functional>
#include
<functional>
using
namespace
Foam
;
using
namespace
Foam
;
...
@@ -121,6 +122,43 @@ int main()
...
@@ -121,6 +122,43 @@ int main()
Info
<<
"Unsorted tuples:"
<<
nl
<<
list1
<<
nl
;
Info
<<
"Unsorted tuples:"
<<
nl
<<
list1
<<
nl
;
// Test minFirst, maxFirst functors
{
indexedScalar
minIndexed
(
labelMax
,
Zero
);
indexedScalar
maxIndexed
(
labelMin
,
Zero
);
for
(
const
auto
&
item
:
list1
)
{
minFirstEqOp
<
label
>
()(
minIndexed
,
item
);
maxFirstEqOp
<
label
>
()(
maxIndexed
,
item
);
}
Foam
::
combineReduce
(
minIndexed
,
minFirstEqOp
<
label
>
());
Foam
::
combineReduce
(
maxIndexed
,
maxFirstEqOp
<
label
>
());
Info
<<
"Min indexed: "
<<
minIndexed
<<
nl
<<
"Max indexed: "
<<
maxIndexed
<<
nl
;
}
// Test minFirst, maxFirst functors
{
indexedScalar
minIndexed
(
labelMax
,
Zero
);
indexedScalar
maxIndexed
(
labelMin
,
Zero
);
for
(
const
auto
&
item
:
list1
)
{
minIndexed
=
minFirstOp
<
label
>
()(
minIndexed
,
item
);
maxIndexed
=
maxFirstOp
<
label
>
()(
maxIndexed
,
item
);
}
Foam
::
combineReduce
(
minIndexed
,
minFirstEqOp
<
label
>
());
Foam
::
combineReduce
(
maxIndexed
,
maxFirstEqOp
<
label
>
());
Info
<<
"Min indexed: "
<<
minIndexed
<<
nl
<<
"Max indexed: "
<<
maxIndexed
<<
nl
;
}
Foam
::
sort
(
list1
,
std
::
less
<
indexedScalar
>
());
Foam
::
sort
(
list1
,
std
::
less
<
indexedScalar
>
());
Info
<<
"sorted tuples:"
<<
nl
<<
list1
<<
nl
;
Info
<<
"sorted tuples:"
<<
nl
<<
list1
<<
nl
;
...
...
This diff is collapsed.
Click to expand it.
src/OpenFOAM/primitives/Tuple2/Tuple2.H
+
82
−
2
View file @
e8fa4623
...
@@ -42,6 +42,7 @@ See also
...
@@ -42,6 +42,7 @@ See also
#include
"Istream.H"
#include
"Istream.H"
#include
"Ostream.H"
#include
"Ostream.H"
#include
"Pair.H"
#include
<utility>
#include
<utility>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
@@ -140,6 +141,8 @@ public:
...
@@ -140,6 +141,8 @@ public:
};
};
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Return reverse of a Tuple2
//- Return reverse of a Tuple2
template
<
class
T1
,
class
T2
>
template
<
class
T1
,
class
T2
>
inline
Tuple2
<
T2
,
T1
>
reverse
(
const
Tuple2
<
T1
,
T2
>&
t
)
inline
Tuple2
<
T2
,
T1
>
reverse
(
const
Tuple2
<
T1
,
T2
>&
t
)
...
@@ -148,6 +151,8 @@ inline Tuple2<T2, T1> reverse(const Tuple2<T1,T2>& t)
...
@@ -148,6 +151,8 @@ inline Tuple2<T2, T1> reverse(const Tuple2<T1,T2>& t)
}
}
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
template
<
class
T1
,
class
T2
>
template
<
class
T1
,
class
T2
>
inline
bool
operator
==
(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
inline
bool
operator
==
(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
{
{
...
@@ -173,7 +178,6 @@ inline bool operator<(const Tuple2<T1,T2>& a, const Tuple2<T1,T2>& b)
...
@@ -173,7 +178,6 @@ inline bool operator<(const Tuple2<T1,T2>& a, const Tuple2<T1,T2>& b)
}
}
template
<
class
T1
,
class
T2
>
template
<
class
T1
,
class
T2
>
inline
bool
operator
<=
(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
inline
bool
operator
<=
(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
{
{
...
@@ -195,7 +199,83 @@ inline bool operator>=(const Tuple2<T1,T2>& a, const Tuple2<T1,T2>& b)
...
@@ -195,7 +199,83 @@ inline bool operator>=(const Tuple2<T1,T2>& a, const Tuple2<T1,T2>& b)
}
}
// IOstream Operators
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
// Comparing first only
//- Compare tuple-like containers
// \return reference to the container with the smaller value of first
template
<
class
T1
>
struct
minFirstOp
{
const
Pair
<
T1
>&
operator
()(
const
Pair
<
T1
>&
a
,
const
Pair
<
T1
>&
b
)
const
{
return
(
b
.
first
()
<
a
.
first
())
?
b
:
a
;
}
template
<
class
T2
>
const
Tuple2
<
T1
,
T2
>&
operator
()(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
const
{
return
(
b
.
first
()
<
a
.
first
())
?
b
:
a
;
}
};
//- Assign tuple-like container to use the one with the smaller value of first
template
<
class
T1
>
struct
minFirstEqOp
{
void
operator
()(
Pair
<
T1
>&
x
,
const
Pair
<
T1
>&
y
)
const
{
if
(
y
.
first
()
<
x
.
first
())
x
=
y
;
}
template
<
class
T2
>
void
operator
()(
Tuple2
<
T1
,
T2
>&
x
,
const
Tuple2
<
T1
,
T2
>&
y
)
const
{
if
(
y
.
first
()
<
x
.
first
())
x
=
y
;
}
};
//- Compare tuple-like containers
// \return reference to the container with the larger value of first
template
<
class
T1
>
struct
maxFirstOp
{
const
Pair
<
T1
>&
operator
()(
const
Pair
<
T1
>&
a
,
const
Pair
<
T1
>&
b
)
const
{
return
(
a
.
first
()
<
b
.
first
())
?
b
:
a
;
}
template
<
class
T2
>
const
Tuple2
<
T1
,
T2
>&
operator
()(
const
Tuple2
<
T1
,
T2
>&
a
,
const
Tuple2
<
T1
,
T2
>&
b
)
const
{
return
(
a
.
first
()
<
b
.
first
())
?
b
:
a
;
}
};
//- Assign tuple-like container to use the one with the larger value of first
template
<
class
T1
>
struct
maxFirstEqOp
{
void
operator
()(
Pair
<
T1
>&
x
,
const
Pair
<
T1
>&
y
)
const
{
if
(
x
.
first
()
<
y
.
first
())
x
=
y
;
}
template
<
class
T2
>
void
operator
()(
Tuple2
<
T1
,
T2
>&
x
,
const
Tuple2
<
T1
,
T2
>&
y
)
const
{
if
(
x
.
first
()
<
y
.
first
())
x
=
y
;
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
//- Read Tuple2 from Istream, discarding contents of existing Tuple2.
//- Read Tuple2 from Istream, discarding contents of existing Tuple2.
template
<
class
T1
,
class
T2
>
template
<
class
T1
,
class
T2
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment