diff --git a/.clang-format b/.clang-format
index 55de366..d4eb548 100644
--- a/.clang-format
+++ b/.clang-format
@@ -149,7 +149,7 @@ PointerAlignment: Left
# 允许重新排版注释
ReflowComments: true
# 允许排序#include
-SortIncludes: CaseInsensitive
+SortIncludes: Never
# 在C风格类型转换后添加空格
SpaceAfterCStyleCast: false
# 在赋值运算符之前添加空格
diff --git a/.gitignore b/.gitignore
index 3051875..77b0d53 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
.vscode
.vs
-.idea
/build
/install
/extlib
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b97bff6..d1cb933 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,6 +66,7 @@ option(FASTCAE_ENABLE_OPENMP "使用OpenMP" OFF)
option(FASTCAE_ENABLE_MPI "使用MPI" OFF)
option(FASTCAE_DOXYGEN_DOC "生成Doxygen文档" OFF)
option(FASTCAE_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON)
+option(FASTCAE_DEBUG_INFO "输出调试信息" ON)
#-----------------------------------------------------------------------------
# 指定编译选项
@@ -109,6 +110,13 @@ if(FASTCAE_ENABLE_MPI)
endif()
endif()
+#-----------------------------------------------------------------------------
+# 输出调试信息
+#-----------------------------------------------------------------------------
+if(FASTCAE_DEBUG_INFO)
+ add_definitions(-DOUTPUT_DEBUG_INFO)
+endif()
+
#-----------------------------------------------------------------------------
# 从系统查找Qt模块,开启Qt中间文件的自动生成
#-----------------------------------------------------------------------------
diff --git a/Changelog.md b/Changelog.md
index 09b2520..7a152f3 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -10,6 +10,7 @@ Version:2.5.x
- 加入OpenGL版本检测函数,当环境OPenGL版本低于3.3时,给出错误提示。
- 新增自动打包功能,Windows需要NSIS 3.03+、Linux需要dpkg-deb或者rpmbuild(需要python3)。
- 新增文档自动生成功能,需要安装Doxygen和Graphviz。
+- 增加vtu、pvtu格式的后处理文件支持
**功能优化**
- 代码全部采用cmake进行管理,可任意选择vscode、Visual Studio、Clion、Qtcreator等支持cmake系统的IDE。
@@ -17,6 +18,9 @@ Version:2.5.x
- 删除Qt浏览器组建及相关依赖(Qt安装不再需要QWebEngine组件)。
- 优化Python调用,不再依赖系统配置,简化操作。
- 从依赖库中移除未使用的VTK、OpenCASCADE模块。
+- 优化CGNS后处理文件解析,添加MIXED类型单元区域的解析。
+- 优化后处理属性面板场变量数据类型的显示方式。
+- 优化日志输出方式,便于错误定位
**功能修复**
- 修复linux环境卸载插件时崩溃的问题
diff --git a/README.md b/README.md
index fba8cf9..201d536 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,39 @@
- src: FastCAE源码
- test: 包含单元测试代码(待整理)
+## 构建编译
+
+### FastCAE相关的cmake构建选项说明
+- `FASTCAE_AUTO_DOWNLOAD`:如果源码目录不存在extlib目录时是否会自动从gitee克隆依赖包。
+- `FASTCAE_DOXYGEN_DOC`:是否需要构建目标Doxygen(需要本地安装Doxygen软件)
+- `FASTCAE_ENABLE_DEV`:是否在构建完成时自动拷贝依赖文件到调试目录。(开启该选项会在每次编译完拷贝第三方依赖库文件到构建目录,会增加构建时间)
+- `FASTCAE_ENABLE_MPI`:是否开启MPI支持(目前无效)。
+- `FASTCAE_ENABLE_OPENMP`:是否开启OpenMP。
+- `FASTCAE_ENABLE_TEST`:是否构建单元测试模块(目前无效)。
+- `FASTCAE_INSTALLATION_PACKAGE`:是否构建安装包制作PACKAGE。
+
+### cmake预定义目标说明:
+- ALL_BUILD:生成所有项目。
+- INSTALL:安装FastCAE到CMAKE_INSTALL_PREFIX定义的目录。
+- PACKAGE或者package: 在Visual Studio中该目标为大写,在其它构建系统中该目标为小写,用于将FastCAE打包成安装包(exe、deb、rpm)。
+- DOXYGEN: 生成FastCAE的Doxygen格式文档(html)。
+
+### 编译视频教程
+
+#### Windows
+
+- cmake 3.24.1 + Visual Studio Community 2017
+- QtCreator编译
+
+
+#### Linux
+
+- cmake + GNU GCC + make
+- 借助vscode构建、编译、安装、打包
+
+### 编译说明
+
+- windows环境下使用vscode时,编译工具链只能使用Visual Studio,目前不支持MinGW工具
### extlib目录结构
diff --git a/src/Common/DebugLogger.cpp b/src/Common/DebugLogger.cpp
new file mode 100644
index 0000000..636c8ed
--- /dev/null
+++ b/src/Common/DebugLogger.cpp
@@ -0,0 +1,111 @@
+#include "DebugLogger.h"
+
+#include
+#include
+#include
+
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
+#define filename(x) strrchr(x, '\\') ? strrchr(x, '\\') + 1 : x
+#else
+#define filename(x) strrchr(x, '/') ? strrchr(x, '/') + 1 : x
+#endif
+
+namespace Common {
+ void DebugLogger::info(const char* file, int line, const char* format, ...)
+ {
+ va_list args;
+ va_start(args, format);
+ output(file, line, format, 0, args);
+ va_end(args);
+ }
+
+ void DebugLogger::warning(const char* file, int line, const char* format, ...)
+ {
+ va_list args;
+ va_start(args, format);
+ output(file, line, format, 1, args);
+ va_end(args);
+ }
+
+ void DebugLogger::error(const char* file, int line, const char* format, ...)
+ {
+ va_list args;
+ va_start(args, format);
+ output(file, line, format, 2, args);
+ va_end(args);
+ }
+
+ char* DebugLogger::currentTime()
+ {
+ time_t rawtime;
+ struct tm* timeS;
+ char* buffer = new char[80];
+
+ time(&rawtime);
+
+ timeS = localtime(&rawtime);
+ sprintf(buffer, "%d-%s%d-%s%d %s%d:%s%d:%s%d", timeS->tm_year + 1900,
+ timeS->tm_mon < 10 ? "0" : "", timeS->tm_mon, timeS->tm_mday < 10 ? "0" : "",
+ timeS->tm_mday, timeS->tm_hour < 10 ? "0" : "", timeS->tm_hour,
+ timeS->tm_min < 10 ? "0" : "", timeS->tm_min, timeS->tm_sec < 10 ? "0" : "",
+ timeS->tm_sec);
+ return buffer;
+ }
+
+ /**
+ * 控制台显示控制格式:ESC[{attr1};{attr2};…;{attrn}m
+ * 显示方式:
+ * 0(默认值)
+ * 1(高亮显示,顺便加粗?不确定)
+ * 2(暗淡)
+ * 22(非粗体,不确定)
+ * 4(下划线)
+ * 5(闪烁,但是我没看出有什么效果。。)
+ * 25(非闪烁)
+ * 7(反显,我也没看出效果)
+ * 27(非反显)
+ * 8(隐藏)
+ *
+ * 字体颜色:
+ * 30(黑色)
+ * 31(红色)
+ * 32(绿色)
+ * 33(黄色)
+ * 34(蓝色)
+ * 35(品红)
+ * 36(青色)
+ * 37(白色)
+ * 背景色:
+ * 40(黑色)
+ * 41(红色)
+ * 42(绿色)
+ * 43(黄色)
+ * 44(蓝色)
+ * 45(品红)
+ * 46(青色)
+ * 47(白色)
+ */
+ void DebugLogger::output(const char* file, int line, const char* format, int level,
+ va_list args)
+ {
+ char type[15] = "";
+ switch(level) {
+ case 1:
+ printf("\033[33m"); // 红色
+ strcpy(type, "WARNING");
+ break;
+ case 2:
+ printf("\033[31m"); // 黄色
+ strcpy(type, "ERROR");
+ break;
+ default:
+ strcpy(type, "INFO");
+ break;
+ }
+
+ printf("[%s][%s:%d][%s]: ", currentTime(), filename(file), line, type);
+
+ vprintf(format, args);
+ printf("\033[0m");
+ }
+} // namespace Common
diff --git a/src/Common/DebugLogger.h b/src/Common/DebugLogger.h
new file mode 100644
index 0000000..65e117d
--- /dev/null
+++ b/src/Common/DebugLogger.h
@@ -0,0 +1,58 @@
+/**
+ * @file DebugLogger.h
+ * @brief 用于输出调试信息的类
+ * @author FastCAE研发小组(fastcae@diso.cn)
+ * @version 2.5.0
+ * @date 2023-05-11 16:12
+ * @copyright Copyright (c) Since 2020 青岛数智船海科技有限公司 All rights reserved.
+ *
+ * ============================================================================
+ * Program: FastCAE
+ *
+ * Copyright (c) Since 2020 青岛数智船海科技有限公司 All rights reserved.
+ * See License or http://www.fastcae.com/ for details.
+ *
+ * BSD 3-Clause License
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.
+ * ==================================================================================
+ */
+#ifndef DEBUGLOGGER_H
+#define DEBUGLOGGER_H
+
+#include "CommonAPI.h"
+
+#include
+
+namespace Common {
+ class COMMONAPI DebugLogger {
+ public:
+ DebugLogger() = delete;
+ ~DebugLogger() = delete;
+
+ public:
+ static void info(const char* file, int line, const char* format, ...);
+ static void warning(const char* file, int line, const char* format, ...);
+ static void error(const char* file, int line, const char* format, ...);
+
+ protected:
+ static char* currentTime();
+ static void output(const char* file, int line, const char* format, int level, va_list args);
+ };
+} // namespace Common
+
+// 用宏OUTPUT_DEBUG_INFO控制调试信息是否输出的开关
+#ifdef OUTPUT_DEBUG_INFO
+#define DebugInfo(FORMAT, ...) Common::DebugLogger::info(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
+#define DebugWarn(FORMAT, ...) Common::DebugLogger::warning(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
+#define DebugError(FORMAT, ...) Common::DebugLogger::error(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
+#else
+#define DebugInfo(FORMAT, ...)
+#define DebugWarn(FORMAT, ...)
+#define DebugError(FORMAT, ...)
+#endif // OUTPUT_DEBUG_INFO
+
+#endif
\ No newline at end of file
diff --git a/src/FastCAE/CMakeLists.txt b/src/FastCAE/CMakeLists.txt
index 87baca9..98549b9 100644
--- a/src/FastCAE/CMakeLists.txt
+++ b/src/FastCAE/CMakeLists.txt
@@ -31,7 +31,7 @@ set_property(DIRECTORY ${CMAKE_SOURCE_DIR}
VS_STARTUP_PROJECT FastCAE
)
-list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow)
+list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow)
if(_WIN_)
#list(APPEND _depend_library XGenerateReport License)
endif()
diff --git a/src/FastCAE/main.cpp b/src/FastCAE/main.cpp
index 3993f06..2c35328 100644
--- a/src/FastCAE/main.cpp
+++ b/src/FastCAE/main.cpp
@@ -20,19 +20,21 @@
* DISCLAIMED.
* ==================================================================================
*/
+#include "CommandLine.h"
+#include "FastCAEVersionMacros.h"
+#include "MainWindow/MainWindow.h"
+#include "XBeautyUI.h"
+
#include
#include
#include
-#include
-#include
#include
-#include "MainWindow/MainWindow.h"
-#include "XBeautyUI.h"
-#include "CommandLine.h"
-#include "FastCAEVersionMacros.h"
+#include
+#include
// #include "ConfigOptions/ConfigDataReader.h"
// #include "ConfigOptions/ConfigOptions.h"
// #include "ConfigOptions/GlobalConfig.h"
+#include "Common/DebugLogger.h"
#include "Settings/BusAPI.h"
#ifdef Q_OS_WIN
@@ -46,24 +48,25 @@
bool testOpenGL()
{
- bool supportOpenGLCore = false;
- QString currentOpenGLVersion = "";
+ bool supportOpenGLCore = false;
+ QString currentOpenGLVersion = "";
QOpenGLContext ctx;
- if (ctx.create())
- {
+ if(ctx.create()) {
auto version = ctx.format();
- if (version.majorVersion() > 3 || (version.majorVersion() == 3 && version.minorVersion() >= 3))
- {
+ if(version.majorVersion() > 3
+ || (version.majorVersion() == 3 && version.minorVersion() >= 3)) {
supportOpenGLCore = true;
- }
- else
- {
- currentOpenGLVersion = QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
+ } else {
+ currentOpenGLVersion =
+ QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
}
}
- if (!supportOpenGLCore)
- {
- QMessageBox::critical(nullptr, "OpenGL Error", "Startup failed: FastCAE requires OpenGL version greater than or equal to 3.3, but the current version is " + currentOpenGLVersion, QMessageBox::Ok);
+ if(!supportOpenGLCore) {
+ QMessageBox::critical(nullptr, "OpenGL Error",
+ "Startup failed: FastCAE requires OpenGL version greater than or "
+ "equal to 3.3, but the current version is "
+ + currentOpenGLVersion,
+ QMessageBox::Ok);
}
return supportOpenGLCore;
}
@@ -74,29 +77,28 @@ bool testOpenGL()
* @return int 返回函数运行结果
* @since 2.5.0
*/
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
// 添加Qt的对高分屏的支持
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
+#if(QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
CommandPara para(argc, argv);
- if (para.isHelp())
+ if(para.isHelp())
return 1;
QApplication app(argc, argv);
- if (!testOpenGL())
- {
+ if(!testOpenGL()) {
return 1;
}
// QString path = qApp->applicationDirPath();
- // ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/", ConfigOption::ConfigOption::getInstance());
- // reader.read();
- // QString qUseRibbon = ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon();
- // bool bUseRibbon = qUseRibbon == "yes" ? true : false;
+ // ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/",
+ // ConfigOption::ConfigOption::getInstance()); reader.read(); QString qUseRibbon =
+ // ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon(); bool
+ // bUseRibbon = qUseRibbon == "yes" ? true : false;
- bool isRibbon = Setting::BusAPI::instance()->isUseRibbon();
+ bool isRibbon = Setting::BusAPI::instance()->isUseRibbon();
GUI::MainWindow mainwindow(isRibbon);
@@ -106,9 +108,8 @@ int main(int argc, char *argv[])
QString qssFileName = XBeautyUI::instance()->qssFilePath();
//**************加载qss******************
- QFile qssFile(qssFileName);
- if (qssFile.exists())
- {
+ QFile qssFile(qssFileName);
+ if(qssFile.exists()) {
qssFile.open(QIODevice::ReadOnly);
QString style = qssFile.readAll();
qApp->setStyleSheet(style);
@@ -127,7 +128,7 @@ int main(int argc, char *argv[])
#endif
//*****************************************
- if (para.exec(&mainwindow))
+ if(para.exec(&mainwindow))
emit mainwindow.sendInfoToStatesBar(QString("Version: %1").arg(FASTCAE_VERSION));
else
return 1;
@@ -147,8 +148,7 @@ int main(int argc, char *argv[])
#endif
#endif
- if (e == -1000)
- {
+ if(e == -1000) {
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
return 0;
}
diff --git a/src/MainWindow/CMakeLists.txt b/src/MainWindow/CMakeLists.txt
index 60b4975..7efc13a 100644
--- a/src/MainWindow/CMakeLists.txt
+++ b/src/MainWindow/CMakeLists.txt
@@ -38,7 +38,7 @@ add_library(MainWindow
#-----------------------------------------------------------------------------
target_compile_definitions(MainWindow PRIVATE "MAINWINDOW_API")
-list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common)
+list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common)
if(_WIN_)
list(APPEND _depend_library XGenerateReport)
endif()
diff --git a/src/MainWindow/MainWindow.cpp b/src/MainWindow/MainWindow.cpp
index ea64cbc..80e3ae0 100644
--- a/src/MainWindow/MainWindow.cpp
+++ b/src/MainWindow/MainWindow.cpp
@@ -328,7 +328,7 @@ namespace GUI {
connect(this, SIGNAL(updatePreMeshActorSig()), this, SLOT(updatePreMeshActor()));
connect(this, SIGNAL(updatePreGeometryActorSig()), this, SLOT(updatePreGeometryActor()));
- connect(this, SIGNAL(openPlot()), _signalHandler, SLOT(openPlotFile()));
+ connect(this, SIGNAL(openPlot()), _signalHandler, SLOT(openPlotFile()));
}
void MainWindow::registerMoudel()
diff --git a/src/MainWindow/MainWindow.h b/src/MainWindow/MainWindow.h
index 66093f3..40bfc42 100644
--- a/src/MainWindow/MainWindow.h
+++ b/src/MainWindow/MainWindow.h
@@ -289,7 +289,7 @@ namespace GUI {
/**
* @brief 更新后处理模型树
*/
- void updatePostTreeSig();
+ void updatePostTreeSig();
//
// 更新二维曲线模型树
@@ -389,7 +389,7 @@ namespace GUI {
// 网格过滤
void on_FilterMesh();
// 创建VTK空间变换窗口
- void on_VTKTranslation();
+ void on_VTKTranslation();
private:
/*初始化Menu*/
diff --git a/src/MainWindow/SignalHandler.cpp b/src/MainWindow/SignalHandler.cpp
index 7b6c990..de76191 100644
--- a/src/MainWindow/SignalHandler.cpp
+++ b/src/MainWindow/SignalHandler.cpp
@@ -1248,7 +1248,7 @@ namespace GUI {
FileDirectoryDialog dlg;
QStringList filterTypes = { "VTK(*.vtk)", "CGNS(*.cgns)", "Plot3D(*.x)",
- "Tecplot(*.szplt)" };
+ "Tecplot(*.szplt)","VTU(*.vtu)","PVTU(*.pvtu)" };
dlg.iniFileFilterType(filterTypes);
if(dlg.exec() != QDialog::Accepted)
return;
diff --git a/src/MainWindow/Translator.cpp b/src/MainWindow/Translator.cpp
index 930e669..2f4cac2 100644
--- a/src/MainWindow/Translator.cpp
+++ b/src/MainWindow/Translator.cpp
@@ -5,7 +5,7 @@
#include
#include
#include
-
+#include "Common/DebugLogger.h"
namespace GUI {
const static QStringList Lang_List = {
":/translations/MainWindow_zh_CN", ":/translations/MainWidgets_zh_CN",
@@ -34,8 +34,11 @@ namespace GUI {
_app->removeTranslator(tranlator);
const QString lang = Lang_List.at(i);
bool ok = tranlator->load(lang);
- qDebug() << lang;
- assert(ok);
+ if(ok) {
+ DebugInfo("Success to load lang file: %s\n", lang.toStdString().c_str());
+ } else {
+ DebugError("Failed to load lang file: %s\n", lang.toStdString().c_str());
+ }
_app->installTranslator(tranlator);
}
}
diff --git a/src/PostAlgorithm/CGNSReaderAlgorithm.cpp b/src/PostAlgorithm/CGNSReaderAlgorithm.cpp
index 731a1a7..6006dff 100644
--- a/src/PostAlgorithm/CGNSReaderAlgorithm.cpp
+++ b/src/PostAlgorithm/CGNSReaderAlgorithm.cpp
@@ -1,359 +1,375 @@
#include "CGNSReaderAlgorithm.h"
-//#include
-#include
+// #include
#include
#include
-//#include
-#include
-#include
-#include
+#include
+// #include
#include
#include
+#include
+#include
#include
#include
#include
-#include
+#include
#include
-//#include
-#include
+#include
+// #include
#include "FCGNSReader.h"
-#include
+
#include
#include
#include
+#include
+#include
-#define MAXBLOCKNUM 2000
+#define MAXBLOCKNUM 2000
CGNSReaderAlgorithm::CGNSReaderAlgorithm()
{
- this->FileName = NULL;
- this->SetNumberOfInputPorts(0);
- this->SetNumberOfOutputPorts(MAXBLOCKNUM+1);
+ this->FileName = NULL;
+ // 设置输入端口的数量
+ this->SetNumberOfInputPorts(0);
+ // 设置输出端口的数量
+ this->SetNumberOfOutputPorts(MAXBLOCKNUM + 1);
- for (int i = 0 ;iFileName = NULL;
+ this->FileName = NULL;
}
-int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
+/**
+ * 许多过滤器可以在不直接提供ProcessRequest()方法的情况下实现。
+ * 标准过滤器超类提供了ProcessRequest()的默认实现,该实现通过将最常见的请求转换为对特定于请求的方法的调用来实现。
+ */
+int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
+ vtkInformationVector* outputVector)
{
- if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
- {
- return this->RequestInformation(request, inputVector,
- outputVector);
- }
- if (request->Has(
- vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
- {
- return this->RequestUpdateExtent(request, inputVector,
- outputVector);
- }
- if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
- {
- return this->RequestData(request, inputVector, outputVector);
- }
- return this->Superclass::ProcessRequest(request, inputVector,
- outputVector);
+ // vtkDemandDrivenPipeline::REQUEST_INFORMATION()定义请求以确保输出信息是最新的
+ if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
+ return this->RequestInformation(request, inputVector, outputVector);
+ }
+ // vtkDemandDrivenPipeline::REQUEST_DATA()定义了向上游传播更新范围的请求。
+ if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
+ return this->RequestUpdateExtent(request, inputVector, outputVector);
+ }
+ // vtkDemandDrivenPipeline::REQUEST_DATA()定义请求以确保输出数据是最新的
+ if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
+ return this->RequestData(request, inputVector, outputVector);
+ }
+ return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
-
-
-int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
+/**
+ * @brief
+ * @param[in]
+ * @param[in] vtkInformationVector**包含输入管道信息。数组的每个元素代表一个输入端口。
+ * 是一个vtkInformationVector,对应输入端口上连接的输入管道信息对象。
+ * @param[in]
+ * outputVector是一个vtkInformationVector,包含滤器的每个输出端口提供一个输出管道信息对象。
+ * @note
+ * 用于输入和输出的每个管道信息对象都包含一个vtkDataObject,其存储键为vtkDataObobject::DATA_OBJECT()。
+ * @since 2.5.0
+ */
+int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**,
+ vtkInformationVector* outputVector)
{
- if (!this->FileName)
- {
- vtkErrorMacro("A FileName must be specified.");
- return 0;
- }
+ if(!this->FileName) {
+ vtkErrorMacro("A FileName must be specified.");
+ return 0;
+ }
+ _blockList.clear();
+ _blockNames.clear();
- _blockList.clear();
- _blockNames.clear();
+ vtkMultiBlockDataSet* mBlock = nullptr;
+ // bool useVTK = useVTKCGNSReader();
- vtkMultiBlockDataSet* mBlock = nullptr;
- //bool useVTK = useVTKCGNSReader();
+ vtkSmartPointer reader = vtkSmartPointer::New();
+ reader->SetFileName(FileName);
+ reader->Update();
+ mBlock = reader->GetOutput();
+ // vtkSmartPointer vtkReader = vtkSmartPointer::New();
+ // if (useVTK)
+ // {
+ // vtkReader->SetFileName(FileName);
+ // vtkReader->Update();
+ // mBlock = vtkReader->GetOutput();
+ // }
+ // else
+ // {
+ // reader->SetFileName(FileName);
+ // reader->Update();
+ // mBlock = reader->GetOutput();
+ // }
+ vtkSmartPointer appFilter = vtkSmartPointer::New();
+ appFilter->MergePointsOn();
- vtkSmartPointer reader = vtkSmartPointer::New();
- reader->SetFileName(FileName);
- reader->Update();
- mBlock = reader->GetOutput();
- // vtkSmartPointer vtkReader = vtkSmartPointer::New();
- // if (useVTK)
- // {
- // vtkReader->SetFileName(FileName);
- // vtkReader->Update();
- // mBlock = vtkReader->GetOutput();
- // }
- // else
- // {
- // reader->SetFileName(FileName);
- // reader->Update();
- // mBlock = reader->GetOutput();
- // }
- vtkSmartPointer appFilter = vtkSmartPointer::New();
- appFilter->MergePointsOn();
+ if(mBlock == nullptr)
+ return 0;
+ getBlocks(mBlock);
- if (mBlock == nullptr) return 0;
- getBlocks(mBlock);
+ for(int i = 0; i < _blockList.size(); ++i) {
+ if(!_visibleStates[i])
+ continue;
+ auto dataset = _blockList.at(i);
- for (int i =0;i< _blockList.size(); ++i)
- {
- if(!_visibleStates[i]) continue;
- auto dataset = _blockList.at(i);
+ fillPointArray(dataset);
+ fillCellArray(dataset);
+ appFilter->AddInputData(dataset);
+ }
- fillPointArray(dataset);
- fillCellArray(dataset);
- appFilter->AddInputData(dataset);
- }
+ appFilter->Update();
+ vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
+ output->CopyStructure(appFilter->GetOutput());
+ output->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
+ output->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
- appFilter->Update();
-
- vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
- output->CopyStructure(appFilter->GetOutput());
- output->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
- output->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
-
- for (int i =1;i<=_blockList.size();i++)
- {
- if (i > MAXBLOCKNUM) break;
- auto data = _blockList.at(i-1);
- vtkUnstructuredGrid* outData = vtkUnstructuredGrid::GetData(outputVector,i);
- vtkSmartPointer appFilter = vtkSmartPointer::New();
- appFilter->AddInputData(data);
- appFilter->Update();
- outData->CopyStructure(appFilter->GetOutput());
- outData->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
- outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());;
- }
- return 1;
+ for(int i = 1; i <= _blockList.size(); i++) {
+ if(i > MAXBLOCKNUM)
+ break;
+ auto data = _blockList.at(i - 1);
+ vtkUnstructuredGrid* outData = vtkUnstructuredGrid::GetData(outputVector, i);
+ vtkSmartPointer appFilter = vtkSmartPointer::New();
+ appFilter->AddInputData(data);
+ appFilter->Update();
+ outData->CopyStructure(appFilter->GetOutput());
+ outData->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
+ outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
+ ;
+ }
+ return 1;
}
bool CGNSReaderAlgorithm::useVTKCGNSReader()
{
- int currentFileIndex = 0;
- int OK = cg_open(FileName, CG_MODE_READ, ¤tFileIndex);
- if (CG_OK != OK) return false;
- bool useVTK = false;
- int nBase = 0;
- OK = cg_nbases(currentFileIndex, &nBase);
+ int currentFileIndex = 0;
+ int OK = cg_open(FileName, CG_MODE_READ, ¤tFileIndex);
+ if(CG_OK != OK)
+ return false;
+ bool useVTK = false;
+ int nBase = 0;
+ OK = cg_nbases(currentFileIndex, &nBase);
- for (int ibase = 1; ibase <= nBase; ++ibase)
- {
- int zone_node_number = 0;
- cg_nzones(currentFileIndex, ibase, &zone_node_number);
-
- for (int izone = 1; izone <= zone_node_number; ++izone)
- {
- CGNS_ENUMT(ZoneType_t) zonetype;
- cg_zone_type(currentFileIndex, ibase, izone, &zonetype);
- if (zonetype == CGNS_ENUMV(Unstructured))
- {
- int nSection{ 0 };
- cg_nsections(currentFileIndex, ibase, izone, &nSection);
- for (int iSec = 1;iSec <= nSection; ++iSec)
- {
- char sectionName[33] = { 0 };
- cgsize_t istart = 0, iend = 0;
- int nbndry = 0, iparent_flag = 0;
- CGNS_ENUMT(ElementType_t) itype;
- OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype
- , &istart, &iend, &nbndry, &iparent_flag);
- if (itype >= 20)
- {
- cg_close(currentFileIndex);
- return true;
- }
+ for(int ibase = 1; ibase <= nBase; ++ibase) {
+ int zone_node_number = 0;
+ cg_nzones(currentFileIndex, ibase, &zone_node_number);
- }
-
- }
- }
- }
- cg_close(currentFileIndex);
- return useVTK;
+ for(int izone = 1; izone <= zone_node_number; ++izone) {
+ CGNS_ENUMT(ZoneType_t) zonetype;
+ cg_zone_type(currentFileIndex, ibase, izone, &zonetype);
+ if(zonetype == CGNS_ENUMV(Unstructured)) {
+ int nSection{ 0 };
+ cg_nsections(currentFileIndex, ibase, izone, &nSection);
+ for(int iSec = 1; iSec <= nSection; ++iSec) {
+ char sectionName[33] = { 0 };
+ cgsize_t istart = 0, iend = 0;
+ int nbndry = 0, iparent_flag = 0;
+ CGNS_ENUMT(ElementType_t) itype;
+ OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype,
+ &istart, &iend, &nbndry, &iparent_flag);
+ if(itype >= 20) {
+ cg_close(currentFileIndex);
+ return true;
+ }
+ }
+ }
+ }
+ }
+ cg_close(currentFileIndex);
+ return useVTK;
}
CGNSReaderAlgorithm* CGNSReaderAlgorithm::New()
{
- auto reader = new CGNSReaderAlgorithm;
- reader->InitializeObjectBase();
- return reader;
+ auto reader = new CGNSReaderAlgorithm;
+ reader->InitializeObjectBase();
+ return reader;
}
-
void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
- this->Superclass::PrintSelf(os, indent);
- os << indent << "FileName:" << (this->FileName ? this->FileName : "(none)") << "\n";
+ this->Superclass::PrintSelf(os, indent);
+ os << indent << "FileName:" << (this->FileName ? this->FileName : "(none)") << "\n";
}
void CGNSReaderAlgorithm::setVisible(int blockIndex, bool vis)
{
- if (blockIndex >= MAXBLOCKNUM) return;
- _visibleStates[blockIndex] = vis;
- // this->Modified();
+ if(blockIndex >= MAXBLOCKNUM)
+ return;
+ _visibleStates[blockIndex] = vis;
+ // this->Modified();
}
int CGNSReaderAlgorithm::getNumberOfBlocks()
{
- return _blockList.size();
+ return _blockList.size();
}
QStringList CGNSReaderAlgorithm::getBlockNames()
{
- return _blockNames;
+ return _blockNames;
}
QStringList CGNSReaderAlgorithm::getBlockBCTypes()
{
- return _bcTypes;
+ return _bcTypes;
}
-int CGNSReaderAlgorithm::FillOutputPortInformation(int port, vtkInformation* info)
+int CGNSReaderAlgorithm::FillInputPortInformation(int, vtkInformation*)
{
- Q_UNUSED(port)
- info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
- return 1;
+ // 该算法没有输入端口
+ // info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
+ // info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
+ // info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
+ return 1;
}
-void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
+int CGNSReaderAlgorithm::FillOutputPortInformation(int, vtkInformation* info)
{
- auto block = vtkMultiBlockDataSet::SafeDownCast(blockData);
+ info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
+ return 1;
+}
- if (block == nullptr)
- {
- auto dataset = vtkDataSet::SafeDownCast(blockData);
- if (dataset == nullptr) return;
- dataset->Modified();
- QString totalName = QString::fromLocal8Bit(Name);
- QStringList NameBC = totalName.split("!|||!");
-
- if (NameBC.size() == 2)
- {
- _blockNames.append(NameBC.at(0));
- _bcTypes.append(NameBC.at(1));
- }
- else
- {
- _blockNames.append(totalName);
- _bcTypes.append("None");
- }
-
- _blockList.append(dataset);
- getPointArray(dataset);
- getCellArray(dataset);
- return;
- }
+void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData, const char* Name)
+{
+ auto block = vtkMultiBlockDataSet::SafeDownCast(blockData);
- block->Modified();
- const int nBlock = block->GetNumberOfBlocks();
+ if(block == nullptr) {
+ auto dataset = vtkDataSet::SafeDownCast(blockData);
+ if(dataset == nullptr)
+ return;
+ dataset->Modified();
+ QString totalName = QString::fromLocal8Bit(Name);
+ QStringList NameBC = totalName.split("!|||!");
- for (int i = 0; i < nBlock; i++)
- {
- vtkDataObject* obj = block->GetBlock(i);
- const char* currentName = block->GetMetaData(i)->Get(vtkCompositeDataSet::NAME());
- getBlocks(obj,currentName);
- }
+ if(NameBC.size() == 2) {
+ _blockNames.append(NameBC.at(0));
+ _bcTypes.append(NameBC.at(1));
+ } else {
+ _blockNames.append(totalName);
+ _bcTypes.append("None");
+ }
+
+ _blockList.append(dataset);
+ getPointArray(dataset);
+ getCellArray(dataset);
+ return;
+ }
+
+ block->Modified();
+ const int nBlock = block->GetNumberOfBlocks();
+
+ for(int i = 0; i < nBlock; i++) {
+ vtkDataObject* obj = block->GetBlock(i);
+ const char* currentName = block->GetMetaData(i)->Get(vtkCompositeDataSet::NAME());
+ getBlocks(obj, currentName);
+ }
}
void CGNSReaderAlgorithm::getPointArray(vtkDataSet* dataset)
{
- if (dataset == nullptr) return;
+ if(dataset == nullptr)
+ return;
- auto pointData = dataset->GetPointData();
- if (pointData == nullptr) return;
+ auto pointData = dataset->GetPointData();
+ if(pointData == nullptr)
+ return;
- const int nPointArray = pointData->GetNumberOfArrays();
- for (int i = 0; i < nPointArray; i++)
- {
- const char* aName = pointData->GetArrayName(i);
- auto dataArray = pointData->GetArray(aName);
- if (dataArray == nullptr) return; //continue;
- int aNum[2]{ 0 };
- aNum[0] = dataArray->GetNumberOfComponents();
- aNum[1] = dataArray->GetNumberOfTuples();
+ const int nPointArray = pointData->GetNumberOfArrays();
+ for(int i = 0; i < nPointArray; i++) {
+ const char* aName = pointData->GetArrayName(i);
+ auto dataArray = pointData->GetArray(aName);
+ if(dataArray == nullptr)
+ return; // continue;
+ int aNum[2]{ 0 };
+ aNum[0] = dataArray->GetNumberOfComponents();
+ aNum[1] = dataArray->GetNumberOfTuples();
- if (_pointDataArray.contains(aName)) continue;
- _pointDataArray.insert(aName, aNum);
- }
+ if(_pointDataArray.contains(aName))
+ continue;
+ _pointDataArray.insert(aName, aNum);
+ }
}
void CGNSReaderAlgorithm::getCellArray(vtkDataSet* dataset)
{
- if (dataset == nullptr) return;
+ if(dataset == nullptr)
+ return;
- auto cellData = dataset->GetCellData();
- if (cellData == nullptr) return;
+ auto cellData = dataset->GetCellData();
+ if(cellData == nullptr)
+ return;
- const int nCellArray = cellData->GetNumberOfArrays();
- for (int i = 0; i < nCellArray; i++)
- {
- const char* aName = cellData->GetArrayName(i);
- auto dataArray = cellData->GetArray(aName);
- if (dataArray == nullptr) return; //continue;
- int aNum[2]{ 0 };
- aNum[0] = dataArray->GetNumberOfComponents();
- aNum[1] = dataArray->GetNumberOfTuples();
+ const int nCellArray = cellData->GetNumberOfArrays();
+ for(int i = 0; i < nCellArray; i++) {
+ const char* aName = cellData->GetArrayName(i);
+ auto dataArray = cellData->GetArray(aName);
+ if(dataArray == nullptr)
+ return; // continue;
+ int aNum[2]{ 0 };
+ aNum[0] = dataArray->GetNumberOfComponents();
+ aNum[1] = dataArray->GetNumberOfTuples();
- if (_cellDataArray.contains(aName)) continue;
- _cellDataArray.insert(aName, aNum);
- }
+ if(_cellDataArray.contains(aName))
+ continue;
+ _cellDataArray.insert(aName, aNum);
+ }
}
void CGNSReaderAlgorithm::fillPointArray(vtkDataSet* dataset)
-{
- Q_UNUSED(dataset)
- // if (dataset == nullptr) return; //continue;
- //
- // vtkPointData* pointData = dataset->GetPointData();
- // if (pointData == nullptr) return;
- //
- // QList pArrayNames = _pointDataArray.uniqueKeys();
- // for (auto name : pArrayNames)
- // {
- // QString2Char(name, cName)
- // vtkDataArray* array = pointData->GetArray(cName);
- // if (array != nullptr)continue;
- //
- // int* aNum = _pointDataArray.value(name);
- // vtkSmartPointer dataArray = vtkSmartPointer::New();
- // dataArray->SetName(cName);
- // dataArray->SetNumberOfComponents(aNum[0]);
- // dataArray->SetNumberOfTuples(aNum[1]);
- // dataArray->Fill(0);
- //
- // pointData->AddArray(dataArray);
- // }
-
+{
+ Q_UNUSED(dataset)
+ // if (dataset == nullptr) return; //continue;
+ //
+ // vtkPointData* pointData = dataset->GetPointData();
+ // if (pointData == nullptr) return;
+ //
+ // QList pArrayNames = _pointDataArray.uniqueKeys();
+ // for (auto name : pArrayNames)
+ // {
+ // QString2Char(name, cName)
+ // vtkDataArray* array = pointData->GetArray(cName);
+ // if (array != nullptr)continue;
+ //
+ // int* aNum = _pointDataArray.value(name);
+ // vtkSmartPointer dataArray = vtkSmartPointer::New();
+ // dataArray->SetName(cName);
+ // dataArray->SetNumberOfComponents(aNum[0]);
+ // dataArray->SetNumberOfTuples(aNum[1]);
+ // dataArray->Fill(0);
+ //
+ // pointData->AddArray(dataArray);
+ // }
}
void CGNSReaderAlgorithm::fillCellArray(vtkDataSet* dataset)
{
- Q_UNUSED(dataset)
- // if (dataset == nullptr) return; //continue;
- //
- // vtkCellData* cellData = dataset->GetCellData();
- // if (cellData == nullptr) return;
- //
- // QList cArrayNames = _cellDataArray.uniqueKeys();
- // for (auto name : cArrayNames)
- // {
- // QString2Char(name, cName)
- // vtkDataArray* array = cellData->GetArray(cName);
- // if (array != nullptr)continue;
- //
- // int* aNum = _pointDataArray.value(name);
- // vtkSmartPointer dataArray = vtkSmartPointer::New();
- // dataArray->SetName(cName);
- // dataArray->SetNumberOfComponents(aNum[0]);
- // dataArray->SetNumberOfTuples(aNum[1]);
- // dataArray->Fill(0);
- //
- // cellData->AddArray(dataArray);
- // }
+ Q_UNUSED(dataset)
+ // if (dataset == nullptr) return; //continue;
+ //
+ // vtkCellData* cellData = dataset->GetCellData();
+ // if (cellData == nullptr) return;
+ //
+ // QList cArrayNames = _cellDataArray.uniqueKeys();
+ // for (auto name : cArrayNames)
+ // {
+ // QString2Char(name, cName)
+ // vtkDataArray* array = cellData->GetArray(cName);
+ // if (array != nullptr)continue;
+ //
+ // int* aNum = _pointDataArray.value(name);
+ // vtkSmartPointer dataArray = vtkSmartPointer::New();
+ // dataArray->SetName(cName);
+ // dataArray->SetNumberOfComponents(aNum[0]);
+ // dataArray->SetNumberOfTuples(aNum[1]);
+ // dataArray->Fill(0);
+ //
+ // cellData->AddArray(dataArray);
+ // }
}
diff --git a/src/PostAlgorithm/CGNSReaderAlgorithm.h b/src/PostAlgorithm/CGNSReaderAlgorithm.h
index c419653..fbedc5e 100644
--- a/src/PostAlgorithm/CGNSReaderAlgorithm.h
+++ b/src/PostAlgorithm/CGNSReaderAlgorithm.h
@@ -3,100 +3,133 @@
#include "PostAlgorithmAPI.h"
#include "PostRenderData/Macros.hxx"
-#include
-#include
+
#include
+#include
+#include
-ForwardDeclar(vtkInformation)
-ForwardDeclar(vtkDataSet)
-ForwardDeclar(vtkDataObject)
-ForwardDeclar(vtkDataArray)
+ForwardDeclar(vtkInformation);
+ForwardDeclar(vtkDataSet);
+ForwardDeclar(vtkDataObject);
+ForwardDeclar(vtkDataArray);
-class POSTALGORITHMAPI CGNSReaderAlgorithm :public vtkUnstructuredGridAlgorithm
-{
+class POSTALGORITHMAPI CGNSReaderAlgorithm : public vtkUnstructuredGridAlgorithm {
public:
static CGNSReaderAlgorithm* New();
vtkTypeMacro(CGNSReaderAlgorithm, vtkUnstructuredGridAlgorithm);
- void PrintSelf(ostream& os, vtkIndent indent);
-
+ /**
+ * @brief 打印对象当前对象(包括超类)的信息
+ *
+ * @param[in] os 输出流
+ * @param[in] indent 缩进
+ */
+ void PrintSelf(ostream& os, vtkIndent indent) override;
+ /** @name Set/Get宏
+ * 相当于setter/getter,同vtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
+ * @{
+ */
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
+ /** @} */
- void setVisible(int blockIndex, bool vis);
+ void setVisible(int blockIndex, bool vis);
- int getNumberOfBlocks();
+ int getNumberOfBlocks();
- QStringList getBlockNames();
+ QStringList getBlockNames();
- QStringList getBlockBCTypes();
-
- int FillOutputPortInformation(int port, vtkInformation* info);
+ QStringList getBlockBCTypes();
/**
- * @brief 获取块数据
- * @param block 数据
- */
- void getBlocks(vtkDataObject* block, const char* cuttentName ="");
+ * @brief 填充该算法的输入端口信息对象
+ * @param[in] port 端口序号,从0开始
+ */
+ int FillInputPortInformation(int port, vtkInformation* info) override;
/**
- * @brief 获取dataset中所有point属性
- * @param dataset
- */
- void getPointArray(vtkDataSet* dataset);
+ * @brief 填充该算法的输入端口信息对象
+ * @param[in] port 端口序号,从0开始
+ */
+ int FillOutputPortInformation(int port, vtkInformation* info) override;
+
/**
- * @brief 获取dataset中所有cell属性
- * @param dataset
- */
- void getCellArray(vtkDataSet* dataset);
+ * @brief 获取块数据
+ * @param block 数据
+ */
+ void getBlocks(vtkDataObject* block, const char* cuttentName = "");
/**
- * @brief 填充point的属性
- * @param dataset
- */
- void fillPointArray(vtkDataSet* dataset);
+ * @brief 获取dataset中所有point属性
+ * @param dataset
+ */
+ void getPointArray(vtkDataSet* dataset);
/**
- * @brief 填充cell的属性
- * @param dataset
- */
- void fillCellArray(vtkDataSet* dataset);
+ * @brief 获取dataset中所有cell属性
+ * @param dataset
+ */
+ void getCellArray(vtkDataSet* dataset);
+ /**
+ * @brief 填充point的属性
+ * @param dataset
+ */
+ void fillPointArray(vtkDataSet* dataset);
+ /**
+ * @brief 填充cell的属性
+ * @param dataset
+ */
+ void fillCellArray(vtkDataSet* dataset);
protected:
CGNSReaderAlgorithm();
~CGNSReaderAlgorithm();
-
- int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
- int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
- bool useVTKCGNSReader();
+ /**
+ * @brief 当VTK管道更新时,过滤器可能会收到请求,要求它处理一些信息和/或数据。
+ * 这些请求首先被发送到过滤器的执行对象,然后由该对象发送请求
+ * 通过调用虚拟方法vtkAlgorithm::ProcessRequest()来实现算法。
+ * 该方法给出了请求信息对象和一组输入输出管道信息要操作的对象。它负责尝试完成请求并报告成功或失败。
+ * 每个算法对象必须按原样提供ProcessRequest()的实现算法执行的入口点.
+ *
+ * \param request
+ * \param inputVector
+ * \param outputVector
+ * \return
+ */
+ int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
+ vtkInformationVector* outputVector) override;
+
+ int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
+
+ bool useVTKCGNSReader();
protected:
char* FileName;
private:
CGNSReaderAlgorithm(const CGNSReaderAlgorithm&);
- void operator=(const CGNSReaderAlgorithm&);
+ void operator=(const CGNSReaderAlgorithm&);
/**
- * @brief 块数据列表
- * @since Version: 1.0.0
- */
- QList _blockList{};
+ * @brief 块数据列表
+ * @since Version: 1.0.0
+ */
+ QList _blockList{};
/**
- * @brief 所有point属性数据
- * @note 缺少tuple
- * @since Version: 1.0.0
- */
+ * @brief 所有point属性数据
+ * @note 缺少tuple
+ * @since Version: 1.0.0
+ */
QHash _pointDataArray{};
/**
- * @brief 所有cell属性数据
- * @note 缺少tuple
- * @since Version: 1.0.0
- */
+ * @brief 所有cell属性数据
+ * @note 缺少tuple
+ * @since Version: 1.0.0
+ */
QHash _cellDataArray{};
- QList _visibleStates{};
+ QList _visibleStates{};
- QStringList _blockNames{};
+ QStringList _blockNames{};
- QStringList _bcTypes;
+ QStringList _bcTypes;
};
#endif
diff --git a/src/PostAlgorithm/CMakeLists.txt b/src/PostAlgorithm/CMakeLists.txt
index 3403352..001fe4c 100644
--- a/src/PostAlgorithm/CMakeLists.txt
+++ b/src/PostAlgorithm/CMakeLists.txt
@@ -28,6 +28,8 @@ add_library(PostAlgorithm
target_compile_definitions(PostAlgorithm PRIVATE "POSTALGORITHM_API")
#target_compile_definitions(PostAlgorithm PRIVATE "H5_BUILT_AS_DYNAMIC_LIB")
+list(APPEND _depend_library Common)
+
list(APPEND _runtimes_libraries
FASTCAE::CGNS FASTCAE::HDF5 FASTCAE::HDF5CPP FASTCAE::TECIO Qt5::Core VTK::CommonColor VTK::CommonComputationalGeometry VTK::CommonCore VTK::CommonDataModel VTK::CommonExecutionModel VTK::CommonMath VTK::CommonMisc VTK::CommonSystem VTK::CommonTransforms VTK::DICOMParser VTK::FiltersCore VTK::FiltersExtraction VTK::FiltersGeneral VTK::FiltersGeometry VTK::FiltersHybrid VTK::FiltersModeling VTK::FiltersParallel VTK::FiltersSources VTK::FiltersStatistics VTK::FiltersTexture VTK::IOCore VTK::IOGeometry VTK::IOImage VTK::IOLegacy VTK::IOParallel VTK::IOXML VTK::IOXMLParser VTK::ImagingCore VTK::ImagingFourier VTK::ImagingSources VTK::ParallelCore VTK::ParallelDIY VTK::RenderingCore VTK::doubleconversion VTK::expat VTK::jpeg VTK::jsoncpp VTK::lz4 VTK::lzma VTK::metaio VTK::png VTK::pugixml VTK::sys VTK::tiff VTK::zlib
)
@@ -37,8 +39,14 @@ list(APPEND _runtimes_libraries
#-----------------------------------------------------------------------------
target_link_libraries(PostAlgorithm PRIVATE
${_runtimes_libraries}
+ ${_depend_library}
)
+#-----------------------------------------------------------------------------
+# 添加依赖关系
+#-----------------------------------------------------------------------------
+add_dependencies(PostAlgorithm ${_depend_library})
+
#-----------------------------------------------------------------------------
# 添加运行时依赖关系
#-----------------------------------------------------------------------------
diff --git a/src/PostAlgorithm/FCGNSGridReaderBase.cpp b/src/PostAlgorithm/FCGNSGridReaderBase.cpp
index a75572e..f9acb5c 100644
--- a/src/PostAlgorithm/FCGNSGridReaderBase.cpp
+++ b/src/PostAlgorithm/FCGNSGridReaderBase.cpp
@@ -1,17 +1,19 @@
#include "FCGNSGridReaderBase.h"
-#include
+
+#include "Common/DebugLogger.h"
+
#include
#include
-#include
-#include
-#include
+#include
#include
+#include
#include
#include
-#include
#include
+#include
+#include
-FCGNSGridReaderBase::FCGNSGridReaderBase(vtkMultiBlockDataSet *root)
+FCGNSGridReaderBase::FCGNSGridReaderBase(vtkMultiBlockDataSet* root)
: _root(root)
{
}
@@ -23,299 +25,308 @@ void FCGNSGridReaderBase::setInfo(int fileIndex, int baseIndex, int zoneIndex)
_zoneIndex = zoneIndex;
}
-void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3], cgsize_t rangeMax[3])
+void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3],
+ cgsize_t rangeMax[3])
{
_vertexList.clear();
_vertexList.fill(VPoint(), count);
- char coordinate_name[33] = {0};
- CGNS_ENUMV(DataType_t)
- datatype;
- int OK = 0;
- for (int i = 1; i <= dim; ++i)
- {
- OK = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name);
- if (CG_OK != OK)
- continue;
- void *xyz{nullptr};
- if (datatype == CGNS_ENUMV(RealSingle))
+ // 坐标名称(CoordinateX,CoordinateY,CoordinateZ,CoordinateR,CoordinateTheta,CoordinatePhi等)
+ // 参考http://cgns.github.io/CGNS_docs_current/sids/dataname.html#dataname_grid
+ char coordinate_name[33] = { 0 };
+ // 坐标值的数据类型(RealSingle 或者 RealDouble)
+ CGNS_ENUMV(DataType_t) datatype;
+ int result = 0;
+ for(int i = 1; i <= dim; ++i) {
+ // 读取坐标信息,构建数据存储数组
+ result = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name);
+ if(CG_OK != result) {
+ DebugError("Failed to get coordinate(index = %d) info\n", i);
+ break;
+ }
+ void* xyz{ nullptr };
+ if(datatype == CGNS_ENUMV(RealSingle)) {
xyz = new float[count];
- else if (datatype == CGNS_ENUMV(RealDouble))
+ } else if(datatype == CGNS_ENUMV(RealDouble)) {
xyz = new double[count];
- if (xyz == nullptr)
- continue;
+ } else {
+ DebugError("Invalid data type for coordinate: %s\n", coordinate_name);
+ break;
+ }
- OK = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype, rangeMin, rangeMax, xyz);
- if (OK != 0)
- continue;
+ // 读取坐标数据
+ // 官方文档(datatype不需要区分RealSingle或者RealDouble,可以自动处理,但是由于数据量一般比较大,考虑
+ // 节约内存,也可以做区分):The function cg_coord_read returns the coordinate array
+ // coord_array, for the range prescribed by range_min and range_max. The array is returned
+ // to the application in the data type requested in mem_datatype. This data type does not
+ // need to be the same as the one in which the coordinates are stored in the file. A
+ // coordinate array stored as double precision in the CGNS file can be returned to the
+ // application as single precision, or vice versa. The functions cg_coord_general_read and
+ // cg_coord_general_write allow for type conversion when both reading from and writing to
+ // the file.
+ result = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype,
+ rangeMin, rangeMax, xyz);
+ if(CG_OK != result) {
+ DebugError("Failed to read grid coordinate: %s\n", coordinate_name);
+ break;
+ }
- if (!strcmp(coordinate_name, "CoordinateX"))
- {
- if (datatype == CGNS_ENUMV(RealDouble))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
+ if(strcmp(coordinate_name, "CoordinateX") == 0) {
+ if(datatype == CGNS_ENUMV(RealDouble)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
+ _vertexList[ipt].x = c[ipt];
+ } else if(datatype == CGNS_ENUMV(RealSingle)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].x = c[ipt];
}
- else if (datatype == CGNS_ENUMV(RealSingle))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
- _vertexList[ipt].x = c[ipt];
- }
- }
- else if (!strcmp(coordinate_name, "CoordinateY"))
- {
- if (datatype == CGNS_ENUMV(RealDouble))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
+ } else if(strcmp(coordinate_name, "CoordinateY") == 0) {
+ if(datatype == CGNS_ENUMV(RealDouble)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
+ _vertexList[ipt].y = c[ipt];
+ } else if(datatype == CGNS_ENUMV(RealSingle)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].y = c[ipt];
}
- else if (datatype == CGNS_ENUMV(RealSingle))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
- _vertexList[ipt].y = c[ipt];
- }
- }
- else if (!strcmp(coordinate_name, "CoordinateZ"))
- {
- if (datatype == CGNS_ENUMV(RealDouble))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
+ } else if(dim == 3 && (strcmp(coordinate_name, "CoordinateZ") == 0)) {
+ if(datatype == CGNS_ENUMV(RealDouble)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].z = c[ipt];
- }
- else if (datatype == CGNS_ENUMV(RealSingle))
- {
- auto *c = static_cast(xyz);
- for (int ipt = 0; ipt < count; ++ipt)
+ } else if(datatype == CGNS_ENUMV(RealSingle)) {
+ auto* c = static_cast(xyz);
+ for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].z = c[ipt];
}
_dim = 3;
}
- if (datatype == CGNS_ENUMV(RealSingle))
- delete (float *)xyz;
- else if (datatype == CGNS_ENUMV(RealDouble))
- delete (double *)xyz;
+ if(datatype == CGNS_ENUMV(RealSingle))
+ delete[](float*)xyz;
+ else if(datatype == CGNS_ENUMV(RealDouble))
+ delete[](double*)xyz;
}
}
-void FCGNSGridReaderBase::readFlowSolution(vtkDataSet *grid)
+void FCGNSGridReaderBase::readFlowSolution(vtkDataSet* grid)
{
- int OK = 0;
- int nsol = 0;
- OK = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol);
- if (CG_OK != OK)
+ int result = 0;
+ int nsol = 0;
+ result = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol);
+ if(CG_OK != result) {
+ DebugError("Failed to read number of flow solution\n");
return;
+ } else {
+ DebugInfo("Number of flow solution is %d\n", nsol);
+ }
+
_dataSet = grid;
- for (int isol = 1; isol <= nsol; ++isol)
- {
- CGNS_ENUMT(GridLocation_t)
- varloc;
- char sol_name[33] = {0};
- OK = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc);
- if (CG_OK != OK)
- continue;
- qDebug() << sol_name << varloc;
+ for(int isol = 1; isol <= nsol; ++isol) {
+ CGNS_ENUMT(GridLocation_t) varloc;
+ char sol_name[33] = { 0 };
+ result = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc);
+ if(CG_OK != result) {
+ DebugError("Failed to read info of flow solution\n");
+ return;
+ } else {
+ DebugInfo("Flow solution: %s, var location: %d\n", sol_name, varloc);
+ }
QList varNames;
- QList values;
- QList valueType; // 3-float 4-double
+ QList values;
+ QList valueType; // 3-float 4-double
readFieldData(isol, varloc, varNames, valueType, values);
addValueToGrid(varloc, varNames, valueType, values);
- for (auto v : values)
+ for(auto v : values)
delete v;
values.clear();
}
}
-void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc,
- QList &varNames, QList &valueType, QList &values)
+void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc,
+ QList& varNames, QList& valueType,
+ QList& values)
{
- qDebug() << loc;
- if (loc != CGNS_ENUMT(Vertex) && loc != CGNS_ENUMT(CellCenter))
- return;
- int OK = 0;
- int var_num = 0;
- OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &var_num);
- if (CG_OK != OK)
- return;
- int valNum = 0;
- for (int iFiled = 1; iFiled <= var_num; ++iFiled)
+ if(loc != CGNS_ENUMT(Vertex) && loc != CGNS_ENUMT(CellCenter))
{
- CGNS_ENUMT(DataType_t)
- datatype;
- char var_name[33] = {0};
- OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iFiled, &datatype, var_name);
- if (CG_OK != OK)
- continue;
- qDebug() << var_name << datatype;
-
- cgsize_t min[3] = {1, 1, 1}, max[3] = {0};
- if (!_isStructedGrid)
+ DebugError("Unsupported grid location: %d\n", loc);
+ return;
+ }
+ int OK = 0;
+ int nFields = 0;
+ OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &nFields);
+ if(CG_OK != OK)
+ {
+ DebugError("Failed to read number of fields\n");
+ return;
+ }
+ int valNum = 0;
+ for(int iField = 1; iField <= nFields; ++iField) {
+ CGNS_ENUMT(DataType_t) datatype;
+ char fieldName[33] = { 0 };
+ OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iField, &datatype,
+ fieldName);
+ if(CG_OK != OK) {
+ DebugError("Failed to read info of field[%d]\n", iField);
+ return;
+ } else
{
- switch (loc)
- {
- case CGNS_ENUMT(Vertex):
- valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfPoints();
- break;
- case CGNS_ENUMT(CellCenter):
- valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfCells();
- break;
- default:
- break;
- }
+ DebugInfo("Begin to parse field: %s\n", fieldName);
}
- else
- {
+
+ cgsize_t min[3] = { 1, 1, 1 }, max[3] = { 0 };
+ if(!_isStructedGrid) {
+ switch(loc) {
+ case CGNS_ENUMT(Vertex):
+ valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfPoints();
+ break;
+ case CGNS_ENUMT(CellCenter):
+ valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfCells();
+ break;
+ default:
+ break;
+ }
+ } else {
auto sG = vtkStructuredGrid::SafeDownCast(_dataSet);
- int dims[3];
+ int dims[3];
sG->GetDimensions(dims);
- switch (loc)
- {
- case CGNS_ENUMT(Vertex):
- max[0] = dims[0];
- max[1] = dims[1];
- max[2] = dims[2];
- valNum = max[0] * max[1] * max[2];
- break;
- case CGNS_ENUMT(CellCenter):
- max[0] = dims[0] - 1;
- max[1] = dims[1] - 1;
- max[2] = dims[2] - 1;
- valNum = max[0] * max[1] * max[2];
- break;
+ switch(loc) {
+ case CGNS_ENUMT(Vertex):
+ max[0] = dims[0];
+ max[1] = dims[1];
+ max[2] = dims[2];
+ valNum = max[0] * max[1] * max[2];
+ break;
+ case CGNS_ENUMT(CellCenter):
+ max[0] = dims[0] - 1;
+ max[1] = dims[1] - 1;
+ max[2] = dims[2] - 1;
+ valNum = max[0] * max[1] * max[2];
+ break;
- default:
- break;
+ default:
+ break;
}
}
- void *valuesArr = nullptr;
+ void* valuesArr = nullptr;
- if (datatype == CGNS_ENUMT(RealSingle))
+ if(datatype == CGNS_ENUMT(RealSingle))
valuesArr = new float[valNum];
- else if (datatype == CGNS_ENUMT(RealDouble))
+ else if(datatype == CGNS_ENUMT(RealDouble))
valuesArr = new double[valNum];
- OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, var_name, datatype, min, max, valuesArr);
- if (CG_OK != OK)
- continue;
+ OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, fieldName, datatype, min,
+ max, valuesArr);
+ if(CG_OK != OK) {
+ DebugError("Failed to read flow solution for %s\n", fieldName);
+ return;
+ }
- varNames.append(var_name);
- values.append(valuesArr);
+ varNames.append(fieldName);
valueType.append(datatype);
+ values.append(valuesArr);
}
}
-void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
- QList varNames, QList vType, QList valueList)
+void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList varNames,
+ QList vType, QList valueList)
{
QHash> vectorName;
- QStringList scalarName;
- for (QString varName : varNames)
- {
+ QStringList scalarName;
+ for(QString varName : varNames) {
QString component, vecName;
- bool isV = isVectorComponent(varName, vecName, component);
- if (!isV)
+ bool isV = isVectorComponent(varName, vecName, component);
+ if(isV) {
+ vectorName[vecName].insert(component.toLower(), varName);
+ } else
{
scalarName.append(varName);
- continue;
}
- vectorName[vecName].insert(component.toLower(), varName);
+
}
QStringList vecKeys = vectorName.keys();
QStringList unVkeys;
- for (QString vecKey : vecKeys)
- {
+ for(QString vecKey : vecKeys) {
QHash vvs = vectorName.value(vecKey);
- if (vvs.size() == _dim)
+ if(vvs.size() == _dim)
continue;
unVkeys.append(vecKey);
scalarName.append(vvs.values());
}
- for (QString uk : unVkeys)
+ for(QString uk : unVkeys)
vectorName.remove(uk);
- if (CGNS_ENUMT(Vertex) == loc)
- {
- int nc = _dataSet->GetNumberOfPoints();
- auto pointArray = _dataSet->GetPointData();
- for (QString sca : scalarName)
- {
- int index = varNames.indexOf(sca);
- int type = vType.at(index);
- void *v = valueList.at(index);
- auto array = generateScalarArray(sca, nc, type, v);
+ if(CGNS_ENUMT(Vertex) == loc) {
+ int nc = _dataSet->GetNumberOfPoints();
+ auto* pointArray = _dataSet->GetPointData();
+ for(QString sca : scalarName) {
+ int index = varNames.indexOf(sca);
+ int type = vType.at(index);
+ void* v = valueList.at(index);
+ auto array = generateScalarArray(sca, nc, type, v);
pointArray->AddArray(array);
}
- for (QString vec : vectorName.keys())
- {
+ for(QString vec : vectorName.keys()) {
QHash comps = vectorName.value(vec);
- QString comp = comps.value("x");
- int index = varNames.indexOf(comp);
- void *x = valueList.at(index);
- int xtype = vType.at(index);
+ QString comp = comps.value("x");
+ int index = varNames.indexOf(comp);
+ void* x = valueList.at(index);
+ int xtype = vType.at(index);
- comp = comps.value("y");
- index = varNames.indexOf(comp);
- void *y = valueList.at(index);
- int ytype = vType.at(index);
+ comp = comps.value("y");
+ index = varNames.indexOf(comp);
+ void* y = valueList.at(index);
+ int ytype = vType.at(index);
- comp = comps.value("z");
- index = varNames.indexOf(comp);
- void *z = nullptr;
- int ztype = 0;
- if (index >= 0)
- {
- z = valueList.at(index);
+ comp = comps.value("z");
+ index = varNames.indexOf(comp);
+ void* z = nullptr;
+ int ztype = 0;
+ if(index >= 0) {
+ z = valueList.at(index);
ztype = vType.at(index);
}
auto array = generateVectorArray(vec, nc, xtype, x, ytype, y, ztype, z);
pointArray->AddArray(array);
}
- }
- else if (CGNS_ENUMT(CellCenter) == loc)
- {
- int nc = _dataSet->GetNumberOfCells();
+ } else if(CGNS_ENUMT(CellCenter) == loc) {
+ int nc = _dataSet->GetNumberOfCells();
auto cellArray = _dataSet->GetCellData();
- for (QString sca : scalarName)
- {
- int index = varNames.indexOf(sca);
- void *v = valueList.at(index);
- int type = vType.at(index);
- auto array = generateScalarArray(sca, nc, type, v);
+ for(QString sca : scalarName) {
+ int index = varNames.indexOf(sca);
+ void* v = valueList.at(index);
+ int type = vType.at(index);
+ auto array = generateScalarArray(sca, nc, type, v);
cellArray->AddArray(array);
}
- for (QString vec : vectorName.keys())
- {
+ for(QString vec : vectorName.keys()) {
QHash comps = vectorName.value(vec);
- QString comp = comps.value("x");
- int index = varNames.indexOf(comp);
- void *x = valueList.at(index);
- int xtype = vType.at(index);
+ QString comp = comps.value("x");
+ int index = varNames.indexOf(comp);
+ void* x = valueList.at(index);
+ int xtype = vType.at(index);
- comp = comps.value("y");
- index = varNames.indexOf(comp);
- void *y = valueList.at(index);
- int ytype = vType.at(index);
+ comp = comps.value("y");
+ index = varNames.indexOf(comp);
+ void* y = valueList.at(index);
+ int ytype = vType.at(index);
- comp = comps.value("z");
- index = varNames.indexOf(comp);
- void *z = nullptr;
- int ztype = 0;
- if (index >= 0)
- {
- z = valueList.at(index);
+ comp = comps.value("z");
+ index = varNames.indexOf(comp);
+ void* z = nullptr;
+ int ztype = 0;
+ if(index >= 0) {
+ z = valueList.at(index);
ztype = vType.at(index);
}
@@ -325,64 +336,59 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
}
}
-bool FCGNSGridReaderBase::isVectorComponent(QString name, QString &vecName, QString &comp)
+bool FCGNSGridReaderBase::isVectorComponent(QString name, QString& vecName, QString& comp)
{
QRegExp pattern("\\s*x$|\\s*X$|\\s*y$|\\s*Y$|\\s*z$|\\s*Z$");
- bool is = false;
- is = name.contains(pattern);
- if (is)
- {
- comp = name.right(1);
+ bool is = false;
+ is = name.contains(pattern);
+ if(is) {
+ comp = name.right(1);
vecName = name.remove(comp);
- if (vecName.isEmpty())
+ if(vecName.isEmpty())
return false;
}
return is;
}
-vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num, int type, void *va)
+vtkDataArray* FCGNSGridReaderBase::generateScalarArray(QString varName, int num, int type, void* va)
{
- vtkDataArray *array = nullptr;
- float *valueFloat = nullptr;
- double *valueDouble = nullptr;
+ vtkDataArray* array = nullptr;
+ float* valueFloat = nullptr;
+ double* valueDouble = nullptr;
- if (type == 3) // float
+ if(type == 3) // float
{
- array = vtkFloatArray::New();
- valueFloat = static_cast(va);
- }
- else if (type == 4) // double
+ array = vtkFloatArray::New();
+ valueFloat = static_cast(va);
+ } else if(type == 4) // double
{
- array = vtkDoubleArray::New();
- valueDouble = static_cast(va);
+ array = vtkDoubleArray::New();
+ valueDouble = static_cast(va);
}
double v = 0;
array->SetName(varName.toLatin1().data());
- for (int i = 0; i < num; ++i)
- {
- switch (type)
- {
- case 3:
- v = valueFloat[i];
- break;
- case 4:
- v = valueDouble[i];
- break;
- default:
- break;
+ for(int i = 0; i < num; ++i) {
+ switch(type) {
+ case 3:
+ v = valueFloat[i];
+ break;
+ case 4:
+ v = valueDouble[i];
+ break;
+ default:
+ break;
}
array->InsertNextTuple1(v);
}
double range[2];
array->GetRange(range);
- qDebug() << varName << range[0] << range[1];
return array;
}
-vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
- int xType, void *x, int yType, void *y, int zType, void *z)
+vtkDataArray* FCGNSGridReaderBase::generateVectorArray(QString varName, int num, int xType, void* x,
+ int yType, void* y, int zType, void* z)
{
auto array = vtkDoubleArray::New();
array->SetName(varName.toLatin1().data());
@@ -391,61 +397,57 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
array->SetComponentName(1, "y");
array->SetComponentName(2, "z");
- float *xFV = nullptr, *yFV = nullptr, *zFV = nullptr;
+ float * xFV = nullptr, *yFV = nullptr, *zFV = nullptr;
double *xDV = nullptr, *yDV = nullptr, *zDV = nullptr;
- if (xType == 3) // float
- xFV = static_cast(x);
- else if (xType == 4) // double
- xDV = static_cast(x);
+ if(xType == 3) // float
+ xFV = static_cast(x);
+ else if(xType == 4) // double
+ xDV = static_cast(x);
- if (yType == 3) // float
- yFV = static_cast(y);
- else if (yType == 4) // double
- yDV = static_cast(y);
+ if(yType == 3) // float
+ yFV = static_cast(y);
+ else if(yType == 4) // double
+ yDV = static_cast(y);
- if (zType == 3) // float
- zFV = static_cast(z);
- else if (zType == 4) // double
- zDV = static_cast(z);
+ if(zType == 3) // float
+ zFV = static_cast(z);
+ else if(zType == 4) // double
+ zDV = static_cast(z);
double vx = 0, vy = 0, vz = 0;
- for (int i = 0; i < num; ++i)
- {
- switch (xType)
- {
- case 3:
- vx = xFV[i];
- break;
- case 4:
- vx = xDV[i];
- break;
- default:
- break;
+ for(int i = 0; i < num; ++i) {
+ switch(xType) {
+ case 3:
+ vx = xFV[i];
+ break;
+ case 4:
+ vx = xDV[i];
+ break;
+ default:
+ break;
}
- switch (yType)
- {
- case 3:
- vy = yFV[i];
- break;
- case 4:
- vy = yDV[i];
- break;
- default:
- break;
+ switch(yType) {
+ case 3:
+ vy = yFV[i];
+ break;
+ case 4:
+ vy = yDV[i];
+ break;
+ default:
+ break;
}
- switch (zType)
- {
- case 3:
- vz = zFV[i];
- break;
- case 4:
- vz = zDV[i];
- break;
- default:
- break;
+ switch(zType) {
+ case 3:
+ vz = zFV[i];
+ break;
+ case 4:
+ vz = zDV[i];
+ break;
+ default:
+ break;
}
array->InsertNextTuple3(vx, vy, vz);
diff --git a/src/PostAlgorithm/FCGNSGridReaderBase.h b/src/PostAlgorithm/FCGNSGridReaderBase.h
index 54112dc..da578f5 100644
--- a/src/PostAlgorithm/FCGNSGridReaderBase.h
+++ b/src/PostAlgorithm/FCGNSGridReaderBase.h
@@ -1,59 +1,154 @@
#ifndef _FCGNSGRIDREADER_H__
#define _FCGNSGRIDREADER_H__
-#include
-#include
#include
+#include
#include
+#include
class vtkMultiBlockDataSet;
class vtkDataSet;
class vtkDataArray;
-struct VPoint
-{
- double x{0};
- double y{0};
- double z{0};
+/**
+ * @brief 用于存储点坐标的结构体
+ * @since 2.5.0
+ */
+struct VPoint {
+ double x{ 0 };
+ double y{ 0 };
+ double z{ 0 };
};
-class FCGNSGridReaderBase
-{
+class FCGNSGridReaderBase {
public:
- FCGNSGridReaderBase(vtkMultiBlockDataSet* root);
- virtual ~FCGNSGridReaderBase() = default;
+ /**
+ * @brief 构造函数
+ * @param[out] root 包含数据的vtkMultiBlockDataSet对象
+ */
+ FCGNSGridReaderBase(vtkMultiBlockDataSet* root);
+ virtual ~FCGNSGridReaderBase() = default;
- void setInfo(int fileIndex, int baseIndex, int zoneIndex);
+ /**
+ * @brief 设置要读取zone的信息
+ *
+ * @param[in] fileIndex 文件索引
+ * @param[in] baseIndex 单库base的索引
+ * @param[in] zoneIndex 区域zone的索引
+ */
+ void setInfo(int fileIndex, int baseIndex, int zoneIndex);
- virtual void read()=0;
+ /**
+ * @brief zone读取函数,由子类重写
+ * @since 2.5.0
+ */
+ virtual void read() = 0;
protected:
- void readCoordinate(int dim,int count, cgsize_t range_from[3], cgsize_t range_to[3]);
+ /**
+ * @brief 读取zone中的坐标信息
+ * @param[in] dim 维数
+ * @param[in] count 顶点数
+ * @param[out] range_from 指定读取范围的最小索引,全部读取时为1
+ * @param[out] range_to 指定读取范围的最大索引,全部读取时为顶点数
+ * @since 2.5.0
+ */
+ void readCoordinate(int dim, int count, cgsize_t range_from[3], cgsize_t range_to[3]);
+ /**
+ * @brief 读取zone中的计算结果
+ * @param[out] grid 要保存计算结果的vtkDataSet对象
+ * @since 2.5.0
+ */
+ void readFlowSolution(vtkDataSet* grid);
+ /**
+ * @brief 读取场数据
+ * @param[in] solIndex 计算结果索引
+ * @param[in] loc 计算结果存储位置
+ * @param[out] varNames 场变量名称数组
+ * @param[out] valueType 场变量类型数组
+ * @param[out] values 场变量数据数组
+ * @since 2.5.0
+ */
+ void readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc, QList& varNames,
+ QList& valueType, QList& values);
+ /**
+ * @brief 添加场数据到vtk格式数据中
+ * @param[in] loc 场变量位置
+ * @param[in] varNames 场变量名称数组
+ * @param[in] valueType 场变量类型数组
+ * @param[in] values 场变量数据数组
+ * @since 2.5.0
+ */
+ void addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList varNames,
+ QList valueType, QList values);
- void readFlowSolution(vtkDataSet* grid);
+ /**
+ * @brief 判断场变量是否为矢量分量
+ * @param[in] name 场变量名称
+ * @param[out] vecName 场变量名称(不含分量x,y,z)
+ * @param[out] comp 分量(x,y,z)
+ * @note 该函数判断依据为变量名称的最后一个字母是否为x,y,z(不区分大小写)。
+ * @since 2.5.0
+ */
+ bool isVectorComponent(QString name, QString& vecName, QString& comp);
+ /**
+ * @brief 生成标量场的vtkDataArray
+ * @param[in] varName 场变量名称
+ * @param[in] num 场变量值数组大小
+ * @param[in] type 场变量数据类型
+ * @param[in] va 场变量值数组
+ * @since 2.5.0
+ */
+ vtkDataArray* generateScalarArray(QString varName, int num, int type, void* va);
- void readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc,QList &varNames,
- QList &valueType, QList &values);
-
- void addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList varNames,
- QList valueType, QList values);
-
- bool isVectorComponent(QString name, QString& vecName, QString& comp);
-
- vtkDataArray* generateScalarArray(QString varName, int num, int type,void* va);
-
- vtkDataArray* generateVectorArray(QString varName, int num,
- int xtype, void * x,int ytype, void* y, int ztype, void* z);
+ /**
+ * @brief 生成矢量场的vtkDataArray
+ * @param[in] varName 场变量名称
+ * @param[in] num 场变量值数组大小
+ * @param[in] xtype 场变量数据x分量类型
+ * @param[in] x 场变量值x分量数组
+ * @param[in] ytype 场变量数据y分量类型
+ * @param[in] y 场变量值y分量数组
+ * @param[in] ztype 场变量数据z分量类型
+ * @param[in] z 场变量值z分量数组
+ * @since 2.5.0
+ */
+ vtkDataArray* generateVectorArray(QString varName, int num, int xtype, void* x, int ytype,
+ void* y, int ztype, void* z);
protected:
- vtkMultiBlockDataSet* _root{};
- int _fileIndex{ -1 }, _baseIndex{ -1 }, _zoneIndex{ -1 };
- bool _isStructedGrid{ false };
- int _dim{ 2 };
- vtkDataSet* _dataSet{};
- QString _zoneName;
+ /**
+ * @brief 存储要返回的结果数据
+ */
+ vtkMultiBlockDataSet* _root{};
+ /**
+ * @brief CGNS文件索引
+ */
+ int _fileIndex{ -1 };
+ /**
+ * @brief base索引
+ */
+ int _baseIndex{ -1 };
+ /**
+ * @brief zone索引
+ */
+ int _zoneIndex{ -1 };
+ /**
+ * @brief 是否为结构化数据
+ */
+ bool _isStructedGrid{ false };
+ /**
+ * @brief 数据维度
+ */
+ int _dim{ 2 };
+ vtkDataSet* _dataSet{};
+ QString _zoneName;
- QVector _vertexList{};
+ /**
+ * @brief 节点数组
+ * @since 2.5.0
+ */
+ QVector _vertexList{};
};
#endif
diff --git a/src/PostAlgorithm/FCGNSReader.cpp b/src/PostAlgorithm/FCGNSReader.cpp
index 1fdf574..acf590f 100644
--- a/src/PostAlgorithm/FCGNSReader.cpp
+++ b/src/PostAlgorithm/FCGNSReader.cpp
@@ -1,234 +1,288 @@
#include "FCGNSReader.h"
+
+#include "Common/DebugLogger.h"
+#include "FCGNSStructureZoneReader.h"
+#include "FCGNSUnStructureZoneReader.h"
+
+#include
+#include
+#include
+#include
#include
#include
-#include
-#include
#include
#include
-#include
-#include
-#include
-#include "FCGNSUnStructureZoneReader.h"
-#include "FCGNSStructureZoneReader.h"
+#include
FCGNSReader* FCGNSReader::New()
{
- auto reader = new FCGNSReader;
- reader->InitializeObjectBase();
- return reader;
+ auto reader = new FCGNSReader;
+ reader->InitializeObjectBase();
+ return reader;
}
void FCGNSReader::PrintSelf(ostream& os, vtkIndent indent)
{
- Q_UNUSED(os)
- Q_UNUSED(indent)
+ Q_UNUSED(os)
+ Q_UNUSED(indent)
}
FCGNSReader::FCGNSReader()
{
- this->SetNumberOfInputPorts(0);
- this->SetNumberOfOutputPorts(1);
- this->FileName = nullptr;
+ this->SetNumberOfInputPorts(0);
+ this->SetNumberOfOutputPorts(1);
+ this->FileName = nullptr;
}
-FCGNSReader::~FCGNSReader()
+FCGNSReader::~FCGNSReader() {}
+
+void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex,
+ vtkMultiBlockDataSet* output)
{
+ // 读取zonetype:Structured 或 Unstructured
+ CGNS_ENUMT(ZoneType_t) zonetype;
+ if(CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype)){
+ DebugError("Failed to read zone(index = %d) type\n", zoneIndex);
+ return;
+ }
+
+ if(zonetype == CGNS_ENUMV(Structured)) {
+ FCGNSStructeGridReader r(output);
+ r.setInfo(fileIndex, baseIndex, zoneIndex);
+ r.setReadBC(_readBC);
+ r.read();
+ } else if(zonetype == CGNS_ENUMV(Unstructured)) {
+ FCGNSUnStructeGridReader r(output);
+ r.setInfo(fileIndex, baseIndex, zoneIndex);
+ r.read();
+ }
}
-void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output)
+int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
+ vtkInformationVector* outputVector)
{
- CGNS_ENUMT(ZoneType_t) zonetype;
- if (CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype))
- return ;
-
- if (zonetype == CGNS_ENUMV(Structured))
- {
- FCGNSStructeGridReader r(output);
- r.setInfo(fileIndex, baseIndex, zoneIndex);
- r.setReadBC(_readBC);
- r.read();
- }
- else if (zonetype == CGNS_ENUMV(Unstructured))
- {
- FCGNSUnStructeGridReader r(output);
- r.setInfo(fileIndex, baseIndex, zoneIndex);
- r.read();
- }
+ if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
+ return this->RequestInformation(request, inputVector, outputVector);
+ }
+ if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
+ return this->RequestUpdateExtent(request, inputVector, outputVector);
+ }
+ if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
+ return this->RequestData(request, inputVector, outputVector);
+ }
+ return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
-int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
+int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**,
+ vtkInformationVector* outputVector)
{
- if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
- {
- return this->RequestInformation(request, inputVector,
- outputVector);
- }
- if (request->Has(
- vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
- {
- return this->RequestUpdateExtent(request, inputVector,
- outputVector);
- }
- if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
- {
- return this->RequestData(request, inputVector, outputVector);
- }
- return this->Superclass::ProcessRequest(request, inputVector,
- outputVector);
-}
+ auto output = vtkMultiBlockDataSet::GetData(outputVector);
-int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
-{
- auto output = vtkMultiBlockDataSet::GetData(outputVector);
+ bool ok = canReadFile();
+ if(!ok) {
+ return 0;
+ }
- bool ok = canReadFile();
- if (!ok) return 0;
+ // 打开文件
+ int currentFileIndex = 0;
+ if(CG_OK != cg_open(FileName, CG_MODE_READ, ¤tFileIndex)) {
+ DebugError("Failed to open file %s\n", FileName);
+ return 0;
+ } else {
+ DebugInfo("Success to open file %s\n", FileName);
+ }
- int currentFileIndex = 0;
- if (cg_open(FileName, CG_MODE_READ, ¤tFileIndex))
- {
- return 0;
- }
-
+ // 获取CGNS数据库的单库(CGNSBase_t)的数量,一般为1
+ int nBase = 0;
+ if(CG_OK != cg_nbases(currentFileIndex, &nBase)) {
+ DebugError("Failed to get number of base\n");
+ return 0;
+ }
- int nBase = 0;
- if (cg_nbases(currentFileIndex, &nBase))
- {
- return 0;
- }
-
- for (int ibase = 1; ibase <= nBase; ++ibase)
- {
- int zone_node_number = 0;
- if (cg_nzones(currentFileIndex, ibase, &zone_node_number))
- {
- return false;
- }
- for (int izone = 1; izone <= zone_node_number; ++izone)
- {
- readZone(currentFileIndex, ibase, izone, output);
- }
-
- }
- cgio_close_file(currentFileIndex);
- return 1;
+ // 遍历读取zone(base和zone节点的索引都是从1开始的)
+ for(int ibase = 1; ibase <= nBase; ++ibase) {
+ int zone_node_number = 0;
+ if(CG_OK != cg_nzones(currentFileIndex, ibase, &zone_node_number)) {
+ return false;
+ }
+ for(int izone = 1; izone <= zone_node_number; ++izone) {
+ readZone(currentFileIndex, ibase, izone, output);
+ }
+ }
+ // 关闭文件
+ cg_close(currentFileIndex);
+ return 1;
}
bool FCGNSReader::canReadFile()
-{
- int cgioFile;
- int ierr = 1;
- double rootNodeId;
- double childId;
- float FileVersion = 0.0;
- int intFileVersion = 0;
- char dataType[CGIO_MAX_DATATYPE_LENGTH + 1];
- char errmsg[CGIO_MAX_ERROR_LENGTH + 1];
- int ndim = 0;
- cgsize_t dimVals[12];
- int fileType = CG_FILE_NONE;
+{
+ int cgioFile;
+ bool ierr = true;
+ double rootNodeId;
+ double childId;
+ float FileVersion = 0.0;
+ int intFileVersion = 0;
+ char dataType[CGIO_MAX_DATATYPE_LENGTH + 1];
+ char errmsg[CGIO_MAX_ERROR_LENGTH + 1];
+ int ndim = 0;
+ cgsize_t dimVals[12];
+ int fileType = CGIO_FILE_NONE;
+ char* fileTypeStr = new char[20];
- if (cgio_open_file(FileName, CG_MODE_READ, CG_FILE_NONE, &cgioFile) != CG_OK)
- {
- cgio_error_message(errmsg);
- vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg);
- return 0;
- }
+ // 检查文件文件名以确定它是否是有效的数据库
+ auto result = cgio_check_file(FileName, &fileType);
+ if(CGIO_ERR_NONE != result || CGIO_FILE_NONE == fileType) {
+ DebugError("%s is a invalid database!\n", FileName);
+ return false;
+ } else {
+ DebugInfo("Check database: %s?\tpass!\n", FileName);
+ }
- cgio_get_root_id(cgioFile, &rootNodeId);
- cgio_get_file_type(cgioFile, &fileType);
+ // 确定当前库是否支持fileType给出的数据库类型
+ // 始终支持CGIO_FILE_ADF;如果库是用HDF5构建的,则支持CGIO_FILE_HDF5;在32位模式下构建时支持CGIO_FILE_ADF2。
+ result = cgio_is_supported(fileType);
+ switch(fileType) {
+ case CGIO_FILE_ADF:
+ strcpy(fileTypeStr, "CGIO_FILE_ADF");
+ break;
+ case CGIO_FILE_HDF5:
+ strcpy(fileTypeStr, "CGIO_FILE_HDF5");
+ break;
+ case CGIO_FILE_ADF2:
+ strcpy(fileTypeStr, "CGIO_FILE_ADF2");
+ break;
+ case CGIO_FILE_NONE:
+ strcpy(fileTypeStr, "CGIO_FILE_NONE");
+ break;
+ default:
+ fileTypeStr = "Unknown";
+ break;
+ }
+ if(CGIO_ERR_FILE_TYPE == result) {
+ DebugError("FileType: %s is not support!\n", fileTypeStr);
+ return false;
+ } else {
+ DebugInfo("FileType: support by library?\tyes!\n");
+ }
- if (cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId))
- {
- cgio_error_message(errmsg);
- vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg);
- ierr = 0;
- goto CanReadError;
- }
+ // 打开数据库,设置数据库标识cgioFile,用于后续操作
+ if(cgio_open_file(FileName, CG_MODE_READ, fileType, &cgioFile) != CG_OK) {
+ cgio_error_message(errmsg);
+ DebugError("Failed to open file %s, error: %s\n", FileName, errmsg);
+ return 0;
+ } else {
+ DebugInfo("Success to open file %s, identifier = %d\n", FileName, cgioFile);
+ }
- if (cgio_get_data_type(cgioFile, childId, dataType))
- {
- vtkErrorMacro(<< "CGNS Version data type");
- ierr = 0;
- goto CanReadError;
- }
+ // 获取数据库中根节点的标识
+ if(CG_OK != cgio_get_root_id(cgioFile, &rootNodeId)) {
+ DebugError("Failed to get root node identifier of database(%d)\n", cgioFile);
+ goto CloseDataBase;
+ } else {
+ DebugInfo("Success to get root node identifier of database(%d), identifier = %d\n",
+ cgioFile, rootNodeId);
+ }
- if (cgio_get_dimensions(cgioFile, childId, &ndim, dimVals))
- {
- vtkErrorMacro(<< "cgio_get_dimensions");
- ierr = 0;
- goto CanReadError;
- }
+ // 为什么还要获取一次fileType?
+ // cgio_get_file_type(cgioFile, &fileType);
- // check data type
- if (strcmp(dataType, "R4") != 0)
- {
- vtkErrorMacro(<< "Unexpected data type for CGNS-Library-Version=" << dataType);
- ierr = 0;
- goto CanReadError;
- }
+ // 获取生成文件的CGNS动态库版本
+ if(CG_OK != cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId)) {
+ cgio_error_message(errmsg);
+ DebugError("Failed to get CGNSLibraryVersion node, error: %s\n", errmsg);
+ ierr = false;
+ goto CloseDataBase;
+ } else {
+ DebugInfo("Success to get CGNSLibraryVersion node, identifier = %f\n", childId);
+ }
- // check data dim
- if ((ndim != 1) || (dimVals[0] != 1))
- {
- vtkDebugMacro(<< "Wrong data dimension for CGNS-Library-Version");
- ierr = 0;
- goto CanReadError;
- }
+ // 获取CGNSLibraryVersion节点的数据类型( "MT", "I4", "I8", "U4", "U8", "R4", "C1", "B1")
+ // "MT" 不包含数据的空节点
+ // "I4" 32位整数(4字节)
+ // "I8" 64位整数(8字节)
+ // "U4" 32位无符号整数(4字节)
+ // "U8" 64位无符号整数(8字节)
+ // "R4" 32位实数(4字节)
+ // "R8" 64位实数(8字节)
+ // "C1" 字符
+ // "B1" 无符号字节
+ if(CG_OK != cgio_get_data_type(cgioFile, childId, dataType)) {
+ cgio_error_message(errmsg);
+ DebugError("Failed to get CGNSLibraryVersion value type, error: %s\n", errmsg);
+ ierr = false;
+ goto CloseDataBase;
+ } else {
+ DebugInfo("Success to get CGNSLibraryVersion value type: %s\n", dataType);
+ }
- // read data
- if (cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion))
- {
- vtkErrorMacro(<< "read CGNS version number");
- ierr = 0;
- goto CanReadError;
- }
+ // 获取CGNSLibraryVersion节点的数据的维度
+ if(CG_OK != cgio_get_dimensions(cgioFile, childId, &ndim, dimVals)) {
+ cgio_error_message(errmsg);
+ DebugError("Failed to get CGNSLibraryVersion value dimensions, error: %s\n", errmsg);
+ ierr = false;
+ goto CloseDataBase;
+ } else {
+ DebugInfo("Success to get CGNSLibraryVersion value dimensions, num of dimensions: %d\n",
+ ndim);
+ }
- // Check that the library version is at least as recent as the one used
- // to create the file being read
+ // 检查CGNSLibraryVersion节点的数据类型(float,参考cg_version函数:http://cgns.github.io/CGNS_docs_current/midlevel/fileops.html)
+ if(strcmp(dataType, "R4") != 0) {
+ DebugError("Unexpected data type for CGNS library version: %s\n", dataType);
+ ierr = false;
+ goto CloseDataBase;
+ }
- intFileVersion = static_cast(FileVersion * 1000 + 0.5);
+ // 检查CGNSLibraryVersion节点的数据的维度
+ if((ndim != 1) || (dimVals[0] != 1)) {
+ DebugError("Invalid data dimension for CGNS library version\n");
+ ierr = false;
+ goto CloseDataBase;
+ }
- if (intFileVersion > CGNS_VERSION)
- {
- // This code allows reading version newer than the lib,
- // as long as the 1st digit of the versions are equal
- if ((intFileVersion / 1000) > (CGNS_VERSION / 1000))
- {
- vtkErrorMacro(<< "The file " << FileName
- << " was written with a more recent version"
- "of the CGNS library. You must update your CGNS"
- "library before trying to read this file.");
- ierr = 0;
- }
- // warn only if different in second digit
- if ((intFileVersion / 100) > (CGNS_VERSION / 100))
- {
- vtkWarningMacro(<< "The file being read is more recent"
- "than the CGNS library used");
- }
- }
- if ((intFileVersion / 10) < 255)
- {
- vtkWarningMacro(<< "The file being read was written with an old version"
- "of the CGNS library. Please update your file"
- "to a more recent version.");
- }
- vtkDebugMacro(<< "FileVersion=" << FileVersion << "\n");
+ // 读取CGNSLibraryVersion节点的数据
+ if(cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion)) {
+ DebugError("An error occurred reading the CGNS library version\n");
+ ierr = false;
+ goto CloseDataBase;
+ } else {
+ DebugInfo("CGNS library version: %f\n", FileVersion);
+ }
-CanReadError:
- cgio_close_file(cgioFile);
- return ierr ? true : false;
+ // 检测生成CGNS文件的库版本号是否比当前版本FastCAE使用的CGNS库版本更新
+ intFileVersion = static_cast(FileVersion * 1000 + 0.5);
+ if(intFileVersion > CGNS_VERSION) {
+ // 主版本号一样的,可以读取
+ if(floor(intFileVersion / 1000) > floor(CGNS_VERSION / 1000)) {
+ DebugError("The file %s was written with a more newer version of the CGNS library\n",
+ FileName);
+ ierr = false;
+ }
+ // warn only if different in second digit
+ if((intFileVersion / 100) > (CGNS_VERSION / 100)) {
+ vtkWarningMacro(<< "The file being read is more recent"
+ "than the CGNS library used");
+ }
+ }
+ if((intFileVersion / 10) < 255) {
+ vtkWarningMacro(<< "The file being read was written with an old version"
+ "of the CGNS library. Please update your file"
+ "to a more recent version.");
+ }
+
+CloseDataBase:
+ cgio_close_file(cgioFile);
+ return ierr;
}
void FCGNSReader::setReadBC(bool read)
{
- _readBC = read;
- this->Modified();
+ _readBC = read;
+ this->Modified();
}
bool FCGNSReader::isReadBC()
{
- return _readBC;
+ return _readBC;
}
diff --git a/src/PostAlgorithm/FCGNSReader.h b/src/PostAlgorithm/FCGNSReader.h
index d91e41d..8c0a35b 100644
--- a/src/PostAlgorithm/FCGNSReader.h
+++ b/src/PostAlgorithm/FCGNSReader.h
@@ -3,36 +3,49 @@
#include
-class FCGNSReader : public vtkMultiBlockDataSetAlgorithm
-{
+class FCGNSReader : public vtkMultiBlockDataSetAlgorithm {
public:
- static FCGNSReader* New();
- vtkTypeMacro(FCGNSReader, vtkMultiBlockDataSetAlgorithm);
- void PrintSelf(ostream& os, vtkIndent indent) override;
+ static FCGNSReader* New();
+ vtkTypeMacro(FCGNSReader, vtkMultiBlockDataSetAlgorithm);
+ void PrintSelf(ostream& os, vtkIndent indent) override;
- vtkSetStringMacro(FileName);
- vtkGetStringMacro(FileName);
+ /**@name Getter和Setter宏
+ * 相当于setter/getter,同vtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
+ * @{
+ */
+ vtkSetStringMacro(FileName);
+ vtkGetStringMacro(FileName);
+ //@}
-
+ int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
+ vtkInformationVector* outputVector) override;
+ int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
- int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
- int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
+ /**
+ * @brief 检测指定文件是否可以被正常读取(包括文件格式、CGNS库版本号)
+ */
+ bool canReadFile();
- bool canReadFile();
+ void setReadBC(bool read);
- void setReadBC(bool read);
-
- bool isReadBC();
+ bool isReadBC();
private:
- FCGNSReader();
- ~FCGNSReader();
-
- void readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output);
+ FCGNSReader();
+ ~FCGNSReader();
+ /**
+ * @brief 读取CGNS文件的单个zone
+ * @param[in] fileIndex 文件的索引号
+ * @param[in] baseIndex base的索引号(从1开始)
+ * @param[in] zoneIndex zone的索引号(从1开始)
+ * @param[out] output
+ * @since 2.5.0
+ */
+ void readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output);
protected:
- char* FileName;
- bool _readBC{true};
+ char* FileName;
+ bool _readBC{ true };
};
#endif
\ No newline at end of file
diff --git a/src/PostAlgorithm/FCGNSStructureZoneReader.cpp b/src/PostAlgorithm/FCGNSStructureZoneReader.cpp
index ebaa8b3..7f3db5c 100644
--- a/src/PostAlgorithm/FCGNSStructureZoneReader.cpp
+++ b/src/PostAlgorithm/FCGNSStructureZoneReader.cpp
@@ -1,245 +1,219 @@
#include "FCGNSStructureZoneReader.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+
#include "PostRenderData/Macros.hxx"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root)
- :FCGNSGridReaderBase(root)
-{
- _isStructedGrid = true;
+ : FCGNSGridReaderBase(root)
+{
+ _isStructedGrid = true;
}
-
void FCGNSStructeGridReader::read()
{
- char zone_name[33] = { 0 };
- cgsize_t zoneSize[3][3] = { 0 };
- int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize[0]);
- if (CG_OK != OK) return;
- _zoneName = QString(zone_name);
-
- int dim{ 0 };
- OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
- if (CG_OK != OK) return;
+ char zone_name[33] = { 0 };
+ cgsize_t zoneSize[3][3] = { 0 };
+ int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize[0]);
+ if(CG_OK != OK)
+ return;
+ _zoneName = QString(zone_name);
- cgsize_t read_range[2][3] = { 0 };
- for (int ijk = 0; ijk < 3; ++ijk)
- {
- read_range[0][ijk] = 1;
- read_range[1][ijk] = zoneSize[0][ijk];
- }
- int nVertex = zoneSize[0][0] * zoneSize[0][1] * zoneSize[0][2];
- this->readCoordinate(dim, nVertex, read_range[0], read_range[1]);
+ int dim{ 0 };
+ OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
+ if(CG_OK != OK)
+ return;
- vtkStructuredGrid* sGrid = vtkStructuredGrid::New();
- sGrid->SetDimensions(zoneSize[0][0], zoneSize[0][1], zoneSize[0][2]);
- // vtkNew points; //形成整体点集合
- DecCreVTKSmartPtr(vtkPoints,points)
-
- for (int i = 0; i < _vertexList.size(); ++i)
- {
- VPoint po = _vertexList.at(i);
- points->InsertNextPoint(po.x, po.y, po.z);
- }
+ cgsize_t read_range[2][3] = { 0 };
+ for(int ijk = 0; ijk < 3; ++ijk) {
+ read_range[0][ijk] = 1;
+ read_range[1][ijk] = zoneSize[0][ijk];
+ }
+ int nVertex = zoneSize[0][0] * zoneSize[0][1] * zoneSize[0][2];
+ this->readCoordinate(dim, nVertex, read_range[0], read_range[1]);
- sGrid->SetPoints(points);
+ vtkStructuredGrid* sGrid = vtkStructuredGrid::New();
+ sGrid->SetDimensions(zoneSize[0][0], zoneSize[0][1], zoneSize[0][2]);
+ // vtkNew points; //形成整体点集合
+ DecCreVTKSmartPtr(vtkPoints, points)
- this->readFlowSolution(sGrid);
+ for(int i = 0; i < _vertexList.size(); ++i)
+ {
+ VPoint po = _vertexList.at(i);
+ points->InsertNextPoint(po.x, po.y, po.z);
+ }
- if(_readBC)
- this->readBC();
+ sGrid->SetPoints(points);
- this->spllitSection(sGrid);
+ this->readFlowSolution(sGrid);
+ if(_readBC)
+ this->readBC();
+
+ this->spllitSection(sGrid);
}
void FCGNSStructeGridReader::setReadBC(bool r)
{
- _readBC = r;
+ _readBC = r;
}
bool FCGNSStructeGridReader::isReadBC()
{
- return _readBC;
+ return _readBC;
}
void FCGNSStructeGridReader::readBC()
{
- int nbc{ 0 };
- int OK = cg_nbocos(_fileIndex, _baseIndex, _zoneIndex, &nbc);
- if (CG_OK != OK) return;
- for (int ibc = 1; ibc <= nbc; ++ibc)
- {
- CGNS_ENUMT(BCType_t) bctype;
- CGNS_ENUMT(PointSetType_t) ptype;
- //CGNS_ENUMT(GridLocation_t) location;
- CGNS_ENUMT(DataType_t) datatype;
- char bc_name[33] = { 0 };
- int nrmlindex[3] = { 0 };
- cgsize_t np = 0, is = 0;
- int ib = 0;
+ int nbc{ 0 };
+ int OK = cg_nbocos(_fileIndex, _baseIndex, _zoneIndex, &nbc);
+ if(CG_OK != OK)
+ return;
+ for(int ibc = 1; ibc <= nbc; ++ibc) {
+ CGNS_ENUMT(BCType_t) bctype;
+ CGNS_ENUMT(PointSetType_t) ptype;
+ // CGNS_ENUMT(GridLocation_t) location;
+ CGNS_ENUMT(DataType_t) datatype;
+ char bc_name[33] = { 0 };
+ int nrmlindex[3] = { 0 };
+ cgsize_t np = 0, is = 0;
+ int ib = 0;
- OK = cg_boco_info(_fileIndex,_baseIndex, _zoneIndex, ibc, bc_name, &bctype,
- &ptype, &np, nrmlindex, &is, &datatype, &ib);
- if (CG_OK != OK) continue;
- if(ptype != CGNS_ENUMV(PointRange)) continue;
+ OK = cg_boco_info(_fileIndex, _baseIndex, _zoneIndex, ibc, bc_name, &bctype, &ptype, &np,
+ nrmlindex, &is, &datatype, &ib);
+ if(CG_OK != OK)
+ continue;
+ if(ptype != CGNS_ENUMV(PointRange))
+ continue;
- cgsize_t * pnpnts = new cgsize_t[6];
- OK = cg_boco_read(_fileIndex, _baseIndex, _zoneIndex, ibc, pnpnts, NULL);
- if(OK != CG_OK) continue;
-
- BCInfo info(bc_name, pnpnts,bctype);
- _bcList.append(info);
- }
+ cgsize_t* pnpnts = new cgsize_t[6];
+ OK = cg_boco_read(_fileIndex, _baseIndex, _zoneIndex, ibc, pnpnts, NULL);
+ if(OK != CG_OK)
+ continue;
+ BCInfo info(bc_name, pnpnts, bctype);
+ _bcList.append(info);
+ }
}
void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird)
{
- int n = _root->GetNumberOfBlocks();
- _root->SetBlock(n, gird);
- QString NameBC = _zoneName + "!|||!" + "None";
- _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
+ int n = _root->GetNumberOfBlocks();
+ _root->SetBlock(n, gird);
+ QString NameBC = _zoneName + "!|||!" + "None";
+ _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
- extractBCs(gird);
+ extractBCs(gird);
}
-void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid *grid)
+void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid* grid)
{
- qDebug() << "BC in zone: " << _zoneName;
- int dim[3] = { 0 };
- grid->GetDimensions(dim);
- for (BCInfo bc: _bcList)
- {
- QList ptIndexs;
- for (int k = bc.kMin; k <= bc.kMax; ++k)
- {
- for (int j = bc.jMin; j <= bc.jMax; ++j)
- {
- for (int i = bc.iMin; i <= bc.iMax; ++i)
- {
- int index = dim[0]*dim[1]*k+ dim[0]*j+i;
- ptIndexs.append(index);
- }
- }
- }
- extractBCGrid(grid, &bc, ptIndexs);
- }
-
-
+ int dim[3] = { 0 };
+ grid->GetDimensions(dim);
+ for(BCInfo bc : _bcList) {
+ QList ptIndexs;
+ for(int k = bc.kMin; k <= bc.kMax; ++k) {
+ for(int j = bc.jMin; j <= bc.jMax; ++j) {
+ for(int i = bc.iMin; i <= bc.iMax; ++i) {
+ int index = dim[0] * dim[1] * k + dim[0] * j + i;
+ ptIndexs.append(index);
+ }
+ }
+ }
+ extractBCGrid(grid, &bc, ptIndexs);
+ }
}
-
-void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info, QList & indexs)
+void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info,
+ QList& indexs)
{
- vtkStructuredGrid* bcMesh = vtkStructuredGrid::New();
- const int iDim = info->iMax - info->iMin + 1;
- const int jDim = info->jMax - info->jMin + 1;
- const int kDim = info->kMax - info->kMin + 1;
+ vtkStructuredGrid* bcMesh = vtkStructuredGrid::New();
+ const int iDim = info->iMax - info->iMin + 1;
+ const int jDim = info->jMax - info->jMin + 1;
+ const int kDim = info->kMax - info->kMin + 1;
- bcMesh->SetDimensions(iDim, jDim, kDim);
+ bcMesh->SetDimensions(iDim, jDim, kDim);
- qDebug() << indexs.size();
- qDebug() << iDim * jDim*kDim;
+ DecCreVTKSmartPtr(vtkPoints, points) for(int index : indexs)
+ {
+ double* coor = grid->GetPoint(index);
+ points->InsertNextPoint(coor);
+ }
+ bcMesh->SetPoints(points);
-// vtkNew points;
- DecCreVTKSmartPtr(vtkPoints,points)
- for (int index : indexs)
- {
- double* coor = grid->GetPoint(index);
- points->InsertNextPoint(coor);
- }
- bcMesh->SetPoints(points);
+ vtkPointData* pointData = grid->GetPointData();
+ const int nArray = pointData->GetNumberOfArrays();
- vtkPointData* pointData = grid->GetPointData();
- const int nArray = pointData->GetNumberOfArrays();
+ for(int iArray = 0; iArray < nArray; ++iArray) {
+ const char* name = pointData->GetArrayName(iArray);
+ vtkDataArray* array = pointData->GetArray(name);
+ const int nComp = array->GetNumberOfComponents();
- for (int iArray = 0; iArray < nArray; ++iArray)
- {
- const char* name = pointData->GetArrayName(iArray);
- vtkDataArray* array = pointData->GetArray(name);
- const int nComp = array->GetNumberOfComponents();
+ vtkDataArray* copyArray = nullptr;
- vtkDataArray* copyArray = nullptr;
-
- if (array->IsA("vtkDoubleArray"))
- copyArray = vtkDoubleArray::New();
- else if (array->IsA("vtkFloatArray"))
- copyArray = vtkFloatArray::New();
- if(copyArray == nullptr) continue;
- copyArray->SetName(name);
+ if(array->IsA("vtkDoubleArray"))
+ copyArray = vtkDoubleArray::New();
+ else if(array->IsA("vtkFloatArray"))
+ copyArray = vtkFloatArray::New();
+ if(copyArray == nullptr)
+ continue;
+ copyArray->SetName(name);
- copyArray->SetNumberOfComponents(nComp);
- for (int ic = 0; ic < nComp; ++ic)
- {
- const char* arrName= array->GetComponentName(ic);
- copyArray->SetComponentName(ic, arrName);
- }
- // copyArray->Resize(indexs.size());
- for (int in =0;inGetComponent(index, ic);
- copyArray->InsertComponent(in, ic, v);
- }
- }
- bcMesh->GetPointData()->AddArray(copyArray);
+ copyArray->SetNumberOfComponents(nComp);
+ for(int ic = 0; ic < nComp; ++ic) {
+ const char* arrName = array->GetComponentName(ic);
+ copyArray->SetComponentName(ic, arrName);
+ }
+ // copyArray->Resize(indexs.size());
+ for(int in = 0; in < indexs.size(); ++in) {
+ int index = indexs.at(in);
+ for(int ic = 0; ic < nComp; ++ic) {
+ double v = array->GetComponent(index, ic);
+ copyArray->InsertComponent(in, ic, v);
+ }
+ }
+ bcMesh->GetPointData()->AddArray(copyArray);
+ }
- }
-
- int n = _root->GetNumberOfBlocks();
- _root->SetBlock(n, bcMesh);
- QString NameBC = info->name + "!|||!" + info->BCType;
- _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
+ int n = _root->GetNumberOfBlocks();
+ _root->SetBlock(n, bcMesh);
+ QString NameBC = info->name + "!|||!" + info->BCType;
+ _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
}
QString GetBCType(QString name, int bcType)
{
- QString sBCType{ "None" };
- QString sName = name.toLower();
- if (bcType == 7)
- {
- sBCType = "Far";
- return sBCType;
- }
- else if (bcType >= 16 && bcType <= 17)
- {
- sBCType = "Sym";
- return sBCType;
- }
- else if (bcType >= 20 && bcType <= 24)
- {
- sBCType = "Wall";
- return sBCType;
- }
- else if(sName.contains("far"))
- {
- sBCType = "Far";
- return sBCType;
- }
- else if (sName.contains("sym"))
- {
- sBCType = "Sym";
- return sBCType;
- }
- else if (sName.contains("wall"))
- {
- sBCType = "Wall";
- return sBCType;
- }
- return sBCType;
+ QString sBCType{ "None" };
+ QString sName = name.toLower();
+ if(bcType == 7) {
+ sBCType = "Far";
+ return sBCType;
+ } else if(bcType >= 16 && bcType <= 17) {
+ sBCType = "Sym";
+ return sBCType;
+ } else if(bcType >= 20 && bcType <= 24) {
+ sBCType = "Wall";
+ return sBCType;
+ } else if(sName.contains("far")) {
+ sBCType = "Far";
+ return sBCType;
+ } else if(sName.contains("sym")) {
+ sBCType = "Sym";
+ return sBCType;
+ } else if(sName.contains("wall")) {
+ sBCType = "Wall";
+ return sBCType;
+ }
+ return sBCType;
}
diff --git a/src/PostAlgorithm/FCGNSUnStructureZoneReader.cpp b/src/PostAlgorithm/FCGNSUnStructureZoneReader.cpp
index 433c635..392a062 100644
--- a/src/PostAlgorithm/FCGNSUnStructureZoneReader.cpp
+++ b/src/PostAlgorithm/FCGNSUnStructureZoneReader.cpp
@@ -1,23 +1,25 @@
#include "FCGNSUnStructureZoneReader.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+
+#include "Common/DebugLogger.h"
#include "PostRenderData/Macros.hxx"
-FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet *root)
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root)
: FCGNSGridReaderBase(root)
{
_isStructedGrid = false;
@@ -25,188 +27,361 @@ FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet *root)
void FCGNSUnStructeGridReader::read()
{
- char zone_name[33] = {0};
- cgsize_t zoneSize[3] = {0, 0, 0};
- int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize);
- if (CG_OK != OK)
+ if(_fileIndex < 0 || _baseIndex < 0 || _zoneIndex < 0) {
+ DebugError("Invalid zone(file: %d, base: %d, zone: %d)\n", _fileIndex, _baseIndex,
+ _zoneIndex);
return;
- _zoneName = QString(zone_name);
+ }
+ DebugInfo("Start reading zone(file: %d, base: %d, zone: %d)...\n", _fileIndex, _baseIndex,
+ _zoneIndex);
+ // 读取zone信息
+ char zone_name[33] = { 0 };
+ // 在非结构化网格数据中zonesize的元素分别对应NVertex, NCell, NBoundVertex
+ cgsize_t zoneSize[3] = { 0, 0, 0 };
+ auto result = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize);
+ if(CG_OK != result) {
+ DebugError("Failed to read zone(index = %d) information\n", _zoneIndex);
+ return;
+ } else {
+ DebugInfo("NVertex = %d, NCell = %d, NBoundVertex = %d\n", zoneSize[0], zoneSize[1],
+ zoneSize[2]);
+ }
+
+ _zoneName = QString(zone_name);
const int nVertex = zoneSize[0], nCell = zoneSize[1], nBoundary = zoneSize[2];
- int dim{0};
- OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
- if (CG_OK != OK)
+ // 坐标数组的个数
+ int dim{ 0 };
+ result = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
+ if(CG_OK != result) {
+ DebugError("Failed to read number of coordinate arrays for zone %d\n", _zoneIndex);
return;
+ } else {
+ DebugInfo("Number of coordinate arrays for zone %d is %d\n", _zoneIndex, dim);
+ }
- // vtkUnstructuredGrid* unsGrid = vtkUnstructuredGrid::New();
-
- DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid)
- cgsize_t read_range[2][3] = {0};
- for (int ijk = 0; ijk < 3; ++ijk)
- {
+ // 需要读取全部数据,所以range=[1,nVertex]
+ cgsize_t read_range[2][3] = { 0 };
+ for(int ijk = 0; ijk < 3; ++ijk) {
read_range[0][ijk] = 1;
read_range[1][ijk] = nVertex;
}
+ // 读取坐标数据信息
this->readCoordinate(dim, nVertex, read_range[0], read_range[1]);
-
- DecCreVTKSmartPtr(vtkPoints, points) //形成整体点集合
- for (int i = 0; i < _vertexList.size(); ++i)
- {
- VPoint po = _vertexList.at(i);
- points->InsertNextPoint(po.x, po.y, po.z);
+ if(_vertexList.size() != nVertex) {
+ DebugError("Failed to read coordinate arrays for zone %d\n", _zoneIndex);
+ return;
}
+ // 准备vtk数据,并插入点
+ DecCreVTKSmartPtr(vtkPoints, points);
+ for(int i = 0; i < _vertexList.size(); ++i) {
+ auto po = _vertexList.at(i);
+ points->InsertNextPoint(po.x, po.y, po.z);
+ }
+ DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid);
unsGrid->SetPoints(points);
- int nSection{0};
- cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection);
+ // 获取网格单元的节点数量
+ int nSection{ 0 };
+ result = cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection);
+ if(CG_OK != result) {
+ DebugError("Failed to get number of element sections\n");
+ return;
+ } else {
+ DebugInfo("Number of element sections is %d\n", nSection);
+ }
QList sectionList = sectionOrder(nSection);
+ if(sectionList.size() == 0) {
+ DebugError("Failed to order sections\n");
+ return;
+ }
- for (int iSection : sectionList)
- {
- char sectionName[33] = {0};
+ for(int iSection : sectionList) {
+ char sectionName[33] = { 0 };
cgsize_t istart = 0, iend = 0;
- int nbndry = 0, iparent_flag = 0;
+ int nbndry = 0, iparent_flag = 0;
CGNS_ENUMT(ElementType_t)
itype;
- OK = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype, &istart, &iend, &nbndry, &iparent_flag);
- const int ncellCount = iend - istart + 1;
+ result = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype,
+ &istart, &iend, &nbndry, &iparent_flag);
- qDebug() << QString(sectionName) << istart << iend;
- cgsize_t elementDataSize = 0;
- OK = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize);
- if (CG_OK != 0)
- continue;
- cgsize_t *elements = new cgsize_t[elementDataSize];
- OK = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL);
- if (CG_OK != 0)
- continue;
- FSection section(QString(sectionName), istart, iend); //记录section
+ if(CG_OK != result) {
+ DebugError("Failed to read element section: %d\n", iSection);
+ return;
+ } else {
+ DebugInfo("element section: %s, element type: %d, first element index: %d, last "
+ "element index: %d\n",
+ sectionName, static_cast(itype), istart, iend);
+ }
+
+ const int ncellCount = iend - istart + 1;
+ cgsize_t elementDataSize = 0;
+ result = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize);
+ if(CG_OK != result) {
+ DebugError("Failed to get size of element connectivity data array\n");
+ return;
+ }
+ cgsize_t* elements = new cgsize_t[elementDataSize];
+ cgsize_t* connectOffset = nullptr;
+ /** */
+
+ if(itype == CGNS_ENUMT(MIXED)) {
+ connectOffset = new cgsize_t[elementDataSize];
+ result = cg_poly_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements,
+ connectOffset, NULL);
+ } else {
+ // 只能读取固定大小的单元类型
+ result = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL);
+ }
+ if(CG_OK != result) {
+ DebugError("Failed to read fixed size element data, error: %s\n", cg_get_error());
+ return;
+ }
+
+ FSection section(QString(sectionName), istart, iend);
_sections.append(section);
- this->addCells(unsGrid, ncellCount, itype, elements);
+ this->addCells(unsGrid, ncellCount, itype, elements, connectOffset);
}
this->readFlowSolution(unsGrid);
this->spllitSection(unsGrid);
}
-void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid *grid, int ncell, CGNS_ENUMT(ElementType_t) type, cgsize_t *elements)
+/**
+ * type:参考http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
+ * ElementTypeNull, ElementTypeUserDefined, NODE, BAR_2, BAR_3, TRI_3, TRI_6, QUAD_4, QUAD_8,
+ * QUAD_9, TETRA_4, TETRA_10, PYRA_5, PYRA_14, PENTA_6, PENTA_15, PENTA_18, HEXA_8, HEXA_20,
+ * HEXA_27, MIXED, PYRA_13, NGON_n, NFACE_n, BAR_4, TRI_9, TRI_10, QUAD_12, QUAD_16, TETRA_16,
+ * TETRA_20, PYRA_21, PYRA_29, PYRA_30, PENTA_24, PENTA_38, PENTA_40, HEXA_32, HEXA_56, HEXA_64,
+ * BAR_5, TRI_12, TRI_15, QUAD_P4_16, QUAD_25, TETRA_22, TETRA_34, TETRA_35, PYRA_P4_29, PYRA_50,
+ * PYRA_55, PENTA_33, PENTA_66, PENTA_75, HEXA_44, HEXA_98, HEXA_125
+ *
+ * CGNS的索引是从1开始的,VTK的索引是从0开始,需要注意
+ */
+void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid* grid, int ncell,
+ CGNS_ENUMT(ElementType_t) type, cgsize_t* elements,
+ cgsize_t* connectOffset)
{
- if (CGNS_ENUMT(TRI_3) == type) //三角形
+ if(CGNS_ENUMT(TRI_3) == type) // 三角形
{
-
- for (int iCnt = 0; iCnt < ncell; ++iCnt)
- {
- vtkSmartPointer idlist = vtkSmartPointer