Esempio n. 1
0
Result* OneSimulation::launch(ProblemConfig config)
{
    // Creating a variables instance containing updated variables
    Variables updatedVariables(*_overwritedVariables);

    OneSimResult* result = new OneSimResult(_omProject,_ModelPlus,*this);
    result->setName(this->name()+" result");

    // check if has modependencies (only for modmodelplus)
    QFileInfoList moDeps;
    ModModelPlus* modModelPlus = dynamic_cast<ModModelPlus*>(_ModelPlus);
    if(modModelPlus)
        moDeps.append(modModelPlus->moDependencies());

    // loop indexes on scannVariables
    QList<int> indexes,maxIndexes;
    Variable* clonedVar;
    ScannedVariable *scannedVar;
    for(int iScanV=0; iScanV < _scannedVariables->size(); iScanV++)
    {
        indexes.push_back(0);
        scannedVar = _scannedVariables->at(iScanV);
        maxIndexes.push_back(scannedVar->nbScans()-1);
        clonedVar = new Variable(*(dynamic_cast<Variable*>(scannedVar)));
        updatedVariables.addItem(clonedVar);
    }

    MOVector<Variable> curVariables(true);
    bool allSimSuccess=true;
    bool curSimSuccess;
    int iScan=0;
    do
    {
        // Update values
        VariablesManip::updateScanValues(&updatedVariables,_scannedVariables,indexes);

        // Simulate
        curVariables.clear();
        curSimSuccess = ctrl()->simulate(_project->tempPath(), &updatedVariables, &curVariables,
                                         QFileInfoList() << _ModelPlus->neededFiles() << _filesToCopy,moDeps);
        allSimSuccess = allSimSuccess && curSimSuccess;

        if(allSimSuccess)
        {
            // Add values
            double curValue;
            //if it is first scan, finalvariables is an empy vector -> fill with curVariables
            if(result->finalVariables()->isEmpty())
            {
                for(int i=0;i<curVariables.size();i++)
                {
                    result->finalVariables()->addItem(new VariableResult(*curVariables.at(i)));
                    curValue = curVariables.at(i)->getFieldValue(Variable::VALUE).toDouble();
                    result->finalVariables()->at(i)->setFinalValue(iScan,0,curValue,true);
                }
            }
            else
            {
                // append scan values
                Variable *curVar;
                for(int i=0;i<result->finalVariables()->size();i++)
                {
                    curVar = curVariables.findItem(result->finalVariables()->at(i)->name());
                    if(curVar)
                    {
                        curValue = curVar->doubleValue();
                        result->finalVariables()->at(i)->setFinalValue(iScan,0,curValue,true);
                    }
                    else
                        result->finalVariables()->at(i)->setFinalValue(iScan,0,-1,false);
                }
            }
        }


        indexes = LowTools::nextIndex(indexes,maxIndexes);
        iScan++;
    }
    while(!indexes.isEmpty() && allSimSuccess);

    curVariables.clear();

    //qDebug(result->finalVariables()->toCSV().toLatin1().data());

    result->setSuccess(allSimSuccess);

    return result;
}