Решение систем нелинейных уравнений 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.0KB

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