Решение систем нелинейных уравнений https://www.mapleprimes.com/users/one%20man/posts?page=1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

solver.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "solver.h"
  2. //#include <iostream>
  3. solver_diff_eqn::solver_diff_eqn(sys_osn_dan &sod_, double exit_tol):sod(&sod_)
  4. {
  5. N=sod->get_par_diff().N;
  6. dt=sod->get_par_diff().dt;
  7. x=sod->get_par_diff().x0;
  8. n_svob=sod->get_par_diff().nsv;
  9. not_comp_=sod->get_par_diff().noc;
  10. std::ifstream stream("test.so");
  11. if ( !(stream.good() && not_comp_) )
  12. {
  13. int systemErr=system("g++ -fPIC -shared -o test.so test.cpp -O2");
  14. if (systemErr == -1)
  15. std::cerr<<"Ошибка компилирования"<<std::endl;
  16. }
  17. stream.close();
  18. shared_object = dlopen("./test.so", RTLD_NOW);
  19. create_t* load_sys = (create_t*) dlsym(shared_object, "create");
  20. destroy_t* unload_sys = (destroy_t*) dlsym(shared_object, "destroy");
  21. diffeqninterface* func_sys=load_sys();
  22. func=func_sys->funcv();
  23. // std::vector<double> temvec{-.6,.2,-2};
  24. double l_dt=0, r_dt=dt;
  25. coordinate.insert(coordinate.end(), x.begin(), x.end());
  26. const state_type x0=x;//начальная точка
  27. state_type _upr_par={0};
  28. if ( exit_tol>0 )
  29. {
  30. c1_=x;
  31. for (size_t i = 0; i < x.size(); i++)
  32. if (x[i] <= 0)
  33. max_x.push_back(-x[i]);
  34. else
  35. max_x.push_back(x[i]);
  36. c_diff.resize(x.size());
  37. }
  38. for (double i=0;i<N;)
  39. for (int k=0; k<n_svob && i<N; k++)
  40. {
  41. i++;
  42. rk.do_step( func[k] , x , l_dt , r_dt );
  43. //std::copy(_upr_par.begin(), _upr_par.end(), std::back_inserter(func_sys->get_upr_par()));
  44. for (size_t i = 0; i < sod->get_par_diff().up.size(); i++)
  45. _upr_par.push_back(func_sys->get_upr_par()[i]);
  46. coordinate.insert(coordinate.end(), x.begin(), x.end());
  47. if ( exit_tol>0 )
  48. {
  49. for (size_t i = 0; i < x.size(); i++)
  50. {
  51. c_diff[i]=fabs(x[i]-x0[i]);
  52. if (x[i] <= 0 && max_x[i] < -x[i] )
  53. max_x[i]=-x[i];
  54. if (x[i] >= 0 && max_x[i] < x[i] )
  55. max_x[i]=x[i];
  56. }
  57. m_diff=std::max_element(c_diff.begin(), c_diff.end());//максимальная разность
  58. m_pos=std::distance(c_diff.begin(), m_diff);//номер координаты
  59. if ( *m_diff < exit_tol*max_x[m_pos] )
  60. {
  61. i=N;
  62. sod->set_par_diff(i,dt);
  63. }
  64. }
  65. }
  66. sod->set_resIN(coordinate);
  67. sod->set_uprIN(_upr_par);
  68. unload_sys(func_sys);
  69. closeso=true; //исправить sysosndan
  70. // if (closeso)
  71. // dlclose(shared_object);
  72. // for (size_t i=0; i<_upr_par.size();i++)
  73. // std::cout<<_upr_par[i]<<std::endl;
  74. }
  75. solver_diff_eqn::~solver_diff_eqn(){ dlclose(shared_object); }//вызывает segmentation fault