コード例 #1
0
ファイル: pythonlabagros.cpp プロジェクト: honzakac/agros2d
// newdocument(name, type, physicfield, numberofrefinements, polynomialorder, adaptivitytype, adaptivitysteps, adaptivitytolerance, frequency, analysistype, timestep, totaltime, initialcondition)
void pythonNewDocument(char *name, char *type, char *physicfield,
                       int numberofrefinements, int polynomialorder, char *adaptivitytype,
                       double adaptivitysteps, double adaptivitytolerance,
                       double frequency,
                       char *analysistype, double timestep, double totaltime, double initialcondition)
{
    logMessage("pythonNewDocument()");

    Util::scene()->clear();
    Util::scene()->problemInfo()->name = QString(name);

    // type
    Util::scene()->problemInfo()->problemType = problemTypeFromStringKey(QString(type));
    if (Util::scene()->problemInfo()->problemType == ProblemType_Undefined)
        throw invalid_argument(QObject::tr("Problem type '%1' is not implemented.").arg(QString(type)).toStdString());

    // physicfield
    PhysicField physicField = physicFieldFromStringKey(QString(physicfield));
    if (physicField != PhysicField_Undefined)
        Util::scene()->problemInfo()->setHermes(hermesFieldFactory(physicField));
    else
        throw invalid_argument(QObject::tr("Physic field '%1' is not implemented.").arg(QString(physicfield)).toStdString());

    // numberofrefinements
    if (numberofrefinements >= 0)
        Util::scene()->problemInfo()->numberOfRefinements = numberofrefinements;
    else
        throw out_of_range(QObject::tr("Number of refinements '%1' is out of range.").arg(numberofrefinements).toStdString());

    // polynomialorder
    if (polynomialorder >= 1 && polynomialorder <= 10)
        Util::scene()->problemInfo()->polynomialOrder = polynomialorder;
    else
        throw out_of_range(QObject::tr("Polynomial order '%1' is out of range.").arg(polynomialorder).toStdString());

    // adaptivitytype
    Util::scene()->problemInfo()->adaptivityType = adaptivityTypeFromStringKey(QString(adaptivitytype));
    if (Util::scene()->problemInfo()->adaptivityType == AdaptivityType_Undefined)
        throw invalid_argument(QObject::tr("Adaptivity type '%1' is not implemented.").arg(QString(adaptivitytype)).toStdString());

    // adaptivitysteps
    if (adaptivitysteps >= 0)
        Util::scene()->problemInfo()->adaptivitySteps = adaptivitysteps;
    else
        throw out_of_range(QObject::tr("Adaptivity step '%1' is out of range.").arg(adaptivitysteps).toStdString());

    // adaptivitytolerance
    if (adaptivitytolerance >= 0)
        Util::scene()->problemInfo()->adaptivityTolerance = adaptivitytolerance;
    else
        throw out_of_range(QObject::tr("Adaptivity tolerance '%1' is out of range.").arg(adaptivitytolerance).toStdString());

    // frequency
    if (Util::scene()->problemInfo()->hermes()->hasHarmonic())
    {
        if (frequency >= 0)
            Util::scene()->problemInfo()->frequency = frequency;
        else
            throw invalid_argument(QObject::tr("The frequency can not be used for this problem.").toStdString());
    }

    // analysis type
    Util::scene()->problemInfo()->analysisType = analysisTypeFromStringKey(QString(analysistype));
    if (Util::scene()->problemInfo()->analysisType == AnalysisType_Undefined)
        throw invalid_argument(QObject::tr("Analysis type '%1' is not implemented").arg(QString(adaptivitytype)).toStdString());

    // analysis type
    Util::scene()->problemInfo()->analysisType = analysisTypeFromStringKey(QString(analysistype));
    if (Util::scene()->problemInfo()->analysisType == AnalysisType_Undefined)
        throw invalid_argument(QObject::tr("Analysis type '%1' is not implemented").arg(QString(adaptivitytype)).toStdString());

    // transient timestep
    if (timestep > 0)
        Util::scene()->problemInfo()->timeStep = Value(QString::number(timestep));
    else if (Util::scene()->problemInfo()->analysisType == AnalysisType_Transient)
        throw out_of_range(QObject::tr("Time step must be positive.").toStdString());

    // transient timetotal
    if (totaltime > 0)
        Util::scene()->problemInfo()->timeTotal = Value(QString::number(totaltime));
    else if (Util::scene()->problemInfo()->analysisType == AnalysisType_Transient)
        throw out_of_range(QObject::tr("Total time must be positive.").toStdString());

    // transient initial condition
    Util::scene()->problemInfo()->initialCondition = Value(QString::number(initialcondition));

    // invalidate
    sceneView()->doDefaultValues();
    Util::scene()->refresh();
}
コード例 #2
0
ファイル: coupling.cpp プロジェクト: LukasKoudela/agros2d
CouplingList::CouplingList()
{
    // read couplings
    QDir dir(datadir() + COUPLINGROOT);

    QStringList filter;
    filter << "*.xml";
    QStringList list = dir.entryList(filter);

    foreach (QString filename, list)
    {
        try
        {
            // todo: this was copied from module. Find a way to do all catching at one place

            // todo: find a way to validate if required. If validated here, sensible error messages will be obtained
            bool validateAtTheBeginning = false;
            ::xml_schema::flags parsing_flags = xml_schema::flags::dont_validate;
            if(validateAtTheBeginning)
            {
                parsing_flags = 0;
                qDebug() << "Warning: Validating all XML files. This is time-consuming and should be switched off in coupling.cpp for release. Set validateAtTheBeginning = false.";
            }

            std::auto_ptr<XMLCoupling::coupling> coupling_xsd = XMLCoupling::coupling_(compatibleFilename(datadir() + COUPLINGROOT + "/" + filename).toStdString(),
                                                                                   xml_schema::flags::dont_validate & xml_schema::flags::dont_initialize);
            XMLCoupling::coupling *coup = coupling_xsd.get();

            // check whether coupling is available for values of source and target fields such as analysis type
            for (int i = 0; i < coup->volume().weakforms_volume().weakform_volume().size(); i++)
            {
                XMLCoupling::weakform_volume wf = coup->volume().weakforms_volume().weakform_volume().at(i);

                CouplingList::Item item;

                item.sourceField = QString::fromStdString(coup->general().modules().source().id());
                item.sourceAnalysisType = analysisTypeFromStringKey(QString::fromStdString(wf.sourceanalysis()));
                item.targetField = QString::fromStdString(coup->general().modules().target().id());
                item.targetAnalysisType = analysisTypeFromStringKey(QString::fromStdString(wf.targetanalysis()));
                item.couplingType = couplingTypeFromStringKey(QString::fromStdString(wf.couplingtype()));

                m_couplings.append(item);
            }
        }
        catch (const xml_schema::expected_element& e)
        {
            QString str = QString("%1: %2").arg(QString::fromStdString(e.what())).arg(QString::fromStdString(e.name()));
            qDebug() << str;
            throw AgrosException(str);
        }
        catch (const xml_schema::expected_attribute& e)
        {
            QString str = QString("%1: %2").arg(QString::fromStdString(e.what())).arg(QString::fromStdString(e.name()));
            qDebug() << str;
            throw AgrosException(str);
        }
        catch (const xml_schema::unexpected_element& e)
        {
            QString str = QString("%1: %2 instead of %3").arg(QString::fromStdString(e.what())).arg(QString::fromStdString(e.encountered_name())).arg(QString::fromStdString(e.expected_name()));
            qDebug() << str;
            throw AgrosException(str);
        }
        catch (const xml_schema::unexpected_enumerator& e)
        {
            QString str = QString("%1: %2").arg(QString::fromStdString(e.what())).arg(QString::fromStdString(e.enumerator()));
            qDebug() << str;
            throw AgrosException(str);
        }
        catch (const xml_schema::expected_text_content& e)
        {
            QString str = QString("%1").arg(QString::fromStdString(e.what()));
            qDebug() << str;
            throw AgrosException(str);
        }
        catch (const xml_schema::parsing& e)
        {
            QString str = QString("%1").arg(QString::fromStdString(e.what()));
            qDebug() << str;
            xml_schema::diagnostics diagnostic = e.diagnostics();
            for(int i = 0; i < diagnostic.size(); i++)
            {
                xml_schema::error err = diagnostic.at(i);
                qDebug() << QString("%1, position %2:%3, %4").arg(QString::fromStdString(err.id())).arg(err.line()).arg(err.column()).arg(QString::fromStdString(err.message()));
            }
            throw AgrosException(str);
        }
        catch (const xml_schema::exception& e)
        {
            qDebug() << QString("Unknow parser exception: %1").arg(QString::fromStdString(e.what()));
            throw AgrosException(QString::fromStdString(e.what()));
        }
    }
}