1 #ifndef DUNE_GRID_UTILITY_TENSORGRIDFACTORY_HH 2 #define DUNE_GRID_UTILITY_TENSORGRIDFACTORY_HH 22 #include <dune/common/fvector.hh> 31 template<
typename Gr
id>
38 template<
typename Gr
id>
42 typedef typename Grid::Traits::CollectiveCommunication
Comm;
52 std::array<std::vector<ctype> , dim>
coords()
const 64 const std::vector<ctype>&
operator[](std::size_t d)
const 80 _coords[d][0] = value;
94 for (
int i = 0; i < n; i++)
95 _coords[d].push_back (_coords[d].back () + h);
109 const ctype h = (end - _coords[d].back ()) / n;
110 for (
int i = 0; i < n - 1; i++)
111 _coords[d].push_back (_coords[d].back () + h);
112 _coords[d].push_back (end);
126 while (_coords[d].back () < end)
127 _coords[d].push_back (_coords[d].back () + h);
143 static_cast<ctype> (0))
147 if (h0 == static_cast<ctype>(0))
148 h = lastInterval (d) * ratio;
149 for (
int i = 0; i < n; i++)
151 _coords[d].push_back (_coords[d].back () + h);
172 if (h0 == static_cast<ctype>(0))
173 h = lastInterval (d) * ratio;
174 while (_coords[d].back () < end)
176 _coords[d].push_back (_coords[d].back () + h);
196 static_cast<ctype> (0),
201 h = lastInterval (d);
202 ctype ratio = newton (n, _coords[d].back (), end, h);
205 h = h * pow (ratio, n - 1);
208 for (
int i = 0; i < n - 1; i++)
210 _coords[d].push_back (_coords[d].back () + h);
213 _coords[d].push_back (end);
219 for (
int i=0; i<
dim; i++)
221 std::cout <<
"Container in direction " << i <<
":" << std::endl <<
"Coordinates: ";
222 for (
auto it = _coords[i].begin(); it != _coords[i].end(); ++it)
223 std::cout << *it <<
" ";
224 std::cout << std::endl <<
"Interval lengths: ";
226 std::vector<ctype> meshsize;
227 for (
auto it = _coords[i].begin(); it != _coords[i].end()-1;)
229 meshsize.push_back(-1.*(*it));
231 meshsize.back() += *it;
234 for (
auto it = meshsize.begin(); it != meshsize.end(); ++it)
235 std::cout << *it <<
" ";
236 std::cout << std::endl <<
"Ratios between interval lengths: ";
238 std::vector<ctype> ratios;
239 for (
auto it = meshsize.begin(); it != meshsize.end() - 1 ;)
240 ratios.push_back((1./(*it)) * *(++it));
242 for (
auto it = ratios.begin(); it != ratios.end(); ++it)
243 std::cout << *it <<
" ";
244 std::cout << std::endl << std::endl << std::endl;
250 void emptyCheck (
int i)
252 if (_coords[i].empty ())
253 _coords[i].push_back (static_cast<ctype> (0));
257 ctype lastInterval (
int d)
259 if (_coords[d].size () < 2)
262 "Not enough elements in coordinate container to deduce interval length in TensorYaspFactory");
264 return _coords[d].back () - _coords[d][_coords[d].size () - 2];
270 ctype newton (
int n, ctype x_s, ctype x_e, ctype h)
272 ctype m = (x_e - x_s) / h;
274 ctype xnew = x_e - x_s;
275 while (
std::abs (xnew - xold) > 1E-8)
279 - (-pow (xold, n) + m * xold - m + 1)
280 / (-n * pow (xold, n - 1) + m);
286 while (
std::abs (xnew - xold) > 1E-8)
290 - (-pow (xold, n) + m * xold - m + 1)
291 / (-n * pow (xold, n - 1) + m);
297 std::array<std::vector<ctype>, dim> _coords;
302 template<
typename Gr
id>
306 typedef typename Grid::Traits::CollectiveCommunication
Comm;
317 if (comm.rank() == 0)
320 std::array<unsigned int, dim> vsizes, esizes;
321 std::size_t size = 1;
322 for (std::size_t i = 0; i<
dim; ++i)
324 vsizes[i] = _factory[i].size();
325 esizes[i] = vsizes[i] - 1;
331 for (std::size_t i=0; i<size; ++i, ++index)
333 Dune::FieldVector<ctype, dim> position;
334 for (std::size_t j = 0; j<
dim; ++j)
335 position[j] = _factory[j][index[j]];
340 std::array<std::size_t, dim> offsets;
342 for (std::size_t i=1; i<
dim; i++)
343 offsets[i] = offsets[i-1] * vsizes[i-1];
347 unsigned int nCorners = 1<<
dim;
349 std::vector<unsigned int> cornersTemplate(nCorners,0);
351 for (
size_t i=0; i<nCorners; i++)
352 for (
int j=0; j<
dim; j++)
354 cornersTemplate[i] += offsets[j];
360 int numElements = eindex.
cycle();
362 for (
int i=0; i<numElements; i++, ++eindex)
365 unsigned int base = 0;
366 for (
int j=0; j<
dim; j++)
367 base += eindex[j] * offsets[j];
370 std::vector<unsigned int> corners = cornersTemplate;
371 for (
size_t j=0; j<corners.size(); j++)
378 return std::shared_ptr<Grid>(fac.
createGrid());
385 template<
typename ctype,
int dim>
396 return std::make_shared<Grid>(_factory.coords(), std::bitset<dim>(0ULL), 1, comm);
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:522
void fillIntervals(int d, int n, ctype h)
pushs n intervals of length h in direction d
Definition: tensorgridfactory.hh:91
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
YaspGrid< dim, TensorProductCoordinates< ctype, dim > > Grid
Definition: tensorgridfactory.hh:389
void geometricFillUntil(int d, ctype ratio, ctype end, ctype h0=static_cast< ctype >(0))
adds intervals in direction d according with a given length ratio until a given coordinate is reached...
Definition: tensorgridfactory.hh:168
void geometricFillRange(int d, int n, ctype end, ctype h=static_cast< ctype >(0), bool first=true)
fills a coordinate range in direction d with n intervals according to a geometric series ...
Definition: tensorgridfactory.hh:195
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:290
Grid::ctype ctype
Definition: tensorgridfactory.hh:43
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
void geometricFillIntervals(int d, int n, ctype ratio, ctype h0=static_cast< ctype >(0))
adds n intervals in direction d with a given length ratio and a given starting interval length...
Definition: tensorgridfactory.hh:142
void fillUntil(int d, ctype h, ctype end)
adds intervals in direction d until a given coordinate is reached
Definition: tensorgridfactory.hh:123
std::shared_ptr< Grid > createGrid(Comm comm=Comm())
Definition: tensorgridfactory.hh:46
Provide a generic factory class for unstructured grids.
void abs(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:326
virtual GridType * createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:316
Grid::Traits::CollectiveCommunication Comm
Definition: tensorgridfactory.hh:306
Implements a multiindex with arbitrary dimension and fixed index ranges This is used by various facto...
std::vector< ctype > & operator[](std::size_t d)
allow to manually tune the factory by overloading operator[] to export the coordinate vectors in the ...
Definition: tensorgridfactory.hh:58
Grid::Traits::CollectiveCommunication Comm
Definition: tensorgridfactory.hh:42
void setStart(int d, ctype value)
set a starting value in a given direction d
Definition: tensorgridfactory.hh:77
Grid::CollectiveCommunication Comm
Definition: tensorgridfactory.hh:390
Definition: tensorgridfactory.hh:32
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: common/grid.hh:519
[ provides Dune::Grid ]
Definition: yaspgrid.hh:56
std::shared_ptr< Grid > createGrid(Comm comm)
Definition: tensorgridfactory.hh:312
TensorGridFactoryCreator(const TensorGridFactory< Grid > &factory)
Definition: tensorgridfactory.hh:392
void fillRange(int d, int n, ctype end)
fills the range to end with n intervals in direction d
Definition: tensorgridfactory.hh:106
Grid::ctype ctype
Definition: tensorgridfactory.hh:307
std::shared_ptr< Grid > createGrid(Comm comm)
Definition: tensorgridfactory.hh:394
Include standard header files.
Definition: agrid.hh:59
Coordinate container for a tensor product YaspGrid.
Definition: coordinates.hh:233
A factory class for conveniently creating tensorproduct grids.
Definition: tensorgridfactory.hh:39
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:279
const std::vector< ctype > & operator[](std::size_t d) const
allow to manually tune the factory by overloading operator[] to export the coordinate vectors in the ...
Definition: tensorgridfactory.hh:64
Definition: multiindex.hh:16
std::array< std::vector< ctype >, dim > coords() const
Definition: tensorgridfactory.hh:52
TensorGridFactoryCreator(const TensorGridFactory< Grid > &factory)
Definition: tensorgridfactory.hh:310
The dimension of the grid.
Definition: common/grid.hh:387
static const int dim
Definition: tensorgridfactory.hh:44
void print()
print the coordinate information given to the factory so far
Definition: tensorgridfactory.hh:217
size_t cycle() const
Compute how many times you can call operator++ before getting to (0,...,0) again. ...
Definition: multiindex.hh:46