Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
amdis
amdis-core
Commits
59e7bf37
Commit
59e7bf37
authored
Mar 16, 2019
by
Praetorius, Simon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TreeContainer default constructible and thus allow matrix containers
parent
95a126a5
Pipeline
#1852
passed with stage
in 25 minutes and 7 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
13 deletions
+87
-13
src/amdis/typetree/TreeContainer.hpp
src/amdis/typetree/TreeContainer.hpp
+26
-13
test/CMakeLists.txt
test/CMakeLists.txt
+3
-0
test/TreeContainerTest.cpp
test/TreeContainerTest.cpp
+58
-0
No files found.
src/amdis/typetree/TreeContainer.hpp
View file @
59e7bf37
...
...
@@ -12,6 +12,7 @@
#include <amdis/common/Apply.hpp>
#include <amdis/common/TypeTraits.hpp>
#include <amdis/typetree/TreePath.hpp>
// NOTE: backport of dune/typetree/treecontainer.hh
...
...
@@ -65,8 +66,9 @@ namespace AMDiS
std
::
enable_if_t
<
Node
::
isComposite
,
int
>
=
0
>
auto
operator
()(
const
Node
&
node
)
{
return
Tools
::
apply_indices
([
&
](
auto
...
indices
)
{
return
Dune
::
makeTupleVector
((
*
this
)(
node
.
child
(
indices
))...);
},
index_t
<
Node
::
degree
()
>
{});
return
Tools
::
apply_indices
([
&
](
auto
...
indices
)
{
return
Dune
::
makeTupleVector
((
*
this
)(
node
.
child
(
indices
))...);
},
index_t
<
Node
::
degree
()
>
{});
}
private:
...
...
@@ -80,6 +82,8 @@ namespace AMDiS
template
<
class
Container
>
class
TreeContainerVectorBackend
{
using
Self
=
TreeContainerVectorBackend
;
template
<
class
C
>
static
constexpr
decltype
(
auto
)
accessByTreePath
(
C
&&
container
,
const
Dune
::
TypeTree
::
HybridTreePath
<>&
path
)
{
...
...
@@ -90,23 +94,22 @@ namespace AMDiS
static
constexpr
decltype
(
auto
)
accessByTreePath
(
C
&&
container
,
const
Dune
::
TypeTree
::
HybridTreePath
<
T
...
>&
path
)
{
auto
head
=
Dune
::
TypeTree
::
treePathEntry
(
path
,
Dune
::
Indices
::
_0
);
auto
tailPath
=
Tools
::
apply_indices
([
&
](
auto
...
i
)
{
using
namespace
Dune
::
TypeTree
;
return
hybridTreePath
(
treePathEntry
(
path
,
index_t
<
i
.
value
+
1
>
{})...);
},
index_t
<
sizeof
...(
T
)
-
1
>
{});
return
accessByTreePath
(
container
[
head
],
tailPath
);
return
accessByTreePath
(
container
[
head
],
pop_front
(
path
));
}
public:
TreeContainerVectorBackend
(
Container
&&
container
)
:
container_
(
std
::
move
(
container
))
{}
TreeContainerVectorBackend
()
=
default
;
TreeContainerVectorBackend
(
Tree
Container
VectorBackend
&&
oth
er
)
:
container_
(
std
::
move
(
other
.
container
_
))
TreeContainerVectorBackend
(
Container
&&
contain
er
)
:
container_
(
std
::
move
(
container
))
{}
TreeContainerVectorBackend
(
const
Self
&
)
=
default
;
TreeContainerVectorBackend
(
Self
&&
)
=
default
;
Self
&
operator
=
(
const
Self
&
)
=
default
;
Self
&
operator
=
(
Self
&&
)
=
default
;
template
<
class
...
T
>
decltype
(
auto
)
operator
[](
const
Dune
::
TypeTree
::
HybridTreePath
<
T
...
>&
path
)
const
{
...
...
@@ -129,6 +132,16 @@ namespace AMDiS
return
container_
;
}
bool
operator
==
(
TreeContainerVectorBackend
const
&
other
)
const
{
return
container_
==
other
.
container_
;
}
bool
operator
!=
(
TreeContainerVectorBackend
const
&
other
)
const
{
return
container_
!=
other
.
container_
;
}
private:
Container
container_
;
};
...
...
test/CMakeLists.txt
View file @
59e7bf37
...
...
@@ -54,3 +54,6 @@ dune_add_test(SOURCES StringTest.cpp
dune_add_test
(
SOURCES TreeDataTest.cpp
LINK_LIBRARIES amdis
)
dune_add_test
(
SOURCES TreeContainerTest.cpp
LINK_LIBRARIES amdis
)
test/TreeContainerTest.cpp
0 → 100644
View file @
59e7bf37
#include <dune/grid/yaspgrid.hh>
#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <amdis/typetree/Traversal.hpp>
#include <amdis/typetree/TreeContainer.hpp>
#include "Tests.hpp"
using
namespace
AMDiS
;
int
main
()
{
Dune
::
YaspGrid
<
2
>
grid
({
1.0
,
1.0
},
{
1
,
1
});
auto
gridView
=
grid
.
leafGridView
();
using
namespace
Dune
::
Functions
::
BasisFactory
;
auto
basis
=
makeBasis
(
gridView
,
composite
(
power
<
2
>
(
lagrange
<
2
>
()),
lagrange
<
1
>
()
));
auto
localView
=
basis
.
localView
();
auto
const
&
tree
=
localView
.
tree
();
auto
c1
=
makeTreeContainer
<
double
>
(
tree
);
auto
c2
=
makeTreeContainer
<
decltype
(
c1
)
>
(
tree
);
auto
c3
=
makeTreeContainer
(
tree
,
[
&
](
auto
const
&
)
{
return
makeTreeContainer
<
double
>
(
tree
);
});
// fill 1d treeContainer with data
for_each_leaf_node
(
tree
,
[
&
](
auto
const
&
node
,
auto
tp
)
{
c1
[
tp
]
=
double
(
node
.
treeIndex
());
});
// copy construction
auto
c4
=
c1
;
AMDIS_TEST
(
c4
==
c1
);
// fill 2d treeContainer with data
for_each_leaf_node
(
tree
,
[
&
](
auto
const
&
row_node
,
auto
row_tp
)
{
for_each_leaf_node
(
tree
,
[
&
](
auto
const
&
col_node
,
auto
col_tp
)
{
c3
[
row_tp
][
col_tp
]
=
double
(
row_node
.
treeIndex
()
+
col_node
.
treeIndex
());
});
});
// copy construction
auto
c5
=
c3
;
AMDIS_TEST
(
c5
==
c3
);
// copy-assignment of container
c2
=
c3
;
AMDIS_TEST
(
c2
==
c3
);
return
report_errors
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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