UltraScan III
us_pcsa_process.h
Go to the documentation of this file.
1 #ifndef US_PCSA_PROCESS_H
3 #define US_PCSA_PROCESS_H
4 
5 #include <QtCore>
6 #include <QTimer>
7 
8 #include "us_extern.h"
9 #include "us_widgets.h"
10 #include "us_dataIO.h"
11 #include "us_simparms.h"
12 #include "us_model.h"
13 #include "us_noise.h"
14 #include "us_db2.h"
15 #include "us_solute.h"
16 #include "us_zsolute.h"
17 #include "us_worker_pc.h"
18 #include "us_pcsa_modelrec.h"
19 
20 #ifndef DbgLv
21 #define DbgLv(a) if(dbg_level>=a)qDebug()
22 #endif
23 #ifndef US_ZS_ATTRIBS
24 #define US_ZS_ATTRIBS
25 #define ATTR_S US_ZSolute::ATTR_S
26 #define ATTR_K US_ZSolute::ATTR_K
27 #define ATTR_W US_ZSolute::ATTR_W
28 #define ATTR_V US_ZSolute::ATTR_V
29 #define ATTR_D US_ZSolute::ATTR_D
30 #define ATTR_C US_ZSolute::ATTR_C
31 #endif
32 
34 
41 class US_pcsaProcess : public QObject
42 {
43  Q_OBJECT
44 
45  public:
48 
52  US_pcsaProcess( QList< US_SolveSim::DataSet* >&, QObject* = 0 );
53 
68  void start_fit( double, double, double, double, int, int,
69  int, int, int, int, int, double, double = 0.0 );
70 
73  void final_fit( double );
74 
86  US_Model*, US_Noise*, US_Noise*, int&,
87  QStringList&, QVector< US_ModelRecord >& );
88 
91  void get_mrec( US_ModelRecord& );
92 
95  void put_mrec( US_ModelRecord& );
96 
99  void put_mrecs( QVector< US_ModelRecord >& );
100 
102  void stop_fit( void );
103 
105  void clear_memory( void );
106 
107  static const int solute_doubles = sizeof( US_ZSolute ) / sizeof( double );
108 
109  // Static routines needed for Levenberg-Marquardt
110  static double fit_function_SL( double, double* );
111  static double fit_function_IS( double, double* );
112  static double fit_function_DS( double, double* );
113  static double fit_function_HL( double, double* );
114 
115 private:
116 
117  signals:
118  void progress_update( double );
119  void process_complete( int );
120  void stage_complete( int, int );
121  void message_update( QString, bool );
122 
123 private:
124  QList< US_SolveSim::DataSet* >& dsets;
125 
126  long int maxrss;
127 
128  long int max_rss( void );
129 
130  QList< WorkerThreadPc* > wthreads; // worker threads
131  QList< WorkPacketPc > job_queue; // job queue
132 
133  QVector< US_ModelRecord > mrecs; // model records for each task
134 
135  QVector< int > wkstates; // worker thread states
136 
137  QList< QVector< US_ZSolute > > orig_sols; // input solutes
138 
139  QVector< double > rmsds; // gfit iteration RMSDs
140  US_DataIO::EditedData* edata; // experimental data (mc_iter)
141  US_DataIO::RawData sdata; // simulation data
142  US_DataIO::RawData rdata; // residuals data
143 
144  US_Model model; // constructed model
145 
146  US_Noise ti_noise; // time-invariant noise
147  US_Noise ri_noise; // radially-invariant noise
148 
149  US_SimulationParameters* simparms; // simulation parameters
150 
151  QString errMsg; // message from last error
152 
153  int dbg_level; // debug level
154  int nthreads; // number of worker threads
155  int cresolu; // curve resolution (points on the line)
156  int curvtype; // curve type flag (0->straight line)
157  int nypts; // number of y points
158  int nctotal; // number of total compute-progress steps
159  int kcsteps; // count of completed progress steps
160  int noisflag; // noise out flag: 0(none), 1(ti), 2(ri), 3(both)
161  int nscans; // number of experiment scans
162  int npoints; // number of reading points per experiment scan
163  int nmtasks; // number of models/tasks to do
164  int kctask; // count of completed subgrid tasks
165  int kstask; // count of started subgrid tasks;
166  int minvarx; // minimum variance model index
167  int time_fg; // time in milliseconds for fixed-grid calcs
168  int time_lm; // time in milliseconds for L-M calcs
169  int lmtm_id; // L-M timing event ID
170  int fi_iter; // Fit iteration counter
171  int fi_itermax; // Maximum fit iterations
172  int lmmxcall; // L-M maximum calls
173  int st_mask; // Solute type mask
174  int attr_x; // Attribute X index
175  int attr_y; // Attribute Y index
176  int attr_z; // Attribute Z index
177 
178  bool abort; // flag used with stop_fit clicked
179  bool lm_done; // flag for L-M completion
180  bool alpha_scn; // flag for alpha-scan only
181 
182  double xlolim; // x lower limit
183  double xuplim; // x upper limit
184  double ylolim; // y lower limit
185  double yuplim; // y upper limit
186  double cparam; // additional curve parameter
187  double varimin; // variance minimum
188  double alpha; // Tikhonov regularization factor
189  double alpha_fx; // Alpha for fixed curves fits
190  double alpha_lm; // Alpha for L-M fits
191  double parlims[ 12 ];// Par1,Par2 limits and other constants
192  double pfi_rmsd; // Previous fit iteration RMSD
193  double cfi_rmsd; // Current fit iteration RMSD
194  double rd_frac; // RMSD-difference fraction: (p-c)/p
195  double rd_thresh; // RMSD-difference threshold factor
196 
197  QTime timer; // timer for elapsed time measure
198 
199  private slots:
200  void queue_task ( WorkPacketPc&, double, double,
201  int, int, QVector< US_ZSolute > );
202  int slmodels ( int, double, double, double, double, int, int );
203  int sigmodels ( int, double, double, double, double, int, int );
204  int pl2models ( double, double, double, double, int, int );
205  void process_job ( WorkerThreadPc* );
207  void submit_job ( WorkPacketPc&, int );
208  void free_worker ( int );
209  void model_statistics( QVector< US_ModelRecord >&, QStringList& );
210  QString pmessage_head( void );
211  WorkPacketPc next_job( void );
212  void LevMarq_fit ( void );
213  void compute_final ( void );
214  void elite_limits ( QVector< US_ModelRecord >&, double&, double&,
215  double&, double&, double&, double& );
216  void restart_fit ( void );
217  static double evaluate_model( QList< US_SolveSim::DataSet* >&,
219 
220  protected:
221  virtual void timerEvent( QTimerEvent *e );
222 };
223 #endif
224