|
|
|
|
|
#ifndef NMCALCULATIONAUTOFITLM_H
|
|
|
|
|
|
#define NMCALCULATIONAUTOFITLM_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "nmCalculation_global.h"
|
|
|
|
|
|
#include "nmDataAutomaticFitting.h"
|
|
|
|
|
|
#include "nmFitLM.h"
|
|
|
|
|
|
#include "nmFitPlatformParameters.h"
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief 软件拟合入口:读取项目配置、调用真实求解器并提交正式成果。 */
|
|
|
|
|
|
class NMCALCULATION_EXPORT nmCalculationAutoFitLM : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit nmCalculationAutoFitLM(QObject* parent = nullptr);
|
|
|
|
|
|
virtual ~nmCalculationAutoFitLM();
|
|
|
|
|
|
/** @brief 调用独立算法,再按原软件流程提交正式成果。 */
|
|
|
|
|
|
bool startAutoFitting();
|
|
|
|
|
|
bool startSensitivityFitting(const nmSensitivityFitSettings& settings,
|
|
|
|
|
|
const std::function<QVector<QVector<double>>(const QVector<double>&)>& evaluate,
|
|
|
|
|
|
const std::function<bool()>& cancelled, bool verticalWell);
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief 设置目标曲线及查询运行结果,保持原界面调用方式。 */
|
|
|
|
|
|
void setTargetLogLogData(const QVector<QVector<double>>& data);
|
|
|
|
|
|
bool isRunning() const;
|
|
|
|
|
|
int getCurrentIteration() const;
|
|
|
|
|
|
int getTotalEvaluations() const;
|
|
|
|
|
|
QVector<double> getBestSolution() const;
|
|
|
|
|
|
double getBestFitness() const;
|
|
|
|
|
|
QString getLastError() const;
|
|
|
|
|
|
void resetOptimizer();
|
|
|
|
|
|
void setTargetWellName(const QString& name);
|
|
|
|
|
|
void stopFitting();
|
|
|
|
|
|
int getSolverCallCount() const;
|
|
|
|
|
|
AutoFitObjectiveBreakdownLM getLastObjectiveBreakdown() const;
|
|
|
|
|
|
signals:
|
|
|
|
|
|
void progressUpdated(int iteration, double bestFitness);
|
|
|
|
|
|
void fittingFinished(bool success, const QString& message);
|
|
|
|
|
|
void bestCurveUpdated(QVector<QVector<double>> targetData, QVector<QVector<double>> bestData, int iteration,
|
|
|
|
|
|
double fitness);
|
|
|
|
|
|
void finalizingStarted();
|
|
|
|
|
|
void logMessageGenerated(const QString& message);
|
|
|
|
|
|
void fittingStageChanged(int stage);
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
void initializeTraceFile();
|
|
|
|
|
|
void writeTraceRow(int iteration, int parameterIndex, const QString& phase, const QVector<double>& parameters,
|
|
|
|
|
|
double solverObjective, bool solverSuccess, int elapsedMs, const QString& decision,
|
|
|
|
|
|
const AutoFitObjectiveBreakdownLM* objectiveBreakdown = nullptr);
|
|
|
|
|
|
void writeTraceMetaFile();
|
|
|
|
|
|
void recordSolverCall();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
// 项目读写、求解与成果提交只在软件入口中实现。
|
|
|
|
|
|
void syncAlgorithmProgress();
|
|
|
|
|
|
int getEnabledParameterCount() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_enabledParamIndices.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
bool initializeTemporaryDirectory();
|
|
|
|
|
|
void cleanupTemporaryDirectory();
|
|
|
|
|
|
void closeTraceFile();
|
|
|
|
|
|
void writeTraceHeader();
|
|
|
|
|
|
void emitRunSummary(bool success, StopReasonLM finalReason);
|
|
|
|
|
|
QVector<double> buildTraceParameterVector(const QVector<double>& selectedParameters) const;
|
|
|
|
|
|
bool loadConfiguration();
|
|
|
|
|
|
void loadOptimizationConfig();
|
|
|
|
|
|
void loadParameterBounds();
|
|
|
|
|
|
nmFitCurve evaluateCurve(const QVector<double>& parameters, bool retrySolver);
|
|
|
|
|
|
void applyParametersToDataManager(const QVector<double>& parameters);
|
|
|
|
|
|
QVector<QVector<double>> runSolverDll();
|
|
|
|
|
|
bool runFinalFullSolver();
|
|
|
|
|
|
void pollEvents();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
nmFitLM* m_engine; ///< 独立算法对象,通过 fit 接口调用。
|
|
|
|
|
|
bool m_isRunning;
|
|
|
|
|
|
QAtomicInt m_shouldStop;
|
|
|
|
|
|
bool m_isFinalizing;
|
|
|
|
|
|
int m_currentIteration;
|
|
|
|
|
|
QString m_lastError;
|
|
|
|
|
|
QVector<double> m_initialValues;
|
|
|
|
|
|
QVector<double> m_globalBestPosition;
|
|
|
|
|
|
double m_globalBestFitness;
|
|
|
|
|
|
nmFitCurve m_lastEvaluatedLogLogData;
|
|
|
|
|
|
QVector<nmFitParameterValue> m_modelParameters;
|
|
|
|
|
|
QVector<bool> m_parameterSelected;
|
|
|
|
|
|
QVector<double> m_parameterLower;
|
|
|
|
|
|
QVector<double> m_parameterUpper;
|
|
|
|
|
|
QVector<int> m_enabledParamIndices;
|
|
|
|
|
|
nmFitCurve m_targetLogLogData;
|
|
|
|
|
|
QString m_targetWellName;
|
|
|
|
|
|
int m_maxIterations;
|
|
|
|
|
|
double m_targetError;
|
|
|
|
|
|
int m_totalEvaluations;
|
|
|
|
|
|
int m_successfulEvaluations;
|
|
|
|
|
|
int m_evaluationInProgress;
|
|
|
|
|
|
double m_userInitialFitness;
|
|
|
|
|
|
QString m_tempDirectory;
|
|
|
|
|
|
QString m_traceRunId;
|
|
|
|
|
|
QString m_traceFilePath;
|
|
|
|
|
|
QString m_traceMetaFilePath;
|
|
|
|
|
|
QFile m_traceFile;
|
|
|
|
|
|
QAtomicInt m_solverCallCount;
|
|
|
|
|
|
bool m_skipShapeStage;
|
|
|
|
|
|
|
|
|
|
|
|
const nmSensitivityFitSettings* m_sensitivitySettings;
|
|
|
|
|
|
bool m_sensitivityVerticalWell;
|
|
|
|
|
|
std::function<QVector<QVector<double>>(const QVector<double>&)> m_sensitivityEvaluate;
|
|
|
|
|
|
std::function<bool()> m_sensitivityCancelled;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // NMCALCULATIONAUTOFITLM_H
|