Skip to content

Commit

Permalink
add support for Tecplot .dat file (Tecplot 2009 compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
truongdangqe committed Jun 12, 2021
1 parent 392990d commit e9fc401
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
52 changes: 52 additions & 0 deletions FvmMesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,55 @@ void FvmMesh2D::writeVtk() {
outfile.close();
}

void FvmMesh2D::writeTecplot() {
/*
* Write converted mesh file in Tecplot 2009 compatible format
*/
string str = mshReader.getFname() + ".dat";
vector<Point> coordNodes = mshReader.getCoordNodes();
vector<NodeIdent> idNodes = mshReader.getIdNodes();
unsigned nbNodes = mshReader.getNbNode();
unsigned nbElm = mshReader.getNbElm();
ofstream outfile(str);

outfile.setf(ios::fixed, ios::floatfield);
outfile.precision(10);
outfile << "VARIABLES=X,Y,CELL_IDENT,NEIGHBOR1,NEIGHBOR2,NEIGHBOR3,NEIGHBOR4" << endl;
outfile << "VARIABLES=X,Y" << endl;
outfile << "ZONE T=\"UNSTRUCTURED-COUNTOUR\"" << endl;
outfile << "ZONETYPE=FEPOLYGON" << endl;
outfile << "NODES=" << nbNodes << endl;
outfile << "ELEMENTS=" << nbElm << endl;
outfile << "FACES=" << nbElm * 4 << endl;
outfile << "NumConnectedBoundaryFaces=0" << endl;
outfile << "TotalNumBoundaryConnections=0" << endl;

for (unsigned i = 0; i < nbNodes; i++) {
outfile << setw(15) << coordNodes[i].getX() << endl;
}

for (unsigned i = 0; i < nbNodes; i++) {
outfile << setw(15) << coordNodes[i].getY() << endl;
}

/*
* Node indexes
*/
for (unsigned i = 0; i < nbElm; i++) {
outfile << idNodes[i].getIdNode()[5] << " " << idNodes[i].getIdNode()[6] << endl;
outfile << idNodes[i].getIdNode()[6] << " " << idNodes[i].getIdNode()[7] << endl;
outfile << idNodes[i].getIdNode()[7] << " " << idNodes[i].getIdNode()[8] << endl;
outfile << idNodes[i].getIdNode()[8] << " " << idNodes[i].getIdNode()[5] << endl;
}

for (unsigned i = 0; i < nbElm; i++) {
outfile << i + 1 << " " << i + 1 << " " << i + 1 << " " << i + 1 << " " << endl;
}

for (unsigned i = 0; i < nbElm; i++) {
outfile << 0 << " " << 0 << " " << 0 << " " << 0 << " " << endl;
}

outfile.close();
}

1 change: 1 addition & 0 deletions FvmMesh2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FvmMesh2D {
void detectNearestNeighbor();
void calculVol();
void writeVtk();
void writeTecplot();

private:
GmshReader mshReader;
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main()
finiteVolumeMesh.assignFaces();
finiteVolumeMesh.assignBoundaryCondition();
finiteVolumeMesh.detectNearestNeighbor();
finiteVolumeMesh.writeVtk();
finiteVolumeMesh.writeTecplot();

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

0 comments on commit e9fc401

Please sign in to comment.