Beispiel #1
0
void ReportDialog::generateIndex()
{
    logMessage("ReportDialog::generateIndex()");

    QString fileNameTemplate = tempProblemDir() + "/report/template.html";
    QString fileNameIndex = tempProblemDir() + "/report/report.html";

    QString content;

    // load template.html
    content = readFileContent(fileNameTemplate);
    QFile::remove(fileNameTemplate);

    // save index.html
    QFile fileIndex(fileNameIndex);
    if (fileIndex.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QTextStream stream(&fileIndex);
        stream.setCodec("UTF-8");

        stream << replaceTemplates(content);

        fileIndex.flush();
        fileIndex.close();
    }
}
Beispiel #2
0
QString cacheProblemDir()
{
#ifdef Q_WS_X11
    // fast fix for ht condor
    static QString cch = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
    QDir dirc(cch);
    if (!dirc.exists() && !cch.isEmpty())
        dirc.mkpath(cch);

    // ro system
    if (!dirc.exists())
        cch = tempProblemDir();

    static QString str = QString("%1/%2").
            arg(cch).
            arg(QString::number(QCoreApplication::applicationPid()));
#endif
#ifdef Q_WS_WIN
    static QString str = QString("%1/agros2d/%2").
            arg(QDir::temp().absolutePath()).
            arg(QString::number(QCoreApplication::applicationPid()));
#endif

    QDir dir(str);
    if (!dir.exists() && !str.isEmpty())
        dir.mkpath(str);

    return str;
}
Beispiel #3
0
void ReportDialog::generateFigures()
{
    logMessage("ReportDialog::generateFigures()");

    bool showRulers = chkShowRulers->isChecked();
    bool showGrid = chkShowGrid->isChecked();
    m_sceneView->saveImagesForReport(tempProblemDir() + "/report",
                                     showRulers,
                                     showGrid,
                                     txtFigureWidth->value().number,
                                     txtFigureHeight->value().number);
}
Beispiel #4
0
void Agros2D::clear()
{
    delete m_singleton.data()->m_scene;
    delete m_singleton.data()->m_problem;
    delete m_singleton.data()->m_configComputer;
    delete m_singleton.data()->m_solutionStore;
    delete m_singleton.data()->m_log;
    delete m_singleton.data()->m_memoryMonitor;

    // remove temp and cache plugins
    removeDirectory(cacheProblemDir());
    removeDirectory(tempProblemDir());
}
Beispiel #5
0
void ImageSequenceDialog::animateSequence(int index)
{
    if (m_images.count() == 0)
        return;

    QString fileName = tempProblemDir() + QString("/video/") + m_images.at(index);
    if (QFile::exists(fileName))
    {
        m_currentImage.load(fileName);
        updateImage();

        lblStep->setText(QString("%1 / %2").arg(index + 1).arg(m_images.count()));
    }
}
Beispiel #6
0
void readMeshDirtyFix()
{
    // fix precalulating matrices for mapping of curved elements

    // save locale
    char *plocale = setlocale (LC_NUMERIC, "");
    setlocale (LC_NUMERIC, "C");

    std::ostringstream os;
    os << "vertices = [" << std::endl <<
          "  [ 0, 0 ]," << std::endl <<
          "  [ 1, 0 ]," << std::endl <<
          "  [ 0, 1 ]" << std::endl <<
          "]" << std::endl << std::endl <<
          "elements = [" << std::endl <<
          "  [ 0, 1, 2, \"element_0\" ]" << std::endl << std::endl <<
          "boundaries = [" << std::endl <<
          "  [ 0, 1, \"0\" ]," << std::endl <<
          "  [ 1, 2, \"0\" ]," << std::endl <<
          "  [ 2, 0, \"0\" ]" << std::endl <<
          "]" << std::endl << std::endl <<
          "curves = [" << std::endl <<
          "  [ 0, 1, 90 ]" << std::endl <<
          "]" << std::endl;

    Mesh mesh;
    H2DReader meshloader;

    std::ofstream outputFile((tempProblemDir().toStdString() + "/dummy.mesh").c_str(), fstream::out);
    outputFile << os.str();
    outputFile.close();

    meshloader.load((tempProblemDir().toStdString() + "/dummy.mesh").c_str(), &mesh);

    // set system locale
    setlocale(LC_NUMERIC, plocale);
}
Beispiel #7
0
static PyObject *pythonTempname(PyObject* self, PyObject* pArgs)
{
    QString tempDir = tempProblemDir() + "/temp/";
    QDir(tempDir).mkdir(tempDir);

    QString tempName = QUuid::createUuid().toString().remove("{").remove("}");

    char *str = "";
    if (PyArg_ParseTuple(pArgs, "|s", &str))
    {
        if (str != "")
            tempName = tempName + "." + str;
    }

    return PyString_FromString((tempDir + tempName).toStdString().c_str());
}
Beispiel #8
0
void VideoDialog::setAdaptiveStep(int adaptiveStep)
{
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowRulers, chkFigureShowRulers->isChecked());
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowGrid, chkFigureShowGrid->isChecked());
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowAxes, chkFigureShowAxes->isChecked());

    m_postHermes->setActiveAdaptivityStep(adaptiveStep - 1);
    m_postHermes->refresh();

    sliderAdaptiveAnimate->setValue(adaptiveStep);
    lblAdaptiveStep->setText(QString("%1 / %2").arg(adaptiveStep).arg(m_adaptiveSteps));

    if (chkSaveImages->isChecked())
        m_sceneViewInterface->saveImageToFile(tempProblemDir() + QString("/video/video_%1.png").arg(QString("0000000" + QString::number(adaptiveStep)).right(8)));

    QApplication::processEvents();
}
Beispiel #9
0
static PyObject *pythonTempname(PyObject* self, PyObject* pArgs)
{
    QString tempDir = tempProblemDir() + "/temp/";
    QDir(tempDir).mkdir(tempDir);

    QString tempName = QUuid::createUuid().toString().remove("{").remove("}");
    QString fn = QFileInfo(tempDir + tempName).absoluteFilePath();

    char *str = NULL;
    if (PyArg_ParseTuple(pArgs, "|s", &str))
    {
        if (!QString(str).trimmed().isEmpty())
            fn = fn + "." + str;
    }

    return PyString_FromString(compatibleFilename(fn).toLatin1().data());
}
Beispiel #10
0
QString ReportDialog::htmlFigure(const QString &fileName, const QString &caption)
{
    logMessage("ReportDialog::htmlFigure()");

    QString out;

    if (QFile::exists(tempProblemDir() + "/report/" + fileName))
    {
        out += "\n";
        out += QString("<img src=\"%1\"><p>" + tr("Figure: %2") + "</p>").
                arg(fileName).
                arg(caption);
        out += "\n";
    }

    return out;
}
Beispiel #11
0
void VideoDialog::setTransientStep(int transientStep)
{
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowRulers, chkFigureShowRulers->isChecked());
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowGrid, chkFigureShowGrid->isChecked());
    Agros2D::problem()->setting()->setValue(ProblemSetting::View_ShowAxes, chkFigureShowAxes->isChecked());

    m_postHermes->setActiveTimeStep(transientStep);
    m_postHermes->setActiveAdaptivityStep(Agros2D::solutionStore()->lastAdaptiveStep(m_postHermes->activeViewField(), SolutionMode_Normal, transientStep));
    m_postHermes->refresh();

    if (chkSaveImages->isChecked())
        m_sceneViewInterface->saveImageToFile(tempProblemDir() + QString("/video/video_%1.png").arg(QString("0000000" + QString::number(transientStep)).right(8)));

    sliderTransientAnimate->setValue(transientStep);

    QString time = QString::number(m_timeLevels[transientStep], 'g');
    lblTransientStep->setText(QString("%1 / %2").arg(transientStep).arg(m_timeSteps));
    lblTransientTime->setText(tr("%1 / %2 s").arg(time).arg(m_timeLevels.last()));

    QApplication::processEvents();
}
Beispiel #12
0
VideoDialog::VideoDialog(SceneViewPostInterface *sceneViewInterface, PostHermes *postHermes, QWidget *parent)
    : QDialog(parent), m_sceneViewInterface(sceneViewInterface), m_postHermes(postHermes)
{
    setModal(true);
    setWindowIcon(icon("video"));
    setWindowTitle(tr("Video"));

    // create directory
    QDir(tempProblemDir()).mkdir("video");

    // store timestep
    m_timeStepStore = m_postHermes->activeTimeStep();
    // store adaptive step
    m_adaptiveStepStore = m_postHermes->activeAdaptivityStep();

    m_showRulersStore = Agros2D::problem()->setting()->value(ProblemSetting::View_ShowRulers).toBool();
    m_showGridStore = Agros2D::problem()->setting()->value(ProblemSetting::View_ShowGrid).toBool();
    m_showAxesStore = Agros2D::problem()->setting()->value(ProblemSetting::View_ShowAxes).toBool();

    // timer create images
    timer = new QTimer(this);

    createControls();
}
Beispiel #13
0
void ReportDialog::doShowReport()
{
    logMessage("ReportDialog::doShowReport()");

    QDir(tempProblemDir()).mkdir("report");

    QFile::remove(QString("%1/report/template.html").arg(tempProblemDir()));
    QFile::remove(QString("%1/report/style.css").arg(tempProblemDir()));
    bool fileTemplateOK = QFile::copy(QString(txtTemplate->text()),
                                      QString("%1/report/template.html").arg(tempProblemDir()));
    bool fileStyleOK = QFile::copy(QString(txtStyleSheet->text()),
                                      QString("%1/report/style.css").arg(tempProblemDir()));
    if (!fileTemplateOK)
        QMessageBox::critical(QApplication::activeWindow(), tr("Error"), tr("Report template could not be copied."));
    else if (!fileStyleOK)
        QMessageBox::critical(QApplication::activeWindow(), tr("Error"), tr("Template style could not be copied."));
    else
    {
        generateFigures();
        generateIndex();

        QDesktopServices::openUrl(QUrl::fromLocalFile(tempProblemDir() + "/report/report.html"));
    }
}
Beispiel #14
0
void ChartDialog::doExportData()
{
    logMessage("ChartDialog::doExportData()");

    QSettings settings;
    QString dir = settings.value("General/LastDataDir").toString();

    QString selectedFilter;
    QString fileName = QFileDialog::getSaveFileName(this, tr("Export data to file"), dir, tr("CSV files (*.csv);;Matlab/Octave script (*.m)"), &selectedFilter);
    if (!fileName.isEmpty())
    {
        QString ext = (selectedFilter.contains("CSV")) ? ".csv" : ".m";
        QFileInfo fileInfo(fileName);

        // open file for write
        if (fileInfo.suffix().isEmpty())
            fileName = fileName + ext;

        QFile file(fileName);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            cerr << "Could not create " + fileName.toStdString() + " file." << endl;
            return;
        }
        QTextStream out(&file);

        // export
        // csv
        if (fileInfo.suffix().toLower() == "csv")
        {
            // header
            for (int j = 0; j < trvTable->columnCount(); j++)
                out << trvTable->horizontalHeaderItem(j)->text() << ";";
            out << endl;

            // items
            for (int i = 0; i < trvTable->rowCount(); i++)
            {
                for (int j = 0; j < trvTable->columnCount(); j++)
                    out << trvTable->item(i, j)->text()  << ";";
                out << endl;
            }
        }

        // m-file
        if (fileInfo.suffix().toLower() == "m")
        {
            // items
            for (int j = 0; j < trvTable->columnCount(); j++)
            {
                out << trvTable->horizontalHeaderItem(j)->text().replace(" ", "_") << " = [";
                for (int i = 0; i < trvTable->rowCount(); i++)
                    out << trvTable->item(i, j)->text().replace(",", ".") << ((i <= trvTable->rowCount()-2) ? ", " : "");
                out << "];" << endl;
            }

            // example
            out << endl << endl;
            out << "% example" << endl;
            out << "% plot(sqrt(X.^2 + Y.^2), " << trvTable->horizontalHeaderItem(2)->text().replace(" ", "_") << ");" << endl;
            out << "% grid on;" << endl;
            out << "% xlabel('length (m)');" << endl;
            out << "% ylabel('" << trvTable->horizontalHeaderItem(2)->text() << "');" << endl;
        }

        if (fileInfo.absoluteDir() != tempProblemDir())
            settings.setValue("General/LastDataDir", fileInfo.absolutePath());

        file.close();
    }
}
Beispiel #15
0
QString tempProblemFileName()
{
    return tempProblemDir() + "/temp";
}
Beispiel #16
0
ImageSequenceDialog::ImageSequenceDialog(QWidget *parent)
    : QDialog(parent)
{
    setModal(true);
    setWindowIcon(icon("video"));
    setWindowTitle(tr("Video"));

    // read images
    QStringList filters;
    filters << "*.png";

    QDir dir(tempProblemDir() + QString("/video"));
    dir.setNameFilters(filters);
    m_images = dir.entryList();

    sliderAnimateSequence = new QSlider(Qt::Horizontal);
    sliderAnimateSequence->setTickPosition(QSlider::TicksBelow);
    sliderAnimateSequence->setMaximum(m_images.count() - 1);
    connect(sliderAnimateSequence, SIGNAL(valueChanged(int)), this, SLOT(animateSequence(int)));

    int speed = 300;
    cmbSpeed = new QComboBox();
    cmbSpeed->addItem(" 10 %", speed / 0.10);
    cmbSpeed->addItem(" 25 %", speed / 0.25);
    cmbSpeed->addItem(" 50 %", speed / 0.50);
    cmbSpeed->addItem(" 75 %", speed / 0.75);
    cmbSpeed->addItem("100 %", speed);
    cmbSpeed->addItem("150 %", speed / 1.50);
    cmbSpeed->addItem("200 %", speed / 2.00);
    cmbSpeed->addItem("300 %", speed / 3.00);
    cmbSpeed->addItem("400 %", speed / 4.00);
    cmbSpeed->addItem("500 %", speed / 5.00);

    QSettings settings;
    cmbSpeed->setCurrentIndex(cmbSpeed->findData(settings.value("ImageSequenceDialog/Speed").toDouble()));
    if (cmbSpeed->currentIndex() == -1)
        cmbSpeed->setCurrentIndex(cmbSpeed->findData(speed));

    btnAnimate = new QPushButton(tr("Run"));

    btnClose = new QPushButton(tr("Close"));
    btnClose->setDefault(true);
    connect(btnClose, SIGNAL(clicked()), this, SLOT(doClose()));

    lblStep = new QLabel();

    QHBoxLayout *layoutControls = new QHBoxLayout();
    layoutControls->addWidget(sliderAnimateSequence);
    layoutControls->addWidget(lblStep);
    layoutControls->addWidget(new QLabel(tr("Speed:")));
    layoutControls->addWidget(cmbSpeed);
    layoutControls->addWidget(btnAnimate);
    layoutControls->addWidget(btnClose);

    lblImage = new QLabel();
    lblImage->setAlignment(Qt::AlignCenter);

    QVBoxLayout *layoutViewport = new QVBoxLayout();
    layoutViewport->addWidget(lblImage, Qt::AlignHCenter);
    layoutViewport->addLayout(layoutControls);

    setLayout(layoutViewport);

    // timer create images
    timer = new QTimer(this);
    connect(btnAnimate, SIGNAL(clicked()), this, SLOT(animate()));
    connect(timer, SIGNAL(timeout()), this, SLOT(animateNextStep()));

    if (m_images.count() > 0)
        animateSequence(0);
}
Beispiel #17
0
bool SolutionAgros::solve(Hermes::vector<Space *> space,
                          Hermes::vector<Solution *> solution,
                          Solver *solver, SparseMatrix *matrix, Vector *rhs)
{
    bool isError = false;
    if (linearityType == LinearityType_Linear)
    {
        DiscreteProblem dpLin(m_wf, space, true);

        isError = !solveLinear(&dpLin, space, solution,
                               solver, matrix, rhs);

        // dump matrix
        FILE *f = fopen(QString(tempProblemDir() + "/matrix.m").toStdString().c_str(), "w");
        matrix->dump(f, QString("mat").toStdString().c_str(), DF_MATRIX_MARKET);
        fclose(f);

        return !isError;
    }

    if (linearityType == LinearityType_Picard)
    {
        /*
        DiscreteProblem dpNonlinPicard(m_wf, space, true);

        // create Picard solution
        Hermes::vector<Solution *> solutionPicard;
        for (int i = 0; i < numberOfSolution; i++)
            solutionPicard.push_back(new Solution());

        // perform the Picard's iteration
        for (int i = 0; i < linearityNonlinearSteps; i++)
        {
            isError = !solveLinear(&dpNonlinPicard, space, solutionPicard,
                                   solver, matrix, rhs, false);

            ProjNormType projNormTypeTMP = HERMES_H1_NORM;
            // ProjNormType projNormTypeTMP = HERMES_L2_NORM;

            // calc error
            double *val_sol, *val_solpic, *val_diff;
            double error = 0.0;
            for (int i = 0; i < numberOfSolution; i++)
            {
                error += calc_abs_error(solution.at(i), solutionPicard.at(i), projNormTypeTMP) * 100.0
                        / calc_norm(&sln_new, HERMES_H1_NORM) * 100;

                val_sol = solution.at(i)->get_fn_values();
                val_solpic = solutionPicard.at(i)->get_fn_values();

                val_diff = new double[Space::get_num_dofs(space)];
                for (int j = 0; j < Space::get_num_dofs(space); j++)
                    val_diff[j] = val_solpic[j]; //  + 0.5 * (val_sol[j] - val_solpic[j]);
            }

            // emit signal
            m_progressItemSolve->emitMessage(QObject::tr("Picards method rel. error (%2/%3): %1%").
                                             arg(error, 0, 'f', 5).
                                             arg(i + 1).
                                             arg(linearityNonlinearSteps), false, 1);

            // add error to the list
            m_progressItemSolve->addNonlinearityError(error);

            if (error < linearityNonlinearTolerance)
            {
                // FIXME - clean up
                break;
            }

            // copy solution
            for (int i = 0; i < numberOfSolution; i++)
            {
                // if (error > 100.0)
                //     solution.at(i)->multiply(0.5);
                // else
                solution.at(i)->copy(solutionPicard.at(i));
            }
            // Solution::vector_to_solutions(val_solpic, space, solution);
            // Solution::vector_to_solutions(solutionPicard., space, solution);
        }

        for (int i = 0; i < solutionPicard.size(); i++)
            delete solutionPicard.at(i);
        solutionPicard.clear();

        return !isError;
        */
    }

    if (linearityType == LinearityType_Newton)
    {
        /*
        // project the initial condition on the FE space to obtain initial
        // coefficient vector for the Newton's method.
        info("Projecting to obtain initial vector for the Newton's method.");
        double *coeff_vec = new double[Space::get_num_dofs(space)];
        OGProjection::project_global(space, solution.at(0), coeff_vec,
                                     Util::scene()->problemInfo()->matrixSolver);

        DiscreteProblem dpNonlinNewton(wf, space, false);

        // The Newton's loop.
        double damping_coeff = 1.0;

        // perform the Picard's iteration
        for (int i = 0; i < linearityNonlinearSteps; i++)
        {
            // assemble the Jacobian matrix and residual vector.
            dpNonlinNewton.assemble(coeff_vec, matrix, rhs, false);

            // Multiply the residual vector with -1 since the matrix
            // equation reads J(Y^n) \deltaY^{n+1} = -F(Y^n).
            rhs->change_sign();

            // Calculate the l2-norm of residual vector
            double error = get_l2_norm(rhs);

            // emit signal
            m_progressItemSolve->emitMessage(QObject::tr("Newton’s method rel. error (%2/%3): %1")
                                             .arg(error, 0, 'f', 5)
                                             .arg(i)
                                             .arg(linearityNonlinearSteps), false, 1);

            // add error to the list
            m_progressItemSolve->addNonlinearityError(error);

            // if residual norm is within tolerance, or the maximum number of iteration has been reached, then quit.
            if (error < linearityNonlinearTolerance)
                break;

            // Solve the linear system.
            isError = solver->solve();
            if (!isError)
                error("Matrix solver failed.\n");

            // add \deltaY^{n+1} to Y^n.
            for (int j = 0; j < Space::get_num_dofs(space); j++)
                coeff_vec[j] += damping_coeff * solver->get_solution()[j];
        }

        Solution::vector_to_solutions(coeff_vec, space, solution);

        delete [] coeff_vec;
        */
    }
}