gtbaseparamanalysize.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Created by lloyd on 2020/9/28.
  3. //
  4. #include <iostream>
  5. #include <math.h>
  6. #include "gtbaseparamanalysize.h"
  7. #include "gtrunconf.h"
  8. #include "gtcommonkits.h"
  9. #include "vector"
  10. #include "DataMapping/dgns_gtbaseparam.h"
  11. void gtbaseparamanalysize::analysisParam(dgns_gtbaseparam *_baseparam ) {
  12. if (!_baseparam->sgt.empty() && _baseparam->n > 0 && _baseparam->sgtpointnum > gtPointsNumConditionlimit) {
  13. _baseparam->l_max = -1000;
  14. _baseparam->l_min = 1000;
  15. _baseparam->s_max = -1000;
  16. _baseparam->s_min = 1000;
  17. _baseparam->area = 0;
  18. _baseparam->upload=0;
  19. _baseparam->download=0;
  20. // pointNum = _baseparam->sgtpointnum;
  21. int i = 0;
  22. double s_xlmax = 0;
  23. double s_xlmin = 0;
  24. double xl_downloadmax = 0;
  25. double xl_downloadmin = 0;
  26. // gtdataContent.clear();
  27. for (i = 0; i < _baseparam->sgtpointnum; i++) {
  28. /*std::vector<double> iputx;
  29. iputx.push_back(_baseparam->sgt[i][0]);
  30. iputx.push_back(_baseparam->sgt[i][1]);
  31. gtdataContent.push_back(iputx);*/
  32. if (_baseparam->sgt[i][0] > _baseparam->s_max) {
  33. _baseparam->s_max = _baseparam->sgt[i][0];
  34. _baseparam->s_max_point_location=i;
  35. }
  36. if (_baseparam->sgt[i][1] > _baseparam->l_max) {
  37. _baseparam->l_max = _baseparam->sgt[i][1];
  38. _baseparam->l_max_point_location = i;
  39. }
  40. if (_baseparam->sgt[i][0] < _baseparam->s_min) {
  41. _baseparam->s_min = _baseparam->sgt[i][0];
  42. _baseparam->s_min_point_location = i;
  43. }
  44. if (_baseparam->sgt[i][1] < _baseparam->l_min) {
  45. _baseparam->l_min = _baseparam->sgt[i][1];
  46. _baseparam->l_min_point_location = i;
  47. }
  48. //上下行对半分
  49. if (i < _baseparam->sgtpointnum / 2 - 1) {
  50. double h = std::abs(_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0]);
  51. double Si = (_baseparam->sgt[i][1] + _baseparam->sgt[i + 1][1]) * h / 2.0;
  52. _baseparam->area = _baseparam->area + Si;
  53. }
  54. if (i < _baseparam->sgtpointnum - 1) {
  55. double h = std::abs(_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0]);
  56. double Si = (_baseparam->sgt[i][1] + _baseparam->sgt[i + 1][1]) * h / 2.0;
  57. _baseparam->area = _baseparam->area - Si;
  58. }
  59. //---
  60. // 根据功图获取有效冲程
  61. // 算法:取下半段功图的斜率最大值跟最小值对应的点的冲程差
  62. if (i >= _baseparam->sgtpointnum / 2 - 1 && i < _baseparam->sgtpointnum - 1) {
  63. double xl = std::abs(
  64. (_baseparam->sgt[i][1] - _baseparam->sgt[i + 1][1]) / (_baseparam->sgt[i][0] - _baseparam->sgt[i + 1][0] + 0.000001));//这里取的是个固定值,可能会有问题
  65. if (i == _baseparam->sgtpointnum / 2 - 1) {
  66. s_xlmin = _baseparam->sgt[i][0];
  67. s_xlmax = _baseparam->sgt[i][0];
  68. xl_downloadmin = xl;
  69. xl_downloadmax = xl;
  70. } else {
  71. if (xl < xl_downloadmin) {
  72. xl_downloadmin = xl;
  73. s_xlmin = _baseparam->sgt[i][0];
  74. }
  75. if (xl > xl_downloadmax) {
  76. xl_downloadmax = xl;
  77. s_xlmax = _baseparam->sgt[i][0];
  78. }
  79. }
  80. }
  81. //----
  82. }
  83. _baseparam-> s_effect = std::abs(s_xlmax - s_xlmin);
  84. _baseparam->s = _baseparam->s_max - _baseparam->s_min;
  85. //N = _baseparam->n;
  86. _baseparam->l = _baseparam->l_max - _baseparam->l_min;
  87. _baseparam ->l_mid = (_baseparam->l_max + _baseparam->l_min) / 2.0;
  88. _baseparam->islegal = 1;
  89. try {
  90. _baseparam->l_fistdownturnpoint = getFirstTurningPoint2(_baseparam->sgt, _baseparam->sgtpointnum);
  91. } catch (const std::exception &e) {
  92. _baseparam->l_fistdownturnpoint=baseparam_l_fistdownturnpoint_default;
  93. std::cerr<<"l_fistdownturnpoint cal ERROR:" << e.what() << std::endl;
  94. }
  95. } else {
  96. _baseparam->islegal = 0;
  97. }
  98. checkGTLegality(_baseparam);
  99. }
  100. void gtbaseparamanalysize::checkGTLegality(dgns_gtbaseparam *_baseparam) {
  101. if (_baseparam->islegal >= 0) {
  102. if (_baseparam->s > 0 && _baseparam->n > 0 && _baseparam->l > 0) _baseparam->islegal = 1;
  103. else _baseparam->islegal = 0;
  104. //TODO:完善更多的功图合法性校验内容
  105. //if(xxxx)
  106. }
  107. }
  108. /**
  109. *
  110. * @param gt 计算功图第一拐点载荷判断 供液不足间歇出液
  111. * @param gt_pointNum
  112. * @return
  113. */
  114. double gtbaseparamanalysize::getFirstTurningPoint2(std::vector<std::vector<double>>gt, int gt_pointNum) {
  115. int start = gt_pointNum / 2;
  116. double minL = gt[start][1];
  117. double maxL = gt[start][1];
  118. double mins = gt[start][0];
  119. double maxs = gt[start][0];
  120. std::vector<std::vector<double>> downwardsegment_gt;
  121. for (int i = start + 1; i < gt_pointNum; i++) {
  122. std::vector<double> item;
  123. item.push_back(gt[i][0]);
  124. item.push_back(gt[i][1]);
  125. downwardsegment_gt.push_back(item);
  126. if (gt[i][1] < minL) minL = gt[i][1];
  127. if (gt[i][1] > maxL) maxL = gt[i][1];
  128. if (gt[i][0] > maxs) maxs = gt[i][0];
  129. if (gt[i][0] < mins) mins = gt[i][0];
  130. }
  131. double Ldd = maxL - minL;
  132. double sdd = maxs - mins;
  133. int countT = (int) std::ceil(std::sqrt(std::pow(Ldd / 0.01, 2) + std::pow(sdd / 0.1, 2)));
  134. gtcommonkits cal;
  135. std::vector<std::vector<double>> gtBezierTemp = cal.BezierInterpolation(downwardsegment_gt, countT, 2);
  136. for (int i = 0; i < gtBezierTemp.size(); i++) {
  137. double zh = gtBezierTemp[i][1];
  138. double s = gtBezierTemp[i][0];
  139. for (int j = i + 1; j < gtBezierTemp.size(); j++) {
  140. if (gtBezierTemp[j][0] < s)
  141. if (std::abs(zh - gtBezierTemp[j][1]) < 0.1)
  142. if (std::abs(zh - gtBezierTemp[j][1]) < std::abs(s - gtBezierTemp[j][0]) * 0.1)
  143. return zh;
  144. }
  145. }
  146. return 0.0;
  147. }