123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // Created by lloyd on 2020/9/28.
- //
- #include <iostream>
- #include <math.h>
- #include "gtbaseparamanalysize.h"
- #include "gtrunconf.h"
- #include "gtcommonkits.h"
- #include "vector"
- #include "DataMapping/dgns_gtbaseparam.h"
- void gtbaseparamanalysize::analysisParam(dgns_gtbaseparam *_baseparam ) {
- if (!_baseparam->sgt.empty() && _baseparam->n > 0 && _baseparam->sgtpointnum > gtPointsNumConditionlimit) {
- _baseparam->l_max = -1000;
- _baseparam->l_min = 1000;
- _baseparam->s_max = -1000;
- _baseparam->s_min = 1000;
- _baseparam->area = 0;
- _baseparam->upload=0;
- _baseparam->download=0;
- // pointNum = _baseparam->sgtpointnum;
- int i = 0;
- double s_xlmax = 0;
- double s_xlmin = 0;
- double xl_downloadmax = 0;
- double xl_downloadmin = 0;
- // gtdataContent.clear();
- for (i = 0; i < _baseparam->sgtpointnum; i++) {
- /*std::vector<double> iputx;
- iputx.push_back(_baseparam->sgt[i][0]);
- iputx.push_back(_baseparam->sgt[i][1]);
- gtdataContent.push_back(iputx);*/
- if (_baseparam->sgt[i][0] > _baseparam->s_max) {
- _baseparam->s_max = _baseparam->sgt[i][0];
- _baseparam->s_max_point_location=i;
- }
- if (_baseparam->sgt[i][1] > _baseparam->l_max) {
- _baseparam->l_max = _baseparam->sgt[i][1];
- _baseparam->l_max_point_location = i;
- }
- if (_baseparam->sgt[i][0] < _baseparam->s_min) {
- _baseparam->s_min = _baseparam->sgt[i][0];
- _baseparam->s_min_point_location = i;
- }
- if (_baseparam->sgt[i][1] < _baseparam->l_min) {
- _baseparam->l_min = _baseparam->sgt[i][1];
- _baseparam->l_min_point_location = i;
- }
- //上下行对半分
- if (i < _baseparam->sgtpointnum / 2 - 1) {
- double h = std::abs(_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0]);
- double Si = (_baseparam->sgt[i][1] + _baseparam->sgt[i + 1][1]) * h / 2.0;
- _baseparam->area = _baseparam->area + Si;
- }
- if (i < _baseparam->sgtpointnum - 1) {
- double h = std::abs(_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0]);
- double Si = (_baseparam->sgt[i][1] + _baseparam->sgt[i + 1][1]) * h / 2.0;
- _baseparam->area = _baseparam->area - Si;
- }
- //---
- // 根据功图获取有效冲程
- // 算法:取下半段功图的斜率最大值跟最小值对应的点的冲程差
- if (i >= _baseparam->sgtpointnum / 2 - 1 && i < _baseparam->sgtpointnum - 1) {
- double xl = std::abs(
- (_baseparam->sgt[i][1] - _baseparam->sgt[i + 1][1]) / (_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0] + 0.000001));//这里取的是个固定值,可能会有问题
- if (i == _baseparam->sgtpointnum / 2 - 1) {
- s_xlmin = _baseparam->sgt[i][0];
- s_xlmax = _baseparam->sgt[i][0];
- xl_downloadmin = xl;
- xl_downloadmax = xl;
- } else {
- if (xl < xl_downloadmin) {
- xl_downloadmin = xl;
- s_xlmin = _baseparam->sgt[i][0];
- }
- if (xl > xl_downloadmax) {
- xl_downloadmax = xl;
- s_xlmax = _baseparam->sgt[i][0];
- }
- }
- }
- //----
- }
- _baseparam-> s_effect = std::abs(s_xlmax - s_xlmin);
- _baseparam->s = _baseparam->s_max - _baseparam->s_min;
- //N = _baseparam->n;
- _baseparam->l = _baseparam->l_max - _baseparam->l_min;
- _baseparam ->l_mid = (_baseparam->l_max + _baseparam->l_min) / 2.0;
- _baseparam->islegal = 1;
- try {
- _baseparam->l_fistdownturnpoint = getFirstTurningPoint2(_baseparam->sgt, _baseparam->sgtpointnum);
- } catch (const std::exception &e) {
- _baseparam->l_fistdownturnpoint=baseparam_l_fistdownturnpoint_default;
- std::cerr<<"l_fistdownturnpoint cal ERROR:" << e.what() << std::endl;
- }
- } else {
- _baseparam->islegal = 0;
- }
- checkGTLegality(_baseparam);
- }
- void gtbaseparamanalysize::checkGTLegality(dgns_gtbaseparam *_baseparam) {
- if (_baseparam->islegal >= 0) {
- if (_baseparam->s > 0 && _baseparam->n > 0 && _baseparam->l > 0) _baseparam->islegal = 1;
- else _baseparam->islegal = 0;
- //TODO:完善更多的功图合法性校验内容
- //if(xxxx)
- }
- }
- /**
- *
- * @param gt 计算功图第一拐点载荷判断 供液不足间歇出液
- * @param gt_pointNum
- * @return
- */
- double gtbaseparamanalysize::getFirstTurningPoint2(std::vector<std::vector<double>>gt, int gt_pointNum) {
- int start = gt_pointNum / 2;
- double minL = gt[start][1];
- double maxL = gt[start][1];
- double mins = gt[start][0];
- double maxs = gt[start][0];
- std::vector<std::vector<double>> downwardsegment_gt;
- for (int i = start + 1; i < gt_pointNum; i++) {
- std::vector<double> item;
- item.push_back(gt[i][0]);
- item.push_back(gt[i][1]);
- downwardsegment_gt.push_back(item);
- if (gt[i][1] < minL) minL = gt[i][1];
- if (gt[i][1] > maxL) maxL = gt[i][1];
- if (gt[i][0] > maxs) maxs = gt[i][0];
- if (gt[i][0] < mins) mins = gt[i][0];
- }
- double Ldd = maxL - minL;
- double sdd = maxs - mins;
- int countT = (int) std::ceil(std::sqrt(std::pow(Ldd / 0.01, 2) + std::pow(sdd / 0.1, 2)));
- gtcommonkits cal;
- std::vector<std::vector<double>> gtBezierTemp = cal.BezierInterpolation(downwardsegment_gt, countT, 2);
- for (int i = 0; i < gtBezierTemp.size(); i++) {
- double zh = gtBezierTemp[i][1];
- double s = gtBezierTemp[i][0];
- for (int j = i + 1; j < gtBezierTemp.size(); j++) {
- if (gtBezierTemp[j][0] < s)
- if (std::abs(zh - gtBezierTemp[j][1]) < 0.1)
- if (std::abs(zh - gtBezierTemp[j][1]) < std::abs(s - gtBezierTemp[j][0]) * 0.1)
- return zh;
- }
- }
- return 0.0;
- }
|