Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
2cdeec92
Commit
2cdeec92
authored
Apr 14, 2020
by
Praetorius, Simon
Browse files
use if constexpr instead of Hybrid::ifElse
parent
de0b3746
Changes
11
Hide whitespace changes
Inline
Side-by-side
amdis/AdaptiveGrid.hpp
View file @
2cdeec92
...
...
@@ -241,10 +241,12 @@ namespace AMDiS
**/
bool
loadBalance
()
{
return
Dune
::
Hybrid
::
ifElse
(
/* if */
std
::
is_convertible
<
decltype
(
std
::
declval
<
HG
>
().
loadBalance
()),
bool
>
{},
[
&
](
auto
id
)
{
return
id
(
hostGrid_
)
->
loadBalance
();
},
[
&
](
auto
id
)
{
id
(
hostGrid_
)
->
loadBalance
();
return
true
;
});
if
constexpr
(
std
::
is_convertible_v
<
decltype
(
std
::
declval
<
HG
>
().
loadBalance
()),
bool
>
)
return
hostGrid_
->
loadBalance
();
else
{
hostGrid_
->
loadBalance
();
return
true
;
}
}
/// \brief Calls loadBalance(handle) on the underlying grid.
...
...
@@ -258,10 +260,12 @@ namespace AMDiS
template
<
class
DataHandle
>
bool
loadBalance
(
DataHandle
&
handle
)
{
return
Dune
::
Hybrid
::
ifElse
(
/* if */
std
::
is_convertible
<
decltype
(
std
::
declval
<
HG
>
().
loadBalance
(
handle
)),
bool
>
{},
[
&
](
auto
id
)
{
return
id
(
hostGrid_
)
->
loadBalance
(
handle
);
},
[
&
](
auto
id
)
{
id
(
hostGrid_
)
->
loadBalance
(
handle
);
return
true
;
});
if
constexpr
(
std
::
is_convertible_v
<
decltype
(
std
::
declval
<
HG
>
().
loadBalance
(
handle
)),
bool
>
)
return
hostGrid_
->
loadBalance
(
handle
);
else
{
hostGrid_
->
loadBalance
(
handle
);
return
true
;
}
}
...
...
@@ -406,9 +410,10 @@ namespace Dune
using
A0
=
GeometryType
;
using
A1
=
std
::
vector
<
unsigned
int
>
;
using
A2
=
ElementParametrizationType
;
Hybrid
::
ifElse
(
Std
::
is_detected
<
HasInsertElement
,
HostGridFactory
,
A0
,
A1
,
A2
>
{},
[
&
](
auto
id
)
{
id
(
hostFactory_
).
insertElement
(
type
,
vertices
,
elementParametrization
);
},
[
&
](
auto
id
)
{
AMDiS
::
error_exit
(
"insertElement() not implemented for HostGrid type."
);
});
if
constexpr
(
Std
::
is_detected
<
HasInsertElement
,
HostGridFactory
,
A0
,
A1
,
A2
>::
value
)
hostFactory_
.
insertElement
(
type
,
vertices
,
elementParametrization
);
else
AMDiS
::
error_exit
(
"insertElement() not implemented for HostGrid type."
);
}
template
<
class
F
,
class
...
Args
>
...
...
@@ -428,9 +433,10 @@ namespace Dune
{
using
A0
=
std
::
vector
<
unsigned
int
>
;
using
A1
=
BoundarySegmentType
;
Hybrid
::
ifElse
(
Std
::
is_detected
<
HasInsertBoundarySegment
,
HostGridFactory
,
A0
,
A1
>
{},
[
&
](
auto
id
)
{
id
(
hostFactory_
).
insertBoundarySegment
(
vertices
,
boundarySegment
);
},
[
&
](
auto
id
)
{
AMDiS
::
error_exit
(
"insertBoundarySegment() not implemented for HostGrid type."
);
});
if
constexpr
(
Std
::
is_detected
<
HasInsertBoundarySegment
,
HostGridFactory
,
A0
,
A1
>::
value
)
hostFactory_
.
insertBoundarySegment
(
vertices
,
boundarySegment
);
else
AMDiS
::
error_exit
(
"insertBoundarySegment() not implemented for HostGrid type."
);
}
/// Finalize grid creation and hand over the grid
...
...
amdis/BoundaryManager.hpp
View file @
2cdeec92
...
...
@@ -151,10 +151,10 @@ namespace AMDiS
if
(
!
segment
.
boundary
())
continue
;
Dune
::
Hybrid
::
ifElse
(
Dune
::
Std
::
is_detected
<
HasBoundaryId
,
Segment
>
{},
[
&
](
auto
id
)
->
void
{
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasBoundaryId
,
Segment
>
::
value
)
{
auto
index
=
segment
.
boundarySegmentIndex
();
boundaryIds_
[
index
]
=
id
(
segment
)
.
boundaryId
();
}
);
boundaryIds_
[
index
]
=
segment
.
boundaryId
();
}
}
}
}
...
...
amdis/ProblemStat.inc.hpp
View file @
2cdeec92
...
...
@@ -453,13 +453,10 @@ Flag ProblemStat<Traits>::
globalRefine
(
int
n
)
{
Dune
::
Timer
t
;
Dune
::
Hybrid
::
ifElse
(
Dune
::
Std
::
is_detected
<
HasGlobalRefineADHI
,
Grid
>
{},
/*then*/
[
&
](
auto
id
)
->
void
{
id
(
grid_
)
->
globalRefine
(
n
,
globalBasis_
->
globalRefineCallback
());
},
/*else*/
[
&
](
auto
id
)
->
void
{
id
(
grid_
)
->
globalRefine
(
n
);
});
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasGlobalRefineADHI
,
Grid
>::
value
)
grid_
->
globalRefine
(
n
,
globalBasis_
->
globalRefineCallback
());
else
grid_
->
globalRefine
(
n
);
msg
(
"globalRefine needed {} seconds"
,
t
.
elapsed
());
return
n
>
0
?
MESH_ADAPTED
:
Flag
(
0
);
...
...
amdis/common/FieldMatVec.inc.hpp
View file @
2cdeec92
...
...
@@ -65,7 +65,6 @@ namespace MatVec {
auto
multiplies
(
A
const
&
a
,
B
const
&
b
)
{
using
T
=
std
::
common_type_t
<
typename
FieldTraits
<
A
>::
field_type
,
typename
FieldTraits
<
B
>::
field_type
>
;
#if AMDIS_HAS_CXX_CONSTEXPR_IF
if
constexpr
(
IsNumber
<
A
>::
value
)
{
typename
MakeMatVec
<
B
,
T
>::
type
b_
{
b
};
return
b_
*=
a
;
...
...
@@ -73,11 +72,6 @@ namespace MatVec {
typename
MakeMatVec
<
A
,
T
>::
type
a_
{
a
};
return
a_
*=
b
;
}
#else
return
Hybrid
::
ifElse
(
IsNumber
<
A
>
{},
[
&
](
auto
id
)
{
typename
MakeMatVec
<
B
,
T
>::
type
b_
{
b
};
return
id
(
b_
)
*=
id
(
a
);
},
[
&
](
auto
id
)
{
typename
MakeMatVec
<
A
,
T
>::
type
a_
{
a
};
return
id
(
a_
)
*=
id
(
b
);
});
#endif
}
template
<
class
T
,
int
N
,
class
S
>
...
...
amdis/linearalgebra/VectorFacade.hpp
View file @
2cdeec92
...
...
@@ -81,17 +81,19 @@ namespace AMDiS
/// Return the number of entries in the local part of the vector
std
::
size_t
localSize
()
const
{
return
Dune
::
Hybrid
::
ifElse
(
Dune
::
Std
::
is_detected
<
HasLocalSize
,
Impl
>
{},
[
&
](
auto
id
)
{
return
id
(
impl_
).
localSize
();
},
[
&
](
auto
id
)
{
return
id
(
impl_
).
size
();
});
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasLocalSize
,
Impl
>::
value
)
return
impl_
.
localSize
();
else
return
impl_
.
size
();
}
/// Return the number of entries in the global vector
std
::
size_t
globalSize
()
const
{
return
Dune
::
Hybrid
::
ifElse
(
Dune
::
Std
::
is_detected
<
HasGlobalSize
,
Impl
>
{},
[
&
](
auto
id
)
{
return
id
(
impl_
).
globalSize
();
},
[
&
](
auto
id
)
{
return
id
(
impl_
).
size
();
});
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasGlobalSize
,
Impl
>::
value
)
return
impl_
.
globalSize
();
else
return
impl_
.
size
();
}
/// Resize the \ref vector to the size of the \ref basis
...
...
amdis/linearalgebra/istl/PreconWrapper.hpp
View file @
2cdeec92
...
...
@@ -60,13 +60,10 @@ namespace AMDiS
template
<
bool
forward
>
void
apply
(
domain_type
&
v
,
range_type
const
&
d
)
{
Dune
::
Hybrid
::
ifElse
(
Dune
::
Std
::
is_detected
<
HasApplyFoward
,
P
>
{},
[
&
](
auto
id
)
{
id
(
precon_
).
template
apply
<
forward
>(
v
,
d
);
},
[
&
](
auto
id
)
{
id
(
precon_
).
apply
(
v
,
d
);
});
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasApplyFoward
,
P
>::
value
)
precon_
.
template
apply
<
forward
>(
v
,
d
);
else
precon_
.
apply
(
v
,
d
);
}
/// \brief Clean up.
...
...
amdis/localoperators/ConvectionDiffusionOperator.hpp
View file @
2cdeec92
...
...
@@ -182,10 +182,10 @@ namespace AMDiS
template
<
class
LocalFct
>
int
coeffOrder
(
LocalFct
const
&
localFct
)
{
using
Concept
=
Dune
::
Std
::
is_detected
<
HasLocalFunctionOrder
,
LocalFct
>
;
return
Dune
::
Hybrid
::
ifElse
(
Concept
{},
[
&
](
auto
id
)
->
int
{
return
order
(
id
(
localFct
));
},
[]
(
auto
)
->
int
{
return
0
;
});
if
constexpr
(
Dune
::
Std
::
is_detected
<
HasLocalFunctionOrder
,
LocalFct
>
::
value
)
return
order
(
localFct
);
else
return
0
;
}
template
<
class
T
,
int
N
>
...
...
amdis/typetree/Traversal.hpp
View file @
2cdeec92
...
...
@@ -92,14 +92,8 @@ namespace AMDiS {
if
(
i
>
0
)
visitor
.
in
(
tree
,
treePath
);
static
constexpr
auto
visitChild
=
Visitor
::
template
VisitChild
<
Tree
,
Child
,
TP
>
::
value
;
#if AMDIS_HAS_CXX_CONSTEXPR_IF
if
constexpr
(
visitChild
)
applyToTree
(
child
,
childTP
,
visitor
);
#else // AMDIS_HAS_CXX_CONSTEXPR_IF
Dune
::
Hybrid
::
ifElse
(
bool_t
<
visitChild
>
{},
[
&
]
(
auto
/*id*/
)
->
void
{
applyToTree
(
child
,
childTP
,
visitor
);
});
#endif // AMDIS_HAS_CXX_CONSTEXPR_IF
visitor
.
afterChild
(
tree
,
child
,
treePath
,
i
);
});
visitor
.
post
(
tree
,
treePath
);
...
...
amdis/utility/QuadratureFactory.hpp
View file @
2cdeec92
...
...
@@ -56,9 +56,10 @@ namespace AMDiS
public:
void
bind
(
LocalFunction
const
&
localFct
)
final
{
order_
=
Dune
::
Hybrid
::
ifElse
(
Concept
{},
[
&
](
auto
id
)
->
int
{
return
AMDiS
::
order
(
id
(
localFct
));
},
[]
(
auto
)
->
int
{
return
-
1
;
});
if
constexpr
(
Concept
::
value
)
order_
=
AMDiS
::
order
(
localFct
);
else
order_
=
-
1
;
}
int
order
()
const
final
{
return
order_
;
}
...
...
cmake/modules/AmdisCXXFeatures.cmake
View file @
2cdeec92
...
...
@@ -16,22 +16,6 @@ check_cxx_source_compiles("
"
AMDIS_HAS_CXX_FOLD_EXPRESSIONS
)
check_cxx_source_compiles
(
"
template <int I>
auto f()
{
if constexpr(I == 0)
return double{1.0};
else
return int{0};
}
int main()
{
return f<1>();
}
"
AMDIS_HAS_CXX_CONSTEXPR_IF
)
check_cxx_source_compiles
(
"
#include <iostream>
#include <tuple>
...
...
config.h.cmake
View file @
2cdeec92
...
...
@@ -54,7 +54,6 @@
/* some detected compiler features may be used in AMDiS */
#cmakedefine AMDIS_HAS_CXX_FOLD_EXPRESSIONS 1
#cmakedefine AMDIS_HAS_CXX_CONSTEXPR_IF 1
#cmakedefine AMDIS_HAS_EXPANSION_STATEMENTS 1
#cmakedefine AMDIS_HAS_CXX_AUTO_TEMPLATE_PARAMETER 1
...
...
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