diff --git a/FvmMesh2D.cpp b/FvmMesh2D.cpp index 8d5842c..14803ae 100644 --- a/FvmMesh2D.cpp +++ b/FvmMesh2D.cpp @@ -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 coordNodes = mshReader.getCoordNodes(); + vector 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(); +} + diff --git a/FvmMesh2D.h b/FvmMesh2D.h index 45f5fa3..4a51e73 100644 --- a/FvmMesh2D.h +++ b/FvmMesh2D.h @@ -25,6 +25,7 @@ class FvmMesh2D { void detectNearestNeighbor(); void calculVol(); void writeVtk(); + void writeTecplot(); private: GmshReader mshReader; diff --git a/main.cpp b/main.cpp index c2237cf..18cd12c 100644 --- a/main.cpp +++ b/main.cpp @@ -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(t2 - t1).count();