示例#1
0
文件: pyvis.cpp 项目: b3sigma/fourd
bool PyVisInterface::PathIntegralSingleStep(NumberList& output) {
    Timer slowness("python time");
    if(!g_PyVis || !g_PyVis->scriptStep)
        return false;

    PyObject* result = PyObject_CallObject(g_PyVis->scriptStep, /* args */ NULL);
    ScopePyDecRef clearResult(result);
    if(!result || !PyList_Check(result) || PyList_Size(result) <= 0) {
        printf("Python script step didn't return a valid list\n");
        return false;
    }

    PyObject* list = PyList_GetItem(result, 0);
    return g_PyVis->CollectNumberList(list, output);
}
示例#2
0
QVector<double> CrustalModel::calculate(const QVector<double> &freq) const
{
    QVector<double> amp(freq.size());
    // Slowness (inverse of the crustal velocity
    QVector<double> slowness(m_velocity.size());

    for (int i = 0; i < slowness.size(); ++i) {
        slowness[i] = 1./m_velocity.at(i);
    }

    // average slowness over a depth range (1/velocity)
    QVector<double> avgSlow(freq.size(), slowness.first());
    // Frequency dependent depth
    QVector<double> depth_f(freq.size(), 0.);

    for (int i = 0; i < freq.size(); ++i) {
        double error = 0;
        int count = 0;

        do {
            ++count;
            depth_f[i] = 1. / (4 * freq.at(i) * avgSlow.at(i));
            const double oldValue = avgSlow.at(i);
            avgSlow[i] = averageValue(m_thickness, slowness, depth_f.at(i));
            error = fabs((oldValue - avgSlow.at(i)) / avgSlow.at(i));
        } while (error > 0.005 && count < 10);
    }

    for (int i = 0; i < freq.size(); ++i) {
        // Average density for the depth range
        const double avgDensity = averageValue(m_thickness, m_density, depth_f.at(i));
        amp[i] = sqrt((m_velocity.at(i) * m_density.at(i)) / (avgDensity / avgSlow.at(i)));
    }

    return amp;
}