225 lines
5.4 KiB
C++
225 lines
5.4 KiB
C++
#ifndef ELEMENTANALYSIS_H
|
|
#define ELEMENTANALYSIS_H
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <sstream>
|
|
#include "qobject.h"
|
|
#include "algorithmanalysis.h"
|
|
#include <iomanip>
|
|
|
|
using namespace std;
|
|
|
|
// 定义峰值结构体
|
|
struct Peak {
|
|
int index;
|
|
double intensity;
|
|
double wavelength;
|
|
string name;
|
|
};
|
|
|
|
struct WaveSpectrum {
|
|
double intensity;
|
|
double wavelength;
|
|
|
|
};
|
|
|
|
//定义元素条数结构体
|
|
struct TTname{
|
|
// 元素名称
|
|
string Telementname;
|
|
int lines = 0;
|
|
};
|
|
|
|
|
|
//定义元素、强度结构体
|
|
//struct ElementPeak {
|
|
// string elementName;
|
|
// double intensity;
|
|
//};
|
|
|
|
// 定义数据点结构体
|
|
struct DataPoint {
|
|
double concentration;
|
|
double intensity;
|
|
};
|
|
|
|
// 定义拟合参数结构体
|
|
struct FitParameters {
|
|
double slope;
|
|
double intercept;
|
|
};
|
|
|
|
// 定义元素含量结构体
|
|
struct SpectrumElementQuantity {
|
|
string name;
|
|
double quantity;
|
|
double percent;// CFLibs计算的百分比
|
|
|
|
};
|
|
|
|
|
|
// 光谱数据
|
|
struct SpecData{
|
|
// 元素名称
|
|
string eleName;
|
|
// 波长
|
|
double waveLength = 0;
|
|
// 强度
|
|
double intensity = 0;
|
|
// 跃升能级
|
|
double transpro;
|
|
// 上能级
|
|
double upplevel;
|
|
// 权重
|
|
double statis;
|
|
// 0=原子,1=离子
|
|
bool ionization;
|
|
|
|
bool operator==(const SpecData& other) const {
|
|
return eleName == other.eleName; // 按照name字段进行去重
|
|
}
|
|
|
|
|
|
|
|
};
|
|
// 元素数据
|
|
struct ElementData{
|
|
// 元素名称
|
|
string eleName;
|
|
// 原子数量
|
|
int atomNum = 0;
|
|
// 离子数量
|
|
int ionNum = 0;
|
|
|
|
// cs原子数量
|
|
int atomNumCS = 0;
|
|
// cs离子数量
|
|
int ionNumCS = 0;
|
|
|
|
// 原子截距
|
|
double bsa = 0;
|
|
// 离子截距
|
|
double bsi = 0;
|
|
|
|
|
|
// 原子的cs
|
|
double csa = 0;
|
|
|
|
// 离子的cs
|
|
double csi = 0;
|
|
|
|
double csit = 0;
|
|
|
|
// 含量比例:未乘以100
|
|
double abundence = 0.0;
|
|
|
|
|
|
};
|
|
// 波长修正数据
|
|
struct FixData{
|
|
double wavelength;
|
|
double fix;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ElementAnalysis : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
ElementAnalysis(QObject *parent = nullptr);
|
|
vector<SpectrumElementQuantity> analysisElementQuantity(vector<pair<int,vector<SpectrumChannelData>>>);
|
|
|
|
|
|
private:
|
|
|
|
//最小二乘法拟合所需要的斜率和截距
|
|
FitParameters fitCurve(string elementName);
|
|
|
|
|
|
// 分割字符串为数组
|
|
vector<string> split(string str, char del);
|
|
|
|
// 2 输入 比对库:200行,7列,输出 到比对库的数据
|
|
vector<SpecData> findCompareLst(string compareFileName);
|
|
|
|
// 3 输入 1中波长和2中波长,输出 差值小于0.02的波长(2中的波长值), 1中的强度,2中的其他字段
|
|
vector<SpecData> doCompare(vector<SpectrumChannelData> peakLst,vector<SpecData> &compareLst,double distance);
|
|
|
|
// 4 输入 3中的差值比较后的光谱数据,修正数据库,输出 修正后的强度
|
|
void fixIntensity(vector<SpecData> &comparedLst,vector<FixData> fixLst, double baseline);
|
|
|
|
// 5 输入 3中fixedLst为修正完的元素数据,casee=计算方式,输出 用函数计算后的温度/密度
|
|
void calculateElementTempne(vector<SpecData> fixedLst,string Telement,int casee,int count7);
|
|
|
|
//获取平均温度和电离子密度
|
|
void getTTMM(vector<TTname> Telementname,vector<SpecData> comparedLst);
|
|
|
|
// 6 输入 温度/密度/强度/元素种类 输出用函数计算后的含量
|
|
void calculateConcentration(vector<SpecData> &tempneLst,vector<ElementData> &elementLst);
|
|
|
|
// 根据截距计算元素含量
|
|
double calculateConcentrationByIntercept(double inten,double transpro,double upplevel,double statis,double temprature);
|
|
|
|
// 根据CS计算元素含量
|
|
double calculateConcentrationByCS(string element,double temprature,int ionization,double electroD,double bs);
|
|
|
|
// 计算U
|
|
double calculateU(string element, double temprature, int ionization);
|
|
|
|
// 计算saha
|
|
double saha(string element,double temprature,double electroD,double csa);
|
|
|
|
// 从光谱数据中获取到元素名称集合
|
|
vector<ElementData> getElementLst(vector<SpecData> peakLst);
|
|
|
|
//获取元素的离子和原子条数
|
|
vector<TTname> GetTTname(vector<ElementData> elementLst,vector<SpecData> comparedLst);
|
|
|
|
// 获取修正数据
|
|
vector<FixData> getFixLst(int gratingNo);
|
|
|
|
//用曲线拟合计算元素ppm
|
|
vector<SpectrumElementQuantity> calculateElementConcentrationByStandardCurve(vector<SpectrumElementPeak> peakLst);
|
|
|
|
//计算元素含量百分比
|
|
vector<SpectrumElementQuantity> calculateElementConcentrationByCFLibs(vector<SpectrumChannelData> spectVector);
|
|
|
|
static vector<pair<int,vector<SpectrumChannelData>>> channelData;
|
|
|
|
// 温度
|
|
double temprature = 0;
|
|
// 密度
|
|
double electroD = 0;
|
|
|
|
//删除重叠区域的峰值
|
|
vector<SpectrumChannelData> selectWavelength(vector<pair<int, vector<SpectrumChannelData>>> peakVector, int inSpacing);
|
|
|
|
|
|
//vector<double> background(vector<double> waveLst,vector<double> averageSpecLst);
|
|
|
|
|
|
|
|
bool isCompletedCalculateByCFLibs = false;
|
|
bool isCompletedCalculateByStandardCurve = false;
|
|
|
|
std::string createErrorMessage(int errorCode, const std::string& message);
|
|
|
|
|
|
|
|
void save(vector<SpectrumChannelData> peakVector);
|
|
|
|
void saveSpecData(vector<SpecData> comparedLst);
|
|
|
|
void saveTTname(vector<TTname> Telementname);
|
|
|
|
void saveElementLst(vector<ElementData> elementLst);
|
|
};
|
|
|
|
#endif // ELEMENTANALYSIS_H
|