Beispiel #1
0
PathInt::PathInt()
 : m_sweeper(new Sweeper)
{
    setExecType(EsBase::Linear);
    setMaxIterations(1000); // n of sweeps
    setMinIterations(1);

    m_sweeper->setTotalSweeps(maxIterations());
//     printHeader("n,S");
}
Beispiel #2
0
//-----------------------------------------------------------------------------------------------
// generates a description for driver file
//-----------------------------------------------------------------------------------------------
QString IpoptOptimizer::description() const
{
    QString str("START OPTIMIZER\n");
    str.append(" TYPE IPOPT \n");
    str.append(" ITERATIONS " + QString::number(maxIterations()) + "\n");
    str.append(" CONT_ITER " + QString::number(maxIterContineous()) + "\n");
    str.append(" PERTURBATION " + QString::number(pertrurbationSize()) + "\n");
    str.append(" PARALLELRUNS " + QString::number(parallelRuns()) + "\n");
    str.append("END OPTIMIZER\n\n");
    return str;
}
void Foam::polyMeshFilterSettings::writeSettings(Ostream& os) const
{
    os  << "Merging:" << nl
        << "    edges with length less than " << minLen() << " metres" << nl
        << "    edges split by a point with edges in line to within "
        << radToDeg(::acos(maxCos())) << " degrees" << nl
        << "    Minimum edge length reduction factor = "
        << edgeReductionFactor() << nl
        << endl;

    if (collapseFacesCoeffDict().empty())
    {
        os  << "Face collapsing is off" << endl;
    }
    else
    {
        os  << "Face collapsing is on" << endl;
        os  << "    Initial face length factor = "<< initialFaceLengthFactor()
            << endl;
    }

    os  << "Control mesh quality = " << controlMeshQuality().asText() << endl;

    if (controlMeshQuality())
    {
        os  << "    Minimum edge length reduction factor = "
            << edgeReductionFactor() << nl
            << "    Minimum face area reduction factor = "
            << faceReductionFactor() << endl;

        os  << "    Maximum number of collapse iterations = " << maxIterations()
            << endl;

        os  << "    Maximum number of edge/face reduction factor smoothing "
            << "iterations = " << maxSmoothIters() << endl;

        os  << "    Maximum number of times a point can contribute to bad "
            << "faces across " << nl
            << "    collapse iterations = " << maxPointErrorCount()
            << endl;
    }

    os  << "Selectively disabling wanted collapses until resulting quality"
        << " satisfies constraints in system/meshQualityDict" << nl
        << endl;
}
Beispiel #4
0
void PathInt::exec(int sweepN)
{
    m_sweeper->doSweep();
//     print(sweepN, m_sweeper->S());

    if (sweepN == maxIterations()) {

        double *meanCorr = m_sweeper->meanCorrelator();
        for (int i = 0; i < m_sweeper->nElements(); i++) {
            print(i, meanCorr[i]);
        }

        std::vector<double> corr_0 = m_sweeper->corr_0();
        double meancorr_0 = meanCorr[0];
        double gamma0 = 0;

        for (int t = 0; t < 100; t++) {

            double variance = 0;

            for (int i = 0; i < sweepN - t; i++) {
                variance += corr_0[i]*corr_0[i+t]/(sweepN-t);
            }

            variance -= pow(meancorr_0, 2.0);

            if (t == 0) {
                gamma0 = variance;
            }

//             print(t, variance/gamma0);
        }

        for (int i = 0; i < m_sweeper->nElements(); i++) {
            std::vector<double> v = m_sweeper->get_cluster(i);
            double sum = std::accumulate(v.begin(), v.end(), 0.0);
            double mean = sum / v.size();

            double stddev = 0.0;
            for (std::vector<double>::iterator j = v.begin(); j != v.end(); j++) {
                stddev += std::pow(*j-mean, 2);
            }
            stddev *= (double)(m_sweeper->nElements()-1)/m_sweeper->nElements();
//             double sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), 0.0);
//             double stdev = std::sqrt(sq_sum / v.size() - mean * mean);
//             print(i, mean, stddev);
        }

        for (int t = 1; t < 7; t++) {
            // Delta E
            // t between 2 and n-1
            std::vector<double> Ek;
            for (int i = 0; i < m_sweeper->nElements(); i++) {
                if (i > 0 and i < 5) {
                    double deltaEi = m_sweeper->get_cluster(t+1)[i]+m_sweeper->get_cluster(t-1)[i];
                    deltaEi /= 2*m_sweeper->get_cluster(t)[i];
                    deltaEi = acosh(deltaEi);
                    Ek.push_back(deltaEi);
                }
            }
            double sum = std::accumulate(Ek.begin(), Ek.end(), 0.0);
            double mean = sum / Ek.size();

            double variance = 0.0;
            for (std::vector<double>::iterator j = Ek.begin(); j != Ek.end(); j++) {
                variance += std::pow((*j)-mean, 2);

//                 print(1, (*j));
            }
            variance *= (double)(m_sweeper->nElements()-1)/m_sweeper->nElements();


//             print (t, mean, sqrt(variance));
        }

    }
}
//-----------------------------------------------------------------------------------------------
// Sets up the parameters object
//-----------------------------------------------------------------------------------------------
void NomadIpoptOptimizer::generateParameters()
{

    p_param = new NOMAD::Parameters(*p_disp);

    // finding the number of variables
    int n_var = runner()->model()->binaryVariables().size() + runner()->model()->integerVariables().size();

    p_param->set_DIMENSION (n_var);     // number of variables

    NOMAD::Point sp(n_var);             // starting point
    NOMAD::Point ub(n_var);             // upper bounds
    NOMAD::Point lb(n_var);             // lower bounds


    // setting all the values for each variable

    int var_num = 0;

    for(int i = 0; i < runner()->model()->binaryVariables().size(); ++i)
    {
        shared_ptr<BinaryVariable> v = runner()->model()->binaryVariables().at(i);

        // setting the type
        p_param->set_BB_INPUT_TYPE(var_num, NOMAD::BINARY);

        // setting the starting point
        sp[var_num] = v->value();

        // setting the upper bound
        ub[var_num] = v->max();

        //setting the lower bound
        lb[var_num] = v->min();

        ++var_num;
    }
    for(int i = 0; i < runner()->model()->integerVariables().size(); ++i)
    {
        shared_ptr<IntVariable> v = runner()->model()->integerVariables().at(i);

        // setting the type
        p_param->set_BB_INPUT_TYPE(var_num, NOMAD::INTEGER);

        // setting the starting point
        sp[var_num] = v->value();

        // setting the upper bound
        ub[var_num] = v->max();

        //setting the lower bound
        lb[var_num] = v->min();

        ++var_num;


    }



    // setting the starting point, upper and lower bounds to the parameters
    p_param->set_X0(sp);
    p_param->set_UPPER_BOUND(ub);
    p_param->set_LOWER_BOUND(lb);


    // setting the objective and constraint info
    int n_con = runner()->model()->constraints().size();

    vector<NOMAD::bb_output_type> bbot (n_con + 1); // definition of output types
    bbot[0] = NOMAD::OBJ;       // the first is the objective
    for(int i = 1; i < n_con + 1; ++i) bbot[i] = NOMAD::PB;     // the rest are constraints

    p_param->set_BB_OUTPUT_TYPE ( bbot );

    // not sure what this does...
    p_param->set_DISPLAY_STATS ( "bbe ( sol ) obj" );

    // setting the maximum number of iterations
    p_param->set_MAX_BB_EVAL(maxIterations());


    // checking if the parameters file exits
    QDir dir(runner()->reservoirSimulator()->folder());

    if(dir.exists("nomad_param.dat"))
    {
        cout << "### Found a NOMAD parameters file... ###" << endl;
        p_param->read(dir.absoluteFilePath("nomad_param.dat").toStdString());

    }




    // parameters validation:
    p_param->check();

    cout << "NOMAD Parameters:" << endl;
    cout << *p_param << endl;



}