Select Git revision
-
Christophe Geuzaine authoredChristophe Geuzaine authored
GModelIO_MSH3.cpp 26.62 KiB
// Gmsh - Copyright (C) 1997-2019 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
#include <sstream>
#include <iomanip>
#include <ctime>
#include "GModel.h"
#include "OS.h"
#include "GmshMessage.h"
#include "MElement.h"
#include "MPoint.h"
#include "MLine.h"
#include "MTriangle.h"
#include "MQuadrangle.h"
#include "MTetrahedron.h"
#include "MHexahedron.h"
#include "MPrism.h"
#include "MPyramid.h"
#include "MTrihedron.h"
#include "StringUtils.h"
#include "discreteVertex.h"
#include "discreteEdge.h"
#include "discreteFace.h"
#include "discreteRegion.h"
static int readMSHPhysicals(FILE *fp, GEntity *ge)
{
int nump;
if(fscanf(fp, "%d", &nump) != 1) return 0;
for(int i = 0; i < nump; i++) {
int tag;
if(fscanf(fp, "%d", &tag) != 1) return 0;
ge->physicals.push_back(tag);
}
return 1;
}
static void readMSHEntities(FILE *fp, GModel *gm)
{
int nv, ne, nf, nr;
int tag;
if(fscanf(fp, "%d %d %d %d", &nv, &ne, &nf, &nr) != 4) return;
for(int i = 0; i < nv; i++) {
if(fscanf(fp, "%d", &tag) != 1) return;
GVertex *gv = gm->getVertexByTag(tag);
if(!gv) {
gv = new discreteVertex(gm, tag);
gm->add(gv);
}
if(!readMSHPhysicals(fp, gv)) return;
}
for(int i = 0; i < ne; i++) {
int n;
if(fscanf(fp, "%d %d", &tag, &n) != 2) return;
GEdge *ge = gm->getEdgeByTag(tag);
if(!ge) {
GVertex *v1 = 0, *v2 = 0;
for(int j = 0; j < n; j++) {
int tagv;
if(fscanf(fp, "%d", &tagv) != 1){
delete ge;
return;
}
GVertex *v = gm->getVertexByTag(tagv);
if(!v) Msg::Error("Unknown GVertex %d", tagv);
if(j == 0) v1 = v;
if(j == 1) v2 = v;
}