推荐去看另外一篇文章,方法更简单->有问题加群:956765008
Midas GTS NX 的中性FPN文件转为 FLAC3D5.0的模型 (FPN to FLAC3D)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MIDAS GTS NX to FLAC3D5.0
0.使用方法:
0、数据导出之前:网格->工具->重新编号:单元、节点
1.//完整程序:
https://pan.baidu.com/s/11-FHPXhWDpMe1zY5vhjUVQ
2.//可以直接运行的程序:
https://pan.baidu.com/s/1QvgMsJG7lMpQ_1PTwyP7KA
3.//以下是完整代码及测试结果
/* 将Midas转为FLAC3D文件 2018.2.4 */
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <time.h>
using namespace std;
typedef struct tetCVert // 节点
{
double x, y, z; // 点坐标
int id, pointattribute;
tetCVert() {};
} tetCVert;
typedef struct tetCTrgl // 单元
{
int pt012[8]; //多边形的点号/ID,三个点或四个点
int id, tettattribute, polyhedron;
string elemname;
tetCTrgl() {};
} tetCTrgl;
/******************************************************************************************/
/*显示进度和持续时间。progress为进度百分比,取值为0~100, 2017.9.18*/
int display_progress(int i, int total, int Currentprogress, clock_t start, clock_t end)
{
int progress;
double cpuTime;
int hours, minutes, secs;
progress = i * 1.0 / total * 101;
if (progress == Currentprogress)
return progress;
cpuTime = (end-start)/ (CLOCKS_PER_SEC);
hours = cpuTime / 3600;
minutes = (cpuTime - 3600 * hours) / 60;
secs = cpuTime - hours * 3600 - minutes * 60;
/*把上次显示的进度条信息全部清空*/
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
/*输出进度条百分比*/
printf("\t进度:%d%%, 耗时:%dh%dm%ds", progress, hours, minutes, secs);
return progress;
}
/******************************************************************************************/
void printinformation()
{
cout<<"//************************************************************************//"<<endl;
cout<<" 2018.1.29 "<<endl;
cout<<" 将Midas GTS NX 转为 FLAC3D5.0 文件 "<<endl;
cout<<" 1、将mIDAS网格节点文件导出至XLSX中,整理成4列,分别为节点ID,X, Y, Z"<<endl;
cout<<"\t\t1)另存为nl.txt文本文件(制表符分隔)格式"<<endl;
cout<<"\t\t2)nl.txt文件第一行加上节点数量"<<endl;
cout<<"\t\t3)如下:"<<endl;
cout<<"\t\t1194 "<<endl;
cout<<"\t\t1 0.000000 0.000000 0.000000"<<endl;
cout<<"\t\t2 0.000000 0.000000 10.000000"<<endl;
cout<<"\t\t3 0.000000 0.000000 20.000000"<<endl;
cout<<"\t\t................................................"<<endl;
cout<<" 2、将mIDAS网格单元文件导出至XLSX中,整理成11列,分别为"<<endl;
cout<<"\t\t1)单元ID,单元类型,材料属性,节点ID1~8; 节点ID数量根据单元类型而定"<<endl;
cout<<"\t\t2)其中单元类型统一改为:六面体->8; 三棱柱->6; 金字塔->5;四面体->4"<<endl;
cout<<"\t\t3)材料属性统一改成阿拉伯数字,如1,2,3等"<<endl;
cout<<"\t\t4)另存为el.txt文本文件(制表符分隔)格式"<<endl;
cout<<"\t\t5)el.txt文件第一行加上单元数量"<<endl;
cout<<"\t\t6)如下:"<<endl;
cout<<"\t\t5190 "<<endl;
cout<<"\t\t1 4 1 1088 937 970 1051"<<endl;
cout<<"\t\t2 4 1 1076 679 767 891"<<endl;
cout<<"\t\t3 4 1 1076 891 767 911"<<endl;
cout<<"\t\t4 4 1 1076 912 891 911"<<endl;
cout<<"\t\t5 4 1 1076 752 679 821"<<endl;
cout<<"\t\t................................................"<<endl;
cout<<"//************************************************************************//"<<endl;
}
int main()
{
printinformation();
int id, attribute, polyhedron, hex[8] = { 0 };
int i, j;
int elemname;
double x, y, z;
vector<int>GroupNum;
bool gp = false;
tetCVert * PTS; // 存放所有块体的节点
tetCTrgl * HEX; // 存放所有块体的单元
int nVert, nHEX; //块体的节点和单元数量
string fnode, fele, ff;
cout<<"\n";
//打开节点文件
std::cout<<"请打开节点文件*.txt: ";
cin >> fnode;
ifstream finnode(fnode+".txt");
if (!finnode)
{
cout<<"\t"<<fnode<<".txt 节点文件打开失败!\n\n";
system("pause");
exit(1);
}
cout << endl;
//读入单元文件
std::cout<<"请打开单元文件*.txt: ";
cin >> fele;
ifstream finele(fele+".txt");
if (!finele)
{
cout<<"\t"<<fele<<".txt 单元文件打开失败!\n\n";
system("pause");
exit(1);
}
cout << endl;
//保存
cout<<"请输入结果文件名称*.flac3d: ";
cin >> ff;
cout << endl;
// Time
int Currentprogress = -1;
clock_t start, end;
start = clock();
/************************************************************/
//读入节点文件
finnode >> nVert;
PTS = new tetCVert[nVert];
//读入点
cout<<"\t正在读入节点...."<<endl;
for (i = 0; i < nVert; i++) {
finnode >> id >> x >> y >> z;
PTS[i].id = id;
PTS[i].x = x;
PTS[i].y = y;
PTS[i].z = z;
end = clock();
Currentprogress = display_progress(i, nVert, Currentprogress, start, end);
}
finnode.close();
cout<<"\n";
cout << "\t节点文件读入完成!\n\n";
/************************************************************/
/************************************************************************************************************************/
//读入单元文件
finele >> nHEX;
HEX = new tetCTrgl[nHEX];
GroupNum.push_back(0);
Currentprogress = -1;
cout<<"\t正在读入单元...."<<endl;
for (i = 0; i < nHEX; i++) {
gp = false;
finele >> id >> elemname >> attribute;
//if(elemname == "四面体") polyhedron = 4;
//if(elemname == "金字塔") polyhedron = 5;
//if(elemname == "三棱柱") polyhedron = 6;
//if(elemname == "六面体") polyhedron = 8;
if (elemname == 4) finele >> hex[0] >> hex[1] >> hex[2] >> hex[3];
if (elemname == 5) finele >> hex[0] >> hex[1] >> hex[2] >> hex[3] >> hex[4];
if (elemname == 6) finele >> hex[0] >> hex[1] >> hex[2] >> hex[3] >> hex[4] >> hex[5];
if (elemname == 8) finele >> hex[0] >> hex[1] >> hex[2] >> hex[3] >> hex[4] >> hex[5] >> hex[6] >> hex[7];
HEX[i].id = id;
HEX[i].elemname = elemname;
HEX[i].polyhedron = elemname;
HEX[i].tettattribute = attribute;
for (j = 0; j < GroupNum.size(); j++)
{
if (attribute == GroupNum.at(j))
{
gp = true;
break;
}
}
if (!gp) GroupNum.push_back(attribute);
for (int j = 0; j < elemname; j++)
{
HEX[i].pt012[j] = hex[j];
}
end = clock();
Currentprogress = display_progress(i, nHEX, Currentprogress, start, end);
}
finele.close();
cout<<"\n";
cout << "\t单元文件读入完成!\n\n";
/************************************************************************************************************************/
/**start********************************************************************/
/* 对点重新排序,并更新单元节点号*
for (i = 0; i < nHEX; i++) {
for (j = 0; j < HEX[i].polyhedron; j++) {
for (k = 0; k < nVert; k++) {
if (HEX[i].pt012[j] == PTS[k].id) { HEX[i].pt012[j] = k; }
}
}
}
/**end**********************************************************************/
/******************************************************************************************************************************************/
/* midas to FLAC3D*/
cout << "正在转换................\n\n";
ff = ff + "_midastoFLAC3D.flac3d";
ofstream fout(ff);
//节点
Currentprogress = -1;
cout<<"\t正在转换节点...."<<endl;
for (int i = 0; i < nVert; i++)
{
fout << "G\t" << PTS[i].id << "\t" << PTS[i].x << "\t" << PTS[i].y << "\t" << PTS[i].z << endl;
end = clock();
Currentprogress = display_progress(i, nVert, Currentprogress, start, end);
}
cout<<"\n";
cout << "\t节点转换完成!\n\n";
//单元
Currentprogress = -1;
cout<<"\t正在转换单元...."<<endl;
for (int i = 0; i < nHEX; i++)
{
hex[0] = HEX[i].pt012[0];
hex[1] = HEX[i].pt012[1];
hex[2] = HEX[i].pt012[2];
hex[3] = HEX[i].pt012[3];
hex[4] = HEX[i].pt012[4];
hex[5] = HEX[i].pt012[5];
hex[6] = HEX[i].pt012[6];
hex[7] = HEX[i].pt012[7];
polyhedron = HEX[i].polyhedron;
if (polyhedron == 4)
fout << "Z\t" << "T4\t" << HEX[i].id << "\t" << hex[0] << "\t" << hex[1] << "\t" << hex[2] << "\t" << hex[3] << endl;
if (polyhedron == 5)
fout << "Z\t" << "P5\t" << HEX[i].id << "\t" << hex[0] << "\t" << hex[1] << "\t" << hex[3] << "\t" << hex[4] << "\t" << hex[2] << endl;
if (polyhedron == 6)
fout << "Z\t" << "W6\t" << HEX[i].id << "\t" << hex[1] << "\t" << hex[0] << "\t" << hex[4] << "\t" << hex[2] << "\t" << hex[3] << "\t" << hex[5] << endl;
if (polyhedron == 8)
{
fout << "Z\t" << "B8\t" << HEX[i].id << "\t" << hex[0] << "\t" << hex[1] << "\t" << hex[3] << "\t" << hex[4] << "\t" << hex[2];
fout << "\t" << hex[7] << "\t" << hex[5] << "\t" << hex[6] << endl;
}
end = clock();
Currentprogress = display_progress(i, nHEX, Currentprogress, start, end);
}
cout<<"\n";
cout << "\t单元转换完成!\n\n";
//分组 GROUP ZGROUP ' ' SLOT 1
cout<<"\t正在转换分组信息...."<<endl;
for (i = 1; i < GroupNum.size(); i++)
{
fout << "ZGROUP\t" << "\'" << GroupNum.at(i) << "\'" << "\tSLOT 1" << endl;
for (j = 0; j < nHEX; j++)
{
if (HEX[j].tettattribute == GroupNum.at(i))
{
fout << HEX[j].id << " ";
if ((j + 1) % 10 == 0) fout << endl;
}
}
fout << endl;
}
fout.close();
cout<<"\n";
cout << "\t分组信息转换完成!\n\n";
delete[] PTS;
delete[] HEX;
GroupNum.clear();
cout<<"转换完成!\n\n";
cout << "文件已保存至: " << ff << endl;
/********************************************************************************************************************************************************/
system("pause");
return 0;
}
4.模型测试:335.6311 万个节点,1165.0211 万个单元,文件大小 656 MB;
4.1文件截图:
5.运行界面:
6.耗时:2min 5s
7.生成的flac3d5.0模型文件:文件大小766MB