Skip to content

Commit e9fc401

Browse files
committed
add support for Tecplot .dat file (Tecplot 2009 compatible)
1 parent 392990d commit e9fc401

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

FvmMesh2D.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,55 @@ void FvmMesh2D::writeVtk() {
380380
outfile.close();
381381
}
382382

383+
void FvmMesh2D::writeTecplot() {
384+
/*
385+
* Write converted mesh file in Tecplot 2009 compatible format
386+
*/
387+
string str = mshReader.getFname() + ".dat";
388+
vector<Point> coordNodes = mshReader.getCoordNodes();
389+
vector<NodeIdent> idNodes = mshReader.getIdNodes();
390+
unsigned nbNodes = mshReader.getNbNode();
391+
unsigned nbElm = mshReader.getNbElm();
392+
ofstream outfile(str);
393+
394+
outfile.setf(ios::fixed, ios::floatfield);
395+
outfile.precision(10);
396+
outfile << "VARIABLES=X,Y,CELL_IDENT,NEIGHBOR1,NEIGHBOR2,NEIGHBOR3,NEIGHBOR4" << endl;
397+
outfile << "VARIABLES=X,Y" << endl;
398+
outfile << "ZONE T=\"UNSTRUCTURED-COUNTOUR\"" << endl;
399+
outfile << "ZONETYPE=FEPOLYGON" << endl;
400+
outfile << "NODES=" << nbNodes << endl;
401+
outfile << "ELEMENTS=" << nbElm << endl;
402+
outfile << "FACES=" << nbElm * 4 << endl;
403+
outfile << "NumConnectedBoundaryFaces=0" << endl;
404+
outfile << "TotalNumBoundaryConnections=0" << endl;
405+
406+
for (unsigned i = 0; i < nbNodes; i++) {
407+
outfile << setw(15) << coordNodes[i].getX() << endl;
408+
}
409+
410+
for (unsigned i = 0; i < nbNodes; i++) {
411+
outfile << setw(15) << coordNodes[i].getY() << endl;
412+
}
413+
414+
/*
415+
* Node indexes
416+
*/
417+
for (unsigned i = 0; i < nbElm; i++) {
418+
outfile << idNodes[i].getIdNode()[5] << " " << idNodes[i].getIdNode()[6] << endl;
419+
outfile << idNodes[i].getIdNode()[6] << " " << idNodes[i].getIdNode()[7] << endl;
420+
outfile << idNodes[i].getIdNode()[7] << " " << idNodes[i].getIdNode()[8] << endl;
421+
outfile << idNodes[i].getIdNode()[8] << " " << idNodes[i].getIdNode()[5] << endl;
422+
}
423+
424+
for (unsigned i = 0; i < nbElm; i++) {
425+
outfile << i + 1 << " " << i + 1 << " " << i + 1 << " " << i + 1 << " " << endl;
426+
}
427+
428+
for (unsigned i = 0; i < nbElm; i++) {
429+
outfile << 0 << " " << 0 << " " << 0 << " " << 0 << " " << endl;
430+
}
431+
432+
outfile.close();
433+
}
434+

FvmMesh2D.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class FvmMesh2D {
2525
void detectNearestNeighbor();
2626
void calculVol();
2727
void writeVtk();
28+
void writeTecplot();
2829

2930
private:
3031
GmshReader mshReader;

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main()
1515
finiteVolumeMesh.assignFaces();
1616
finiteVolumeMesh.assignBoundaryCondition();
1717
finiteVolumeMesh.detectNearestNeighbor();
18-
finiteVolumeMesh.writeVtk();
18+
finiteVolumeMesh.writeTecplot();
1919

2020
high_resolution_clock::time_point t2 = high_resolution_clock::now();
2121
auto duration = duration_cast<seconds>(t2 - t1).count();

0 commit comments

Comments
 (0)