针对fluent集成案例修复bug

master
禅元天道 2023-07-25 13:12:18 +08:00
parent b4c4e7e064
commit d518eed8db
2 changed files with 477 additions and 592 deletions

View File

@ -18,14 +18,15 @@
#include <string> #include <string>
#include <set> #include <set>
namespace MeshData namespace MeshData {
{ MSHdataExchange::MSHdataExchange(const QString& fileName, MeshOperation operation,
MSHdataExchange::MSHdataExchange(const QString &fileName, MeshOperation operation, GUI::MainWindow *mw, int modelId) : // _fileName(fileName), GUI::MainWindow* mw, int modelId)
_operation(operation), : // _fileName(fileName),
_meshData(MeshData::getInstance()), _operation(operation)
_totalNumber(0), , _meshData(MeshData::getInstance())
MeshThreadBase(fileName, operation, mw), , _totalNumber(0)
_modelId(modelId) , MeshThreadBase(fileName, operation, mw)
, _modelId(modelId)
{ {
_fileName = fileName; _fileName = fileName;
_file = new QFile(_fileName); _file = new QFile(_fileName);
@ -43,10 +44,8 @@ namespace MeshData
QString MSHdataExchange::readLine() QString MSHdataExchange::readLine()
{ {
while (_threadRuning) while(_threadRuning) {
{ if(_stream->atEnd()) {
if (_stream->atEnd())
{
//_threadRuning = false; //_threadRuning = false;
return QString(); return QString();
; ;
@ -71,19 +70,15 @@ namespace MeshData
return false; return false;
// QTextStream* tempStream=new QTextStream(&tempfile); // QTextStream* tempStream=new QTextStream(&tempfile);
QTextStream tempStream(&tempfile); QTextStream tempStream(&tempfile);
while (!tempStream.atEnd()) while(!tempStream.atEnd()) {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
QString line = tempStream.readLine().simplified(); QString line = tempStream.readLine().simplified();
if (line.contains("GAMBIT")) if(line.contains("GAMBIT")) {
{
mMeshType = typeGambit; mMeshType = typeGambit;
tempfile.close(); tempfile.close();
return true; return true;
} } else if(line.contains("Fluent")) {
else if (line.contains("Fluent"))
{
mMeshType = typeFluent; mMeshType = typeFluent;
tempfile.close(); tempfile.close();
return true; return true;
@ -102,8 +97,7 @@ namespace MeshData
{ {
ModuleBase::ThreadTask::run(); ModuleBase::ThreadTask::run();
bool result = false; bool result = false;
switch (_operation) switch(_operation) {
{
case MESH_READ: case MESH_READ:
emit showInformation(tr("Import MSH Mesh File From \"%1\"").arg(_fileName)); emit showInformation(tr("Import MSH Mesh File From \"%1\"").arg(_fileName));
result = read(); result = read();
@ -120,9 +114,9 @@ namespace MeshData
bool MSHdataExchange::read() bool MSHdataExchange::read()
{ {
if (!readHeader()) if(!readHeader()) {
{ // QMessageBox::warning(nullptr, tr("Prompt"), tr("The file format could not parse the
// QMessageBox::warning(nullptr, tr("Prompt"), tr("The file format could not parse the amount!"), QMessageBox::Ok); // amount!"), QMessageBox::Ok);
return false; return false;
} }
@ -151,13 +145,11 @@ namespace MeshData
int kid = k->getID(); int kid = k->getID();
std::unordered_map<int, std::string> zones = parser->getZones(); std::unordered_map<int, std::string> zones = parser->getZones();
QMap<int, std::string> zoneNames{}; QMap<int, std::string> zoneNames{};
for (auto zone : zones) for(auto zone : zones) {
{
zoneNames.insert(zone.first, zone.second); zoneNames.insert(zone.first, zone.second);
} }
std::unordered_map<int, std::pair<int, int>> zoneIndexes = parser->getCellZones(); std::unordered_map<int, std::pair<int, int>> zoneIndexes = parser->getCellZones();
for (auto it : zoneIndexes) for(auto it : zoneIndexes) {
{
int setid = it.first; int setid = it.first;
MeshSet* set = new MeshSet; MeshSet* set = new MeshSet;
set->setType(SetType::Element); set->setType(SetType::Element);
@ -166,8 +158,7 @@ namespace MeshData
else else
set->setName("ElementSet" + QString::number(it.first)); set->setName("ElementSet" + QString::number(it.first));
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -178,8 +169,7 @@ namespace MeshData
set->appendTempMem(i - 1); set->appendTempMem(i - 1);
} }
std::unordered_map<int, std::pair<int, int>> faceZones = parser->getPointZones(); std::unordered_map<int, std::pair<int, int>> faceZones = parser->getPointZones();
for (auto it : faceZones) for(auto it : faceZones) {
{
int setid = it.first; int setid = it.first;
MeshSet* set = new MeshSet; MeshSet* set = new MeshSet;
set->setType(SetType::Node); set->setType(SetType::Node);
@ -188,8 +178,7 @@ namespace MeshData
else else
set->setName("PointSet" + QString::number(it.first)); set->setName("PointSet" + QString::number(it.first));
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -199,26 +188,24 @@ namespace MeshData
for(int i = firstIndex; i <= lastIndex; ++i) for(int i = firstIndex; i <= lastIndex; ++i)
set->appendTempMem(i - 1); set->appendTempMem(i - 1);
} }
std::unordered_map<int, std::pair<int, int>> face2CellIndex = parser->getFaceIDtoCellIndex(); std::unordered_map<int, std::pair<int, int>> face2CellIndex =
for (auto faceZone : parser->getFaceZones()) parser->getFaceIDtoCellIndex();
{ for(auto faceZone : parser->getFaceZones()) {
int zoneId = faceZone.first; int zoneId = faceZone.first;
if (zoneNames.contains(zoneId)) if(zoneNames.contains(zoneId)) {
{
BoundMeshSet* set = new BoundMeshSet; BoundMeshSet* set = new BoundMeshSet;
set->setName(QString::fromStdString(zoneNames[zoneId])); set->setName(QString::fromStdString(zoneNames[zoneId]));
QMap<int, QVector<int>> cellFaces{}; QMap<int, QVector<int>> cellFaces{};
int firstIndex = faceZone.second.first; int firstIndex = faceZone.second.first;
int lastIndex = faceZone.second.second; int lastIndex = faceZone.second.second;
for (int i = firstIndex; i <= lastIndex; ++i) for(int i = firstIndex; i <= lastIndex; ++i) {
{
int cellIndex = face2CellIndex[i].first; int cellIndex = face2CellIndex[i].first;
int index = face2CellIndex[i].second; int index = face2CellIndex[i].second;
cellFaces[cellIndex - 1].push_back(index - 1); cellFaces[cellIndex - 1].push_back(index - 1);
set->appendTempMem(i - 1);
} }
MeshSet* s = _idsetList.value(zoneId); MeshSet* s = _idsetList.value(zoneId);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(zoneId); _idsetList.remove(zoneId);
} }
@ -226,8 +213,7 @@ namespace MeshData
} }
} }
QList<MeshSet*> setList = _idsetList.values(); QList<MeshSet*> setList = _idsetList.values();
for (int i = 0; i < _idsetList.size(); ++i) for(int i = 0; i < _idsetList.size(); ++i) {
{
MeshSet* set = setList.at(i); MeshSet* set = setList.at(i);
set->setKeneralID(kid); set->setKeneralID(kid);
_meshData->appendMeshSet(set); _meshData->appendMeshSet(set);
@ -253,8 +239,7 @@ namespace MeshData
void MSHdataExchange::readPoints10(vtkUnstructuredGrid* dataset, QString info) void MSHdataExchange::readPoints10(vtkUnstructuredGrid* dataset, QString info)
{ {
vtkSmartPointer<vtkPoints> points = dataset->GetPoints(); vtkSmartPointer<vtkPoints> points = dataset->GetPoints();
if (points == nullptr) if(points == nullptr) {
{
points = vtkSmartPointer<vtkPoints>::New(); points = vtkSmartPointer<vtkPoints>::New();
dataset->SetPoints(points); dataset->SetPoints(points);
} }
@ -264,8 +249,7 @@ namespace MeshData
int startIndex = 0; int startIndex = 0;
int endIndex = 0; int endIndex = 0;
QStringList infos = info.split(" "); QStringList infos = info.split(" ");
if (infos.length() > 5) if(infos.length() > 5) {
{
if(!_threadRuning) if(!_threadRuning)
return; return;
index = strToInt(infos.at(0), true); index = strToInt(infos.at(0), true);
@ -277,8 +261,7 @@ namespace MeshData
set->setType(SetType::Node); set->setType(SetType::Node);
set->setName("Point"); set->setName("Point");
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -287,13 +270,11 @@ namespace MeshData
// vtkIdTypeArray* idlist = vtkIdTypeArray::New(); // vtkIdTypeArray* idlist = vtkIdTypeArray::New();
double coordinate[3] = { 0.0, 0.0, 0.0 }; double coordinate[3] = { 0.0, 0.0, 0.0 };
// fluent文件会多出一行( // fluent文件会多出一行(
if (mMeshType == typeFluent) if(mMeshType == typeFluent) {
{
QString line = this->readLine(); QString line = this->readLine();
} }
// //
for (int i = startIndex; i <= endIndex; i++) for(int i = startIndex; i <= endIndex; i++) {
{
if(!_threadRuning) if(!_threadRuning)
return; return;
// idlist->InsertNextValue(i); // idlist->InsertNextValue(i);
@ -315,8 +296,7 @@ namespace MeshData
void MSHdataExchange::readPoints130(vtkUnstructuredGrid* dataset, QString info) void MSHdataExchange::readPoints130(vtkUnstructuredGrid* dataset, QString info)
{ {
vtkSmartPointer<vtkPoints> points = dataset->GetPoints(); vtkSmartPointer<vtkPoints> points = dataset->GetPoints();
if (points == nullptr) if(points == nullptr) {
{
points = vtkSmartPointer<vtkPoints>::New(); points = vtkSmartPointer<vtkPoints>::New();
dataset->SetPoints(points); dataset->SetPoints(points);
} }
@ -329,8 +309,7 @@ namespace MeshData
set->setType(SetType::Node); set->setType(SetType::Node);
set->setName("001"); set->setName("001");
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -338,8 +317,7 @@ namespace MeshData
// vtkIdTypeArray* idlist = vtkIdTypeArray::New(); // vtkIdTypeArray* idlist = vtkIdTypeArray::New();
double coordinate[3] = { 0.0, 0.0, 0.0 }; double coordinate[3] = { 0.0, 0.0, 0.0 };
for (int i = startIndex; i <= endIndex; ++i) for(int i = startIndex; i <= endIndex; ++i) {
{
if(!_threadRuning) if(!_threadRuning)
return; return;
// idlist->InsertNextValue(i); // idlist->InsertNextValue(i);
@ -365,8 +343,7 @@ namespace MeshData
set->setType(SetType::Element); set->setType(SetType::Element);
set->setName("002"); set->setName("002");
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -374,8 +351,7 @@ namespace MeshData
// vtkIdTypeArray* idlist = vtkIdTypeArray::New(); // vtkIdTypeArray* idlist = vtkIdTypeArray::New();
double coordinate[3] = { 0.0, 0.0, 0.0 }; double coordinate[3] = { 0.0, 0.0, 0.0 };
for (int i = startIndex; i <= endIndex; ++i) for(int i = startIndex; i <= endIndex; ++i) {
{
if(!_threadRuning) if(!_threadRuning)
return; return;
// idlist->InsertNextValue(i); // idlist->InsertNextValue(i);
@ -384,23 +360,18 @@ namespace MeshData
QStringList selelist = sele.split(" "); QStringList selelist = sele.split(" ");
QList<int> member; QList<int> member;
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
for (int i = 0; i < selelist.size(); ++i) for(int i = 0; i < selelist.size(); ++i) {
{
if(!_threadRuning) if(!_threadRuning)
return; return;
int d = selelist.at(i).toInt(); int d = selelist.at(i).toInt();
if (!member.contains(d)) if(!member.contains(d)) {
{
member.append(d); member.append(d);
idlist->InsertNextId(d); idlist->InsertNextId(d);
} }
} }
if (member.size() == 3) if(member.size() == 3) {
{
dataset->InsertNextCell(VTK_TRIANGLE, idlist); dataset->InsertNextCell(VTK_TRIANGLE, idlist);
} } else if(member.size() == 4) {
else if (member.size() == 4)
{
dataset->InsertNextCell(VTK_QUAD, idlist); dataset->InsertNextCell(VTK_QUAD, idlist);
} }
} }
@ -417,8 +388,7 @@ namespace MeshData
set->setType(SetType::Element); set->setType(SetType::Element);
set->setName("002"); set->setName("002");
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -426,29 +396,23 @@ namespace MeshData
// vtkIdTypeArray* idlist = vtkIdTypeArray::New(); // vtkIdTypeArray* idlist = vtkIdTypeArray::New();
double coordinate[3] = { 0.0, 0.0, 0.0 }; double coordinate[3] = { 0.0, 0.0, 0.0 };
for (int i = startIndex; i <= endIndex; ++i) for(int i = startIndex; i <= endIndex; ++i) {
{
// idlist->InsertNextValue(i); // idlist->InsertNextValue(i);
set->appendTempMem(i); set->appendTempMem(i);
QString sele = this->readLine(); QString sele = this->readLine();
QStringList selelist = sele.split(" "); QStringList selelist = sele.split(" ");
QList<int> member; QList<int> member;
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
for (int i = 0; i < selelist.size(); ++i) for(int i = 0; i < selelist.size(); ++i) {
{
int d = selelist.at(i).toInt(); int d = selelist.at(i).toInt();
if (!member.contains(d)) if(!member.contains(d)) {
{
member.append(d); member.append(d);
idlist->InsertNextId(d); idlist->InsertNextId(d);
} }
} }
if (member.size() == 3) if(member.size() == 3) {
{
dataset->InsertNextCell(VTK_TRIANGLE, idlist); dataset->InsertNextCell(VTK_TRIANGLE, idlist);
} } else if(member.size() == 4) {
else if (member.size() == 4)
{
dataset->InsertNextCell(VTK_QUAD, idlist); dataset->InsertNextCell(VTK_QUAD, idlist);
} }
} }
@ -491,8 +455,7 @@ namespace MeshData
set->setType(SetType::Element); set->setType(SetType::Element);
set->setName("002"); set->setName("002");
MeshSet* s = _idsetList.value(setid); MeshSet* s = _idsetList.value(setid);
if (s != nullptr) if(s != nullptr) {
{
delete s; delete s;
_idsetList.remove(setid); _idsetList.remove(setid);
} }
@ -501,8 +464,7 @@ namespace MeshData
facenumber = endIndex - startIndex + 1; facenumber = endIndex - startIndex + 1;
// vtkIdTypeArray* idlist = vtkIdTypeArray::New(); // vtkIdTypeArray* idlist = vtkIdTypeArray::New();
double coordinate[3] = { 0.0, 0.0, 0.0 }; double coordinate[3] = { 0.0, 0.0, 0.0 };
for (int i = 0; i < facenumber; ++i) for(int i = 0; i < facenumber; ++i) {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
QList<int> member; QList<int> member;
@ -512,15 +474,12 @@ namespace MeshData
QString sele = this->readLine(); QString sele = this->readLine();
QStringList selelist = sele.split(" "); QStringList selelist = sele.split(" ");
int firstFaceType = 0; int firstFaceType = 0;
if (mMeshType == typeGambit) if(mMeshType == typeGambit) {
{
// 取每一个面对应的类型,不是头中的类型 // 取每一个面对应的类型,不是头中的类型
if (selelist.count() > 1) if(selelist.count() > 1) {
{
firstFaceType = strToInt(selelist.at(0)); firstFaceType = strToInt(selelist.at(0));
} }
} } else if(mMeshType == typeFluent) // fluent类型文件面中没有类型这里取的是头中的类型
else if (mMeshType == typeFluent) // fluent类型文件面中没有类型这里取的是头中的类型
{ {
firstFaceType = facetype; firstFaceType = facetype;
} }
@ -529,44 +488,31 @@ namespace MeshData
// 第一个字符串是单元类型,不需要保存,最后两个字符串不需要保存一个是cellid,另外一个为0 // 第一个字符串是单元类型,不需要保存,最后两个字符串不需要保存一个是cellid,另外一个为0
// 4 1 77 32b0 29 0 1 // 4 1 77 32b0 29 0 1
int j = 0; int j = 0;
if (mMeshType == typeFluent) if(mMeshType == typeFluent) {
{
j = 0; j = 0;
} } else if(mMeshType == typeGambit) {
else if (mMeshType == typeGambit)
{
j = 1; j = 1;
} }
for (j; j <= selelist.count() - 3; j++) for(j; j <= selelist.count() - 3; j++) {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
int pointIndex = strToInt(selelist.at(j), true); int pointIndex = strToInt(selelist.at(j), true);
if (pointIndex > 0) if(pointIndex > 0) {
{
pointIndex = pointIndex - 1; pointIndex = pointIndex - 1;
if (!member.contains(pointIndex)) if(!member.contains(pointIndex)) {
{
member.append(pointIndex); member.append(pointIndex);
pointIdList->InsertNextId(pointIndex); pointIdList->InsertNextId(pointIndex);
} }
} }
} }
if (firstFaceType == 3) if(firstFaceType == 3) {
{
dataset->InsertNextCell(VTK_TRIANGLE, pointIdList); dataset->InsertNextCell(VTK_TRIANGLE, pointIdList);
} } else if(firstFaceType == 4) {
else if (firstFaceType == 4)
{
dataset->InsertNextCell(VTK_QUAD, pointIdList); dataset->InsertNextCell(VTK_QUAD, pointIdList);
} } else if(firstFaceType == 2) {
else if (firstFaceType == 2)
{
dataset->InsertNextCell(VTK_LINE, pointIdList); dataset->InsertNextCell(VTK_LINE, pointIdList);
} } else if(firstFaceType == 5) {
else if (firstFaceType == 5)
{
dataset->InsertNextCell(VTK_POLYGON, pointIdList); dataset->InsertNextCell(VTK_POLYGON, pointIdList);
} }
} }
@ -584,10 +530,8 @@ namespace MeshData
bool MSHdataExchange::isHex(QString line) bool MSHdataExchange::isHex(QString line)
{ {
bool isHex = false; bool isHex = false;
for (int i = 0; i < line.length(); i++) for(int i = 0; i < line.length(); i++) {
{ if(line.at(i) > '9') {
if (line.at(i) > '9')
{
isHex = true; isHex = true;
return isHex; return isHex;
} }
@ -597,12 +541,9 @@ namespace MeshData
int MSHdataExchange::strToInt(QString line, bool isHex) int MSHdataExchange::strToInt(QString line, bool isHex)
{ {
if (isHex) if(isHex) {
{
return line.toInt(0, 16); return line.toInt(0, 16);
} } else {
else
{
return line.toInt(); return line.toInt();
} }
} }
@ -610,16 +551,14 @@ namespace MeshData
bool MSHdataExchange::readGambitFile(vtkUnstructuredGrid* dataset) bool MSHdataExchange::readGambitFile(vtkUnstructuredGrid* dataset)
{ {
QString line; QString line;
do do {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
line = this->readLine(); line = this->readLine();
char* ch; char* ch;
QByteArray ba = line.toLatin1(); QByteArray ba = line.toLatin1();
ch = ba.data(); ch = ba.data();
if (line.endsWith(")(")) if(line.endsWith(")(")) {
{
line = line.remove("(").remove(")"); line = line.remove("(").remove(")");
if(line.isEmpty()) if(line.isEmpty())
continue; continue;
@ -628,29 +567,23 @@ namespace MeshData
int index; int index;
// 取出数字标识 // 取出数字标识
sscanf(ch, "(%d", &index); sscanf(ch, "(%d", &index);
if (slist.at(0) == "0") if(slist.at(0) == "0") {
{
_describe = slist.at(1); _describe = slist.at(1);
_describe.remove("\""); _describe.remove("\"");
} }
if (index == 130) if(index == 130) {
{
readPoints130(dataset, line); readPoints130(dataset, line);
} } else if(slist.at(0) == "120") {
else if (slist.at(0) == "120")
{
readCells120(dataset, line); readCells120(dataset, line);
} }
// 10为GAMBIT to Fluent File // 10为GAMBIT to Fluent File
else if (index == 10) else if(index == 10) {
{
// 读取16进制 // 读取16进制
readPoints10(dataset, line); readPoints10(dataset, line);
} }
// 读取Face // 读取Face
if (index == 13) if(index == 13) {
{
//(13(0 1 1a7c9 0)) //(13(0 1 1a7c9 0))
// 13如果为13标志在13后插入空格和其他格式对应上 // 13如果为13标志在13后插入空格和其他格式对应上
QString replaceLine; QString replaceLine;
@ -658,9 +591,7 @@ namespace MeshData
replaceLine.insert(2, " "); replaceLine.insert(2, " ");
readFace13(dataset, replaceLine); readFace13(dataset, replaceLine);
} }
} } else if(line.endsWith("))") && line.startsWith("(")) {
else if (line.endsWith("))") && line.startsWith("("))
{
line = line.remove("(").remove(")"); line = line.remove("(").remove(")");
if(line.isEmpty()) if(line.isEmpty())
continue; continue;
@ -672,8 +603,7 @@ namespace MeshData
} while(!_stream->atEnd()); } while(!_stream->atEnd());
_file->close(); _file->close();
QList<MeshSet*> setList = _idsetList.values(); QList<MeshSet*> setList = _idsetList.values();
if (dataset != nullptr) if(dataset != nullptr) {
{
MeshKernal* k = new MeshKernal; MeshKernal* k = new MeshKernal;
k->setName(_baseFileName); k->setName(_baseFileName);
k->setPath(_filePath); k->setPath(_filePath);
@ -681,8 +611,7 @@ namespace MeshData
_meshData->appendMeshKernal(k); _meshData->appendMeshKernal(k);
int kid = k->getID(); int kid = k->getID();
for (int i = 0; i < setList.size(); ++i) for(int i = 0; i < setList.size(); ++i) {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
MeshSet* set = setList.at(i); MeshSet* set = setList.at(i);
@ -693,8 +622,7 @@ namespace MeshData
return true; return true;
} }
for (int i = 0; i < setList.size(); ++i) for(int i = 0; i < setList.size(); ++i) {
{
MeshSet* set = setList.at(i); MeshSet* set = setList.at(i);
delete set; delete set;
} }
@ -705,8 +633,7 @@ namespace MeshData
bool MSHdataExchange::readFluentFile(vtkUnstructuredGrid* dataset) bool MSHdataExchange::readFluentFile(vtkUnstructuredGrid* dataset)
{ {
QString line; QString line;
do do {
{
if(!_threadRuning) if(!_threadRuning)
return false; return false;
line = this->readLine(); line = this->readLine();
@ -722,15 +649,12 @@ namespace MeshData
int index; int index;
// 取出数字标识 // 取出数字标识
sscanf(ch, "(%d", &index); sscanf(ch, "(%d", &index);
if (slist.at(0) == "0") if(slist.at(0) == "0") {
{
_describe = slist.at(1); _describe = slist.at(1);
_describe.remove("\""); _describe.remove("\"");
} }
// 10为GAMBIT to Fluent File // 10为GAMBIT to Fluent File
else if (index == 10) else if(index == 10) {
{
startIndex = strToInt(slist.at(1), true); startIndex = strToInt(slist.at(1), true);
// 如果startindex<1应该是区的标识不读取 // 如果startindex<1应该是区的标识不读取
if(startIndex < 1) if(startIndex < 1)
@ -739,27 +663,23 @@ namespace MeshData
readPoints10(dataset, line); readPoints10(dataset, line);
} }
// 读取Face // 读取Face
else if (index == 13) else if(index == 13) {
{
// face面总的信息不读取 // face面总的信息不读取
startIndex = strToInt(slist.at(1), true); startIndex = strToInt(slist.at(1), true);
if (startIndex < 1) if(startIndex < 1) {
{
continue; continue;
} }
readFace13(dataset, line); readFace13(dataset, line);
} }
// 读取区域名称,包含边界 // 读取区域名称,包含边界
if (index == 39) if(index == 39) {
{
QStringList slist = line.split(" "); QStringList slist = line.split(" ");
readZone45(line); readZone45(line);
} }
} while(!_stream->atEnd()); } while(!_stream->atEnd());
_file->close(); _file->close();
QList<MeshSet*> setList = _idsetList.values(); QList<MeshSet*> setList = _idsetList.values();
if (dataset != nullptr) if(dataset != nullptr) {
{
MeshKernal* k = new MeshKernal; MeshKernal* k = new MeshKernal;
k->setName(_baseFileName); k->setName(_baseFileName);
k->setPath(_filePath); k->setPath(_filePath);
@ -768,8 +688,7 @@ namespace MeshData
int kid = k->getID(); int kid = k->getID();
for (int i = 0; i < setList.size(); ++i) for(int i = 0; i < setList.size(); ++i) {
{
MeshSet* set = setList.at(i); MeshSet* set = setList.at(i);
// set->setDataSet(dataset); // set->setDataSet(dataset);
set->setKeneralID(kid); set->setKeneralID(kid);
@ -778,8 +697,7 @@ namespace MeshData
return true; return true;
} }
for (int i = 0; i < setList.size(); ++i) for(int i = 0; i < setList.size(); ++i) {
{
MeshSet* set = setList.at(i); MeshSet* set = setList.at(i);
delete set; delete set;
} }
@ -787,7 +705,6 @@ namespace MeshData
return false; return false;
} }
bool CFDMshFileParser::setFile(const std::string& file) bool CFDMshFileParser::setFile(const std::string& file)
{ {
m_File = file; m_File = file;
@ -843,8 +760,7 @@ namespace MeshData
{ {
std::ifstream in{}; std::ifstream in{};
in.open(m_File, std::ios_base::in); in.open(m_File, std::ios_base::in);
if (!in.is_open()) if(!in.is_open()) {
{
return false; return false;
} }
std::stringstream buffer; std::stringstream buffer;
@ -872,8 +788,7 @@ namespace MeshData
int first = m_ByteArray.find(nodeLabel); int first = m_ByteArray.find(nodeLabel);
if(first == -1) if(first == -1)
return false; return false;
while (first != -1) while(first != -1) {
{
int end = m_ByteArray.find("\n", first + nlSize); int end = m_ByteArray.find("\n", first + nlSize);
if(end == -1) if(end == -1)
return false; return false;
@ -892,13 +807,10 @@ namespace MeshData
int fIndex{ 0 }, lIndex{ 0 }; int fIndex{ 0 }, lIndex{ 0 };
sscanf(firstIndex.c_str(), "%X", &fIndex); sscanf(firstIndex.c_str(), "%X", &fIndex);
sscanf(lastIndex.c_str(), "%X", &lIndex); sscanf(lastIndex.c_str(), "%X", &lIndex);
if (zoneID == 0) if(zoneID == 0) {
{
std::string pnStr = list.at(3); std::string pnStr = list.at(3);
m_PointNumber = strtol(pnStr.c_str(), 0, 16); m_PointNumber = strtol(pnStr.c_str(), 0, 16);
} } else {
else
{
m_PointZones[zoneID] = std::make_pair(fIndex, lIndex); m_PointZones[zoneID] = std::make_pair(fIndex, lIndex);
int first = m_ByteArray.find(")", end + 1); int first = m_ByteArray.find(")", end + 1);
if(first == -1) if(first == -1)
@ -906,14 +818,12 @@ namespace MeshData
std::string nodes = m_ByteArray.substr(end + 1, first - end); std::string nodes = m_ByteArray.substr(end + 1, first - end);
std::vector<std::string> arrays{}; std::vector<std::string> arrays{};
stringSplit(nodes, '\n', arrays); stringSplit(nodes, '\n', arrays);
for (auto& array : arrays) for(auto& array : arrays) {
{
std::string coords{ array }; std::string coords{ array };
stringTrimmed(coords); stringTrimmed(coords);
std::vector<std::string> cs{}; std::vector<std::string> cs{};
stringSplit(coords, ' ', cs); stringSplit(coords, ' ', cs);
if (cs.size() == 3) if(cs.size() == 3) {
{
m_Points.push_back(atof(cs.at(0).c_str())); m_Points.push_back(atof(cs.at(0).c_str()));
m_Points.push_back(atof(cs.at(1).c_str())); m_Points.push_back(atof(cs.at(1).c_str()));
m_Points.push_back(atof(cs.at(2).c_str())); m_Points.push_back(atof(cs.at(2).c_str()));
@ -930,16 +840,14 @@ namespace MeshData
{ {
std::string zoneLable{ "\n(39" }; std::string zoneLable{ "\n(39" };
int first = m_ByteArray.find(zoneLable); int first = m_ByteArray.find(zoneLable);
if (first == -1) if(first == -1) {
{
zoneLable = "\n(45"; zoneLable = "\n(45";
first = m_ByteArray.find(zoneLable); first = m_ByteArray.find(zoneLable);
} }
if(first == -1) if(first == -1)
return false; return false;
int clSize = zoneLable.size(); int clSize = zoneLable.size();
while (first != -1) while(first != -1) {
{
int end = m_ByteArray.find("\n", first + clSize); int end = m_ByteArray.find("\n", first + clSize);
std::string line = m_ByteArray.substr(first + clSize, end - first - clSize); std::string line = m_ByteArray.substr(first + clSize, end - first - clSize);
int i = line.find("("); int i = line.find("(");
@ -952,8 +860,7 @@ namespace MeshData
stringTrimmed(element); stringTrimmed(element);
std::vector<std::string> segs{}; std::vector<std::string> segs{};
stringSplit(element, ' ', segs); stringSplit(element, ' ', segs);
if (segs.size() >= 3) if(segs.size() >= 3) {
{
std::string name = segs.at(2); std::string name = segs.at(2);
int zoneID = strtol(segs.at(0).c_str(), 0, 10); int zoneID = strtol(segs.at(0).c_str(), 0, 10);
m_Zones[zoneID] = name; m_Zones[zoneID] = name;
@ -971,8 +878,7 @@ namespace MeshData
int first = m_ByteArray.find(faceLable); int first = m_ByteArray.find(faceLable);
if(first == -1) if(first == -1)
return false; return false;
while (first != -1) while(first != -1) {
{
int end = m_ByteArray.find("\n", first + flSize); int end = m_ByteArray.find("\n", first + flSize);
if(end == -1) if(end == -1)
return false; return false;
@ -991,12 +897,9 @@ namespace MeshData
sscanf(zoneStr.c_str(), "%x", &zoneId); sscanf(zoneStr.c_str(), "%x", &zoneId);
int startFaceIndex = strtol(list.at(1).c_str(), 0, 16); int startFaceIndex = strtol(list.at(1).c_str(), 0, 16);
int endFaceIndex = strtol(list.at(2).c_str(), 0, 16); int endFaceIndex = strtol(list.at(2).c_str(), 0, 16);
if (zoneId == 0) if(zoneId == 0) {
{
m_FaceNumber = strtol(list.at(2).c_str(), 0, 16); m_FaceNumber = strtol(list.at(2).c_str(), 0, 16);
} } else {
else
{
m_FaceZones[zoneId] = std::make_pair(startFaceIndex, endFaceIndex); m_FaceZones[zoneId] = std::make_pair(startFaceIndex, endFaceIndex);
int bcType; int bcType;
sscanf(list.at(3).c_str(), "%d", &bcType); sscanf(list.at(3).c_str(), "%d", &bcType);
@ -1008,8 +911,7 @@ namespace MeshData
std::string faces = m_ByteArray.substr(end + 1, first - end); std::string faces = m_ByteArray.substr(end + 1, first - end);
std::vector<std::string> arrays{}; std::vector<std::string> arrays{};
stringSplit(faces, '\n', arrays); stringSplit(faces, '\n', arrays);
for (auto& array : arrays) for(auto& array : arrays) {
{
std::string coords{ array }; std::string coords{ array };
stringTrimmed(coords); stringTrimmed(coords);
std::vector<std::string> cs{}; std::vector<std::string> cs{};
@ -1032,12 +934,12 @@ namespace MeshData
int first = m_ByteArray.find(cellLable); int first = m_ByteArray.find(cellLable);
if(first == -1) if(first == -1)
return false; return false;
while (first != -1) while(first != -1) {
{
int end = m_ByteArray.find("\n", first + clSize); int end = m_ByteArray.find("\n", first + clSize);
if(end == -1) if(end == -1)
return false; return false;
std::string element{ m_ByteArray.substr(first + cellLable.size(), end - first-cellLable.size()) }; std::string element{ m_ByteArray.substr(first + cellLable.size(),
end - first - cellLable.size()) };
stringTrimmed(element); stringTrimmed(element);
std::vector<std::string> list{}; std::vector<std::string> list{};
stringSplit(element, ' ', list); stringSplit(element, ' ', list);
@ -1050,26 +952,22 @@ namespace MeshData
int type = strtol(list.at(3).c_str(), 0, 16); int type = strtol(list.at(3).c_str(), 0, 16);
if(zoneId == 0) if(zoneId == 0)
; ;
else else {
{
m_CellZones[zoneId] = std::make_pair(startIndex, endIndex); m_CellZones[zoneId] = std::make_pair(startIndex, endIndex);
std::string str = list.at(4); std::string str = list.at(4);
int elementType{ -1 }; int elementType{ -1 };
std::string etStr = str.substr(0, str.find_first_of(")")); std::string etStr = str.substr(0, str.find_first_of(")"));
sscanf(etStr.c_str(), "%x", &elementType); sscanf(etStr.c_str(), "%x", &elementType);
if (elementType == 0) if(elementType == 0) {
{
int bodyEnd = m_ByteArray.find(")", end + 1); int bodyEnd = m_ByteArray.find(")", end + 1);
if (bodyEnd != -1) if(bodyEnd != -1) {
{
std::string body{ m_ByteArray.substr(end + 1, bodyEnd - end - 1) }; std::string body{ m_ByteArray.substr(end + 1, bodyEnd - end - 1) };
stringTrimmed(body); stringTrimmed(body);
if(body.at(0) == '(') if(body.at(0) == '(')
body = body.substr(1); body = body.substr(1);
std::vector<std::string> types{}; std::vector<std::string> types{};
stringSplit(body, ' ', types); stringSplit(body, ' ', types);
for (const std::string& ty : types) for(const std::string& ty : types) {
{
int type{}; int type{};
sscanf(ty.c_str(), "%d", &type); sscanf(ty.c_str(), "%d", &type);
m_CellsType[startIndex] = type; m_CellsType[startIndex] = type;
@ -1077,9 +975,7 @@ namespace MeshData
} }
end = bodyEnd; end = bodyEnd;
} }
} } else {
else
{
for(int i = startIndex; i <= endIndex; ++i) for(int i = startIndex; i <= endIndex; ++i)
m_CellsType[i] = elementType; m_CellsType[i] = elementType;
} }
@ -1089,22 +985,21 @@ namespace MeshData
return true; return true;
} }
void CFDMshFileParser::parseFaceAndCells(int faceIndex, const std::vector<std::string>& faceLineSegs, int faceType) void CFDMshFileParser::parseFaceAndCells(int faceIndex,
const std::vector<std::string>& faceLineSegs,
int faceType)
{ {
bool ok; bool ok;
switch (faceType) switch(faceType) {
{ case 0:
case 0: case 5: case 5: {
{ if(faceLineSegs.size() >= 5) {
if (faceLineSegs.size() >= 5)
{
std::string pnStr = faceLineSegs.front(); std::string pnStr = faceLineSegs.front();
int pointNum{ 0 }; int pointNum{ 0 };
sscanf(pnStr.c_str(), "%d", &pointNum); sscanf(pnStr.c_str(), "%d", &pointNum);
std::vector<int> pointIDs{}; std::vector<int> pointIDs{};
int i = 1; int i = 1;
for (; i <= pointNum; ++i) for(; i <= pointNum; ++i) {
{
std::string idStr = faceLineSegs.at(i); std::string idStr = faceLineSegs.at(i);
int id = strtol(idStr.c_str(), 0, 16); int id = strtol(idStr.c_str(), 0, 16);
pointIDs.push_back(id); pointIDs.push_back(id);
@ -1115,26 +1010,23 @@ namespace MeshData
++i; ++i;
std::string nbStr = faceLineSegs.at(i); std::string nbStr = faceLineSegs.at(i);
int neigbur = strtol(nbStr.c_str(), 0, 16); int neigbur = strtol(nbStr.c_str(), 0, 16);
if (owner != 0) if(owner != 0) {
{
m_Cells[owner].push_back(faceIndex); m_Cells[owner].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(owner, m_Cells[owner].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(owner, m_Cells[owner].size());
} }
if (neigbur != 0) if(neigbur != 0) {
{
m_Cells[neigbur].push_back(faceIndex); m_Cells[neigbur].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(neigbur, m_Cells[neigbur].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(neigbur, m_Cells[neigbur].size());
} }
} }
} } break;
break; case 3: {
case 3:
{
if(faceLineSegs.size() != 5) if(faceLineSegs.size() != 5)
return; return;
std::vector<int> pointIds{}; std::vector<int> pointIds{};
for (int i = 0; i< 3; ++i) for(int i = 0; i < 3; ++i) {
{
int id = strtol(faceLineSegs.at(i).c_str(), 0, 16); int id = strtol(faceLineSegs.at(i).c_str(), 0, 16);
pointIds.push_back(id); pointIds.push_back(id);
} }
@ -1143,25 +1035,22 @@ namespace MeshData
int owner = strtol(ownerStr.c_str(), 0, 16); int owner = strtol(ownerStr.c_str(), 0, 16);
std::string nbStr{ faceLineSegs.at(4) }; std::string nbStr{ faceLineSegs.at(4) };
int neighber = strtol(nbStr.c_str(), 0, 16); int neighber = strtol(nbStr.c_str(), 0, 16);
if (owner != 0) if(owner != 0) {
{
m_Cells[owner].push_back(faceIndex); m_Cells[owner].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(owner, m_Cells[owner].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(owner, m_Cells[owner].size());
} }
if (neighber != 0) if(neighber != 0) {
{
m_Cells[neighber].push_back(faceIndex); m_Cells[neighber].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(neighber, m_Cells[neighber].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(neighber, m_Cells[neighber].size());
} }
} } break;
break; case 4: {
case 4:
{
if(faceLineSegs.size() != 6) if(faceLineSegs.size() != 6)
return; return;
std::vector<int> pointIds{}; std::vector<int> pointIds{};
for (int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i) {
{
int id = strtol(faceLineSegs.at(i).c_str(), 0, 16); int id = strtol(faceLineSegs.at(i).c_str(), 0, 16);
pointIds.push_back(id); pointIds.push_back(id);
} }
@ -1170,29 +1059,28 @@ namespace MeshData
int owner = strtol(ownerStr.c_str(), 0, 16); int owner = strtol(ownerStr.c_str(), 0, 16);
std::string nbStr{ faceLineSegs.at(5) }; std::string nbStr{ faceLineSegs.at(5) };
int neighber = strtol(nbStr.c_str(), 0, 16); int neighber = strtol(nbStr.c_str(), 0, 16);
if (owner != 0) if(owner != 0) {
{
m_Cells[owner].push_back(faceIndex); m_Cells[owner].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(owner, m_Cells[owner].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(owner, m_Cells[owner].size());
} }
if (neighber != 0) if(neighber != 0) {
{
m_Cells[neighber].push_back(faceIndex); m_Cells[neighber].push_back(faceIndex);
m_FaceIdToCellFaceIndex[faceIndex] = std::make_pair(neighber, m_Cells[neighber].size()); m_FaceIdToCellFaceIndex[faceIndex] =
std::make_pair(neighber, m_Cells[neighber].size());
} }
} } break;
break;
default: default:
break; break;
} }
} }
void CFDMshFileParser::stringSplit(const std::string str, const char split, std::vector<std::string> &vec) void CFDMshFileParser::stringSplit(const std::string str, const char split,
std::vector<std::string>& vec)
{ {
std::istringstream iss(str); std::istringstream iss(str);
std::string token; std::string token;
while (getline(iss, token, split)) while(getline(iss, token, split)) {
{
if(token.size() != 0) if(token.size() != 0)
vec.push_back(token); vec.push_back(token);
} }
@ -1227,29 +1115,25 @@ namespace MeshData
const std::unordered_map<int, int> cellTyps = m_Parser->getCellsType(); const std::unordered_map<int, int> cellTyps = m_Parser->getCellsType();
std::set<int> usedFaces{}; std::set<int> usedFaces{};
int num = ps.size() / 3; int num = ps.size() / 3;
for (int i = 0; i < num; ++i) for(int i = 0; i < num; ++i) {
{
double coord[3]{ ps[i * 3], ps[i * 3 + 1], ps[i * 3 + 2] }; double coord[3]{ ps[i * 3], ps[i * 3 + 1], ps[i * 3 + 2] };
points->InsertNextPoint(coord); points->InsertNextPoint(coord);
} }
m_ugrid->SetPoints(points); m_ugrid->SetPoints(points);
std::unordered_map<int, std::vector<int>>::const_iterator it = cells.cbegin(); std::unordered_map<int, std::vector<int>>::const_iterator it = cells.cbegin();
while (it != cells.cend()) while(it != cells.cend()) {
{
std::vector<vtkIdType> pointIds{}; std::vector<vtkIdType> pointIds{};
vtkSmartPointer<vtkIdList> facesIDS = vtkSmartPointer<vtkIdList>::New(); vtkSmartPointer<vtkIdList> facesIDS = vtkSmartPointer<vtkIdList>::New();
std::vector<int> faceids = it->second; std::vector<int> faceids = it->second;
int index = it->first; int index = it->first;
for (int id : faceids) for(int id : faceids) {
{
auto it = faces.find(id); auto it = faces.find(id);
if(it == faces.cend()) if(it == faces.cend())
continue; continue;
const std::vector<int> pids = it->second; const std::vector<int> pids = it->second;
usedFaces.insert(it->first); usedFaces.insert(it->first);
facesIDS->InsertNextId(pids.size()); facesIDS->InsertNextId(pids.size());
for (int pid : pids) for(int pid : pids) {
{
pointIds.push_back(pid - 1); pointIds.push_back(pid - 1);
facesIDS->InsertNextId(pid - 1); facesIDS->InsertNextId(pid - 1);
} }
@ -1258,7 +1142,8 @@ namespace MeshData
std::sort(pointIds.begin(), pointIds.end()); std::sort(pointIds.begin(), pointIds.end());
auto ii = std::unique(pointIds.begin(), pointIds.end()); auto ii = std::unique(pointIds.begin(), pointIds.end());
pointIds.erase(ii, pointIds.end()); pointIds.erase(ii, pointIds.end());
m_ugrid->InsertNextCell(VTK_POLYHEDRON, pointIds.size(), pointIds.data(), faceids.size(), facesIDS->GetPointer(0)); m_ugrid->InsertNextCell(VTK_POLYHEDRON, pointIds.size(), pointIds.data(),
faceids.size(), facesIDS->GetPointer(0));
++it; ++it;
} }
return true; return true;
@ -1269,4 +1154,4 @@ namespace MeshData
return m_ugrid; return m_ugrid;
} }
} } // namespace MeshData

View File

@ -105,7 +105,8 @@ namespace SolverControl {
_processBar = new ModuleBase::ProcessBar(_mainWindow, _description, false); _processBar = new ModuleBase::ProcessBar(_mainWindow, _description, false);
QString args = _solver->getParameter(); QString args = _solver->getParameter();
QRegExp regExp("%.*%"); args.replace("%modelpath%", startPath, Qt::CaseInsensitive);
/*QRegExp regExp("%.*%");
regExp.setMinimal(true); regExp.setMinimal(true);
// int pos = regExp.indexIn(args); // int pos = regExp.indexIn(args);
QStringList variables = regExp.capturedTexts(); QStringList variables = regExp.capturedTexts();
@ -114,8 +115,7 @@ namespace SolverControl {
QString va = variable.remove("%"); QString va = variable.remove("%");
if(va.toLower() == "modelpath") if(va.toLower() == "modelpath")
args.replace(variables.at(i), startPath); args.replace(variables.at(i), startPath);
// qDebug() << args; }*/
}
// QString startProcess = solverPath + " " + args; // QString startProcess = solverPath + " " + args;
// if (solverPath.contains(" ")) // if (solverPath.contains(" "))