Newer
Older
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <string>
#include <iostream>
#include <vector>
// Also test the deprecated version
#include <dune/common/deprecated.hh>
#include <dune/geometry/type.hh>
#include <dune/geometry/utility/typefromvertexcount.hh>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
std::string convBase(unsigned long v, long base)
{
const char* digits = "0123456789abcdef";
std::string result;
if((base < 2) || (base > 16)) {
result = "Error: base out of range.";
}
else {
do {
result = digits[v % base] + result;
v /= base;
}
while(v);
}
return result;
}
void guessTopologyId(unsigned int dim, unsigned int vertices,
unsigned int v, unsigned int id, unsigned int d,
std::vector<unsigned int> & ids)
{
if (d == dim)
{
if (v == vertices)
ids.push_back(id);
return;
}
// try simplex
guessTopologyId(dim,vertices,v+1,id,d+1,ids);
// try cube
guessTopologyId(dim,vertices,v*2,id+(1<<d),d+1,ids);
}
unsigned int guessTopologyId(unsigned int dim, unsigned int vertices)
{
std::vector<unsigned int> ids;
if (dim == 0 || dim == 1)
return 0;
if (vertices < dim+1 || vertices > 1u<<dim)
DUNE_THROW(Dune::Exception, "IMPOSSIBLE");
guessTopologyId(dim,vertices,2,1,1,ids);
if (ids.size() == 0)
DUNE_THROW(Dune::Exception, "Impossible setting");
if (ids.size() > 1)
DUNE_THROW(Dune::Exception, "Too many options");
return ids[0];
}
void testGuess(unsigned int dim, unsigned int vertices)
{
std::cout << "check dim: " << dim
<< " vertices: " << vertices
<< std::endl;
Dune::GeometryType gt = Dune::geometryTypeFromVertexCount(dim, vertices);
if (Dune::GeometryType(id,dim) != gt)
DUNE_THROW(Dune::Exception, "Failed to guess the geometry type from the number of vertices.");
DUNE_NO_DEPRECATED_BEGIN
Dune::GeometryType gt2;
gt2.makeFromVertices(dim, vertices);
if (gt != gt2)
DUNE_THROW(Dune::Exception, "geometryTypeFromVertexCount and makeFromVertices return different type");
DUNE_NO_DEPRECATED_END
std::vector<std::vector<int>> configurations = { {1}, {2}, {3,4}, {4,5,6,8} };
for (int d=0; d<=3; d++)
for (int v : configurations[d])
catch (Dune::Exception & e)
{
std::cout << "Error: " << e.what() << std::endl;