Пример #1
0
/*
 * Reads an HTTP request from stream (fd), and writes an HTTP response
 * containing:
 *
 *   1) If user requested an existing file, respond with the file
 *   2) If user requested a directory and index.html exists in the directory,
 *      send the index.html file.
 *   3) If user requested a directory and index.html doesn't exist, send a list
 *      of files in the directory with links to each.
 *   4) Send a 404 Not Found response.
 */
void handle_files_request(int fd) {
  struct http_request*request=http_request_parse(fd);
  char*fullpath,*fullfullpath;
  struct stat st;
  
  if(0==strcmp("GET",request->method)){
    fullpath=conc(server_files_directory,request->path);
    if(0==stat(fullpath,&st)){ // file/dir exists
      if(S_ISREG(st.st_mode)){ // is file
	http_send_file(fd,fullpath);
      }else if(S_ISDIR(st.st_mode)){ // is dir
	fullfullpath=conc(fullpath,"/index.html");
	if(0==stat(fullfullpath,&st)){ // has an index.html
	  http_send_file(fd,fullfullpath);
	}else{ // hasnt. list files
	  DIR*d=opendir(fullpath);
	  struct dirent*di;
	  http_start_response(fd,200);
	  http_send_header(fd,"Content-type","text/html");
	  http_end_headers(fd);
	  while(NULL!=(di=readdir(d)))
	    http_send_anchor(fd,di->d_name);
	}
	free(fullfullpath);
      }
    }else{ // doesnt exist. error 404
      http_start_response(fd,404);
      http_send_header(fd,"Content-type","text/html");
      http_end_headers(fd);
      http_send_string(fd,"<center><p>ERROR 404</p></center>");
    }
    free(fullpath);
  }
}
Пример #2
0
static void test(void)
{
 mps_arena_t arena;
 mps_pool_t pool;
 mps_thr_t thread;
 mps_root_t root;

 mps_fmt_t format;
 mps_chain_t chain;

 locell *a,*b,*c,*z;
 int i;

 alloclocomments = 0;
 allowlocopies = 0;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE),
      "create arena");

 die(mps_thread_reg(&thread, arena), "register thread");
 die(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread,
                         mps_stack_scan_ambig, stackpointer, 0),
     "create root");

 die(mps_fmt_create_A(&format, arena, &fmtLO), "create format");
 cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create");

 die(mmqa_pool_create_chain(&pool, arena, mps_class_amcz(), format, chain),
     "create pool");

 cdie(
  mps_ap_create(&ap, pool, mps_rank_exact()),
  "create ap");

 a = string_ch("Hello there");
 b = string_ch("Wibble wobble foo");
 c = string_ch("Ba ");

 for (i=0; i<10000; i++) {
  a = conc(string_ch("B"), a);
  c = conc(string_ch("Hello there"), string_ch(" folks!"));
  z = alloclo(ap, 0x4000);
 }

 mps_arena_park(arena);
 mps_ap_destroy(ap);
 mps_pool_destroy(pool);
 mps_chain_destroy(chain);
 mps_fmt_destroy(format);
 mps_root_destroy(root);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
Пример #3
0
Liste_Pts_INT2 cAppli_Ortho::CompConx
               (
                   Pt2di aGerm,
                   int aValSet
               )
{
     Liste_Pts_INT2 cc(2);
     Neighbourhood V4 = Neighbourhood::v4();




     ELISE_COPY
     (
         conc
         (
             aGerm,
             mImEtiqTmp.neigh_test_and_set
             (
                 V4,
                 mTImEtiqTmp.get(aGerm),
                 aValSet,
                 100
             )
         ),
         0,
         cc 
     );

     return cc;
}
Пример #4
0
int main(int argc, char *argv[])
{
    typedef PRISMS::PField<double*, double, 2> ScalarField2D;
    typedef PRISMS::Body<double*, 2> Body2D;
    
    double coord[2];
    double tmp[2];
    Body2D body;
    
    
    body.read_vtk("2D.vtk");
    
    ScalarField2D &conc = body.find_scalar_field("c");
    
    double incr = (body.mesh.max(0) - body.mesh.min(0))/100.0;
    coord[0] = body.mesh.min(0);
    coord[1] = 0.24;
    
    for( int i=0; i<100; i++)
    {
        std::cout << "x: " << coord[0] << " y: " << coord[1] << "  c: " << conc( coord) << std::endl;
        coord[0] += incr;
    }
    
    return 0;
}
Пример #5
0
nodo_lista *conc(nodo_lista *L1, nodo_lista *L2){	//PRE=(lista(L1) e lista(L2) sono corrette).
	if(!L1)											//se L1 è vuota, ritorno semplicemente L2
		return L2;
	else{											//altrimenti scorro L1 fino in fondo, al ritorno riattacco tutto
		L1->next=conc(L1->next, L2);				//fa un sacco di "riagganci" inutili
		return L1;
	}
}//POST=(detto c il puntatore restituito, allora lista(c)=lista(a)@lista(b)).
Пример #6
0
double cosmology::dM4rs_dMphys(double mvir0,double z0,double z1,double z2){
    if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){
        std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl;
        init_pe_rho_rdelta_phys_Zhao(mvir0,z0);
    }
    if(z0>z1 || z0>z2){
        std::cout<<"# z0 should be smaller than z1 and z2\n";
        return 0;
    }
    if(z2<z1){
        std::cout<<"# z1 should be smaller than z2\n";
        return 0;
    }
    /// Calculate the total mass evolution
    double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc);
    double Mvir2=gsl_spline_eval(mah_Zhao_spline,z2,mah_Zhao_acc);
    //mofz=(Mvir1+Mvir2)/2.;

    double Rvir1=rvir_from_mvir(Mvir1,z1);
    Rvir1=Rvir1/(1+z1);
    double Rvir2=rvir_from_mvir(Mvir2,z2);
    Rvir2=Rvir2/(1+z2);

    /// Calculate the pseudo-evolution component
    double Mpe=gsl_spline_eval_integ(pe_rho_rdelta_phys_Zhao_spline,Rvir2,Rvir1,pe_rho_rdelta_phys_Zhao_acc);
    //std::cout<<"DEBUG: "<<Mpe<<" "<<Mvir2-Mvir1<<std::endl;
    
    double dMphys=Mvir1-Mvir2-Mpe;

    // First calculate concentration of these halos
    double conc1=conc(Mvir1,z1);
    double conc2=conc(Mvir2,z2);

    double M4rs1=getM4rs(Mvir1,conc1);
    double M4rs2=getM4rs(Mvir2,conc2);

    double dM4rs=(M4rs1-M4rs2);
    //fprintf(stderr,"# Mvir1:%e Mvir2:%e Mpe:%e dMphys:%e M4rs1:%e M4rs2:%e dM4rs:%e\n",Mvir1,Mvir2,Mpe,dMphys,M4rs1,M4rs2,dM4rs);

    if(dM4rs<0)
        return -1.0;
    else
        return dM4rs/dMphys;
}
Пример #7
0
/// Radii are in physical units here, so be careful
void cosmology::modelNFWhalo(double m200,double z,double &Mvir, double &Rvir, double &cvir, double &R200, double &c200)
{
    Mvir=getMvir(m200,z);
    Rvir=getRvirfromMvir(Mvir, z)/(1.+z);

    double Delta=200.;
    R200=getRDelfromMDel(m200, z, Delta)/(1.+z);

    cvir=conc(Mvir,z);

    c200=getc200(cvir,z);

}
Пример #8
0
nodo_lista *f(nodo_albero *r, int y){				//PRE=(albero(r) corretto, albero(vr)=albero(r), y definito).
	if(!r)											//caso base: albero vuoto
		return 0;									//ritorno una lista vuota
	else{
		nodo_lista *L1=f(r->left, y);				//ottengo il risultato del sottoalbero sx
		nodo_lista *L2=f(r->right, y);				//ottengo il risultato del sottoalbero dx
		
		if(r->info==y)								//valutazione nodo corrente
			L2=new nodo_lista(r, L2);				//attacco in testa ad L2 il nodo corrente
		
		return conc(L1, L2);						//se volessi usare conc_rif dovrei sostituire questa riga con: conc_rif(L1, L2); return L1;
	}
}//POST=(ritorna una lista (corretta) di puntatori ai nodi di albero(r) che hanno campo info==y in ordine infisso, albero(r)==albero(vr) cioè non è stato modificato).
Пример #9
0
/// Radii are in comoving units here
void cosmology::modelNFWhalo_com(double m200,double z,double &Mvir, double &Rvir, double &cvir)
{
    Mvir=getMvir(m200,z);

    Rvir=0.169*pow(Mvir/1.e12,1./3.);
    Rvir*=pow(Delta_crit(z)/178.0,-1.0/3.0);
    Rvir*=pow(Eofz(z),-2./3.);

    cvir=conc(Mvir,z);

    Rvir=Rvir*(1.+z);

}
Пример #10
0
/// Radii are in physical units here, so be careful
void cosmology::modelNFWhalo(double m200,double z,double &Mvir, double &Rvir, double &cvir, double &R200, double &c200)
{
    Mvir=getMvir(m200,z);

    Rvir=0.169*pow(Mvir/1.e12,1./3.);
    Rvir*=pow(Delta_crit(z)/178.0,-1.0/3.0);
    Rvir*=pow(Eofz(z),-2./3.);

    double Delta=200.;
    R200=pow( 1.0e12/(4./3.*Delta*3e4*0.3/(8*gee)),1./3.);
    R200*=pow(m200/1.e12,1./3.);
    R200*=pow(Omega(z)/0.3,-1.0/3.0);
    R200*=pow(Eofz(z),-2./3.);

    cvir=conc(Mvir,z);

    c200=getc200(cvir,z);

}
Пример #11
0
/// Radii are in comoving units here
void cosmology::modelNFWhalo_com(double m200,double z,double &Mvir, double &Rvir, double &cvir, double &R200, double &c200)
{
    Mvir=getMvir(m200,z);
    Rvir=getRvirfromMvir(Mvir, z);
    
    double Delta=200.;
    R200=getRDelfromMDel(m200, z, Delta);

    /*
    R200=pow( 1.0e12/(4./3.*Delta*3e4*0.3/(8*gee)),1./3.);
    R200*=pow(m200/1.e12,1./3.);
    R200*=pow(Omega(z)/0.3,-1.0/3.0);
    R200*=pow(Eofz(z),-2./3.);
    */

    cvir=conc(Mvir,z);
    c200=getc200(cvir,z);

}
Пример #12
0
void addBC(double *h, double *h0, double *h1, int nBC, int n, int nBCs, double *nh)
{ 
    //maybe an error in calculating G
    int j,k;


    double *hb = malloc(nBC*sizeof(double));
    double *he = malloc(nBC*sizeof(double));
    //ADD BC we get h,G need to solve for u then add in boundaries for G using u and h

    //front end
    //i keeps track of big array
    //j keeps track of small bc arrays
    //k keeps track of small new bc arrays
    j = nBCs-1;

    for(k = nBC -1; k > -1 ; k--)
    {
        hb[k] = h0[j];
        j--;
    }

    //back end
    j = 0;
    for(k = 0; k < nBC ; k++)
    {
        he[k] = h1[j];
        j++;

    }

    //bring them all together

    conc(hb,h,he,nBC,n,nBC,nh);

    free(hb);
    free(he);  

}
Пример #13
0
/// Radii are in comoving units here
void cosmology::modelNFWhalo_com_ext(double mDel,double z,double &Mvir,
double &Rvir, double &cvir, double &RDel, double &cDel,double Del)
{
    //std::cout<<Delta_crit(z)<<std::endl;exit(0);
    Mvir=getMvir(mDel,z,Del);

    Rvir=0.169*pow(Mvir/1.e12,1./3.);
    Rvir*=pow(Delta_crit(z)/178.0,-1.0/3.0);
    Rvir*=pow(Eofz(z),-2./3.);

    double Delta=Del;
    RDel=pow( 1.0e12/(4./3.*Delta*3e4*0.3/(8*gee)),1./3.);
    RDel*=pow(mDel/1.e12,1./3.);
    RDel*=pow(Omega(z)/0.3,-1.0/3.0);
    RDel*=pow(Eofz(z),-2./3.);

    cvir=conc(Mvir,z);

    cDel=getcDel(cvir,z,Delta);

    Rvir=Rvir*(1.+z);
    RDel=RDel*(1.+z);

}
Пример #14
0
void FiltreRemoveBorderHeter(Im2D_REAL4 anIm,Im2D_U_INT1 aImMasq,double aCostRegul,double aCostTrans)
{
    Pt2di aSz = anIm.sz();
    double aVMax,aVMin;

    ELISE_COPY(aImMasq.border(1),0,aImMasq.out());
    ELISE_COPY(aImMasq.all_pts(),aImMasq.in()!=0,aImMasq.out());
    ELISE_COPY(anIm.all_pts(),anIm.in(),VMax(aVMax)|VMin(aVMin));
    Video_Win * aW = Video_Win::PtrWStd(aSz);
    ELISE_COPY(anIm.all_pts(),(anIm.in()-aVMin) * (255.0/(aVMax-aVMin)),aW->ogray());
    std::cout << "VMAX " << aVMax << "\n";

    //ELISE_COPY(aW->all_pts(),aImMasq.in(),aW->odisc());
    //aW->clik_in();

    ELISE_COPY
    (
          aW->all_pts(),
          nflag_close_sym(flag_front8(aImMasq.in_proj()!=0)),
          aW->out_graph(Line_St(aW->pdisc()(P8COL::red)))
    );

    cParamFiltreDepthByPrgDyn aParam =  StdGetFromSI(Basic_XML_MM_File("DefFiltrPrgDyn.xml"),ParamFiltreDepthByPrgDyn);
    aParam.CostTrans() = aCostTrans;
    aParam.CostRegul() = aCostRegul;

    Im2D_Bits<1>  aNewMasq =  FiltrageDepthByProgDyn(anIm,aImMasq,aParam);
  
    ELISE_COPY
    (
         select(aNewMasq.all_pts(),aNewMasq.in()),
         2,
         aImMasq.out()
    );
    TIm2D<U_INT1,INT> aTMasq(aImMasq);
    FiltrageCardCC(false,aTMasq,2,0,100);

    Neighbourhood aNV4=Neighbourhood::v4();
    Neigh_Rel     aNrV4 (aNV4);

    ELISE_COPY
    (
           conc
           (
               select(select(aImMasq.all_pts(),aImMasq.in()==1),aNrV4.red_sum(aImMasq.in()==0)),
               aImMasq.neigh_test_and_set(aNV4,1,0,256)
           ),
           3,
           Output::onul()
    );



    ELISE_COPY
    (
         aNewMasq.all_pts(),
         aImMasq.in(),
         aW->odisc()
    );

/*
    ELISE_COPY
    (
          aW->all_pts(),
          nflag_close_sym(flag_front8(aNewMasq.in_proj())),
          aW->out_graph(Line_St(aW->pdisc()(P8COL::green)))
    );
*/


    aW->clik_in();

}
Пример #15
0
void bench_im_rle(Pt2di sz,INT NbLabel,Pt2di SzBox,INT NbLissage)
{
    typedef EliseRle::tIm  tIm;
    bool  ModeV8 = NRrandom3() > 0.5;
    Im2D<tIm,INT> Im1(sz.x,sz.y);
    Im2D<tIm,INT> Im2(sz.x,sz.y);
    Im2D<tIm,INT> Im3(sz.x,sz.y);
    Im2D<tIm,INT> ImOri(sz.x,sz.y);

    Im2D<tIm,INT> ImBox1(sz.x,sz.y,0);
    Im2D<tIm,INT> ImBox2(sz.x,sz.y,0);

    Fonc_Num f = Iconv(frandr()*20*NbLabel)%NbLabel;
    for (INT k=0 ; k<NbLissage ; k++)
        f = label_maj(f,NbLabel,Pt2di(5,5));


    ELISE_COPY(Im1.all_pts() , f-2, Im1.out()|Im2.out()|Im3.out()|ImOri.out() );
    ELISE_COPY(Im1.border(1) , 0  , Im1.out()|Im2.out()|Im3.out()|ImOri.out() );


    tIm ** data1 = Im1.data();
    tIm ** data2 = Im2.data();


    Neighbourhood V8 = Neighbourhood::v8();     
    Neighbourhood V4 = Neighbourhood::v4();     

    U_INT1 ColBig = NbLabel * 2 +1;
    EliseRle::tContainer  Rles;

    INT cptSmall1 =0; 
    INT cptSmall2 =0; 
    INT cptBig1 =0; 
    INT cptBig2 =0; 
    ELISE_COPY(select(Im1.all_pts(),Im1.in()<0),0,Im1.out());

    BenchConc aBc(NbLabel,false);
    BenchConc * aBcPtr = &aBc;

    if (NRrandom3() >0.5)
        aBcPtr = new BenchConc(NbLabel,true);

    ELISE_COPY
    (
         Im3.all_pts(),
         BoxedConc(Im3.in(0),SzBox,ModeV8,aBcPtr,(INT)(9+SzBox.y*2.9*NRrandom3())),
         Im3.out()
    );


    for (INT y=0; y<sz.y ; y++)
    {
       for (INT x=0; x<sz.x ; x++)
       {
           tIm v1 = data1[y][x];
           Neighbourhood V = ModeV8 ? V8 : V4;
           Liste_Pts_INT2 l2(2);
           if ((v1 >0) && (v1<=NbLabel))
           {
               Pt2di p0,p1;
               ELISE_COPY
               (
                   conc
                   (
                      Pt2di(x,y),
                      Im1.neigh_test_and_set (V,v1,ColBig,ColBig+1)
                   ),
                   Virgule(FX,FY),
                   (l2|p0.VMin()|p1.VMax())
              );
              p1 += Pt2di(1,1);

              if ((p1.x-p0.x<=SzBox.x) && (p1.y-p0.y<=SzBox.y))
              {
                 cptSmall1++;
                 ELISE_COPY(l2.all_pts(),v1+NbLabel,Im1.out());
              }
              else
              {
                 cptBig1++;
              }
              ELISE_COPY(rectangle(p0,p1),(ImBox1.in()+v1)%256,ImBox1.out());
           }

           tIm v2 = data2[y][x];
           if ((v2 >0) && (v2<=NbLabel))
           {
                Box2di Box =  EliseRle::ConcIfInBox
                              (
                                   Pt2di(x,y),
                                   Rles,
                                   data2,
                                   v2,ColBig,
                                   ModeV8,
                                   SzBox
                              );
                if (! Rles.empty())
                {
                   cptSmall2++;
                   EliseRle::SetIm(Rles,data2, v2+NbLabel);
                }
                else
                {
                   cptBig2++;
                }
                ELISE_COPY
                (
                    rectangle(Box._p0,Box._p1),
                    (ImBox2.in()+v2)%256,
                    ImBox2.out()
                );
           }
       }
    }
    ELISE_COPY(select(Im1.all_pts(),ImOri.in()<0),ImOri.in(),Im1.out());

    BENCH_ASSERT(cptSmall2 == cptSmall1);
    BENCH_ASSERT(cptBig2 == cptBig1);
    INT Dif1;
    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(Im1.in()-Im2.in()),
       VMax(Dif1)
    );
    BENCH_ASSERT(Dif1==0);
    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(ImBox1.in()-ImBox2.in()),
       VMax(Dif1)
    );
    BENCH_ASSERT(Dif1==0);


    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(Im1.in()-Im3.in()),
       VMax(Dif1)
    );
    
    BENCH_ASSERT(Dif1==0);
}
Пример #16
0
void evolveBC(double *G, double *h, double *h0, double *h1, double *u0, double *u1, double g, double dx, double dt, int nBC, int n, int nBCs,double *nG, double *nh, double *nu)
{ 
    //maybe an error in calculating G
    double idx = 1.0 / dx;
    double ithree = 1.0 / 3.0;
    int j = nBCs -1;


    double *Gb = malloc(nBC*sizeof(double));
    double *Ge = malloc(nBC*sizeof(double));
    double *ub = malloc(nBC*sizeof(double));
    double *ue = malloc(nBC*sizeof(double));
    double *hb = malloc(nBC*sizeof(double));
    double *he = malloc(nBC*sizeof(double));
    double *u = malloc(n*sizeof(double));
    //ADD BC we get h,G need to solve for u then add in boundaries for G using u and h
    getufromG(h,G, u0[j], u1[0], h0[j], h1[0],dx,n,u);

    //front end
    //i keeps track of big array
    //j keeps track of small bc arrays
    //k keeps track of small new bc arrays
    int i = -1;
    int k = nBC -1;
    j = nBCs -1;


    double hx = 0.5*idx*(h[i+1] - h0[j-1]);

    Gb[k] = (0.5*idx*h0[j]*h0[j]*hx - idx*idx*ithree*h0[j]*h0[j]*h0[j])*u0[j-1]
                    + (h0[j] + 2*ithree*idx*idx*h0[j]*h0[j]*h0[j])*u0[j]
                    + (-0.5*idx*h0[j]*h0[j]*hx - idx*idx*ithree*h0[j]*h0[j]*h0[j])*u[i+1];
    ub[k] = u0[j];
    hb[k] = h0[j];


    for(k = k-1; k > -1 ; k--)
    {
        j--;
        hx = 0.5*idx*(h0[j+1] - h0[j-1]);

        Gb[k] = (0.5*idx*h0[j]*h0[j]*hx - idx*idx*ithree*h0[j]*h0[j]*h0[j])*u0[j-1]
                    + (h0[j] + 2*ithree*idx*idx*h0[j]*h0[j]*h0[j])*u0[j]
                    + (-0.5*idx*h0[j]*h0[j]*hx - idx*idx*ithree*h0[j]*h0[j]*h0[j])*u0[j+1];

        ub[k] = u0[j];
        hb[k] = h0[j];
    }

    //back end
    i = n;
    k = 0;
    j = 0;

    hx = 0.5*idx*(h1[j+1] - h[i-1]);

    Ge[k] = (0.5*idx*h1[j]*h1[j]*hx - idx*idx*ithree*h1[j]*h1[j]*h1[j])*u[i-1]
            + (h1[j] + 2*ithree*idx*idx*h1[j]*h1[j]*h1[j])*u1[j]
            + (-0.5*idx*h1[j]*h1[j]*hx - idx*idx*ithree*h1[j]*h1[j]*h1[j])*u1[j+1];

    ue[k] = u1[j];
    he[k] = h1[j];

    for(k = k+1; k < nBC ; k++)
    {
        j++;
        hx = 0.5*idx*(h1[j+1] - h1[j-1]);

        Ge[k] = (0.5*idx*h1[j]*h1[j]*hx - idx*idx*ithree*h1[j]*h1[j]*h1[j])*u1[j-1]
                    + (h1[j] + 2*ithree*idx*idx*h1[j]*h1[j]*h1[j])*u1[j]
                    + (-0.5*idx*h1[j]*h1[j]*hx - idx*idx*ithree*h1[j]*h1[j]*h1[j])*u1[j+1];
        ue[k] = u1[j];
        he[k] = h1[j];

    }

    //bring them all together

    conc(Gb,G,Ge,nBC,n,nBC,nG);
    conc(hb,h,he,nBC,n,nBC,nh);
    conc(ub,u,ue,nBC,n,nBC,nu);

    free(Gb);
    free(Ge);
    free(hb);
    free(he);
    free(ub);
    free(ue);
    free(u);    

}
Пример #17
0
void bench_flag_front (Pt2di   sz,bool FN)
{
    Neighbourhood V4 = Neighbourhood::v4();
    Neighbourhood V8 = Neighbourhood::v8();

    Im2D_U_INT1 Im(sz.x,sz.y,0);
    Liste_Pts_INT4 ListTrou(2);

    ELISE_COPY ( Im.all_pts(), frandr() > 0.5, Im.out() );

    ELISE_COPY(Im.border(2),0,Im.out());
    ELISE_COPY
    (
        select
        (
              select(Im.all_pts(),Im.in()),
              Neigh_Rel(V8).red_max(Im.in()) == 0
        ),
        2,
        ListTrou | Im.out() 
    );

    INT nbZ1 = 0;
    INT nbZ0 = -1;  // pour tenir compte de la zone externe
    {
          Im2D_U_INT1 ImZ(sz.x,sz.y); 
          ELISE_COPY(ImZ.all_pts(),Im.in()==1,ImZ.out());
          ELISE_COPY(ImZ.border(1),2,ImZ.out());
          U_INT1 ** z = ImZ.data();
          for (INT x=0 ; x<sz.x ; x++)
              for (INT y=0 ; y<sz.y ; y++)
                  if (z[y][x] != 2)
                  {
                      if (z[y][x] == 1) 
                         nbZ1 ++; 
                      else 
                         nbZ0++;
                      Neighbourhood  neigh = ((z[y][x] == 1) ? V8 : V4);
                      ELISE_COPY
                      (
                          conc(Pt2di(x,y),ImZ.neigh_test_and_set(neigh,z[y][x],2,10)),
                          2,
                          ImZ.out()
                      );
                  }
    }



    Im2D_U_INT1 IFront(sz.x,sz.y);
    ELISE_COPY
    (
       Im.all_pts(),
       flag_front8(Im.in(0)),
       IFront.out()
    );

    Im2D_U_INT1 check(sz.x,sz.y,0);

    ElFifo<Pt2di>   pts;
    WCEP wcep(check);

    if (FN)
    {
	ELISE_COPY
        (
	    Im.all_pts(),
            cont_vect (Im.in(),&wcep,true),
            Output::onul() 
        );

    }
    else
        explore_cyle(&wcep,pts,IFront);

    ELISE_COPY(ListTrou.all_pts(),check.in()+2,check.out());

    INT dif;
    ELISE_COPY(Im.all_pts(),Abs(Im.in()-check.in()),sigma(dif));

    BENCH_ASSERT(dif==0);
    BENCH_ASSERT(nbZ0 == wcep._nb_int);
    BENCH_ASSERT(nbZ1 == wcep._nb_ext);
    
}
Пример #18
0
void cAppli_Ortho::InitBoucheTrou(const Pt2di & aP,const cBoucheTrou  & aBT)
{
   Liste_Pts_INT2 aL = CompConx(aP,2);
   ELISE_COPY(aL.all_pts(),1,mImEtiqTmp.out());


   double aScoreMax = 1e-5;
   cLoadedIm * mBestLI = 0;
   // Im2D_INT2 aL.image();
   for (int aK=0 ; aK<int(mVLI.size()) ; aK++)
   {
        double aScore = ScoreOneHypBoucheTrou(aBT,aL,mVLI[aK]);
        if (aScoreMax<aScore)
        {
            aScoreMax = aScore;
            mBestLI = mVLI[aK];
        }
        // std::cout << "SCORE =" << aScore << "\n";
   }
   if (!mBestLI)
   {
       ELISE_COPY(aL.all_pts(),2,mImEtiqTmp.out());
       return;
   }

   ELISE_COPY
   (
        select
        (
             aL.all_pts(),
             (mBestLI->ImPCBrute().in() <= aBT.SeuilVisibBT().Val())
        ),
        2,
        mImEtiqTmp.out() | (mImIndex.out() << mBestLI->Ind()) 
        // | (mW->odisc() << P8COL::red)
    );


// Fermeture morphologique

   Liste_Pts_INT2 aLFront(2);
   Neighbourhood V4 = Neighbourhood::v4();
           // On dilate 3 fois de suite , a partir des point valant 2,
           // sur les points valante 1, on les colorie en 3
   ELISE_COPY
   (
        conc
        (
            select(aL.all_pts(),mImEtiqTmp.in()==2),
            mImEtiqTmp.neigh_test_and_set(V4,1,3,100),
            2
        ),
        0,
        aLFront
   );
      // On dilate dansl'autre sens (3 ->1) a partir des points ayant
      // au moins un voisin 1
   ELISE_COPY
   (
        conc
        (
            select
            (
                aLFront.all_pts(),
                Neigh_Rel(V4).red_sum(mImEtiqTmp.in()==1)
            ),
            mImEtiqTmp.neigh_test_and_set(V4,3,1,100),
            2
        ),
        0,
        Output::onul()
   );


   int aCpt;
   ELISE_COPY
   (
       select(aL.all_pts(),mImEtiqTmp.in()==3),
       Virgule(1,2, mBestLI->Ind()),
       Virgule(sigma(aCpt),mImEtiqTmp.out(),mImIndex.out())
   );

   // std::cout << "CPT = " << aCpt << "\n";





// getchar();

    Im2D_INT2 aIm = aL.image();
    int aNb = aIm.tx();
    INT2 * aTabX = aIm.data()[0];
    INT2 * aTabY = aIm.data()[1];
    for (int aK=0 ; aK<aNb ; aK++)
    {
        Pt2di aP(aTabX[aK],aTabY[aK]);
        if (mTImEtiqTmp.get(aP)==1)
           InitBoucheTrou(aP,aBT);
    }

}
Пример #19
0
void testConcat(std::string const & s0, std::string const & s1)
{
	uint64_t const l0 = s0.size();
	uint64_t const l1 = s1.size();

	for ( uint64_t bs = 1; bs <= 16; ++bs )
		for ( uint64_t b_0 = 0; b_0 <= l0; ++b_0 )
			for ( uint64_t b_1 = 0; b_1 <= l0-b_0; ++b_1 )
				for ( uint64_t c_0 = 0; c_0 <= l1; ++c_0 )
					for ( uint64_t c_1 = 0; c_1 <= l1-c_0; ++c_1 )
					{
						#if 0
						std::cerr 
							<< "b_0=" << b_0 << " b_1=" << b_1 << " "
							<< "c_0=" << c_0 << " c_1=" << c_1 << " "
							<< "bs=" << bs
							<< std::endl;
						#endif

						std::ostringstream o_0, o_1;
						libmaus2::lz::ZlibCompressorObjectFactory scompfact;
						libmaus2::lz::SimpleCompressedOutputStream<std::ostream> lzout_0(o_0,scompfact,bs);
						libmaus2::lz::SimpleCompressedOutputStream<std::ostream> lzout_1(o_1,scompfact,bs);
						
						// std::cerr << "encoding s_0" << std::endl;
						lzout_0.write(s0.c_str(),b_0);
						std::pair<uint64_t,uint64_t> start_0 = lzout_0.getOffset();
						lzout_0.write(s0.c_str()+b_0,b_1);
						std::pair<uint64_t,uint64_t> end_0 = lzout_0.getOffset();
						lzout_0.write(s0.c_str()+b_0+b_1,s0.size()-(b_0+b_1));
						lzout_0.flush();
						
						std::string const u0 = s0.substr(b_0,b_1);
						
						// std::cerr << "encoding s_1" << std::endl;
						lzout_1.write(s1.c_str(),c_0);
						std::pair<uint64_t,uint64_t> start_1 = lzout_1.getOffset();
						lzout_1.write(s1.c_str()+c_0,c_1);
						std::pair<uint64_t,uint64_t> end_1 = lzout_1.getOffset();
						lzout_1.write(s1.c_str()+c_0+c_1,s1.size()-(c_0+c_1));
						lzout_1.flush();

						std::string const u1 = s1.substr(c_0,c_1);
						std::string const u = u0+u1;
						
						std::istringstream i_0(o_0.str());
						libmaus2::lz::SimpleCompressedConcatInputStreamFragment<std::istream> frag_0(start_0,end_0,&i_0);
						std::istringstream i_1(o_1.str());
						libmaus2::lz::SimpleCompressedConcatInputStreamFragment<std::istream> frag_1(start_1,end_1,&i_1);
						
						std::vector<libmaus2::lz::SimpleCompressedConcatInputStreamFragment<std::istream> > frags;
						frags.push_back(frag_0);
						frags.push_back(frag_1);
						
						libmaus2::lz::ZlibDecompressorObjectFactory decompfact;
						libmaus2::lz::SimpleCompressedConcatInputStream<std::istream> conc(frags,decompfact);
						
						#if 0
						std::cerr << "expecting " << u << std::endl;
						std::cerr << "write     ";
						std::cerr.write(s0.c_str()+b_0,b_1);
						std::cerr.write(s1.c_str()+c_0,c_1);
						std::cerr << std::endl;
						
						std::cerr << "frags[0]=" 
							<< frags[0].low.first << ","
							<< frags[0].low.second << ","
							<< frags[0].high.first << ","
							<< frags[0].high.second << std::endl;
						std::cerr << "frags[1]=" 
							<< frags[1].low.first << ","
							<< frags[1].low.second << ","
							<< frags[1].high.first << ","
							<< frags[1].high.second << std::endl;
						#endif
						
						int c = -1;
						uint64_t j = 0;
						while ( (c = conc.get()) != -1 )
						{
							// std::cout.put(c);
							assert ( c == u[j++] );
						}
						assert ( j == u.size() );

						// std::cout.put('\n');
					}

}
Пример #20
0
void evolve(double *h,double *G, double *hblank,double *Gblank,double *bed,double g,double *u0,double *u1,double *h0,double *h1,double *b0,double *b1,double theta, int n, int nBC,double dx,double dt)
{
    
    //get averages
    double idx = 1.0 / dx;  

	double *u = malloc(n*sizeof(double));
	int i,j;
	int nBCn = 3;
    double th,hx,bx,bxx,D,ai,bi,ci,gb1,gb2,gb3,ge1,ge2,ge3;
    
    //calculate u at time step
	//getufromG(h,G,bed, u, u0[nBC - 1], u1[0], h0[nBC - 1], h1[0], b0[nBC - 1], b1[0], n,dx);
	// u seems to be the problem here
	getufromG(h,G,bed,u0[nBC - 1], u1[0], h0[nBC - 1], h1[0],b0[nBC - 1], b1[0],dx,n,u);
    
    //boundaries
    //beginning
    //i=-1
    i = -1;
    j = nBC-1;
    th = h0[j];
    hx = 0.5*idx*(h[i+1] - h0[j-1]);
    bx = 0.5*idx*(bed[i+1] - b0[j-1]);
    bxx =idx*idx*(bed[i+1] -2*b0[j] + b0[j-1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    gb3 = ai*u0[j-1] + bi*u0[j] +ci*u[i+1];
	//printf("uim1 : %f | ui : %f | uip1 : %f\n",u0[j-1],u0[j],u[i+1]);
	//printf("uip2 : %f | uip3 : %f | uip4 : %f\n",u[i+2],u[i+3], u[i+4]);
    
    //i=-2
    i = -2;
    j = nBC -2;
    th = h0[j];
    hx = 0.5*idx*(h0[j+1] - h0[j-1]);
    bx = 0.5*idx*(b0[j+1] - b0[j-1]);
    bxx = idx*idx*(b0[j+1] - 2*b0[j] + b0[j+1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    gb2 = ai*u0[j-1] + bi*u0[j] +ci*u0[j+1];
    
    //i=-3
    i = -3;
    j = nBC -3;
    th = h0[j];
    hx = 0.5*idx*(h0[j+1] - h0[j-1]);
    bx = 0.5*idx*(b0[j+1] - b0[j-1]);
    bxx = idx*idx*(b0[j+1] - 2*b0[j] + b0[j+1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    gb1 = ai*u0[j-1] + bi*u0[j] +ci*u0[j+1];
    
    //i = n
    i = n;
    j = 0;
    th = h1[j];
    hx = 0.5*idx*(h1[j+1] - h[i-1]);
    bx = 0.5*idx*(b1[j+1] - bed[i-1]);
    bxx = idx*idx*(b1[j+1] - 2*b1[j] + bed[i-1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    ge1 = ai*u[i-1] + bi*u1[j] + ci*u1[j+1];
    
    //i = n+1
    j = 1;
    th = h1[j];
    hx = 0.5*idx*(h1[j+1] - h1[j-1]);
    bx = 0.5*idx*(b1[j+1] - b1[j-1]);
    bxx = idx*idx*(b1[j+1] - 2*b1[j] + b1[j-1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    ge2 = ai*u1[j-1] + bi*u1[j] +ci*u1[j+1];
    
    //i = n+2    
    j = 2;
    th = h1[j];
    hx = 0.5*idx*(h1[j+1] - h1[j-1]);
    bx = 0.5*idx*(b1[j+1] - b1[j-1]);
    bxx = idx*idx*(b1[j+1] - 2*b1[j] + b1[j-1]);
    
    D = th + th*hx*bx + 0.5*th*th*bxx + th*bx*bx;
    
    ai = th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    bi = D + 2.0*i3*th*th*th*(idx*idx);
    ci = -1.0*th*th*hx*(0.5*idx) - i3*th*th*th*(idx*idx);
    
    ge3 = ai*u1[j-1] + bi*u1[j] +ci*u1[j+1];
    
    

    double *ubeg = malloc(nBCn*sizeof(double));
    double *uend = malloc(nBCn*sizeof(double));
    double *bbeg = malloc(nBCn*sizeof(double));
    double *bend = malloc(nBCn*sizeof(double));
    double *hbeg = malloc(nBCn*sizeof(double));
    double *hend = malloc(nBCn*sizeof(double));
    double *gbeg = malloc(nBCn*sizeof(double));
    double *gend = malloc(nBCn*sizeof(double));


	ubeg[0] = u0[1];
	ubeg[1] = u0[2];
	ubeg[2] = u0[3];

	hbeg[0] = h0[1];
	hbeg[1] = h0[2];
	hbeg[2] = h0[3];

	bbeg[0] = b0[1];
	bbeg[1] = b0[2];
	bbeg[2] = b0[3];

	uend[0] = u1[0];
	uend[1] = u1[1];
	uend[2] = u1[2];

	hend[0] = h1[0];
	hend[1] = h1[1];
	hend[2] = h1[2];

	bend[0] = b1[0];
	bend[1] = b1[1];
	bend[2] = b1[2];

    gbeg[0] = gb1;
    gbeg[1] = gb2;
    gbeg[2] = gb3;
    
    gend[0] = ge1;
    gend[1] = ge2;
    gend[2] = ge3;

	//printf("gb1 : %f | gb2 : %f | gb3 : %f \n",gb1,gb2,gb3);
	//printf("ge1 : %f | ge2 : %f | ge3 : %f \n",ge1,ge2,ge3);
    
    double *Gbc = malloc((n + 2*nBCn)*sizeof(double));
    double *hbc = malloc((n + 2*nBCn)*sizeof(double));
    double *ubc = malloc((n + 2*nBCn)*sizeof(double));
    double *bedbc = malloc((n + 2*nBCn)*sizeof(double));

    conc(gbeg,G,gend,nBCn,n,nBCn,Gbc);
    conc(hbeg,h,hend,nBCn,n,nBCn,hbc);
    conc(bbeg,bed,bend,nBCn,n,nBCn,bedbc);
    conc(ubeg,u,uend,nBCn,n,nBCn,ubc);
        
    //do normal stuff 

    double wi,wip1,wip2,wip3,wim1,wim2,dwib,dwif,dwim,dhib,dhif,dhim,dGib,dGif,dGim;
    double duib,duif,duim, dwi,dhi, dGi, dui;
    double hir,wir,Gir,uir,bir,hil,wil,Gil,uil,bil;  
        
    //i = 2
    i = nBCn -1;
    //define the stage
    wi = hbc[i] + bedbc[i];
    wip1 = hbc[i+1] + bedbc[i+1];
    wip2 = hbc[i+2] + bedbc[i+2];
    wip3 = hbc[i+3] + bedbc[i+3];
    wim1 = hbc[i-1] + bedbc[i-1];
    wim2 = hbc[i-2] + bedbc[i-2];
        
    //reconstruct common values first
        
    //i left and right
        
    //gradients
    dwib = (wi - wim1);
    dwif = (wip1 - wi);
    dwim = 0.5*(wip1 - wim1);
    dhib = (hbc[i] - hbc[i-1]);
    dhif = (hbc[i+1] - hbc[i]);
    dhim = 0.5*(hbc[i+1] - hbc[i-1]);
    dGib = (Gbc[i] - Gbc[i-1]);
    dGif = (Gbc[i+1] - Gbc[i]);
    dGim = 0.5*(Gbc[i+1] - Gbc[i-1]);
    duib = (ubc[i] - ubc[i-1]);
    duif = (ubc[i+1] - ubc[i]);
    duim = 0.5*(ubc[i+1] - ubc[i-1]);
        
    //limiting
    dwi = minmod(theta*dwib,theta*dwif,dwim);
    dhi = minmod(theta*dhib,theta*dhif,dhim);
    dGi = minmod(theta*dGib,theta*dGif,dGim);
    dui = minmod(theta*duib,theta*duif,duim);
      
    //reconstruct right
    hir = hbc[i]+ 0.5*dhi;
    wir = wi + 0.5*dwi;
    Gir = Gbc[i] + 0.5*dGi;
    uir = ubc[i] + 0.5*dui;
    bir = wir - hir;
        
    //reconstruct left
    hil = hbc[i] - 0.5*dhi;
    wil = wi - 0.5*dwi;
    Gil = Gbc[i] - 0.5*dGi;
    uil = ubc[i] - 0.5*dui;
    bil = wil - hil;
        
    //only left of i+1 common but do both

    double dwip1b,dwip1f,dwip1m,dhip1b,dhip1f,dhip1m,dGip1b,dGip1f,dGip1m;
    double duip1b,duip1f,duip1m, dwip1,dhip1, dGip1, duip1;
    double hip1r,wip1r,Gip1r,uip1r,bip1r,hip1l,wip1l,Gip1l,uip1l,bip1l; 
        
    //gradients
    dwip1b = (wip1 - wi);
    dwip1f = (wip2 - wip1);
    dwip1m = 0.5*(wip2 - wi);
    dhip1b = (hbc[i+1] - hbc[i]);
    dhip1f = (hbc[i+2] - hbc[i+1]);
    dhip1m = 0.5*(hbc[i+2] - hbc[i]);
    dGip1b = (Gbc[i+1] - Gbc[i]);
    dGip1f = (Gbc[i+2] - Gbc[i+1]);
    dGip1m = 0.5*(Gbc[i+2] - Gbc[i]);
    duip1b = (ubc[i+1] - ubc[i]);
    duip1f = (ubc[i+2] - ubc[i+1]);
    duip1m = 0.5*(ubc[i+2] - ubc[i]);
        
    //limiting
    dwip1 = minmod(theta*dwip1b,theta*dwip1f,dwip1m);
    dhip1 = minmod(theta*dhip1b,theta*dhip1f,dhip1m);
    dGip1 = minmod(theta*dGip1b,theta*dGip1f,dGip1m);
    duip1 = minmod(theta*duip1b,theta*duip1f,duip1m);
        
    //reconstruct right
    hip1r = hbc[i+1] + 0.5*dhip1;
    wip1r = wip1 + 0.5*dwip1;
    Gip1r = Gbc[i+1] + 0.5*dGip1;
    uip1r = ubc[i+1] + 0.5*duip1;
    bip1r = wip1r - hip1r;
        
    //reconstruct left
    hip1l = hbc[i+1] - 0.5*dhip1;
    wip1l = wip1 - 0.5*dwip1;
    Gip1l = Gbc[i+1] - 0.5*dGip1;
    uip1l = ubc[i+1] - 0.5*duip1;
    bip1l = wip1l - hip1l;
        
        
    //only right of i-1
    //i-1  right

    double dwim1b,dwim1f,dwim1m,dhim1b,dhim1f,dhim1m,dGim1b,dGim1f,dGim1m;
    double duim1b,duim1f,duim1m, dwim1,dhim1, dGim1, duim1;
    double him1r,wim1r,Gim1r,uim1r,bim1r,him1l,wim1l,Gim1l,uim1l,bim1l; 
        
    //gradients
    dwim1b = (wim1 - wim2);
    dwim1f = (wi - wim1);
    dwim1m = 0.5*(wi - wim2);
    dhim1b = (hbc[i-1] - hbc[i-2]);
    dhim1f = (hbc[i] - hbc[i-1]);
    dhim1m = 0.5*(hbc[i] - hbc[i-2]);
    dGim1b = (Gbc[i-1] - Gbc[i-2]);
    dGim1f = (Gbc[i] - Gbc[i-1]);
    dGim1m = 0.5*(Gbc[i] - Gbc[i-2]);
    duim1b = (ubc[i-1] - ubc[i-2]);
    duim1f = (ubc[i] - ubc[i-1]);
    duim1m = 0.5*(ubc[i] - ubc[i-2]);
        
    //limiting
    dwim1 = minmod(theta*dwim1b,theta*dwim1f,dwim1m);
    dhim1 = minmod(theta*dhim1b,theta*dhim1f,dhim1m);
    dGim1 = minmod(theta*dGim1b,theta*dGim1f,dGim1m);
    duim1 = minmod(theta*duim1b,theta*duim1f,duim1m);
        
    //reconstruct right
    him1r = hbc[i-1] + 0.5*dhim1;
    wim1r = wim1 + 0.5*dwim1;
    Gim1r = Gbc[i-1] + 0.5*dGim1;
    uim1r = ubc[i-1] + 0.5*duim1;
    bim1r = wim1r - him1r;
        
    //reconstruct i+2 left
    double dwip2b,dwip2f,dwip2m,dhip2b,dhip2f,dhip2m,dGip2b,dGip2f,dGip2m;
    double duip2b,duip2f,duip2m,dwip2,dhip2, dGip2, duip2;
    double hip2r,wip2r,Gip2r,uip2r,bip2r,hip2l,wip2l,Gip2l,uip2l,bip2l; 
    
    //gradients
    dwip2b = (wip2 - wip1);
    dwip2f = (wip3 - wip2);
    dwip2m = 0.5*(wip3 - wip1);
    dhip2b = (hbc[i+2] - hbc[i+1]);
    dhip2f = (hbc[i+3] - hbc[i+2]);
    dhip2m = 0.5*(hbc[i+3] - hbc[i+1]);
    dGip2b = (Gbc[i+2] - Gbc[i+1]);
    dGip2f = (Gbc[i+3] - Gbc[i+2]);
    dGip2m = 0.5*(Gbc[i+3] - Gbc[i+1]);
    duip2b = (ubc[i+2] - ubc[i+1]);
    duip2f = (ubc[i+3] - ubc[i+2]);
    duip2m = 0.5*(ubc[i+3] - ubc[i+1]);
        
    //limiting
    dwip2 = minmod(theta*dwip2b,theta*dwip2f,dwip2m);
    dhip2 = minmod(theta*dhip2b,theta*dhip2f,dhip2m);
    dGip2 = minmod(theta*dGip2b,theta*dGip2f,dGip2m);
    duip2 = minmod(theta*duip2b,theta*duip2f,duip2m);
                
    //reconstruct left
    hip2l = hbc[i+2] - 0.5*dhip2;
    wip2l = wip2 - 0.5*dwip2;
    Gip2l = Gbc[i+2] - 0.5*dGip2;
    uip2l = ubc[i+2] - 0.5*duip2;
    bip2l = wip2l - hip2l;
    
    //calculate forces          
    double nbi,hihm,hihp,her,Ger,uer,hel,Gel,uel, himhp; 
    double duer,duel,dber,dbel,sqrtghel,sqrtgher,sl,sr,felh,felG,ferh,ferG,isrmsl;   
    double foh,foG,fih,fiG;
        
    //right force i
    nbi = fmax(bip1l,bir);
    hihm = fmax(0,wir-nbi);
    hihp = fmax(0,wip1l-nbi);

    her = hihp;
    Ger = Gip1l;
    uer = uip1l;
        
    hel = hihm;
    Gel = Gir;
    uel = uir;

	//do u like o2fix
	double ue = 0.5*(ubc[i+1]+ubc[i]);
	double due = idx*(ubc[i+1] - ubc[i]);

	double dbe = idx*(bedbc[i+1] - bedbc[i]);

	uer = ue;
	uel = ue;
	duer = due;
	duel = due;
	dber = dbe;
	dbel = dbe;

        
    //duer = idx*(uip2l - uip1l);
    dber = idx*(bip2l - bip1l);
            
    //duel = idx*(uir - uim1r);
    dbel = idx*(bir - bim1r);
        
    sqrtghel = sqrt(g*hel);
    sqrtgher = sqrt(g*her);
    sl = fmin(0, fmin(uel - sqrtghel, uer - sqrtgher));
    sr = fmax(0,fmax(uel + sqrtghel, uer + sqrtgher));
        
    felh = uel*hel;
    felG = Gel*uel + 0.5*g*hel*hel - 2*i3*hel*hel*hel*duel*duel + hel*hel*uel*duel*dbel;
    ferh = uer*her;
    ferG = Ger*uer + 0.5*g*her*her - 2*i3*her*her*her*duer*duer + her*her*uer*duer*dber;

	//printf("%d || hihm - hir : %e || hihp - wip1l : %e\n", i, hihm - hir,hihp - wip1l);
  
    isrmsl = 0.0;

    if(sr != sl) isrmsl = 1.0 / (sr - sl);

    foh = isrmsl*(sr*felh - sl*ferh + sl*sr*(her - hel ));
    foG = isrmsl*(sr*felG - sl*ferG + sl*sr*(Ger - Gel ));
    
    fih = foh;
    fiG = foG;
    himhp = hihp;
        
    him1r = hir;
    wim1r = wir;
    bim1r = bir;
    Gim1r = Gir;
    uim1r = uir;
        
    hil = hip1l;
    wil = wip1l;
    bil = bip1l;
    Gil = Gip1l;
    uil = uip1l;
        
    hir = hip1r;
    wir = wip1r;
    bir = bip1r;
    Gir = Gip1r;
    uir = uip1r;
    
    hip1l = hip2l;
    wip1l = wip2l;
    bip1l = bip2l;
    Gip1l = Gip2l;
    uip1l = uip2l;      
    
    dhip1 = dhip2;
    dwip1 = dwip2;
    duip1 = duip2;
    dGip1 = dGip2;
    
	for(i = nBCn; i < n + nBCn; i++)
    {
        //update both forces at same time

        //define the stage
        wi = hbc[i] + bedbc[i];
        wip1 = hbc[i+1]  + bedbc[i+1];
        wip2 = hbc[i+2]  + bedbc[i+2];
        wip3 = hbc[i+3] + bedbc[i+3];
        wim1 = hbc[i-1]  + bedbc[i-1];
        wim2 = hbc[i-2]  + bedbc[i-2];
        
        //reconstruct common values first
                
        //only left of i+1 common but do both   
        
        //reconstruct right
        hip1r = hbc[i+1] + 0.5*dhip1;
        wip1r = wip1 + 0.5*dwip1;
        Gip1r = Gbc[i+1] + 0.5*dGip1;
        uip1r = ubc[i+1] + 0.5*duip1;
        bip1r = wip1r - hip1r;
        
        
        //reconstruct i+2 left
        
        //gradients
        dwip2b = (wip2 - wip1);
        dwip2f = (wip3 - wip2);
        dwip2m = 0.5*(wip3 - wip1);
        dhip2b = (hbc[i+2] - hbc[i+1]);
        dhip2f = (hbc[i+3] - hbc[i+2]);
        dhip2m = 0.5*(hbc[i+3] - hbc[i+1]);
        dGip2b = (Gbc[i+2] - Gbc[i+1]);
        dGip2f = (Gbc[i+3] - Gbc[i+2]);
        dGip2m = 0.5*(Gbc[i+3] - Gbc[i+1]);
        duip2b = (ubc[i+2] - ubc[i+1]);
        duip2f = (ubc[i+3] - ubc[i+2]);
        duip2m = 0.5*(ubc[i+3] - ubc[i+1]);
        
        //limiting
        dwip2 = minmod(theta*dwip2b,theta*dwip2f,dwip2m);
        dhip2 = minmod(theta*dhip2b,theta*dhip2f,dhip2m);
        dGip2 = minmod(theta*dGip2b,theta*dGip2f,dGip2m);
        duip2 = minmod(theta*duip2b,theta*duip2f,duip2m);
                
        //reconstruct left
        hip2l = hbc[i+2] - 0.5*dhip2;
        wip2l = wip2 - 0.5*dwip2;
        Gip2l = Gbc[i+2] - 0.5*dGip2;
        uip2l = ubc[i+2] - 0.5*duip2;
        bip2l = wip2l - hip2l;


                
        //calculate forces              
        
        //right force i
        nbi = fmax(bip1l,bir);
        hihm = fmax(0.0,wir-nbi);
        hihp = fmax(0.0,wip1l-nbi);

		//printf("%d || hihm - hir : %e || hihp - wip1l : %e\n", i, hihm - hir,hihp - wip1l);

        her = hihp;
        Ger = Gip1l;
        uer = uip1l;
        
        hel = hihm;
        Gel = Gir;
        uel = uir;
        
        duer = idx*(uip2l - uip1l);
        dber = idx*(bip2l - bip1l);

            
        duel = idx*(uir - uim1r);
        dbel = idx*(bir - bim1r);

		ue = 0.5*(ubc[i+1]+ubc[i]);
		due = idx*(ubc[i+1] - ubc[i]);

		dbe = idx*(bedbc[i+1] - bedbc[i]);

		uer = ue;
		uel = ue;
		duer = due;
		duel = due;
		dber = dbe;
		dbel = dbe;
        
        sqrtghel = sqrt(g*hel);
        sqrtgher = sqrt(g*her);
        sl = fmin(0,fmin(uel - sqrtghel, uer - sqrtgher));
        sr = fmax(0,fmax(uel + sqrtghel, uer + sqrtgher));
        
        felh = uel*hel;
        felG = Gel*uel + 0.5*g*hel*hel - 2*i3*hel*hel*hel*duel*duel + hel*hel*uel*duel*dbel;
        ferh = uer*her;
        ferG = Ger*uer + 0.5*g*her*her - 2*i3*her*her*her*duer*duer + her*her*uer*duer*dber;

        isrmsl = 0.0;

        if(sr != sl) isrmsl = 1.0 / (sr - sl);
        foh = isrmsl*(sr*felh - sl*ferh + sl*sr*(her - hel ));
        foG = isrmsl*(sr*felG - sl*ferG + sl*sr*(Ger - Gel ));
        
        double th,tu,tux,tbx,tbxx, sourcer, sourcec, sourcel;
        //calculate the source term
        th = hbc[i];
        tu = ubc[i];
        tux = 0.5*idx*(ubc[i+1] - ubc[i-1]);
        tbx = 0.5*idx*(bedbc[i+1] - bedbc[i-1]);
        tbxx = idx*idx*(bedbc[i+1] - 2*bedbc[i] + bedbc[i-1]);
        
        sourcer = g*0.5*(hihm*hihm - hir*hir);
        sourcec = g*th*tbx +  0.5*th*th*tu*tux*tbxx - th*tu*tu*tbx*tbxx ;
        sourcel = g*0.5*(hil*hil - himhp*himhp);

		//printf("%d | Source: %e\n",i, dt*idx*(sourcer+sourcel + sourcec));
        
        hblank[i-nBCn] = hbc[i] - dt*idx*(foh - fih);
        Gblank[i-nBCn] = Gbc[i] - dt*idx*(foG - fiG) + dt*idx*(sourcer+sourcel + sourcec);
        
        fih = foh;
        fiG = foG;
        himhp = hihp;
        
        him1r = hir;
        wim1r = wir;
        bim1r = bir;
        Gim1r = Gir;
        uim1r = uir;
        
        hil = hip1l;
        wil = wip1l;
        bil = bip1l;
        Gil = Gip1l;
        uil = uip1l;
        
        hir = hip1r;
        wir = wip1r;
        bir = bip1r;
        Gir = Gip1r;
        uir = uip1r;
    
        hip1l = hip2l;
        wip1l = wip2l;
        bip1l = bip2l;
        Gip1l = Gip2l;
        uip1l = uip2l;      
        
    
        dhip1 = dhip2;
        dwip1 = dwip2;
        duip1 = duip2;
        dGip1 = dGip2;
    }
        
    free(u);
    free(ubeg);
    free(uend);
    free(bbeg);
    free(bend);
    free(hbeg);
    free(hend);
    free(gbeg);
    free(gend);
    free(Gbc);
    free(hbc);
    free(ubc);
    free(bedbc);

}
Пример #21
0
static void test(void) {
 mps_arena_t arena;
 mps_pool_t pool;
 mps_thr_t thread;
 mps_root_t root;

 mps_fmt_t format;

 locell *a;
 int i;

 alloclocomments = 0;
 allowlocopies = 0;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena");

 cdie(mps_thread_reg(&thread, arena), "register thread");

 cdie(
  mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread,
   mps_stack_scan_ambig, stackpointer, 0),
  "create root");

 cdie(
  mps_fmt_create_A(&format, arena, &fmtLO),
  "create format");

 cdie(
  mps_pool_create(&pool, arena, mps_class_lo(), format),
  "create pool");

 cdie(
  mps_ap_create(&ap, pool, mps_rank_exact()),
  "create ap");

 a = string_ch("Hello there");
 (void)string_ch("Wibble wobble foo");
 (void)string_ch("Ba ");

 for (i=0; i<10000; i++) {
  a = conc(string_ch("B"), a);
  (void)conc(string_ch("Hello there"), string_ch(" folks!"));
 }

 mps_arena_park(arena);
 mps_ap_destroy(ap);
 comment("Destroyed ap.");

 mps_pool_destroy(pool);
 comment("Destroyed pool.");

 mps_fmt_destroy(format);
 comment("Destroyed format.");

 mps_root_destroy(root);
 comment("Destroyed root.");

 mps_thread_dereg(thread);
 comment("Deregistered thread.");

 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
Пример #22
0
void bench_front_to_surf
     (
          Flux_Pts   front_8,
          Flux_Pts   front_4,
          Flux_Pts   surf_with_fr,
          Flux_Pts   surf_without_fr,
          Fonc_Num   fcarac,
          bool       with_fc,
          bool       test_dil,
          Pt2di      sz
     )
{
     Im2D_U_INT1 i1(sz.x,sz.y,0);
     Im2D_U_INT1 i2(sz.x,sz.y,0);

     INT dif;
     if (with_fc)
     {
         ELISE_COPY(surf_without_fr,1,i1.out());
         ELISE_COPY(i2.all_pts(),fcarac,i2.out());

         ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));

          BENCH_ASSERT(dif == 0);
     }
     else
         ELISE_COPY(surf_without_fr,1,i1.out()|i2.out());

     Neighbourhood v4 (TAB_4_NEIGH,4);
     Neighbourhood v8 (TAB_8_NEIGH,8);
     
     if (test_dil)
     {
         bench_fr_front_to_surf(front_8,i1,v4);

         bench_fr_front_to_surf(front_4,i2,v8);
     }


     ELISE_COPY(i1.all_pts(),1,i1.out());
     ELISE_COPY(i1.border(1),0,i1.out());
     ELISE_COPY(front_8,0,i1.out());
     ELISE_COPY(conc(Pt2di(1,1),sel_func(v4,i1.in()==1)),0,i1.out());

     ELISE_COPY(i2.all_pts(),0,i2.out());
     ELISE_COPY(surf_without_fr,1,i2.out());
     ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));
      
     BENCH_ASSERT(dif == 0);


     ELISE_COPY(i1.all_pts(),0,i1.out() | i2.out());

     ELISE_COPY(surf_with_fr   ,1,i1.out());
     ELISE_COPY(surf_without_fr,2,i1.histo());

     ELISE_COPY(surf_with_fr   ,3,i2.out());
     ELISE_COPY(front_8        ,1,i2.out());

     
     ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));

     BENCH_ASSERT(dif == 0);

}