7#ifndef DUNE_FUFEM_UTILITIES_GRIDCONSTRUCTION_HH
8#define DUNE_FUFEM_UTILITIES_GRIDCONSTRUCTION_HH
14#include <dune/grid/common/gridfactory.hh>
31template <
class Gr
idType,
int dim>
34template <
class Gr
idType>
37 const static int dim=GridType::dimension;
38 using ctype =
typename GridType::ctype;
43 if (type ==
"interval")
44 return createInterval(config);
51 FV lower = config.
get<
FV>(
"lowerCorner");
52 FV upper = config.
get<
FV>(
"upperCorner");
56 for (
int i=0; i<
dim; i++)
57 size[i] = (upper[i]-lower[i])/((
ctype) nElements[i]);
62 for(
ctype x=lower[0]; x<=upper[0]; x+=
size[0])
67 for (
unsigned i=0;i<nElements[0]; i++) {
68 factory.
insertElement(Dune::GeometryTypes::line, E({i, i+1}));
76template <
class Gr
idType>
79 const static int dim=GridType::dimension;
80 using ctype =
typename GridType::ctype;
92 if (type ==
"rectangle")
93 return createRectangle(config);
94 else if (type ==
"circle")
103 FV lower = config.
get<
FV>(
"lowerCorner");
104 FV upper = config.
get<
FV>(
"upperCorner");
107 for (
int i=0; i<
dim; i++)
108 size[i] = (upper[i]-lower[i])/((
ctype) nElements[i]);
113 for(
unsigned i=0; i<=nElements[0]; i++)
114 for(
unsigned j=0; j<=nElements[1]; j++)
118 bool tetra = config.
get<
bool>(
"tetrahedral");
120 gt = Dune::GeometryTypes::simplex(
dim);
125 unsigned nY = nElements[1]+1;
127 for (
unsigned i=0;i<nElements[0]; i++) {
128 for (
unsigned j=0;j<nElements[1]; j++) {
132 factory.
insertElement(gt,E({i*nY+j, (i+1)*nY + j, i*nY + j+1}));
133 factory.
insertElement(gt,E({(i+1)*nY+j+1, i*nY + j+1, (i+1)*nY + j}));
136 i*nY + j+1, (i+1)*nY + j+1}));
145 return ::createCircle<GridType>(config.
get<
FV>(
"center"), config.
get<
ctype>(
"radius"));
150template <
class Gr
idType>
153 const static int dim=GridType::dimension;
154 using ctype =
typename GridType::ctype;
166 if (type ==
"tubeSegment")
167 return createTubeSegment(config);
168 else if (type ==
"sphere")
169 return createSphere(config);
170 else if (type ==
"cuboid")
171 return createCuboid(config);
178 return makeTubeSegment3D<GridType>(config.
get<
FV>(
"center"), config.
get<
ctype>(
"thickness"),
181 config.
get<
unsigned>(
"nElementRing"), config.
get<
unsigned>(
"nElementLength"),
182 config.
get<
bool>(
"closeTube"), config.
get<
size_t>(
"axis"),
183 config.
get<
bool>(
"tetrahedra"), config.
get<
bool>(
"parameterizedBoundary"));
191 return makeSphereOnOctahedron<GridType>(config.
get<
FV>(
"center"),
201 FV lower = config.
get<
FV>(
"lowerCorner");
202 FV upper = config.
get<
FV>(
"upperCorner");
205 for (
int i=0; i<
dim; i++)
206 size[i] = (upper[i]-lower[i])/((
ctype) nElements[i]);
211 for(
ctype x=lower[0]; x<=upper[0]; x+=
size[0])
212 for(
ctype y=lower[1]; y<=upper[1]; y+=
size[1])
213 for(
ctype z=lower[2]; z<=upper[2]; z+=
size[2])
217 bool tetra = config.
get<
bool>(
"tetrahedral");
219 gt = Dune::GeometryTypes::tetrahedron;
221 gt = Dune::GeometryTypes::cube(
dim);
226 unsigned nZY = (nElements[1]+1)*(nElements[2]+1);
228 for (
unsigned i=0;i<nElements[0]; i++) {
229 for (
unsigned j=0;j<nElements[1]; j++) {
230 for (
unsigned k=0;k<nElements[2]; k++) {
233 E hexa = {i*nZY + j*(nElements[2] + 1) + k, (i+1)*nZY + j*(nElements[2]+1) + k,
234 i*nZY + (j+1)*(nElements[2]+1) + k, (i+1)*nZY + (j+1)*(nElements[2]+1) + k,
235 i*nZY + j*(nElements[2]+1) + k + 1, (i+1)*nZY + j*(nElements[2]+1) + k + 1,
236 i*nZY + (j+1)*(nElements[2]+1) + k + 1, (i+1)*nZY + (j+1)*(nElements[2]+1) + k + 1};
242 tet={hexa[0],hexa[1],hexa[3],hexa[7]};
244 tet={hexa[0],hexa[5],hexa[1],hexa[7]};
246 tet={hexa[0],hexa[4],hexa[5],hexa[7]};
248 tet={hexa[0],hexa[4],hexa[6],hexa[7]};
250 tet={hexa[0],hexa[6],hexa[2],hexa[7]};
252 tet={hexa[0],hexa[3],hexa[2],hexa[7]};
#define DUNE_THROW(E,...)
std::unique_ptr< GridType > createCircle(const Dune::FieldVector< double, 2 > ¢er, double r)
Definition makehalfcircle.hh:19
std::string get(const std::string &key, const std::string &defaultValue) const
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
virtual std::unique_ptr< GridType > createGrid()
A factory class that can create several often used grids like cuboids, spheres and tubes from a param...
Definition gridconstruction.hh:32
typename GridType::ctype ctype
Definition gridconstruction.hh:38
static std::unique_ptr< GridType > createGrid(const ParameterTree &config)
Definition gridconstruction.hh:41
static std::unique_ptr< GridType > createInterval(const ParameterTree &config)
Definition gridconstruction.hh:49
static std::unique_ptr< GridType > createGrid(const ParameterTree &config)
Create various grids.
Definition gridconstruction.hh:89
typename GridType::ctype ctype
Definition gridconstruction.hh:80
static std::unique_ptr< GridType > createCircle(const ParameterTree &config)
Create a circular grid.
Definition gridconstruction.hh:144
static std::unique_ptr< GridType > createRectangle(const ParameterTree &config)
Create a rectangular grid.
Definition gridconstruction.hh:101
static std::unique_ptr< GridType > createTubeSegment(const ParameterTree &config)
Definition gridconstruction.hh:176
static std::unique_ptr< GridType > createGrid(const ParameterTree &config)
Create various grids.
Definition gridconstruction.hh:163
typename GridType::ctype ctype
Definition gridconstruction.hh:154
static std::unique_ptr< GridType > createCuboid(const ParameterTree &config)
Create a rectangular grid.
Definition gridconstruction.hh:199
static std::unique_ptr< GridType > createSphere(const ParameterTree &config)
Create a sphere grid.
Definition gridconstruction.hh:190