UltraScan III
us_grid_editor.cpp
Go to the documentation of this file.
1 
3 #include <QApplication>
4 #include "us_grid_editor.h"
5 
6 const double MPISQ = M_PI * M_PI;
7 const double THIRD = 1.0 / 3.0;
8 const double VOL_FAC = 0.75 / M_PI;
9 const double SPH_FAC = 0.06 * M_PI * VISC_20W;
10 
11 // main program
12 int main( int argc, char* argv[] )
13 {
14  QApplication application( argc, argv );
15 
16  #include "main1.inc"
17 
18  // License is OK. Start up.
19 
21  w.show();
22  return application.exec();
23 }
24 
25 // US_Grid_Editor class constructor
27 {
28  // set up the GUI
29  QString str;
30 
31  setWindowTitle( tr( "UltraScan 2DSA Grid Initialization Editor" ) );
32  setPalette( US_GuiSettings::frameColor() );
33 
34  // primary layouts
35  QHBoxLayout* main = new QHBoxLayout( this );
36  QVBoxLayout* right = new QVBoxLayout();
37  QGridLayout* left = new QGridLayout();
38  main->setSpacing ( 2 );
39  main->setContentsMargins( 2, 2, 2, 2 );
40  left->setSpacing ( 1 );
41  left->setContentsMargins( 0, 0, 0, 0 );
42  right->setSpacing ( 0 );
43  right->setContentsMargins( 0, 1, 0, 1 );
45  density = DENS_20W;
47 
48  int s_row = 0;
50 
51  // series of rows: most of them label on left, counter/box on right
52  lb_info1 = us_banner( tr( "Grid Editor Controls" ) );
53 
54  QPushButton* pb_investigator = us_pushbutton( tr( "Select Investigator" ) );
55  connect( pb_investigator, SIGNAL( clicked() ), SLOT( sel_investigator() ) );
56 
57  if ( US_Settings::us_inv_level() < 1 )
58  pb_investigator->setEnabled( false );
59 
60  int id = US_Settings::us_inv_ID();
61  QString number = ( id > 0 ) ?
62  QString::number( US_Settings::us_inv_ID() ) + ": "
63  : "";
65  1, true );
66 
69  connect( dkdb_cntrls, SIGNAL( changed( bool ) ),
70  this, SLOT( update_disk_db( bool ) ) );
71 
72  lb_xaxis = us_label( tr( "Adjust X-Axis as:" ) );
73  lb_xaxis->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
74 
75  lb_yaxis = us_label( tr( "Adjust Y-Axis as:" ) );
76  lb_yaxis->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
77 
78  QGridLayout* x_s = us_radiobutton( tr( "Sedimentation Coeff." ),
79  rb_x_s, true );
80  QGridLayout* x_ff0 = us_radiobutton( tr( "Frictional Ratio" ),
81  rb_x_ff0, false );
82  QGridLayout* x_mw = us_radiobutton( tr( "Molecular Weight" ),
83  rb_x_mw, true );
84  QGridLayout* x_vbar = us_radiobutton( tr( "Partial Specific Volume" ),
85  rb_x_vbar, true );
86  QGridLayout* x_D = us_radiobutton( tr( "Diffusion Coefficient" ),
87  rb_x_D, true );
88  QGridLayout* x_f = us_radiobutton( tr( "Frictional Coefficient" ),
89  rb_x_f, true );
90  QGridLayout* y_s = us_radiobutton( tr( "Sedimentation Coeff." ),
91  rb_y_s, false );
92  QGridLayout* y_ff0 = us_radiobutton( tr( "Frictional Ratio" ),
93  rb_y_ff0, true );
94  QGridLayout* y_mw = us_radiobutton( tr( "Molecular Weight" ),
95  rb_y_mw, true );
96  QGridLayout* y_vbar = us_radiobutton( tr( "Partial Specific Volume" ),
97  rb_y_vbar, true );
98  QGridLayout* y_D = us_radiobutton( tr( "Diffusion Coefficient" ),
99  rb_y_D, true );
100  QGridLayout* y_f = us_radiobutton( tr( "Frictional Coefficient" ),
101  rb_y_f, true );
102 
103  QGridLayout* toggle1 = us_radiobutton( tr( "X-Axis View" ),
104  rb_plot1, true );
105  QGridLayout* toggle2 = us_radiobutton( tr( "Molecular Weight View" ),
106  rb_plot2, true );
107 
108  QButtonGroup* x_axis = new QButtonGroup( this );
109  x_axis->addButton( rb_x_s, ATTR_S );
110  x_axis->addButton( rb_x_ff0, ATTR_K );
111  x_axis->addButton( rb_x_mw, ATTR_W );
112  x_axis->addButton( rb_x_vbar, ATTR_V );
113  x_axis->addButton( rb_x_D, ATTR_D );
114  x_axis->addButton( rb_x_f, ATTR_F );
115  connect( x_axis, SIGNAL( buttonReleased( int ) ),
116  SLOT ( select_x_axis ( int ) ) );
117 
118  QButtonGroup* y_axis = new QButtonGroup( this );
119  y_axis->addButton( rb_y_s, ATTR_S );
120  y_axis->addButton( rb_y_ff0, ATTR_K );
121  y_axis->addButton( rb_y_mw, ATTR_W );
122  y_axis->addButton( rb_y_vbar, ATTR_V );
123  y_axis->addButton( rb_y_D, ATTR_D );
124  y_axis->addButton( rb_y_f, ATTR_F );
125  connect( y_axis, SIGNAL( buttonReleased( int ) ),
126  SLOT ( select_y_axis ( int ) ) );
127 
128  QButtonGroup* toggle_plot = new QButtonGroup( this );
129  toggle_plot->addButton( rb_plot1, 0 );
130  toggle_plot->addButton( rb_plot2, 1 );
131  rb_plot1 ->setChecked( true );
132  connect( toggle_plot, SIGNAL( buttonReleased( int ) ),
133  SLOT ( select_plot ( int ) ) );
134 
135  lb_fixed = us_label( tr( "Fixed Attribute:" ) );
136  cb_fixed = us_comboBox();
137  cb_fixed->addItem( tr( "Partial Specific Volume" ) );
138  cb_fixed->addItem( tr( "Frictional Ratio" ) );
139  cb_fixed->addItem( tr( "Molecular Weight" ) );
140  cb_fixed->addItem( tr( "Sedimentation Coefficient" ) );
141  cb_fixed->addItem( tr( "Diffusion Coefficient" ) );
142  cb_fixed->addItem( tr( "Frictional Coefficient" ) );
143  cb_fixed->setEnabled( true );
144  cb_fixed->setCurrentIndex( 0 );
145  connect( cb_fixed, SIGNAL( activated ( const QString& ) ),
146  this, SLOT ( select_fixed( const QString& ) ) );
147 
148  lb_xRes = us_label( tr( "X Resolution:" ) );
149  lb_xRes->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
150 
151  ct_xRes = us_counter( 3, 10.0, 1000.0, 60.0 );
152  ct_xRes->setStep( 1 );
153  connect( ct_xRes, SIGNAL( valueChanged( double ) ),
154  this, SLOT ( update_xRes ( double ) ) );
155 
156  lb_yRes = us_label( tr( "f/f0 Resolution:" ) );
157  lb_yRes->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
158 
159  ct_yRes = us_counter( 3, 10.0, 1000.0, 60.0 );
160  ct_yRes->setStep( 1 );
161  connect( ct_yRes, SIGNAL( valueChanged( double ) ),
162  this, SLOT ( update_yRes ( double ) ) );
163 
164  lb_xMin = us_label( tr( "s (x 1e13) Minimum:" ) );
165  lb_xMin->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
166 
167  ct_xMin = us_counter( 3, -10000.0, 10000.0, 0.1 );
168  ct_xMin->setStep( 1 );
169  connect( ct_xMin, SIGNAL( valueChanged( double ) ),
170  this, SLOT ( update_xMin ( double ) ) );
171 
172  lb_xMax = us_label( tr( "s (x 1e13) Maximum:" ) );
173  lb_xMax->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
174 
175  ct_xMax = us_counter( 3, -10000.0, 10000.0, 0.1 );
176  ct_xMax->setStep( 1 );
177  connect( ct_xMax, SIGNAL( valueChanged( double ) ),
178  this, SLOT ( update_xMax ( double ) ) );
179 
180  lb_yMin = us_label( tr( "f/f0 Minimum:" ) );
181  lb_yMin->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
182 
183  ct_yMin = us_counter( 3, 1.0, 50.0, 0.1 );
184  ct_yMin->setStep( 1 );
185  connect( ct_yMin, SIGNAL( valueChanged( double ) ),
186  this, SLOT( update_yMin ( double ) ) );
187 
188  lb_yMax = us_label( tr( "f/f0 Maximum:" ) );
189  lb_yMax->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
190 
191  ct_yMax = us_counter( 3, 1.0, 50.0, 0.1 );
192  ct_yMax->setStep( 1 );
193  connect( ct_yMax, SIGNAL( valueChanged( double ) ),
194  this, SLOT( update_yMax ( double ) ) );
195 
196  lb_zVal = us_label( tr( "Partial Specific Volume:" ) );
197  lb_zVal->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
198 
199  ct_zVal = us_counter( 3, 0.01, 3.0, 0.001 );
200  ct_zVal->setStep ( 1 );
201  ct_zVal->setValue( 0.72 );
202  connect( ct_zVal, SIGNAL( valueChanged( double ) ),
203  this, SLOT( update_zVal ( double ) ) );
204 
205  lb_density = us_label( tr( "Density:" ) );
206  lb_density->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
207  str.setNum( density );
208  QLineEdit* le_density = us_lineedit( str.setNum( density ));
209  connect( le_density, SIGNAL( textChanged ( const QString& ) ),
210  this, SLOT ( update_density( const QString& ) ) );
211 
212  lb_viscosity = us_label( tr( "Viscosity:" ) );
213  lb_viscosity->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
214  str.setNum( viscosity );
215  QLineEdit* le_viscosity = us_lineedit( str.setNum( viscosity ));
216  connect( le_viscosity, SIGNAL( textChanged ( const QString& ) ),
217  this, SLOT ( update_viscosity( const QString& ) ) );
218 
219  pb_add_partialGrid = us_pushbutton( tr( "Add this Grid" ) );
220  pb_add_partialGrid->setEnabled( true );
221  connect( pb_add_partialGrid, SIGNAL( clicked() ),
222  this, SLOT ( add_partialGrid() ) );
223 
224  QGridLayout *showgrid = us_checkbox( tr("Show Final Grid"),
225  ck_show_final_grid, false );
226  connect( ck_show_final_grid, SIGNAL( clicked ( bool ) ),
227  this, SLOT ( show_final_grid( bool ) ) );
228  ck_show_final_grid->setEnabled( false );
229 
230  pb_delete_partialGrid = us_pushbutton( tr( "Delete Partial Grid" ) );
231  pb_delete_partialGrid->setEnabled( false );
232  connect( pb_delete_partialGrid, SIGNAL( clicked() ),
233  this, SLOT ( delete_partialGrid() ) );
234 
235  QGridLayout *showsubgrid = us_checkbox( tr("Show Subgrids"), ck_show_sub_grid, false );
236  connect( ck_show_sub_grid, SIGNAL( clicked(bool) ),
237  this, SLOT( show_sub_grid(bool) ) );
238  ck_show_sub_grid->setEnabled( false );
239 
240  lb_partialGrid = us_label( tr( "Highlight Partial Grid #:" ) );
241  lb_partialGrid->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
242 
243  ct_partialGrid = us_counter( 3, 0, 1000, 0.0 );
244  ct_partialGrid->setStep( 1 );
245  ct_partialGrid->setEnabled( false );
246  connect( ct_partialGrid, SIGNAL( valueChanged( double ) ),
247  this, SLOT( update_partialGrid( double ) ) );
248 
249  lb_subGrid = us_label( tr( "Number of Subgrids:" ) );
250  lb_subGrid->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
251 
252  ct_subGrids = us_counter( 3, 1, 500, 13.0 );
253  ct_subGrids->setStep( 1 );
254  ct_subGrids->setEnabled( false );
255  connect( ct_subGrids, SIGNAL( valueChanged( double ) ),
256  this, SLOT( update_subGrids( double ) ) );
257 
258  pb_reset = us_pushbutton( tr( "Reset" ) );
259  pb_reset->setEnabled( true );
260  connect( pb_reset, SIGNAL( clicked() ),
261  this, SLOT( reset() ) );
262 
263  pb_save = us_pushbutton( tr( "Save" ) );
264  pb_save->setEnabled( false );
265  connect( pb_save, SIGNAL( clicked() ),
266  this, SLOT( save() ) );
267 
268  pb_help = us_pushbutton( tr( "Help" ) );
269  pb_help->setEnabled( true );
270  connect( pb_help, SIGNAL( clicked() ),
271  this, SLOT( help() ) );
272 
273  pb_close = us_pushbutton( tr( "Close" ) );
274  pb_close->setEnabled( true );
275  connect( pb_close, SIGNAL( clicked() ),
276  this, SLOT( close() ) );
277 
278  // set up plot component window on right side
279 
280  QBoxLayout* plot1 = new US_Plot( data_plot1,
281  tr( "Grid Layout" ),
282  tr( "Sedimentation Coefficient (s20,W)"),
283  tr( "Frictional Ratio f/f0" ) );
284  data_plot1->setAutoDelete( true );
285  data_plot1->setMinimumSize( 640, 480 );
286  data_plot1->enableAxis( QwtPlot::xBottom, true );
287  data_plot1->enableAxis( QwtPlot::yLeft, true );
288  data_plot1->setAxisScale( QwtPlot::xBottom, 1.0, 40.0 );
289  data_plot1->setAxisScale( QwtPlot::yLeft, 1.0, 4.0 );
290 
291  left->addWidget( lb_info1, s_row++, 0, 1, 4 );
292  left->addWidget( pb_investigator, s_row, 0, 1, 2 );
293  left->addWidget( le_investigator, s_row++, 2, 1, 2 );
294  left->addLayout( dkdb_cntrls, s_row++, 0, 1, 4 );
295  left->addWidget( lb_xaxis, s_row, 0, 1, 2 );
296  left->addWidget( lb_yaxis, s_row++, 2, 1, 2 );
297  left->addLayout( x_s, s_row, 0, 1, 2 );
298  left->addLayout( y_s, s_row++, 2, 1, 2 );
299  left->addLayout( x_ff0, s_row, 0, 1, 2 );
300  left->addLayout( y_ff0, s_row++, 2, 1, 2 );
301  left->addLayout( x_mw, s_row, 0, 1, 2 );
302  left->addLayout( y_mw, s_row++, 2, 1, 2 );
303  left->addLayout( x_vbar, s_row, 0, 1, 2 );
304  left->addLayout( y_vbar, s_row++, 2, 1, 2 );
305  left->addLayout( x_D, s_row, 0, 1, 2 );
306  left->addLayout( y_D, s_row++, 2, 1, 2 );
307  left->addLayout( x_f, s_row, 0, 1, 2 );
308  left->addLayout( y_f, s_row++, 2, 1, 2 );
309  left->addWidget( lb_fixed, s_row, 0, 1, 2 );
310  left->addWidget( cb_fixed, s_row++, 2, 1, 2 );
311  left->addLayout( toggle1, s_row, 0, 1, 2 );
312  left->addLayout( toggle2, s_row++, 2, 1, 2 );
313  left->addWidget( lb_xRes, s_row, 0, 1, 2 );
314  left->addWidget( ct_xRes, s_row++, 2, 1, 2 );
315  left->addWidget( lb_yRes, s_row, 0, 1, 2 );
316  left->addWidget( ct_yRes, s_row++, 2, 1, 2 );
317  left->addWidget( lb_xMin, s_row, 0, 1, 2 );
318  left->addWidget( ct_xMin, s_row++, 2, 1, 2 );
319  left->addWidget( lb_xMax, s_row, 0, 1, 2 );
320  left->addWidget( ct_xMax, s_row++, 2, 1, 2 );
321  left->addWidget( lb_yMin, s_row, 0, 1, 2 );
322  left->addWidget( ct_yMin, s_row++, 2, 1, 2 );
323  left->addWidget( lb_yMax, s_row, 0, 1, 2 );
324  left->addWidget( ct_yMax, s_row++, 2, 1, 2 );
325  left->addWidget( lb_zVal, s_row, 0, 1, 2 );
326  left->addWidget( ct_zVal, s_row++, 2, 1, 2 );
327  left->addWidget( lb_density, s_row, 0, 1, 1 );
328  left->addWidget( le_density, s_row, 1, 1, 1 );
329  left->addWidget( lb_viscosity, s_row, 2, 1, 1 );
330  left->addWidget( le_viscosity, s_row++, 3, 1, 1 );
331  left->addWidget( pb_add_partialGrid, s_row, 0, 1, 2 );
332  left->addLayout( showgrid, s_row++, 2, 1, 2 );
333  left->addWidget( pb_delete_partialGrid, s_row, 0, 1, 2 );
334  left->addLayout( showsubgrid, s_row++, 2, 1, 2 );
335  left->addWidget( lb_partialGrid, s_row, 0, 1, 2 );
336  left->addWidget( ct_partialGrid, s_row++, 2, 1, 2 );
337  left->addWidget( lb_subGrid, s_row, 0, 1, 2 );
338  left->addWidget( ct_subGrids, s_row++, 2, 1, 2 );
339  left->addWidget( pb_reset, s_row, 0, 1, 1 );
340  left->addWidget( pb_save, s_row, 1, 1, 1 );
341  left->addWidget( pb_help, s_row, 2, 1, 1 );
342  left->addWidget( pb_close, s_row++, 3, 1, 1 );
343 
344  right->addLayout( plot1 );
345 
346  main->addLayout( left );
347  main->addLayout( right );
348  main->setStretchFactor( left, 2 );
349  main->setStretchFactor( right, 6 );
350 
351  reset();
352 }
353 
354 // reset the GUI
356 {
357  data_plot1->detachItems( );
358  pick1 = new US_PlotPicker( data_plot1 );
359 
360  xRes = 60.0;
361  yRes = 60.0;
362 qDebug() << "reset yRes" << yRes;
363  yMin = 1.0;
364  yMax = 4.0;
365  xMin = 1.0;
366  xMax = 10.0;
367  zVal = 0.72;
368  vbar = 0.72;
369  ff0 = 1.0;
370  plot_x = ATTR_S; // plot s
371  plot_y = ATTR_K; // plot f/f0
372  plot_z = ATTR_V; // fixed vbar
373  selected_plot = 0;
375  density = DENS_20W;
376  grid_index = 0;
377  partialGrid = 0;
378  subGrids = 13;
379  final_grid.clear();
380 
381 qDebug() << "1)set yRes" << yRes;
382  ct_xRes->setRange( 10.0, 1000.0, 1.0 );
383 qDebug() << "2)set yRes" << yRes;
384  ct_xRes->setValue( xRes );
385 qDebug() << "3)set yRes" << yRes;
386  ct_yRes->setRange( 10.0, 1000.0, 1.0 );
387 qDebug() << "set yRes" << yRes;
388  ct_yRes->setValue( yRes );
389  ct_partialGrid ->setEnabled( false );
390  ct_subGrids ->setEnabled( false );
391  ct_partialGrid ->setRange( 0, 0, 0);
392  ct_partialGrid ->setValue( 0 );
393  ck_show_final_grid->setEnabled( false );
394  ck_show_final_grid->setChecked( false );
395  ck_show_sub_grid ->setEnabled( false );
396  ck_show_sub_grid ->setChecked( false );
397  ct_xRes ->setEnabled( true );
398  ct_yRes ->setEnabled( true );
399  ct_xMin ->setEnabled( true );
400  ct_yMin ->setEnabled( true );
401  ct_xMax ->setEnabled( true );
402  ct_yMax ->setEnabled( true );
403  ct_zVal ->setEnabled( true );
404  rb_x_s ->setEnabled( true );
405  rb_x_ff0 ->setEnabled( false );
406  rb_x_mw ->setEnabled( true );
407  rb_x_vbar->setEnabled( true );
408  rb_x_D ->setEnabled( true );
409  rb_x_f ->setEnabled( true );
410  rb_y_s ->setEnabled( false );
411  rb_y_ff0 ->setEnabled( true );
412  rb_y_mw ->setEnabled( true );
413  rb_y_vbar->setEnabled( true );
414  rb_y_D ->setEnabled( true );
415  rb_y_f ->setEnabled( true );
416  rb_x_s ->setChecked( true );
417  rb_y_ff0 ->setChecked( true );
418  pb_add_partialGrid ->setEnabled( true );
419  pb_save ->setEnabled( false );
420  pb_delete_partialGrid->setEnabled( false );
421 
424  select_fixed ( cb_fixed->currentText() );
425 
427  update_plot ();
428 }
429 
430 // save the grid data
432 {
433  US_Model model;
435  QString modelPath, modelGuid;
436  US_Model::model_path( modelPath );
437  QDateTime now_time = QDateTime::currentDateTime ();
438  QList< double > xvals;
439  QList< double > yvals;
440  QList< double > zvals;
441  double gridinc = 1.0 / (double)subGrids;
442  int indexsg = 1;
443  bool flag;
444  modelGuid = US_Util::new_guid();
446  model.description = now_time.toString( "yyyyMMdd-hhmm")
447  + "-CustomGrid" + ".model";
448  model.subGrids = subGrids;
449  model.modelGUID = modelGuid;
450  model.global = US_Model::NONE;
451  double vbmin = 1e99;
452  double vbmax = -1e99;
453  double ffmin = 1e99;
454  double ffmax = -1e99;
455  sc.signal_concentration = 1.0;
456 
457  for ( int ii = 0; ii < final_grid.size(); ii++ )
458  {
459  flag = true;
460  sc.s = final_grid[ ii ].s * 1.0e-13;
461  sc.D = final_grid[ ii ].D;
462  sc.f = final_grid[ ii ].f;
463  sc.f_f0 = final_grid[ ii ].ff0;
464  sc.vbar20 = final_grid[ ii ].vbar;
465  sc.mw = final_grid[ ii ].mw;
466 
467  double xval = grid_value( final_grid[ ii ], plot_x );
468  double yval = grid_value( final_grid[ ii ], plot_y );
469  double zval = grid_value( final_grid[ ii ], plot_z );
470  int indexx = xvals.indexOf( xval ) + 1;
471  int indexy = yvals.indexOf( yval ) + 1;
472  int indexz = zvals.indexOf( zval ) + 1;
473  if ( indexx < 1 ) { indexx = xvals.size() + 1; xvals << xval; }
474  if ( indexy < 1 ) { indexy = yvals.size() + 1; yvals << yval; }
475  if ( indexz < 1 ) { indexz = zvals.size() + 1; zvals << zval; }
476  sc.name = QString().sprintf( "X%3.3dY%3.3dZ%2.2d",
477  indexx, indexy, indexz );
478  sc.signal_concentration = gridinc * (double)indexsg;
479  if ( (++indexsg) > subGrids ) indexsg = 1;
480 
481  for ( int jj = 0; jj < model.components.size(); jj++ )
482  {
483  vbmin = qMin( vbmin, sc.vbar20 ); // Accumulate vbar,f/f0 extents
484  vbmax = qMax( vbmax, sc.vbar20 );
485  ffmin = qMin( ffmin, sc.f_f0 );
486  ffmax = qMax( ffmax, sc.f_f0 );
487 
488  if ( sc.s == model.components[ jj ].s &&
489  sc.f_f0 == model.components[ jj ].f_f0 &&
490  sc.mw == model.components[ jj ].mw &&
491  sc.vbar20 == model.components[ jj ].vbar20 )
492  {
493  flag = false;
494  break; // don't add a component that is already in the model
495  }
496  }
497 
498  if ( flag ) model.components.push_back(sc);
499  }
500 
501  // Open a dialog that reports and allows modification of description
502  QMessageBox mbox;
503  QString msg1 = tr( "A grid model has been created. "
504  "It's description is:<br/><b>" )
505  + model.description + "</b>.<br/><br/>"
506  + tr( "Click:<br/><br/>" )
507  + tr( " <b>OK</b> to output the model as is;<br/>"
508  " <b>Edit</b> to append custom text to the name;<br/>"
509  " <b>Cancel</b> to abort model creation.<br/>" );
510 
511  mbox.setWindowTitle( tr( "Save Grid Model" ) );
512  mbox.setText ( msg1 );
513  QPushButton *pb_ok = mbox.addButton( tr( "OK" ),
514  QMessageBox::YesRole );
515  QPushButton *pb_edit = mbox.addButton( tr( "Edit" ) ,
516  QMessageBox::AcceptRole );
517  QPushButton *pb_canc = mbox.addButton( tr( "Cancel" ),
518  QMessageBox::RejectRole );
519  mbox.setEscapeButton ( pb_canc );
520  mbox.setDefaultButton( pb_ok );
521 
522  mbox.exec();
523 
524  if ( mbox.clickedButton() == pb_canc ) return;
525 
526  if ( mbox.clickedButton() == pb_edit )
527  { // Open another dialog to get a modified runID
528  bool ok;
529  QString newtext = "";
530  int jj = model.description.indexOf( ".model" );
531  if ( jj > 0 ) model.description = model.description.left( jj );
532  QString msg2 = tr( "The default run ID for the grid model<br/>"
533  "is <b>" ) + model.description + "</b>.<br/><br/>"
534  + tr( "You may append additional text to the model description.<br/>"
535  "Use alphanumeric characters, underscores, or hyphens<br/>"
536  "(no spaces). Enter 1 to 40 characters." );
537  newtext = QInputDialog::getText( this,
538  tr( "Modify Model Name" ),
539  msg2,
540  QLineEdit::Normal,
541  newtext,
542  &ok );
543 
544  if ( !ok ) return;
545 
546  newtext.remove( QRegExp( "[^\\w\\d_-]" ) );
547 
548  int slen = newtext.length();
549  if ( slen > 40 ) newtext = newtext.left( 40 );
550  // add string containing
551  model.description = model.description + "-" + newtext + ".model";
552  }
553 
554  // Output the combined grid model
555  int code;
556  if ( dkdb_cntrls->db() )
557  {
558  US_Passwd pw;
559  US_DB2 db( pw.getPasswd() );
560  code = model.write( &db );
561  }
562  else
563  {
564  bool newFile;
565  QString fnamo = US_Model::get_filename( modelPath, modelGuid, newFile );
566  code = model.write( fnamo );
567  }
568 
569  QString mtitle = tr( "Grid Model Saving..." );
570 
571  if ( code == US_DB2::OK )
572  {
573  QString destination = dkdb_cntrls->db() ?
574  tr ( "local disk and database." ) :
575  tr ( "local disk." );
576  QMessageBox::information( this, mtitle,
577  tr( "The file \"" ) + model.description
578  + tr( "\"\n was successfully saved to " ) + destination );
579  }
580  else
581  {
582  QMessageBox::warning( this, mtitle,
583  tr( "Writing the model file \"") + model.description
584  + tr( "\"\n resulted in error code " )
585  + QString::number( code ) + " ." );
586  }
587 }
588 
589 // update raster x resolution
590 void US_Grid_Editor::update_xRes( double dval )
591 {
592 qDebug() << "ux1)yRes" << yRes;
593  xRes = dval;
594 qDebug() << "ux2)yRes" << yRes;
595  update_plot();
596 qDebug() << "ux3)yRes" << yRes;
597 }
598 
599 // update raster y resolution
600 void US_Grid_Editor::update_yRes( double dval )
601 {
602  yRes = dval;
603  update_plot();
604 }
605 
606 // update plot limit x min
607 void US_Grid_Editor::update_xMin( double dval )
608 {
609  xMin = dval;
610  ct_xMax->disconnect();
611  ct_xMax->setMinValue( xMin );
612 
613  connect( ct_xMax, SIGNAL( valueChanged( double ) ),
614  this, SLOT ( update_xMax ( double ) ) );
615 
616  validate_ff0();
617 
618  update_plot();
619 }
620 
621 // update plot limit x max
622 void US_Grid_Editor::update_xMax( double dval )
623 {
624  xMax = dval;
625  ct_xMin->disconnect();
626  ct_xMin->setMaxValue( xMax );
627 
628  connect( ct_xMin, SIGNAL( valueChanged( double ) ),
629  this, SLOT ( update_xMin ( double ) ) );
630 
631  validate_ff0();
632 
633  update_plot();
634 }
635 
636 // update plot limit y min
637 void US_Grid_Editor::update_yMin( double dval )
638 {
639  yMin = dval;
640 qDebug() << "update_yMin" << yMin;
641  ct_yMax->disconnect();
642  ct_yMax->setMinValue( yMin );
643 
644  connect( ct_yMax, SIGNAL( valueChanged( double ) ),
645  this, SLOT ( update_yMax ( double ) ) );
646 
647  validate_ff0();
648 
649  update_plot();
650 }
651 
652 // update plot limit y max
653 void US_Grid_Editor::update_yMax( double dval )
654 {
655  yMax = dval;
656 qDebug() << "update_yMax" << yMax;
657  ct_yMin->disconnect();
658  ct_yMin->setMaxValue( yMax );
659 
660  connect( ct_yMin, SIGNAL( valueChanged( double ) ),
661  this, SLOT ( update_yMin ( double ) ) );
662 
663  validate_ff0();
664 
665  update_plot();
666 }
667 
668 // update plot limit z-value (f/f0 or vbar)
669 void US_Grid_Editor::update_zVal( double dval )
670 {
671  zVal = dval;
672  vbar = ( plot_y == ATTR_V ) ? zVal : vbar;
673  ff0 = ( plot_y == ATTR_K ) ? zVal : ff0;
674 
675  validate_ff0();
676 
677  update_plot();
678 }
679 
680 // Select a partialGrid from all subgrids in the final grid for highlighting
682 {
683  partialGrid = (int) dval;
684  update_plot();
685 }
686 
687 // Select a subgrid from the final grid for highlighting:
689 {
690  subGrids = (int) dval;
691  ct_partialGrid->setRange( 1, subGrids, 1);
692  update_plot();
693 }
694 
695 // update density
696 void US_Grid_Editor::update_density( const QString & str )
697 {
698  // Skip updating if not likely done entering
699  if ( str.toDouble() == 0.0 ) return;
700 
701  // Update density value and re-plot
702  density = str.toDouble();
703  update_plot();
704 }
705 
706 // update viscosity
707 void US_Grid_Editor::update_viscosity( const QString & str )
708 {
709  // Skip updating if not likely done entering
710  if ( str.toDouble() == 0.0 ) return;
711 
712  // Update viscosity value and re-plot
713  viscosity = str.toDouble();
714  update_plot();
715 }
716 
717 // update plot
719 {
720 qDebug() << "update_plot: call calc_gridpoints()";
721  calc_gridpoints();
722 
723  data_plot1->clear();
724  QString xatitle = tr( "Sedimentation Coefficient" );
725  QString yatitle = tr( "Frictional Ratio" );
726 qDebug() << " up0)yRes" << yRes;
727 
728  switch ( plot_x )
729  {
730  default:
731  case ATTR_S:
732  xatitle = tr( "Sedimentation Coefficient" );
733  break;
734  case ATTR_K:
735  xatitle = tr( "Frictional Ratio" );
736  break;
737  case ATTR_W:
738  xatitle = tr( "Molecular Weight" );
739  break;
740  case ATTR_V:
741  xatitle = tr( "Partial Specific Volume" );
742  break;
743  case ATTR_D:
744  xatitle = tr( "Diffusion Coefficient" );
745  break;
746  case ATTR_F:
747  xatitle = tr( "Frictional Coefficient" );
748  break;
749  }
750 
751  switch ( plot_y )
752  {
753  case ATTR_S:
754  yatitle = tr( "Sedimentation Coefficient" );
755  break;
756  default:
757  case ATTR_K:
758  yatitle = tr( "Frictional Ratio" );
759  break;
760  case ATTR_W:
761  yatitle = tr( "Molecular Weight" );
762  break;
763  case ATTR_V:
764  yatitle = tr( "Partial Specific Volume" );
765  break;
766  case ATTR_D:
767  yatitle = tr( "Diffusion Coefficient" );
768  break;
769  case ATTR_F:
770  yatitle = tr( "Frictional Coefficient" );
771  break;
772  }
773 
774  if ( selected_plot == 1 )
775  xatitle = tr( "Molecular Weight" );
776 
777  data_plot1->setAxisTitle( QwtPlot::xBottom, xatitle );
778  data_plot1->setAxisTitle( QwtPlot::yLeft, yatitle );
779 
780  //print_minmax();
781  int gridsize;
782  QVector <double> xData1;
783  QVector <double> yData1;
784  QVector <double> xData2;
785  QVector <double> yData2;
786 
787  int iplt_x = ( selected_plot == 0 ) ? plot_x : ATTR_W;
788 
789  xData1.clear();
790  yData1.clear();
791  xData2.clear();
792  yData2.clear();
793 
794  if ( ck_show_final_grid->isChecked() &&
795  !ck_show_sub_grid->isChecked())
796  {
797  gridsize = final_grid.size();
798 
799  for ( int ii = 0; ii < gridsize; ii++ )
800  {
801  if ( final_grid[ ii ].index == partialGrid )
802  {
803  xData1 << grid_value( final_grid[ ii ], iplt_x );
804  yData1 << grid_value( final_grid[ ii ], plot_y );
805  }
806 
807  else
808  {
809  xData2 << grid_value( final_grid[ ii ], iplt_x );
810  yData2 << grid_value( final_grid[ ii ], plot_y );
811  }
812  }
813 
814  QwtPlotCurve *c1;
815  QwtSymbol sym1;
816  sym1.setStyle( QwtSymbol::Ellipse );
817  sym1.setBrush( QColor( Qt::red ) );
818  sym1.setPen ( QColor( Qt::red ) );
819  sym1.setSize( 3 );
820 
821  c1 = us_curve( data_plot1, "highlighted Grid points" );
822  c1->setData ( xData1.data(), yData1.data(), xData1.size());
823  c1->setSymbol( sym1 );
824  c1->setStyle ( QwtPlotCurve::NoCurve );
825 
826  QwtPlotCurve *c2;
827  QwtSymbol sym2;
828  sym2.setStyle( QwtSymbol::Ellipse );
829  sym2.setBrush( QColor( Qt::yellow ) );
830  sym2.setPen ( QColor( Qt::yellow ) );
831  sym2.setSize( 3 );
832 
833  c2 = us_curve( data_plot1, "Other Grid points" );
834  c2->setData ( xData2.data(), yData2.data(), xData2.size());
835  c2->setSymbol( sym2 );
836  c2->setStyle ( QwtPlotCurve::NoCurve );
837  }
838 
839  else if ( ck_show_final_grid->isChecked() &&
840  ck_show_sub_grid->isChecked())
841  {
842  gridsize = final_grid.size();
843  int counter = 1;
844 
845  for ( int ii = 0; ii < gridsize; ii++ )
846  {
847  if ( counter == partialGrid )
848  {
849  xData1 << grid_value( final_grid[ ii ], iplt_x );
850  yData1 << grid_value( final_grid[ ii ], plot_y );
851  }
852 
853  else
854  {
855  xData2 << grid_value( final_grid[ ii ], iplt_x );
856  yData2 << grid_value( final_grid[ ii ], plot_y );
857  }
858 
859  counter++;
860 
861  if ( counter > subGrids )
862  counter = 1;
863  }
864 
865  QwtPlotCurve *c1;
866  QwtSymbol sym1;
867  sym1.setStyle( QwtSymbol::Ellipse );
868  sym1.setBrush( QColor( Qt::red ) );
869  sym1.setPen ( QColor( Qt::red ) );
870  sym1.setSize( 3 );
871 
872  c1 = us_curve( data_plot1, "highlighted Grid points" );
873  c1->setData ( xData1.data(), yData1.data(), xData1.size());
874  c1->setSymbol( sym1 );
875  c1->setStyle ( QwtPlotCurve::NoCurve );
876 
877  QwtPlotCurve *c2;
878  QwtSymbol sym2;
879  sym2.setStyle( QwtSymbol::Ellipse );
880  sym2.setBrush( QColor( Qt::yellow ) );
881  sym2.setPen ( QColor( Qt::yellow ) );
882  sym2.setSize( 3 );
883 
884  c2 = us_curve( data_plot1, "Other Grid points" );
885  c2->setData ( xData2.data(), yData2.data(), xData2.size());
886  c2->setSymbol( sym2 );
887  c2->setStyle ( QwtPlotCurve::NoCurve );
888  }
889 
890  else
891  { // Set up current grid plot
892  gridsize = current_grid.size();
893 qDebug() << " updplt: gridsize" << gridsize;
894  xData1.resize( gridsize );
895  yData1.resize( gridsize );
896 
897  for ( int ii = 0; ii < gridsize; ii++ )
898  {
899  xData1[ ii ] = grid_value( current_grid[ ii ], iplt_x );
900  yData1[ ii ] = grid_value( current_grid[ ii ], plot_y );
901  }
902 
903  QwtPlotCurve *c1;
904  QwtSymbol sym;
905  sym.setStyle( QwtSymbol::Ellipse );
906  sym.setBrush( QColor( Qt::yellow ) );
907  sym.setPen ( QColor( Qt::yellow ) );
908  sym.setSize( 3 );
909 
910  c1 = us_curve( data_plot1, "Grid points 1" );
911  c1->setData ( xData1.data(), yData1.data(), gridsize );
912  c1->setSymbol( sym );
913  c1->setStyle ( QwtPlotCurve::NoCurve );
914  }
915 
916 qDebug() << " up9)yRes" << yRes;
917  data_plot1->setAxisAutoScale( QwtPlot::xBottom );
918  data_plot1->setAxisAutoScale( QwtPlot::yLeft );
919  data_plot1->replot();
920 }
921 
922 // Calculate all grid points for the selected setting
924 {
925  struct gridpoint tmp_point;
926 qDebug() << "calc_g: px py pz" << plot_x << plot_y << plot_z;
927 
928 qDebug() << " cg1)yRes" << yRes;
929  current_grid.clear();
930  //bool flag = true;
931  maxgridpoint.s = -9.9e99;
932  maxgridpoint.D = 0.0;
933  maxgridpoint.vbar = 0.0;
934  maxgridpoint.mw = 0.0;
935  maxgridpoint.ff0 = 0.0;
936  maxgridpoint.f0 = 0.0;
937  maxgridpoint.f = 0.0;
938  mingridpoint.s = 9.9e99;
939  mingridpoint.D = 9.9e99;
940  mingridpoint.vbar = 9.9e99;
941  mingridpoint.mw = 9.9e99;
942  mingridpoint.ff0 = 9.9e99;
943  mingridpoint.f0 = 9.9e99;
944  mingridpoint.f = 9.9e99;
945 
946 qDebug() << " cg2)yRes" << yRes;
947  xRes = ct_xRes->value();
948  xMin = ct_xMin->value();
949  xMax = ct_xMax->value();
950  yRes = ct_yRes->value();
951  yMin = ct_yMin->value();
952  yMax = ct_yMax->value();
953  zVal = ct_zVal->value();
954  vbar = zVal;
955 qDebug() << " cg3)yRes" << yRes;
956  double xinc = ( xMax - xMin ) / ( xRes - 1.0 );
957  double yinc = ( yMax - yMin ) / ( yRes - 1.0 );
958  double xval = xMin;
959  double yval = yMin;
960  int nxvals = (int)xRes;
961  int nyvals = (int)yRes;
962  int nerr_w = 0;
963  int nerr_k = 0;
964  bool comp_ok = true;
965 qDebug() << "calc_g: zVal nx ny" << zVal << nxvals << nyvals
966  << "xMin xMax xinc" << xMin << xMax << xinc
967  << "yMin yMax yinc" << yMin << yMax << yinc;
968 
969  switch( plot_z )
970  {
971  case ATTR_S:
972  tmp_point.s = zVal;
973  break;
974  case ATTR_K:
975  tmp_point.ff0 = zVal;
976  break;
977  case ATTR_W:
978  tmp_point.mw = zVal;
979  break;
980  case ATTR_V:
981  tmp_point.vbar = zVal;
982  break;
983  case ATTR_D:
984  tmp_point.D = zVal;
985  break;
986  case ATTR_F:
987  tmp_point.f = zVal;
988  break;
989  }
990 qDebug() << " cg4)yRes" << yRes;
991  if ( plot_x != ATTR_V && plot_y != ATTR_V && plot_z != ATTR_V )
992  {
993 qDebug() << "calc_g: CG2";
995  }
997  else if ( plot_x == ATTR_S && plot_y == ATTR_K ) // s and f_f0
998  {
999  for ( int ii = 0; ii < nxvals; ii++ )
1000  {
1001  tmp_point.s = xval;
1002  xval += xinc;
1003  yval = yMin;
1004 
1005  for ( int jj = 0; jj < nyvals; jj++ )
1006  {
1007  tmp_point.ff0 = yval;
1008  yval += yinc;
1009 
1010  if ( set_comp_skv( tmp_point ) )
1011  {
1012  current_grid << tmp_point;
1013  set_minmax( tmp_point );
1014  }
1015  else
1016  nerr_w++;
1017  }
1018  }
1019 qDebug() << " cg5)yRes" << yRes;
1020  }
1022  else if ( plot_x == ATTR_S && plot_y == ATTR_W ) // s and mw
1023  {
1024  int lstiek = -1;
1025  int lstjek = -1;
1026  for ( int ii = 0; ii < nxvals; ii++ )
1027  {
1028  tmp_point.s = xval;
1029  xval += xinc;
1030  yval = yMin;
1031 
1032  for ( int jj = 0; jj < nyvals; jj++ )
1033  {
1034  tmp_point.mw = yval;
1035  yval += yinc;
1036 
1037  if ( set_comp_swv( tmp_point ) )
1038  {
1039  current_grid << tmp_point;
1040  set_minmax( tmp_point );
1041  }
1042  else
1043  nerr_w++;
1044 
1045  if ( tmp_point.ff0 < 1.0 )
1046  {
1047  nerr_k++;
1048  lstiek = ii;
1049  lstjek = jj;
1050 qDebug() << " ii jj" << ii << jj << "s w k" << tmp_point.s << tmp_point.mw
1051  << tmp_point.ff0;
1052  }
1053  }
1054  }
1055 qDebug() << " (0)ff0" << current_grid[0].ff0;
1056 qDebug() << " (n)ff0" << current_grid[nxvals*nyvals-1].ff0;
1057 qDebug() << " lstiek lstjek" << lstiek << lstjek << "nxy" << nxvals << nyvals;
1058  }
1060  else if ( plot_x == ATTR_S && plot_y == ATTR_V ) // s and vbar
1061  {
1062  for ( int ii = 0; ii < nxvals; ii++ )
1063  {
1064  tmp_point.s = xval;
1065  xval += xinc;
1066  yval = yMin;
1067 
1068  for ( int jj = 0; jj < nyvals; jj++ )
1069  {
1070  tmp_point.vbar = yval;
1071  yval += yinc;
1072 
1073  if ( plot_z == ATTR_K )
1074  comp_ok = set_comp_skv( tmp_point );
1075  else if ( plot_z == ATTR_W )
1076  comp_ok = set_comp_swv( tmp_point );
1077  else if ( plot_z == ATTR_D )
1078  comp_ok = set_comp_svd( tmp_point );
1079  else if ( plot_z == ATTR_F )
1080  comp_ok = set_comp_svf( tmp_point );
1081 
1082  if ( comp_ok )
1083  {
1084  current_grid << tmp_point;
1085  set_minmax( tmp_point );
1086  }
1087  else
1088  nerr_w++;
1089 
1090  if ( tmp_point.ff0 < 1.0 )
1091  nerr_k++;
1092  }
1093  }
1094  }
1096  else if ( plot_x == ATTR_S && plot_y == ATTR_D ) // s and D
1097  {
1098  for ( int ii = 0; ii < nxvals; ii++ )
1099  {
1100  tmp_point.s = xval;
1101  xval += xinc;
1102  yval = yMin;
1103 
1104  for ( int jj = 0; jj < nyvals; jj++ )
1105  {
1106  tmp_point.D = yval;
1107  yval += yinc;
1108 
1109  if ( set_comp_svd( tmp_point ) )
1110  {
1111  current_grid << tmp_point;
1112  set_minmax( tmp_point );
1113  }
1114  else
1115  nerr_w++;
1116 
1117  if ( tmp_point.ff0 < 1.0 )
1118  nerr_k++;
1119  }
1120  }
1121  }
1123  else if ( plot_x == ATTR_S && plot_y == ATTR_W ) // s and f
1124  {
1125  for ( int ii = 0; ii < nxvals; ii++ )
1126  {
1127  tmp_point.s = xval;
1128  xval += xinc;
1129  yval = yMin;
1130 
1131  for ( int jj = 0; jj < nyvals; jj++ )
1132  {
1133  tmp_point.f = yval;
1134  yval += yinc;
1135 
1136  if ( set_comp_swv( tmp_point ) )
1137  {
1138  current_grid << tmp_point;
1139  set_minmax( tmp_point );
1140  }
1141  else
1142  nerr_w++;
1143 
1144  if ( tmp_point.ff0 < 1.0 )
1145  nerr_k++;
1146  }
1147  }
1148  }
1150  else if ( plot_x == ATTR_K && plot_y == ATTR_S ) // ff0 and s
1151  {
1152  for ( int ii = 0; ii < nxvals; ii++ )
1153  {
1154  tmp_point.ff0 = xval;
1155  xval += xinc;
1156  yval = yMin;
1157 
1158  for ( int jj = 0; jj < nyvals; jj++ )
1159  {
1160  tmp_point.s = yval;
1161  yval += yinc;
1162 
1163  if ( set_comp_skv( tmp_point ) )
1164  {
1165  current_grid << tmp_point;
1166  set_minmax( tmp_point );
1167  }
1168  else
1169  nerr_w++;
1170  }
1171  }
1172  }
1174  else if ( plot_x == ATTR_K && plot_y == ATTR_W ) // ff0 and mw
1175  {
1176  for ( int ii = 0; ii < nxvals; ii++ )
1177  {
1178  tmp_point.ff0 = xval;
1179  xval += xinc;
1180  yval = yMin;
1181 
1182  for ( int jj = 0; jj < nyvals; jj++ )
1183  {
1184  tmp_point.mw = yval;
1185  yval += yinc;
1186 
1187  if ( set_comp_kwv( tmp_point ) )
1188  {
1189  current_grid << tmp_point;
1190  set_minmax( tmp_point );
1191  }
1192  else
1193  nerr_w++;
1194  }
1195  }
1196  }
1198  else if ( plot_x == ATTR_K && plot_y == ATTR_V ) // ff0 and vbar
1199  {
1200  for ( int ii = 0; ii < nxvals; ii++ )
1201  {
1202  tmp_point.ff0 = xval;
1203  xval += xinc;
1204  yval = yMin;
1205 
1206  for ( int jj = 0; jj < nyvals; jj++ )
1207  {
1208  tmp_point.vbar = yval;
1209  yval += yinc;
1210 
1211  if ( plot_z == ATTR_S )
1212  comp_ok = set_comp_skv( tmp_point );
1213  else if ( plot_z == ATTR_W )
1214  comp_ok = set_comp_kwv( tmp_point );
1215  else if ( plot_z == ATTR_D )
1216  comp_ok = set_comp_kvd( tmp_point );
1217  else if ( plot_z == ATTR_F )
1218  comp_ok = set_comp_kvf( tmp_point );
1219 
1220  if ( comp_ok )
1221  {
1222  current_grid << tmp_point;
1223  set_minmax( tmp_point );
1224  }
1225  else
1226  nerr_w++;
1227  }
1228  }
1229  }
1231  else if ( plot_x == ATTR_K && plot_y == ATTR_D ) // ff0 and D
1232  {
1233  for ( int ii = 0; ii < nxvals; ii++ )
1234  {
1235  tmp_point.ff0 = xval;
1236  xval += xinc;
1237  yval = yMin;
1238 
1239  for ( int jj = 0; jj < nyvals; jj++ )
1240  {
1241  tmp_point.D = yval;
1242  yval += yinc;
1243 
1244  if ( set_comp_kvd( tmp_point ) )
1245  {
1246  current_grid << tmp_point;
1247  set_minmax( tmp_point );
1248  }
1249  else
1250  nerr_w++;
1251  }
1252  }
1253  }
1255  else if ( plot_x == ATTR_K && plot_y == ATTR_F ) // ff0 and f
1256  {
1257  for ( int ii = 0; ii < nxvals; ii++ )
1258  {
1259  tmp_point.ff0 = xval;
1260  xval += xinc;
1261  yval = yMin;
1262 
1263  for ( int jj = 0; jj < nyvals; jj++ )
1264  {
1265  tmp_point.f = yval;
1266  yval += yinc;
1267 
1268  if ( set_comp_kvf( tmp_point ) )
1269  {
1270  current_grid << tmp_point;
1271  set_minmax( tmp_point );
1272  }
1273  else
1274  nerr_w++;
1275  }
1276  }
1277  }
1279  else if ( plot_x == ATTR_W && plot_y == ATTR_S ) // mw and s
1280  {
1281  for ( int ii = 0; ii < nxvals; ii++ )
1282  {
1283  tmp_point.mw = xval;
1284  xval += xinc;
1285  yval = yMin;
1286 
1287  for ( int jj = 0; jj < nyvals; jj++ )
1288  {
1289  tmp_point.s = yval;
1290  yval += yinc;
1291 
1292  if ( set_comp_swv( tmp_point ) )
1293  {
1294  current_grid << tmp_point;
1295  set_minmax( tmp_point );
1296  }
1297  else
1298  nerr_w++;
1299 
1300  if ( tmp_point.ff0 < 1.0 )
1301  nerr_k++;
1302  }
1303  }
1304  }
1306  else if ( plot_x == ATTR_W && plot_y == ATTR_K ) // mw and f/f0
1307  {
1308  for ( int ii = 0; ii < nxvals; ii++ )
1309  {
1310  tmp_point.mw = xval;
1311  xval += xinc;
1312  yval = yMin;
1313 
1314  for ( int jj = 0; jj < nyvals; jj++ )
1315  {
1316  tmp_point.ff0 = yval;
1317  yval += yinc;
1318 
1319  if ( set_comp_kwv( tmp_point ) )
1320  {
1321  current_grid << tmp_point;
1322  set_minmax( tmp_point );
1323  }
1324  else
1325  nerr_w++;
1326  }
1327  }
1328  }
1330  else if ( plot_x == ATTR_W && plot_y == ATTR_V ) // mw and vbar
1331  {
1332  for ( int ii = 0; ii < nxvals; ii++ )
1333  {
1334  tmp_point.mw = xval;
1335  xval += xinc;
1336  yval = yMin;
1337 
1338  for ( int jj = 0; jj < nyvals; jj++ )
1339  {
1340  tmp_point.vbar = yval;
1341  yval += yinc;
1342 
1343  if ( plot_z == ATTR_S )
1344  comp_ok = set_comp_swv( tmp_point );
1345  else if ( plot_z == ATTR_K )
1346  comp_ok = set_comp_kwv( tmp_point );
1347  else if ( plot_z == ATTR_D )
1348  comp_ok = set_comp_wvd( tmp_point );
1349  else if ( plot_z == ATTR_F )
1350  comp_ok = set_comp_wvf( tmp_point );
1351 
1352  if ( comp_ok )
1353  {
1354  current_grid << tmp_point;
1355  set_minmax( tmp_point );
1356  }
1357  else
1358  nerr_w++;
1359 
1360  if ( tmp_point.ff0 < 1.0 )
1361  nerr_k++;
1362  }
1363  }
1364  }
1366  else if ( plot_x == ATTR_W && plot_y == ATTR_D ) // mw and D
1367  {
1368  for ( int ii = 0; ii < nxvals; ii++ )
1369  {
1370  tmp_point.mw = xval;
1371  xval += xinc;
1372  yval = yMin;
1373 
1374  for ( int jj = 0; jj < nyvals; jj++ )
1375  {
1376  tmp_point.D = yval;
1377  yval += yinc;
1378 
1379  if ( set_comp_wvd( tmp_point ) )
1380  {
1381  current_grid << tmp_point;
1382  set_minmax( tmp_point );
1383  }
1384  else
1385  nerr_w++;
1386 
1387  if ( tmp_point.ff0 < 1.0 )
1388  nerr_k++;
1389  }
1390  }
1391  }
1393  else if ( plot_x == ATTR_W && plot_y == ATTR_F ) // mw and f
1394  {
1395  for ( int ii = 0; ii < nxvals; ii++ )
1396  {
1397  tmp_point.mw = xval;
1398  xval += xinc;
1399  yval = yMin;
1400 
1401  for ( int jj = 0; jj < nyvals; jj++ )
1402  {
1403  tmp_point.f = yval;
1404  yval += yinc;
1405 
1406  if ( set_comp_wvf( tmp_point ) )
1407  {
1408  current_grid << tmp_point;
1409  set_minmax( tmp_point );
1410  }
1411  else
1412  nerr_w++;
1413 
1414  if ( tmp_point.ff0 < 1.0 )
1415  nerr_k++;
1416  }
1417  }
1418  }
1420  else if ( plot_x == ATTR_V && plot_y == ATTR_S ) // vbar and s
1421  {
1422  for ( int ii = 0; ii < nxvals; ii++ )
1423  {
1424  tmp_point.vbar = xval;
1425  xval += xinc;
1426  yval = yMin;
1427 
1428  for ( int jj = 0; jj < nyvals; jj++ )
1429  {
1430  tmp_point.s = yval;
1431  yval += yinc;
1432 
1433  if ( plot_z == ATTR_K )
1434  comp_ok = set_comp_skv( tmp_point );
1435  else if ( plot_z == ATTR_W )
1436  comp_ok = set_comp_swv( tmp_point );
1437  else if ( plot_z == ATTR_D )
1438  comp_ok = set_comp_svd( tmp_point );
1439  else if ( plot_z == ATTR_F )
1440  comp_ok = set_comp_svf( tmp_point );
1441 
1442  if ( comp_ok )
1443  {
1444  current_grid << tmp_point;
1445  set_minmax( tmp_point );
1446  }
1447  else
1448  nerr_w++;
1449 
1450  if ( tmp_point.ff0 < 1.0 )
1451  nerr_k++;
1452  }
1453  }
1454  }
1456  else if ( plot_x == ATTR_V && plot_y == ATTR_K ) // vbar and ff0
1457  {
1458  for ( int ii = 0; ii < nxvals; ii++ )
1459  {
1460  tmp_point.vbar = xval;
1461  xval += xinc;
1462  yval = yMin;
1463 
1464  for ( int jj = 0; jj < nyvals; jj++ )
1465  {
1466  tmp_point.ff0 = yval;
1467  yval += yinc;
1468 
1469  if ( plot_z == ATTR_S )
1470  comp_ok = set_comp_skv( tmp_point );
1471  else if ( plot_z == ATTR_W )
1472  comp_ok = set_comp_kwv( tmp_point );
1473  else if ( plot_z == ATTR_D )
1474  comp_ok = set_comp_kvd( tmp_point );
1475  else if ( plot_z == ATTR_F )
1476  comp_ok = set_comp_kvf( tmp_point );
1477 
1478  if ( comp_ok )
1479  {
1480  current_grid << tmp_point;
1481  set_minmax( tmp_point );
1482  }
1483  else
1484  nerr_w++;
1485  }
1486  }
1487  }
1489  else if ( plot_x == ATTR_V && plot_y == ATTR_W ) // vbar and mw
1490  {
1491  for ( int ii = 0; ii < nxvals; ii++ )
1492  {
1493  tmp_point.vbar = xval;
1494  xval += xinc;
1495  yval = yMin;
1496 
1497  for ( int jj = 0; jj < nyvals; jj++ )
1498  {
1499  tmp_point.mw = yval;
1500  yval += yinc;
1501 
1502  if ( plot_z == ATTR_S )
1503  comp_ok = set_comp_swv( tmp_point );
1504  else if ( plot_z == ATTR_K )
1505  comp_ok = set_comp_kwv( tmp_point );
1506  else if ( plot_z == ATTR_D )
1507  comp_ok = set_comp_wvd( tmp_point );
1508  else if ( plot_z == ATTR_F )
1509  comp_ok = set_comp_wvf( tmp_point );
1510 
1511  if ( comp_ok )
1512  {
1513  current_grid << tmp_point;
1514  set_minmax( tmp_point );
1515  }
1516  else
1517  nerr_w++;
1518 
1519  if ( tmp_point.ff0 < 1.0 )
1520  nerr_k++;
1521  }
1522  }
1523  }
1525  else if ( plot_x == ATTR_V && plot_y == ATTR_D ) // vbar and D
1526  {
1527  for ( int ii = 0; ii < nxvals; ii++ )
1528  {
1529  tmp_point.vbar = xval;
1530  xval += xinc;
1531  yval = yMin;
1532 
1533  for ( int jj = 0; jj < nyvals; jj++ )
1534  {
1535  tmp_point.D = yval;
1536  yval += yinc;
1537 
1538  if ( plot_z == ATTR_S )
1539  comp_ok = set_comp_svd( tmp_point );
1540  else if ( plot_z == ATTR_K )
1541  comp_ok = set_comp_kvd( tmp_point );
1542  else if ( plot_z == ATTR_W )
1543  comp_ok = set_comp_wvd( tmp_point );
1544  else if ( plot_z == ATTR_F )
1545  comp_ok = set_comp_vdf( tmp_point );
1546 
1547  if ( comp_ok )
1548  {
1549  current_grid << tmp_point;
1550  set_minmax( tmp_point );
1551  }
1552  else
1553  nerr_w++;
1554 
1555  if ( tmp_point.ff0 < 1.0 )
1556  nerr_k++;
1557  }
1558  }
1559  }
1561  else if ( plot_x == ATTR_V && plot_y == ATTR_F ) // vbar and f
1562  {
1563  for ( int ii = 0; ii < nxvals; ii++ )
1564  {
1565  tmp_point.vbar = xval;
1566  xval += xinc;
1567  yval = yMin;
1568 
1569  for ( int jj = 0; jj < nyvals; jj++ )
1570  {
1571  tmp_point.f = yval;
1572  yval += yinc;
1573 
1574  if ( plot_z == ATTR_S )
1575  comp_ok = set_comp_svf( tmp_point );
1576  else if ( plot_z == ATTR_K )
1577  comp_ok = set_comp_kvf( tmp_point );
1578  else if ( plot_z == ATTR_W )
1579  comp_ok = set_comp_wvf( tmp_point );
1580  else if ( plot_z == ATTR_D )
1581  comp_ok = set_comp_vdf( tmp_point );
1582 
1583  if ( comp_ok )
1584  {
1585  current_grid << tmp_point;
1586  set_minmax( tmp_point );
1587  }
1588  else
1589  nerr_w++;
1590 
1591  if ( tmp_point.ff0 < 1.0 )
1592  nerr_k++;
1593  }
1594  }
1595  }
1597  else if ( plot_x == ATTR_D && plot_y == ATTR_S ) // D and s
1598  {
1599  for ( int ii = 0; ii < nxvals; ii++ )
1600  {
1601  tmp_point.D = xval;
1602  xval += xinc;
1603  yval = yMin;
1604 
1605  for ( int jj = 0; jj < nyvals; jj++ )
1606  {
1607  tmp_point.s = yval;
1608  yval += yinc;
1609 
1610  if ( set_comp_svd( tmp_point ) )
1611  {
1612  current_grid << tmp_point;
1613  set_minmax( tmp_point );
1614  }
1615  else
1616  nerr_w++;
1617 
1618  if ( tmp_point.ff0 < 1.0 )
1619  nerr_k++;
1620  }
1621  }
1622  }
1624  else if ( plot_x == ATTR_D && plot_y == ATTR_K ) // D and ff0
1625  {
1626  for ( int ii = 0; ii < nxvals; ii++ )
1627  {
1628  tmp_point.D = xval;
1629  xval += xinc;
1630  yval = yMin;
1631 
1632  for ( int jj = 0; jj < nyvals; jj++ )
1633  {
1634  tmp_point.ff0 = yval;
1635  yval += yinc;
1636 
1637  if ( set_comp_kvd( tmp_point ) )
1638  {
1639  current_grid << tmp_point;
1640  set_minmax( tmp_point );
1641  }
1642  else
1643  nerr_w++;
1644  }
1645  }
1646  }
1648  else if ( plot_x == ATTR_D && plot_y == ATTR_W ) // D and mw
1649  {
1650  for ( int ii = 0; ii < nxvals; ii++ )
1651  {
1652  tmp_point.D = xval;
1653  xval += xinc;
1654  yval = yMin;
1655 
1656  for ( int jj = 0; jj < nyvals; jj++ )
1657  {
1658  tmp_point.mw = yval;
1659  yval += yinc;
1660 
1661  if ( set_comp_wvd( tmp_point ) )
1662  {
1663  current_grid << tmp_point;
1664  set_minmax( tmp_point );
1665  }
1666  else
1667  nerr_w++;
1668 
1669  if ( tmp_point.ff0 < 1.0 )
1670  nerr_k++;
1671  }
1672  }
1673  }
1675  else if ( plot_x == ATTR_D && plot_y == ATTR_V ) // D and vbar
1676  {
1677  for ( int ii = 0; ii < nxvals; ii++ )
1678  {
1679  tmp_point.D = xval;
1680  xval += xinc;
1681  yval = yMin;
1682 
1683  for ( int jj = 0; jj < nyvals; jj++ )
1684  {
1685  tmp_point.vbar = yval;
1686  yval += yinc;
1687 
1688  if ( plot_z == ATTR_S )
1689  comp_ok = set_comp_svd( tmp_point );
1690  else if ( plot_z == ATTR_K )
1691  comp_ok = set_comp_kvd( tmp_point );
1692  else if ( plot_z == ATTR_W )
1693  comp_ok = set_comp_wvd( tmp_point );
1694  else if ( plot_z == ATTR_F )
1695  comp_ok = set_comp_vdf( tmp_point );
1696 
1697  if ( comp_ok )
1698  {
1699  current_grid << tmp_point;
1700  set_minmax( tmp_point );
1701  }
1702  else
1703  nerr_w++;
1704 
1705  if ( tmp_point.ff0 < 1.0 )
1706  nerr_k++;
1707  }
1708  }
1709  }
1711  else if ( plot_x == ATTR_D && plot_y == ATTR_F ) // D and f
1712  {
1713  for ( int ii = 0; ii < nxvals; ii++ )
1714  {
1715  tmp_point.D = xval;
1716  xval += xinc;
1717  yval = yMin;
1718 
1719  for ( int jj = 0; jj < nyvals; jj++ )
1720  {
1721  tmp_point.f = yval;
1722  yval += yinc;
1723 
1724  if ( set_comp_vdf( tmp_point ) )
1725  {
1726  current_grid << tmp_point;
1727  set_minmax( tmp_point );
1728  }
1729  else
1730  nerr_w++;
1731 
1732  if ( tmp_point.ff0 < 1.0 )
1733  nerr_k++;
1734  }
1735  }
1736  }
1738  else if ( plot_x == ATTR_F && plot_y == ATTR_S ) // f and s
1739  {
1740  for ( int ii = 0; ii < nxvals; ii++ )
1741  {
1742  tmp_point.f = xval;
1743  xval += xinc;
1744  yval = yMin;
1745 
1746  for ( int jj = 0; jj < nyvals; jj++ )
1747  {
1748  tmp_point.s = yval;
1749  yval += yinc;
1750 
1751  if ( set_comp_svf( tmp_point ) )
1752  {
1753  current_grid << tmp_point;
1754  set_minmax( tmp_point );
1755  }
1756  else
1757  nerr_w++;
1758 
1759  if ( tmp_point.ff0 < 1.0 )
1760  nerr_k++;
1761  }
1762  }
1763  }
1765  else if ( plot_x == ATTR_F && plot_y == ATTR_K ) // f and ff0
1766  {
1767  for ( int ii = 0; ii < nxvals; ii++ )
1768  {
1769  tmp_point.f = xval;
1770  xval += xinc;
1771  yval = yMin;
1772 
1773  for ( int jj = 0; jj < nyvals; jj++ )
1774  {
1775  tmp_point.ff0 = yval;
1776  yval += yinc;
1777 
1778  if ( set_comp_kvf( tmp_point ) )
1779  {
1780  current_grid << tmp_point;
1781  set_minmax( tmp_point );
1782  }
1783  else
1784  nerr_w++;
1785  }
1786  }
1787  }
1789  else if ( plot_x == ATTR_F && plot_y == ATTR_W ) // f and mw
1790  {
1791  for ( int ii = 0; ii < nxvals; ii++ )
1792  {
1793  tmp_point.f = xval;
1794  xval += xinc;
1795  yval = yMin;
1796 
1797  for ( int jj = 0; jj < nyvals; jj++ )
1798  {
1799  tmp_point.mw = yval;
1800  yval += yinc;
1801 
1802  if ( set_comp_wvf( tmp_point ) )
1803  {
1804  current_grid << tmp_point;
1805  set_minmax( tmp_point );
1806  }
1807  else
1808  nerr_w++;
1809 
1810  if ( tmp_point.ff0 < 1.0 )
1811  nerr_k++;
1812  }
1813  }
1814  }
1816  else if ( plot_x == ATTR_F && plot_y == ATTR_V ) // f and vbar
1817  {
1818  for ( int ii = 0; ii < nxvals; ii++ )
1819  {
1820  tmp_point.f = xval;
1821  xval += xinc;
1822  yval = yMin;
1823 
1824  for ( int jj = 0; jj < nyvals; jj++ )
1825  {
1826  tmp_point.vbar = yval;
1827  yval += yinc;
1828 
1829  if ( plot_z == ATTR_S )
1830  comp_ok = set_comp_svf( tmp_point );
1831  else if ( plot_z == ATTR_K )
1832  comp_ok = set_comp_kvf( tmp_point );
1833  else if ( plot_z == ATTR_W )
1834  comp_ok = set_comp_wvf( tmp_point );
1835  else if ( plot_z == ATTR_D )
1836  comp_ok = set_comp_vdf( tmp_point );
1837 
1838  if ( comp_ok )
1839  {
1840  current_grid << tmp_point;
1841  set_minmax( tmp_point );
1842  }
1843  else
1844  nerr_w++;
1845 
1846  if ( tmp_point.ff0 < 1.0 )
1847  nerr_k++;
1848  }
1849  }
1850  }
1852  else if ( plot_x == ATTR_F && plot_y == ATTR_D ) // f and D
1853  {
1854  for ( int ii = 0; ii < nxvals; ii++ )
1855  {
1856  tmp_point.f = xval;
1857  xval += xinc;
1858  yval = yMin;
1859 
1860  for ( int jj = 0; jj < nyvals; jj++ )
1861  {
1862  tmp_point.D = yval;
1863  yval += yinc;
1864 
1865  if ( set_comp_vdf( tmp_point ) )
1866  {
1867  current_grid << tmp_point;
1868  set_minmax( tmp_point );
1869  }
1870  else
1871  nerr_w++;
1872 
1873  if ( tmp_point.ff0 < 1.0 )
1874  nerr_k++;
1875  }
1876  }
1877  }
1878 qDebug() << "calc_g: xval yval" << xval << yval
1879  << "gsize" << current_grid.size();
1880 
1881  if ( nerr_w > 0 || nerr_k > 0 || current_grid.size() == 0 )
1882  {
1883  QString wmsg;
1884 
1885  if ( plot_x != ATTR_V && plot_y != ATTR_V && plot_z != ATTR_V )
1886  {
1887  wmsg = tr( "Presently, one of the axes or the fixed attribute "
1888  "must be Partial Specific Volume (vbar). Please "
1889  "select the Axis types and Fixed attribute so that "
1890  "one of them is Partial Specific Volume." );
1891  }
1892 
1893  else if ( nerr_w > 0 )
1894  {
1895  wmsg = tr( "You have selected a nonsensical parameter setting. "
1896  "The product of the sedimentation coefficient, s, "
1897  "and the buoyancy term, (1 - vbar * Density), "
1898  "must be positive. Please examine your settings for "
1899  "the sedimentation coefficient range, the density, "
1900  "and the partial specific volume before proceeding." );
1901  }
1902 
1903  else if ( nerr_k > 0 )
1904  {
1905  wmsg = tr( "You have selected a set of parameter settings that "
1906  "result in f/f0 value(s) less than 1. "
1907  "Please adjust the fixed value or ranges so that "
1908  "the frictional ratio is at least 1." );
1909  }
1910 
1911  else
1912  {
1913  wmsg = tr( "Grid size is zero" );
1914  }
1915 
1916  QMessageBox::warning( this,
1917  tr( "Invalid Attributes/Parameters" ),
1918  wmsg );
1919  }
1920 }
1921 
1922 // Calculate all grid points for the selected setting (vbar unspecified)
1924 {
1925  current_grid.clear();
1926 #if 0 // Currently, we simply do not handle cases with no vbar given
1927  //bool flag = true;
1928  maxgridpoint.s = -9.9e99;
1929  maxgridpoint.D = 0.0;
1930  maxgridpoint.vbar = 0.0;
1931  maxgridpoint.mw = 0.0;
1932  maxgridpoint.ff0 = 0.0;
1933  maxgridpoint.f0 = 0.0;
1934  maxgridpoint.f = 0.0;
1935  mingridpoint.s = 9.9e99;
1936  mingridpoint.D = 9.9e99;
1937  mingridpoint.vbar = 9.9e99;
1938  mingridpoint.mw = 9.9e99;
1939  mingridpoint.ff0 = 9.9e99;
1940  mingridpoint.f0 = 9.9e99;
1941  mingridpoint.f = 9.9e99;
1942  struct gridpoint tmp_point;
1943  double zVal = ct_zVal->value();
1944  double xinc = ( xMax - xMin ) / ( xRes - 1.0 );
1945  double yinc = ( yMax - yMin ) / ( yRes - 1.0 );
1946  double xval = xMin;
1947  double yval = yMin;
1948  int nxvals = (int)xRes;
1949  int nyvals = (int)yRes;
1950 
1951  switch( plot_z )
1952  {
1953  case ATTR_S:
1954  tmp_point.s = zVal;
1955  break;
1956  case ATTR_K:
1957  tmp_point.ff0 = zVal;
1958  break;
1959  case ATTR_W:
1960  tmp_point.mw = zVal;
1961  break;
1962  case ATTR_V:
1963  tmp_point.vbar = zVal;
1964  break;
1965  case ATTR_D:
1966  tmp_point.D = zVal;
1967  break;
1968  case ATTR_F:
1969  tmp_point.f = zVal;
1970  break;
1971  }
1972 #endif
1973 
1974  return;
1975 }
1976 
1977 // add current grid to the list of grids
1979 {
1980  grid_index++;
1981  for (int i=0; i<current_grid.size(); i++)
1982  {
1983  //check for overlaps first...
1984  current_grid[i].index = grid_index;
1985  final_grid.push_back(current_grid[i]);
1986  }
1987  pb_save->setEnabled( true );
1988  ck_show_final_grid->setEnabled( true );
1989  pb_delete_partialGrid->setEnabled( true );
1990  ct_partialGrid->setEnabled( true );
1991 }
1992 
1993 // delete current grid
1995 {
1996  for (int i=final_grid.size() - 1; i>=0; i--)
1997  {
1998  if (final_grid[i].index == partialGrid)
1999  {
2000  final_grid.removeAt(i);
2001  }
2002  }
2003  // renumber index positions
2004  for (int i=0; i<final_grid.size(); i++)
2005  {
2006  if (final_grid[i].index > partialGrid)
2007  {
2008  final_grid[i].index--;
2009  }
2010  }
2011  grid_index--;
2012  ct_partialGrid->setRange( 1, grid_index, 1 );
2013  if (grid_index == 0)
2014  {
2015  ck_show_final_grid->setChecked (false);
2016  ck_show_final_grid->setEnabled (false);
2017  ct_partialGrid->setRange (0, 0, 1);
2018  ct_partialGrid->setEnabled( false );
2019  show_final_grid( false );
2020  }
2021  update_plot();
2022 }
2023 
2024 // find the minimum and maximum in a grid
2025 void US_Grid_Editor::set_minmax( const struct gridpoint & tmp_point)
2026 {
2027  mingridpoint.s = qMin( mingridpoint.s, tmp_point.s );
2028  mingridpoint.D = qMin( mingridpoint.D, tmp_point.D );
2029  mingridpoint.vbar = qMin( mingridpoint.vbar, tmp_point.vbar );
2030  mingridpoint.mw = qMin( mingridpoint.mw, tmp_point.mw );
2031  mingridpoint.ff0 = qMin( mingridpoint.ff0, tmp_point.ff0 );
2032  mingridpoint.f0 = qMin( mingridpoint.f0, tmp_point.f0 );
2033  mingridpoint.f = qMin( mingridpoint.f, tmp_point.f );
2034  maxgridpoint.s = qMax( maxgridpoint.s, tmp_point.s );
2035  maxgridpoint.D = qMax( maxgridpoint.D, tmp_point.D );
2036  maxgridpoint.vbar = qMax( maxgridpoint.vbar, tmp_point.vbar );
2037  maxgridpoint.mw = qMax( maxgridpoint.mw, tmp_point.mw );
2038  maxgridpoint.ff0 = qMax( maxgridpoint.ff0, tmp_point.ff0 );
2039  maxgridpoint.f0 = qMax( maxgridpoint.f0, tmp_point.f0 );
2040  maxgridpoint.f = qMax( maxgridpoint.f, tmp_point.f );
2041 }
2042 
2043 // find the minimum and maximum in a grid
2045 {
2046  DbgLv(1) << "min s:" << mingridpoint.s
2047  << "\nmin D:" << mingridpoint.D
2048  << "\nmin vbar:" << mingridpoint.vbar
2049  << "\nmin MW:" << mingridpoint.mw
2050  << "\nmin f/f0:" << mingridpoint.ff0
2051  << "\nmin f0:" << mingridpoint.f0
2052  << "\nmin f:" << mingridpoint.f
2053  << "\nmax s:" << maxgridpoint.s
2054  << "\nmax D:" << maxgridpoint.D
2055  << "\nmax vbar:" << maxgridpoint.vbar
2056  << "\nmax mw:" << maxgridpoint.mw
2057  << "\nmax f/f0:" << maxgridpoint.ff0
2058  << "\nmax f0:" << maxgridpoint.f0
2059  << "\nmax f:" << maxgridpoint.f << "\n";
2060 }
2061 
2062 // Select plot1 (X-axis view) or plot2 (Molecular Weight view)
2064 {
2065  selected_plot = ival;
2066 
2067  update_plot();
2068 }
2069 
2070 // Select coordinate for horizontal axis
2072 {
2073  // Axis types s f/f0 mw vbar D f
2074  const double xvmns[] = { 1.0, 1.0, 2e+4, 0.60, 1e-8, 1e-8 };
2075  const double xvmxs[] = { 10.0, 4.0, 1e+5, 0.80, 1e-7, 1e-7 };
2076  const double xmins[] = { -10000.0, 1.0, 0.0, 0.01, 1e-9, 1e-9 };
2077  const double xmaxs[] = { 10000.0, 50.0, 1e+10, 3.00, 1e-5, 1e-5 };
2078  const double xincs[] = { 0.01, 0.01, 1000.0, 0.01, 1e-9, 1e-9 };
2079  const QString xtitls[] = { tr( "s (x 1e13)" ),
2080  tr( "f/f0-value" ),
2081  tr( "mw-value" ),
2082  tr( "vbar-value" ),
2083  tr( "D-value" ),
2084  tr( "f-value" ) };
2085  plot_x = ival;
2086 
2087  lb_xRes->setText( xtitls[ plot_x ] + tr( " Resolution:" ) );
2088  lb_xMin->setText( xtitls[ plot_x ] + tr( " Minimum:" ) );
2089  lb_xMax->setText( xtitls[ plot_x ] + tr( " Maximum:" ) );
2090  ct_xMin->disconnect();
2091  ct_xMax->disconnect();
2092  xMin = xvmns[ plot_x ];
2093  xMax = xvmxs[ plot_x ];
2094  ct_xMin->setRange( xmins[ plot_x ], xmaxs[ plot_x ], xincs[ plot_x ] );
2095  ct_xMax->setRange( xmins[ plot_x ], xmaxs[ plot_x ], xincs[ plot_x ] );
2096  ct_xMin->setValue( xMin );
2097  ct_xMax->setValue( xMax );
2098 
2099  connect( ct_xMin, SIGNAL( valueChanged( double ) ),
2100  this, SLOT ( update_xMin ( double ) ) );
2101  connect( ct_xMax, SIGNAL( valueChanged( double ) ),
2102  this, SLOT ( update_xMax ( double ) ) );
2103 
2104  rb_y_s ->setEnabled( plot_x != ATTR_S );
2105  rb_y_ff0 ->setEnabled( plot_x != ATTR_K );
2106  rb_y_mw ->setEnabled( plot_x != ATTR_W );
2107  rb_y_vbar->setEnabled( plot_x != ATTR_V );
2108  rb_y_D ->setEnabled( plot_x != ATTR_D );
2109  rb_y_f ->setEnabled( plot_x != ATTR_F );
2110  rb_x_s ->setEnabled( plot_y != ATTR_S );
2111  rb_x_ff0 ->setEnabled( plot_y != ATTR_K );
2112  rb_x_mw ->setEnabled( plot_y != ATTR_W );
2113  rb_x_vbar->setEnabled( plot_y != ATTR_V );
2114  rb_x_D ->setEnabled( plot_y != ATTR_D );
2115  rb_x_f ->setEnabled( plot_y != ATTR_F );
2116 
2117  cb_fixed->disconnect();
2118  cb_fixed->clear();
2119  if ( plot_x != ATTR_V && plot_y != ATTR_V )
2120  cb_fixed->addItem( tr( "Partial Specific Volume" ) );
2121  if ( plot_x != ATTR_K && plot_y != ATTR_K )
2122  cb_fixed->addItem( tr( "Frictional Ratio" ) );
2123  if ( plot_x != ATTR_W && plot_y != ATTR_W )
2124  cb_fixed->addItem( tr( "Molecular Weight" ) );
2125  if ( plot_x != ATTR_S && plot_y != ATTR_S )
2126  cb_fixed->addItem( tr( "Sedimentation Coefficient" ) );
2127  if ( plot_x != ATTR_D && plot_y != ATTR_D )
2128  cb_fixed->addItem( tr( "Diffusion Coefficient" ) );
2129  if ( plot_x != ATTR_F && plot_y != ATTR_F )
2130  cb_fixed->addItem( tr( "Frictional Coefficient" ) );
2131  cb_fixed->setCurrentIndex( 0 );
2132  select_fixed( cb_fixed->currentText() );
2133  connect( cb_fixed, SIGNAL( activated ( const QString& ) ),
2134  this, SLOT ( select_fixed( const QString& ) ) );
2135 
2136  validate_ff0();
2137 
2138  update_plot();
2139 }
2140 
2141 // select coordinate for vertical axis
2143 {
2144  // Axis types s f/f0 mw vbar D f
2145  const double yvmns[] = { 1.0, 1.0, 2e+4, 0.60, 1e-8, 1e-8 };
2146  const double yvmxs[] = { 10.0, 4.0, 1e+6, 0.80, 1e-7, 1e-7 };
2147  const double ymins[] = { -10000.0, 1.0, 0.0, 0.01, 1e-9, 1e-9 };
2148  const double ymaxs[] = { 10000.0, 50.0, 1e+10, 3.00, 1e-5, 1e-5 };
2149  const double yincs[] = { 0.01, 0.01, 1000.0, 0.01, 1e-9, 1e-9 };
2150  const QString ytitls[] = { tr( "s (x 1e13)" ),
2151  tr( "f/f0-value" ),
2152  tr( "mw-value" ),
2153  tr( "vbar-value" ),
2154  tr( "D-value" ),
2155  tr( "f-value" ) };
2156  plot_y = ival;
2157 
2158  lb_yRes->setText( ytitls[ plot_y ] + tr( " Resolution:" ) );
2159  lb_yMin->setText( ytitls[ plot_y ] + tr( " Minimum:" ) );
2160  lb_yMax->setText( ytitls[ plot_y ] + tr( " Maximum:" ) );
2161  ct_yMin->disconnect();
2162  ct_yMax->disconnect();
2163  yMin = yvmns[ plot_y ];
2164  yMax = yvmxs[ plot_y ];
2165  ct_yMin->setRange( ymins[ plot_y ], ymaxs[ plot_y ], yincs[ plot_y ] );
2166  ct_yMax->setRange( ymins[ plot_y ], ymaxs[ plot_y ], yincs[ plot_y ] );
2167  ct_yMin->setValue( yMin );
2168  ct_yMax->setValue( yMax );
2169 
2170  connect( ct_yMin, SIGNAL( valueChanged( double ) ),
2171  this, SLOT ( update_yMin ( double ) ) );
2172  connect( ct_yMax, SIGNAL( valueChanged( double ) ),
2173  this, SLOT ( update_yMax ( double ) ) );
2174 
2175  rb_x_s ->setEnabled( plot_y != ATTR_S );
2176  rb_x_ff0 ->setEnabled( plot_y != ATTR_K );
2177  rb_x_mw ->setEnabled( plot_y != ATTR_W );
2178  rb_x_vbar->setEnabled( plot_y != ATTR_V );
2179  rb_x_D ->setEnabled( plot_y != ATTR_D );
2180  rb_x_f ->setEnabled( plot_y != ATTR_F );
2181  rb_y_s ->setEnabled( plot_x != ATTR_S );
2182  rb_y_ff0 ->setEnabled( plot_x != ATTR_K );
2183  rb_y_mw ->setEnabled( plot_x != ATTR_W );
2184  rb_y_vbar->setEnabled( plot_x != ATTR_V );
2185  rb_y_D ->setEnabled( plot_x != ATTR_D );
2186  rb_y_f ->setEnabled( plot_x != ATTR_F );
2187 
2188  cb_fixed->disconnect();
2189  cb_fixed->clear();
2190  if ( plot_x != ATTR_V && plot_y != ATTR_V )
2191  cb_fixed->addItem( tr( "Partial Specific Volume" ) );
2192  if ( plot_x != ATTR_K && plot_y != ATTR_K )
2193  cb_fixed->addItem( tr( "Frictional Ratio" ) );
2194  if ( plot_x != ATTR_W && plot_y != ATTR_W )
2195  cb_fixed->addItem( tr( "Molecular Weight" ) );
2196  if ( plot_x != ATTR_S && plot_y != ATTR_S )
2197  cb_fixed->addItem( tr( "Sedimentation Coefficient" ) );
2198  if ( plot_x != ATTR_D && plot_y != ATTR_D )
2199  cb_fixed->addItem( tr( "Diffusion Coefficient" ) );
2200  if ( plot_x != ATTR_F && plot_y != ATTR_F )
2201  cb_fixed->addItem( tr( "Frictional Coefficient" ) );
2202  cb_fixed->setCurrentIndex( 0 );
2203  select_fixed( cb_fixed->currentText() );
2204  connect( cb_fixed, SIGNAL( activated ( const QString& ) ),
2205  this, SLOT ( select_fixed( const QString& ) ) );
2206 
2207  validate_ff0();
2208 
2209  update_plot();
2210 }
2211 
2212 // Select coordinate flag for the fixed attribute
2213 void US_Grid_Editor::select_fixed( const QString& fixstr )
2214 {
2215  // Axis types s f/f0 mw vbar D f
2216  const double zmins[] = { -10000.0, 1.0, 0.0, 0.01, 1e+6, 1e+6 };
2217  const double zmaxs[] = { 10000.0, 50.0, 1e+10, 3.00, 1e+8, 1e+6 };
2218  const double zincs[] = { 0.01, 0.01, 1000.0, 0.001, 1e+5, 1e+5 };
2219  //const double zvals[] = { 5.00, 2.0, 1e+5, 0.72, 1e+7, 1e+7 };
2220 
2221  plot_z = fixstr.contains( tr( "Partial S" ) ) ? ATTR_V : 0;
2222  plot_z = fixstr.contains( tr( "nal Ratio" ) ) ? ATTR_K : plot_z;
2223  plot_z = fixstr.contains( tr( "ar Weight" ) ) ? ATTR_W : plot_z;
2224  plot_z = fixstr.contains( tr( "Sedimenta" ) ) ? ATTR_S : plot_z;
2225  plot_z = fixstr.contains( tr( "Diffusion" ) ) ? ATTR_D : plot_z;
2226  plot_z = fixstr.contains( tr( "nal Coeff" ) ) ? ATTR_F : plot_z;
2227 qDebug() << "SelFix: " << fixstr << "plot_z" << plot_z;
2228 
2229  ct_zVal->setRange( zmins[ plot_z ], zmaxs[ plot_z ], zincs[ plot_z ] );
2230  //ct_zVal->setValue( zvals[ plot_z ] );
2231  lb_zVal->setText( fixstr );
2232 
2233  validate_ff0();
2234 }
2235 
2236 // activated when the "Show Final Grid" Checkbox is set
2238 {
2239  if (flag)
2240  {
2241  ct_partialGrid ->setRange(1, grid_index, 1);
2242  ct_partialGrid ->setEnabled( true );
2243  pb_delete_partialGrid->setEnabled( true );
2244  pb_add_partialGrid ->setEnabled( false );
2245  ck_show_sub_grid ->setEnabled( true );
2246  ct_subGrids ->setEnabled( false );
2247  }
2248  else
2249  {
2250  ct_partialGrid ->setEnabled( false );
2251  pb_delete_partialGrid->setEnabled( false );
2252  pb_add_partialGrid ->setEnabled( true );
2253  ck_show_sub_grid ->setEnabled( false );
2254  ct_subGrids ->setEnabled( false );
2255  }
2256 
2257  update_plot();
2258 }
2259 
2260 // activated when the "Show Subgrids" Checkbox is set
2262 {
2263  if (flag)
2264  {
2265  int maxsubgrids = (int) final_grid.size()/50;
2266  int defsubgrids = ( maxsubgrids / 2 ) | 1;
2267 DbgLv(1) << "finalsize" << final_grid.size() << "maxsubgs" << maxsubgrids;
2268  lb_partialGrid ->setText ( tr( "Highlight Subgrid #:" ) );
2269  ct_subGrids ->setEnabled( true );
2270  ct_subGrids ->setRange ( 1, maxsubgrids, 1 );
2271  ct_subGrids ->setValue ( defsubgrids );
2272  ct_partialGrid ->setRange ( 1, subGrids, 1 );
2273  pb_delete_partialGrid->setEnabled( false );
2274  }
2275  else
2276  {
2277  lb_partialGrid ->setText ( tr( "Highlight Partial Grid #:" ) );
2278  ct_subGrids ->setEnabled( false );
2279  ct_partialGrid ->setRange ( 1, grid_index, 1 );
2280  ct_partialGrid ->setValue ( 1 );
2281  pb_delete_partialGrid->setEnabled( true );
2282  }
2283 
2284  update_plot();
2285 }
2286 
2287 // Reset Disk_DB control whenever data source is changed in any dialog
2289 {
2290  isDB ? dkdb_cntrls->set_db() : dkdb_cntrls->set_disk();
2291 }
2292 
2293 // Select DB investigator
2295 {
2296  int investigator = US_Settings::us_inv_ID();
2297 
2298  US_Investigator* dialog = new US_Investigator( true, investigator );
2299  dialog->exec();
2300 
2301  investigator = US_Settings::us_inv_ID();
2302 
2303  QString inv_text = QString::number( investigator ) + ": "
2305 
2306  le_investigator->setText( inv_text );
2307 }
2308 
2309 // Get a grid value of the selected type
2310 double US_Grid_Editor::grid_value( struct gridpoint& gpoint, int atype )
2311 {
2312  double gvalue = ( atype == ATTR_S ) ? gpoint.s : 0.0;
2313  gvalue = ( atype == ATTR_K ) ? gpoint.ff0 : gvalue;
2314  gvalue = ( atype == ATTR_W ) ? gpoint.mw : gvalue;
2315  gvalue = ( atype == ATTR_V ) ? gpoint.vbar : gvalue;
2316  gvalue = ( atype == ATTR_D ) ? gpoint.D : gvalue;
2317  gvalue = ( atype == ATTR_F ) ? gpoint.f : gvalue;
2318 
2319  return gvalue;
2320 }
2321 
2322 // Complete component given s+k+w (s, ff0, mw)
2324 {
2325  double vbar = gpoint.vbar;
2326  double buoy = 1.0 - vbar * density;
2327  bool is_ok = check_grid_point( buoy, gpoint );
2328 
2329  return is_ok;
2330 }
2331 
2332 // Complete component given s+k+v (s, ff0, vbar)
2334 {
2335  double vbar = gpoint.vbar;
2336  double buoy = 1.0 - vbar * density;
2337  double sval = gpoint.s * 1.0e-13;
2338 
2339  gpoint.D = R * K20 / ( AVOGADRO * 18 * M_PI
2340  * pow( ( viscosity * 0.01 * gpoint.ff0 ), (3.0/2.0) )
2341  * pow( ( sval * vbar / ( 2.0 * buoy ) ), 0.5 ) );
2342 
2343  bool is_ok = check_grid_point( buoy, gpoint );
2344 
2345  if ( is_ok )
2346  {
2347  gpoint.mw = sval * R * K20 / ( gpoint.D * buoy );
2348  gpoint.f = R * K20 / ( AVOGADRO * gpoint.D );
2349  gpoint.f0 = gpoint.f / gpoint.ff0;
2350  }
2351 
2352  return is_ok;
2353 }
2354 
2355 // Complete component given s+k+d (s, ff0, D)
2357 {
2358  double vbar = gpoint.vbar;
2359  double buoy = 1.0 - vbar * density;
2360  bool is_ok = check_grid_point( buoy, gpoint );
2361 
2362  return is_ok;
2363 }
2364 // Complete component given s+k+f (s, ff0, f)
2366 {
2367  double vbar = gpoint.vbar;
2368  double buoy = 1.0 - vbar * density;
2369  bool is_ok = check_grid_point( buoy, gpoint );
2370 
2371  return is_ok;
2372 }
2373 // Complete component given s+w+v (s, mw, vbar)
2375 {
2376  double vbar = gpoint.vbar;
2377  double buoy = 1.0 - vbar * density;
2378  double sval = gpoint.s * 1.0e-13;
2379  double ssgn = ( gpoint.s < 0.0 ) ? -1.0 : 1.0;
2380  gpoint.D = ssgn * sval * R * K20 / ( buoy * gpoint.mw );
2381  gpoint.f = ssgn * gpoint.mw * buoy / ( sval * AVOGADRO );
2382  double volume = vbar * gpoint.mw / AVOGADRO;
2383  double sphere = pow( volume * VOL_FAC, THIRD );
2384  gpoint.f0 = sphere * SPH_FAC;
2385  gpoint.f0 = ( gpoint.f0 == 0.0 ) ? 1.0 : gpoint.f0;
2386  gpoint.ff0 = gpoint.f / gpoint.f0;
2387  gpoint.ff0 = qRound( gpoint.ff0 * 1.0e+5 ) * 1.0e-5;
2388  bool is_ok = check_grid_point( buoy, gpoint );
2389 //qDebug() << "comp_swv s w v k" << gpoint.s << gpoint.mw << gpoint.vbar
2390 // << gpoint.ff0;
2391 
2392  return is_ok;
2393 }
2394 // Complete component given s+w+d (s, mw, D)
2396 {
2397  double vbar = gpoint.vbar;
2398  double buoy = 1.0 - vbar * density;
2399  bool is_ok = check_grid_point( buoy, gpoint );
2400 qDebug() << "comp_swd buoy" << buoy;
2401 
2402  return is_ok;
2403 }
2404 // Complete component given s+w+f (s, mw, f)
2406 {
2407  double vbar = gpoint.vbar;
2408  double buoy = 1.0 - vbar * density;
2409 qDebug() << "comp_swf buoy" << buoy;
2410  bool is_ok = check_grid_point( buoy, gpoint );
2411 
2412  return is_ok;
2413 }
2414 // Complete component given s+v+d (s, vbar, D)
2416 {
2417  double vbar = gpoint.vbar;
2418  double buoy = 1.0 - vbar * density;
2419  double ssgn = ( gpoint.s < 0.0 ) ? -1.0 : 1.0;
2420  double sval = gpoint.s * 1.0e-13;
2421  gpoint.f = R * K20 / ( AVOGADRO * gpoint.D );
2422  gpoint.mw = ssgn * sval * R * K20 / ( gpoint.D * buoy );
2423  double volume = vbar * gpoint.mw / AVOGADRO;
2424  double sphere = pow( volume * VOL_FAC, THIRD );
2425  gpoint.ff0 = gpoint.f / ( sphere * SPH_FAC );
2426  gpoint.f0 = gpoint.f / qMax( 1.0, gpoint.ff0 );
2427  bool is_ok = check_grid_point( buoy, gpoint );
2428 
2429  return is_ok;
2430 }
2431 // Complete component given s+v+f (s, vbar, f)
2433 {
2434  double vbar = gpoint.vbar;
2435  double buoy = 1.0 - vbar * density;
2436  double ssgn = ( gpoint.s < 0.0 ) ? -1.0 : 1.0;
2437  double sval = gpoint.s * 1.0e-13;
2438  gpoint.D = R * K20 / ( AVOGADRO * gpoint.f );
2439  gpoint.mw = ssgn * sval * R * K20 / ( gpoint.D * buoy );
2440  double volume = vbar * gpoint.mw / AVOGADRO;
2441  double sphere = pow( volume * VOL_FAC, THIRD );
2442  gpoint.ff0 = gpoint.f / ( sphere * SPH_FAC );
2443  gpoint.ff0 = qRound( gpoint.ff0 * 1.0e+5 ) * 1.0e-5;
2444  gpoint.f0 = gpoint.f / qMax( 1.0, gpoint.ff0 );
2445  bool is_ok = check_grid_point( buoy, gpoint );
2446 
2447  return is_ok;
2448 }
2449 // Complete component given s+d+f (s, D, f)
2451 {
2452  double vbar = gpoint.vbar;
2453  double buoy = 1.0 - vbar * density;
2454 qDebug() << "comp_sdf buoy" << buoy;
2455  bool is_ok = check_grid_point( buoy, gpoint );
2456  gpoint.ff0 = qRound( gpoint.ff0 * 1.0e+5 ) * 1.0e-5;
2457 
2458  return is_ok;
2459 }
2460 // Complete component given k+w+v (ff0, mw, vbar)
2462 {
2463  double vbar = gpoint.vbar;
2464  double buoy = 1.0 - vbar * density;
2465  double vbrat = vbar / AVOGADRO;
2466  double viscf = viscosity * 0.01;
2467 
2468  gpoint.f0 = viscf * pow( ( 162.0 * gpoint.mw * MPISQ * vbrat ), THIRD );
2469  gpoint.f = gpoint.ff0 * gpoint.f0;
2470  gpoint.s = 1.0e13 * gpoint.mw * buoy / ( AVOGADRO * gpoint.f );
2471  gpoint.D = R * K20 / ( AVOGADRO * gpoint.f );
2472  bool is_ok = check_grid_point( buoy, gpoint );
2473 
2474  return is_ok;
2475 }
2476 // Complete component given k+w+d (ff0, mw, D)
2478 {
2479  double vbar = gpoint.vbar;
2480  double buoy = 1.0 - vbar * density;
2481 qDebug() << "comp_kwd buoy" << buoy;
2482  bool is_ok = check_grid_point( buoy, gpoint );
2483 
2484  return is_ok;
2485 }
2486 // Complete component given k+w+f (ff0, mw, f)
2488 {
2489  double vbar = gpoint.vbar;
2490  double buoy = 1.0 - vbar * density;
2491 qDebug() << "comp_kwf buoy" << buoy;
2492  bool is_ok = check_grid_point( buoy, gpoint );
2493 
2494  return is_ok;
2495 }
2496 // Complete component given k+v+d (ff0, vbar, D)
2498 {
2499  double vbar = gpoint.vbar;
2500  double buoy = 1.0 - vbar * density;
2501 qDebug() << "comp_kvd buoy" << buoy;
2502  gpoint.f = R * K20 / ( AVOGADRO * gpoint.D );
2503  gpoint.f0 = gpoint.f / qMax( 1.0, gpoint.ff0 );
2504  double sphere = gpoint.f0 / ( 0.06 * M_PI * VISC_20W );
2505  double volume = ( 4.0 / 3.0 ) * M_PI * pow( sphere, 3.0 );
2506  gpoint.mw = volume * AVOGADRO / vbar;
2507  double sval = gpoint.mw * buoy / ( AVOGADRO * gpoint.f );
2508  gpoint.s = sval * 1.0e+13;
2509  gpoint.ff0 = ( gpoint.f0 != 0.0 ) ? gpoint.f / gpoint.f0 : 1.0;
2510  bool is_ok = check_grid_point( buoy, gpoint );
2511 
2512  return is_ok;
2513 }
2514 // Complete component given k+v+f (ff0, vbar, f)
2516 {
2517  double vbar = gpoint.vbar;
2518  double buoy = 1.0 - vbar * density;
2519 qDebug() << "comp_kvf buoy" << buoy;
2520  gpoint.f0 = gpoint.f / qMax( 1.0, gpoint.ff0 );
2521  gpoint.D = R * K20 / ( AVOGADRO * gpoint.f );
2522  double sphere = gpoint.f0 / ( 0.06 * M_PI * VISC_20W );
2523  double volume = ( 4.0 / 3.0 ) * M_PI * pow( sphere, 3.0 );
2524  gpoint.mw = volume * AVOGADRO / vbar;
2525  double sval = gpoint.mw * buoy / ( AVOGADRO * gpoint.f );
2526  gpoint.s = sval * 1.0e+13;
2527  bool is_ok = check_grid_point( buoy, gpoint );
2528 
2529  return is_ok;
2530 }
2531 // Complete component given k+d+f (ff0, D, f)
2533 {
2534  double vbar = gpoint.vbar;
2535  double buoy = 1.0 - vbar * density;
2536 qDebug() << "comp_kdf buoy" << buoy;
2537  bool is_ok = check_grid_point( buoy, gpoint );
2538 
2539  return is_ok;
2540 }
2541 // Complete component given w+v+d (mw, vbar, D)
2543 {
2544  double vbar = gpoint.vbar;
2545  double buoy = 1.0 - vbar * density;
2546 qDebug() << "comp_wvd buoy" << buoy;
2547  double volume = vbar * gpoint.mw / AVOGADRO;
2548  double sphere = pow( volume * VOL_FAC, THIRD );
2549  gpoint.f0 = sphere * SPH_FAC;
2550  double sval = gpoint.D * buoy * gpoint.mw / ( R * K20 );
2551  gpoint.f = gpoint.mw * buoy / ( sval * AVOGADRO );
2552  gpoint.ff0 = ( gpoint.f0 != 0.0 ) ? gpoint.f / gpoint.f0 : 1.0;
2553  gpoint.s = sval * 1.0e+13;
2554  bool is_ok = check_grid_point( buoy, gpoint );
2555 
2556  return is_ok;
2557 }
2558 // Complete component given w+v+f (mw, vbar, f)
2560 {
2561  double vbar = gpoint.vbar;
2562  double buoy = 1.0 - vbar * density;
2563 qDebug() << "comp_wvf buoy" << buoy;
2564  double volume = vbar * gpoint.mw / AVOGADRO;
2565  double sphere = pow( volume * VOL_FAC, THIRD );
2566  gpoint.f0 = sphere * SPH_FAC;
2567  gpoint.ff0 = ( gpoint.f0 != 0.0 ) ? gpoint.f / gpoint.f0 : 1.0;
2568  double sval = gpoint.mw * buoy / ( AVOGADRO * gpoint.f );
2569  gpoint.D = sval * R * K20 / ( buoy * gpoint.mw );
2570  gpoint.s = sval * 1.0e+13;
2571  bool is_ok = check_grid_point( buoy, gpoint );
2572 
2573  return is_ok;
2574 }
2575 // Complete component given w+d+f (mw, D, f)
2577 {
2578  double vbar = gpoint.vbar;
2579  double buoy = 1.0 - vbar * density;
2580 qDebug() << "comp_wdf buoy" << buoy;
2581  gpoint.ff0 = qRound( gpoint.ff0 * 1.0e+5 ) * 1.0e-5;
2582  bool is_ok = check_grid_point( buoy, gpoint );
2583 
2584  return is_ok;
2585 }
2586 // Complete component given v+d+f (vbar, D, f)
2588 {
2589  double vbar = gpoint.vbar;
2590  double buoy = 1.0 - vbar * density;
2591 qDebug() << "comp_vdf buoy" << buoy;
2592  gpoint.ff0 = qRound( gpoint.ff0 * 1.0e+5 ) * 1.0e-5;
2593  bool is_ok = check_grid_point( buoy, gpoint );
2594 
2595  return is_ok;
2596 }
2597 
2598 // Check the validity of a grid point
2599 bool US_Grid_Editor::check_grid_point( double buoy, struct gridpoint& gpoint )
2600 {
2601  bool is_ok = true;
2602 
2603  if ( buoy == 0.0 || gpoint.vbar == 0.0 ||
2604  ( gpoint.s < 0 && buoy > 0.0 ) ||
2605  ( gpoint.s > 0 && buoy < 0.0 ) )
2606  { // If point is nonsensical, flag it and mark molecular weight negative
2607  gpoint.mw = -1.0;
2608  is_ok = false;
2609  }
2610 
2611  return is_ok;
2612 }
2613 
2614 // Adjust value/ranges so that f/f0 is not less than 1
2616 {
2617  bool is_ok = true;
2618 
2619  if ( plot_x == ATTR_K || plot_y == ATTR_K || plot_z == ATTR_K )
2620  { // If one of the attributes is f/f0, no need for checking
2621  return is_ok;
2622  }
2623 
2624  struct gridpoint zpoint;
2625  struct gridpoint tmp_point;
2626  xMin = ct_xMin->value();
2627  xMax = ct_xMax->value();
2628  yMin = ct_yMin->value();
2629  yMax = ct_yMax->value();
2630 qDebug() << "valFF0: xMin xMax yMin yMax" << xMin << xMax << yMin << yMax;
2631  zVal = ct_zVal->value();
2632  clear_grid( zpoint );
2633  set_grid_value( zpoint, plot_z, zVal );
2634  // Get f/f0 for xMin,yMin
2635  tmp_point = zpoint;
2636  set_grid_value( tmp_point, plot_x, xMin );
2637  set_grid_value( tmp_point, plot_y, yMin );
2638  complete_comp ( tmp_point );
2639  double ffx1y1 = tmp_point.ff0;
2640  // Get f/f0 for xMin,yMax
2641  tmp_point = zpoint;
2642  set_grid_value( tmp_point, plot_x, xMin );
2643  set_grid_value( tmp_point, plot_y, yMax );
2644  complete_comp ( tmp_point );
2645  double ffx1y2 = tmp_point.ff0;
2646  // Get f/f0 for xMax,yMin
2647  tmp_point = zpoint;
2648  set_grid_value( tmp_point, plot_x, xMax );
2649  set_grid_value( tmp_point, plot_y, yMin );
2650  complete_comp ( tmp_point );
2651  double ffx2y1 = tmp_point.ff0;
2652  // Get f/f0 for xMax,yMax
2653  tmp_point = zpoint;
2654  set_grid_value( tmp_point, plot_x, xMax );
2655  set_grid_value( tmp_point, plot_y, yMax );
2656  complete_comp ( tmp_point );
2657  double ffx2y2 = tmp_point.ff0;
2658  // Get overall minimum f/f0
2659  double ff0min = qMin( ffx1y1, ffx1y2 );
2660  ff0min = qMin( ff0min, ffx2y1 );
2661  ff0min = qMin( ff0min, ffx2y2 );
2662 qDebug() << "valFF0: zVal xMin yMin ff0" << zVal << xMin << yMin << ffx1y1;
2663 qDebug() << "valFF0: xMin yMax ff0 " << xMin << yMax << ffx1y2;
2664 qDebug() << "valFF0: xMax yMin ff0 " << xMax << yMin << ffx2y1;
2665 qDebug() << "valFF0: xMax yMax ff0 " << xMax << yMax << ffx2y2;
2666 
2667  if ( ff0min < 1.0 )
2668  { // Ranges include values that set f/f0 less than 1: must adjust ranges
2669 
2670  if ( plot_x == ATTR_W || plot_x == ATTR_F )
2671  { // Adjust the X range (if MW or f)
2672  ct_xMin->disconnect();
2673  ct_xMax->disconnect();
2674  tmp_point = zpoint;
2675  set_grid_value( tmp_point, ATTR_K, 1.0 );
2676 
2677  if ( ffx1y1 < ffx1y2 )
2678  { // Increasing Y means increasing f/f0, so get X for k=1,ymin
2679  set_grid_value( tmp_point, plot_y, yMin );
2680  complete_comp ( tmp_point );
2681  double xVal = grid_value( tmp_point, plot_x );
2682 
2683  if ( ffx1y1 < ffx2y1 )
2684  { // Increasing X means increasing f/f0, so set lower limit
2685 qDebug() << "valFF0: (1xMin)xVal" << xVal;
2686  ct_xMin->setMinValue( xVal );
2687  ct_xMax->setMinValue( xVal );
2688  }
2689 
2690  else
2691  { // Increasing X means decreasing f/f0, so set upper limit
2692 qDebug() << "valFF0: (2xMin)xVal" << xVal;
2693  ct_xMin->setMaxValue( xVal );
2694  ct_xMax->setMaxValue( xVal );
2695  }
2696  }
2697 
2698  else
2699  { // Increasing Y means decreasing f/f0, so get X for k=1,ymax
2700  set_grid_value( tmp_point, plot_y, yMax );
2701  complete_comp ( tmp_point );
2702  double xVal = grid_value( tmp_point, plot_x );
2703 
2704  if ( ffx1y1 < ffx2y1 )
2705  { // Increasing X means increasing f/f0, so set lower limit
2706 qDebug() << "valFF0: (3xMin)xVal" << xVal;
2707  ct_xMin->setMinValue( xVal );
2708  ct_xMax->setMinValue( xVal );
2709  }
2710 
2711  else
2712  { // Increasing X means decreasing f/f0, so set upper limit
2713 qDebug() << "valFF0: (4xMin)xVal" << xVal;
2714  ct_xMin->setMaxValue( xVal );
2715  ct_xMax->setMaxValue( xVal );
2716  }
2717  }
2718 
2719  connect( ct_xMin, SIGNAL( valueChanged( double ) ),
2720  this, SLOT ( update_xMin ( double ) ) );
2721  connect( ct_xMax, SIGNAL( valueChanged( double ) ),
2722  this, SLOT ( update_xMax ( double ) ) );
2723  }
2724 
2725  if ( plot_y == ATTR_W || plot_y == ATTR_F )
2726  { // Adjust the Y range (if MW or f)
2727  ct_yMin->disconnect();
2728  ct_yMax->disconnect();
2729  tmp_point = zpoint;
2730  set_grid_value( tmp_point, ATTR_K, 1.0 );
2731 
2732  if ( ffx1y1 < ffx2y1 )
2733  { // Increasing X means increasing f/f0, so get Y for k=1,xmin
2734  set_grid_value( tmp_point, plot_x, xMin );
2735  complete_comp ( tmp_point );
2736  double yVal = grid_value( tmp_point, plot_y );
2737 
2738  if ( ffx1y1 < ffx1y2 )
2739  { // Increasing Y means increasing f/f0, so set lower limit
2740 qDebug() << "valFF0: (5yMin)yVal" << yVal;
2741  ct_yMin->setMinValue( yVal );
2742  ct_yMax->setMinValue( yVal );
2743  }
2744 
2745  else
2746  { // Increasing Y means decreasing f/f0, so set upper limit
2747 qDebug() << "valFF0: (6yMax)yVal" << yVal;
2748  ct_yMin->setMaxValue( yVal );
2749  ct_yMax->setMaxValue( yVal );
2750  }
2751  }
2752 
2753  else
2754  { // Increasing X means decreasing f/f0, so get y for k=1,xmax
2755  set_grid_value( tmp_point, plot_x, xMax );
2756  complete_comp ( tmp_point );
2757  double yVal = grid_value( tmp_point, plot_y );
2758 
2759  if ( ffx1y1 < ffx1y2 )
2760  { // Increasing Y means increasing f/f0, so set lower limit
2761 qDebug() << "valFF0: (7yMin)yVal" << yVal;
2762  ct_yMin->setMinValue( yVal );
2763  ct_yMax->setMinValue( yVal );
2764  }
2765 
2766  else
2767  { // Increasing Y means decreasing f/f0, so set upper limit
2768 qDebug() << "valFF0: (8yMax)yVal" << yVal;
2769  ct_yMin->setMaxValue( yVal );
2770  ct_yMax->setMaxValue( yVal );
2771  }
2772  }
2773 
2774  connect( ct_yMin, SIGNAL( valueChanged( double ) ),
2775  this, SLOT ( update_yMin ( double ) ) );
2776  connect( ct_yMax, SIGNAL( valueChanged( double ) ),
2777  this, SLOT ( update_yMax ( double ) ) );
2778  }
2779  }
2780 
2781  xMin = ct_xMin->value();
2782  xMax = ct_xMax->value();
2783  yMin = ct_yMin->value();
2784  yMax = ct_yMax->value();
2785 qDebug() << "valFF0: (out)xMin xMax yMin yMax" << xMin << xMax << yMin << yMax;
2786 
2787  return is_ok;
2788 }
2789 
2790 // Clear a gridpoint structure
2792 {
2793  gpoint.s = 0.0;
2794  gpoint.ff0 = 0.0;
2795  gpoint.mw = 0.0;
2796  gpoint.vbar = 0.0;
2797  gpoint.D = 0.0;
2798  gpoint.f = 0.0;
2799 }
2800 
2801 // Set a gridpoint value of the selected type
2802 void US_Grid_Editor::set_grid_value( struct gridpoint& gpoint, int atype,
2803  double gvalue )
2804 {
2805  if ( atype == ATTR_S )
2806  gpoint.s = gvalue;
2807  else if ( atype == ATTR_K )
2808  gpoint.ff0 = gvalue;
2809  else if ( atype == ATTR_W )
2810  gpoint.mw = gvalue;
2811  else if ( atype == ATTR_V )
2812  gpoint.vbar = gvalue;
2813  else if ( atype == ATTR_D )
2814  gpoint.D = gvalue;
2815  else if ( atype == ATTR_F )
2816  gpoint.f = gvalue;
2817 }
2818 
2819 // Complete component where 3 attributes are given
2821 {
2823  sc.s = gpoint.s * 1.0e-13;
2824  sc.f_f0 = gpoint.ff0;
2825  sc.mw = gpoint.mw;
2826  sc.vbar20 = gpoint.vbar;
2827  sc.D = gpoint.D;
2828  sc.f = gpoint.f;
2829 
2830  bool is_ok = US_Model::calc_coefficients( sc );
2831 
2832  if ( is_ok )
2833  {
2834  gpoint.s = sc.s * 1.0e+13;
2835  gpoint.ff0 = sc.f_f0;
2836  gpoint.mw = sc.mw;
2837  gpoint.vbar = sc.vbar20;
2838  gpoint.D = sc.D;
2839  gpoint.f = sc.f;
2840  }
2841 
2842  return is_ok;
2843 }
2844