caizm пре 2 година
родитељ
комит
50c744bac8
2 измењених фајлова са 152 додато и 175 уклоњено
  1. 150 175
      CAE_Solution/src/VTK/mesh/mesh_tecplot.cpp
  2. 2 0
      CAE_Solution/src/VTK/mesh/mesh_tecplot.h

+ 150 - 175
CAE_Solution/src/VTK/mesh/mesh_tecplot.cpp

@@ -3,6 +3,7 @@
 #include "../MeshDS/meshunstructured.h"
 #include "mesh_tecplot.h"
 #include <QStringList>
+#include <ctype.h>
 
 
 /**
@@ -15,6 +16,7 @@
   */
 Mesh_Tecplot::Mesh_Tecplot() : Mesh()
 {
+    celltype_empty = false;
 }
 
 /**
@@ -54,7 +56,7 @@ bool Mesh_Tecplot::Load_Ascii(const string &gridFile)
 bool Mesh_Tecplot::Load_Binary(const string &gridFile)
 {
     cout << gridFile << endl;
-  //  ifstream infile(gridFile);
+    //  ifstream infile(gridFile);
     ifstream infile;
     infile.open(gridFile, ios::binary);
     return Load_Tecp_Binary(infile);
@@ -80,169 +82,122 @@ bool Mesh_Tecplot::Load_Tecp_Ascii(ifstream &infile)
     string title = str;
     title = title.substr(title.find_first_of("\"")+1);
     title = title.substr(0,title.find_first_of("\""));
-    title_ = (char*)title.c_str();
+    title_ = (char*)title.c_str();//解析title
     char str1[1024];
     infile.getline(str1,1024);
     string variables = str1;
-    variables = variables.substr(variables.find_first_of("=")+1);
+    variables = variables.substr(variables.find_first_of("=")+1);//解析标量
     QStringList var_l= QString::fromStdString(variables).split(" ");
     scalarName_.resize(var_l.size()-3);
     scalarNumber_ = var_l.size()-3;
     for(int i =3;i<var_l.size();i++){
         scalarName_[i-3]=var_l[i].toStdString();
     }
-    char str2[1024];
-    infile.getline(str2,1024);
-    string zone_temp = str2;
-    QStringList temp_vec = QString::fromStdString(zone_temp).split(",");
-    string temp = temp_vec[0].toStdString();
-    temp = temp.substr(temp.find_first_of("\"")+1);
-    temp = temp.substr(0,temp.find_first_of("\""));
-    zoneName_.push_back(temp);
-    solutionTime_=((temp_vec[1].split("=")[1]).simplified()).toDouble();
-    zoneNumber_ = 1;
-//    strandid_vec.push_back(((temp_vec[2].split("=")[1]).simplified()).toStdString());
-    int numOfPoint = temp_vec[3].split("=")[1].simplified().toInt();
-    int numOfCell = temp_vec[4].split("=")[1].simplified().toInt();
-    string datatype = temp_vec[5].split("=")[1].simplified().toStdString();
-    string celltype;
-    if(temp_vec.size()==6){
-        celltype = "tetrahedron";
-    }else if(temp_vec.size()==7){
-       celltype = temp_vec[6].split("=")[1].simplified().toStdString();
-    }
-
-    if(datatype == "feblock"){
-        ScalarsData_.resize(zoneNumber_);
-
-        vector<double*> temp_vec_data;
-        temp_vec_data.resize(scalarNumber_+3);
-        double * temp_data_x = new double[numOfPoint];
-        for(int i = 0;i<numOfPoint;i++){
-            infile>>temp_data_x[i];//x
-        }
-        temp_vec_data[0]=temp_data_x;
-
-        double * temp_data_y = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_y[i];//y
-        }
-        temp_vec_data[1]=temp_data_y;
-
-        double * temp_data_z = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_z[i];//z
-        }
-        temp_vec_data[2]=temp_data_z;
-
-        double * temp_data_rho = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_rho[i];//r
-        }
-        temp_vec_data[3]=temp_data_rho;
-
-        double * temp_data_u = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_u[i];//u
-        }
-        temp_vec_data[4]=temp_data_u;
-
-        double * temp_data_v = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_v[i];//v
-        }
-        temp_vec_data[5]=temp_data_v;
-
-        double * temp_data_w = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_w[i];//w
-        }
-        temp_vec_data[6]=temp_data_w;
-
-        double * temp_data_p = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_p[i];//p
-        }
-        temp_vec_data[7]=temp_data_p;
-
-        double * temp_data_cp = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_cp[i];//cp
+    while(!infile.eof()){//循环读zone
+
+        int numOfPoint,numOfCell;
+        string datatype,celltype;
+        celltype.clear();
+
+        char str2[1024];
+        infile.getline(str2,1024);
+        string zone_temp = str2;
+        zone_temp=zone_temp.substr(zone_temp.find("zone")+5);//截取掉zone关键字
+        trim(zone_temp);//删除空格
+        QStringList temp_vec = QString::fromStdString(zone_temp).split(",");
+        for(int i=0;i<temp_vec.size();i++){
+            QStringList temp_name =temp_vec[i].split("=");
+            string temp_name_str = temp_name[0].toStdString();
+            for (int j = 0; j < temp_name_str.size(); j++)
+                    temp_name_str[j] = toupper(temp_name_str[j]);
+            if(temp_name_str == "t"){
+                string zone_name=temp_name[1].toStdString();
+                zone_name = zone_name.substr(zone_name.find_first_of("\"")+1);
+                zone_name = zone_name.substr(0,zone_name.find_first_of("\""));
+                zoneName_.push_back(zone_name);
+            }else if(temp_name_str == "solutiontime"){
+                solutionTime_ = temp_name[1].toDouble();
+            }else if(temp_name_str == "strandid"){
+
+            }else if((temp_name_str == "i")||(temp_name_str=="n")||(temp_name_str=="nodes")){
+                numOfPoint = temp_name[1].toInt();
+            }else if((temp_name_str == "j")||(temp_name_str == "e")||(temp_name_str == "elements")){
+                numOfCell = temp_name[1].toInt();
+            }else if(temp_name_str == "f"){
+                datatype = temp_name[1].toStdString();
+            }else if(temp_name_str == "et"){
+                celltype = temp_name[1].toStdString();
+            }
         }
-        temp_vec_data[8]=temp_data_cp;
 
-        double * temp_data_mach = new double[numOfPoint];
-        for(int i =0;i<numOfPoint;i++){
-            infile>>temp_data_mach[i];//mach
+        if(celltype.empty()){//如果没有指定et
+            celltype = "tetrahedron";
+            celltype_empty = true;//标志位 0-有指定拓扑结构 1-未指定拓扑结构
         }
-        temp_vec_data[9]=temp_data_mach;
-
-        ScalarsData_[0] = temp_vec_data;
-    }else if(datatype=="fepoint"){
-        ScalarsData_.resize(zoneNumber_);
+        zoneNumber_++;
 
-        vector<double*> temp_vec_data;
-        double * temp_data_x = new double[numOfPoint];
-        double * temp_data_y = new double[numOfPoint];
-        double * temp_data_z = new double[numOfPoint];
-        double * temp_data_rho = new double[numOfPoint];
-        double * temp_data_u = new double[numOfPoint];
-        double * temp_data_v = new double[numOfPoint];
-        double * temp_data_w = new double[numOfPoint];
-        double * temp_data_p = new double[numOfPoint];
-        double * temp_data_cp = new double[numOfPoint];
-        double * temp_data_mach = new double[numOfPoint];
-        for(int i=0;i<numOfPoint;i++){
-            infile>>temp_data_x[i]>>temp_data_y[i]>>temp_data_z[i]>>temp_data_rho[i]>>temp_data_u[i]>>temp_data_v[i]>>temp_data_w[i]>>temp_data_p[i]>>temp_data_cp[i]>>temp_data_mach[i];
-        }
-        temp_vec_data[0]=temp_data_x;
-        temp_vec_data[1]=temp_data_y;
-        temp_vec_data[2]=temp_data_z;
-        temp_vec_data[3]=temp_data_rho;
-        temp_vec_data[4]=temp_data_u;
-        temp_vec_data[5]=temp_data_v;
-        temp_vec_data[6]=temp_data_w;
-        temp_vec_data[7]=temp_data_p;
-        temp_vec_data[8]=temp_data_cp;
-        temp_vec_data[9]=temp_data_mach;
 
-        ScalarsData_[0] = temp_vec_data;
-    }
-    vector<vector<int>> cell_vec;
-    if(celltype == "tetrahedron"){//tetrahedron四节点四面体   
-        cell_vec.resize(numOfCell);
-        for(int i=0;i<numOfCell;i++){
-            vector<int> cell_tmp;
-            cell_tmp.resize(4);
-            infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3];
-            cell_vec[i] = cell_tmp;
-        }
-    }else if(celltype == "triangle"){//triangle 三节点三角形
-        cell_vec.resize(numOfCell);
-        for(int i=0;i<numOfCell;i++){
-            vector<int> cell_tmp;
-            cell_tmp.resize(3);
-            infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2];
-            cell_vec[i] = cell_tmp;
-        }
-    }else if(celltype == "quadrilateral"){//quadrilateral 四节点四边形单元
-        cell_vec.resize(numOfCell);
-        for(int i=0;i<numOfCell;i++){
-            vector<int> cell_tmp;
-            cell_tmp.resize(4);
-            infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3];
-            cell_vec[i] = cell_tmp;
-        }
-    }else if(celltype == "brick"){//brick八节点六面体
-        cell_vec.resize(numOfCell);
-        for(int i=0;i<numOfCell;i++){
-            vector<int> cell_tmp;
-            cell_tmp.resize(8);
-            infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3]>>cell_tmp[4]>>cell_tmp[5]>>cell_tmp[6]>>cell_tmp[7];
-            cell_vec[i] = cell_tmp;
+        if(datatype == "feblock"){
+            vector<double*> temp_vec_data;
+            temp_vec_data.resize(scalarNumber_+3);
+            for(int i =0;i<scalarNumber_+3;i++){
+                double* temp_data = new double[numOfPoint];
+                for(int j=0;j<numOfPoint;j++){
+                    infile>>temp_data[j];
+                }
+                temp_vec_data[i] = temp_data;
+            }
+            ScalarsData_.push_back(temp_vec_data);
+        }else if(datatype=="fepoint"){
+            vector<double*> temp_vec_data;
+            temp_vec_data.resize(scalarNumber_+3);
+            for(int i = 0;i<scalarNumber_+3;i++){
+                double* temp_data = new double[numOfPoint];
+                temp_vec_data[i] = temp_data;
+            }
+            for(int j =0;j<numOfPoint;j++){
+                for(int k=0;k<scalarNumber_+3;k++){
+                    infile>>temp_vec_data[k][j];
+                }
+            }
+            ScalarsData_.push_back(temp_vec_data);
+        }
+        vector<vector<int>> cell_vec;
+        if(celltype == "tetrahedron"){//tetrahedron四节点四面体
+            cell_vec.resize(numOfCell);
+            for(int i=0;i<numOfCell;i++){
+                vector<int> cell_tmp;
+                cell_tmp.resize(4);
+                infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3];
+                cell_vec[i] = cell_tmp;
+            }
+        }else if(celltype == "triangle"){//triangle 三节点三角形
+            cell_vec.resize(numOfCell);
+            for(int i=0;i<numOfCell;i++){
+                vector<int> cell_tmp;
+                cell_tmp.resize(3);
+                infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2];
+                cell_vec[i] = cell_tmp;
+            }
+        }else if(celltype == "quadrilateral"){//quadrilateral 四节点四边形单元
+            cell_vec.resize(numOfCell);
+            for(int i=0;i<numOfCell;i++){
+                vector<int> cell_tmp;
+                cell_tmp.resize(4);
+                infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3];
+                cell_vec[i] = cell_tmp;
+            }
+        }else if(celltype == "brick"){//brick八节点六面体
+            cell_vec.resize(numOfCell);
+            for(int i=0;i<numOfCell;i++){
+                vector<int> cell_tmp;
+                cell_tmp.resize(8);
+                infile>>cell_tmp[0]>>cell_tmp[1]>>cell_tmp[2]>>cell_tmp[3]>>cell_tmp[4]>>cell_tmp[5]>>cell_tmp[6]>>cell_tmp[7];
+                cell_vec[i] = cell_tmp;
+            }
         }
+        SaveData_Ascii(numOfPoint,numOfCell,celltype,cell_vec);
     }
-    SaveData_Ascii(numOfPoint,numOfCell,celltype,cell_vec);
     return true;
 }
 
@@ -277,7 +232,7 @@ bool Mesh_Tecplot:: Load_Tecp_Binary(ifstream &infile)
     infile.read((char*)&fileType, sizeof(fileType));
     //cout << "file type:   " << fileType << "    (0:full  1:grid  2:solution)" << endl;
     //title
-   // cout << "title:  ";
+    // cout << "title:  ";
     int title_char = -1;
     vector<char> title;
     while (true)
@@ -433,16 +388,16 @@ bool Mesh_Tecplot:: Load_Tecp_Binary(ifstream &infile)
             cout << "Find unsupported data type, abort!" << endl;  //other markers are not supported now.
             return false;
         }
-       // cout << "----------zone " << zone_index+1 << " data----------" << endl;
-       // cout << "zone marker(299):  " << zoneMarker << endl;
+        // cout << "----------zone " << zone_index+1 << " data----------" << endl;
+        // cout << "zone marker(299):  " << zoneMarker << endl;
         zoneVarDataFormat[zone_index] = new int[nvar];
-       // cout << "variable data format(1=float, 2=double, others aren't supported): ";
+        // cout << "variable data format(1=float, 2=double, others aren't supported): ";
         infile.read((char*)zoneVarDataFormat[zone_index], sizeof(int)*nvar);
         for (int i = 0; i < nvar; ++i)
         {
-        //    cout << zoneVarDataFormat[zone_index][i] << " ";
+            //    cout << zoneVarDataFormat[zone_index][i] << " ";
         }
-       // cout << endl;
+        // cout << endl;
         int hasPassiveVariables, hasVariableSharing, zoneNumber_ShareConnectivity;
         infile.read((char*)&hasPassiveVariables, sizeof(hasPassiveVariables));
         //cout << "has passive variables:  " << hasPassiveVariables << endl;
@@ -604,7 +559,7 @@ bool Mesh_Tecplot:: Load_Tecp_Binary(ifstream &infile)
     }
     delete[] zoneScalarRange;
     delete[] zoneEleConnectivity;
-cout << "over" << endl;
+    cout << "over" << endl;
     return true;
 }
 
@@ -691,7 +646,7 @@ void Mesh_Tecplot::SaveData_Binary(
             {
                 int start = i * 3;
                 if (zoneEleConnectivity[blockIndex][start] == zoneEleConnectivity[blockIndex][start + 1] &&
-                    zoneEleConnectivity[blockIndex][start] == zoneEleConnectivity[blockIndex][start + 2])
+                        zoneEleConnectivity[blockIndex][start] == zoneEleConnectivity[blockIndex][start + 2])
                 {
                     /////////point
                     //vtkIdList* list = vtkIdList::New();
@@ -805,6 +760,10 @@ void Mesh_Tecplot::SaveData_Ascii(int numofpoint, int numofcell, string celltype
     zonePointsVec_.push_back(points);
     unMesh->SetPoints(points);
 
+    if(celltype_empty){
+        celltype = "triangle";
+    }
+
     CellBase* cell =0;
     if(celltype == "tetrahedron"){
         for(int i =0;i<numofcell;i++){
@@ -819,41 +778,40 @@ void Mesh_Tecplot::SaveData_Ascii(int numofpoint, int numofcell, string celltype
     }else if(celltype == "triangle"){
         for(int i =0;i<numofcell;i++){
             cell = new CellTetra();
-            cell->SetPoint(0,cell_vec[i][0]);
-            cell->SetPoint(1,cell_vec[i][1]);
-            cell->SetPoint(2,cell_vec[i][2]);
+            cell->SetPoint(0,cell_vec[i][0]-1);
+            cell->SetPoint(1,cell_vec[i][1]-1);
+            cell->SetPoint(2,cell_vec[i][2]-1);
             unMesh->SetCell(i,cell);
             delete cell;
         }
     }else if(celltype == "quadrilateral"){
         for(int i =0;i<numofcell;i++){
             cell = new CellTetra();
-            cell->SetPoint(0,cell_vec[i][0]);
-            cell->SetPoint(1,cell_vec[i][1]);
-            cell->SetPoint(2,cell_vec[i][2]);
-            cell->SetPoint(3,cell_vec[i][3]);
+            cell->SetPoint(0,cell_vec[i][0]-1);
+            cell->SetPoint(1,cell_vec[i][1]-1);
+            cell->SetPoint(2,cell_vec[i][2]-1);
+            cell->SetPoint(3,cell_vec[i][3]-1);
             unMesh->SetCell(i,cell);
             delete cell;
         }
     }else if(celltype == "brick"){
         for(int i =0;i<numofcell;i++){
             cell = new CellTetra();
-            cell->SetPoint(0,cell_vec[i][0]);
-            cell->SetPoint(1,cell_vec[i][1]);
-            cell->SetPoint(2,cell_vec[i][2]);
-            cell->SetPoint(3,cell_vec[i][3]);
-            cell->SetPoint(4,cell_vec[i][4]);
-            cell->SetPoint(5,cell_vec[i][5]);
-            cell->SetPoint(6,cell_vec[i][6]);
-            cell->SetPoint(7,cell_vec[i][7]);
+            cell->SetPoint(0,cell_vec[i][0]-1);
+            cell->SetPoint(1,cell_vec[i][1]-1);
+            cell->SetPoint(2,cell_vec[i][2]-1);
+            cell->SetPoint(3,cell_vec[i][3]-1);
+            cell->SetPoint(4,cell_vec[i][4]-1);
+            cell->SetPoint(5,cell_vec[i][5]-1);
+            cell->SetPoint(6,cell_vec[i][6]-1);
+            cell->SetPoint(7,cell_vec[i][7]-1);
             unMesh->SetCell(i,cell);
             delete cell;
         }
     }
+    celltype_empty = false;//再置回来
     /*************************************/
     //方便使用meshtovtksource这个接口进行转换拓扑
-    zoneScalarType_.resize(1);//tecplt单个文件只有一个zone
-    zoneScalarShareVec_.resize(1);
     vector<int> scalar_share_tmp;
     vector<int> scalar_type_tmp;
     scalar_share_tmp.resize(scalarNumber+3);
@@ -862,8 +820,8 @@ void Mesh_Tecplot::SaveData_Ascii(int numofpoint, int numofcell, string celltype
         scalar_type_tmp[i] = 0;//pointscalar
         scalar_share_tmp[i] = -1;//unshare
     }
-    zoneScalarType_[0] = scalar_type_tmp;
-    zoneScalarShareVec_[0] = scalar_share_tmp;
+    zoneScalarType_.push_back(scalar_type_tmp);
+    zoneScalarShareVec_.push_back(scalar_share_tmp);
     /*****************************************/
     zoneMeshVec_.push_back(unMesh);
 }
@@ -898,4 +856,21 @@ bool Mesh_Tecplot::Save_Binary(const string &gridFile)
     return true;
 }
 
+/*
+ * @brief: remove string's spaces
+ * @param: string
+ * @ret: void
+ * @birth: created by czm in 20230616
+ */
+void Mesh_Tecplot::trim(string &s)
+{
+    int index = 0;
+    if(!s.empty())
+    {
+        while( (index = s.find(' ',index)) != string::npos)
+        {
+            s.erase(index,1);
+        }
+    }
+}
 

+ 2 - 0
CAE_Solution/src/VTK/mesh/mesh_tecplot.h

@@ -39,6 +39,8 @@ private:
             int numofcell,
             string celltype,
             vector<vector<int>> &cell_vec);
+    void trim(string &s);
+    bool celltype_empty;
 };