Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
0d3fc440
Commit
0d3fc440
authored
Aug 25, 2021
by
Martin Schneider
Browse files
[metadata] Use dune concepts for metadata class
parent
ba86ee00
Changes
1
Show whitespace changes
Inline
Side-by-side
dumux/common/metadata.hh
View file @
0d3fc440
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#include <dune/common/hybridutilities.hh>
#include <dune/common/hybridutilities.hh>
#include <dune/common/indices.hh>
#include <dune/common/indices.hh>
#include <dune/common/concept.hh>
#include <dune/grid/common/gridview.hh>
#include "dumux/io/json/json.hpp"
#include "dumux/io/json/json.hpp"
...
@@ -47,47 +49,71 @@
...
@@ -47,47 +49,71 @@
namespace
Dumux
{
namespace
Dumux
{
namespace
Detail
{
namespace
Concept
{
//!
Helper to determine whether a given type inherits from Base
GridGeometry
//!
Concept of
GridGeometry
struct
is
GridGeometry
struct
GridGeometry
{
{
template
<
typename
...
Args
>
template
<
class
GG
>
void
isConstructable
(
const
BaseGridGeometry
<
Args
...
>&
)
auto
require
(
const
GG
&
gg
)
->
decltype
(
{}
gg
.
isPeriodic
(),
gg
.
numScv
(),
template
<
class
GridGeometry
>
gg
.
numScvf
(),
auto
operator
()(
GridGeometry
&&
gg
)
gg
.
numBoundaryScvf
(),
->
decltype
(
isConstructable
(
gg
))
gg
.
numDofs
(),
{}
GG
::
discMethod
);
};
};
//! Helper to determine whether a given type inherits from FVGridVariables
template
<
class
GG
>
struct
isGridVariables
static
constexpr
bool
isGridGeometry
()
{
return
Dune
::
models
<
GridGeometry
,
GG
>
();
}
//! Concept of GridVariables
struct
GridVariables
{
{
template
<
typename
...
Args
>
template
<
class
GV
>
void
isConstructable
(
const
FVGridVariables
<
Args
...
>&
)
auto
require
(
const
GV
&
gv
)
->
decltype
(
{}
Dune
::
Concept
::
requireType
<
typename
GV
::
GridVolumeVariables
>
(),
Dune
::
Concept
::
requireType
<
typename
GV
::
VolumeVariables
>
(),
template
<
class
GridVariables
>
Dune
::
Concept
::
requireType
<
typename
GV
::
GridFluxVariablesCache
>
()
auto
operator
()(
GridVariables
&&
gv
)
);
->
decltype
(
isConstructable
(
gv
))
{}
};
};
std
::
string
removeNamespace
(
std
::
string
&&
s
)
template
<
class
GV
>
static
constexpr
bool
isGridVariables
()
{
return
Dune
::
models
<
GridVariables
,
GV
>
();
}
//! Concept of GridView
struct
GridView
{
{
template
<
class
GV
>
auto
require
(
const
GV
&
gv
)
->
decltype
(
Dune
::
Concept
::
requireBaseOf
<
Dune
::
GridView
<
typename
GV
::
Traits
>
,
GV
>
()
);
};
template
<
class
GV
>
static
constexpr
bool
isGridView
()
{
return
Dune
::
models
<
GridView
,
GV
>
();
}
}
// end namespace Concept
namespace
Detail
{
std
::
string
removeNamespace
(
std
::
string
&&
s
)
{
std
::
size_t
last
=
s
.
find_last_of
(
"::"
);
std
::
size_t
last
=
s
.
find_last_of
(
"::"
);
if
(
last
!=
std
::
string
::
npos
)
if
(
last
!=
std
::
string
::
npos
)
s
.
erase
(
0
,
last
+
1
);
s
.
erase
(
0
,
last
+
1
);
return
std
::
move
(
s
);
return
std
::
move
(
s
);
}
}
template
<
class
TTagTuple
,
class
Collector
>
template
<
class
TTagTuple
,
class
Collector
>
void
collectTypeTagsFromTuple
(
Collector
&
collector
,
int
depth
=
0
,
int
parentBranch
=-
1
)
void
collectTypeTagsFromTuple
(
Collector
&
collector
,
int
depth
=
0
,
int
parentBranch
=-
1
)
{
{
using
namespace
Dune
::
Hybrid
;
using
namespace
Dune
::
Hybrid
;
forEach
(
std
::
make_index_sequence
<
std
::
tuple_size_v
<
TTagTuple
>>
{},
[
&
](
auto
i
)
forEach
(
std
::
make_index_sequence
<
std
::
tuple_size_v
<
TTagTuple
>>
{},
[
&
](
auto
i
)
{
{
...
@@ -96,7 +122,7 @@ void collectTypeTagsFromTuple(Collector& collector, int depth=0, int parentBranc
...
@@ -96,7 +122,7 @@ void collectTypeTagsFromTuple(Collector& collector, int depth=0, int parentBranc
if
constexpr
(
Dumux
::
Properties
::
Detail
::
hasParentTypeTag
<
type
>
(
int
{}))
if
constexpr
(
Dumux
::
Properties
::
Detail
::
hasParentTypeTag
<
type
>
(
int
{}))
collectTypeTagsFromTuple
<
typename
type
::
InheritsFrom
>
(
collector
,
int
{
depth
+
1
},
i
);
collectTypeTagsFromTuple
<
typename
type
::
InheritsFrom
>
(
collector
,
int
{
depth
+
1
},
i
);
});
});
}
}
}
// end namespace Detail
}
// end namespace Detail
...
@@ -135,6 +161,12 @@ public:
...
@@ -135,6 +161,12 @@ public:
return
hideTemplates
?
hideTemplateArguments
(
Dune
::
className
(
c
))
:
Dune
::
className
(
c
);
return
hideTemplates
?
hideTemplateArguments
(
Dune
::
className
(
c
))
:
Dune
::
className
(
c
);
}
}
template
<
class
T
>
static
std
::
string
className
(
bool
hideTemplates
)
{
return
hideTemplates
?
hideTemplateArguments
(
Dune
::
className
<
T
>
())
:
Dune
::
className
<
T
>
();
}
static
std
::
string
hideTemplateArguments
(
std
::
string
&&
s
)
static
std
::
string
hideTemplateArguments
(
std
::
string
&&
s
)
{
{
std
::
size_t
first
=
s
.
find
(
"<"
);
std
::
size_t
first
=
s
.
find
(
"<"
);
...
@@ -168,32 +200,42 @@ void collectMetaData(Collector& collector, const FVAssembler<TypeTag, diffmethod
...
@@ -168,32 +200,42 @@ void collectMetaData(Collector& collector, const FVAssembler<TypeTag, diffmethod
obj
[
"Stationary"
]
=
a
.
isStationaryProblem
();
obj
[
"Stationary"
]
=
a
.
isStationaryProblem
();
}
}
template
<
class
Collector
,
class
GridGeometry
>
template
<
class
Collector
,
class
GridGeometry
,
std
::
enable_if_t
<
Concept
::
isGridGeometry
<
GridGeometry
>(),
int
>
=
0
>
auto
collectMetaData
(
Collector
&
collector
,
const
GridGeometry
&
gg
,
bool
hideTemplates
=
true
)
void
collectMetaData
(
Collector
&
collector
,
const
GridGeometry
&
gg
,
bool
hideTemplates
=
true
)
->
typename
std
::
enable_if_t
<
decltype
(
isValid
(
Detail
::
isGridGeometry
())(
gg
))
::
value
,
void
>
{
{
using
GridView
=
typename
GridGeometry
::
GridView
;
auto
&
obj
=
collector
[
"GridGeometry"
];
auto
&
obj
=
collector
[
"GridGeometry"
];
obj
[
"Type"
]
=
Metadata
::
className
(
gg
,
hideTemplates
);
obj
[
"Type"
]
=
Metadata
::
className
(
gg
,
hideTemplates
);
obj
[
"GridView"
][
"Type"
]
=
Metadata
::
className
(
gg
.
gridView
(),
hideTemplates
);
obj
[
"GridView"
][
"dimension"
]
=
GridView
::
dimension
;
obj
[
"GridView"
][
"dimensionWorld"
]
=
GridView
::
dimensionworld
;
obj
[
"GridView"
][
"Grid"
][
"Type"
]
=
Metadata
::
className
(
gg
.
gridView
().
grid
(),
hideTemplates
);
obj
[
"IsPeriodic"
]
=
gg
.
isPeriodic
();
obj
[
"IsPeriodic"
]
=
gg
.
isPeriodic
();
obj
[
"DiscretisationMethod"
]
=
toString
(
GridGeometry
::
discMethod
);
obj
[
"DiscretisationMethod"
]
=
toString
(
GridGeometry
::
discMethod
);
obj
[
"MaxElementStencilSize"
]
=
GridGeometry
::
maxElementStencilSize
;
obj
[
"NumScvs"
]
=
gg
.
numScv
();
obj
[
"NumScvs"
]
=
gg
.
numScv
();
obj
[
"NumScvfs"
]
=
gg
.
numScvf
();
obj
[
"NumScvfs"
]
=
gg
.
numScvf
();
obj
[
"SumBoundaryScvfs"
]
=
gg
.
numBoundaryScvf
();
obj
[
"SumBoundaryScvfs"
]
=
gg
.
numBoundaryScvf
();
obj
[
"NumDofs"
]
=
gg
.
numDofs
();
obj
[
"NumDofs"
]
=
gg
.
numDofs
();
}
}
template
<
class
Collector
,
class
GridVariables
>
template
<
class
Collector
,
class
GridVariables
,
std
::
enable_if_t
<
Concept
::
isGridVariables
<
GridVariables
>(),
int
>
=
0
>
auto
collectMetaData
(
Collector
&
collector
,
const
GridVariables
&
gv
,
bool
hideTemplates
=
true
)
auto
collectMetaData
(
Collector
&
collector
,
const
GridVariables
&
gv
,
bool
hideTemplates
=
true
)
->
typename
std
::
enable_if_t
<
decltype
(
isValid
(
Detail
::
isGridVariables
())(
gv
))
::
value
,
void
>
{
{
auto
&
obj
=
collector
[
"GridVariables"
];
auto
&
obj
=
collector
[
"GridVariables"
];
obj
[
"Type"
]
=
Metadata
::
className
(
gv
,
hideTemplates
);
obj
[
"Type"
]
=
Metadata
::
className
(
gv
,
hideTemplates
);
obj
[
"GridVolumeVariables"
][
"Type"
]
=
Metadata
::
className
<
typename
GridVariables
::
GridVolumeVariables
>
(
hideTemplates
);
obj
[
"VolumeVariables"
][
"Type"
]
=
Metadata
::
className
<
typename
GridVariables
::
VolumeVariables
>
(
hideTemplates
);
obj
[
"GridFluxVariablesCache"
][
"Type"
]
=
Metadata
::
className
<
typename
GridVariables
::
GridFluxVariablesCache
>
(
hideTemplates
);
}
template
<
class
Collector
,
class
GridView
,
std
::
enable_if_t
<
Concept
::
isGridView
<
GridView
>(),
int
>
=
0
>
auto
collectMetaData
(
Collector
&
collector
,
const
GridView
&
gridView
,
bool
hideTemplates
=
true
)
{
auto
&
obj
=
collector
[
"GridView"
];
obj
[
"Type"
]
=
Metadata
::
className
(
gridView
,
hideTemplates
);
obj
[
"dimension"
]
=
GridView
::
dimension
;
obj
[
"dimensionWorld"
]
=
GridView
::
dimensionworld
;
obj
[
"conforming"
]
=
GridView
::
conforming
;
//obj["Grid"]["Type"] = Metadata::className(gridView.grid(), hideTemplates);
for
(
int
codim
=
0
;
codim
<
GridView
::
dimension
;
++
codim
)
obj
[
"numEntities"
][
"codim "
+
std
::
to_string
(
codim
)
]
=
gridView
.
size
(
codim
);
//TODO parallel runs, i.e. overlapSize() etc.
}
}
template
<
class
TypeTag
,
class
Collector
>
template
<
class
TypeTag
,
class
Collector
>
...
...
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