OrionShipTest.cpp 6.3 KB

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