perf(numerical): 降低复用网格求解的内存峰值

- 复用缓存网格时直接将 DLL 输出复制到任务结果,移除中间局部副本
- 将 DLL 网格输出峰值由三套降低为两套
- 直接使用 GRID 构造模型输入,避免临时模型输入产生的完整网格复制
feature/grid-solver-workflow-20260827
lh 2 weeks ago
parent 98a63a9ee3
commit 69895a6717

@ -286,11 +286,10 @@ bool applyPropertyInterpolation(
} }
/** /**
* @brief * @brief
*/ */
bool buildModelInputFromSnapshot( bool buildModelInputFromSnapshot(
const nmPebiSolverInputSnapshot& oSnapshot, const nmPebiSolverInputSnapshot& oSnapshot,
const HX_NWTM_GRID_OUTPUT2& oGridOutput,
HX_NWTM_MODEL_INPUT& oModelInput, HX_NWTM_MODEL_INPUT& oModelInput,
QString& sErrorMessage, QString& sErrorMessage,
const QAtomicInt* pCancelRequested) const QAtomicInt* pCancelRequested)
@ -300,10 +299,6 @@ bool buildModelInputFromSnapshot(
if(isTaskCancellationRequested(pCancelRequested)) { if(isTaskCancellationRequested(pCancelRequested)) {
return false; return false;
} }
oModelInput = HX_NWTM_MODEL_INPUT(oGridOutput);
if(isTaskCancellationRequested(pCancelRequested)) {
return false;
}
// 第一步:恢复井槽位、产量制度和井筒参数。场景与网格快照在同一次捕获中 // 第一步:恢复井槽位、产量制度和井筒参数。场景与网格快照在同一次捕获中
// 生成,因此这些外层数组天然使用同一个 DLL 下标顺序。 // 生成,因此这些外层数组天然使用同一个 DLL 下标顺序。
@ -356,7 +351,7 @@ bool buildModelInputFromSnapshot(
oModelInput.Base.dt_Min = oScene.Base.dt_Min; oModelInput.Base.dt_Min = oScene.Base.dt_Min;
oModelInput.Base.dt_Max = oScene.Base.dt_Max; oModelInput.Base.dt_Max = oScene.Base.dt_Max;
const size_t nCellCount = oGridOutput.Trinodexy.size(); const size_t nCellCount = oModelInput.GRID.Trinodexy.size();
oModelInput.Base.k = dVec1(nCellCount, oScene.Base.k_ref); oModelInput.Base.k = dVec1(nCellCount, oScene.Base.k_ref);
oModelInput.Base.phi = dVec1(nCellCount, oScene.Base.phi_ref); oModelInput.Base.phi = dVec1(nCellCount, oScene.Base.phi_ref);
oModelInput.Base.h = dVec1(nCellCount, oScene.Base.h_ref); oModelInput.Base.h = dVec1(nCellCount, oScene.Base.h_ref);
@ -854,21 +849,16 @@ bool nmCalculationDllPebiSolverTask::prepareManualInput()
reportStage(tr("Checking grid cache..."), 0, 0); reportStage(tr("Checking grid cache..."), 0, 0);
if(m_pInputSnapshot->m_bMayUseCachedGrid) { if(m_pInputSnapshot->m_bMayUseCachedGrid) {
HX_NWTM_GRID_OUTPUT1 oGridOutput1; nmPebiGridResult& oGridResult =
HX_NWTM_GRID_OUTPUT2 oGridOutput2; m_pInputSnapshot->m_oGridResult;
int nPebiCount = -1; // 缓存直接复制到任务快照,避免大网格在局部对象中产生额外副本。
if(pGridService->copyCurrentGridFor( if(pGridService->copyCurrentGridFor(
m_pDataManager, m_pDataManager,
m_nGridInputRevision, m_nGridInputRevision,
oGridOutput1, oGridResult.m_oGridOutput1,
oGridOutput2, oGridResult.m_oGridOutput2,
nPebiCount, oGridResult.m_nPebiCount,
&m_nCancelRequested)) { &m_nCancelRequested)) {
nmPebiGridResult& oGridResult =
m_pInputSnapshot->m_oGridResult;
oGridResult.m_oGridOutput1 = oGridOutput1;
oGridResult.m_oGridOutput2 = oGridOutput2;
oGridResult.m_nPebiCount = nPebiCount;
oGridResult.m_bSucceeded = true; oGridResult.m_bSucceeded = true;
reportStage(tr("Preparing result grid..."), 0, 0); reportStage(tr("Preparing result grid..."), 0, 0);
@ -1002,11 +992,11 @@ bool nmCalculationDllPebiSolverTask::execPebiMode()
// 第三步:由场景值快照重建完整模型输入。属性插值可以耗时,但它只读取任务 // 第三步:由场景值快照重建完整模型输入。属性插值可以耗时,但它只读取任务
// 自己的点集副本,因此放在工作线程不会阻塞或竞争界面数据。 // 自己的点集副本,因此放在工作线程不会阻塞或竞争界面数据。
HX_NWTM_MODEL_INPUT oModelInput; // 直接初始化可避免先构造临时模型输入、再复制完整 GRID 的额外内存峰值。
HX_NWTM_MODEL_INPUT oModelInput(oGridResult.m_oGridOutput2);
QString sInterpolationError; QString sInterpolationError;
reportStage(tr("Preparing model input..."), 0, 0); reportStage(tr("Preparing model input..."), 0, 0);
if(!buildModelInputFromSnapshot(*m_pInputSnapshot, if(!buildModelInputFromSnapshot(*m_pInputSnapshot,
oGridResult.m_oGridOutput2,
oModelInput, oModelInput,
sInterpolationError, sInterpolationError,
pCancelRequested)) { pCancelRequested)) {

Loading…
Cancel
Save