From 1c21c0315f2254cdec34a48fedcd6f759c871aa9 Mon Sep 17 00:00:00 2001 From: Anders Hafreager Date: Wed, 28 Oct 2015 11:46:02 +0100 Subject: [PATCH 1/5] Fixed so computes don't use fix ave/time anymore. --- atomify-lammps/CPcompute.cpp | 67 +++++++++++++---------------- atomify-lammps/CPcompute.h | 10 +---- atomify-lammps/lammpscontroller.cpp | 36 ++-------------- atomify-lammps/lammpscontroller.h | 38 ++++++++-------- atomify-lammps/linegraph.cpp | 1 + atomify-lammps/linegraph.h | 2 +- atomify-lammps/mysimulator.cpp | 19 ++++++++ atomify-lammps/mysimulator.h | 17 +------- atomify-lammps/qml/main.qml | 57 +++++++++++++++++++----- 9 files changed, 126 insertions(+), 121 deletions(-) diff --git a/atomify-lammps/CPcompute.cpp b/atomify-lammps/CPcompute.cpp index c353f6c8..e179574f 100644 --- a/atomify-lammps/CPcompute.cpp +++ b/atomify-lammps/CPcompute.cpp @@ -2,29 +2,37 @@ #include "mysimulator.h" #include "lammpscontroller.h" -LammpsOutput &CPCompute::output() -{ - return m_output; -} - bool CPCompute::isVector() const { return m_isVector; } -QString CPCompute::fixIdentifier() const +void CPCompute::update(LAMMPSController *lammpsController) { - return m_fixIdentifier; -} + LAMMPS_NS::Compute *lmp_compute = lammpsController->findComputeByIdentifier(identifier()); + if(lmp_compute != nullptr) { + QVector newValues; -QString CPCompute::fixCommand() const -{ - return m_fixCommand; + if(isVector()) { + lmp_compute->compute_vector(); + double *values = lmp_compute->vector; + int numValues = lmp_compute->size_vector; + + for(int i=0; icompute_scalar(); + newValues.push_back(value); + } + + setValues(newValues); + } } CPCompute::CPCompute(QObject *parent) : QObject(parent) { - m_output.m_compute = this; + } CPCompute::~CPCompute() @@ -56,21 +64,25 @@ QStringList CPCompute::dependencies() const double CPCompute::firstValue() const { + if(m_values.size()<1) return NAN; return m_values.at(0); } double CPCompute::secondValue() const { + if(m_values.size()<2) return NAN; return m_values.at(1); } double CPCompute::thirdValue() const { + if(m_values.size()<3) return NAN; return m_values.at(2); } double CPCompute::fourthValue() const { + if(m_values.size()<4) return NAN; return m_values.at(3); } @@ -126,12 +138,13 @@ void CPCompute::setValues(QVector values) m_time = m_simulator->simulationTime(); m_values.clear(); m_values = QList::fromVector(values); - - emit valuesChanged(m_values); - emit firstValueChanged(m_values.at(0)); - if(values.size() > 1) secondValueChanged(m_values.at(1)); - if(values.size() > 2) thirdValueChanged(m_values.at(2)); - if(values.size() > 3) fourthValueChanged(m_values.at(3)); + if(m_values.size()>0) { + emit valuesChanged(m_values); + emit firstValueChanged(m_values.at(0)); + if(values.size() > 1) secondValueChanged(m_values.at(1)); + if(values.size() > 2) thirdValueChanged(m_values.at(2)); + if(values.size() > 3) fourthValueChanged(m_values.at(3)); + } } void CPCompute::setIsVector(bool isVector) @@ -142,21 +155,3 @@ void CPCompute::setIsVector(bool isVector) m_isVector = isVector; emit isVectorChanged(isVector); } - -void CPCompute::setFixIdentifier(QString fixIdentifier) -{ - if (m_fixIdentifier == fixIdentifier) - return; - - m_fixIdentifier = fixIdentifier; - emit fixIdentifierChanged(fixIdentifier); -} - -void CPCompute::setFixCommand(QString fixCommand) -{ - if (m_fixCommand == fixCommand) - return; - - m_fixCommand = fixCommand; - emit fixCommandChanged(fixCommand); -} diff --git a/atomify-lammps/CPcompute.h b/atomify-lammps/CPcompute.h index 42b87353..e894de85 100644 --- a/atomify-lammps/CPcompute.h +++ b/atomify-lammps/CPcompute.h @@ -10,8 +10,6 @@ class CPCompute : public QObject { Q_OBJECT Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) - Q_PROPERTY(QString fixIdentifier READ fixIdentifier WRITE setFixIdentifier NOTIFY fixIdentifierChanged) - Q_PROPERTY(QString fixCommand READ fixCommand WRITE setFixCommand NOTIFY fixCommandChanged) Q_PROPERTY(QString command READ command WRITE setCommand NOTIFY commandChanged) Q_PROPERTY(AtomifySimulator* simulator READ simulator WRITE setSimulator NOTIFY simulatorChanged) Q_PROPERTY(QStringList dependencies READ dependencies WRITE setDependencies NOTIFY dependenciesChanged) @@ -29,7 +27,6 @@ class CPCompute : public QObject QString m_fixCommand; QString m_command; - LammpsOutput m_output; AtomifySimulator* m_simulator = nullptr; QStringList m_dependencies; QList m_values; @@ -52,8 +49,7 @@ class CPCompute : public QObject QList values() const; LammpsOutput &output(); bool isVector() const; - QString fixIdentifier() const; - QString fixCommand() const; + void update(LAMMPSController *lammpsController); signals: void identifierChanged(QString identifier); @@ -66,8 +62,6 @@ class CPCompute : public QObject void fourthValueChanged(double value); void valuesChanged(QList values); void isVectorChanged(bool isVector); - void fixIdentifierChanged(QString fixIdentifier); - void fixCommandChanged(QString fixCommand); public slots: void setIdentifier(QString identifier); @@ -76,7 +70,5 @@ public slots: void setDependencies(QStringList dependencies); void setValues(QVector values); void setIsVector(bool isVector); - void setFixIdentifier(QString fixIdentifier); - void setFixCommand(QString fixCommand); }; #endif // COMPUTE_H diff --git a/atomify-lammps/lammpscontroller.cpp b/atomify-lammps/lammpscontroller.cpp index cef26249..8804726c 100644 --- a/atomify-lammps/lammpscontroller.cpp +++ b/atomify-lammps/lammpscontroller.cpp @@ -169,6 +169,7 @@ LAMMPS_NS::Fix* LAMMPSController::findFixByIdentifier(QString identifier) { } int LAMMPSController::findFixIndex(QString identifier) { + if(!m_lammps) return -1; return m_lammps->modify->find_fix(identifier.toStdString().c_str()); } @@ -176,13 +177,14 @@ bool LAMMPSController::fixExists(QString identifier) { return findFixIndex(identifier) >= 0; } -LAMMPS_NS::Compute* LAMMPSController::findCompute(QString identifier) { +LAMMPS_NS::Compute* LAMMPSController::findComputeByIdentifier(QString identifier) { int computeId = findComputeId(identifier); if(computeId < 0) return nullptr; else return m_lammps->modify->compute[computeId]; } int LAMMPSController::findComputeId(QString identifier) { + if(!m_lammps) return -1; return m_lammps->modify->find_compute(identifier.toStdString().c_str()); } @@ -200,8 +202,6 @@ void LAMMPSController::processComputes() { for(QString key : m_computes.keys()) { if(!computeExists(key)) { - qDebug() << "Missing key: " << key; - CPCompute *compute = m_computes[key]; // We need to add it. First check all dependencies bool allDependenciesFound = true; // Assume all are found and find potential counterexample @@ -213,25 +213,9 @@ void LAMMPSController::processComputes() } if(allDependenciesFound) { - qDebug() << "All dependencies found"; state.preRunNeeded = true; // When a new compute is added, a run with pre yes is needed for it to be included // Now that all dependencies are met we can add this one too executeCommandInLAMMPS(compute->command()); - // Now we need to create a fix that will store these values - QString fixIdentifier = QString("fix%1").arg(compute->identifier()); - compute->setFixIdentifier(fixIdentifier); - - QString fixCommand = QString("fix %1 all ave/time 1 1 1 c_%2").arg(fixIdentifier, compute->identifier()); - if(compute->isVector()) fixCommand.append(" mode vector"); - - compute->setFixCommand(fixCommand); - executeCommandInLAMMPS(fixCommand); - // Now replace the output on the object - FixAveTime *fix = dynamic_cast(findFixByIdentifier(fixIdentifier)); - if(fix) { - // This is our baby - fix->fp = compute->output().stream(); - } } } } @@ -260,19 +244,7 @@ void LAMMPSController::executeActiveRunCommand() { void LAMMPSController::reset() { - if(m_lammps != nullptr) { - // We need to set FILE pointers in fixes to NULL so that they are not closed when LAMMPS deallocates. - for(CPCompute *compute : m_computes) { - if(computeExists(compute->identifier())) { - FixAveTime *fix = dynamic_cast(findFixByIdentifier(compute->fixIdentifier())); - if(fix != nullptr) { - fix->fp = nullptr; - } - } - } - } - - int nargs = 1; + int nargs = 3; char **argv = new char*[nargs]; for(int i=0; i simulatorControls; template - T *findFixByType() { - for(int i=0; imodify->nfix; i++) { - LAMMPS_NS::Fix *fix = m_lammps->modify->fix[i]; + T *findFixByType(); + void processSimulatorControls(); +}; - T *myFix = dynamic_cast(fix); - if(myFix) { - return myFix; - } - } +template +T *LAMMPSController::findFixByType() { + for(int i=0; imodify->nfix; i++) { + LAMMPS_NS::Fix *fix = m_lammps->modify->fix[i]; - return nullptr; + T *myFix = dynamic_cast(fix); + if(myFix) { + return myFix; + } } - void processSimulatorControls(); -}; + + return nullptr; +} #endif // LAMMPSCONTROLLER_H diff --git a/atomify-lammps/linegraph.cpp b/atomify-lammps/linegraph.cpp index aa3f4ce8..3c224046 100644 --- a/atomify-lammps/linegraph.cpp +++ b/atomify-lammps/linegraph.cpp @@ -1,5 +1,6 @@ #include "linegraph.h" #include "figure.h" +#include LineGraph::LineGraph() { diff --git a/atomify-lammps/linegraph.h b/atomify-lammps/linegraph.h index fec5e9d3..d4219a80 100644 --- a/atomify-lammps/linegraph.h +++ b/atomify-lammps/linegraph.h @@ -9,7 +9,7 @@ class LineGraphDataSource : public QObject { QVector m_points; int m_firstIndex = 0; int m_numberOfPoints = 0; - int m_maxNumberOfPoints = 500; + int m_maxNumberOfPoints = 50000; void cleanupMemory(); public: Q_INVOKABLE void addPoint(float x, float y); diff --git a/atomify-lammps/mysimulator.cpp b/atomify-lammps/mysimulator.cpp index 45c38787..ee444ceb 100644 --- a/atomify-lammps/mysimulator.cpp +++ b/atomify-lammps/mysimulator.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,10 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) mySimulator->setSystemSize(m_lammpsController.systemSize()); mySimulator->setTimePerTimestep(m_lammpsController.timePerTimestep()); + for(CPCompute *compute : mySimulator->computes()) { + compute->update(&m_lammpsController); + } + m_lammpsController.setScriptHandler(mySimulator->scriptHandler()); if(m_lammpsController.crashed() && !m_lammpsController.currentException().isReported()) { @@ -254,6 +259,11 @@ bool AtomifySimulator::willReset() const return m_willReset; } +int AtomifySimulator::numberOfTimesteps() const +{ + return m_numberOfTimesteps; +} + int AtomifySimulator::simulationSpeed() const { return m_simulationSpeed; @@ -367,3 +377,12 @@ void AtomifySimulator::setWillReset(bool willReset) m_willReset = willReset; emit willResetChanged(willReset); } + +void AtomifySimulator::setNumberOfTimesteps(int numberOfTimesteps) +{ + if (m_numberOfTimesteps == numberOfTimesteps) + return; + + m_numberOfTimesteps = numberOfTimesteps; + emit numberOfTimestepsChanged(numberOfTimesteps); +} diff --git a/atomify-lammps/mysimulator.h b/atomify-lammps/mysimulator.h index f401e06b..a6cc0e77 100644 --- a/atomify-lammps/mysimulator.h +++ b/atomify-lammps/mysimulator.h @@ -75,11 +75,7 @@ class AtomifySimulator : public Simulator QString lammpsErrorMessage() const; ScriptHandler* scriptHandler() const; bool willReset() const; - - int numberOfTimesteps() const - { - return m_numberOfTimesteps; - } + int numberOfTimesteps() const; public slots: void setSimulationSpeed(int arg); @@ -94,15 +90,7 @@ public slots: void setLammpsErrorMessage(QString lammpsErrorMessage); void setScriptHandler(ScriptHandler* scriptHandler); void setWillReset(bool willReset); - - void setNumberOfTimesteps(int numberOfTimesteps) - { - if (m_numberOfTimesteps == numberOfTimesteps) - return; - - m_numberOfTimesteps = numberOfTimesteps; - emit numberOfTimestepsChanged(numberOfTimesteps); - } + void setNumberOfTimesteps(int numberOfTimesteps); signals: void simulationSpeedChanged(int arg); @@ -119,7 +107,6 @@ public slots: void lammpsDidReset(); void scriptHandlerChanged(ScriptHandler* scriptHandler); void willResetChanged(bool willReset); - void numberOfTimestepsChanged(int numberOfTimesteps); protected: diff --git a/atomify-lammps/qml/main.qml b/atomify-lammps/qml/main.qml index 96a94e9d..a6484790 100644 --- a/atomify-lammps/qml/main.qml +++ b/atomify-lammps/qml/main.qml @@ -72,20 +72,54 @@ ApplicationWindow { Compute { property real maxValue: 0 - id: computeTemp - identifier: "temp" - command: "compute temp all temp" + id: computeMsd + identifier: "msd" + command: "compute msd all msd" + isVector: true simulator: mySimulator - onValueChanged: { + onFourthValueChanged: { // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) - tempGraph.addPoint(mySimulator.simulationTime, value) + tempGraph.addPoint(mySimulator.simulationTime, fourthValue) tempPlot.xMax = mySimulator.simulationTime - tempPlot.xMin = mySimulator.simulationTime-1 - maxValue = Math.max(maxValue, value) + //tempPlot.xMin = mySimulator.simulationTime-1 + maxValue = Math.max(maxValue, fourthValue) tempPlot.yMax = maxValue } } + Compute { + property real maxValue: 0 + id: computePressure + identifier: "pressure" + command: "compute pressure all pressure temperature" + simulator: mySimulator + dependencies: ["temperature"] + onValueChanged: { + // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) +// tempGraph.addPoint(mySimulator.simulationTime, value) +// tempPlot.xMax = mySimulator.simulationTime +// tempPlot.xMin = mySimulator.simulationTime-1 +// maxValue = Math.max(maxValue, value) +// tempPlot.yMax = maxValue + } + } + + Compute { + property real maxValue: 0 + id: computeTemp + identifier: "temperature" + command: "compute temperature all temp" + simulator: mySimulator +// onValueChanged: { +// // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) +// tempGraph.addPoint(mySimulator.simulationTime, value) +// tempPlot.xMax = mySimulator.simulationTime +// tempPlot.xMin = mySimulator.simulationTime-1 +// maxValue = Math.max(maxValue, value) +// tempPlot.yMax = maxValue +// } + } + Rectangle { width: 400 height: 400 @@ -94,13 +128,16 @@ ApplicationWindow { Figure { id: tempPlot anchors.fill: parent - yMin: -1 + yMin: 0 yMax: 1 xLabel: "t [ps] " - yLabel: "T" - title: "Temperature" + yLabel: "<∆r^2>" + title: "Mean square displacement" LineGraph { id: tempGraph + color: "red" + width: 3 + style: Qt.DashDotDotLine } } } From 5a68e2c42b4809c3f61e7d4a5c04e6361e9a0db4 Mon Sep 17 00:00:00 2001 From: Anders Hafreager Date: Wed, 28 Oct 2015 13:13:14 +0100 Subject: [PATCH 2/5] Fixed so editor commands are #/ instead of #!. --- atomify-lammps/scriptparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atomify-lammps/scriptparser.cpp b/atomify-lammps/scriptparser.cpp index eefb4f0c..30b09913 100644 --- a/atomify-lammps/scriptparser.cpp +++ b/atomify-lammps/scriptparser.cpp @@ -53,7 +53,7 @@ void ScriptParser::atomType(QString command, std::function Date: Wed, 28 Oct 2015 18:51:20 +0100 Subject: [PATCH 3/5] Rewrote SimulatorControl so Fix and Compute inherit from the general type. --- atomify-lammps/CPcompute.cpp | 157 --------------- atomify-lammps/CPcompute.h | 74 ------- atomify-lammps/atomify-lammps.pro | 16 +- atomify-lammps/cpcompute.cpp | 124 ++++++++++++ atomify-lammps/cpcompute.h | 51 +++++ atomify-lammps/cpfix.cpp | 35 ++++ atomify-lammps/cpfix.h | 27 +++ atomify-lammps/figure.cpp | 21 +- atomify-lammps/figure.h | 40 ++-- atomify-lammps/lammpscontroller.cpp | 39 +--- atomify-lammps/lammpscontroller.h | 4 +- atomify-lammps/lammpsoutput.cpp | 170 ---------------- atomify-lammps/lammpsoutput.h | 39 ---- atomify-lammps/main.cpp | 5 +- atomify-lammps/mysimulator.cpp | 18 +- atomify-lammps/mysimulator.h | 2 - atomify-lammps/nvt.cpp | 168 ++++++++-------- atomify-lammps/nvt.h | 52 ++--- atomify-lammps/qml/desktop/MainDesktop.qml | 4 +- .../qml/desktop/SimulationSummary.qml | 20 +- atomify-lammps/qml/main.qml | 110 +++++------ atomify-lammps/scriptcommand.h | 1 - atomify-lammps/simulatorcontrol.cpp | 109 +++++++++- atomify-lammps/simulatorcontrol.h | 37 +++- atomify-lammps/stdioext.c | 187 ------------------ atomify-lammps/stdioext.h | 28 --- 26 files changed, 598 insertions(+), 940 deletions(-) delete mode 100644 atomify-lammps/CPcompute.cpp delete mode 100644 atomify-lammps/CPcompute.h create mode 100644 atomify-lammps/cpcompute.cpp create mode 100644 atomify-lammps/cpcompute.h create mode 100644 atomify-lammps/cpfix.cpp create mode 100644 atomify-lammps/cpfix.h delete mode 100644 atomify-lammps/lammpsoutput.cpp delete mode 100644 atomify-lammps/lammpsoutput.h delete mode 100644 atomify-lammps/stdioext.c delete mode 100644 atomify-lammps/stdioext.h diff --git a/atomify-lammps/CPcompute.cpp b/atomify-lammps/CPcompute.cpp deleted file mode 100644 index e179574f..00000000 --- a/atomify-lammps/CPcompute.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "CPcompute.h" -#include "mysimulator.h" -#include "lammpscontroller.h" - -bool CPCompute::isVector() const -{ - return m_isVector; -} - -void CPCompute::update(LAMMPSController *lammpsController) -{ - LAMMPS_NS::Compute *lmp_compute = lammpsController->findComputeByIdentifier(identifier()); - if(lmp_compute != nullptr) { - QVector newValues; - - if(isVector()) { - lmp_compute->compute_vector(); - double *values = lmp_compute->vector; - int numValues = lmp_compute->size_vector; - - for(int i=0; icompute_scalar(); - newValues.push_back(value); - } - - setValues(newValues); - } -} - -CPCompute::CPCompute(QObject *parent) : QObject(parent) -{ - -} - -CPCompute::~CPCompute() -{ - m_values.clear(); - m_simulator = nullptr; - m_dependencies.clear(); -} - -QString CPCompute::identifier() const -{ - return m_identifier; -} - -QString CPCompute::command() const -{ - return m_command; -} - -AtomifySimulator *CPCompute::simulator() const -{ - return m_simulator; -} - -QStringList CPCompute::dependencies() const -{ - return m_dependencies; -} - -double CPCompute::firstValue() const -{ - if(m_values.size()<1) return NAN; - return m_values.at(0); -} - -double CPCompute::secondValue() const -{ - if(m_values.size()<2) return NAN; - return m_values.at(1); -} - -double CPCompute::thirdValue() const -{ - if(m_values.size()<3) return NAN; - return m_values.at(2); -} - -double CPCompute::fourthValue() const -{ - if(m_values.size()<4) return NAN; - return m_values.at(3); -} - -double CPCompute::time() const -{ - return m_time; -} - -QList CPCompute::values() const -{ - return m_values; -} - -void CPCompute::setIdentifier(QString identifier) -{ - if (m_identifier == identifier) - return; - - m_identifier = identifier; - emit identifierChanged(identifier); -} - -void CPCompute::setCommand(QString command) -{ - if (m_command == command) - return; - - m_command = command; - emit commandChanged(command); -} - -void CPCompute::setSimulator(AtomifySimulator *simulator) -{ - if (m_simulator == simulator) - return; - - m_simulator = simulator; - simulator->addCompute(this); - emit simulatorChanged(simulator); -} - -void CPCompute::setDependencies(QStringList dependencies) -{ - if (m_dependencies == dependencies) - return; - - m_dependencies = dependencies; - emit dependenciesChanged(dependencies); -} - -void CPCompute::setValues(QVector values) -{ - m_time = m_simulator->simulationTime(); - m_values.clear(); - m_values = QList::fromVector(values); - if(m_values.size()>0) { - emit valuesChanged(m_values); - emit firstValueChanged(m_values.at(0)); - if(values.size() > 1) secondValueChanged(m_values.at(1)); - if(values.size() > 2) thirdValueChanged(m_values.at(2)); - if(values.size() > 3) fourthValueChanged(m_values.at(3)); - } -} - -void CPCompute::setIsVector(bool isVector) -{ - if (m_isVector == isVector) - return; - - m_isVector = isVector; - emit isVectorChanged(isVector); -} diff --git a/atomify-lammps/CPcompute.h b/atomify-lammps/CPcompute.h deleted file mode 100644 index e894de85..00000000 --- a/atomify-lammps/CPcompute.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef COMPUTE_H -#define COMPUTE_H - -#include -#include -#include "lammpsoutput.h" - -class AtomifySimulator; class LAMMPSController; -class CPCompute : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) - Q_PROPERTY(QString command READ command WRITE setCommand NOTIFY commandChanged) - Q_PROPERTY(AtomifySimulator* simulator READ simulator WRITE setSimulator NOTIFY simulatorChanged) - Q_PROPERTY(QStringList dependencies READ dependencies WRITE setDependencies NOTIFY dependenciesChanged) - Q_PROPERTY(bool isVector READ isVector WRITE setIsVector NOTIFY isVectorChanged) - Q_PROPERTY(double time READ time) - Q_PROPERTY(QList values READ values NOTIFY valuesChanged) - Q_PROPERTY(double value READ firstValue NOTIFY firstValueChanged) - Q_PROPERTY(double firstValue READ firstValue NOTIFY firstValueChanged) - Q_PROPERTY(double secondValue READ secondValue NOTIFY secondValueChanged) - Q_PROPERTY(double thirdValue READ thirdValue NOTIFY thirdValueChanged) - Q_PROPERTY(double fourthValue READ fourthValue NOTIFY fourthValueChanged) -private: - QString m_identifier; - QString m_fixIdentifier; - QString m_fixCommand; - QString m_command; - - AtomifySimulator* m_simulator = nullptr; - QStringList m_dependencies; - QList m_values; - double m_time = 0; - bool m_isVector = false; - -public: - explicit CPCompute(QObject *parent = 0); - ~CPCompute(); - - QString identifier() const; - QString command() const; - AtomifySimulator* simulator() const; - QStringList dependencies() const; - double firstValue() const; - double secondValue() const; - double thirdValue() const; - double fourthValue() const; - double time() const; - QList values() const; - LammpsOutput &output(); - bool isVector() const; - void update(LAMMPSController *lammpsController); - -signals: - void identifierChanged(QString identifier); - void commandChanged(QString command); - void simulatorChanged(AtomifySimulator* simulator); - void dependenciesChanged(QStringList dependencies); - void firstValueChanged(double value); - void secondValueChanged(double value); - void thirdValueChanged(double value); - void fourthValueChanged(double value); - void valuesChanged(QList values); - void isVectorChanged(bool isVector); - -public slots: - void setIdentifier(QString identifier); - void setCommand(QString command); - void setSimulator(AtomifySimulator* simulator); - void setDependencies(QStringList dependencies); - void setValues(QVector values); - void setIsVector(bool isVector); -}; -#endif // COMPUTE_H diff --git a/atomify-lammps/atomify-lammps.pro b/atomify-lammps/atomify-lammps.pro index e82c6cc4..7d2ca632 100644 --- a/atomify-lammps/atomify-lammps.pro +++ b/atomify-lammps/atomify-lammps.pro @@ -12,8 +12,8 @@ CONFIG += warn_off android { DEFINES += LAMMPS_XDR - SOURCES += stdioext.c - HEADERS += stdioext.h + SOURCES += + HEADERS += LIBS += -fopenmp include(../lammps-android.pri) } else { @@ -43,8 +43,6 @@ SOURCES += \ mysimulator.cpp \ lammpscontroller.cpp \ highlighter.cpp \ - CPcompute.cpp \ - lammpsoutput.cpp \ atomstyle.cpp \ fileio.cpp \ scriptparser.cpp \ @@ -54,14 +52,14 @@ SOURCES += \ scriptcommand.cpp \ linegraph.cpp \ graph.cpp \ - figure.cpp + figure.cpp \ + cpfix.cpp \ + cpcompute.cpp HEADERS += \ mysimulator.h \ lammpscontroller.h \ highlighter.h \ - CPcompute.h \ - lammpsoutput.h \ atomstyle.h \ fileio.h \ scriptparser.h \ @@ -71,7 +69,9 @@ HEADERS += \ scriptcommand.h \ linegraph.h \ graph.h \ - figure.h + figure.h \ + cpfix.h \ + cpcompute.h DISTFILES += \ iOS.plist \ diff --git a/atomify-lammps/cpcompute.cpp b/atomify-lammps/cpcompute.cpp new file mode 100644 index 00000000..682864f2 --- /dev/null +++ b/atomify-lammps/cpcompute.cpp @@ -0,0 +1,124 @@ +#include "cpcompute.h" +#include "lammpscontroller.h" +#include "mysimulator.h" + +CPCompute::CPCompute() +{ + +} + +void CPCompute::setValues(double time, QVector values) +{ + m_time = time; + m_values.clear(); + m_values = QList::fromVector(values); + if(m_values.size()>0) { + emit valuesChanged(m_values); + emit firstValueChanged(m_values.at(0)); + if(values.size() > 1) secondValueChanged(m_values.at(1)); + if(values.size() > 2) thirdValueChanged(m_values.at(2)); + if(values.size() > 3) fourthValueChanged(m_values.at(3)); + } +} + +void CPCompute::updateCommand() +{ + // For standard computes, command doesn't change +} + +void CPCompute::update(LAMMPSController *lammpsController) +{ + SimulatorControl::update(lammpsController); + LAMMPS_NS::Compute *lmp_compute = lammpsController->findComputeByIdentifier(identifier()); + if(lmp_compute != nullptr) { + QVector newValues; + + if(isVector()) { + lmp_compute->compute_vector(); + double *values = lmp_compute->vector; + int numValues = lmp_compute->size_vector; + + for(int i=0; icompute_scalar(); + newValues.push_back(value); + } + + setValues(lammpsController->simulationTime(), newValues); + } +} + +QString CPCompute::enabledCommand() +{ + return QString("compute %1 %2").arg(identifier()).arg(command()); +} + +QString CPCompute::disableCommand() +{ + return QString("uncompute %1").arg(identifier()); +} + +bool CPCompute::existsInLammps(LAMMPSController *lammpsController) +{ + LAMMPS_NS::Compute *compute = lammpsController->findComputeByIdentifier(identifier()); + return compute!=nullptr; +} + +QList CPCompute::values() const +{ + return m_values; +} + +double CPCompute::firstValue() const +{ + if(m_values.size()<1) return NAN; + return m_values.at(0); +} + +double CPCompute::secondValue() const +{ + if(m_values.size()<2) return NAN; + return m_values.at(1); +} + +double CPCompute::thirdValue() const +{ + if(m_values.size()<3) return NAN; + return m_values.at(2); +} + +double CPCompute::fourthValue() const +{ + if(m_values.size()<4) return NAN; + return m_values.at(3); +} + +double CPCompute::time() const +{ + return m_time; +} + +bool CPCompute::isVector() const +{ + return m_isVector; +} + +void CPCompute::setTime(double time) +{ + if (m_time == time) + return; + + m_time = time; + emit timeChanged(time); +} + +void CPCompute::setIsVector(bool isVector) +{ + if (m_isVector == isVector) + return; + + m_isVector = isVector; + emit isVectorChanged(isVector); +} diff --git a/atomify-lammps/cpcompute.h b/atomify-lammps/cpcompute.h new file mode 100644 index 00000000..d9c6e014 --- /dev/null +++ b/atomify-lammps/cpcompute.h @@ -0,0 +1,51 @@ +#ifndef COMPUTE_H +#define COMPUTE_H +#include "simulatorcontrol.h" +class CPCompute : public SimulatorControl +{ + Q_OBJECT + Q_PROPERTY(QList values READ values NOTIFY valuesChanged) + Q_PROPERTY(double value READ firstValue NOTIFY firstValueChanged) + Q_PROPERTY(double firstValue READ firstValue NOTIFY firstValueChanged) + Q_PROPERTY(double secondValue READ secondValue NOTIFY secondValueChanged) + Q_PROPERTY(double thirdValue READ thirdValue NOTIFY thirdValueChanged) + Q_PROPERTY(double fourthValue READ fourthValue NOTIFY fourthValueChanged) + Q_PROPERTY(double time READ time WRITE setTime NOTIFY timeChanged) + Q_PROPERTY(bool isVector READ isVector WRITE setIsVector NOTIFY isVectorChanged) + +protected: + bool m_isVector = false; + double m_time = 0; + QList m_values; + void setValues(double time, QVector values); + + virtual void updateCommand() override; + QString enabledCommand() override; + QString disableCommand() override; +public: + CPCompute(); + void update(LAMMPSController *lammpsController) override; + bool existsInLammps(LAMMPSController *lammpsController) override; + QList values() const; + double firstValue() const; + double secondValue() const; + double thirdValue() const; + double fourthValue() const; + double time() const; + bool isVector() const; + +signals: + void valuesChanged(QList values); + void firstValueChanged(double firstValue); + void secondValueChanged(double secondValue); + void thirdValueChanged(double thirdValue); + void fourthValueChanged(double fourthValue); + void timeChanged(double time); + void isVectorChanged(bool isVector); + +public slots: + void setTime(double time); + void setIsVector(bool isVector); +}; + +#endif // COMPUTE_H diff --git a/atomify-lammps/cpfix.cpp b/atomify-lammps/cpfix.cpp new file mode 100644 index 00000000..af8e0194 --- /dev/null +++ b/atomify-lammps/cpfix.cpp @@ -0,0 +1,35 @@ +#include "cpfix.h" +#include "lammpscontroller.h" + +CPFix::CPFix() +{ + +} + +void CPFix::update(LAMMPSController *lammpsController) +{ + SimulatorControl::update(lammpsController); + +} + + +QString CPFix::enabledCommand() +{ + return QString("fix %1 %2").arg(identifier()).arg(command()); +} + +QString CPFix::disableCommand() +{ + return QString("unfix %1 ").arg(identifier()); +} + + +void CPFix::updateCommand() +{ +} + +bool CPFix::existsInLammps(LAMMPSController *lammpsController) +{ + LAMMPS_NS::Fix *fix = lammpsController->findFixByIdentifier(identifier()); + return fix!=nullptr; +} diff --git a/atomify-lammps/cpfix.h b/atomify-lammps/cpfix.h new file mode 100644 index 00000000..e1488ccb --- /dev/null +++ b/atomify-lammps/cpfix.h @@ -0,0 +1,27 @@ +#ifndef CPFIX_H +#define CPFIX_H + +#include "simulatorcontrol.h" +class LAMMPSController; +class CPFix : public SimulatorControl +{ + Q_OBJECT +protected: + QString enabledCommand() override; + QString disableCommand() override; + +public: + CPFix(); + void update(LAMMPSController *lammpsController) override; + virtual bool existsInLammps(LAMMPSController *lammpsController); + +signals: + +public slots: + + // SimulatorControl interface +protected: + virtual void updateCommand(); +}; + +#endif // CPFIX_H diff --git a/atomify-lammps/figure.cpp b/atomify-lammps/figure.cpp index 60b6ec2c..24b263d5 100644 --- a/atomify-lammps/figure.cpp +++ b/atomify-lammps/figure.cpp @@ -1,13 +1,13 @@ #include "figure.h" #include "graph.h" #include - +#include Figure::Figure(QQuickItem *parent) : QQuickPaintedItem(parent) { - connect(this, SIGNAL(xMinChanged(float)), this, SLOT(update())); - connect(this, SIGNAL(xMaxChanged(float)), this, SLOT(update())); - connect(this, SIGNAL(yMinChanged(float)), this, SLOT(update())); - connect(this, SIGNAL(yMaxChanged(float)), this, SLOT(update())); + connect(this, SIGNAL(xMinChanged(double)), this, SLOT(update())); + connect(this, SIGNAL(xMaxChanged(double)), this, SLOT(update())); + connect(this, SIGNAL(yMinChanged(double)), this, SLOT(update())); + connect(this, SIGNAL(yMaxChanged(double)), this, SLOT(update())); connect(this, SIGNAL(xLabelChanged(QString)), this, SLOT(update())); connect(this, SIGNAL(yLabelChanged(QString)), this, SLOT(update())); connect(this, SIGNAL(titleChanged(QString)), this, SLOT(update())); @@ -192,7 +192,7 @@ QRectF Figure::scaled(const QRectF &rect) { return QRectF(scaled(rect.topLeft()), scaled(rect.bottomRight())); } -void Figure::setXMin(float xMin) +void Figure::setXMin(double xMin) { if (m_xMin == xMin) return; @@ -201,7 +201,7 @@ void Figure::setXMin(float xMin) emit xMinChanged(xMin); } -void Figure::setXMax(float xMax) +void Figure::setXMax(double xMax) { if (m_xMax == xMax) return; @@ -210,16 +210,17 @@ void Figure::setXMax(float xMax) emit xMaxChanged(xMax); } -void Figure::setYMin(float yMin) +void Figure::setYMin(double yMin) { - if (m_yMin == yMin) + if (m_yMin == yMin) { return; + } m_yMin = yMin; emit yMinChanged(yMin); } -void Figure::setYMax(float yMax) +void Figure::setYMax(double yMax) { if (m_yMax == yMax) return; diff --git a/atomify-lammps/figure.h b/atomify-lammps/figure.h index 8b50f22c..924f93fc 100644 --- a/atomify-lammps/figure.h +++ b/atomify-lammps/figure.h @@ -7,20 +7,20 @@ class Figure : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(float xMin READ xMin WRITE setXMin NOTIFY xMinChanged) - Q_PROPERTY(float xMax READ xMax WRITE setXMax NOTIFY xMaxChanged) - Q_PROPERTY(float yMin READ yMin WRITE setYMin NOTIFY yMinChanged) - Q_PROPERTY(float yMax READ yMax WRITE setYMax NOTIFY yMaxChanged) + Q_PROPERTY(double xMin READ xMin WRITE setXMin NOTIFY xMinChanged) + Q_PROPERTY(double xMax READ xMax WRITE setXMax NOTIFY xMaxChanged) + Q_PROPERTY(double yMin READ yMin WRITE setYMin NOTIFY yMinChanged) + Q_PROPERTY(double yMax READ yMax WRITE setYMax NOTIFY yMaxChanged) Q_PROPERTY(QString xLabel READ xLabel WRITE setXLabel NOTIFY xLabelChanged) Q_PROPERTY(QString yLabel READ yLabel WRITE setYLabel NOTIFY yLabelChanged) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) private: - float m_xMin = 0; - float m_xMax = 0; - float m_yMin = 0; - float m_yMax = 0; + double m_xMin = 0; + double m_xMax = 0; + double m_yMin = 0; + double m_yMax = 0; QRectF m_figureRectangle; int numTicksX() { return width() / 100; } @@ -48,10 +48,10 @@ class Figure : public QQuickPaintedItem QLineF scaled(const QLineF &line); QPointF scaled(const QPointF &p, const QRectF &rect, const QPointF delta = QPointF(0,0)); - float xMin() const { return m_xMin; } - float xMax() const { return m_xMax; } - float yMin() const { return m_yMin; } - float yMax() const { return m_yMax; } + double xMin() const { return m_xMin; } + double xMax() const { return m_xMax; } + double yMin() const { return m_yMin; } + double yMax() const { return m_yMax; } QString xLabel() const; QString yLabel() const; @@ -60,10 +60,10 @@ class Figure : public QQuickPaintedItem QColor color() const; public slots: - void setXMin(float xMin); - void setXMax(float xMax); - void setYMin(float yMin); - void setYMax(float yMax); + void setXMin(double xMin); + void setXMax(double xMax); + void setYMin(double yMin); + void setYMax(double yMax); void setXLabel(QString xLabel); void setYLabel(QString yLabel); void setTitle(QString title); @@ -71,10 +71,10 @@ public slots: void setColor(QColor color); signals: - void xMinChanged(float xMin); - void xMaxChanged(float xMax); - void yMinChanged(float yMin); - void yMaxChanged(float yMax); + void xMinChanged(double xMin); + void xMaxChanged(double xMax); + void yMinChanged(double yMin); + void yMaxChanged(double yMax); void xLabelChanged(QString xLabel); void yLabelChanged(QString yLabel); void titleChanged(QString title); diff --git a/atomify-lammps/lammpscontroller.cpp b/atomify-lammps/lammpscontroller.cpp index 8804726c..803bc949 100644 --- a/atomify-lammps/lammpscontroller.cpp +++ b/atomify-lammps/lammpscontroller.cpp @@ -24,7 +24,7 @@ #include #include -#include "CPcompute.h" +#include "cpcompute.h" #include "mysimulator.h" #include "simulatorcontrol.h" #include "scriptcommand.h" @@ -194,30 +194,8 @@ bool LAMMPSController::computeExists(QString identifier) { void LAMMPSController::processSimulatorControls() { for(SimulatorControl *control : simulatorControls) { - control->synchronizeLammps(this); - } -} - -void LAMMPSController::processComputes() -{ - for(QString key : m_computes.keys()) { - if(!computeExists(key)) { - CPCompute *compute = m_computes[key]; - // We need to add it. First check all dependencies - bool allDependenciesFound = true; // Assume all are found and find potential counterexample - foreach(QString dependencyIdentifier, compute->dependencies()) { - if(!computeExists(dependencyIdentifier)) { - allDependenciesFound = false; - break; - } - } - - if(allDependenciesFound) { - state.preRunNeeded = true; // When a new compute is added, a run with pre yes is needed for it to be included - // Now that all dependencies are met we can add this one too - executeCommandInLAMMPS(compute->command()); - } - } + qDebug() << "Checking control: " << control->identifier(); + control->update(this); } } @@ -244,7 +222,7 @@ void LAMMPSController::executeActiveRunCommand() { void LAMMPSController::reset() { - int nargs = 3; + int nargs = 1; char **argv = new char*[nargs]; for(int i=0; iscreen = NULL; state = State(); // Reset current state variables } @@ -269,9 +247,8 @@ void LAMMPSController::tick() // If we have an active run command, perform the run command with the current chosen speed. if(state.runCommandActive > 0) { - processSimulatorControls(); - processComputes(); // Only work with computes and output when we will do a run executeActiveRunCommand(); + processSimulatorControls(); state.dataDirty = true; return; } @@ -294,8 +271,6 @@ void LAMMPSController::tick() } else { if(state.paused) return; // If no commands are queued, just perform a normal run command with the current simulation speed. - processSimulatorControls(); - processComputes(); // Only work with computes and output when we will do a run QElapsedTimer t; t.start(); @@ -305,6 +280,8 @@ void LAMMPSController::tick() } else { executeCommandInLAMMPS(QString("run %1 pre no post no").arg(state.simulationSpeed)); } + + processSimulatorControls(); state.numberOfTimesteps += state.simulationSpeed; state.timeSpentInLammps += t.elapsed(); } diff --git a/atomify-lammps/lammpscontroller.h b/atomify-lammps/lammpscontroller.h index aaba7d08..c31983cb 100644 --- a/atomify-lammps/lammpscontroller.h +++ b/atomify-lammps/lammpscontroller.h @@ -9,8 +9,7 @@ #include #include #include -#include "lammpsoutput.h" -#include "CPcompute.h" +#include "cpcompute.h" #include "scripthandler.h" using namespace LAMMPS_NS; @@ -38,7 +37,6 @@ class LAMMPSController LAMMPS *m_lammps = nullptr; MyWorker *m_worker = nullptr; - void processComputes(); void executeActiveRunCommand(); void notifySimulatorControlsAboutCommand(); public: diff --git a/atomify-lammps/lammpsoutput.cpp b/atomify-lammps/lammpsoutput.cpp deleted file mode 100644 index 2043d90d..00000000 --- a/atomify-lammps/lammpsoutput.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "lammpsoutput.h" -#include -#include -#include -#include -#include -#include "CPcompute.h" -#if defined(Q_OS_ANDROID) -#include "stdioext.h" -#elif defined(Q_OS_LINUX) -#include -#endif -using namespace std; - -LammpsOutput::LammpsOutput() -{ -#ifdef Q_OS_LINUX - cookie_io_functions_t funcs; - funcs.close = LammpsOutput::clean; - funcs.read = LammpsOutput::read; - funcs.write = LammpsOutput::write; - funcs.seek = LammpsOutput::seek; - m_filePointer = fopencookie((void*)this, "w", funcs); -#else - m_filePointer = funopen((const void*)this, LammpsOutput::read, LammpsOutput::write, LammpsOutput::seek, LammpsOutput::clean); -#endif - -} - -#if defined(Q_OS_ANDROID) -ssize_t LammpsOutput::read(void *, char *, size_t ) { - -} - -ssize_t LammpsOutput::write(void *cookie, const char *buffer, size_t n) { - LammpsOutput *parser = (LammpsOutput*)cookie; - parser->parse(QString(buffer)); -} - -int LammpsOutput::seek(void *cookie, off_t *__pos, int __w) { - return 0; -} -#elif defined(Q_OS_LINUX) -ssize_t LammpsOutput::read(void *, char *, size_t ) { - -} - -ssize_t LammpsOutput::write(void *cookie, const char *buffer, size_t n) { - LammpsOutput *parser = (LammpsOutput*)cookie; - parser->parse(QString(buffer)); -} - -int LammpsOutput::seek(void *cookie, _IO_off64_t *__pos, int __w) { - return 0; -} -#else -int LammpsOutput::read (void *, char *, int ) { - -} - -int LammpsOutput::write (void *cookie, const char *buffer, int size) { - LammpsOutput *parser = (LammpsOutput*)cookie; - parser->parse(QString(buffer)); -} - - -fpos_t LammpsOutput::seek (void *, fpos_t , int ) { - fpos_t obj; - return obj; -} - -#endif - -int LammpsOutput::clean (void *) { - - return 0; -} - -FILE *LammpsOutput::stream() -{ - return m_filePointer; -} - -void LammpsOutput::parseVectorOutput(const QString &buffer) { - QStringList lines = buffer.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); - - unsigned int timestep = 0; - int numberOfValues = 0; - QVector numericalOutput; - - bool isFirstLine = true; - foreach(const QString &line, lines) { - bool invalidLine = false; - QStringList words = line.split(QRegExp("[ ]"), QString::SkipEmptyParts); // Split by spaces. - - bool isFirstWord = true; - foreach(const QString &word, words) { - bool isNumerical; - double value = word.toDouble(&isNumerical); - if(!isNumerical) { - // Could not parse to double. Then this line is nothing we want. - invalidLine = true; - break; - } - - if(isFirstLine) { - // This line contains 'Timestep NumValues' - if(isFirstWord) { - timestep = value; - isFirstWord = false; - } else { - numberOfValues = value; - } - } else { - // This line contains ValueId Value - if(isFirstWord) { - // First word is the value id (1,2,...) - isFirstWord = false; - } else { - // This is our value - numericalOutput.push_back(value); - } - } - } - - if(isFirstLine) isFirstLine = false; - } - - m_compute->setValues(numericalOutput); -} - -void LammpsOutput::parseScalarOutput(const QString &buffer) { - QStringList lines = buffer.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); - - unsigned int timestep = 0; - foreach(const QString &line, lines) { - bool invalidLine = false; - - QStringList words = line.split(QRegExp("[ ]"), QString::SkipEmptyParts); // Split by spaces. - QVector numericalOutput; - - bool isFirstWord = true; - foreach(const QString &word, words) { - bool isNumerical; - double value = word.toDouble(&isNumerical); - if(!isNumerical) { - // Could not parse to double. Then this line is nothing we want. - invalidLine = true; - break; - } - - if(isFirstWord) { - // First word in fix outputs is always timestep - timestep = value; - isFirstWord = false; - } else numericalOutput.push_back(value); - } - - if(!invalidLine) { - m_compute->setValues(numericalOutput); - } - } -} - -void LammpsOutput::parse(QString buffer) -{ - if(m_compute->isVector()) parseVectorOutput(buffer); - else parseScalarOutput(buffer); - -} diff --git a/atomify-lammps/lammpsoutput.h b/atomify-lammps/lammpsoutput.h deleted file mode 100644 index d9808140..00000000 --- a/atomify-lammps/lammpsoutput.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LAMMPSOUTPUTPARSER_H -#define LAMMPSOUTPUTPARSER_H -#include -#include -#include -#include - -class CPCompute; -class LammpsOutput : public QObject -{ - Q_OBJECT -public: - LammpsOutput(); - FILE *stream(); - void parse(QString buffer); -private: - // These are functions allowing us to mimic a FILE* object -#if defined(Q_OS_ANDROID) - static ssize_t read(void *, char *, size_t); - static ssize_t write(void *cookie, const char *buffer, size_t n); - static int seek(void *cookie, off_t *__pos, int __w); -#elif defined(Q_OS_LINUX) - static __ssize_t read(void *, char *, size_t); - static __ssize_t write(void *cookie, const char *buffer, size_t n); - static int seek(void *cookie, __off64_t *__pos, int __w); -#else - static fpos_t seek(void *, fpos_t, int); - static int write(void *cookie, const char *buffer, int size); - static int read(void *, char *, int); -#endif - static int clean(void *); - FILE *m_filePointer = nullptr; - CPCompute* m_compute; - friend class CPCompute; - void parseVectorOutput(const QString &buffer); - void parseScalarOutput(const QString &buffer); -}; - -#endif // LAMMPSOUTPUTPARSER_H diff --git a/atomify-lammps/main.cpp b/atomify-lammps/main.cpp index d0f14a23..0339dbfb 100644 --- a/atomify-lammps/main.cpp +++ b/atomify-lammps/main.cpp @@ -10,8 +10,7 @@ #include "mysimulator.h" #include "highlighter.h" -#include "CPcompute.h" -#include "lammpsoutput.h" +#include "cpcompute.h" #include "atomstyle.h" #include "fileio.h" #include "nvt.h" @@ -25,7 +24,7 @@ int main(int argc, char *argv[]) qmlRegisterType("Atomify", 1, 0, "Highlighter"); qmlRegisterType("Atomify", 1, 0, "Compute"); qmlRegisterType("Atomify", 1, 0, "AtomStyle"); - qmlRegisterType("Atomify", 1, 0, "NVT"); + // qmlRegisterType("Atomify", 1, 0, "NVT"); qmlRegisterType("Atomify", 1, 0, "ScriptHandler"); qmlRegisterType
("QMLPlot", 1, 0, "Figure"); qmlRegisterType("QMLPlot", 1, 0, "LineGraph"); diff --git a/atomify-lammps/mysimulator.cpp b/atomify-lammps/mysimulator.cpp index ee444ceb..41fb6ec2 100644 --- a/atomify-lammps/mysimulator.cpp +++ b/atomify-lammps/mysimulator.cpp @@ -42,10 +42,6 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) if(mySimulator->willReset()) { m_lammpsController.reset(); mySimulator->setWillReset(false); - auto simulatorControls = mySimulator->findChildren(); - for(auto *simulatorControl : simulatorControls) { - simulatorControl->setDirty(false); - } emit mySimulator->lammpsDidReset(); } @@ -73,9 +69,9 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) mySimulator->setSystemSize(m_lammpsController.systemSize()); mySimulator->setTimePerTimestep(m_lammpsController.timePerTimestep()); - for(CPCompute *compute : mySimulator->computes()) { - compute->update(&m_lammpsController); - } +// for(CPCompute *compute : mySimulator->computes()) { +// compute->update(&m_lammpsController); +// } m_lammpsController.setScriptHandler(mySimulator->scriptHandler()); @@ -199,10 +195,10 @@ void AtomifySimulator::setComputes(const QMap &computes) m_computes = computes; } -void AtomifySimulator::addCompute(CPCompute *compute) -{ - m_computes[compute->identifier()] = compute; -} +//void AtomifySimulator::addCompute(CPCompute *compute) +//{ +// m_computes[compute->identifier()] = compute; +//} bool AtomifySimulator::paused() const { diff --git a/atomify-lammps/mysimulator.h b/atomify-lammps/mysimulator.h index a6cc0e77..35fa0065 100644 --- a/atomify-lammps/mysimulator.h +++ b/atomify-lammps/mysimulator.h @@ -10,7 +10,6 @@ #include #include "lammpscontroller.h" -#include "lammpsoutput.h" #include "atomstyle.h" #include "scripthandler.h" @@ -63,7 +62,6 @@ class AtomifySimulator : public Simulator void addCompute(CPCompute *compute); QMap computes() const; void setComputes(const QMap &computes); - LammpsOutput* lammpsOutput() const; AtomStyle* atomStyle() const; double simulationTime() const; bool paused() const; diff --git a/atomify-lammps/nvt.cpp b/atomify-lammps/nvt.cpp index 92a22e6a..cdc41372 100644 --- a/atomify-lammps/nvt.cpp +++ b/atomify-lammps/nvt.cpp @@ -1,96 +1,96 @@ -#include "nvt.h" -#include "lammpscontroller.h" -#include -#include +//#include "nvt.h" +//#include "lammpscontroller.h" +//#include +//#include -class FixNHHack : public FixNH { -public: - double target() { return t_target; } - void setTargets(double targetValue) { - t_target = targetValue; - t_start = targetValue; - t_stop = targetValue; - } -}; +//class FixNHHack : public FixNH { +//public: +// double target() { return t_target; } +// void setTargets(double targetValue) { +// t_target = targetValue; +// t_start = targetValue; +// t_stop = targetValue; +// } +//}; -NVT::NVT(QObject *parent) : SimulatorControl(parent) -{ +//NVT::NVT(QObject *parent) : SimulatorControl(parent) +//{ -} +//} -double NVT::targetTemperature() const -{ - return m_targetTemperature; -} +//double NVT::targetTemperature() const +//{ +// return m_targetTemperature; +//} -void NVT::setTargetTemperature(double targetTemperature) -{ - if (m_targetTemperature == targetTemperature) - return; +//void NVT::setTargetTemperature(double targetTemperature) +//{ +// if (m_targetTemperature == targetTemperature) +// return; - m_targetTemperature = targetTemperature; - setDirty(true); - emit targetTemperatureChanged(targetTemperature); -} +// m_targetTemperature = targetTemperature; +// setDirty(true); +// emit targetTemperatureChanged(targetTemperature); +//} -void NVT::setTemperatureDampening(double temperatureDampening) -{ - if (m_temperatureDampening == temperatureDampening) - return; +//void NVT::setTemperatureDampening(double temperatureDampening) +//{ +// if (m_temperatureDampening == temperatureDampening) +// return; - m_temperatureDampening = temperatureDampening; - emit temperatureDampeningChanged(temperatureDampening); -} +// m_temperatureDampening = temperatureDampening; +// emit temperatureDampeningChanged(temperatureDampening); +//} -void NVT::synchronizeLammps(LAMMPSController *lammpsController) -{ - if(lammpsController->scriptHandler() == nullptr) { - return; - } - FixNVT *fix = lammpsController->findFixByType(); - if(fix) { - FixNH *fixNH = dynamic_cast(fix); - FixNHHack *fixHack = reinterpret_cast(fixNH); - if(fixHack) { - if(m_dirty) { - m_dirty = false; - if(!m_enabled) { - QList disableCommands; - disableCommands.push_back(QString("unfix %1").arg(fix->id)); - disableCommands.push_back("fix nve all nve"); - lammpsController->scriptHandler()->addCommandsToTop(disableCommands, ScriptCommand::Type::SingleCommand); - return; - } +//void NVT::update(LAMMPSController *lammpsController) +//{ +// if(lammpsController->scriptHandler() == nullptr) { +// return; +// } +// FixNVT *fix = lammpsController->findFixByType(); +// if(fix) { +// FixNH *fixNH = dynamic_cast(fix); +// FixNHHack *fixHack = reinterpret_cast(fixNH); +// if(fixHack) { +// if(m_dirty) { +// m_dirty = false; +// if(!m_enabled) { +// QList disableCommands; +// disableCommands.push_back(QString("unfix %1").arg(fix->id)); +// disableCommands.push_back("fix nve all nve"); +// lammpsController->scriptHandler()->addCommandsToTop(disableCommands, ScriptCommand::Type::SingleCommand); +// return; +// } - if(m_targetTemperature != fixHack->target()) { - fixHack->setTargets(m_targetTemperature); - } - } else { - if(m_targetTemperature != fixHack->target()) { - m_targetTemperature = fixHack->target(); - emit targetTemperatureChanged(m_targetTemperature); - } - if(!m_enabled) { - m_enabled = true; - emit enabledChanged(m_enabled); - } - } - } - } else { - if(m_dirty && m_enabled) { - lammpsController->disableAllEnsembleFixes(); - QString command = QString("fix nvt all nvt temp %1 %1 %2").arg(m_targetTemperature).arg(m_temperatureDampening); - lammpsController->scriptHandler()->addCommandToTop(ScriptCommand(command, ScriptCommand::Type::SingleCommand)); - } else if(m_enabled) { - m_enabled = false; - emit enabledChanged(m_enabled); - } - } +// if(m_targetTemperature != fixHack->target()) { +// fixHack->setTargets(m_targetTemperature); +// } +// } else { +// if(m_targetTemperature != fixHack->target()) { +// m_targetTemperature = fixHack->target(); +// emit targetTemperatureChanged(m_targetTemperature); +// } +// if(!m_enabled) { +// m_enabled = true; +// emit enabledChanged(m_enabled); +// } +// } +// } +// } else { +// if(m_dirty && m_enabled) { +// lammpsController->disableAllEnsembleFixes(); +// QString command = QString("fix nvt all nvt temp %1 %1 %2").arg(m_targetTemperature).arg(m_temperatureDampening); +// lammpsController->scriptHandler()->addCommandToTop(ScriptCommand(command, ScriptCommand::Type::SingleCommand)); +// } else if(m_enabled) { +// m_enabled = false; +// emit enabledChanged(m_enabled); +// } +// } - m_dirty = false; -} +// m_dirty = false; +//} -double NVT::temperatureDampening() const -{ - return m_temperatureDampening; -} +//double NVT::temperatureDampening() const +//{ +// return m_temperatureDampening; +//} diff --git a/atomify-lammps/nvt.h b/atomify-lammps/nvt.h index a512fe6e..7dbd8205 100644 --- a/atomify-lammps/nvt.h +++ b/atomify-lammps/nvt.h @@ -1,33 +1,33 @@ -#ifndef NVT_H -#define NVT_H +//#ifndef NVT_H +//#define NVT_H -#include "simulatorcontrol.h" -#include "mysimulator.h" +//#include "simulatorcontrol.h" +//#include "mysimulator.h" -class NVT : public SimulatorControl -{ - Q_OBJECT - Q_PROPERTY(double targetTemperature READ targetTemperature WRITE setTargetTemperature NOTIFY targetTemperatureChanged) - Q_PROPERTY(double temperatureDampening READ temperatureDampening WRITE setTemperatureDampening NOTIFY temperatureDampeningChanged) -private: - double m_targetTemperature = 1; - double m_temperatureDampening = 1.0; +//class NVT : public SimulatorControl +//{ +// Q_OBJECT +// Q_PROPERTY(double targetTemperature READ targetTemperature WRITE setTargetTemperature NOTIFY targetTemperatureChanged) +// Q_PROPERTY(double temperatureDampening READ temperatureDampening WRITE setTemperatureDampening NOTIFY temperatureDampeningChanged) +//private: +// double m_targetTemperature = 1; +// double m_temperatureDampening = 1.0; -public: - explicit NVT(QObject *parent = 0); - double targetTemperature() const; +//public: +// explicit NVT(QObject *parent = 0); +// double targetTemperature() const; -signals: - void targetTemperatureChanged(double targetTemperature); - void temperatureDampeningChanged(double temperatureDampening); +//signals: +// void targetTemperatureChanged(double targetTemperature); +// void temperatureDampeningChanged(double temperatureDampening); -public slots: -void setTargetTemperature(double targetTemperature); -void setTemperatureDampening(double temperatureDampening); +//public slots: +//void setTargetTemperature(double targetTemperature); +//void setTemperatureDampening(double temperatureDampening); -public: -virtual void synchronizeLammps(LAMMPSController *lammpsController); -double temperatureDampening() const; -}; +//public: +//virtual void update(LAMMPSController *lammpsController); +//double temperatureDampening() const; +//}; -#endif // NVT_H +//#endif // NVT_H diff --git a/atomify-lammps/qml/desktop/MainDesktop.qml b/atomify-lammps/qml/desktop/MainDesktop.qml index 61f19f9b..6a62cdfb 100644 --- a/atomify-lammps/qml/desktop/MainDesktop.qml +++ b/atomify-lammps/qml/desktop/MainDesktop.qml @@ -74,8 +74,8 @@ Item { SimulationSummary { simulator: desktopRoot.simulator - pressure: pressure - temperature: temperature +// pressure: pressure +// temperature: temperature } Rectangle { diff --git a/atomify-lammps/qml/desktop/SimulationSummary.qml b/atomify-lammps/qml/desktop/SimulationSummary.qml index fc21274d..f1e7e397 100644 --- a/atomify-lammps/qml/desktop/SimulationSummary.qml +++ b/atomify-lammps/qml/desktop/SimulationSummary.qml @@ -4,8 +4,8 @@ import Atomify 1.0 Rectangle { property AtomifySimulator simulator - property Compute pressure - property Compute temperature +// property Compute pressure +// property Compute temperature x: 20 y: 20 width: statusColumn.width+20 @@ -40,15 +40,15 @@ Rectangle { text: "Time per timestep [ms]: "+simulator.timePerTimestep.toFixed(2) } - Text { - font.bold: true - text: "Temperature: "+ (temperature ? temperature.value : "N/A") - } +// Text { +// font.bold: true +// text: "Temperature: "+ (temperature ? temperature.value : "N/A") +// } - Text { - font.bold: true - text: "Pressure: " + (pressure ? pressure.value : "N/A") - } +// Text { +// font.bold: true +// text: "Pressure: " + (pressure ? pressure.value : "N/A") +// } } MouseArea { diff --git a/atomify-lammps/qml/main.qml b/atomify-lammps/qml/main.qml index a6484790..335d97fc 100644 --- a/atomify-lammps/qml/main.qml +++ b/atomify-lammps/qml/main.qml @@ -58,67 +58,63 @@ ApplicationWindow { id: myAtomStyle } - NVT { - id: nvt - temperatureDampening: 0.01 - onEnabledChanged: { - nvtCheck.checked = enabled - } - } +// NVT { +// id: nvt +// temperatureDampening: 0.01 +// onEnabledChanged: { +// nvtCheck.checked = enabled +// } +// } scriptHandler: ScriptHandler { atomStyle: myAtomStyle } - } - Compute { - property real maxValue: 0 - id: computeMsd - identifier: "msd" - command: "compute msd all msd" - isVector: true - simulator: mySimulator - onFourthValueChanged: { - // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) - tempGraph.addPoint(mySimulator.simulationTime, fourthValue) - tempPlot.xMax = mySimulator.simulationTime - //tempPlot.xMin = mySimulator.simulationTime-1 - maxValue = Math.max(maxValue, fourthValue) - tempPlot.yMax = maxValue + Compute { + property real maxValue: 0 + id: computeTemp + identifier: "temperature" + command: "all temp" + onValueChanged: { +// tempGraph.addPoint(mySimulator.simulationTime, value) +// tempPlot.xMax = mySimulator.simulationTime +// tempPlot.xMin = mySimulator.simulationTime-1 +// maxValue = Math.max(maxValue, value) +// tempPlot.yMax = maxValue + } } - } - Compute { - property real maxValue: 0 - id: computePressure - identifier: "pressure" - command: "compute pressure all pressure temperature" - simulator: mySimulator - dependencies: ["temperature"] - onValueChanged: { - // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) -// tempGraph.addPoint(mySimulator.simulationTime, value) -// tempPlot.xMax = mySimulator.simulationTime -// tempPlot.xMin = mySimulator.simulationTime-1 -// maxValue = Math.max(maxValue, value) -// tempPlot.yMax = maxValue + Compute { + property real maxValue: 0 + id: computePressure + identifier: "pressure" + command: "all pressure temperature" + dependencies: [computeTemp] + onValueChanged: { + tempGraph.addPoint(mySimulator.simulationTime, value) + tempPlot.xMax = mySimulator.simulationTime + tempPlot.xMin = mySimulator.simulationTime-1 + maxValue = Math.max(maxValue, value) + tempPlot.yMax = maxValue + } } } - Compute { - property real maxValue: 0 - id: computeTemp - identifier: "temperature" - command: "compute temperature all temp" - simulator: mySimulator -// onValueChanged: { +// Compute { +// property real maxValue: 0 +// id: computeMsd +// identifier: "msd" +// command: "compute msd all msd" +// isVector: true +// simulator: mySimulator +// onFourthValueChanged: { // // tempGraph.addPoint(mySimulator.simulationTime, 0.2+0.8*Math.sin(mySimulator.simulationTime)) -// tempGraph.addPoint(mySimulator.simulationTime, value) +// tempGraph.addPoint(mySimulator.simulationTime, fourthValue) // tempPlot.xMax = mySimulator.simulationTime -// tempPlot.xMin = mySimulator.simulationTime-1 -// maxValue = Math.max(maxValue, value) +// //tempPlot.xMin = mySimulator.simulationTime-1 +// maxValue = Math.max(maxValue, fourthValue) // tempPlot.yMax = maxValue // } - } +// } Rectangle { width: 400 @@ -158,15 +154,15 @@ ApplicationWindow { } } - Slider { - id: nvtSlider - minimumValue: 0.1 - maximumValue: 6 - value: nvt.targetTemperature - onValueChanged: { - nvt.targetTemperature = value - } - } +// Slider { +// id: nvtSlider +// minimumValue: 0.1 +// maximumValue: 6 +// value: nvt.targetTemperature +// onValueChanged: { +// nvt.targetTemperature = value +// } +// } } } diff --git a/atomify-lammps/scriptcommand.h b/atomify-lammps/scriptcommand.h index 81ebd2b1..d128c7c3 100644 --- a/atomify-lammps/scriptcommand.h +++ b/atomify-lammps/scriptcommand.h @@ -7,7 +7,6 @@ class ScriptCommand { public: enum class Type {NoCommand, File, Editor, SingleCommand, SkipLammpsTick}; - ScriptCommand(QString command = "", Type type = Type::NoCommand, int line = -1, QString filename = ""); const QString& command() const; diff --git a/atomify-lammps/simulatorcontrol.cpp b/atomify-lammps/simulatorcontrol.cpp index c1719fc4..302e13b5 100644 --- a/atomify-lammps/simulatorcontrol.cpp +++ b/atomify-lammps/simulatorcontrol.cpp @@ -1,13 +1,75 @@ #include "simulatorcontrol.h" +#include "lammpscontroller.h" +#include "scripthandler.h" +#include "mysimulator.h" SimulatorControl::SimulatorControl(QObject *parent) : QObject(parent) { } -bool SimulatorControl::dirty() const +bool SimulatorControl::addToLammps(LAMMPSController *lammpsController) { + qDebug() << "Trying to add to lammps..."; + for(const QVariant &variant : m_dependencies) { + SimulatorControl *dependency = qvariant_cast(variant); + if(dependency && !dependency->existsInLammps(lammpsController)) { + // We found one dependency that is not added to LAMMPS, abort this mission + return false; + } + } + + qDebug() << "All dependencies are met"; + ScriptHandler *scriptHandler = lammpsController->scriptHandler(); + scriptHandler->addCommandToTop(ScriptCommand(enabledCommand(), ScriptCommand::Type::SingleCommand)); + return true; +} + +bool SimulatorControl::dependenciesValid(LAMMPSController *lammpsController) +{ + bool valid = true; + for(const QVariant &variant : m_dependencies) { + SimulatorControl *dependency = qvariant_cast(variant); + if(dependency) { + // Check if the dependency is not in lammps or one of its dependencies are not in lammps + if(!dependency->existsInLammps(lammpsController) || !dependency->dependenciesValid(lammpsController)) { + valid = false; + } + } + } + + return valid; +} + +void SimulatorControl::update(LAMMPSController *lammpsController) { - return m_dirty; + qDebug() << "Updating control with identifier " << identifier(); + if(!lammpsController->scriptHandler()) { + return; + } + + bool exists = existsInLammps(lammpsController); + qDebug() << identifier() << " exists: " << exists; + qDebug() << "Enabled: " << m_enabled; + if(!exists && m_enabled) { + // We should exist, so let's try to add. + // Whatever happens, just return. We aren't ready to compute any values yet anyway. + addToLammps(lammpsController); + return; + } + + if(exists && !m_enabled || !dependenciesValid(lammpsController)) { + // We should not exist, but we do. Now remove from lammps + lammpsController->scriptHandler()->addCommandToTop(disableCommand()); + } + + if(exists) { + QString currentCommand = command(); + updateCommand(); + if(currentCommand!=command()) { + QList reAddCommands = { disableCommand(), enabledCommand() }; + lammpsController->scriptHandler()->addCommandsToTop(reAddCommands, ScriptCommand::Type::SingleCommand); + } + } } bool SimulatorControl::enabled() const @@ -15,21 +77,52 @@ bool SimulatorControl::enabled() const return m_enabled; } -void SimulatorControl::setDirty(bool dirty) +QString SimulatorControl::identifier() const { - if (m_dirty == dirty) - return; + return m_identifier; +} + +QString SimulatorControl::command() const +{ + return m_command; +} - m_dirty = dirty; - emit dirtyChanged(dirty); +QVariantList SimulatorControl::dependencies() const +{ + return m_dependencies; } void SimulatorControl::setEnabled(bool enabled) { if (m_enabled == enabled) return; - setDirty(true); m_enabled = enabled; emit enabledChanged(enabled); } +void SimulatorControl::setIdentifier(QString identifier) +{ + if (m_identifier == identifier) + return; + + m_identifier = identifier; + emit identifierChanged(identifier); +} + +void SimulatorControl::setCommand(QString command) +{ + if (m_command == command) + return; + + m_command = command; + emit commandChanged(command); +} + +void SimulatorControl::setDependencies(QVariantList dependencies) +{ + if (m_dependencies == dependencies) + return; + + m_dependencies = dependencies; + emit dependenciesChanged(dependencies); +} diff --git a/atomify-lammps/simulatorcontrol.h b/atomify-lammps/simulatorcontrol.h index 54733876..37535d1b 100644 --- a/atomify-lammps/simulatorcontrol.h +++ b/atomify-lammps/simulatorcontrol.h @@ -2,30 +2,49 @@ #define SIMULATORCONTROL_H #include -class LAMMPSController; +#include +class LAMMPSController; +class AtomifySimulator; class SimulatorControl : public QObject { Q_OBJECT - Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) + Q_PROPERTY(QString command READ command WRITE setCommand NOTIFY commandChanged) + Q_PROPERTY(QVariantList dependencies READ dependencies WRITE setDependencies NOTIFY dependenciesChanged) + protected: - bool m_dirty = false; - bool m_enabled = false; + QString m_command; + QString m_identifier; + QVariantList m_dependencies; + bool m_enabled = true; + bool addToLammps(LAMMPSController *lammpsController); + virtual void updateCommand() = 0; + virtual QString enabledCommand() = 0; + virtual QString disableCommand() = 0; public: explicit SimulatorControl(QObject *parent = 0); - virtual void synchronizeLammps(LAMMPSController *lammpsController) = 0; - bool dirty() const; bool enabled() const; -signals: + QString identifier() const; + QString command() const; + QVariantList dependencies() const; + bool dependenciesValid(LAMMPSController *lammpsController); + virtual bool existsInLammps(LAMMPSController *lammpsController) = 0; + virtual void update(LAMMPSController *lammpsController); - void dirtyChanged(bool dirty); +signals: void enabledChanged(bool enabled); + void identifierChanged(QString identifier); + void commandChanged(QString command); + void dependenciesChanged(QVariantList dependencies); public slots: - void setDirty(bool dirty); void setEnabled(bool enabled); + void setIdentifier(QString identifier); + void setCommand(QString command); + void setDependencies(QVariantList dependencies); }; #endif // SIMULATORCONTROL_H diff --git a/atomify-lammps/stdioext.c b/atomify-lammps/stdioext.c deleted file mode 100644 index 81ecf2b2..00000000 --- a/atomify-lammps/stdioext.c +++ /dev/null @@ -1,187 +0,0 @@ -/* Copyright (C) 2007 Eric Blake - * Permission to use, copy, modify, and distribute this software - * is freely granted, provided that this notice is preserved. - * - * Modifications for Android written Jul 2009 by Alan Viverette - */ - -/* -FUNCTION -<>---open a stream with custom callbacks - -INDEX - fopencookie - -ANSI_SYNOPSIS - #include - typedef ssize_t (*cookie_read_function_t)(void *_cookie, char *_buf, - size_t _n); - typedef ssize_t (*cookie_write_function_t)(void *_cookie, - const char *_buf, size_t _n); - typedef int (*cookie_seek_function_t)(void *_cookie, off_t *_off, - int _whence); - typedef int (*cookie_close_function_t)(void *_cookie); - FILE *fopencookie(const void *<[cookie]>, const char *<[mode]>, - cookie_io_functions_t <[functions]>); - -DESCRIPTION -<> creates a <> stream where I/O is performed using -custom callbacks. The callbacks are registered via the structure: - -. typedef struct -. { -. cookie_read_function_t *read; -. cookie_write_function_t *write; -. cookie_seek_function_t *seek; -. cookie_close_function_t *close; -. } cookie_io_functions_t; - -The stream is opened with <[mode]> treated as in <>. The -callbacks <[functions.read]> and <[functions.write]> may only be NULL -when <[mode]> does not require them. - -<[functions.read]> should return -1 on failure, or else the number of -bytes read (0 on EOF). It is similar to <>, except that -<[cookie]> will be passed as the first argument. - -<[functions.write]> should return -1 on failure, or else the number of -bytes written. It is similar to <>, except that <[cookie]> -will be passed as the first argument. - -<[functions.seek]> should return -1 on failure, and 0 on success, with -*<[_off]> set to the current file position. It is a cross between -<> and <>, with the <[_whence]> argument interpreted in -the same manner. A NULL <[functions.seek]> makes the stream behave -similarly to a pipe in relation to stdio functions that require -positioning. - -<[functions.close]> should return -1 on failure, or 0 on success. It -is similar to <>, except that <[cookie]> will be passed as the -first argument. A NULL <[functions.close]> merely flushes all data -then lets <> succeed. A failed close will still invalidate -the stream. - -Read and write I/O functions are allowed to change the underlying -buffer on fully buffered or line buffered streams by calling -<>. They are also not required to completely fill or empty -the buffer. They are not, however, allowed to change streams from -unbuffered to buffered or to change the state of the line buffering -flag. They must also be prepared to have read or write calls occur on -buffers other than the one most recently specified. - -RETURNS -The return value is an open FILE pointer on success. On error, -<> is returned, and <> will be set to EINVAL if a -function pointer is missing or <[mode]> is invalid, ENOMEM if the -stream cannot be created, or EMFILE if too many streams are already -open. - -PORTABILITY -This function is a newlib extension, copying the prototype from Linux. -It is not portable. See also the <> interface from BSD. - -Supporting OS subroutines required: <>. -*/ - -#include -#include -#include -#include "stdioext.h" - -typedef struct fccookie { - void *cookie; - FILE *fp; - ssize_t (*readfn)(void *, char *, size_t); - ssize_t (*writefn)(void *, const char *, size_t); - int (*seekfn)(void *, off_t *, int); - int (*closefn)(void *); -} fccookie; - -static int -fcread(void *cookie, char *buf, int n) -{ - int result; - fccookie *c = (fccookie *) cookie; - result = c->readfn (c->cookie, buf, n); - return result; -} - -static int -fcwrite(void *cookie, const char *buf, int n) -{ - int result; - fccookie *c = (fccookie *) cookie; - if (c->fp->_flags & __SAPP && c->fp->_seek) - { - c->fp->_seek (cookie, 0, SEEK_END); - } - result = c->writefn (c->cookie, buf, n); - return result; -} - -static fpos_t -fcseek(void *cookie, fpos_t pos, int whence) -{ - fccookie *c = (fccookie *) cookie; - off_t offset = (off_t) pos; - - c->seekfn (c->cookie, &offset, whence); - - return (fpos_t) offset; -} - -static int -fcclose(void *cookie) -{ - int result = 0; - fccookie *c = (fccookie *) cookie; - if (c->closefn) - { - result = c->closefn (c->cookie); - } - free (c); - return result; -} - -FILE * -fopencookie(void *cookie, const char *mode, cookie_io_functions_t functions) -{ - FILE *fp; - fccookie *c; - int flags; - int dummy; - - if ((flags = __sflags (mode, &dummy)) == 0) - return NULL; - if (((flags & (__SRD | __SRW)) && !functions.read) - || ((flags & (__SWR | __SRW)) && !functions.write)) - { - return NULL; - } - if ((fp = (FILE *) __sfp ()) == NULL) - return NULL; - if ((c = (fccookie *) malloc (sizeof *c)) == NULL) - { - fp->_flags = 0; - return NULL; - } - - fp->_file = -1; - fp->_flags = flags; - c->cookie = cookie; - c->fp = fp; - fp->_cookie = c; - c->readfn = functions.read; - fp->_read = fcread; - c->writefn = functions.write; - fp->_write = fcwrite; - c->seekfn = functions.seek; - fp->_seek = functions.seek ? fcseek : NULL; - c->closefn = functions.close; - fp->_close = fcclose; - - return fp; -} - - - diff --git a/atomify-lammps/stdioext.h b/atomify-lammps/stdioext.h deleted file mode 100644 index 6c1bd416..00000000 --- a/atomify-lammps/stdioext.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _STDIOEXT_H -#define _STDIOEXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct cookie_io_functions_t { - ssize_t (*read)(void *cookie, char *buf, size_t n); - ssize_t (*write)(void *cookie, const char *buf, size_t n); - int (*seek)(void *cookie, off_t *pos, int whence); - int (*close)(void *cookie); -} cookie_io_functions_t; - -FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t functions); - -FILE *fmemopen(void *buf, size_t size, const char *mode); - -FILE *open_memstream(char **buf, size_t *size); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* _STDIOEXT_H */ From af46bc69bdebaefdf682dd34a5a0ae98b861472b Mon Sep 17 00:00:00 2001 From: Anders Hafreager Date: Wed, 28 Oct 2015 20:50:05 +0100 Subject: [PATCH 4/5] Fixed better handling of SimulatorControl. Added resetCommands, enabledCommands and disableCommands. Fixed so disableAllEnsembleFixes adds commands to stack instead of calling directly on LAMMPS. --- atomify-lammps/cpcompute.cpp | 16 ++- atomify-lammps/cpcompute.h | 9 +- atomify-lammps/cpfix.cpp | 19 ++-- atomify-lammps/cpfix.h | 12 +-- atomify-lammps/lammpscontroller.cpp | 47 ++++----- atomify-lammps/main.cpp | 6 +- atomify-lammps/mysimulator.cpp | 4 +- atomify-lammps/nvt.cpp | 149 ++++++++++------------------ atomify-lammps/nvt.h | 56 ++++++----- atomify-lammps/qml/main.qml | 52 +++++----- atomify-lammps/scriptcommand.h | 2 +- atomify-lammps/scripthandler.cpp | 32 +++--- atomify-lammps/scripthandler.h | 2 +- atomify-lammps/scriptparser.cpp | 9 ++ atomify-lammps/scriptparser.h | 1 + atomify-lammps/simulatorcontrol.cpp | 18 ++-- atomify-lammps/simulatorcontrol.h | 6 +- 17 files changed, 216 insertions(+), 224 deletions(-) diff --git a/atomify-lammps/cpcompute.cpp b/atomify-lammps/cpcompute.cpp index 682864f2..9b570784 100644 --- a/atomify-lammps/cpcompute.cpp +++ b/atomify-lammps/cpcompute.cpp @@ -2,7 +2,7 @@ #include "lammpscontroller.h" #include "mysimulator.h" -CPCompute::CPCompute() +CPCompute::CPCompute(QObject *parent) : SimulatorControl(parent) { } @@ -50,14 +50,14 @@ void CPCompute::update(LAMMPSController *lammpsController) } } -QString CPCompute::enabledCommand() +QList CPCompute::enabledCommands() { - return QString("compute %1 %2").arg(identifier()).arg(command()); + return { QString("compute %1 %2").arg(identifier()).arg(command()) }; } -QString CPCompute::disableCommand() +QList CPCompute::disableCommands() { - return QString("uncompute %1").arg(identifier()); + return {QString("uncompute %1").arg(identifier())}; } bool CPCompute::existsInLammps(LAMMPSController *lammpsController) @@ -122,3 +122,9 @@ void CPCompute::setIsVector(bool isVector) m_isVector = isVector; emit isVectorChanged(isVector); } + + +QList CPCompute::resetCommands() +{ + return { QString("uncompute %1").arg(identifier()), QString("compute %1 %2").arg(identifier()).arg(command()) }; +} diff --git a/atomify-lammps/cpcompute.h b/atomify-lammps/cpcompute.h index d9c6e014..ed679aab 100644 --- a/atomify-lammps/cpcompute.h +++ b/atomify-lammps/cpcompute.h @@ -20,10 +20,13 @@ class CPCompute : public SimulatorControl void setValues(double time, QVector values); virtual void updateCommand() override; - QString enabledCommand() override; - QString disableCommand() override; + QList enabledCommands() override; + QList disableCommands() override; + virtual QList resetCommands() override; + public: - CPCompute(); + explicit CPCompute(QObject *parent = 0); + ~CPCompute() { } void update(LAMMPSController *lammpsController) override; bool existsInLammps(LAMMPSController *lammpsController) override; QList values() const; diff --git a/atomify-lammps/cpfix.cpp b/atomify-lammps/cpfix.cpp index af8e0194..c57cbcb3 100644 --- a/atomify-lammps/cpfix.cpp +++ b/atomify-lammps/cpfix.cpp @@ -1,7 +1,7 @@ #include "cpfix.h" #include "lammpscontroller.h" -CPFix::CPFix() +CPFix::CPFix(QObject *parent) : SimulatorControl(parent) { } @@ -12,20 +12,19 @@ void CPFix::update(LAMMPSController *lammpsController) } - -QString CPFix::enabledCommand() +QList CPFix::enabledCommands() { - return QString("fix %1 %2").arg(identifier()).arg(command()); + return {QString("fix %1 %2").arg(identifier()).arg(command())}; } -QString CPFix::disableCommand() +QList CPFix::disableCommands() { - return QString("unfix %1 ").arg(identifier()); + return {QString("unfix %1 ").arg(identifier())}; } - void CPFix::updateCommand() { + } bool CPFix::existsInLammps(LAMMPSController *lammpsController) @@ -33,3 +32,9 @@ bool CPFix::existsInLammps(LAMMPSController *lammpsController) LAMMPS_NS::Fix *fix = lammpsController->findFixByIdentifier(identifier()); return fix!=nullptr; } + + +QList CPFix::resetCommands() +{ + return { QString("unfix %1").arg(identifier()), QString("fix %1 %2").arg(identifier()).arg(command()) }; +} diff --git a/atomify-lammps/cpfix.h b/atomify-lammps/cpfix.h index e1488ccb..61a71099 100644 --- a/atomify-lammps/cpfix.h +++ b/atomify-lammps/cpfix.h @@ -7,11 +7,14 @@ class CPFix : public SimulatorControl { Q_OBJECT protected: - QString enabledCommand() override; - QString disableCommand() override; + QList enabledCommands() override; + QList disableCommands() override; + virtual void updateCommand() override; + virtual QList resetCommands() override; public: - CPFix(); + explicit CPFix(QObject *parent = 0); + ~CPFix() { } void update(LAMMPSController *lammpsController) override; virtual bool existsInLammps(LAMMPSController *lammpsController); @@ -19,9 +22,6 @@ class CPFix : public SimulatorControl public slots: - // SimulatorControl interface -protected: - virtual void updateCommand(); }; #endif // CPFIX_H diff --git a/atomify-lammps/lammpscontroller.cpp b/atomify-lammps/lammpscontroller.cpp index 803bc949..4865b4cf 100644 --- a/atomify-lammps/lammpscontroller.cpp +++ b/atomify-lammps/lammpscontroller.cpp @@ -92,7 +92,10 @@ void LAMMPSController::executeCommandInLAMMPS(QString command) { return; } -// qDebug() << command; + if(!command.startsWith("run")) { + qDebug() << command; + } + try { lammps_command((void*)m_lammps, (char*) command.toStdString().c_str()); } catch (LammpsException &exception) { @@ -194,7 +197,6 @@ bool LAMMPSController::computeExists(QString identifier) { void LAMMPSController::processSimulatorControls() { for(SimulatorControl *control : simulatorControls) { - qDebug() << "Checking control: " << control->identifier(); control->update(this); } } @@ -303,35 +305,28 @@ int LAMMPSController::numberOfAtomTypes() const void LAMMPSController::disableAllEnsembleFixes() { + if(!m_scriptHandler) { + qDebug() << "Error, LAMMPSController doesn't have script handler. Aborting!"; + exit(1); + } state.preRunNeeded = true; - while(true) { - bool didFindFix = false; - for(int i=0; imodify->nfix; i++) { - LAMMPS_NS::Fix *fix = m_lammps->modify->fix[i]; - - LAMMPS_NS::FixNVT *nvt = dynamic_cast(fix); - if(nvt) { - executeCommandInLAMMPS(QString("unfix %1").arg(nvt->id)); - didFindFix = true; - break; - } + for(int i=0; imodify->nfix; i++) { + LAMMPS_NS::Fix *fix = m_lammps->modify->fix[i]; - LAMMPS_NS::FixNVE *nve = dynamic_cast(fix); - if(nve) { - executeCommandInLAMMPS(QString("unfix %1").arg(nve->id)); - didFindFix = true; - break; - } + LAMMPS_NS::FixNVT *nvt = dynamic_cast(fix); + if(nvt) { + m_scriptHandler->addCommandToTop(ScriptCommand(QString("unfix %1").arg(nvt->id), ScriptCommand::Type::SingleCommand)); + } - LAMMPS_NS::FixNPT *npt = dynamic_cast(fix); - if(npt) { - executeCommandInLAMMPS(QString("unfix %1").arg(npt->id)); - didFindFix = true; - break; - } + LAMMPS_NS::FixNVE *nve = dynamic_cast(fix); + if(nve) { + m_scriptHandler->addCommandToTop(ScriptCommand(QString("unfix %1").arg(nve->id), ScriptCommand::Type::SingleCommand)); } - if(!didFindFix) return; + LAMMPS_NS::FixNPT *npt = dynamic_cast(fix); + if(npt) { + m_scriptHandler->addCommandToTop(ScriptCommand(QString("unfix %1").arg(npt->id), ScriptCommand::Type::SingleCommand)); + } } } diff --git a/atomify-lammps/main.cpp b/atomify-lammps/main.cpp index 0339dbfb..5f300255 100644 --- a/atomify-lammps/main.cpp +++ b/atomify-lammps/main.cpp @@ -22,13 +22,15 @@ int main(int argc, char *argv[]) { qmlRegisterType("Atomify", 1, 0, "AtomifySimulator"); qmlRegisterType("Atomify", 1, 0, "Highlighter"); - qmlRegisterType("Atomify", 1, 0, "Compute"); qmlRegisterType("Atomify", 1, 0, "AtomStyle"); - // qmlRegisterType("Atomify", 1, 0, "NVT"); qmlRegisterType("Atomify", 1, 0, "ScriptHandler"); qmlRegisterType
("QMLPlot", 1, 0, "Figure"); qmlRegisterType("QMLPlot", 1, 0, "LineGraph"); qmlRegisterType("QMLPlot", 1, 0, "LineGraphDataSource"); + qmlRegisterType("Atomify", 1, 0, "Compute"); + qmlRegisterType("Atomify", 1, 0, "Fix"); + qmlRegisterType("Atomify", 1, 0, "NVT"); + QApplication app(argc, argv); QQmlApplicationEngine engine; diff --git a/atomify-lammps/mysimulator.cpp b/atomify-lammps/mysimulator.cpp index 41fb6ec2..47bb61d0 100644 --- a/atomify-lammps/mysimulator.cpp +++ b/atomify-lammps/mysimulator.cpp @@ -99,8 +99,8 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) ScriptCommand nextCommandObject = scriptHandler->nextCommand(); QString nextCommand = nextCommandObject.command(); - if(scriptParser.isEditorCommand(nextCommand)) { - scriptHandler->parseEditorCommand(nextCommand, mySimulator); + if(scriptParser.isEditorCommand(nextCommand) && scriptParser.isGUICommand(nextCommand)) { + scriptHandler->parseGUICommand(nextCommand); m_lammpsController.state.nextCommand = ScriptCommand("", ScriptCommand::Type::SkipLammpsTick); } else { m_lammpsController.state.nextCommand = nextCommandObject; diff --git a/atomify-lammps/nvt.cpp b/atomify-lammps/nvt.cpp index cdc41372..3c90d32a 100644 --- a/atomify-lammps/nvt.cpp +++ b/atomify-lammps/nvt.cpp @@ -1,96 +1,55 @@ -//#include "nvt.h" -//#include "lammpscontroller.h" -//#include -//#include +#include "nvt.h" +#include "lammpscontroller.h" +#include + +NVT::NVT(QObject *parent) : CPFix(parent) +{ + setIdentifier(QString("cp_nvt")); + updateCommand(); +} + +double NVT::targetTemperature() const +{ + return m_targetTemperature; +} + +void NVT::setTargetTemperature(double targetTemperature) +{ + if (m_targetTemperature == targetTemperature) + return; + + m_targetTemperature = targetTemperature; + emit targetTemperatureChanged(targetTemperature); +} + +void NVT::setTemperatureDampening(double temperatureDampening) +{ + if (m_temperatureDampening == temperatureDampening) + return; + + m_temperatureDampening = temperatureDampening; + emit temperatureDampeningChanged(temperatureDampening); +} + +double NVT::temperatureDampening() const +{ + return m_temperatureDampening; +} + +void NVT::updateCommand() +{ + QString newCommand = QString("all nvt temp %1 %1 %2").arg(m_targetTemperature).arg(m_temperatureDampening); + setCommand(newCommand); +} + +QList NVT::enabledCommands() +{ + QString enableCommand = QString("fix %1 %2").arg(identifier()).arg(command()); + return {QString("#/disableAllEnsembleFixes"), enableCommand}; +} + +QList NVT::disableCommands() +{ + return {QString("unfix %1").arg(identifier()), QString("fix cp_nve all nve")}; +} -//class FixNHHack : public FixNH { -//public: -// double target() { return t_target; } -// void setTargets(double targetValue) { -// t_target = targetValue; -// t_start = targetValue; -// t_stop = targetValue; -// } -//}; - -//NVT::NVT(QObject *parent) : SimulatorControl(parent) -//{ - -//} - -//double NVT::targetTemperature() const -//{ -// return m_targetTemperature; -//} - -//void NVT::setTargetTemperature(double targetTemperature) -//{ -// if (m_targetTemperature == targetTemperature) -// return; - -// m_targetTemperature = targetTemperature; -// setDirty(true); -// emit targetTemperatureChanged(targetTemperature); -//} - -//void NVT::setTemperatureDampening(double temperatureDampening) -//{ -// if (m_temperatureDampening == temperatureDampening) -// return; - -// m_temperatureDampening = temperatureDampening; -// emit temperatureDampeningChanged(temperatureDampening); -//} - -//void NVT::update(LAMMPSController *lammpsController) -//{ -// if(lammpsController->scriptHandler() == nullptr) { -// return; -// } -// FixNVT *fix = lammpsController->findFixByType(); -// if(fix) { -// FixNH *fixNH = dynamic_cast(fix); -// FixNHHack *fixHack = reinterpret_cast(fixNH); -// if(fixHack) { -// if(m_dirty) { -// m_dirty = false; -// if(!m_enabled) { -// QList disableCommands; -// disableCommands.push_back(QString("unfix %1").arg(fix->id)); -// disableCommands.push_back("fix nve all nve"); -// lammpsController->scriptHandler()->addCommandsToTop(disableCommands, ScriptCommand::Type::SingleCommand); -// return; -// } - -// if(m_targetTemperature != fixHack->target()) { -// fixHack->setTargets(m_targetTemperature); -// } -// } else { -// if(m_targetTemperature != fixHack->target()) { -// m_targetTemperature = fixHack->target(); -// emit targetTemperatureChanged(m_targetTemperature); -// } -// if(!m_enabled) { -// m_enabled = true; -// emit enabledChanged(m_enabled); -// } -// } -// } -// } else { -// if(m_dirty && m_enabled) { -// lammpsController->disableAllEnsembleFixes(); -// QString command = QString("fix nvt all nvt temp %1 %1 %2").arg(m_targetTemperature).arg(m_temperatureDampening); -// lammpsController->scriptHandler()->addCommandToTop(ScriptCommand(command, ScriptCommand::Type::SingleCommand)); -// } else if(m_enabled) { -// m_enabled = false; -// emit enabledChanged(m_enabled); -// } -// } - -// m_dirty = false; -//} - -//double NVT::temperatureDampening() const -//{ -// return m_temperatureDampening; -//} diff --git a/atomify-lammps/nvt.h b/atomify-lammps/nvt.h index 7dbd8205..e71f16cf 100644 --- a/atomify-lammps/nvt.h +++ b/atomify-lammps/nvt.h @@ -1,33 +1,37 @@ -//#ifndef NVT_H -//#define NVT_H +#ifndef NVT_H +#define NVT_H -//#include "simulatorcontrol.h" -//#include "mysimulator.h" +#include "cpfix.h" +#include "mysimulator.h" -//class NVT : public SimulatorControl -//{ -// Q_OBJECT -// Q_PROPERTY(double targetTemperature READ targetTemperature WRITE setTargetTemperature NOTIFY targetTemperatureChanged) -// Q_PROPERTY(double temperatureDampening READ temperatureDampening WRITE setTemperatureDampening NOTIFY temperatureDampeningChanged) -//private: -// double m_targetTemperature = 1; -// double m_temperatureDampening = 1.0; +class NVT : public CPFix +{ + Q_OBJECT + Q_PROPERTY(double targetTemperature READ targetTemperature WRITE setTargetTemperature NOTIFY targetTemperatureChanged) + Q_PROPERTY(double temperatureDampening READ temperatureDampening WRITE setTemperatureDampening NOTIFY temperatureDampeningChanged) +private: + double m_targetTemperature = 1.0; + double m_temperatureDampening = 1.0; -//public: -// explicit NVT(QObject *parent = 0); -// double targetTemperature() const; +public: + explicit NVT(QObject *parent = 0); + ~NVT() { } + double targetTemperature() const; + double temperatureDampening() const; -//signals: -// void targetTemperatureChanged(double targetTemperature); -// void temperatureDampeningChanged(double temperatureDampening); +signals: + void targetTemperatureChanged(double targetTemperature); + void temperatureDampeningChanged(double temperatureDampening); -//public slots: -//void setTargetTemperature(double targetTemperature); -//void setTemperatureDampening(double temperatureDampening); +public slots: + void setTargetTemperature(double targetTemperature); + void setTemperatureDampening(double temperatureDampening); -//public: -//virtual void update(LAMMPSController *lammpsController); -//double temperatureDampening() const; -//}; + // SimulatorControl interface +protected: + virtual void updateCommand() override; + virtual QList enabledCommands(); + virtual QList disableCommands(); +}; -//#endif // NVT_H +#endif // NVT_H diff --git a/atomify-lammps/qml/main.qml b/atomify-lammps/qml/main.qml index 335d97fc..a1152788 100644 --- a/atomify-lammps/qml/main.qml +++ b/atomify-lammps/qml/main.qml @@ -58,13 +58,13 @@ ApplicationWindow { id: myAtomStyle } -// NVT { -// id: nvt -// temperatureDampening: 0.01 -// onEnabledChanged: { -// nvtCheck.checked = enabled -// } -// } + NVT { + id: nvt + temperatureDampening: 0.01 + onEnabledChanged: { + nvtCheck.checked = enabled + } + } scriptHandler: ScriptHandler { atomStyle: myAtomStyle } @@ -75,11 +75,11 @@ ApplicationWindow { identifier: "temperature" command: "all temp" onValueChanged: { -// tempGraph.addPoint(mySimulator.simulationTime, value) -// tempPlot.xMax = mySimulator.simulationTime -// tempPlot.xMin = mySimulator.simulationTime-1 -// maxValue = Math.max(maxValue, value) -// tempPlot.yMax = maxValue + tempGraph.addPoint(mySimulator.simulationTime, value) + tempPlot.xMax = mySimulator.simulationTime + tempPlot.xMin = mySimulator.simulationTime-1 + maxValue = Math.max(maxValue, value) + tempPlot.yMax = maxValue } } @@ -90,11 +90,11 @@ ApplicationWindow { command: "all pressure temperature" dependencies: [computeTemp] onValueChanged: { - tempGraph.addPoint(mySimulator.simulationTime, value) - tempPlot.xMax = mySimulator.simulationTime - tempPlot.xMin = mySimulator.simulationTime-1 - maxValue = Math.max(maxValue, value) - tempPlot.yMax = maxValue +// tempGraph.addPoint(mySimulator.simulationTime, value) +// tempPlot.xMax = mySimulator.simulationTime +// tempPlot.xMin = mySimulator.simulationTime-1 +// maxValue = Math.max(maxValue, value) +// tempPlot.yMax = maxValue } } } @@ -154,15 +154,15 @@ ApplicationWindow { } } -// Slider { -// id: nvtSlider -// minimumValue: 0.1 -// maximumValue: 6 -// value: nvt.targetTemperature -// onValueChanged: { -// nvt.targetTemperature = value -// } -// } + Slider { + id: nvtSlider + minimumValue: 0.1 + maximumValue: 6 + value: nvt.targetTemperature + onValueChanged: { + nvt.targetTemperature = value + } + } } } diff --git a/atomify-lammps/scriptcommand.h b/atomify-lammps/scriptcommand.h index d128c7c3..dbca4820 100644 --- a/atomify-lammps/scriptcommand.h +++ b/atomify-lammps/scriptcommand.h @@ -7,7 +7,7 @@ class ScriptCommand { public: enum class Type {NoCommand, File, Editor, SingleCommand, SkipLammpsTick}; - ScriptCommand(QString command = "", Type type = Type::NoCommand, int line = -1, QString filename = ""); + explicit ScriptCommand(QString command = "", Type type = Type::NoCommand, int line = -1, QString filename = ""); const QString& command() const; Type type() const; diff --git a/atomify-lammps/scripthandler.cpp b/atomify-lammps/scripthandler.cpp index 5253dc21..79f8ce04 100644 --- a/atomify-lammps/scripthandler.cpp +++ b/atomify-lammps/scripthandler.cpp @@ -88,8 +88,25 @@ void ScriptHandler::runFile(QString filename) runScript(script, ScriptCommand::Type::File, filename); } -void ScriptHandler::parseEditorCommand(QString command, AtomifySimulator *mySimulator) { +bool ScriptHandler::parseLammpsCommand(QString command, LAMMPSController *lammpsController) { + if(m_parser.isEditorCommand(command)) { + command = command.trimmed(); + command.remove(0,2); + + if(m_parser.isDisableAllEnsembleFixes(command)) { + lammpsController->disableAllEnsembleFixes(); + return true; + } + } + + return false; +} + +void ScriptHandler::parseGUICommand(QString command) +{ + command = command.trimmed(); command.remove(0,2); + if(m_parser.isAtomType(command)) { m_parser.atomType(command, [&](QString atomTypeName, int atomType) { if(m_atomStyle) m_atomStyle->setAtomType(atomTypeName, atomType); @@ -105,15 +122,6 @@ void ScriptHandler::parseEditorCommand(QString command, AtomifySimulator *mySimu } } -bool ScriptHandler::parseLammpsCommand(QString command, LAMMPSController *lammpsController) { - if(command.trimmed().compare("disableAllEnsembleFixes") == 0) { - lammpsController->disableAllEnsembleFixes(); - return true; - } - - return false; -} - void ScriptHandler::doRunScript(QString script, ScriptCommand::Type type, QString filename) { if(!script.isEmpty()) { @@ -124,7 +132,6 @@ void ScriptHandler::doRunScript(QString script, ScriptCommand::Type type, QStrin QStringList lines = script.split("\n"); for(QString line : lines) { - qDebug() << "Executing " << line; line = line.trimmed(); if(line.endsWith("&")) { line.remove(line.length() - 1, 1); @@ -137,7 +144,6 @@ void ScriptHandler::doRunScript(QString script, ScriptCommand::Type type, QStrin currentCommand = currentCommand.trimmed(); if(m_parser.isInclude(currentCommand)) { - qDebug() << "Is include"; QString filename = m_parser.includePath(currentCommand); loadScriptFromFile(filename); currentCommand.clear(); lineNumber++; continue; // This line is complete @@ -168,8 +174,8 @@ void ScriptHandler::runScript(QString script, ScriptCommand::Type type, QString void ScriptHandler::runCommand(QString command, bool addToPreviousCommands) { QMutexLocker locker(&m_mutex); - if(addToPreviousCommands) m_previousSingleCommands.push_back(command); auto commandObject = ScriptCommand(command, ScriptCommand::Type::SingleCommand); + if(addToPreviousCommands) m_previousSingleCommands.push_back(commandObject); m_queuedCommands.enqueue(commandObject); } diff --git a/atomify-lammps/scripthandler.h b/atomify-lammps/scripthandler.h index c9b2ded9..aaac740f 100644 --- a/atomify-lammps/scripthandler.h +++ b/atomify-lammps/scripthandler.h @@ -37,8 +37,8 @@ class ScriptHandler : public QObject void loadScriptFromFile(QString filename); AtomStyle* atomStyle() const; ScriptParser &parser() { return m_parser; } - void parseEditorCommand(QString command, AtomifySimulator *mySimulator); bool parseLammpsCommand(QString command, LAMMPSController *lammpsController); + void parseGUICommand(QString command); public slots: void runScript(QString script, ScriptCommand::Type type = ScriptCommand::Type::Editor, QString filename = ""); diff --git a/atomify-lammps/scriptparser.cpp b/atomify-lammps/scriptparser.cpp index 30b09913..5f53ed4a 100644 --- a/atomify-lammps/scriptparser.cpp +++ b/atomify-lammps/scriptparser.cpp @@ -51,8 +51,17 @@ void ScriptParser::atomType(QString command, std::function(variant); if(dependency && !dependency->existsInLammps(lammpsController)) { @@ -18,9 +22,8 @@ bool SimulatorControl::addToLammps(LAMMPSController *lammpsController) { } } - qDebug() << "All dependencies are met"; ScriptHandler *scriptHandler = lammpsController->scriptHandler(); - scriptHandler->addCommandToTop(ScriptCommand(enabledCommand(), ScriptCommand::Type::SingleCommand)); + scriptHandler->addCommandsToTop(enabledCommands(), ScriptCommand::Type::SingleCommand); return true; } @@ -42,14 +45,11 @@ bool SimulatorControl::dependenciesValid(LAMMPSController *lammpsController) void SimulatorControl::update(LAMMPSController *lammpsController) { - qDebug() << "Updating control with identifier " << identifier(); if(!lammpsController->scriptHandler()) { return; } bool exists = existsInLammps(lammpsController); - qDebug() << identifier() << " exists: " << exists; - qDebug() << "Enabled: " << m_enabled; if(!exists && m_enabled) { // We should exist, so let's try to add. // Whatever happens, just return. We aren't ready to compute any values yet anyway. @@ -59,15 +59,15 @@ void SimulatorControl::update(LAMMPSController *lammpsController) if(exists && !m_enabled || !dependenciesValid(lammpsController)) { // We should not exist, but we do. Now remove from lammps - lammpsController->scriptHandler()->addCommandToTop(disableCommand()); + lammpsController->scriptHandler()->addCommandsToTop(disableCommands(), ScriptCommand::Type::SingleCommand); } if(exists) { QString currentCommand = command(); updateCommand(); if(currentCommand!=command()) { - QList reAddCommands = { disableCommand(), enabledCommand() }; - lammpsController->scriptHandler()->addCommandsToTop(reAddCommands, ScriptCommand::Type::SingleCommand); + + lammpsController->scriptHandler()->addCommandsToTop(resetCommands(), ScriptCommand::Type::SingleCommand); } } } diff --git a/atomify-lammps/simulatorcontrol.h b/atomify-lammps/simulatorcontrol.h index 37535d1b..5ab86b23 100644 --- a/atomify-lammps/simulatorcontrol.h +++ b/atomify-lammps/simulatorcontrol.h @@ -21,11 +21,13 @@ class SimulatorControl : public QObject bool m_enabled = true; bool addToLammps(LAMMPSController *lammpsController); virtual void updateCommand() = 0; - virtual QString enabledCommand() = 0; - virtual QString disableCommand() = 0; + virtual QList enabledCommands() = 0; + virtual QList disableCommands() = 0; + virtual QList resetCommands() = 0; public: explicit SimulatorControl(QObject *parent = 0); + ~SimulatorControl(); bool enabled() const; QString identifier() const; QString command() const; From 983374449e7e9c271b662b455e9efd23354c22bd Mon Sep 17 00:00:00 2001 From: Anders Hafreager Date: Wed, 28 Oct 2015 21:29:55 +0100 Subject: [PATCH 5/5] Added handleCommand in SimulatorControl. --- atomify-lammps/mysimulator.cpp | 10 +++------- atomify-lammps/nvt.cpp | 5 +++-- atomify-lammps/simulations/other/water/water.in | 4 ++-- atomify-lammps/simulatorcontrol.h | 1 + 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/atomify-lammps/mysimulator.cpp b/atomify-lammps/mysimulator.cpp index 47bb61d0..67684c64 100644 --- a/atomify-lammps/mysimulator.cpp +++ b/atomify-lammps/mysimulator.cpp @@ -58,7 +58,6 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) m_lammpsController.setComputes(mySimulator->computes()); m_lammpsController.setPaused(mySimulator->paused()); m_lammpsController.setSimulationSpeed(mySimulator->simulationSpeed()); - // QVector simulatorControls; m_lammpsController.simulatorControls = mySimulator->findChildren(); // Sync properties from lammps controller @@ -69,9 +68,6 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) mySimulator->setSystemSize(m_lammpsController.systemSize()); mySimulator->setTimePerTimestep(m_lammpsController.timePerTimestep()); -// for(CPCompute *compute : mySimulator->computes()) { -// compute->update(&m_lammpsController); -// } m_lammpsController.setScriptHandler(mySimulator->scriptHandler()); @@ -81,9 +77,6 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) mySimulator->setLammpsErrorMessage(QString(m_lammpsController.currentException().error().c_str()).trimmed()); m_lammpsController.currentException().setIsReported(true); -// console.log(" Simulation crashed. Error in parsing LAMMPS command: '"+mySimulator.scriptHandler.currentCommand+"'") -// console.log(" LAMMPS error message: '"+mySimulator.lammpsErrorMessage+"'") - emit mySimulator->errorInLammpsScript(); return; } @@ -103,6 +96,9 @@ void MyWorker::synchronizeSimulator(Simulator *simulator) scriptHandler->parseGUICommand(nextCommand); m_lammpsController.state.nextCommand = ScriptCommand("", ScriptCommand::Type::SkipLammpsTick); } else { + for(auto *simulatorControl : mySimulator->findChildren()) { + simulatorControl->handleCommand(nextCommandObject.command()); + } m_lammpsController.state.nextCommand = nextCommandObject; } } diff --git a/atomify-lammps/nvt.cpp b/atomify-lammps/nvt.cpp index 3c90d32a..55ef659e 100644 --- a/atomify-lammps/nvt.cpp +++ b/atomify-lammps/nvt.cpp @@ -1,6 +1,8 @@ #include "nvt.h" #include "lammpscontroller.h" #include +#include +#include NVT::NVT(QObject *parent) : CPFix(parent) { @@ -50,6 +52,5 @@ QList NVT::enabledCommands() QList NVT::disableCommands() { - return {QString("unfix %1").arg(identifier()), QString("fix cp_nve all nve")}; + return { QString("unfix %1").arg(identifier()), QString("fix cp_nve all nve") }; } - diff --git a/atomify-lammps/simulations/other/water/water.in b/atomify-lammps/simulations/other/water/water.in index da70f387..1f4c4280 100644 --- a/atomify-lammps/simulations/other/water/water.in +++ b/atomify-lammps/simulations/other/water/water.in @@ -29,5 +29,5 @@ thermo 100 fix nvt all nvt temp 1500 1500 0.1 atom_modify sort 100 3 -#!atom 2 oxygen -#!atom 3 hydrogen \ No newline at end of file +#/atom 2 oxygen +#/atom 3 hydrogen diff --git a/atomify-lammps/simulatorcontrol.h b/atomify-lammps/simulatorcontrol.h index 5ab86b23..f6be1912 100644 --- a/atomify-lammps/simulatorcontrol.h +++ b/atomify-lammps/simulatorcontrol.h @@ -35,6 +35,7 @@ class SimulatorControl : public QObject bool dependenciesValid(LAMMPSController *lammpsController); virtual bool existsInLammps(LAMMPSController *lammpsController) = 0; virtual void update(LAMMPSController *lammpsController); + virtual void handleCommand(QString command) { /* TODO */ } signals: void enabledChanged(bool enabled);