Skip to content

Commit 1cbda46

Browse files
committed
Moved parameter sanity check from mainwindowsupport.cpp to parameters.cpp
1 parent 138f54e commit 1cbda46

6 files changed

Lines changed: 214 additions & 284 deletions

File tree

src/app/calc/parameters.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/app/calc/parameters.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/app/dialog/mainwindowsupport.cpp

Lines changed: 1 addition & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "dialog/mainwindowsupport.h"
77
#include "dialog/plotdata.h"
8+
#include <QMessageBox>
89

910
MainWindowSupport::MainWindowSupport(void)
1011
{
@@ -485,204 +486,3 @@ void MainWindowSupport::ReadCustomData(parameters *para, QString fileName, bool
485486
para->stdDev = 1.0;
486487
}
487488
}
488-
489-
/************************* Sanity check *********************************************/
490-
//Input parameter check
491-
bool MainWindowSupport::CheckInputParameters(Ui_MainWindow *ui, parameters *para)
492-
{
493-
QMessageBox msgBox, msgBoxWarn;
494-
msgBox.setWindowTitle("Error");
495-
msgBox.setIcon(QMessageBox::Critical);
496-
msgBoxWarn.setWindowTitle("Warning");
497-
msgBoxWarn.setIcon(QMessageBox::Warning);
498-
499-
if ((para->scatRefReal <= 0.0) || (para->medRef <= 0.0))
500-
{
501-
msgBox.setText("Refractive index cannot be zero");
502-
msgBox.exec();
503-
return 1;
504-
}
505-
if ((para->scatRefReal/para->medRef == 1.0))
506-
{
507-
msgBox.setText("Relative refractive index cannot be 1.0");
508-
msgBox.exec();
509-
return 1;
510-
}
511-
double m = para->scatRefReal / para->medRef;
512-
if ((m < 0.05) || (m > 5.0))
513-
{
514-
msgBoxWarn.setText("Unrealistic relative refractive index.");
515-
msgBoxWarn.setInformativeText("Check sphere and medium refractive index values");
516-
msgBoxWarn.exec();
517-
return 1;
518-
}
519-
if (para->scatRefImag >= 5.0)
520-
{
521-
msgBox.setText("Imaginary refractive index must be negative or less than 5.0.");
522-
msgBox.exec();
523-
return 1;
524-
}
525-
//Avoid zeros
526-
if ((para->startWavel <= 0.0) || (para->endWavel <= 0.0))
527-
{
528-
msgBox.setText("The starting or ending wavelength cannot be zero");
529-
msgBox.exec();
530-
return 1;
531-
}
532-
//Avoid zeros
533-
if (para->stepWavel <= 0.0)
534-
{
535-
msgBox.setText("Wavelength step cannot be zero");
536-
msgBox.exec();
537-
return 1;
538-
}
539-
if (para->startWavel < 50.0)
540-
{
541-
msgBox.setText("Minimum wavlength is 50nm");
542-
msgBox.exec();
543-
return 1;
544-
}
545-
if (para->endWavel > 3000.0)
546-
{
547-
msgBox.setText("Maximum wavlength is 3000nm");
548-
msgBox.exec();
549-
return 1;
550-
}
551-
if (para->endWavel - para->startWavel < 0.0)
552-
{
553-
msgBox.setText("The starting wavelength is greater than the ending wavelength");
554-
msgBox.exec();
555-
return 1;
556-
}
557-
if (ui->radioButton_NumDen->isChecked())
558-
{
559-
if (para->sphNumDensity <= 0.0)
560-
{
561-
msgBox.setText("Sphere concentration cannot be zero");
562-
msgBox.exec();
563-
return 1;
564-
}
565-
}
566-
if (ui->radioButton_VolFrac->isChecked())
567-
{
568-
if (para->volFraction <= 0.0)
569-
{
570-
msgBox.setText("Volume Fraction cannot be zero");
571-
msgBox.exec();
572-
return 1;
573-
}
574-
575-
if (para->volFraction >= 1.0)
576-
{
577-
msgBox.setText("Volume Fraction cannot exceed 1.0");
578-
msgBox.exec();
579-
return 1;
580-
}
581-
}
582-
if ((para->meanRadius < 0.00005) ||(para->meanRadius >150))
583-
{
584-
msgBox.setText("Diameter is out of range!");
585-
msgBox.setInformativeText("Enter a value between 0.0001μm and 300μm");
586-
msgBox.exec();
587-
return 1;
588-
}
589-
if (ui->radioButton_MonoDisperse->isChecked())
590-
{
591-
if (ui->radioButton_NumDen->isChecked())
592-
{
593-
double volume = 4.0 * M_PI *para->meanRadius * para->meanRadius * para->meanRadius / 3.0;
594-
if (para->sphNumDensity*volume >= 1e9)
595-
{
596-
msgBoxWarn.setText("Concentration x Sphere Volume exceeds 1mm³.");
597-
msgBoxWarn.setInformativeText("Reduce Concentration.");
598-
msgBoxWarn.exec();
599-
return 1;
600-
}
601-
}
602-
}
603-
return 0;
604-
}
605-
606-
//Poly disperse distribution parameter check
607-
bool MainWindowSupport::CheckDistribution(Ui_MainWindow *ui, parameters *para)
608-
{
609-
QMessageBox msgBox;
610-
msgBox.setWindowTitle("Error");
611-
612-
if (para->stdDev == 0.0)
613-
{
614-
msgBox.setText("Standard Deviation is zero.");
615-
msgBox.setInformativeText("Use 'Mono Disperse'.");
616-
msgBox.exec();
617-
return 1;
618-
}
619-
if(ui->comboBox_Distribution->currentIndex() == 0)
620-
{
621-
if (para->stdDev > 3.0)
622-
{
623-
msgBox.setIcon(QMessageBox::Critical);
624-
msgBox.setText("Large standard deviation provides an abnormal Log Normal distribution.");
625-
msgBox.setInformativeText("The limit was set to 3.0μm.");
626-
msgBox.exec();
627-
return 1;
628-
}
629-
if (para->stdDev < 1e-5)
630-
{
631-
msgBox.setIcon(QMessageBox::Critical);
632-
msgBox.setText("The standard deviation is too small.");
633-
msgBox.setInformativeText("Use 'Mono Disperse'.");
634-
msgBox.exec();
635-
return 1;
636-
}
637-
}
638-
639-
if(ui->comboBox_Distribution->currentIndex() == 1)
640-
{
641-
if (para->stdDev > 50.0)
642-
{
643-
msgBox.setIcon(QMessageBox::Critical);
644-
msgBox.setText("The standard deviation is too large.");
645-
msgBox.setInformativeText("The limit was set to 50.0μm.");
646-
msgBox.exec();
647-
return 1;
648-
}
649-
if (para->stdDev < 1e-8)
650-
{
651-
msgBox.setIcon(QMessageBox::Critical);
652-
msgBox.setText("The standard deviation is too small.");
653-
msgBox.setInformativeText("Use 'Mono Disperse'.");
654-
msgBox.exec();
655-
return 1;
656-
}
657-
}
658-
if (para->nRadius == 1)
659-
{
660-
msgBox.setText("Discrete sphere size is 1. ");
661-
msgBox.setInformativeText("Use 'Mono Disperse'.");
662-
msgBox.exec();
663-
return 1;
664-
}
665-
if ((para->nRadius < 2.0) ||(para->nRadius >101.0))
666-
{
667-
msgBox.setText("Number of sphere sizes is out of range.");
668-
msgBox.setInformativeText("Enter a value between 2 and 101.");
669-
msgBox.exec();
670-
return 1;
671-
}
672-
if ((para->meanRadius < 0.0005) ||(para->meanRadius >25))
673-
{
674-
msgBox.setText("Diameter is out of range.");
675-
msgBox.setInformativeText("Enter a value between 0.001μm and 50μm.");
676-
msgBox.exec();
677-
return 1;
678-
}
679-
if (para->stdDev/para->meanRadius < 1.999e-5)
680-
{
681-
msgBox.setIcon(QMessageBox::Critical);
682-
msgBox.setText("Standard deviation to mean diameter ratio is smaller than 1e-5.");
683-
msgBox.setInformativeText("Use 'Mono Disperse'");
684-
msgBox.exec();
685-
return 1;
686-
}
687-
return 0;
688-
}

src/app/dialog/mainwindowsupport.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef MAINWINDOWSUPPORT_H
22
#define MAINWINDOWSUPPORT_H
33

4-
#include <QMessageBox>
54
#include <qmath.h>
65
#include "lib/qcustomplot.h"
76
#include "parameters.h"
@@ -24,9 +23,7 @@ class MainWindowSupport
2423
void DisableEnableRealImagButtons(Ui_MainWindow *ui);
2524
void DisableWidgetsDuringSimulation(Ui_MainWindow *ui, parameters *para, bool flag);
2625
void DisableWidgetsDuringCustomPolyDisperseData(Ui_MainWindow *ui, bool flag);
27-
void ReadCustomData(parameters * para, QString fileName, bool * dataValidFlag);
28-
bool CheckInputParameters(Ui_MainWindow *ui, parameters *para);
29-
bool CheckDistribution(Ui_MainWindow *ui, parameters *para);
26+
void ReadCustomData(parameters * para, QString fileName, bool * dataValidFlag);
3027

3128
private:
3229
QCustomPlot *mCustomPlot;

0 commit comments

Comments
 (0)