Commit 46d41374 authored by Stenger, Florian's avatar Stenger, Florian
Browse files

new branch for physicalTags and msh2-format

parent 396a57a0
Pipeline #6174 failed with stage
in 10 minutes and 7 seconds
...@@ -8,4 +8,4 @@ Version: 0.2 ...@@ -8,4 +8,4 @@ Version: 0.2
Maintainer: simon.praetorius@tu-dresden.de Maintainer: simon.praetorius@tu-dresden.de
#depending on #depending on
Depends: dune-grid Depends: dune-grid
Suggests: dune-alugrid dune-foamgrid dune-vtk dune-curvedsurfacegrid Suggests: dune-alugrid dune-foamgrid dune-vtk dune-curvedgrid
#pragma once #pragma once
#include <iosfwd> #include <iosfwd>
#include <set>
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector> #include <vector>
...@@ -10,6 +11,8 @@ ...@@ -10,6 +11,8 @@
#include <dune/gmsh4/filereader.hh> #include <dune/gmsh4/filereader.hh>
#include <dune/gmsh4/gridcreators/continuousgridcreator.hh> // default GridCreator #include <dune/gmsh4/gridcreators/continuousgridcreator.hh> // default GridCreator
#include <dune/grid/io/file/gmshreader.hh> //for old msh2.2 reader
namespace Dune namespace Dune
{ {
/// File-Reader for GMsh unstructured .msh files /// File-Reader for GMsh unstructured .msh files
...@@ -42,6 +45,10 @@ namespace Dune ...@@ -42,6 +45,10 @@ namespace Dune
public: public:
using size_type = SizeType; using size_type = SizeType;
Gmsh4Reader ()
: creator_(new GridCreator)
{}
/// Constructor. Creates a new GridCreator with the passed factory /// Constructor. Creates a new GridCreator with the passed factory
template <class... Args, template <class... Args,
std::enable_if_t<std::is_constructible<GridCreator, Args...>::value,int> = 0> std::enable_if_t<std::is_constructible<GridCreator, Args...>::value,int> = 0>
...@@ -59,6 +66,39 @@ namespace Dune ...@@ -59,6 +66,39 @@ namespace Dune
: creator_(std::move(creator)) : creator_(std::move(creator))
{} {}
//convenience-method to keep compatibility with old GmshReader from dune-grid.
static ToUniquePtr<Grid> read (const std::string& fileName, bool verbose,
bool insertBoundarySegments);
//convenience-method to keep compatibility with old GmshReader from dune-grid.
static void read (Dune::GridFactory<Grid>& factory, const std::string& fileName,
bool verbose = true, bool insertBoundarySegments=true);
//Needed for following read-method. Also declared in GmshReader. Should probably by public
//there are accessible via friend-declaration...
struct DataArg {
std::vector<int> *data_ = nullptr;
DataArg(std::vector<int> &data) : data_(&data) {}
DataArg(const decltype(std::ignore)&) {}
DataArg() = default;
};
struct DataFlagArg : DataArg {
bool flag_ = false;
using DataArg::DataArg;
DataFlagArg(bool flag) : flag_(flag) {}
};
//convenience-method to keep compatibility with old GmshReader from dune-grid.
static void read (Dune::GridFactory<Grid> &factory, const std::string &fileName,
DataFlagArg boundarySegmentData, DataArg elementData, bool verbose=true);
//convenience-method to keep compatibility with old GmshReader from dune-grid.
static void read (Dune::GridFactory<Grid>& factory, const std::string& fileName,
std::vector<int>& boundarySegmentToPhysicalEntity,
std::vector<int>& elementToPhysicalEntity,
bool verbose=true, bool insertBoundarySegments=true);
/// Read the grid from file with `filename` into the GridFactory stored in the GridCreator /// Read the grid from file with `filename` into the GridFactory stored in the GridCreator
/** /**
* \param filename The name of the input file * \param filename The name of the input file
...@@ -108,6 +148,8 @@ namespace Dune ...@@ -108,6 +148,8 @@ namespace Dune
#endif #endif
private: private:
void prepareBoundingEntityTags();
std::vector<int>& getPhysicalTags(int entityDim, int entityTag);
template<class T> template<class T>
void readValueBinary(std::ifstream& input, T &v); void readValueBinary(std::ifstream& input, T &v);
void readMeshFormat (std::ifstream& input, void readMeshFormat (std::ifstream& input,
...@@ -228,11 +270,15 @@ namespace Dune ...@@ -228,11 +270,15 @@ namespace Dune
// PhysicalNames section // PhysicalNames section
std::vector<PhysicalNamesAttributes> physicalNames_; std::vector<PhysicalNamesAttributes> physicalNames_;
// boundary handling
std::set<int> boundingEntityTags;
std::set<int> boundaryEntities;
// Entities section // Entities section
std::vector<PointAttributes> points_; std::map<int, PointAttributes> points_;
std::vector<EntityAttributes> curves_; std::map<int, EntityAttributes> curves_;
std::vector<EntityAttributes> surfaces_; std::map<int, EntityAttributes> surfaces_;
std::vector<EntityAttributes> volumes_; std::map<int, EntityAttributes> volumes_;
// PartitionedEntities section // PartitionedEntities section
size_type numPartitions_ = 0; size_type numPartitions_ = 0;
...@@ -267,6 +313,10 @@ namespace Dune ...@@ -267,6 +313,10 @@ namespace Dune
}; };
// deduction guides // deduction guides
template <class Grid>
Gmsh4Reader ()
-> Gmsh4Reader<Grid, Gmsh4::ContinuousGridCreator<Grid>>;
template <class Grid> template <class Grid>
Gmsh4Reader (GridFactory<Grid>&) Gmsh4Reader (GridFactory<Grid>&)
-> Gmsh4Reader<Grid, Gmsh4::ContinuousGridCreator<Grid>>; -> Gmsh4Reader<Grid, Gmsh4::ContinuousGridCreator<Grid>>;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <dune/gmsh4/utility/filesystem.hh> #include <dune/gmsh4/utility/filesystem.hh>
#include <dune/gmsh4/utility/string.hh> #include <dune/gmsh4/utility/string.hh>
#include <dune/grid/io/file/gmshreader.hh> //for old msh2.2 reader
// Helper-function to deal with endianness in binary msh-files. // Helper-function to deal with endianness in binary msh-files.
inline void swapBytes (char *array, int size) inline void swapBytes (char *array, int size)
{ {
...@@ -240,6 +242,7 @@ struct Gmsh4Reader<G,C,S>::ElementAttributes ...@@ -240,6 +242,7 @@ struct Gmsh4Reader<G,C,S>::ElementAttributes
int entityDim; int entityDim;
int entityTag; int entityTag;
int elementType; int elementType;
std::vector<int> physicalTags;
std::vector<Element> elements; std::vector<Element> elements;
}; };
...@@ -260,6 +263,38 @@ struct Gmsh4Reader<G,C,S>::PeriodicAttributes ...@@ -260,6 +263,38 @@ struct Gmsh4Reader<G,C,S>::PeriodicAttributes
}; };
template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::prepareBoundingEntityTags()
{
switch((int)G::dimension){
case 1:
for(auto &curv : curves_)
for(auto tag : curv.second.boundingEntities) boundingEntityTags.insert(tag);
break;
case 2:
for(auto &surface : surfaces_)
for(auto tag : surface.second.boundingEntities) boundingEntityTags.insert(tag);
break;
case 3:
for(auto &volume : volumes_)
for(auto tag : volume.second.boundingEntities) boundingEntityTags.insert(tag);
}
}
template <class G, class C, class S>
std::vector<int>& Gmsh4Reader<G,C,S>::getPhysicalTags(int entityDim, int entityTag)
{
switch(entityDim){
case 0: return points_[entityTag].physicalTags;
case 1: return curves_[entityTag].physicalTags;
case 2: return surfaces_[entityTag].physicalTags;
case 3: return volumes_[entityTag].physicalTags;
}
DUNE_THROW(Dune::NotImplemented, "Only entities of dimension 0, 1, 2 and 3 allowed.");
}
template <class G, class C, class S> template <class G, class C, class S>
template <class T> template <class T>
void Gmsh4Reader<G,C,S>::readValueBinary(std::ifstream& input, T &v) void Gmsh4Reader<G,C,S>::readValueBinary(std::ifstream& input, T &v)
...@@ -270,6 +305,62 @@ void Gmsh4Reader<G,C,S>::readValueBinary(std::ifstream& input, T &v) ...@@ -270,6 +305,62 @@ void Gmsh4Reader<G,C,S>::readValueBinary(std::ifstream& input, T &v)
} }
//convenience-method to keep compatibility with old GmshReader from dune-grid.
template <class G, class C, class S>
ToUniquePtr<G> Gmsh4Reader<G,C,S>::read (const std::string& fileName, bool verbose,
bool insertBoundarySegments)
{
std::cout << "WARNING! You are using a deprecated syntax for the GmshReader! "
"Use \"read(std::string const& filename, bool fillCreator = true)\" instead, "
"especially if you need to read MSH 4.1 files." << std::endl;
return GmshReader<G>::read(fileName, verbose, insertBoundarySegments);
}
//convenience-function to keep compatibility with old GmshReader from dune-grid.
template<class T> static T &discarded(T &&value) { return value; }
//convenience-method to keep compatibility with old GmshReader from dune-grid.
template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::read (Dune::GridFactory<G>& factory, const std::string& fileName,
bool verbose, bool insertBoundarySegments)
{
std::cout << "WARNING! You are using a deprecated syntax for the GmshReader! "
"Use \"read(std::string const& filename, bool fillCreator = true)\" instead, "
"especially if you need to read MSH 4.1 files." << std::endl;
GmshReader<G>::read(factory, fileName, discarded(std::vector<int>{}),
discarded(std::vector<int>{}), verbose, insertBoundarySegments);
}
//convenience-method to keep compatibility with old GmshReader from dune-grid.
template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::read (Dune::GridFactory<G> &factory, const std::string &fileName,
DataFlagArg boundarySegmentData, DataArg elementData, bool verbose)
{
std::cout << "WARNING! You are using a deprecated syntax for the GmshReader! "
"Use \"read(std::string const& filename, bool fillCreator = true)\" instead, "
"especially if you need to read MSH 4.1 files." << std::endl;
GmshReader<G>::read(factory, fileName, boundarySegmentData, elementData, verbose);
}
//convenience-method to keep compatibility with old GmshReader from dune-grid.
template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::read (Dune::GridFactory<G>& factory, const std::string& fileName,
std::vector<int>& boundarySegmentToPhysicalEntity,
std::vector<int>& elementToPhysicalEntity,
bool verbose, bool insertBoundarySegments)
{
std::cout << "WARNING! You are using a deprecated syntax for the GmshReader! "
"Use \"read(std::string const& filename, bool fillCreator = true)\" instead, "
"especially if you need to read MSH 4.1 files." << std::endl;
GmshReader<G>::read(factory, fileName, boundarySegmentToPhysicalEntity,
elementToPhysicalEntity, verbose, insertBoundarySegments);
}
template <class G, class C, class S> template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator) void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator)
{ {
...@@ -277,13 +368,15 @@ void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator) ...@@ -277,13 +368,15 @@ void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator)
if (!Gmsh4::exists(filename)) if (!Gmsh4::exists(filename))
DUNE_THROW(IOError, "File " << filename << " does not exist!"); DUNE_THROW(IOError, "File " << filename << " does not exist!");
clear();
std::ifstream input(filename, std::ios_base::in | std::ios_base::binary); std::ifstream input(filename, std::ios_base::in | std::ios_base::binary);
GMSH4_ASSERT(input.is_open()); GMSH4_ASSERT(input.is_open());
std::string ext = Gmsh4::Path(filename).extension().string(); std::string ext = Gmsh4::Path(filename).extension().string();
if (ext == ".msh") { if (ext == ".msh") {
readSerialFileFromStream(input, fillCreator);
pieces_.push_back(filename); pieces_.push_back(filename);
readSerialFileFromStream(input, fillCreator);
} else if (ext == ".pro") { } else if (ext == ".pro") {
readParallelFileFromStream(input, comm().rank(), comm().size(), fillCreator); readParallelFileFromStream(input, comm().rank(), comm().size(), fillCreator);
} else { } else {
...@@ -295,8 +388,6 @@ void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator) ...@@ -295,8 +388,6 @@ void Gmsh4Reader<G,C,S>::read (std::string const& filename, bool fillCreator)
template <class G, class C, class S> template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fillCreator) void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fillCreator)
{ {
clear();
// MeshFormat section // MeshFormat section
double version = 0.0; double version = 0.0;
int file_type = 0; int file_type = 0;
...@@ -320,14 +411,23 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi ...@@ -320,14 +411,23 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi
switch (section) { switch (section) {
case Sections::MESH_FORMAT: { case Sections::MESH_FORMAT: {
readMeshFormat(input, version, file_type, data_size); readMeshFormat(input, version, file_type, data_size);
GMSH4_ASSERT_MSG(version >= 4.0 && version < 5.0, GMSH4_ASSERT_MSG((version >= 4.0 && version < 5.0) || (version >= 2.0 && version <= 2.2),
"Can only read gmsh files versions >= 4.0 and < 5.0"); "Can only read gmsh files versions >= 4.0 and < 5.0 or versions >= 2.0 and <= 2.2");
GMSH4_ASSERT_MSG(file_type == 0 || file_type == 1, if( version >= 2.0 && version <= 2.2 ){
"Invalid file-type: 0 for ASCII mode, 1 for binary mode"); std::vector<int> boundarySegmentToPhysicalEntity, elementToPhysicalEntity;
GMSH4_ASSERT_MSG(data_size >= 4 && data_size <= 16, GmshReader<G>::read(creator_->factory(), pieces_.back(),
"Invalid data-size range: should be in {4, 16}"); boundarySegmentToPhysicalEntity, elementToPhysicalEntity,
GMSH4_ASSERT_MSG(file_type != 1 || data_size == sizeof(size_type), /*verbose=*/false, /*insertBoundarySegments=*/true);
"Invalid data-size: must be sizeof(size_t)"); //translate physicalTags from vector<int> to vector<vector<int>>
creator_->expandTagsVectors(elementToPhysicalEntity, boundarySegmentToPhysicalEntity);
}else{
GMSH4_ASSERT_MSG(file_type == 0 || file_type == 1,
"Invalid file-type: 0 for ASCII mode, 1 for binary mode");
GMSH4_ASSERT_MSG(data_size >= 4 && data_size <= 16,
"Invalid data-size range: should be in {4, 16}");
GMSH4_ASSERT_MSG(file_type != 1 || data_size == sizeof(size_type),
"Invalid data-size: must be sizeof(size_t)");
}
break; break;
} }
case Sections::PHYSICAL_NAMES: case Sections::PHYSICAL_NAMES:
...@@ -345,6 +445,7 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi ...@@ -345,6 +445,7 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi
else readNodesBinary(input); else readNodesBinary(input);
break; break;
case Sections::ELEMENTS: case Sections::ELEMENTS:
prepareBoundingEntityTags();
if(file_type == 0) readElementsAscii(input); if(file_type == 0) readElementsAscii(input);
else readElementsBinary(input); else readElementsBinary(input);
break; break;
...@@ -376,7 +477,6 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi ...@@ -376,7 +477,6 @@ void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input, bool fi
template <class G, class C, class S> template <class G, class C, class S>
void Gmsh4Reader<G,C,S>::readParallelFileFromStream (std::ifstream& input, int commRank, int commSize, bool fillCreator) void Gmsh4Reader<G,C,S>::readParallelFileFromStream (std::ifstream& input, int commRank, int commSize, bool fillCreator)
{ {
clear();
DUNE_THROW(Dune::NotImplemented, "Reading parallel .pro files not yet implemented."); DUNE_THROW(Dune::NotImplemented, "Reading parallel .pro files not yet implemented.");
if (fillCreator) if (fillCreator)
fillGridCreator(); fillGridCreator();
...@@ -437,7 +537,6 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input) ...@@ -437,7 +537,6 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
} }
// points // points
points_.reserve(numPoints);
for (size_type i = 0; i < numPoints; ++i) { for (size_type i = 0; i < numPoints; ++i) {
if (!std::getline(input,line)) if (!std::getline(input,line))
break; break;
...@@ -453,12 +552,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input) ...@@ -453,12 +552,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
for (size_type j = 0; j < numPhysicalTags; ++j) for (size_type j = 0; j < numPhysicalTags; ++j)
stream >> attr.physicalTags[j]; stream >> attr.physicalTags[j];
points_.push_back(attr); points_[attr.tag] = attr;
} }
GMSH4_ASSERT(points_.size() == numPoints); GMSH4_ASSERT(points_.size() == numPoints);
// curves // curves
curves_.reserve(numCurves);
for (size_type i = 0; i < numCurves; ++i) { for (size_type i = 0; i < numCurves; ++i) {
if (!std::getline(input,line)) if (!std::getline(input,line))
break; break;
...@@ -481,12 +579,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input) ...@@ -481,12 +579,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
for (size_type j = 0; j < numBoundingPoints; ++j) for (size_type j = 0; j < numBoundingPoints; ++j)
stream >> attr.boundingEntities[j]; stream >> attr.boundingEntities[j];
curves_.push_back(attr); curves_[attr.tag] = attr;
} }
GMSH4_ASSERT(curves_.size() == numCurves); GMSH4_ASSERT(curves_.size() == numCurves);
// surfaces // surfaces
surfaces_.reserve(numSurfaces);
for (size_type i = 0; i < numSurfaces; ++i) { for (size_type i = 0; i < numSurfaces; ++i) {
if (!std::getline(input,line)) if (!std::getline(input,line))
break; break;
...@@ -509,12 +606,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input) ...@@ -509,12 +606,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
for (size_type j = 0; j < numBoundingCurves; ++j) for (size_type j = 0; j < numBoundingCurves; ++j)
stream >> attr.boundingEntities[j]; stream >> attr.boundingEntities[j];
surfaces_.push_back(attr); surfaces_[attr.tag] = attr;
} }
GMSH4_ASSERT(surfaces_.size() == numSurfaces); GMSH4_ASSERT(surfaces_.size() == numSurfaces);
// volumes // volumes
volumes_.reserve(numVolumes);
for (size_type i = 0; i < numVolumes; ++i) { for (size_type i = 0; i < numVolumes; ++i) {
if (!std::getline(input,line)) if (!std::getline(input,line))
break; break;
...@@ -537,7 +633,7 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input) ...@@ -537,7 +633,7 @@ void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
for (size_type j = 0; j < numBoundingSurfaces; ++j) for (size_type j = 0; j < numBoundingSurfaces; ++j)
stream >> attr.boundingEntities[j]; stream >> attr.boundingEntities[j];
volumes_.push_back(attr); volumes_[attr.tag] = attr;
} }
GMSH4_ASSERT(volumes_.size() == numVolumes); GMSH4_ASSERT(volumes_.size() == numVolumes);
} }
...@@ -554,7 +650,6 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input) ...@@ -554,7 +650,6 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
readValueBinary(input, numVolumes); readValueBinary(input, numVolumes);
// points // points
points_.reserve(numPoints);
for (size_type i = 0; i < numPoints; ++i) { for (size_type i = 0; i < numPoints; ++i) {
PointAttributes attr; PointAttributes attr;
...@@ -569,12 +664,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input) ...@@ -569,12 +664,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
for (size_type j = 0; j < numPhysicalTags; ++j) for (size_type j = 0; j < numPhysicalTags; ++j)
readValueBinary(input, attr.physicalTags[j]); readValueBinary(input, attr.physicalTags[j]);
points_.push_back(attr); points_[attr.tag] = attr;
} }
GMSH4_ASSERT(points_.size() == numPoints); GMSH4_ASSERT(points_.size() == numPoints);
// curves // curves
curves_.reserve(numCurves);
for (size_type i = 0; i < numCurves; ++i) { for (size_type i = 0; i < numCurves; ++i) {
EntityAttributes attr; EntityAttributes attr;
...@@ -598,12 +692,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input) ...@@ -598,12 +692,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
for (size_type j = 0; j < numBoundingPoints; ++j) for (size_type j = 0; j < numBoundingPoints; ++j)
readValueBinary(input, attr.boundingEntities[j]); readValueBinary(input, attr.boundingEntities[j]);
curves_.push_back(attr); curves_[attr.tag] = attr;
} }
GMSH4_ASSERT(curves_.size() == numCurves); GMSH4_ASSERT(curves_.size() == numCurves);
// surfaces // surfaces
surfaces_.reserve(numSurfaces);
for (size_type i = 0; i < numSurfaces; ++i) { for (size_type i = 0; i < numSurfaces; ++i) {
EntityAttributes attr; EntityAttributes attr;
...@@ -627,12 +720,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input) ...@@ -627,12 +720,11 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
for (size_type j = 0; j < numBoundingCurves; ++j) for (size_type j = 0; j < numBoundingCurves; ++j)
readValueBinary(input, attr.boundingEntities[j]); readValueBinary(input, attr.boundingEntities[j]);
surfaces_.push_back(attr); surfaces_[attr.tag] = attr;
} }
GMSH4_ASSERT(surfaces_.size() == numSurfaces); GMSH4_ASSERT(surfaces_.size() == numSurfaces);
// volumes // volumes
volumes_.reserve(numVolumes);
for (size_type i = 0; i < numVolumes; ++i) { for (size_type i = 0; i < numVolumes; ++i) {
EntityAttributes attr; EntityAttributes attr;
...@@ -656,7 +748,7 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input) ...@@ -656,7 +748,7 @@ void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
for (size_type j = 0; j < numBoundingSurfaces; ++j) for (size_type j = 0; j < numBoundingSurfaces; ++j)
readValueBinary(input, attr.boundingEntities[j]); readValueBinary(input, attr.boundingEntities[j]);
volumes_.push_back(attr); volumes_[attr.tag] = attr;
} }
GMSH4_ASSERT(volumes_.size() == numVolumes); GMSH4_ASSERT(volumes_.size() == numVolumes);
std::string line; std::string line;
...@@ -1123,6 +1215,14 @@ void Gmsh4Reader<G,C,S>::readElementsAscii (std::ifstream& input) ...@@ -1123,6 +1215,14 @@ void Gmsh4Reader<G,C,S>::readElementsAscii (std::ifstream& input)
std::istringstream stream(line); std::istringstream stream(line);
stream >> entityBlock.entityDim >> entityBlock.entityTag >> entityBlock.elementType >> numElementsInBlock; stream >> entityBlock.entityDim >> entityBlock.entityTag >> entityBlock.elementType >> numElementsInBlock;
if(entityBlock.entityDim == G::dimension){
entityBlock.physicalTags = getPhysicalTags(entityBlock.entityDim, entityBlock.entityTag);
}else if(entityBlock.entityDim == G::dimension - 1
&& boundingEntityTags.find(entityBlock.entityTag) != boundingEntityTags.end()){
boundaryEntities.insert(entityBlock.entityTag);
entityBlock.physicalTags = getPhysicalTags(entityBlock.entityDim, entityBlock.entityTag);
}
size_type numNodes = elementType_[entityBlock.elementType]; size_type numNodes = elementType_[entityBlock.elementType];
entityBlock.elements.resize(numElementsInBlock); entityBlock.elements.resize(numElementsInBlock);
...@@ -1162,6 +1262,14 @@ void Gmsh4Reader<G,C,S>::readElementsBinary (std::ifstream& input) ...@@ -1162,6 +1262,14 @@ void Gmsh4Reader<G,C,S>::readElementsBinary (std::ifstream& input)
readValueBinary(input, entityBlock.elementType); readValueBinary(input, entityBlock.elementType);
readValueBinary(input, numElementsInBlock); readValueBinary(input, numElementsInBlock);
if(entityBlock.entityDim == G::dimension){
entityBlock.physicalTags = getPhysicalTags(entityBlock.entityDim, entityBlock.entityTag);
}else if(entityBlock.entityDim == G::dimension - 1
&& boundingEntityTags.find(entityBlock.entityTag) != boundingEntityTags.end()){
boundaryEntities.insert(entityBlock.entityTag);
entityBlock.physicalTags = getPhysicalTags(entityBlock.entityDim, entityBlock.entityTag);
}
size_type numNodes = elementType_[entityBlock.elementType]; size_type numNodes = elementType_[entityBlock.elementType];