Ejemplo n.º 1
0
void OpenModelica::setInputParametersXml(QDomDocument &doc,MOParameters *parameters)
{
    QDomElement xfmi = doc.firstChildElement("fmiModelDescription");
    QDomElement oldxfmi = xfmi;

    QDomElement xExp = xfmi.firstChildElement("DefaultExperiment");
    QDomElement oldxExp = xExp;


    double starttime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STARTTIME),0).toDouble();
    double stoptime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STOPTIME),1).toDouble();
    int nbIntervals = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS),2).toInt();
    double stepSize = (stoptime-starttime)/nbIntervals;


    MOParameter * curParam;
    MOParameterListed* curParamListed;
    for(int i=0;i<parameters->size();i++)
    {
        curParam = parameters->at(i);

        if(!curParam->name().contains(" ")) // remove old parameters, temporary
        {
            if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::SOLVER))
            {
                curParamListed = dynamic_cast<MOParameterListed*>(curParam);
                xExp.setAttribute(curParamListed->name(),curParamListed->strValue());
            }
            else if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::OUTPUT))
            {
                curParamListed = dynamic_cast<MOParameterListed*>(curParam);
                xExp.setAttribute(curParamListed->name(),curParamListed->strValue());
            }
            else if (curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS))
            {
                xExp.setAttribute("stepSize",QString::number(stepSize));
            }
            else
            {
                xExp.setAttribute(curParam->name(),curParam->value().toString());
            }
        }
    }

    // update xfmi with new vars
    xfmi.replaceChild(xExp,oldxExp);
    doc.replaceChild(xfmi,oldxfmi);
}
Ejemplo n.º 2
0
void Dymola::writeParameters(QString &allDsinText,MOParameters *parameters)
{
    QString newLine;

    QStringList lines = allDsinText.split("\n");
    int iLForm = lines.indexOf(QRegExp(".* # lform .*"));
    if(iLForm>-1)
    {
        newLine =  " 0                         # lform    0/1 ASCII/Matlab-binary storage format of results";
        lines.replace(iLForm,newLine);
    }


    MOParameter* pStopTime = parameters->findItem(DymolaParameters::str(DymolaParameters::STOPTIME));
    int iLStopTime = lines.indexOf(QRegExp(".* # StopTime .*"));
    if((iLStopTime>-1) && pStopTime)
    {
        newLine =  "       "
                +pStopTime->getFieldValue(MOParameter::VALUE).toString()
                +"                   # StopTime     Time at which integration stops";
        lines.replace(iLStopTime,newLine);
    }

    MOParameter* pTolerance = parameters->findItem(DymolaParameters::str(DymolaParameters::TOLERANCE));
    int iLTolerance = lines.indexOf(QRegExp(".*  # Tolerance .*"));
    if((iLTolerance>-1) && pTolerance)
    {
        newLine =  "       "
                +pTolerance->getFieldValue(MOParameter::VALUE).toString()
                +"                   # nInterval    Relative precision of signals for \n                            #              simulation, linearization and trimming";
        lines.replace(iLTolerance,newLine);
    }

    MOParameter* pnInterval = parameters->findItem(DymolaParameters::str(DymolaParameters::NINTERVAL));
    int iLnInterval = lines.indexOf(QRegExp(".*  # nInterval .*"));
    if((iLnInterval>-1) && pnInterval)
    {
        newLine =  "       "
                +pnInterval->getFieldValue(MOParameter::VALUE).toString()
                +"                   # nInterval    Number of communication intervals, if > 0";
        lines.replace(iLnInterval,newLine);
    }

    MOParameter* pSolver = parameters->findItem(DymolaParameters::str(DymolaParameters::SOLVER));
    int iLSolver = lines.indexOf(QRegExp(".*  # Algorithm .*"));
    if((iLSolver>-1) && pSolver)
    {
        newLine =  "       "
                +pSolver->getFieldValue(MOParameter::VALUE).toString()
                +"                   # Algorithm    Integration algorithm as integer";
        lines.replace(iLSolver,newLine);
    }

    MOParameter* pFinalFile = parameters->findItem(DymolaParameters::str(DymolaParameters::FINALFILE));
    int iLineLRes = lines.indexOf(QRegExp(".*  # lres     0/1 do not/store results .*"));
    if((iLineLRes>-1) && pFinalFile)
    {
        int lRes;
        switch(pFinalFile->value().toInt())
        {
        case DymolaParameters::DSFINAL :
            lRes = 0;
            break;
        case DymolaParameters::DSRES :
        default :
            lRes = 1;
            break;
        }

        newLine =  "       "
                +QString::number(lRes)
                +"                   # lres     0/1 do not/store results on result file";
        lines.replace(iLineLRes,newLine);
    }


    allDsinText = lines.join("\n");
}