3 #ifndef DUNE_STARCD_READER_HH
4 #define DUNE_STARCD_READER_HH
6 #include <dune/common/exceptions.hh>
7 #include <dune/common/to_unique_ptr.hh>
9 #include <dune/geometry/type.hh>
49 template <
class Gr
idType>
63 static ToUniquePtr<GridType>
read(
const std::string& fileName,
bool verbose =
true)
66 const int dim = GridType::dimension;
70 DUNE_THROW(Dune::NotImplemented,
71 "Reading Star-CD format is not implemented for dimension " << dim);
77 std::string vertexFileName = fileName +
".vrt";
80 std::ifstream vertexFile(vertexFileName.c_str());
82 DUNE_THROW(Dune::IOError,
"Could not open " << vertexFileName);
86 int numberOfVertices = 0;
87 while (vertexFile >> dummyIdx) {
90 Dune::FieldVector<double,dim> position;
92 for (
int k = 0; k < dim; k++)
93 vertexFile >> position[k];
98 std::cout << numberOfVertices <<
" vertices read." << std::endl;
101 std::string elementFileName = fileName +
".cel";
104 std::ifstream elementFile(elementFileName.c_str());
106 DUNE_THROW(Dune::IOError,
"Could not open " << elementFileName);
109 int numberOfElements = 0;
110 int numberOfSimplices = 0;
111 int numberOfPyramids = 0;
112 int numberOfPrisms = 0;
113 int numberOfCubes = 0;;
114 int maxNumberOfVertices = (int)pow(2, dim);
116 while (elementFile >> dummyIdx) {
117 std::vector<unsigned int> vertices(maxNumberOfVertices);
118 for (
int k = 0; k < maxNumberOfVertices; k++)
119 elementFile >> vertices[k];
122 elementFile >> boundaryId;
124 int volumeOrSurface[2];
125 elementFile >> volumeOrSurface[0] >> volumeOrSurface[1];
127 if (volumeOrSurface[0] == isVolume) {
130 if (vertices[2] == vertices[3]) {
131 if (vertices[4] == vertices[5]) {
133 std::vector<unsigned int> simplexVertices(4);
134 for (
int k = 0; k < 3; k++)
135 simplexVertices[k] = vertices[k] - 1;
136 simplexVertices[3] = vertices[4] - 1;
141 std::vector<unsigned int> prismVertices(6);
142 for (
int k = 0; k < 3; k++)
143 prismVertices[k] = vertices[k] - 1;
144 for (
int k = 3; k < 6; k++)
145 prismVertices[k] = vertices[k+1] - 1;
150 if (vertices[4] == vertices[5]) {
152 std::vector<unsigned int> pyramidVertices(5);
153 for (
int k = 0; k < 5; k++)
154 pyramidVertices[k] = vertices[k] - 1;
159 std::vector<unsigned int> cubeVertices(8);
160 for (
int k = 0; k < 8; k++)
161 cubeVertices[k] = vertices[k] - 1;
162 std::swap(cubeVertices[2], cubeVertices[3]);
163 std::swap(cubeVertices[6], cubeVertices[7]);
170 std::cout << numberOfElements <<
" elements read: "
171 << numberOfSimplices <<
" simplices, " << numberOfPyramids <<
" pyramids, "
172 << numberOfPrisms <<
" prisms, " << numberOfCubes <<
" cubes." << std::endl;
176 std::cout <<
"Starting createGrid() ... " << std::flush;
Include standard header files.
Definition: agrid.hh:59
@ pyramid
Definition: common.hh:189
@ tetrahedron
Definition: common.hh:186
@ prism
Definition: common.hh:188
@ hexahedron
Definition: common.hh:187
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:269
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:301
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:290
virtual ToUniquePtr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:327
File reader for the Star-CD format.
Definition: starcdreader.hh:50
static ToUniquePtr< GridType > read(const std::string &fileName, bool verbose=true)
Read grid from a Star-CD file.
Definition: starcdreader.hh:63
Provide a generic factory class for unstructured grids.