RLV_test.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #include <iostream>
  2. #include <armadillo>
  3. #include <time.h>
  4. #include <stdio.h>
  5. #include <cstdio>
  6. #include <stdlib.h>
  7. #include "GPM.h"
  8. // 用户新增头文件
  9. #include "RLV.h"
  10. using namespace std;
  11. using namespace arma;
  12. int main(){
  13. // 计时器开始
  14. double dur;
  15. clock_t start, end;
  16. start = clock();
  17. ////////////////////////////////////参数初始化//////////////////////////////////////////////
  18. input0 input;
  19. output0* output;
  20. auxdata1 auxdata;
  21. // 伪谱法条件初始化
  22. Intput_Initial(&input);
  23. // 人为编辑定义部分
  24. auxdata.Sref = 0.4839;
  25. auxdata.M0 = 907;
  26. auxdata.C1_v = 2e-8; // 与热流密度相关参数
  27. auxdata.Rd_v = 0.006; // 与热流密度相关参数
  28. auxdata.n_v = 0.5; // 与热流密度相关参数
  29. auxdata.m_v = 3.15;
  30. auxdata.g = 9.80665;
  31. auxdata.Re = 6371110;
  32. input.setup.auxdata = auxdata;
  33. // 归一化单位向量
  34. double pi = datum::pi;
  35. double g = auxdata.g;
  36. double Re = auxdata.Re;
  37. double tc = sqrt(Re / g);
  38. double rc = Re;
  39. double vc = sqrt(Re*g);
  40. vec state_c; state_c << vc << 1.0 << 1.0 << rc << 1.0 << 1.0 << endr;
  41. // 范围赋值
  42. int length_state = 6;
  43. int length_control = 2;
  44. double initialtime_lower = 0;
  45. double initialtime_upper = 0;
  46. double finaltime_lower = 0;
  47. double finaltime_upper = 500.0 / tc;
  48. vec initialstate_lower; initialstate_lower << 6000.0 << 0.0 / 180.0 * pi << 50.0 / 180.0 * pi << 60.0 * 1e3 + Re << 0.0 / 180.0 * pi << 0.0 / 180.0 * pi << endr;
  49. vec initialstate_upper; initialstate_upper << 6000.0 << 0.0 / 180.0 * pi << 50.0 / 180.0 * pi << 60.0 * 1e3 + Re << 0.0 / 180.0 * pi << 0.0 / 180.0 * pi << endr;
  50. vec state_lower; state_lower << 5400.0 << -15.0 / 180.0 * pi << 35.0 / 180.0 * pi << 40.0 * 1e3 + Re << 0.0 / 180.0 * pi << 0.0 / 180.0 * pi << endr;
  51. vec state_upper; state_upper << 6000.0 << +15.0 / 180.0 * pi << 55.0 / 180.0 * pi << 60.0 * 1e3 + Re << 10.0 / 180.0 * pi << 12.0 / 180.0 * pi << endr;
  52. vec finalstate_lower; finalstate_lower << 5400.0 << -0.001 / 180.0 * pi << 35.0 / 180.0 * pi << 54.0 * 1e3 + Re << 8.0 / 180.0 * pi << 9.0 / 180.0 * pi << endr;
  53. vec finalstate_upper; finalstate_upper << 5600.0 << +0.001 / 180.0 * pi << 51.0 / 180.0 * pi << 56.0 * 1e3 + Re << 10.0 / 180.0 * pi << 11.0 / 180.0 * pi << endr;
  54. vec control_lower; control_lower << 0.0 / 180.0 * pi << -90.0 / 180.0 * pi << endr;
  55. vec control_upper; control_upper << 30.0 / 180.0 * pi << 90.0 / 180.0 * pi << endr;
  56. vec path_lower; path_lower << 0.0 << 0.0 << 0.0 << endr;
  57. vec path_upper; path_upper << 3.0 << 100.0 * 1e3 << 1500.0 * 1e3 << endr;
  58. rowvec integral_lower; integral_lower << -10.0 << endr;
  59. rowvec integral_upper; integral_upper << 10.0 << endr;
  60. input.setup.state_length = length_state;
  61. input.setup.control_length = length_control;
  62. input.setup.bounds.phase.initialtime.lower = initialtime_lower;
  63. input.setup.bounds.phase.initialtime.upper = initialtime_upper;
  64. input.setup.bounds.phase.finaltime.lower = finaltime_lower;
  65. input.setup.bounds.phase.finaltime.upper = finaltime_upper;
  66. input.setup.bounds.phase.initialstate.lower = initialstate_lower / state_c;
  67. input.setup.bounds.phase.initialstate.upper = initialstate_upper / state_c;
  68. input.setup.bounds.phase.state.lower = state_lower / state_c;
  69. input.setup.bounds.phase.state.upper = state_upper / state_c; // 默认状态上限为正无穷
  70. input.setup.bounds.phase.finalstate.lower = finalstate_lower / state_c;
  71. input.setup.bounds.phase.finalstate.upper = finalstate_upper / state_c;
  72. input.setup.bounds.phase.control.lower = control_lower;
  73. input.setup.bounds.phase.control.upper = control_upper;
  74. input.setup.bounds.phase.path.lower = path_lower;
  75. input.setup.bounds.phase.path.upper = path_upper;
  76. input.setup.bounds.phase.integral.lower = integral_lower;
  77. input.setup.bounds.phase.integral.upper = integral_upper;
  78. input.setup.bounds.phase.event.lower.reset();
  79. input.setup.bounds.phase.event.upper.reset();
  80. // 猜测值
  81. guess0 guess;
  82. int length_path = 3;
  83. vec guess_time; guess_time << 0.0 << 300.0 / tc << endr;
  84. mat guess_state(2, length_state, fill::zeros);
  85. mat guess_control(2, length_control, fill::zeros);
  86. mat guess_path(2, length_path, fill::zeros);
  87. rowvec guess_integral;
  88. guess_state.row(0) = input.setup.bounds.phase.initialstate.lower.t();
  89. guess_state.row(1) = input.setup.bounds.phase.finalstate.lower.t();
  90. guess_control.row(0) = input.setup.bounds.phase.control.lower.t();
  91. guess_control.row(1) = input.setup.bounds.phase.control.upper.t();
  92. guess_integral << 0 << endr;
  93. guess_path.row(0) = input.setup.bounds.phase.path.lower.t();
  94. guess_path.row(1) = input.setup.bounds.phase.path.upper.t();
  95. guess.phase.time = guess_time;
  96. guess.phase.state = guess_state;
  97. guess.phase.control = guess_control;
  98. guess.phase.integral = guess_integral;
  99. guess.phase.path = guess_path;
  100. input.setup.guess = guess;
  101. // 配点设置
  102. int inter_num = 2;
  103. input.setup.name = "RLV"; // 问题
  104. mesh1 mesh;
  105. mesh.method = "p-h"; // 网格细化方法的名字,字符串表示
  106. mesh.tolerance = 1e-5; // 网格细化精度的允许值
  107. mesh.maxiterration = 3; // 网格细化最大迭代次数
  108. mesh.colpointsmin = 2; // 网格细化产生新interval下的最小配点数目
  109. mesh.colpointsmax = 20; // 网格细化产生新interval下的最大配点数目
  110. mesh.splitmult = 1.2; // 比例因子,确定创建新网格的间隔数目
  111. mesh.curveratio = 2; // 网格间隔中解的最大平均曲率比的阈值,以确定是否增加新间隔
  112. mesh.phase.inter_num = inter_num; // 段p内的间隔数目, 整数
  113. mesh.phase.colpoints = 2 * ones(inter_num, 1); // 段p内的配置点数目,整数数组,长度与间隔数目相等
  114. mesh.phase.i_proportion = 2.0 / inter_num * ones(inter_num, 1); // 初始网格划分的比例(当前为均等划分,和为2)
  115. input.setup.mesh = mesh; // 组合setup.mesh结构体
  116. // input.setup.Scal = 0;
  117. input.setup.warmstart = 0;
  118. input.setup.interp.method = "linear";
  119. // 函数设置
  120. functions1 functions;
  121. functions.continous1 = Dynamics123;
  122. functions.endpoint = Objective123;
  123. // 求解器设置
  124. NLP1 NLP;
  125. NLP.ipoptoptions.print_level = 1;
  126. NLP.ipoptoptions.hessian_approximation = "limited-memory";
  127. NLP.ipoptoptions.mu_strategy = "adaptive";
  128. NLP.ipoptoptions.linear_solver = "ma27"; //mumps、pardiso
  129. NLP.ipoptoptions.tolerance = 1e-2;
  130. NLP.ipoptoptions.maxiterration = 3000;
  131. input.setup.NLP = NLP;
  132. input.setup.derivatives.supplier = "FD";
  133. //input.setup.feature.FSE = 1; ///////
  134. // 伪谱法过程实现
  135. int iteration_final;
  136. output = PM_Process(&input, functions, &iteration_final);
  137. // 计时结束
  138. end = clock();
  139. dur = (double)(end - start);
  140. #ifndef LUOYC20220707
  141. printf("Use Time: %f \n", (dur / CLOCKS_PER_SEC));
  142. #else
  143. printf_s("Use Time: %f \n", (dur / CLOCKS_PER_SEC));
  144. #endif
  145. getchar();
  146. return 1;
  147. }