MultiScaleQuadrature( )
        :
        super( (1+std::pow(2,ioption("msi.level")))*(std::pow(2,ioption("msi.level"))+1) )
    {

        int gridsize=std::pow(2,ioption("msi.level"));

        // build rules in x and y direction
        weights_type wx( (gridsize+1)*(gridsize+1) );
        //weights_type px( (gridsize*gridsize );
        
        double tmpx=-1.;
        double tmpy=1.;
        for ( int i = 0,  k = 0; i <= gridsize; i++ )
        {
            for ( int j = 0; j <=  gridsize; j++, ++k )
            {
                // computes the weight of the k-th node
                this->M_w( k ) = 4./( (gridsize+1)*(gridsize+1)) ;//wx( i ) * wx( j );
                this->M_points( 0, k ) = tmpx ;
                this->M_points( 1, k ) = tmpy ;
                tmpx+=2./gridsize;
            }
            tmpx=-1.;
            tmpy-=2./gridsize;
        }
        std::cout << "quadrature points:" << this->M_points << std::endl; 
        boost::shared_ptr<GT_Lagrange<2, 1, 2, Hypercube, T> > gm( new GT_Lagrange<2, 1, 2, Hypercube, T> );
        boost::shared_ptr<face_quad_type> face_qr( new face_quad_type());
        // construct face quadratures
        this->constructQROnFace( Reference<Hypercube<2, 1>,2,1>(), gm, face_qr );

    }
    MultiScaleQuadrature()
        :
        super( std::pow(2,ioption("msi.level"))+1  )
    {

        int  gridsize = std::pow(2,ioption("msi.level"));

        // build rules in x and y direction
        weights_type wx( gridsize+1  );
        weights_type px( gridsize+1  );

        double tmp=-1;
        for ( int i = 0; i <=gridsize ; i++ )
        {
            // computes the weight of the k-th node
            this->M_w( i ) = 2./(gridsize+1) ;// wx( i );
            this->M_points( 0, i ) = tmp ;
            tmp+=2./gridsize ;
        }

        boost::shared_ptr<GT_Lagrange<1,1,1, Hypercube,T> > gm( new GT_Lagrange<1, 1, 1, Hypercube, T> );
        boost::shared_ptr<face_quad_type> face_qr( new face_quad_type );
        // construct face quadratures
        this->constructQROnFace( Reference<Hypercube<1, 1>, 1, 1>(), gm, face_qr );

    }
Exemple #3
0
    Beam()
        :
        super(),
        meshSize( doption("hsize"  )),
        beta(     doption("beta"   )),
        bcCoeff(  doption("bccoeff")),
        M_bctype( ioption("bctype" )),
        exporter( Exporter<mesh_type>::New( this->about().appName() ) ),
        timers()
    {
        LOG(INFO) << "[Beam] hsize = " << meshSize << "\n";
        LOG(INFO) << "[Beam] beta = " << beta << "\n";
        LOG(INFO) << "[Beam] bccoeff = " << bcCoeff << "\n";
        LOG(INFO) << "[Beam] bctype = " <<  M_bctype << "\n";

    }
Exemple #4
0
void
ExporterVTK<MeshType,N>::save() const
{
    int stepIndex = TS_INITIAL_INDEX;
    double time = 0.0;
    bool hasSteps = true;
    std::ostringstream fname;
    std::ostringstream oss;

    DVLOG(2) << "[ExporterVTK] checking if frequency is ok\n";

    if ( this->cptOfSave() % this->freq()  )
    {
        this->saveTimeSet();
        return;
    }

    DVLOG(2) << "[ExporterVTK] frequency is ok\n";

    DVLOG(2) << "[ExporterVTK] save()...\n";

    timeset_const_iterator __ts_it = this->beginTimeSet();
    timeset_const_iterator __ts_en = this->endTimeSet();

    int i = 0;
    while ( __ts_it != __ts_en )
    {
        timeset_ptrtype __ts = *__ts_it;

        typename timeset_type::step_const_iterator __it = __ts->beginStep();
        typename timeset_type::step_const_iterator __end = __ts->endStep();

        /* instanciante data object */
        vtkSmartPointer<vtkout_type> out = vtkSmartPointer<vtkout_type>::New();

        /* check if we have steps for the current dataset */
        if(__it == __end)
        {
            LOG(INFO) << "Timeset " << __ts->name() << " (" << __ts->index() << ") contains no timesteps (Consider using add() or addRegions())" << std::endl;
            hasSteps = false;

            /* save mesh if we have one */
            if(__ts->hasMesh())
            {
                this->saveMesh(__ts->mesh(), out);
            }
        }
        else
        {
            __it = boost::prior( __end );

            typename timeset_type::step_ptrtype __step = *__it;

            if ( __step->isInMemory() )
            {
                /* write data into vtk object */
                this->saveMesh(__step->mesh(), out);
                this->saveNodeData( __step, __step->beginNodalScalar(), __step->endNodalScalar(), out );
                this->saveNodeData( __step, __step->beginNodalVector(), __step->endNodalVector(), out );
                this->saveNodeData( __step, __step->beginNodalTensor2(), __step->endNodalTensor2(), out );
                this->saveElementData( __step, __step->beginElementScalar(), __step->endElementScalar(), out );
                this->saveElementData( __step, __step->beginElementVector(), __step->endElementVector(), out );
                this->saveElementData( __step, __step->beginElementTensor2(), __step->endElementTensor2(), out );

#if VTK_MAJOR_VERSION >= 6 && defined(VTK_HAS_PARALLEL)
                out->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), __step->time());
#endif

                /* record time value */
                time = __step->time();
                stepIndex = __step->index();

            }
        }

        /* Build a multi block dataset based on gathered data */
        vtkSmartPointer<vtkMultiBlockDataSet> mbds = this->buildMultiBlockDataSet( time, out );

        /* InitializeExternal is only supported from 5.10+, */
        /* but lets aim for the latest major version 6 to reduce the complexity */
        fname.str("");
        fname << this->path() << "/" << this->prefix()  //<< this->prefix() //this->path()
              << "-" << (stepIndex - TS_INITIAL_INDEX);
#if VTK_MAJOR_VERSION < 6 || !defined(VTK_HAS_PARALLEL)
        fname << "-" << this->worldComm().size() << "_" << this->worldComm().rank();
#endif
        fname << ".vtm";

#if defined(FEELPP_VTK_INSITU_ENABLED)
        /* initialize in-situ visualization if needed and if we specified pipelines to handle */
        if(boption( _name="exporter.vtk.insitu.enable" ) && inSituProcessor->GetNumberOfPipelines() > 0)
        {
            //std::cout << "Processing timestep In-Situ " << (__step->index() - TS_INITIAL_INDEX) << " " << __step->time() << std::endl;
            vtkSmartPointer<vtkCPDataDescription> dataDescription = vtkSmartPointer<vtkCPDataDescription>::New();
            dataDescription->AddInput("input");
            dataDescription->SetTimeData(time, stepIndex - TS_INITIAL_INDEX);

            vtkStdString sh = soption( _name="exporter.vtk.insitu.hostname");

            vtkSmartPointer<vtkStringArray> hname = vtkSmartPointer<vtkStringArray>::New();
            hname->SetName( "hostname" );
            hname->InsertNextValue(sh);
            vtkSmartPointer<vtkIntArray> port = vtkSmartPointer<vtkIntArray>::New();
            port->SetName( "port" );
            port->InsertNextValue( ioption( _name="exporter.vtk.insitu.port") );

            vtkSmartPointer<vtkFieldData> fdata = vtkSmartPointer<vtkFieldData>::New();
            fdata->AddArray(hname);
            fdata->AddArray(port);

            dataDescription->SetUserData(fdata);

            if(inSituProcessor->RequestDataDescription(dataDescription.GetPointer()) != 0)
            {
                dataDescription->GetInputDescriptionByName("input")->SetGrid(mbds);
                //dataDescription->SetForceOutput(true);
                //std::cout << "CoProcess " << inSituProcessor->CoProcess(dataDescription.GetPointer())<< std::endl;
                inSituProcessor->CoProcess(dataDescription.GetPointer());
            }
        }

        /* if insitu is not enable, or if it is enabled but we want to save data */
        /* handle thoses cases with this if */
        if(!(boption( _name="exporter.vtk.insitu.enable" )) || inSituProcessor->GetNumberOfPipelines() == 0
                || (boption( _name="exporter.vtk.insitu.enable" ) && boption( _name="exporter.vtk.insitu.save" ) ) )
        {
#endif
            /* write VTK files */
            this->write(stepIndex, fname.str(), mbds);

            /* write additional file for handling time steps */
            /* only write on master rank */
            if(this->worldComm().isMasterRank())
            {
                /* rebuild the filename for the pvd file */
                /* This removes the path used for exporting */
                std::ostringstream lfile;
                lfile << this->prefix()  //<< this->prefix() //this->path()
                      << "-" << (stepIndex - TS_INITIAL_INDEX);
#if VTK_MAJOR_VERSION < 6 || !defined(VTK_HAS_PARALLEL)
                lfile << "-" << this->worldComm().size() << "_" << this->worldComm().rank();
#endif
                lfile << ".vtm";

                /* check if we are on the initial timestep */
                /* if so, we delete the previous pvd file */
                /* otherwise we would append dataset to already existing data */
                std::string pvdFilename = this->path() + "/" + this->prefix() + ".pvd";
                if( (stepIndex - TS_INITIAL_INDEX) == 0 && fs::exists(pvdFilename.c_str()))
                {
                    fs::remove(pvdFilename.c_str());
                }
#if VTK_MAJOR_VERSION < 6 || !defined(VTK_HAS_PARALLEL)
                /* when we are not writing data with parallel filters */
                /* we provide the info about the different parts from with */
                /* a dataset is built: the different file names and the part id */
                std::ostringstream oss;
                for(int i = 0; i < this->worldComm().size(); i++)
                {
                    oss.str("");
                    oss << this->prefix() << "-" << (stepIndex - TS_INITIAL_INDEX)
                        << "-" << this->worldComm().size() << "_" << i
                        << ".vtm";
                    this->writeTimePVD(pvdFilename, time, oss.str(), i);
                }
#else
                /* When writing in parallel, we only write one entry in the pvd file */
                this->writeTimePVD(pvdFilename, time, lfile.str());
#endif
            }
#if defined(FEELPP_VTK_INSITU_ENABLED)
        }
#endif

        __ts_it++;
    }

    DVLOG(2) << "[ExporterVTK] saving done\n";

    this->saveTimeSet();
}
Exemple #5
0
      ( parametricnodes, *( boost::is_integral<mpl::_> ), 0 )
      ( in_memory,       *( boost::is_integral<mpl::_> ), boption(_prefix=prefix,_name="gmsh.in-memory") )
      ( straighten,      *( boost::is_integral<mpl::_> ), boption(_prefix=prefix,_name="gmsh.straighten") )
      ( refine,          *( boost::is_integral<mpl::_> ), ioption(_prefix=prefix,_name="gmsh.refine") )
      ( structured,          *( boost::is_integral<mpl::_> ), ioption(_prefix=prefix,_name="gmsh.structured") )
      ( update,          *( boost::is_integral<mpl::_> ), MESH_RENUMBER|MESH_UPDATE_EDGES|MESH_UPDATE_FACES|MESH_CHECK )
      ( force_rebuild,   *( boost::is_integral<mpl::_> ), 0 )
      ( physical_are_elementary_regions,           *,boption(_prefix=prefix,_name="gmsh.physical_are_elementary_regions"))
      ( periodic,        *, PeriodicEntities() )
      ( respect_partition,	(bool), boption(_prefix=prefix,_name="gmsh.respect_partition") )
      ( rebuild_partitions,	(bool), boption(_prefix=prefix,_name="gmsh.partition") )
      ( rebuild_partitions_filename, *( boost::is_convertible<mpl::_,std::string> )	, desc->prefix()+".msh" )
      ( worldcomm,      *, Environment::worldComm() )
      ( partitions,   *( boost::is_integral<mpl::_> ), worldcomm.localSize() )
      ( partition_file,   *( boost::is_integral<mpl::_> ), 0 )
      ( partitioner,   *( boost::is_integral<mpl::_> ), ioption(_prefix=prefix,_name="gmsh.partitioner") )
        )
    )
{
    typedef typename Feel::detail::mesh<Args>::type _mesh_type;
    typedef typename Feel::detail::mesh<Args>::ptrtype _mesh_ptrtype;

    _mesh_ptrtype _mesh( mesh );
    _mesh->setWorldComm( worldcomm );

    if ( worldcomm.isActive() )
    {
        desc->setDimension( mesh->nDim );
        desc->setOrder( mesh->nOrder );
        desc->setWorldComm( worldcomm );
        desc->setNumberOfPartitions( partitions );
Exemple #6
0
typename CRBTrilinear<TruthModelType>::convergence_type
CRBTrilinear<TruthModelType>::offline()
{

    int proc_number = this->worldComm().globalRank();

    bool rebuild_database = boption(_name="crb.rebuild-database") ;
    bool orthonormalize_primal = boption(_name="crb.orthonormalize-primal") ;

    boost::timer ti;
    if( this->worldComm().isMasterRank() )
        std::cout << "Offline CRBTrilinear starts, this may take a while until Database is computed..."<<std::endl;
    LOG(INFO) << "[CRBTrilinear::offline] Starting offline for output " << this->M_output_index << "\n";
    LOG(INFO) << "[CRBTrilinear::offline] initialize underlying finite element model\n";
    //M_model->initModel();
    LOG( INFO )<< " -- model init done in " << ti.elapsed() << "s";

    parameter_type mu( this->M_Dmu );

    double delta_pr;
    double delta_du;
    size_type index;
    //if M_N == 0 then there is not an already existing database
    if ( rebuild_database || this->M_N == 0)
    {

        ti.restart();

        LOG(INFO) << "[CRBTrilinear::offline] compute random sampling\n";

        int total_proc = this->worldComm().globalSize();
        std::string sampling_mode = soption("crb.sampling-mode");
        bool all_proc_same_sampling=boption("crb.all-procs-have-same-sampling");
        int sampling_size = ioption("crb.sampling-size");
        std::string file_name = ( boost::format("M_Xi_%1%_"+sampling_mode+"-proc%2%on%3%") % sampling_size %proc_number %total_proc ).str();
        if( all_proc_same_sampling )
            file_name+="-all-proc-have-same-sampling";

        std::ifstream file ( file_name );

        if( ! file )
        {

            // random sampling
            std::string supersamplingname =(boost::format("Dmu-%1%-generated-by-master-proc") %sampling_size ).str();

            if( sampling_mode == "log-random" )
                this->M_Xi->randomize( sampling_size , all_proc_same_sampling , supersamplingname );
            else if( sampling_mode == "log-equidistribute" )
                this->M_Xi->logEquidistribute( sampling_size , all_proc_same_sampling , supersamplingname );
            else if( sampling_mode == "equidistribute" )
                this->M_Xi->equidistribute( sampling_size , all_proc_same_sampling , supersamplingname );
            else
                throw std::logic_error( "[CRBTrilinear::offline] ERROR invalid option crb.sampling-mode, please select between log-random, log-equidistribute or equidistribute" );
            //M_Xi->equidistribute( this->vm()["crb.sampling-size"].template as<int>() );

            this->M_Xi->writeOnFile(file_name);

        }
        else
        {
            this->M_Xi->clear();
            this->M_Xi->readFromFile(file_name);
        }

        this->M_WNmu->setSuperSampling( this->M_Xi );


        LOG( INFO )<<"[CRBTrilinear offline] M_error_type = "<<this->M_error_type<<std::endl;

        LOG(INFO) << " -- sampling init done in " << ti.elapsed() << "s";
        ti.restart();

        // empty sets
        this->M_WNmu->clear();
        if( this->M_error_type == CRB_NO_RESIDUAL )
            mu = this->M_Dmu->element();
        else
        {
            // start with M_C = { arg min mu, mu \in Xi }
            boost::tie( mu, index ) = this->M_Xi->min();
        }


        int size = mu.size();
        //std::cout << " -- WN size :  " << M_WNmu->size() << "\n";

        // dimension of reduced basis space
        this->M_N = 0;

        this->M_maxerror = 1e10;
        delta_pr = 0;
        delta_du = 0;
        //boost::tie( M_maxerror, mu, index ) = maxErrorBounds( N );

        LOG(INFO) << "[CRBTrilinear::offline] allocate reduced basis data structures\n";

        this->M_Aqm_pr.resize( this->M_model->Qa() );
        for(int q=0; q<this->M_model->Qa(); q++)
        {
            this->M_Aqm_pr[q].resize( 1 );
        }

        M_Aqm_tril_pr.resize( this->M_model->QaTri() );

        //for(int q=0; q<this->M_model->QaTri(); q++)
        this->M_Fqm_pr.resize( this->M_model->Ql( 0 ) );

        for(int q=0; q<this->M_model->Ql( 0 ); q++)
        {
            this->M_Fqm_pr[q].resize( 1 );
        }

        this->M_Lqm_pr.resize( this->M_model->Ql( this->M_output_index ) );
        for(int q=0; q<this->M_model->Ql( this->M_output_index ); q++)
            this->M_Lqm_pr[q].resize( 1 );

    }//end of if( rebuild_database )
#if 1
    else
    {
        mu = this->M_current_mu;
        if( proc_number == 0 )
        {
            std::cout<<"we are going to enrich the reduced basis"<<std::endl;
            std::cout<<"there are "<<this->M_N<<" elements in the database"<<std::endl;
        }
        LOG(INFO) <<"we are going to enrich the reduced basis"<<std::endl;
        LOG(INFO) <<"there are "<<this->M_N<<" elements in the database"<<std::endl;
    }//end of else associated to if ( rebuild_databse )
#endif

    LOG(INFO) << "[CRBTrilinear::offline] compute affine decomposition\n";

    std::vector< std::vector<sparse_matrix_ptrtype> > Aqm;
    std::vector< std::vector<sparse_matrix_ptrtype> > Aqm_tril;
    std::vector< std::vector<std::vector<vector_ptrtype> > > Fqm;

    boost::tie( boost::tuples::ignore, Aqm, Fqm ) = this->M_model->computeAffineDecomposition();

    element_ptrtype u( new element_type( this->M_model->functionSpace() ) );

    LOG(INFO) << "[CRBTrilinear::offline] starting offline adaptive loop\n";

    bool reuse_prec = this->vm()["crb.reuse-prec"].template as<bool>() ;

    bool use_predefined_WNmu = this->vm()["crb.use-predefined-WNmu"].template as<bool>() ;
    int N_log_equi = this->vm()["crb.use-logEquidistributed-WNmu"].template as<int>() ;
    int N_equi = this->vm()["crb.use-equidistributed-WNmu"].template as<int>() ;
    int N_random = ioption( "crb.use-random-WNmu" );

    /*    if( N_log_equi > 0 || N_equi > 0 )
     use_predefined_WNmu = true;*/

    // file where the sampling is savec
    std::string file_name = ( boost::format("SamplingWNmu") ).str();
    std::ifstream file ( file_name );

    this->M_WNmu->clear();

    if ( use_predefined_WNmu ) // In this case we want to read the sampling
    {
        if( ! file ) // The user forgot to give the sampling file
            throw std::logic_error( "[CRB::offline] ERROR the file SamplingWNmu doesn't exist so it's impossible to known which parameters you want to use to build the database" );
        else
        {
            int sampling_size = this->M_WNmu->readFromFile(file_name);
            if( Environment::isMasterRank() )
                std::cout<<"[CRB::offline] Read WNmu ( sampling size : "
                         << sampling_size <<" )"<<std::endl;
            LOG( INFO )<<"[CRB::offline] Read WNmu ( sampling size : "
                       << sampling_size <<" )";
        }
    }
    else // We generate the sampling with choosen strategy
    {
        if ( N_log_equi>0 )
        {
            this->M_WNmu->logEquidistribute( N_log_equi , true );
            if( Environment::isMasterRank() )
                std::cout<<"[CRB::offline] Log-Equidistribute WNmu ( sampling size : "
                         <<N_log_equi<<" )"<<std::endl;
            LOG( INFO )<<"[CRB::offline] Log-Equidistribute WNmu ( sampling size : "
                       <<N_log_equi<<" )";
        }
        else if ( N_equi>0 )
        {
            this->M_WNmu->equidistribute( N_equi , true );
            if( Environment::isMasterRank() )
                std::cout<<"[CRB::offline] Equidistribute WNmu ( sampling size : "
                         <<N_equi<<" )"<<std::endl;
            LOG( INFO )<<"[CRB::offline] Equidistribute WNmu ( sampling size : "
                       <<N_equi<<" )";
        }
        else if ( N_random>0 )
        {
            this->M_WNmu->randomize( N_random , true );
            if( Environment::isMasterRank() )
                std::cout<<"[CRB::offline] Randomize WNmu ( sampling size : "
                         <<N_random<<" )"<<std::endl;
            LOG( INFO )<<"[CRB::offline] Randomize WNmu ( sampling size : "
                       <<N_random<<" )";
        }
        else // In this case we don't know what sampling to use
            throw std::logic_error( "[CRB::offline] ERROR : You have to choose an appropriate strategy for the offline sampling : random, equi, logequi or predefined" );

        this->M_WNmu->writeOnFile(file_name);

        /*        if( ! file )
        {
            this->M_WNmu->clear();
            std::vector< parameter_type > V;
            parameter_type __mu;
            __mu = this->M_Dmu->element();
            __mu(0)= 1      ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 111112 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 222223 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 333334 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 444445 , __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 555556 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 666667 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 777778 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 888889 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 1e+06  ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 8123   ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)= 9123   ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=1.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=2.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=4.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=912     ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=1.123e3 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=4.123e3 ; __mu(1)= 1  ; V.push_back( __mu );
         __mu(0)=7.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=2123    ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=6.123e3 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=3.123e3 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=3.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=5.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=9.123e4 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=812     ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=5.111e3 ; __mu(1)= 1  ; V.push_back( __mu );
            __mu(0)=5.124e2 ; __mu(1)= 1  ; V.push_back( __mu );
            this->M_WNmu->setElements( V );
            this->M_iter_max = this->M_WNmu->size();
            this->M_WNmu->writeOnFile(file_name);
         }*/
        use_predefined_WNmu=true;
    } //build sampling

    this->M_iter_max = this->M_WNmu->size();
    mu = this->M_WNmu->at( this->M_N ); // first element


    if( this->M_error_type == CRB_NO_RESIDUAL || use_predefined_WNmu )
    {
        //in this case it makes no sens to check the estimated error
        this->M_maxerror = 1e10;
    }


    LOG(INFO) << "[CRBTrilinear::offline] strategy "<< this->M_error_type <<"\n";

    while ( this->M_maxerror > this->M_tolerance && this->M_N < this->M_iter_max )
    {

        boost::timer timer, timer2;
        LOG(INFO) <<"========================================"<<"\n";
        if( proc_number == this->worldComm().masterRank() )
            std::cout<<"construction of "<<this->M_N<<"/"<<this->M_iter_max<<" basis "<<std::endl;
        LOG(INFO) << "N=" << this->M_N << "/"  << this->M_iter_max << "( nb proc : "<<worldComm().globalSize()<<")";

        // for a given parameter \p mu assemble the left and right hand side
        u->setName( ( boost::format( "fem-primal-N%1%-proc%2%" ) % (this->M_N)  % proc_number ).str() );

        mu.check();
        u->zero();

        timer2.restart();

        LOG(INFO) << "[CRB::offline] solving primal" << "\n";
        *u = this->M_model->solve( mu );

        //if( proc_number == this->worldComm().masterRank() ) std::cout << "  -- primal problem solved in " << timer2.elapsed() << "s\n";
        timer2.restart();


        if( ! use_predefined_WNmu )
            this->M_WNmu->push_back( mu, index );

        this->M_WNmu_complement = this->M_WNmu->complement();

        this->M_model->rBFunctionSpace()->addPrimalBasisElement( *u );
        //WARNING : the dual element is not the real dual solution !
        //no dual problem was solved
        this->M_model->rBFunctionSpace()->addDualBasisElement( *u );

        int number_of_added_elements=1;
        this->M_N+=number_of_added_elements;

        if ( orthonormalize_primal )
        {
            this->orthonormalize( this->M_N, this->M_model->rBFunctionSpace()->primalRB() , number_of_added_elements );
            this->orthonormalize( this->M_N, this->M_model->rBFunctionSpace()->primalRB() , number_of_added_elements );
            this->orthonormalize( this->M_N, this->M_model->rBFunctionSpace()->primalRB() , number_of_added_elements );
        }

        LOG(INFO) << "[CRB::offline] compute Aq_pr, Aq_du, Aq_pr_du" << "\n";
        for  (size_type q = 0; q < this->M_model->Qa(); ++q )
        {
            this->M_Aqm_pr[q][0].conservativeResize( this->M_N, this->M_N );

            // only compute the last line and last column of reduced matrices
            for ( size_type i = this->M_N-number_of_added_elements; i < this->M_N; i++ )
            {
                for ( size_type j = 0; j < this->M_N; ++j )
                {
                    this->M_Aqm_pr[q][0]( i, j ) = Aqm[q][0]->energy( this->M_model->rBFunctionSpace()->primalBasisElement(i) , this->M_model->rBFunctionSpace()->primalBasisElement(j) );
                }
            }

            for ( size_type j=this->M_N-number_of_added_elements; j < this->M_N; j++ )
            {
                for ( size_type i = 0; i < this->M_N; ++i )
                {
                    this->M_Aqm_pr[q][0]( i, j ) = Aqm[q][0]->energy( this->M_model->rBFunctionSpace()->primalBasisElement(i), this->M_model->rBFunctionSpace()->primalBasisElement(j) );
                }
            }
        }//loop over q


        LOG(INFO) << "[CRBTrilinear::offline] compute Fq_pr" << "\n";

        for ( size_type q = 0; q < this->M_model->Ql( 0 ); ++q )
        {
            this->M_Fqm_pr[q][0].conservativeResize( this->M_N );

            for ( size_type l = 1; l <= number_of_added_elements; ++l )
            {
                int index = this->M_N-l;
                this->M_Fqm_pr[q][0]( index ) = this->M_model->Fqm( 0, q, 0, this->M_model->rBFunctionSpace()->primalBasisElement(index) );
            }
        }//loop over q

        LOG(INFO) << "[CRB::offline] compute Lq_pr" << "\n";

        for ( size_type q = 0; q < this->M_model->Ql( this->M_output_index ); ++q )
        {
            this->M_Lqm_pr[q][0].conservativeResize( this->M_N );

            for ( size_type l = 1; l <= number_of_added_elements; ++l )
            {
                int index = this->M_N-l;
                this->M_Lqm_pr[q][0]( index ) = this->M_model->Fqm( this->M_output_index, q, 0, this->M_model->rBFunctionSpace()->primalBasisElement(index) );
            }
        }//loop over q

        sparse_matrix_ptrtype trilinear_form;
        for  (size_type q = 0; q < this->M_model->QaTri(); ++q )
        {
            M_Aqm_tril_pr[q].resize( this->M_N );
            for (int k=0 ; k<this->M_N; k++)
            {
                //bring back the matrix associated to the trilinear form for a given basis function
                //we do this here to use only one matrix
                trilinear_form  = this->M_model->computeTrilinearForm( this->M_model->rBFunctionSpace()->primalBasisElement(k) );

                M_Aqm_tril_pr[q][k].conservativeResize( this->M_N, this->M_N );
                for ( int i = 0; i < this->M_N; ++i )
                {
                    for ( int j = 0; j < this->M_N; ++j )
                    {
                        M_Aqm_tril_pr[q][k]( i, j ) = trilinear_form->energy( this->M_model->rBFunctionSpace()->primalBasisElement(j), this->M_model->rBFunctionSpace()->primalBasisElement(i) );
                    }//j
                }//i
            }//k
        }// q

        timer2.restart();

        if ( ! use_predefined_WNmu )
        {
            bool already_exist;
            do
            {
                //initialization
                already_exist=false;
                //pick randomly an element
                mu = this->M_Dmu->element();
                //make sure that the new mu is not already is M_WNmu
                BOOST_FOREACH( auto _mu, *this->M_WNmu )
                {
                    if( mu == _mu )
                        already_exist=true;
                }
            }
            while( already_exist );
            this->M_current_mu = mu;
        }
        else
        {
            //remmber that in this case M_iter_max = sampling size
            if( this->M_N < this->M_iter_max )
Exemple #7
0
void get_config(char *config_filename)
{
 char *cnf="mark";
 
 printf("Configured keywords: ");
 parse(config_filename)
 {
  option("keyword",kwd);
  if(kwd)
  {
   printf("%s ",kwd);

   create(keyword,Keyword);
   keyword->key=kwd;
   keyword->asymetry_ratio=1;          /* ratio for ADSL-like upload */
   keyword->asymetry_fixed=0;          /* fixed treshold for ADSL-like upload */
   keyword->data_limit=8;              /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */
   keyword->data_prio=4;              /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */
   keyword->fixed_limit=0;             /* fixed data limit for setting lower HTB ceil */
   keyword->fixed_prio=0;              /* fixed data limit for setting lower HTB prio */
   keyword->reserve_min=8;	       /* bonus for nominal HTB rate bandwidth (in kbps) */
   keyword->reserve_max=0;	       /* malus for nominal HTB ceil (in kbps) */
/* obsolete:
   keyword->divide_max=0;	       relative malus: new_ceil=rate+(old_ceil-rate)/divide_max
   keyword->htb_ceil_bonus_divide=0;   relative bonus: new_ceil=old_ceil+old_ceil/htb_ceil_bonus_divide
*/
   keyword->default_prio=1;
   keyword->html_color="000000";
   keyword->ip_count=0;
   keyword->leaf_discipline="";

   push(keyword,keywords);
   if(!defaultkeyword) defaultkeyword=keyword;
   keywordcount++;
   
   kwd=NULL;
  }
  else every(keyword,keywords)
  {
   int l=strlen(keyword->key);


   if(!strncmp(keyword->key,_,l) && strlen(_)>l+2)
   {
    char *tmptr=_; /*  <---- l+1 ----> */
    _+=l+1;        /*  via-prometheus-asymetry-ratio, etc. */
    ioption("asymetry-ratio",keyword->asymetry_ratio);
    ioption("asymetry-treshold",keyword->asymetry_fixed);
    ioption("magic-relative-limit",keyword->data_limit);
    ioption("magic-relative-prio",keyword->data_prio);
    loption("magic-fixed-limit",keyword->fixed_limit);
    loption("magic-fixed-prio",keyword->fixed_prio);
    ioption("htb-default-prio",keyword->default_prio);
    ioption("htb-rate-bonus",keyword->reserve_min);
    ioption("htb-ceil-malus",keyword->reserve_max);
/* obsolete:
    ioption("htb-ceil-divide",keyword->divide_max);
    ioption("htb-ceil-bonus-divide",keyword->htb_ceil_bonus_divide);
*/
    option("leaf-discipline",keyword->leaf_discipline);
    option("html-color",keyword->html_color);
    _=tmptr;
    
    if(keyword->data_limit || keyword->fixed_limit || 
       keyword->data_prio || keyword->fixed_prio)
        use_credit=1;
        

   }
  }

  option("tc",tc);
  option("iptables",iptables);
  option("iptables-save",iptablessave); /* new */
  option("iptables-restore",iptablesrestore); /* new */
  option("iptables-file",iptablesfile); /* new */
  option("hosts",hosts);
  option("lan-interface",lan);
  option("wan-interface",wan);
  option("lan-medium",lan_medium);
  option("wan-medium",wan_medium);
  lloption("wan-download",line);
  lloption("wan-upload",up);
  ioption("hall-of-fame-enable",hall_of_fame);
  option("hall-of-fame-title",title);
  option("hall-of-fame-filename",html);
  option("hall-of-fame-preview",preview);
  option("log-filename",cmdlog);
  option("credit-filename",credit);
  ioption("credit-enable",enable_credit);
  option("log-traffic-directory",log_dir);
  option("log-traffic-url-path",log_url);
  option("qos-free-zone",qos_free_zone);
  ioption("qos-free-delay",qos_free_delay);
  ioption("qos-proxy-enable",qos_proxy);
  option("qos-proxy-ip",proxy_ip);
  option("htb-leaf-discipline",qos_leaf);
  ioption("qos-proxy-port",proxy_port);
  ioption("free-rate",free_min);
  ioption("free-ceil",free_max);
  ioption("htb-burst",burst);
  ioption("htb-burst-main",burst_main);
  ioption("htb-burst-group",burst_group);
  ioption("htb-nesting-limit",max_nesting);
  ioption("htb-r2q",htb_r2q);
  ioption("magic-include-upload",include_upload);
  ioption("magic-priorities",magic_priorities);
  ioption("magic-treshold",magic_treshold);
  
  option("filter-type", cnf);
  
/* not yet implemented:
  ioption("magic-fixed-packets",fixed_packets);
  ioption("magic-relative-packets",packet_limit);
*/
 }