/DataAssimilation/DataAssimilationConstantSystem/src/data_assimilation_test01.cpp

http://github.com/xyan075/examples · C++ · 82 lines · 50 code · 18 blank · 14 comment · 4 complexity · c8fd2fae57a95678c4e4047a72315e49 MD5 · raw file

  1. #define MEASUREMENT_DIR "./" //where to find the measurement files, relative to the path of running the exe file
  2. #include "data_assimilation_routines.h"
  3. //model operator 01: simplest
  4. MODEL_TYPE*
  5. model_opeartor_01(MODEL_TYPE* model, APP_CONTEXT_TYPE* app_context);
  6. //model operator 01: constant system
  7. //evalute model with (model->n_ensem) sigma points,
  8. //forwad the system state (model->theta_k[i],model->x_k[i]) and previous states (model->x_k_minus_1[i],model->theta_k_minus_1[i])
  9. //by 1 (model->k) time step or 0.01s (model->t)
  10. MODEL_TYPE*
  11. model_opeartor_01(MODEL_TYPE* model, APP_CONTEXT_TYPE* app_context)
  12. {
  13. PetscInt i=0;
  14. for(i=0; i<model->n_ensem; i++){
  15. //1. update the system state vector
  16. VecCopy(model->x_k[i],model->x_k_minus_1[i]);
  17. //2. update the system parameter vector
  18. VecCopy(model->theta_k[i],model->theta_k_minus_1[i]);
  19. //VecCopy(model->theta_k[i],model->x_k[i]);
  20. //debug diagnosis
  21. if(app_context->diagnosisMode & DIAGNOSIS_DISP_INITIAL_CONF){
  22. app_context_report_info(INFO_PETSC_INT, 1, &model->k,"===simulation==== \nmodel_opeartor_01, model->k", app_context);
  23. app_context_report_info(INFO_PETSC_REAL, 1, &model->t,"model_opeartor_01, model->t", app_context);
  24. app_context_report_info(INFO_PETSC_INT, 1, &i,"i", app_context);
  25. app_context_report_info(INFO_PETSC_INT, 1, &model->n_x,"model_opeartor_01, model->n_x", app_context);
  26. app_context_report_info(INFO_PETSC_INT, 1, &model->n_theta,"model_opeartor_01, model->n_theta", app_context);
  27. app_context_report_info(INFO_PETSC_VEC, 1, &model->theta_k[i],"model_opeartor_01, model->theta_k_hat", app_context);
  28. app_context_report_info(INFO_PETSC_VEC, 1, &model->theta_k_minus_1[i],"model_opeartor_01, model->theta_k_minus_1_hat", app_context);
  29. }
  30. if(app_context->diagnosisMode & DIAGNOSIS_DISP_EVERYTHING){
  31. app_context_report_info(INFO_PETSC_VEC,1, &model->x_k[i],"model_opeartor_01, model->x_k_hat", app_context);
  32. app_context_report_info(INFO_PETSC_VEC, 1, &model->x_k_minus_1[i],"model_opeartor_01, model->x_k_minus_1_hat", app_context);
  33. }
  34. }
  35. //update the system time stamp
  36. model->k=model->k+1;
  37. model->t=model->t+0.01;
  38. return model;
  39. }
  40. //-------------------------------------------------------------------------------------------------
  41. //---test routines---
  42. int
  43. test01(int argc, char **args)
  44. {
  45. APP_CONTEXT_TYPE* app_context = app_context_create_and_initialize(argc, args);
  46. MEAUSREMENT_TYPE* measurement = measurement_create_and_initialize(app_context);
  47. MODEL_TYPE* model = model_create_and_initialize (&model_opeartor_01, app_context);
  48. FILTER_TYPE* filter = filter_create_and_initialize (app_context, model);
  49. app_context_create_and_initialize_dependently(app_context, filter, model, measurement);
  50. filter_set_intial_condition(filter, model, app_context);
  51. for(int k=0; k<3; k++){
  52. filter_time_update (filter, model, app_context);
  53. filter_measurement_update(filter, model, measurement, app_context);
  54. }
  55. app_context_destroy_and_finalize(app_context);
  56. return 0;
  57. }
  58. //-------------------------------------------------------------------------------------------------
  59. //---driver routines---
  60. int
  61. main(int argc,char **args)
  62. {
  63. return test01(argc,args);
  64. }