perf(nmNum): 跳过 LM 形状阶段冻结参数的灵敏度试算

- 普通形状调整仅计算可调参数的灵敏度,跳过冻结的井储和表皮
- 保留井储表皮初调、回检及整体 LM 阶段的灵敏度重建逻辑
- 按当前子阶段所需参数列数显示重建结果,同步轨迹策略元数据和注释
feature/AutoFit-Optimize-20260914
lvjunjie 2 weeks ago
parent 08de98335a
commit 43b7c770ed

@ -1212,7 +1212,7 @@ void nmCalculationAutoFitLM::writeTraceMetaFile()
QTextStream out(&metaFile);
out << "{\n";
out << " \"schema_version\": 30,\n";
out << " \"schema_version\": 31,\n";
out << " \"strategy\": \"permeability_height_then_shape_then_joint_lm\",\n";
out << " \"height_acceptance\": \"reliable_vertical_loss_decrease; no_shape_or_total_loss_constraint\",\n";
out << " \"shape_priority\": \"storage_then_skin_then_shape_without_wellbore_then_optional_wellbore_recheck\",\n";
@ -1227,7 +1227,7 @@ void nmCalculationAutoFitLM::writeTraceMetaFile()
out << " \"early_wellbore_total_constraint\": false,\n";
out << " \"shape_stage_total_constraint\": false,\n";
out << " \"shape_wellbore_parameters_frozen\": true,\n";
out << " \"shape_sensitivity_refresh\": \"full Jacobian at joint shape entry and stagnation confirmation\",\n";
out << " \"shape_sensitivity_refresh\": \"non_wellbore_columns_only at joint shape entry and stagnation confirmation; full Jacobian rebuilt at total-stage entry\",\n";
out << " \"shape_expansion_policy\": \"one expansion per reliable shape direction, up to 2x when actual rho exceeds 0.75; retain ordinary step on failure\",\n";
out << " \"shape_global_parameter_selection\": \"all_valid_non_wellbore_columns_with_positive_response\",\n";
out << " \"stage2_budget\": \"adaptive, no fixed iteration or evaluation quota; full window/global rounds, 2 ineffective rounds then fresh-J confirmation\",\n";
@ -2038,7 +2038,7 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
StopReasonLM stopReason = LM_MAX_ITERATIONS;
// jacobian 的行对应当前采样层的残差,列对应用户勾选的参数。
// Fisher 按当前阶段取数值或形状残差行,完整 Jacobian 在阶段之间复用。
// Fisher 按当前阶段取数值或形状残差行;冻结列不参与形状差分,整体阶段重建全部列。
QVector<QVector<double> > jacobian;
QVector<bool> jacobianColumnValid(dimensions, false);
@ -2371,7 +2371,7 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
wellboreRecheck = false;
effectiveImprovementBaseline = current.fitness;
reuseSensitivityForNextStage();
// 初调、回检只测井储/表皮;所有出口都在当前点重建完整 J,不能把缺列模型带入整体 LM。
// 第二阶段只测各子阶段需要的列;所有出口都在当前点重建完整 J,不能把缺列模型带入整体 LM。
jacobian.clear();
rebuildRequested = true;
rebuildReason = QT_TR_NOOP("full sensitivity at total-stage entry");
@ -2562,6 +2562,8 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
auto rebuildSensitivity = [&]() -> bool {
// 第二阶段差分不受第三阶段额度限制;每列仍只有有限的缩步和反向重试。
const int evaluationLimit = shapeStage ? (std::numeric_limits<int>::max)() : maximumEvaluations;
const int sensitivityColumnCount = shapeStage
? (earlyShapeStage ? wellboreParameterCount : dimensions - wellboreParameterCount) : dimensions;
const TrustRegionEvaluation base = current;
const QVector<double> baseResidual = trustRegionFullResidual(base.breakdown);
const int residualCount = baseResidual.size();
@ -2589,6 +2591,8 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
++column) {
const int parameterIndex = m_enabledParamIndices[column];
if(earlyShapeStage && parameterIndex != 1 && parameterIndex != 2) continue;
// 普通形状阶段跳过冻结的井储、表皮,避免无用正演;回检和整体阶段会重新差分。
if(shapeStage && !earlyShapeStage && !parameterAllowedInStage(column)) continue;
const double lower = m_parameterLower[parameterIndex];
const double upper = m_parameterUpper[parameterIndex];
if(upper <= lower) continue;
@ -2676,7 +2680,7 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
jacobianColumnValid[column] = true;
columnBuilt = true;
// 其他参数仍建立灵敏度供后续复用,但不能绕过当前子阶段的选参限制。
// 前期同时测井储和表皮,但缓存探针不能绕过当前子阶段的选参限制。
// 前期首次正式调整必须从小步开始,测形状灵敏度的大探针不能提前成为工作点。
if((!earlyShapeStage || earlyShapeHasImproved) &&
parameterAllowedInStage(column) && acceptable(probe, base) &&
@ -2747,7 +2751,7 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
emit logMessageGenerated(
tr("Sensitivity model rebuilt: %1/%2 parameter columns valid")
.arg(validColumnCount)
.arg(dimensions));
.arg(sensitivityColumnCount));
return true;
};
@ -2768,7 +2772,7 @@ StopReasonLM nmCalculationAutoFitLM::runTrustRegionFitting()
if(shapeStage && !earlyShapeStage && !jointShapeStarted) {
jointShapeStarted = true;
shapeRoundBaseline = current.breakdown.shapeLoss;
// 初调已改变井储/表皮,普通形状必须在新的工作点测完整响应。
// 初调已改变井储/表皮,普通形状必须在新的工作点重测其余可调参数的响应。
jacobian.clear();
reuseSensitivityForNextStage();
rebuildRequested = true;

Loading…
Cancel
Save