physics.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include "qt/input/physics.hpp"
  2. QtInputPhysics::QtInputPhysics():QWidget(){
  3. g_label=new QLabel("Gravity (g) : ");
  4. rho_label=new QLabel("Fluid density (ρ) : ");
  5. phi_label=new QLabel("Porosity of the soil (φ) : ");
  6. k0_label=new QLabel("Conductivity of the saturated soil (k<sub>0</sub>) : ");
  7. nivrivsat_label=new QLabel("Water pressure at the bottom of overland water (nivrivsat) : ");
  8. g_input=new QLineEdit();
  9. rho_input=new QLineEdit();
  10. phi_input=new QLineEdit();
  11. k0_input=new QLineEdit();
  12. nivrivsat_input=new QLineEdit();
  13. for(size_t i=0;i<Physics::max_model_parameters;++i){
  14. model_label[i]=new QLabel(this);
  15. model_input[i]=new QLineEdit(this);
  16. }
  17. //Text format
  18. rho_label->setTextFormat(Qt::RichText);
  19. phi_label->setTextFormat(Qt::RichText);
  20. k0_label->setTextFormat(Qt::RichText);
  21. for(size_t i=0;i<Physics::max_model_parameters;++i){
  22. model_label[i]->setTextFormat(Qt::RichText);
  23. }
  24. //Hide model parameters
  25. for(size_t i=0;i<Physics::max_model_parameters;++i){
  26. model_label[i]->hide();
  27. model_input[i]->hide();
  28. }
  29. //Input validators
  30. double_validator=new QDoubleValidator;
  31. positive_double_validator=new QDoubleValidator;
  32. positive_double_validator->setBottom(0);
  33. g_input->setValidator(positive_double_validator);
  34. rho_input->setValidator(double_validator);
  35. phi_input->setValidator(double_validator);
  36. k0_input->setValidator(double_validator);
  37. nivrivsat_input->setValidator(double_validator);
  38. //Boxes
  39. phy_common_box=new QGroupBox("Common parameters");
  40. phy_model_box=new QGroupBox("Model parameters");
  41. phy_model_selection_box=new QComboBox;
  42. phy_model_selection_box->addItem("Brooks and Corey");
  43. //Button
  44. refresh_button=new QPushButton("Refresh");
  45. //Widget
  46. phy_base_widget=new QWidget;
  47. //Layouts
  48. main_layout=new QVBoxLayout;
  49. phy_base_layout=new QHBoxLayout;
  50. phy_common_layout=new QVBoxLayout;
  51. phy_model_layout=new QVBoxLayout;
  52. //Phy commont layout
  53. int vspace=20;
  54. phy_common_layout->addWidget(g_label);
  55. phy_common_layout->addWidget(g_input);
  56. phy_common_layout->addSpacing(vspace);
  57. phy_common_layout->addWidget(rho_label);
  58. phy_common_layout->addWidget(rho_input);
  59. phy_common_layout->addSpacing(vspace);
  60. phy_common_layout->addWidget(phi_label);
  61. phy_common_layout->addWidget(phi_input);
  62. phy_common_layout->addSpacing(vspace);
  63. phy_common_layout->addWidget(k0_label);
  64. phy_common_layout->addWidget(k0_input);
  65. phy_common_layout->addSpacing(vspace);
  66. phy_common_layout->addWidget(nivrivsat_label);
  67. phy_common_layout->addWidget(nivrivsat_input);
  68. phy_common_layout->addStretch();
  69. //Phy model layout
  70. phy_model_layout->addWidget(phy_model_selection_box);
  71. for(size_t i=0;i<Physics::max_model_parameters;++i){
  72. phy_model_layout->addSpacing(vspace);
  73. phy_model_layout->addWidget(model_label[i]);
  74. phy_model_layout->addWidget(model_input[i]);
  75. }
  76. phy_model_layout->addStretch();
  77. //Boxes
  78. phy_common_box->setLayout(phy_common_layout);
  79. phy_model_box->setLayout(phy_model_layout);
  80. //Base widget
  81. phy_base_layout->addWidget(phy_common_box);
  82. phy_base_layout->addWidget(phy_model_box);
  83. phy_base_widget->setLayout(phy_base_layout);
  84. //Main_lyaout
  85. main_layout->addWidget(phy_base_widget);
  86. main_layout->addWidget(refresh_button);
  87. setLayout(main_layout);
  88. //Conections
  89. connect(phy_model_selection_box,QOverload<int>::of(&QComboBox::activated),this,&QtInputPhysics::modelChoosed);
  90. //Display model specific interface
  91. nb_model_parameters=0;
  92. modelChoosed(phy_model_selection_box->currentIndex());
  93. connect(refresh_button,&QPushButton::clicked,this,&QtInputPhysics::emitPhysicsChanged);
  94. getPhysics();
  95. }
  96. void
  97. QtInputPhysics::modelChoosed(int index){
  98. for(size_t i=0;i<Physics::max_model_parameters;++i){
  99. model_label[i]->hide();
  100. model_input[i]->hide();
  101. }
  102. switch(index){
  103. case 0:
  104. //Brooks and Corey
  105. Physics::setModel(Physics::BrooksCorey);
  106. nb_model_parameters=4;
  107. model_label[0]->setText("Minimal pressure p<sub>sat</sub> such that s(p<sub>sat</sub>)=1");
  108. model_input[0]->setValidator(double_validator);
  109. model_input[0]->setText(QString::number(Physics::model_data[0]));
  110. model_label[1]->setText("Minimal residual pressure (s<sub>res</sub>)");
  111. model_input[1]->setValidator(double_validator);
  112. model_input[1]->setText(QString::number(Physics::model_data[1]));
  113. model_label[2]->setText("&lambda; exponent");
  114. model_input[2]->setValidator(double_validator);
  115. model_input[2]->setText(QString::number(Physics::model_data[2]));
  116. model_label[3]->setText("&alpha; exponent");
  117. model_input[3]->setValidator(double_validator);
  118. model_input[3]->setText(QString::number(Physics::model_data[3]));
  119. break;
  120. default:
  121. break;
  122. };
  123. for(size_t i=0;i<nb_model_parameters;++i){
  124. model_label[i]->show();
  125. model_input[i]->show();
  126. }
  127. }
  128. QWidget*
  129. QtInputPhysics::validate(){
  130. if(not g_input->hasAcceptableInput()) return g_input;
  131. if(not rho_input->hasAcceptableInput()) return rho_input;
  132. if(not phi_input->hasAcceptableInput()) return phi_input;
  133. if(not k0_input->hasAcceptableInput()) return k0_input;
  134. if(not nivrivsat_input->hasAcceptableInput()) return nivrivsat_input;
  135. for(size_t i=0;i<nb_model_parameters;++i){
  136. if(not model_input[i]->hasAcceptableInput()) return model_input[i];
  137. }
  138. return nullptr;
  139. }
  140. void
  141. QtInputPhysics::getPhysics(){
  142. g_input->setText(QString::number(Physics::g));
  143. rho_input->setText(QString::number(Physics::rho));
  144. phi_input->setText(QString::number(Physics::phi));
  145. k0_input->setText(QString::number(Physics::k0));
  146. nivrivsat_input->setText(QString::number(Physics::nivrivsat));
  147. phy_model_selection_box->setCurrentIndex(Physics::model);
  148. for(size_t i=0;i<Physics::max_model_parameters;++i){
  149. model_input[i]->setText(QString::number(Physics::model_data[i]));
  150. }
  151. }
  152. void
  153. QtInputPhysics::setPhysics(){
  154. Physics::g=g_input->text().toDouble();
  155. Physics::rho=rho_input->text().toDouble();
  156. Physics::phi=phi_input->text().toDouble();
  157. Physics::k0=k0_input->text().toDouble();
  158. Physics::nivrivsat=nivrivsat_input->text().toDouble();
  159. //Model must be already assigned by QtInputPhysics::modelChoosed
  160. for(size_t i=0;i<Physics::max_model_parameters;++i){
  161. Physics::model_data[i]=model_input[i]->text().toDouble();
  162. }
  163. }
  164. void
  165. QtInputPhysics::emitPhysicsChanged(){
  166. QWidget* widget=validate();
  167. if(widget!=nullptr){
  168. QMessageBox msgBox;
  169. msgBox.setText("Incorrect geometry entry");
  170. msgBox.exec();
  171. widget->setFocus();
  172. }
  173. else{
  174. setPhysics();
  175. emit physicsChanged();
  176. }
  177. }