Skip to content

Commit

Permalink
Add interface to new svzerod solver 1034 (SimVascular#1040)
Browse files Browse the repository at this point in the history
* Add 0D solver to SV Preferences page for ROM simulation.

* Modify the sv4guiROMSimulationView class to execute the 0D solver binary.

* Remove references to Python svZeroDSolver.

* Add a more detailed arror message if the 0d solver can't be found.
  • Loading branch information
ktbolt authored Nov 7, 2023
1 parent edd1fc7 commit bb559fc
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sv4guiROMSimulationPreferencePage::~sv4guiROMSimulationPreferencePage()
void sv4guiROMSimulationPreferencePage::InitializeSolverLocations()
{
SetOneDSolver();
SetZeroDSolver();
}

void sv4guiROMSimulationPreferencePage::CreateQtControl(QWidget* parent)
Expand All @@ -71,7 +72,10 @@ void sv4guiROMSimulationPreferencePage::CreateQtControl(QWidget* parent)
Q_ASSERT(prefService);

m_Preferences = prefService->GetSystemPreferences()->Node("/org.sv.views.romsimulation");

connect( m_Ui->SolverExecutablePath_Button, SIGNAL(clicked()), this, SLOT(SetOneDSolverFile()) );
connect( m_Ui->ZeroDSolverExecutablePath_Button, SIGNAL(clicked()), this, SLOT(SetZeroDSolverFile()) );

this->Update();

// Set the locations of the solver binary.
Expand All @@ -85,6 +89,7 @@ void sv4guiROMSimulationPreferencePage::CreateQtControl(QWidget* parent)
//
void sv4guiROMSimulationPreferencePage::SetOneDSolverFile()
{
std::cout << "sv4guiROMSimulationPreferencePage::SetOneDSolverFile()" << std::endl;
QString filePath = QFileDialog::getOpenFileName(m_Control, "Select the 1D solver executable");

if (!filePath.isEmpty()) {
Expand All @@ -100,6 +105,7 @@ void sv4guiROMSimulationPreferencePage::SetOneDSolverFile()
//
void sv4guiROMSimulationPreferencePage::SetOneDSolver()
{
std::cout << "sv4guiROMSimulationPreferencePage::SetOneDSolver()" << std::endl;
QString solver = m_Ui->SolverExecutablePath_LineEdit->text().trimmed();
if (!solver.isEmpty() && (solver != m_DefaultPrefs.UnknownBinary)) {
return;
Expand All @@ -109,6 +115,42 @@ void sv4guiROMSimulationPreferencePage::SetOneDSolver()
m_Ui->SolverExecutablePath_LineEdit->setText(solver);
}

//--------------------
// SetZeroDSolverFile
//--------------------
// Set the location of the 9D solver executable using a file browser.
//
void sv4guiROMSimulationPreferencePage::SetZeroDSolverFile()
{
std::cout << "sv4guiROMSimulationPreferencePage::SetZeroDSolverFile()" << std::endl;

QString filePath = QFileDialog::getOpenFileName(m_Control, "Select the 0D solver executable");

if (!filePath.isEmpty()) {
m_Ui->ZeroDSolverExecutablePath_LineEdit->setText(filePath);
}
}

//---------------
// SetZeroDSolver
//---------------
// Set the 0D solver executable from the GUI line edit widget
// or from the default value.
//
void sv4guiROMSimulationPreferencePage::SetZeroDSolver()
{
std::cout << "sv4guiROMSimulationPreferencePage::SetZeroDSolver()" << std::endl;

QString solver = m_Ui->ZeroDSolverExecutablePath_LineEdit->text().trimmed();
if (!solver.isEmpty() && (solver != m_DefaultPrefs.UnknownBinary)) {
return;
}

solver = m_DefaultPrefs.GetZeroDSolver();
m_Ui->ZeroDSolverExecutablePath_LineEdit->setText(solver);
}


QWidget* sv4guiROMSimulationPreferencePage::GetQtControl() const
{
return m_Control;
Expand All @@ -125,13 +167,19 @@ void sv4guiROMSimulationPreferencePage::PerformCancel()
bool sv4guiROMSimulationPreferencePage::PerformOk()
{
using namespace sv4guiROMSimulationPreferenceDBKey;

QString oneDSolverPath = m_Ui->SolverExecutablePath_LineEdit->text().trimmed();
m_Preferences->Put(ONED_SOLVER_PATH, oneDSolverPath);

QString zeroDSolverPath = m_Ui->ZeroDSolverExecutablePath_LineEdit->text().trimmed();
m_Preferences->Put(ZEROD_SOLVER_PATH, zeroDSolverPath);

return true;
}

void sv4guiROMSimulationPreferencePage::Update()
{
m_Ui->SolverExecutablePath_LineEdit->setText(m_Preferences->Get("1d solver executable path",""));
m_Ui->ZeroDSolverExecutablePath_LineEdit->setText(m_Preferences->Get("0d solver executable path",""));
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class sv4guiROMSimulationPreferencePage;
//
namespace sv4guiROMSimulationPreferenceDBKey {
const QString ONED_SOLVER_PATH = "oned solver path";
const QString ZEROD_SOLVER_PATH = "zerod solver path";
};


Expand All @@ -69,13 +70,15 @@ class sv4guiROMSimulationPreferencePage : public QObject, public berry::IQtPrefe

private slots:
void SetOneDSolverFile();
void SetZeroDSolverFile();

private:
berry::IPreferences::Pointer m_Preferences;
QScopedPointer<Ui::sv4guiROMSimulationPreferencePage> m_Ui;
QWidget* m_Control;
sv4guiROMSimulationPreferences m_DefaultPrefs;
void SetOneDSolver();
void SetZeroDSolver();

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,87 @@
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_7" native="true">
<layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Path to 0D Solver executable</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="ZeroDSolverExecutablePath_Button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ZeroDSolverExecutablePath_LineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ sv4guiROMSimulationPreferences::~sv4guiROMSimulationPreferences()
//
void sv4guiROMSimulationPreferences::InitializeSolverLocations()
{
// Set the default install location of the solver.
// Set the default install location of the 1D solver.
//
QString solverInstallPath = "/usr/local/sv/oneDSolver";
QStringList dirList = QDir(solverInstallPath).entryList(QDir::Dirs|QDir::NoDotAndDotDot|QDir::NoSymLinks,QDir::Name);
if (dirList.size() != 0) {
Expand All @@ -75,12 +76,25 @@ void sv4guiROMSimulationPreferences::InitializeSolverLocations()

// Set the path to the SimVascular-build/bin directory.
QString applicationPath = "";
//QString applicationPath = QCoreApplication::applicationDirPath();

//sv4gui_parse_registry_for_svsolver();

// Set the solver binaries.
SetOneDSolver(solverInstallPath, applicationPath);


// Set the default install location of the 0D solver.
//
solverInstallPath = "/usr/local/sv/ZeroDSolver";
dirList = QDir(solverInstallPath).entryList(QDir::Dirs|QDir::NoDotAndDotDot|QDir::NoSymLinks,QDir::Name);
if (dirList.size() != 0) {
solverInstallPath += "/" + dirList.back();
}

// Set the path to the SimVascular-build/bin directory.
applicationPath = "";

// Set the solver binaries.
SetZeroDSolver(solverInstallPath, applicationPath);

}

//---------------
Expand Down Expand Up @@ -138,6 +152,59 @@ QString sv4guiROMSimulationPreferences::GetOneDSolver()
return m_svOneDSolver;
}

//----------------
// SetZeroDSolver
//----------------
// Set the ZeroDSolver binary.
//
void sv4guiROMSimulationPreferences::SetZeroDSolver(const QString& solverInstallPath, const QString& applicationPath)
{
QString svZeroDSolver = UnknownBinary;

#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
QString filePath = "";
QString svZeroDSolverName = "/svzerodsolver";

// For the flow solver with mpi, prefer to use the script one which sets
// paths to libs needed in Ubuntu 16.
//
if(QFile(filePath=solverInstallPath+svZeroDSolverName).exists()) {
svZeroDSolver = filePath;

} else if(QFile(filePath=solverInstallPath+"/bin/"+svZeroDSolverName).exists()) {
svZeroDSolver = filePath;

} else if(QFile(filePath=applicationPath+svZeroDSolverName).exists()) {
svZeroDSolver = filePath;

} else if(QFile(filePath=applicationPath+"/bin/"+svZeroDSolverName).exists()) {
svZeroDSolver = filePath;
}

#elif defined(Q_OS_WIN)

char result[1024];
result[0] = '\0';

// This returns the full path including the executable for the svZeroDSolver.
//
// The most recent installed solver is returned.
//
// The registry entry name is 'SVONEDSOLVER_EXE' and is located under WOW6432Node/SimVascular/Solvers/svZeroDSolver.
//
if (sv4gui_rom_parse_registry_for_svonedsolver("SVZERODSOLVER_EXE",result) == SV_OK) {
svZeroDSolver = result;
}

#endif

m_svZeroDSolver = svZeroDSolver;
std::cout << "svZeroDSolver executable: '" << m_svZeroDSolver.toStdString() << "'" << std::endl;
}

QString sv4guiROMSimulationPreferences::GetZeroDSolver()
{
return m_svZeroDSolver;
}


Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ class sv4guiROMSimulationPreferences

void InitializeSolverLocations();
QString GetOneDSolver();
QString GetZeroDSolver();
static const QString UnknownBinary;

private:
QString m_svOneDSolver;
QString m_svZeroDSolver;

void SetOneDSolver(const QString& solverInstallPath, const QString& applicationPath);
void SetZeroDSolver(const QString& solverInstallPath, const QString& applicationPath);
};

#endif // SV4GUI_SIMULATIONPREFERENCES_H
Loading

0 comments on commit bb559fc

Please sign in to comment.