3 #include <dune/common/typeutilities.hh> 4 #include <dune/common/version.hh> 5 #include <dune/grid/utility/structuredgridfactory.hh> 9 template <
class Gr
idType>
10 struct CubedWrapper :
public GridType {};
13 template <
class Gr
idType>
14 class GridFactory<CubedWrapper<
GridType>>
17 using Self = GridFactory;
19 using ctype =
typename GridType::ctype;
21 enum { dim = GridType::dimension };
22 enum { dimworld = GridType::dimensionworld };
25 template <
class... Args, disableCopyMove<Self, Args...> = 0>
26 GridFactory (Args&&... args)
27 : factory_(
std::make_shared<GridFactory<
GridType>>(
std::forward<Args>(args)...))
30 GridFactory (GridFactory<GridType>& factory)
31 : factory_(stackobject_to_shared_ptr(factory))
35 void insertVertex (
const FieldVector<ctype,dimworld>& pos)
override 37 factory_->insertVertex(pos);
47 void insertElement (
const GeometryType& type,
48 const std::vector<unsigned int>& vertices)
override 51 static const auto reference_cubes = std::make_tuple(
52 std::array<std::array<int,2>, 1>{std::array<int,2>{0,1}},
53 std::array<std::array<int,3>, 2>{std::array<int,3>{3,0,1}, std::array<int,3>{0,3,2}},
54 std::array<std::array<int,4>, 6>{std::array<int,4>{0,7,3,1}, std::array<int,4>{0,7,5,1},
55 std::array<int,4>{0,7,5,4}, std::array<int,4>{0,7,3,2},
56 std::array<int,4>{0,7,6,2}, std::array<int,4>{0,7,6,4}} );
58 assert(type == GeometryTypes::cube(dim));
60 auto const& simplices = std::get<dim-1>(reference_cubes);
61 thread_local std::vector<unsigned int> corners(dim+1);
62 for (
auto const& simplex : simplices) {
63 for (std::size_t i = 0; i < simplex.size(); ++i)
64 corners[i] = vertices[simplex[i]];
66 factory_->insertElement(GeometryTypes::simplex(dim), corners);
70 using Super::insertElement;
74 void insertBoundarySegment (
const std::vector<unsigned int>& vertices)
override 76 factory_->insertBoundarySegment(vertices);
79 using Super::insertBoundarySegment;
82 std::unique_ptr<GridType> createGrid ()
override 84 return factory_->createGrid();
88 std::shared_ptr<GridFactory<GridType>> factory_;
96 template <
class Gr
idType>
99 using ctype =
typename GridType::ctype;
101 enum { dim = GridType::dimension };
102 enum { dimworld = GridType::dimensionworld };
106 static std::unique_ptr<GridType>
createSimplexGrid (Dune::GridFactory<GridType>& originalFactory,
107 const Dune::FieldVector<ctype,dimworld>& lowerLeft,
108 const Dune::FieldVector<ctype,dimworld>& upperRight,
109 const std::array<unsigned int,dim>& numElements)
111 Dune::GridFactory<Dune::CubedWrapper<GridType>> factory(originalFactory);
112 Dune::StructuredGridFactory<Dune::CubedWrapper<GridType>>::createCubeGrid(factory, lowerLeft, upperRight, numElements);
113 return std::unique_ptr<GridType>(factory.createGrid());
117 static std::unique_ptr<GridType>
createSimplexGrid (
const Dune::FieldVector<ctype,dimworld>& lowerLeft,
118 const Dune::FieldVector<ctype,dimworld>& upperRight,
119 const std::array<unsigned int,dim>& numElements)
121 Dune::GridFactory<Dune::CubedWrapper<GridType>> factory;
122 Dune::StructuredGridFactory<Dune::CubedWrapper<GridType>>::createCubeGrid(factory, lowerLeft, upperRight, numElements);
123 return std::unique_ptr<GridType>(factory.createGrid());
Definition: AdaptiveGrid.hpp:373
Definition: FieldMatVec.hpp:12
Definition: AdaptBase.hpp:6
static std::unique_ptr< GridType > createSimplexGrid(Dune::GridFactory< GridType > &originalFactory, const Dune::FieldVector< ctype, dimworld > &lowerLeft, const Dune::FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &numElements)
insert structured simplex grid into grid factory
Definition: MacroGridFactory.hpp:106
static std::unique_ptr< GridType > createSimplexGrid(const Dune::FieldVector< ctype, dimworld > &lowerLeft, const Dune::FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &numElements)
Create a structured simplex grid.
Definition: MacroGridFactory.hpp:117
Definition: MacroGridFactory.hpp:97