FPN文件转为 FLAC3D5.0的模型
1.使用方法
新增:依据Midas中的网格组,将FLAC3D的模型进行分组的程序,无需再填写属性,数据导出之前一定要执行步骤(1),
(链接:https://pan.baidu.com/s/1JDsgstUYOtqw_Efcd-jXJg 提取码:6j3h ),2019.4.22,
有问题加群:956765008。
(1)数据导出之前:网格->工具->重新编号:单元、节点
请剖分的时候给网格组赋属性,这样才能在flac3d中正确分组,或者直接使用新的程序。
(2)打开MIDAS GTS NX 软件,单击界面左上角的NX图标,将模型输出为FPN格式的文件。
(请查看FPN文件的大小,确认里面是否存有节点和单元等数据,有时候会导出空的FPN文件)
(3)双击打开 FPNtoFLAC3D.exe ,输入FPN文件名称,回车,程序将自动开始读取文件,并转换为FLAC3D5.0文件。
(注意:FPNtoFLAC3D.exe 和 FPN文件放在同一个文件夹)
(保存在当前目录下)
2.可以直接运行的程序
https://pan.baidu.com/s/1nrCkDTBWkw4XluWV9lpD6Q
3.完整程序
https://pan.baidu.com/s/1u9Vq1eKkmkan2-gtygdOQA
4.以下为程序源码
/************************************************************************/
/* 将Midas的FPN中性文件转为FLAC3D文件 2018.4.7 */
/************************************************************************/
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
class CVert // 节点
{
public:
CVert() {};
CVert(int Id, double xx, double yy, double zz)
{
id = Id;
x = xx;
y = yy;
z = zz;
};
~CVert(){};
double x, y, z; // 点坐标
int id;
} ;
class CElem // 单元
{
public:
CElem(){};
CElem(int Id, int teta, int ph, string ele, int *nid)
{
id = Id;
polyhedron = ph;
tettattribute = teta;
pt012[0] = nid[0] - 1;
pt012[1] = nid[1] - 1;
pt012[2] = nid[2] - 1;
pt012[3] = nid[3] - 1;
pt012[4] = nid[4] - 1;
pt012[5] = nid[5] - 1;
pt012[6] = nid[6] - 1;
pt012[7] = nid[7] - 1;
};
~CElem(){};
int pt012[8];
int id;
int tettattribute;
int polyhedron;
string elemname;
} ;
void printinformation()
{
cout<<"//************************************************************************//"<<endl;
cout<<" 2018.4.7 "<<endl;
cout<<" 将Midas GTS NX 的 FPN 中性文件转为 FLAC3D5.0 文件 "<<endl;
cout<<"//************************************************************************//"<<endl;
}
int main()
{
printinformation();
int id;
vector<int>GroupNum;
bool gp = false;
string elemname;
string fpnname;
cout << endl;
std::cout<<"请打开FPN文件*.fpn: ";
cin >> fpnname;
ifstream fin(fpnname+".fpn");
if (!fin)
{
cout<<"\t"<<fpnname<<".fpn 文件打开失败!\n\n";
system("pause");
exit(1);
}
cout << endl;
/************************************************************/
//读入FPN文件
int num;
string lintext;
getline(fin, lintext);
cout<<"\t"<<lintext<<endl;
while(lintext != "$$ Node")
{
getline(fin, lintext);
cout<<"\t"<<lintext<<"\n";
}
//读入节点
string scom;
double x, y, z;
vector<CVert> pts;
fin >> lintext;
//cout<<"\t"<<lintext<<endl;
while(lintext == "NODE")
{
fin >> scom >> id >> scom;
fin >> x >> scom >> y >> scom >> z >> scom >> num;
fin >> scom >> scom >> scom;
pts.push_back(CVert(id, x, y, z));
fin >> lintext;
}
cout<<"\t读入 "<<pts.size() <<"个节点\n";
//读入单元
int attribute, polyhedron, hex[8];
vector<CElem> eles;
GroupNum.push_back(0);
fin >> lintext;
cout<<"\t$$\t"<<lintext<<endl;
fin >> lintext;
while(lintext != "$$")
{
gp = false;
if(lintext == "HEXA")
{
polyhedron = 8;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom;
fin >> hex[4] >> scom >> hex[5] >> scom >> hex[6] >> scom >> hex[7] >> scom;
fin >> scom >> scom >> scom >> scom >> scom;
}
if(lintext == "PRISM")
{
polyhedron = 6;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom;
fin >> hex[4] >> scom >> hex[5];
}
if(lintext == "PYRAM")
{
polyhedron = 5;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom >> hex[4] >> scom;
}
if(lintext == "TETRA")
{
polyhedron = 4;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom >> scom;
}
if (lintext == "TETRA" || lintext == "PYRAM" ||lintext == "PRISM" ||lintext == "HEXA")
{
eles.push_back(CElem(id, attribute, polyhedron, lintext, hex));
for (int j = 0; j < GroupNum.size(); j++)
{
if (attribute == GroupNum[j])
{
gp = true;
break;
}
}
if (!gp) GroupNum.push_back(attribute);
}
fin >> lintext;
}
fin.close();
cout<<"\t读入 "<<eles.size() <<"个单元\n";
//******************************************************************************************************************************************/
//* midas to FLAC3D*/
cout << "\n\n正在转换................\n\n";
string ff = fpnname + "_midastoFLAC3D.flac3d";
ofstream fout(ff);
//节点
cout<<"\t正在转换节点...."<<endl;
for (int i = 0; i < pts.size(); i++)
{
fout << "G\t" << pts[i].id << "\t" << pts[i].x << "\t" << pts[i].y << "\t" << pts[i].z << endl;
}
cout<<"\n";
//单元
cout<<"\t正在转换单元...."<<endl;
for (int i = 0; i < eles.size(); i++)
{
hex[0] = eles[i].pt012[0] + 1;
hex[1] = eles[i].pt012[1] + 1;
hex[2] = eles[i].pt012[2] + 1;
hex[3] = eles[i].pt012[3] + 1;
hex[4] = eles[i].pt012[4] + 1;
hex[5] = eles[i].pt012[5] + 1;
hex[6] = eles[i].pt012[6] + 1;
hex[7] = eles[i].pt012[7] + 1;
polyhedron = eles[i].polyhedron;
if (polyhedron == 4)
fout << "Z\t" << "T4\t" << eles[i].id << "\t" << hex[0] << "\t" << hex[1] << "\t" << hex[2] << "\t" << hex[3] << endl;
if (polyhedron == 5)
fout << "Z\t" << "P5\t" << eles[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" << eles[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" << eles[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;
}
}
cout<<"\n";
//分组 GROUP ZGROUP ' ' SLOT 1
cout<<"\t正在转换分组信息...."<<endl;
for (int i = 1; i < GroupNum.size(); i++)
{
fout << "ZGROUP\t" << "\'" << GroupNum.at(i) << "\'" << "\tSLOT 1" << endl;
for (int j = 0; j < eles.size(); j++)
{
if (eles[j].tettattribute == GroupNum.at(i))
{
fout << eles[j].id << " ";
if ((j + 1) % 10 == 0) fout << endl;
}
}
fout << endl;
}
fout.close();
cout<<"\n";
pts.clear();
pts.shrink_to_fit();
eles.clear();
eles.shrink_to_fit();
GroupNum.clear();
GroupNum.shrink_to_fit();
cout<<"转换完成!\n\n";
cout << "文件已保存至: " << ff << endl;
system("pause");
return 0;
}
/************************************************************************/
/* 将Midas的FPN中性文件转为FLAC3D文件 2019.4.22 */
/************************************************************************/
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
class CVert // 节点
{
public:
CVert() {};
CVert(int Id, double xx, double yy, double zz)
{
id = Id;
x = xx;
y = yy;
z = zz;
};
~CVert(){};
double x, y, z; // 点坐标
int id;
} ;
class CElem // 单元
{
public:
CElem(){};
CElem(int Id, int teta, int ph, string ele, int *nid)
{
id = Id;
polyhedron = ph;
tettattribute = teta;
pt012[0] = nid[0] - 1;
pt012[1] = nid[1] - 1;
pt012[2] = nid[2] - 1;
pt012[3] = nid[3] - 1;
pt012[4] = nid[4] - 1;
pt012[5] = nid[5] - 1;
pt012[6] = nid[6] - 1;
pt012[7] = nid[7] - 1;
};
~CElem(){};
int pt012[8];
int id;
int tettattribute;
int polyhedron;
string elemname;
} ;
void printinformation()
{
cout<<"//************************************************************************//"<<endl;
cout<<" 2018.4.7 "<<endl;
cout << " 2019.4.22修改:依据Midas中的网格组将FLAC3D中的模型进行分组 " << endl;
cout<<" 将Midas GTS NX 的 FPN 中性文件转为 FLAC3D5.0 文件 "<<endl;
cout<<"//************************************************************************//"<<endl;
}
int main()
{
printinformation();
int id;
//vector<int>GroupNum;
bool gp = false;
string elemname;
string fpnname;
cout << endl;
std::cout<<"请打开FPN文件*.fpn: ";
cin >> fpnname;
ifstream fin(fpnname+".fpn");
if (!fin)
{
cout<<"\t"<<fpnname<<".fpn 文件打开失败!\n\n";
system("pause");
exit(1);
}
cout << endl;
/************************************************************/
//读入FPN文件
int num;
string lintext;
getline(fin, lintext);
cout<<"\t"<<lintext<<endl;
while(lintext != "$$ Node")
{
getline(fin, lintext);
cout<<"\t"<<lintext<<"\n";
}
//读入节点
string scom;
double x, y, z;
vector<CVert> pts;
fin >> lintext;
//cout<<"\t"<<lintext<<endl;
while(lintext == "NODE")
{
fin >> scom >> id >> scom;
fin >> x >> scom >> y >> scom >> z >> scom >> num;
fin >> scom >> scom >> scom;
pts.push_back(CVert(id, x, y, z));
fin >> lintext;
}
cout<<"\t读入 "<<pts.size() <<"个节点\n";
//读入单元
int attribute, polyhedron, hex[8];
vector<CElem> eles;
//GroupNum.push_back(0);
fin >> lintext;
cout<<"\t$$\t"<<lintext<<endl;
fin >> lintext;
while(lintext != "$$")
{
//gp = false;
if(lintext == "HEXA")
{
polyhedron = 8;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom;
fin >> hex[4] >> scom >> hex[5] >> scom >> hex[6] >> scom >> hex[7] >> scom;
fin >> scom >> scom >> scom >> scom >> scom;
}
if(lintext == "PRISM")
{
polyhedron = 6;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom;
fin >> hex[4] >> scom >> hex[5];
}
if(lintext == "PYRAM")
{
polyhedron = 5;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom >> hex[4] >> scom;
}
if(lintext == "TETRA")
{
polyhedron = 4;
fin >> scom >> id >> scom >> attribute >> scom;
fin >> hex[0] >> scom >> hex[1] >> scom >> hex[2] >> scom >> hex[3] >> scom >> scom;
}
if (lintext == "TETRA" || lintext == "PYRAM" ||lintext == "PRISM" ||lintext == "HEXA")
{
eles.push_back(CElem(id, attribute, polyhedron, lintext, hex));
/*for (int j = 0; j < GroupNum.size(); j++)
{
if (attribute == GroupNum[j])
{
gp = true;
break;
}
}
if (!gp) GroupNum.push_back(attribute);*/
}
fin >> lintext;
}
cout<<"\t读入 "<<eles.size() <<"个单元\n";
//读入分组
while(lintext != "$$ MeshSet")
{
getline(fin, lintext);
}
cout<<"\t"<<lintext<<"\n";
fin >> lintext;
int elegroup = 0;
while(lintext != "$$")
{
while(lintext == "MSETE")
{
fin >> scom >> attribute >> scom >> num >> scom>> scom>> scom>> scom>> scom>> scom;
cout<<"GROUP: "<<attribute<<endl;
for(int i = 0; i < num; i++)
{
fin >> scom >>elegroup ;
eles[elegroup-1].tettattribute = attribute;
}
fin >> lintext;
}
fin >> lintext;
}
fin.close();
//******************************************************************************************************************************************/
//* midas to FLAC3D*/
cout << "\n\n正在转换................\n\n";
string ff = fpnname + "_midastoFLAC3D.flac3d";
ofstream fout(ff);
//节点
cout<<"\t正在转换节点...."<<endl;
for (int i = 0; i < pts.size(); i++)
{
fout << "G\t" << pts[i].id << "\t" << pts[i].x << "\t" << pts[i].y << "\t" << pts[i].z << endl;
}
cout<<"\n";
//单元
cout<<"\t正在转换单元...."<<endl;
for (int i = 0; i < eles.size(); i++)
{
hex[0] = eles[i].pt012[0] + 1;
hex[1] = eles[i].pt012[1] + 1;
hex[2] = eles[i].pt012[2] + 1;
hex[3] = eles[i].pt012[3] + 1;
hex[4] = eles[i].pt012[4] + 1;
hex[5] = eles[i].pt012[5] + 1;
hex[6] = eles[i].pt012[6] + 1;
hex[7] = eles[i].pt012[7] + 1;
polyhedron = eles[i].polyhedron;
if (polyhedron == 4)
fout << "Z\t" << "T4\t" << eles[i].id << "\t" << hex[0] << "\t" << hex[1] << "\t" << hex[2] << "\t" << hex[3] << endl;
if (polyhedron == 5)
fout << "Z\t" << "P5\t" << eles[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" << eles[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" << eles[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;
}
}
cout<<"\n";
//分组 GROUP ZGROUP ' ' SLOT 1
vector<int>GroupNum0;
GroupNum0.push_back(-1);
for(int i = 0; i < eles.size(); i++)
{
gp = false;
attribute = eles[i].tettattribute;
for (int j = 0; j < GroupNum0.size(); j++)
{
if (attribute == GroupNum0[j])
{
gp = true;
break;
}
}
if (!gp) GroupNum0.push_back(attribute);
}
cout<<"\t正在转换分组信息...."<<endl;
for (int i = 0; i < GroupNum0.size(); i++)
{
fout << "ZGROUP\t" << "\'" << GroupNum0.at(i) << "\'" << "\tSLOT 1" << endl;
for (int j = 0; j < eles.size(); j++)
{
if (eles[j].tettattribute == GroupNum0.at(i))
{
fout << eles[j].id << " ";
if ((j + 1) % 10 == 0) fout << endl;
}
}
fout << endl;
}
fout.close();
cout<<"\n";
pts.clear();
pts.shrink_to_fit();
eles.clear();
eles.shrink_to_fit();
//GroupNum.clear();
//GroupNum.shrink_to_fit();
GroupNum0.clear();
GroupNum0.shrink_to_fit();
cout<<"转换完成!\n\n";
cout << "文件已保存至: " << ff << endl;
system("pause");
return 0;
}