bool ModPlusDymolaCtrl::simulate(QDir tempDir,MOVector<Variable> * updatedVars,MOVector<Variable> * outputVars,QFileInfoList filesTocopy,QFileInfoList moDependencies) { // Info InfoSender::sendCurrentTask("Dymola : Simulating model "+_modModelPlus->modModelName()); // clear outputVars outputVars->clear(); bool compileOk = isCompiled(); // eventually compile model if(!compileOk) compileOk = compile(moDependencies); if(!compileOk) return false; // compilation failed, useless to pursue // Create tempDir LowTools::mkdir(tempDir.absolutePath(),true); /// copy files in temp dir (\todo : optimize with a config.updateTempDir in case of several consecutive launches) QFileInfoList allFilesToCopy; QDir mmoDir = QDir(_modModelPlus->mmoFolder()); allFilesToCopy << mmoDir.filePath("dsin.txt") << mmoDir.filePath("dymosim.exe"); allFilesToCopy.append(filesTocopy); QFileInfo fileToCopyInfo; QFile fileToCopy; for(int i=0; i< allFilesToCopy.size();i++) { fileToCopy.setFileName(allFilesToCopy.at(i).absoluteFilePath()); fileToCopyInfo.setFile(fileToCopy); tempDir.remove(fileToCopyInfo.fileName()); fileToCopy.copy(tempDir.filePath(fileToCopyInfo.fileName())); } // remove previous dymola log files QStringList filesToRemove; filesToRemove << "status" << "failure" << "success" << "dslog.txt"; for(int i=0;i<filesToRemove.size();i++) tempDir.remove(filesToRemove.at(i)); QString tempDsin = tempDir.absoluteFilePath("dsin.txt"); QString tempDsres = tempDir.absoluteFilePath("dsres.txt"); // Specifying new Variables values in dymosim input file Dymola::setVariablesToDsin(tempDsin,_modModelPlus->modModelName(),updatedVars,_parameters); // Launching Dymosim int maxNSec=-1; int iParam = _parameters->findItem(DymolaParameters::str(DymolaParameters::MAXSIMTIME)); if(iParam>-1) maxNSec=_parameters->at(iParam)->getFieldValue(MOParameter::VALUE).toInt(); Dymola::start(tempDir,_simProcess,maxNSec); QString logFile = tempDir.absoluteFilePath("dslog.txt"); //getting results //Checking if successed bool success=QFile::exists(tempDir.absoluteFilePath("success")); if(!success) { InfoSender::instance()->send(Info(ListInfo::ONESIMULATIONFAILED,logFile)); return false; } else { InfoSender::instance()->send(Info(ListInfo::ONESIMULATIONSUCCESS,logFile)); } bool readOk = readOutputVariables(outputVars,tempDir.absolutePath()); InfoSender::eraseCurrentTask(); return readOk; }
bool ModPlusOMCtrl::simulate(QDir tempFolder,MOVector<Variable> * inputVars,MOVector<Variable> * outputVars,QFileInfoList filesToCopy,QFileInfoList moDependencies) { // Info InfoSender::sendCurrentTask("Open Modelica : Simulating model "+_ModelPlus->modelName()); // clear outputVars outputVars->clear(); bool compileOk = isCompiled(); // eventually compile model if(!compileOk) compileOk = compile(_modModelPlus->moDependencies(),filesToCopy); if(!compileOk) return false; // compilation failed, useless to pursue // Create tempDir LowTools::mkpath(tempFolder.absolutePath(),false); /// copy files in temp dir (\todo : optimize with a config.updateTempDir in case of several consecutive launches) QFileInfoList allFilesToCopy; QDir mmoDir = QDir(_ModelPlus->mmoFolder()); allFilesToCopy << mmoDir.filePath(_exeFile); allFilesToCopy.append(filesToCopy); bool xml=mmoDir.exists(_initFileXml); allFilesToCopy << mmoDir.filePath(_initFileXml); InfoSender::instance()->debug("Start copying in temp directory : "+tempFolder.absolutePath()); //QFile fileToCopy; bool copyOk = LowTools::copyFilesInFolder(allFilesToCopy,tempFolder); if(!copyOk) return false; // remove previous log / result files QStringList filesToRemove; filesToRemove << resFile(); for(int i=0;i<filesToRemove.size();i++) tempFolder.remove(filesToRemove.at(i)); QString tempInitFileXml = tempFolder.absoluteFilePath(_initFileXml); QString tempResFile = tempFolder.absoluteFilePath(resFile()); QString tempExeFile = tempFolder.absoluteFilePath(_exeFile); // Specifying new Variables values in OM input file bool setInputFileOk = OpenModelica::setInputXml(tempInitFileXml,inputVars,_ModelPlus->modelName(),parameters()); if(!setInputFileOk) { InfoSender::instance()->sendWarning("Simulation failed : failed to set input file"); return false; } // Launching openmodelica int maxNSec=_parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::MAXSIMTIME),-1).toInt(); QString startErrMsg; bool startOk = OpenModelica::start(tempExeFile,startErrMsg,maxNSec); if(!startOk) { InfoSender::instance()->sendWarning("Simulation failed : "+startErrMsg); return false; } InfoSender::eraseCurrentTask(); //getting results //Checking if successed bool success=QFile::exists(tempResFile); if(!success) return false; bool readOk = readOutputVariables(outputVars,tempResFile); return readOk; }