You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/nmNum/nmCalculation/nmCalculationPebiGrid.h

151 lines
6.8 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef NMCALCULATIONPEBIGRID_H
#define NMCALCULATIONPEBIGRID_H
#include "nmCalculation_global.h"
#include <QVector>
#include <QPointF>
#include <QString>
#include "pch.h"
#include "nmDataBinaryTools.h"
#include "nmDataNumericalAnalysisCase.h"
#include <vtkUnstructuredGrid.h>
#include <vtkSmartPointer.h>
class nmDataAnalyzeManager;
/**
* @brief 一次 PEBI 网格任务使用的不可变输入快照。
*
* 该结构只保存值类型,不持有 DataManager、QObject 或井对象指针。主线程在
* 启动任务前完整填充,后台线程随后只读取本结构,从而避免与 Map 编辑并发访问。
*/
struct nmPebiGridInputSnapshot
{
/** @brief 创建空快照m_bValid 为 false不能直接提交给网格 DLL。 */
nmPebiGridInputSnapshot()
: m_nGridInputRevision(0),
m_bValid(false)
{
}
HX_NWTM_GRID_INPUT m_oGridInput; ///< 边界、井、断层和裂缝等 DLL 输入。
nmDataBinaryTools::NM_PEBI_SCENE m_oScene; ///< 与本次网格输入一致的 ML 场景数据。
QVector<nmSolverWellRef> m_vecSolverWellOrder; ///< DLL 数组槽位对应的稳定井编码顺序。
QString m_sLicensePath; ///< 网格 DLL 授权文件路径副本。
quint64 m_nGridInputRevision; ///< 捕获时的几何输入版本。
bool m_bValid; ///< 主线程是否已完成全部输入校验。
};
/**
* @brief 后台 PEBI 计算产生、尚未写回分析成果的局部结果。
*/
struct nmPebiGridResult
{
/** @brief 创建空结果;只有 m_bSucceeded 为 true 时才允许提交。 */
nmPebiGridResult()
: m_pUnstructuredGrid(nullptr),
m_nPebiCount(-1),
m_bSucceeded(false)
{
}
HX_NWTM_GRID_OUTPUT1 m_oGridOutput1; ///< 网格 DLL 主输出。
HX_NWTM_GRID_OUTPUT2 m_oGridOutput2; ///< 网格 DLL 辅助输出。
vtkSmartPointer<vtkUnstructuredGrid> m_pUnstructuredGrid; ///< 局部构造的 VTK 网格。
int m_nPebiCount; ///< DLL 返回的 PEBI 单元数量。
bool m_bSucceeded; ///< DLL 和 VTK 转换是否全部成功。
};
class NMCALCULATION_EXPORT nmCalculationPebiGrid
{
public:
/** @brief 返回进程内唯一的 PEBI 网格服务实例。 */
static nmCalculationPebiGrid* getInstance();
nmCalculationPebiGrid();
~nmCalculationPebiGrid();
/** @brief 在调用线程从 DataManager 复制一份完整且不含指针的网格输入。 */
bool captureInputSnapshot(nmDataAnalyzeManager* pDataManager,
nmPebiGridInputSnapshot& oSnapshot);
/** @brief 仅使用值快照调用网格 DLL并把输出保存在局部结果中。 */
bool calculateSnapshot(const nmPebiGridInputSnapshot& oSnapshot,
nmPebiGridResult& oResult,
bool bCreateUnstructuredGrid = true);
/** @brief 在主线程校验输入版本,并一次性提交井顺序、网格和单例缓存。 */
bool commitSnapshotResult(nmDataAnalyzeManager* pDataManager,
const nmPebiGridInputSnapshot& oSnapshot,
const nmPebiGridResult& oResult);
/** @brief 设置 PEBI 网格控制值,并同步到指定分析方案。 */
void setGridControl(double dGridControl,
nmDataAnalyzeManager* pDataManager = nullptr);
/** @brief 仅在缓存属于指定管理器时清理;空参数强制清理当前缓存。 */
void clearGridData(const nmDataAnalyzeManager* pDataManager = nullptr);
private:
/** @brief 从绑定数据管理器构造边界输入。 */
bool meshGenPebiBoundary(nmDataAnalyzeManager* pDataManager,
HX_NWTM_GRID_INPUT& inputObj);
/** @brief 按有效计算井集合构造井几何并记录 DLL 井顺序。 */
bool meshGenPebiWells(nmDataAnalyzeManager* pDataManager,
HX_NWTM_GRID_INPUT& inputObj,
QVector<nmSolverWellRef>& vecSolverWellOrder);
/** @brief 从 Map 构造断层输入。 */
bool meshGenPebiFault(nmDataAnalyzeManager* pDataManager,
HX_NWTM_GRID_INPUT& inputObj);
/** @brief 从 Map 构造手工裂缝输入和求解器占位条目。 */
bool meshGenPebiCrack(nmDataAnalyzeManager* pDataManager,
HX_NWTM_GRID_INPUT& inputObj,
QVector<nmSolverWellRef>& vecSolverWellOrder);
/** @brief 从主线程数据构造与网格输入一致的 ML 场景值快照。 */
bool buildPebiScene(nmDataAnalyzeManager* pDataManager,
const HX_NWTM_GRID_INPUT& oGridInput,
const QVector<nmSolverWellRef>& vecSolverWellOrder,
nmDataBinaryTools::NM_PEBI_SCENE& oScene);
/** @brief 更新单例中的 DLL 输入输出缓存,不改变网格有效版本。 */
void commitOutputCache(nmDataAnalyzeManager* pDataManager,
const nmPebiGridInputSnapshot& oSnapshot,
const nmPebiGridResult& oResult);
// 生成vtk数据
void genPebiVTK(const HX_NWTM_GRID_OUTPUT1& P1, QString vtkDir);
// 根据网格输出结构体创建 vtkUnstructuredGrid 对象
vtkSmartPointer<vtkUnstructuredGrid> createPebiUnstructuredGrid(const HX_NWTM_GRID_OUTPUT1& P1);
// 日志输出
void logCurrentState();
void logInputParameters(const HX_NWTM_GRID_INPUT& input);
public:
/** @brief 非阻塞复制当前有效网格DLL忙碌或缓存不匹配时返回 false。 */
bool copyCurrentGridFor(const nmDataAnalyzeManager* pDataManager,
HX_NWTM_GRID_OUTPUT1& oGridOutput1,
HX_NWTM_GRID_OUTPUT2& oGridOutput2,
int& nPebiCount) const;
public:
/** @brief 在线程锁保护下返回最近一次网格输出 p1 的副本。 */
HX_NWTM_GRID_OUTPUT1 getGridOutput1();
/** @brief 在线程锁保护下返回最近一次网格输出 p2 的副本。 */
HX_NWTM_GRID_OUTPUT2 getGridOutput2();
/** @brief 返回最近一次网格划分生成的 PEBI 单元数量。 */
int getPebiCount() const;
private:
static nmCalculationPebiGrid* m_instance; ///< 进程内共享的 PEBI 网格服务实例。
HX_NWTM_GRID_INPUT p0; ///< 最近一次提交给网格 DLL 的输入快照。
HX_NWTM_GRID_OUTPUT1 p1; ///< 最近一次网格 DLL 主输出。
HX_NWTM_GRID_OUTPUT2 p2; ///< 最近一次网格 DLL 辅助输出。
double m_dGridControl; ///< 对应 HX_NWTM_GRID_INPUT::GridControl。
int m_nPebiCount; ///< 最近一次成功网格的单元数量,未生成时为 -1。
quint64 m_nCachedGridInputRevision; ///< 单例 DLL 输出对应的网格输入版本。
/** @brief 当前单例缓存所属的数据管理器,不拥有对象。 */
nmDataAnalyzeManager* m_pDataManager;
};
#endif // NMCALCULATIONPEBIGRID_H