Commit d64976bf authored by Müller, Felix's avatar Müller, Felix
Browse files

Remove makeGlobalBasis

parent ccde07a0
...@@ -91,12 +91,12 @@ namespace AMDiS ...@@ -91,12 +91,12 @@ namespace AMDiS
static auto create(std::string const& name, GridView const& gridView) static auto create(std::string const& name, GridView const& gridView)
{ {
return makeGlobalBasis(name, gridView, PreBasisCreator::create()); return ParallelGlobalBasis(name, gridView, PreBasisCreator::create());
} }
static auto create(GridView const& gridView) static auto create(GridView const& gridView)
{ {
return makeGlobalBasis(gridView, PreBasisCreator::create()); return ParallelGlobalBasis(gridView, PreBasisCreator::create());
} }
using GlobalBasis = decltype(create(std::declval<GridView>())); using GlobalBasis = decltype(create(std::declval<GridView>()));
......
...@@ -37,6 +37,13 @@ ...@@ -37,6 +37,13 @@
namespace AMDiS namespace AMDiS
{ {
template <class PreBasisFactory>
using MultiIndex = std::conditional_t<
(remove_cvref_t<PreBasisFactory>::requiredMultiIndexSize == 1),
Dune::Functions::FlatMultiIndex<std::size_t>,
Dune::ReservedVector<std::size_t, remove_cvref_t<PreBasisFactory>::requiredMultiIndexSize>>;
/** /**
* \brief Parallel global basis defined on a (sequential) pre-basis * \brief Parallel global basis defined on a (sequential) pre-basis
* *
...@@ -92,11 +99,11 @@ namespace AMDiS ...@@ -92,11 +99,11 @@ namespace AMDiS
, comm_(CommunicationCreator<Comm>::create(static_cast<Super const&>(*this), name + "->solver")) , comm_(CommunicationCreator<Comm>::create(static_cast<Super const&>(*this), name + "->solver"))
{} {}
/// Construct this global basis with empty name /// Construct this global basis with a preBasisFactory
template <class... Args, template <class PBF>
Dune::Functions::enableIfConstructible<PreBasis, Args...> = 0> ParallelGlobalBasis(std::string const& name, GridView const& gridView, PBF&& preBasisFactory)
ParallelGlobalBasis(Grid const& grid, Args&&... args) : ParallelGlobalBasis(name, gridView.grid(),
: ParallelGlobalBasis(std::string(""), grid, FWD(args)...) preBasisFactory.template makePreBasis<MultiIndex<PBF>>(gridView))
{} {}
/// Converting constructor from dune-functions style basis. /// Converting constructor from dune-functions style basis.
...@@ -105,10 +112,16 @@ namespace AMDiS ...@@ -105,10 +112,16 @@ namespace AMDiS
* argument and a new communication object is built. * argument and a new communication object is built.
*/ */
template <class GB_, template <class GB_,
Dune::disableCopyMove<Self, GB_> = 0,
REQUIRES(Concepts::GlobalBasis<GB_,GridView>)> REQUIRES(Concepts::GlobalBasis<GB_,GridView>)>
ParallelGlobalBasis(GB_&& from) ParallelGlobalBasis(std::string const& name, GB_&& from)
: ParallelGlobalBasis(std::string(""), from.gridView().grid(), from.preBasis()) : ParallelGlobalBasis(name, from.gridView().grid(), from.preBasis())
{}
/// Construct this global basis with empty name
template <class Arg, class... Args,
REQUIRES(!std::is_same_v<std::string, remove_cvref_t<Arg>>)>
ParallelGlobalBasis(Arg&& arg, Args&&... args)
: ParallelGlobalBasis(std::string(""), FWD(arg), FWD(args)...)
{} {}
/// Copy constructor /// Copy constructor
...@@ -175,29 +188,15 @@ namespace AMDiS ...@@ -175,29 +188,15 @@ namespace AMDiS
}; };
template <class MultiIndex, class GV, class PBF> // Deduction guides
auto makeGlobalBasis(std::string const& name, GV const& gridView, PBF&& preBasisFactory)
{
auto preBasis = preBasisFactory.template makePreBasis<MultiIndex>(gridView);
return ParallelGlobalBasis<TYPEOF(preBasis)>(name, gridView.grid(), std::move(preBasis));
}
template <class GV, class PBF> template <class GV, class PBF>
auto makeGlobalBasis(std::string const& name, GV const& gridView, PBF&& preBasisFactory) ParallelGlobalBasis(std::string const& name, GV const& gridView, PBF&& preBasisFactory)
{ -> ParallelGlobalBasis<decltype(
using RawPreBasisFactory = remove_cvref_t<PBF>; preBasisFactory.template makePreBasis<MultiIndex<PBF>>(gridView))>;
using MultiIndex = std::conditional_t<
(RawPreBasisFactory::requiredMultiIndexSize == 1),
Dune::Functions::FlatMultiIndex<std::size_t>,
Dune::ReservedVector<std::size_t, RawPreBasisFactory::requiredMultiIndexSize>>;
return makeGlobalBasis<MultiIndex, GV, PBF>(name, gridView, FWD(preBasisFactory));
}
template <class GV, class PBF> template <class GV, class PBF>
auto makeGlobalBasis(GV const& gridView, PBF&& preBasisFactory) ParallelGlobalBasis(GV const& gridView, PBF&& preBasisFactory)
{ -> ParallelGlobalBasis<decltype(
return makeGlobalBasis(std::string(""), gridView, FWD(preBasisFactory)); preBasisFactory.template makePreBasis<MultiIndex<PBF>>(gridView))>;
}
} // end namespace AMDiS } // end namespace AMDiS
...@@ -109,12 +109,12 @@ using Grid = Dune::YaspGrid<2>; ...@@ -109,12 +109,12 @@ using Grid = Dune::YaspGrid<2>;
Grid grid({1.0, 1.0}, {2, 2}); Grid grid({1.0, 1.0}, {2, 2});
using namespace Dune::Functions::BasisFactory; using namespace Dune::Functions::BasisFactory;
auto basis1 = makeGlobalBasis(grid.leafGridView(), lagrange<2>()); ParallelGlobalBasis basis1(grid.leafGridView(), lagrange<2>());
DOFVector<decltype(basis1)> vec0(basis1); DOFVector<decltype(basis1)> vec0(basis1);
DOFVector vec1(basis1); // C++17 only DOFVector vec1(basis1); // C++17 only
auto basis2 = makeUniquePtr(makeGlobalBasis(grid.leafGridView(), lagrange<2>())); auto basis2 = makeUniquePtr(ParallelGlobalBasis(grid.leafGridView(), lagrange<2>()));
DOFVector<Underlying_t<decltype(basis2)>> vec2(std::move(basis2)); DOFVector<Underlying_t<decltype(basis2)>> vec2(std::move(basis2));
``` ```
...@@ -251,7 +251,7 @@ underlying type is either the `remove_cvref_t` for references, or the pointed-to ...@@ -251,7 +251,7 @@ underlying type is either the `remove_cvref_t` for references, or the pointed-to
using namespace Dune::Functions::BasisFactory; using namespace Dune::Functions::BasisFactory;
// pass a reference to the basis // pass a reference to the basis
auto basis1 = makeGlobalBasis(gridView, lagrange<2>()); ParallelGlobalBasis basis1(gridView, lagrange<2>());
auto vec1 = makeDOFVector<double>(basis1); auto vec1 = makeDOFVector<double>(basis1);
// pass a smart pointer // pass a smart pointer
...@@ -391,7 +391,7 @@ Returns the const (1) or mutable (2) sub-range view of the stored DOFVector. ...@@ -391,7 +391,7 @@ Returns the const (1) or mutable (2) sub-range view of the stored DOFVector.
#### Example #### Example
```c++ ```c++
auto basis = makeGlobalBasis(gridView, power<3>(lagrange<1>())); ParallelGlobalBasis basis(gridView, power<3>(lagrange<1>()));
auto vec = makeDOFVector(basis); auto vec = makeDOFVector(basis);
auto df = makeDiscreteFunction(vec); auto df = makeDiscreteFunction(vec);
...@@ -452,7 +452,7 @@ Note, the range type of the expression must be compatible with the `Range` type ...@@ -452,7 +452,7 @@ Note, the range type of the expression must be compatible with the `Range` type
#### Example #### Example
```c++ ```c++
auto basis = makeGlobalBasis(gridView, power<3>(lagrange<1>())); ParallelGlobalBasis basis(gridView, power<3>(lagrange<1>()));
auto vec = makeDOFVector(basis); auto vec = makeDOFVector(basis);
auto df1 = vec.child(); auto df1 = vec.child();
...@@ -504,7 +504,7 @@ thereby given by the type of `makeTreePath(preTreePath)`. ...@@ -504,7 +504,7 @@ thereby given by the type of `makeTreePath(preTreePath)`.
using namespace Dune::Functions::BasisFactory; using namespace Dune::Functions::BasisFactory;
// pass a reference to the basis // pass a reference to the basis
auto basis = makeGlobalBasis(gridView, power<2>(lagrange<2>())); ParallelGlobalBasis basis(gridView, power<2>(lagrange<2>()));
auto vec = makeDOFVector<double>(basis1); auto vec = makeDOFVector<double>(basis1);
auto df1 = makeDiscreteFunction(vec); auto df1 = makeDiscreteFunction(vec);
...@@ -512,4 +512,3 @@ auto df2 = makeDiscreteFunction(vec, 1); ...@@ -512,4 +512,3 @@ auto df2 = makeDiscreteFunction(vec, 1);
auto df3 = makeDiscreteFunction(vec, _1); auto df3 = makeDiscreteFunction(vec, _1);
auto df4 = makeDiscreteFunction(vec, Dune::TypeTree::hybridTreePath(0)); auto df4 = makeDiscreteFunction(vec, Dune::TypeTree::hybridTreePath(0));
``` ```
...@@ -119,7 +119,7 @@ using namespace Dune::Functions::BasisFactory; ...@@ -119,7 +119,7 @@ using namespace Dune::Functions::BasisFactory;
// create a power basis of 3 lagrange bases with local polynomial degree 2 // create a power basis of 3 lagrange bases with local polynomial degree 2
// on the leaf elements of the grid // on the leaf elements of the grid
auto basis1 = makeGlobalBasis(grid2->leafGridView(), power<3>(lagrange<2>())); ParallelGlobalBasis basis1(grid2->leafGridView(), power<3>(lagrange<2>()));
``` ```
or by using some predefined wrappers: or by using some predefined wrappers:
...@@ -139,8 +139,7 @@ auto basis2 = BasisCreator::create(grid2->leafGridView()); ...@@ -139,8 +139,7 @@ auto basis2 = BasisCreator::create(grid2->leafGridView());
grid refinement or by repartitioning. Additionally, it stores a communication object grid refinement or by repartitioning. Additionally, it stores a communication object
to construct global DOFMappings for distributed data structured. to construct global DOFMappings for distributed data structured.
This `ParallelGlobalBasis` is automatically constructed with `makeGlobalBasis` and This `ParallelGlobalBasis` can be converted from a `DefaultGlobalBasis` of dune-functions.
can be converted from a `DefaultGlobalBasis` of dune-functions.
A [`DOFVector`](../reference/DOFVector.md) takes a global basis and provides the coefficient vector as data member. A [`DOFVector`](../reference/DOFVector.md) takes a global basis and provides the coefficient vector as data member.
......
...@@ -72,7 +72,7 @@ int main(int argc, char** argv) ...@@ -72,7 +72,7 @@ int main(int argc, char** argv)
auto preBasis = composite(power<2>(lagrange<2>(), flatInterleaved()), auto preBasis = composite(power<2>(lagrange<2>(), flatInterleaved()),
lagrange<1>(), lagrange<1>(),
flatLexicographic()); flatLexicographic());
auto basis = makeGlobalBasis(gridView, preBasis); ParallelGlobalBasis basis(gridView, preBasis);
using Basis = decltype(basis); using Basis = decltype(basis);
......
...@@ -22,9 +22,9 @@ void test() ...@@ -22,9 +22,9 @@ void test()
// use T as range type for basis // use T as range type for basis
using namespace Dune::Functions::BasisFactory; using namespace Dune::Functions::BasisFactory;
#if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7) #if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7)
auto basis = makeGlobalBasis(grid.leafGridView(), power<1>(lagrange<1>(), flatLexicographic())); ParallelGlobalBasis basis(grid.leafGridView(), power<1>(lagrange<1>(), flatLexicographic()));
#else #else
auto basis = makeGlobalBasis(grid.leafGridView(), power<1>(lagrange<1,T>(), flatLexicographic())); ParallelGlobalBasis basis(grid.leafGridView(), power<1>(lagrange<1,T>(), flatLexicographic()));
#endif #endif
using Basis = decltype(basis); using Basis = decltype(basis);
......
Supports Markdown
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