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

View File

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