示例#1
0
    //------------------------------------------------------------------------------
    void writeVTKFile( const std::string& baseName,
                       const unsigned     step ) const
    {
        // create file name with step number
        const std::string vtkFile =
            baseName + "." + base::io::leadingZeros( step ) + ".vtk";
        std::ofstream vtk( vtkFile.c_str() );
        base::io::vtk::LegacyWriter vtkWriter( vtk );
        vtkWriter.writeUnstructuredGrid( mesh_ );
        
        base::io::vtk::writePointData( vtkWriter, mesh_, current_, "current" );

        //{
        //    std::vector<typename Mesh::Node::VecDim> oldDisp;
        //    base::post::evaluateHistoryAtNodes<1>( mesh_, current_, oldDisp );
        //    vtkWriter.writePointData( oldDisp.begin(), oldDisp.end(), "disp2" );
        //
        //}

#if 0
        typedef mat::hypel::SpatialWrapper<Material> AuxMat;
        AuxMat auxMat( material_ );
        
        base::io::vtk::writeCellData(  vtkWriter, mesh_, current_, 
                                       boost::bind( ::cauchy<typename Mesh::Element,
                                                    typename Field::Element,
                                                    AuxMat>, //Material>,
                                                    _1, _2,
                                                    auxMat ), "sigma" );
        //material_ ), "sigma" );
#endif       
        vtk.close();
    }
示例#2
0
/// Initializes constraints and prepares data to be processed
Sivia::Sivia(Data &data, bool calcInner)
{
    //constraints to check to see if a trajectory belongs to a tube

    //c1=   gdot= d/dx(gi)(x,t)*f(x,t)+d/dt(gi)(x,t)>=0
    //c2=   gi(x,t)=0j
    //c3=   g(x,t)<=0

    Function g("g.txt");
    Function dg(g, Function::DIFF);                                     //  d/dx(gi)(x,t)

    Variable x(data.numVarF),t;                                         //we have x[] and t as variables for our fns

    // initialize auxMat and auxVector to the correct sizes and fill with zeros
    IntervalMatrix auxMat(data.numVarF+1, data.numVarF,Interval::ZERO);
    IntervalVector auxVector(data.numVarF+1,Interval::ZERO);

    //put 1 in the diagonal of auxMat
    for (int i=0; i<data.numVarF; i++){
        auxMat[i][i]=1;}

    auxVector[data.numVarF]=1;

    if (calcInner){         //for the inner approximation of the tube, we set a new function f and its correspondent constraints
        cout<<endl<<"Start inner approx calculation"<<endl;
        Function f=("f.txt");
        Function gdot(x,t,dg(x,t)*(auxMat*transpose(f(x,t))+auxVector));


        NumConstraint c3(g, EQ);                                           //LEQ means less or equal 0

        Array<Ctc> individualTubeConstraints;                               //put together the constraints in an array

        individualTubeConstraints.add(*new CtcHC4(Array<NumConstraint>(c3)));

        CtcUnion unionTubeConstraints(individualTubeConstraints);           //calculate the union

        Ctc3BCid tubeConstraints(unionTubeConstraints);                     //this contracts the whole union to its final form

        data.boxes.push_back(data.initialBox);                              //initialize the boxes

        do_Sivia(tubeConstraints, data, gdot, calcInner);

        print_results(data);
    }

    else{                       //for the outer approximation
        Function f("f.txt");
        Function gdot(x,t,dg(x,t)*(auxMat*transpose(f(x,t))+auxVector));
        //c1 & c2
        Array<NumConstraint> c1, c2;

        int numConstraints = data.g->expr().dim.max_index()+1;              //find how many gi we have

        for (int i = 0; i < numConstraints; ++i) {                          //create constraints based on the dimensions of g
            c1.add(*new NumConstraint(x,t,gdot(x,t)[i] >= 0));
            c2.add(*new NumConstraint(x,t,g(x,t)[i] = 0));
        }

        NumConstraint c3(g, LEQ);                                           //LEQ means less or equal 0

        Array<Ctc> individualTubeConstraints;                               //put together the constraints in an array

        for (int i=0;i<numConstraints ;i++) {
            individualTubeConstraints.add(*new CtcHC4(Array<NumConstraint>(c1[i],c2[i],c3)));}

        CtcUnion unionTubeConstraints(individualTubeConstraints);           //calculate the union

        Ctc3BCid tubeConstraints(unionTubeConstraints);                     //this contracts the whole union to its final form

        data.boxes.push_back(data.initialBox);                              //initialize the boxes

        do_Sivia(tubeConstraints, data, gdot, calcInner);
        if (!data.calcInner){
            print_results(data);
        }
    }
}