Commit 06c12acf authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'feature/metadata-extraction-concepts' into 'feature/metadata-extraction'

Feature/metadata extraction concepts

See merge request !2797
parents ba86ee00 8c2aa4fe
Pipeline #7716 waiting for manual action with stages
......@@ -33,6 +33,8 @@
#include <dune/common/hybridutilities.hh>
#include <dune/common/indices.hh>
#include <dune/common/concept.hh>
#include <dune/grid/common/gridview.hh>
#include "dumux/io/json/json.hpp"
......@@ -45,58 +47,70 @@
#include "dumux/discretization/basegridgeometry.hh"
#include "dumux/discretization/fvgridvariables.hh"
namespace Dumux {
namespace Dumux::MetaData {
namespace Detail {
namespace Concept {
//! Helper to determine whether a given type inherits from BaseGridGeometry
struct isGridGeometry
//! Concept of GridGeometry
struct GridGeometry
{
template<typename ...Args>
void isConstructable(const BaseGridGeometry<Args...>&)
{}
template<class GridGeometry>
auto operator()(GridGeometry&& gg)
-> decltype(isConstructable(gg))
{}
template<class GG>
auto require(const GG& gg) -> decltype(
gg.isPeriodic(),
gg.numScv(),
gg.numScvf(),
gg.numBoundaryScvf(),
gg.numDofs(),
GG::discMethod
);
};
//! Helper to determine whether a given type inherits from FVGridVariables
struct isGridVariables
//! Concept of GridVariables
struct GridVariables
{
template<typename ...Args>
void isConstructable(const FVGridVariables<Args...>&)
{}
template<class GridVariables>
auto operator()(GridVariables&& gv)
-> decltype(isConstructable(gv))
{}
template<class GV>
auto require(const GV& gv) -> decltype(
Dune::Concept::requireType<typename GV::GridVolumeVariables>(),
Dune::Concept::requireType<typename GV::VolumeVariables>(),
Dune::Concept::requireType<typename GV::GridFluxVariablesCache>()
);
};
std::string removeNamespace(std::string&& s)
//! Concept of GridView
struct GridView
{
std::size_t last = s.find_last_of("::");
template<class GV>
auto require(const GV& gv) -> decltype(
Dune::Concept::requireBaseOf<Dune::GridView<typename GV::Traits>, GV>()
);
};
if(last != std::string::npos)
s.erase(0, last+1);
} // end namespace Concept
return std::move(s);
}
namespace Detail {
template<class TTagTuple, class Collector>
void collectTypeTagsFromTuple(Collector& collector, int depth=0, int parentBranch=-1)
{
using namespace Dune::Hybrid;
forEach(std::make_index_sequence<std::tuple_size_v<TTagTuple>>{}, [&](auto i)
std::string removeNamespace(std::string&& s)
{
using type = typename std::tuple_element<i, TTagTuple>::type;
collector.push_back(std::tuple<int, int, std::string>{depth, parentBranch, removeNamespace(Dune::className<type>())});
if constexpr (Dumux::Properties::Detail::hasParentTypeTag<type>(int{}))
collectTypeTagsFromTuple<typename type::InheritsFrom>(collector, int{depth+1}, i);
});
}
std::size_t last = s.find_last_of("::");
if(last != std::string::npos)
s.erase(0, last+1);
return std::move(s);
}
template<class TTagTuple, class Collector>
void collectTypeTagsFromTuple(Collector& collector, int depth=0, int parentBranch=-1)
{
using namespace Dune::Hybrid;
forEach(std::make_index_sequence<std::tuple_size_v<TTagTuple>>{}, [&](auto i)
{
using type = typename std::tuple_element<i, TTagTuple>::type;
collector.push_back(std::tuple<int, int, std::string>{depth, parentBranch, removeNamespace(Dune::className<type>())});
if constexpr (Dumux::Properties::Detail::hasParentTypeTag<type>(int{}))
collectTypeTagsFromTuple<typename type::InheritsFrom>(collector, int{depth+1}, i);
});
}
} // end namespace Detail
......@@ -135,6 +149,12 @@ public:
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)
{
std::size_t first = s.find("<");
......@@ -170,18 +190,12 @@ void collectMetaData(Collector& collector, const FVAssembler<TypeTag, diffmethod
template<class Collector, class GridGeometry>
auto collectMetaData(Collector& collector, const GridGeometry& gg, bool hideTemplates = true)
-> typename std::enable_if_t<decltype(isValid(Detail::isGridGeometry())(gg))::value, void>
-> typename std::enable_if_t<Dune::models<Concept::GridGeometry, GridGeometry>()>
{
using GridView = typename GridGeometry::GridView;
auto& obj = collector["GridGeometry"];
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["DiscretisationMethod"] = toString(GridGeometry::discMethod);
obj["MaxElementStencilSize"] = GridGeometry::maxElementStencilSize;
obj["NumScvs"] = gg.numScv();
obj["NumScvfs"] = gg.numScvf();
obj["SumBoundaryScvfs"] = gg.numBoundaryScvf();
......@@ -190,10 +204,29 @@ auto collectMetaData(Collector& collector, const GridGeometry& gg, bool hideTemp
template<class Collector, class GridVariables>
auto collectMetaData(Collector& collector, const GridVariables& gv, bool hideTemplates = true)
-> typename std::enable_if_t<decltype(isValid(Detail::isGridVariables())(gv))::value, void>
-> typename std::enable_if_t<Dune::models<Concept::GridVariables, GridVariables>()>
{
auto& obj = collector["GridVariables"];
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>
auto collectMetaData(Collector& collector, const GridView& gridView, bool hideTemplates = true)
-> typename std::enable_if_t<Dune::models<Concept::GridView, GridView>()>
{
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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment