Exemple #1
0
void mc_config_tsec_carveout(u32 bom, u32 size1mb, int lock)
{
	MC(0x670) = 0x90000000;
	MC(0x674) = 1;
	if (lock)
		MC(0x678) = 1;
}
Exemple #2
0
int main(int argc, char **argv) {
    Sim *sim;
    Config *cfg;
    int rank, size, dims[3];
    MPI_Comm cart;
    int restart;

    m::ini(&argc, &argv);

    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &cart);

    MC(m::Comm_rank(cart, &rank));
    MC(m::Comm_size(cart, &size));
    msg_ini(rank);
    msg_print("mpi rank/size: %d/%d", rank, size);
    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, cfg));

    UC(sim_ini(cfg, cart, &sim));
    UC(conf_lookup_bool(cfg, "glb.restart", &restart));
    msg_print("read restart: %s", restart ? "YES" : "NO" );
    if (restart) UC(sim_strt(sim));
    else         UC(sim_gen(sim));
    UC(sim_fin(sim));

    UC(conf_fin(cfg));

    MC(m::Barrier(cart));
    m::fin();
    msg_print("end");
}
Exemple #3
0
void mc_enable_ahb_redirect()
{
	CLOCK(0x3A4) = CLOCK(0x3A4) & 0xFFF7FFFF | 0x80000;
	//MC(MC_IRAM_REG_CTRL) &= 0xFFFFFFFE;
	MC(MC_IRAM_BOM) = 0x40000000;
	MC(MC_IRAM_TOM) = 0x4003F000;
}
Exemple #4
0
int main(int argc, char **argv) {
    const char *arg;
    char **v;
    int rank, c, dims[3];
    const char delim[] = " \t";
    Config *cfg;
    MPI_Comm cart;
    
    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &cart);

    MC(m::Comm_rank(cart, &rank));
    msg_ini(rank);
    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, /**/ cfg));
    UC(coords_ini_conf(cart, cfg, /**/ &coords));
    UC(conf_lookup_string(cfg, "a", &arg));
    tok_ini(arg, delim, /**/ &c, &v);

    main3(c, v);

    tok_fin(c, v);
    UC(coords_fin(coords));
    UC(conf_fin(cfg));

    MC(m::Barrier(cart));
    m::fin();
}
Exemple #5
0
void mc_disable_ahb_redirect()
{
	MC(MC_IRAM_BOM) = 0xFFFFF000;
	MC(MC_IRAM_TOM) = 0;
	//Disable IRAM_CFG_WRITE_ACCESS (sticky).
	//MC(MC_IRAM_REG_CTRL) = MC(MC_IRAM_REG_CTRL) & 0xFFFFFFFE | 1;
	CLOCK(0x3A4) &= 0xFFF7FFFF;
}
Exemple #6
0
int main(int argc, char **argv) {
    int rank, size, dims[3];
    MPI_Comm cart;
    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &cart);

    MC(m::Comm_rank(cart, &rank));
    MC(m::Comm_size(cart, &size));
    msg_ini(rank);
    msg_print("mpi size: %d", size);
    main1();

    MC(m::Barrier(cart));
    m::fin();    
}
int main( )
{
  //& Quadratic equation : How do I generate a random quadratic equation?
  int nGen = 2;
  int nVar = 3;
  int len = 8;
  Equation eq = Equation::randomQuadraticEquation( nGen , nVar , len );
  cout << "Eq = " << eq << endl;
  
  
  //& Quadratic equation : How do I solve a quadratic equation using Monte-Carlo method?
  QuadEquationTranformationGraph MC( eq );
  int max_iter = 10000;
  for( int iter=0 ; iter<max_iter ; ++iter ) {
    MC.extend( );
    if( MC.solutionFound( ) ) {
      cout << "The trivial solution is found" << endl;
      cout << "Constructed part contains " << MC.getGraph( ).getVertices( ).size( ) << " vertices." << endl;
      break;
    }
    if( MC.isDone( ) ) {
      cout << "The graph is fully constructed" << endl;
      break;
    }
    if( iter==max_iter-1 )
      cout << "Solution is not found within " << max_iter << " iterations." << endl;
  }
  cout << "Final size = " << MC.getGraph( ).getVertices( ).size( ) << " vertices." << endl;
  
  return 0;
}
Exemple #8
0
int OCCEdge::createArc(OCCVertex *start, OCCVertex *end, OCCStruct3d center) {
    try {
        gp_Pnt aP1(start->X(), start->Y(), start->Z());
        gp_Pnt aP2(center.x, center.y, center.z);
        gp_Pnt aP3(end->X(), end->Y(), end->Z());
        
        Standard_Real Radius = aP1.Distance(aP2);
        gce_MakeCirc MC(aP2,gce_MakePln(aP1, aP2, aP3).Value(), Radius);
        const gp_Circ& Circ = MC.Value();
        
        Standard_Real Alpha1 = ElCLib::Parameter(Circ, aP1);
        Standard_Real Alpha2 = ElCLib::Parameter(Circ, aP3);
        Handle(Geom_Circle) C = new Geom_Circle(Circ);
        Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false);
        
        this->setShape(BRepBuilderAPI_MakeEdge(arc, start->vertex, end->vertex));
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create arc");
        }
        return 0;
    }
    return 1;
}
Exemple #9
0
static B setparm(C*v,C*ms,HParamBlockRec mp){I n;
 n=strlen(v);
 ASSERT(n<=NPATH,EVLIMIT); *ms=n; MC(1+ms,v,n);
 mp.fileParam.ioNamePtr=ms;
 mp.fileParam.ioVRefNum=0;
 mp.fileParam.ioDirID  =0;
 R 1;
}
Exemple #10
0
static A jtrdns(J jt,F f){A za,z;I n;size_t r,tr=0;
 GA(za,LIT,n=1024,1,0); clearerr(f);
 while(!feof(f) && (r=fread(CAV(za)+tr,sizeof(C),n-tr,f))){
  tr+=r; if(tr==(U)n){RZ(za=ext(0,za));n*=2;}
 }
 if(tr==(U)n)z=za;
 else {GA(z,LIT,tr,1,0); MC(CAV(z),CAV(za),tr);}
 R z;
}    /* read entire file stream (non-seekable) */
Exemple #11
0
F1(bool){A b,h;I j,*v;
 RZ(w);
 if(VERB&AT(w))R ADERIV(CBOOL, basis1,0L, 0L,0L,0L);
 RZ(w=vi(w));
 v=AV(w);
 DO(AN(w), j=*v++; ASSERT(-16<=j&&j<16,EVINDEX));
 GA(b,BOOL,64,2,0); *AS(b)=16; *(1+AS(b))=4; MC(AV(b),booltab,64L);
 RZ(h=cant2(apv(AR(w),0L,1L),from(w,b)));
 R fdef(CBOOL,VERB, bool1,bool2, w,0L,h, 0L, RMAXL,0L,0L);
}
Exemple #12
0
static A jtmakename(J jt,C*s){A z;I m;NM*zv;
 m=strlen(s);
 GATV(z,NAME,m,1,0); zv=NAV(z);  // Use GATV because GA doesn't support NAME type
 MC(zv->s,s,m); *(m+zv->s)=0;
 zv->m   =(UC)m; 
 zv->bucket=zv->bucketx=0;
 zv->flag=NMDOT;
 zv->hash=nmhash(m,s);
 ACX(z);
 R z;
}
Exemple #13
0
static DF1(reduce){PROLOG;DECLF;A y,z;C*u,*v;I c,k,m,old,t;
 RZ(w);
 m=IC(w);
 if(!m)R df1(w,iden(fs));
 RZ(z=tail(w));
 if(1==m)R z;
 t=AT(w); c=AN(z);
 GA(y,t,c,AR(z),AS(z)); u=CAV(y); k=SZT(t,c); v=CAV(w)+k*(m-1);
 old=tbase+ttop;
 DO(m-1, MC(u,v-=k,k); RZ(z=f2(y,z,fs)); gc(z,old));
 EPILOG(z);
}
Exemple #14
0
static F1(lparen) {
    A z;
    C*v;
    I n;
    RZ(w);
    n=AN(w);
    GA(z,CHAR,2+n,1,0);
    v=CAV(z);
    *v='(';
    *(v+n+1)=')';
    MC(1+v,AV(w),n);
    R z;
}
Exemple #15
0
int main(int argc, char **argv) {
    const char *path;
    Config *cfg;
    int rank, dims[3];
    MPI_Comm comm;

    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &comm);

    MC(m::Comm_rank(comm, &rank));
    msg_ini(rank);

    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, cfg));
    UC(conf_lookup_string(cfg, "o", &path));
    main0(comm, path);

    UC(conf_fin(cfg));
    MC(m::Barrier(comm));
    m::fin();
}
Exemple #16
0
int main(int argc, char **argv) {
    const char *i;
    Out out;
    Config *cfg;
    int rank, size, dims[3];
    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &out.comm);

    MC(m::Comm_rank(out.comm, &rank));
    MC(m::Comm_size(out.comm, &size));

    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, cfg));
    UC(conf_lookup_string(cfg, "i", &i));
    UC(conf_lookup_string(cfg, "o", &out.path));

    main0(i, &out);

    UC(conf_fin(cfg));
    MC(m::Barrier(out.comm));
    m::fin();
}
Exemple #17
0
static FMTX(fmtD,D){B q;C buf[1+WD],c,*t;D x=*v;I k=0;
 sprintf(buf,qpps,0==x&&1!=x?0:x);  /* 1!=x to handle NaN */
 c=*buf;
 if(c==CPMINUS)*s++=CSIGN;
 q=(c==CPMINUS)||(c==CPPLUS);
 c=buf[q];
 if(c==CPINF){*s++='_'; *s=0;}
 else if(c==CPNAN){if('-'!=*buf)*s++='_'; *s++='.'; *s=0;}
 else{
  if('.'==c)*s++='0';
  MC(s,buf+q,WD+1-q);
  if((t=strchr(s,'e'))){
   if(CPMINUS==*++t)*t++=CSIGN;
   while(c=*(k+t),c=='0'||c==CPPLUS)k++;
   if(k)while((*t=*(k+t)))t++;
}}}
Exemple #18
0
// Derived verb for f//. y
static DF1(jtobqfslash){A y,z;B b=0,p;C er,id,*wv;I c,d,k,m,m1,mn,n,n1,r,*s,wt;
 RZ(w);
 r=AR(w); s=AS(w); wt=AT(w); wv=CAV(w);
 if(!(AN(w)&&1<r&&DENSE&wt))R oblique(w,self);  // revert to default if rank<2, empty, or sparse
 y=VAV(self)->f; y=VAV(y)->f; id=vaid(y);
 m=s[0]; m1=m-1;
 n=s[1]; n1=n-1; mn=m*n; d=m+n-1; PROD(c,r-2,2+s);
 if(1==m||1==n){GA(z,wt,AN(w),r-1,1+s); *AS(z)=d; MC(AV(z),wv,AN(w)*bp(wt)); R z;}
 if(wt&FL+CMPX)NAN0;
 if(1==c)switch(OBQCASE(CTTZ(wt),id)){
  case OBQCASE(B01X, CNE     ): OBQLOOP(B,B,wt,x=*u, x^=*u        ); break;
  case OBQCASE(B01X, CEQ     ): OBQLOOP(B,B,wt,x=*u, x=x==*u      ); break;
  case OBQCASE(B01X, CMAX    ):
  case OBQCASE(B01X, CPLUSDOT): OBQLOOP(B,B,wt,x=*u, x|=*u        ); break;
  case OBQCASE(B01X, CMIN    ):
  case OBQCASE(B01X, CSTAR   ):
  case OBQCASE(B01X, CSTARDOT): OBQLOOP(B,B,wt,x=*u, x&=*u        ); break;
  case OBQCASE(B01X, CLT     ): OBQLOOP(B,B,wt,x=*u, x=*u< x      ); break;
  case OBQCASE(B01X, CLE     ): OBQLOOP(B,B,wt,x=*u, x=*u<=x      ); break;
  case OBQCASE(B01X, CGT     ): OBQLOOP(B,B,wt,x=*u, x=*u> x      ); break;
  case OBQCASE(B01X, CGE     ): OBQLOOP(B,B,wt,x=*u, x=*u>=x      ); break;
  case OBQCASE(B01X, CPLUS   ): OBQLOOP(B,I,INT,x=*u, x+=*u       ); break;
  case OBQCASE(SBTX, CMAX    ): OBQLOOP(SB,SB,wt,x=*u, x=SBGT(x,*u)?x:*u ); break;
  case OBQCASE(SBTX, CMIN    ): OBQLOOP(SB,SB,wt,x=*u, x=SBLT(x,*u)?x:*u ); break;
  case OBQCASE(FLX,  CMAX    ): OBQLOOP(D,D,wt,x=*u, x=MAX(x,*u)  ); break;
  case OBQCASE(FLX,  CMIN    ): OBQLOOP(D,D,wt,x=*u, x=MIN(x,*u)  ); break;
  case OBQCASE(FLX,  CPLUS   ): OBQLOOP(D,D,wt,x=*u, x+=*u        ); break;
  case OBQCASE(CMPXX,CPLUS   ): OBQLOOP(Z,Z,wt,x=*u, x=zplus(x,*u)); break;
  case OBQCASE(XNUMX,CMAX    ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)? x:*u); break;
  case OBQCASE(XNUMX,CMIN    ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)?*u: x); break;
  case OBQCASE(XNUMX,CPLUS   ): OBQLOOP(X,X,wt,x=*u, x=xplus(x,*u)); break;
  case OBQCASE(RATX, CMAX    ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)? x:*u); break;
  case OBQCASE(RATX, CMIN    ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)?*u: x); break;
  case OBQCASE(RATX, CPLUS   ): OBQLOOP(Q,Q,wt,x=*u, x=qplus(x,*u)); break;
  case OBQCASE(INTX, CBW0001 ): OBQLOOP(I,I,wt,x=*u, x&=*u        ); break;
  case OBQCASE(INTX, CBW0110 ): OBQLOOP(I,I,wt,x=*u, x^=*u        ); break;
  case OBQCASE(INTX, CBW0111 ): OBQLOOP(I,I,wt,x=*u, x|=*u        ); break;
  case OBQCASE(INTX, CMAX    ): OBQLOOP(I,I,wt,x=*u, x=MAX(x,*u)  ); break;
  case OBQCASE(INTX, CMIN    ): OBQLOOP(I,I,wt,x=*u, x=MIN(x,*u)  ); break;
  case OBQCASE(INTX, CPLUS   ): 
   er=0; OBQLOOP(I,I,wt,x=*u, {p=0>x; x+=*u; BOV(p==0>*u&&p!=0>x);}); 
   if(er>=EWOV)OBQLOOP(I,D,FL,x=(D)*u, x+=*u);
 }
Exemple #19
0
void occQt::makeChamfer()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(8.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeChamfer MC(aTopoBox);
    TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap;

    TopExp::MapShapesAndAncestors(aTopoBox, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap);

    for (Standard_Integer i = 1; i <= aEdgeFaceMap.Extent(); ++i)
    {
        TopoDS_Edge anEdge = TopoDS::Edge(aEdgeFaceMap.FindKey(i));
        TopoDS_Face aFace = TopoDS::Face(aEdgeFaceMap.FindFromIndex(i).First());

        MC.Add(0.6, 0.6, anEdge, aFace);
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MC.Shape());
    anAisShape->SetColor(Quantity_NOC_TOMATO);

    mContext->Display(anAisShape);
}
Exemple #20
0
	MK(MINUS),MK(EQUAL),MK(BACKSLASH),MK(BACKSPACE),
	MK(ESCAPE),MK(Q),MK(W),MK(E),MK(R),MK(T),MK(Y),MK(U),MK(I),MK(O),
	MK(P),MK(TILDE),MK(BRACKET_LEFT),MK(ENTER),
	MK(LEFTCONTROL),MK(A),MK(S),MK(D),MK(F),MK(G),MK(H),MK(J),MK(K),
	MK(L),MK(SEMICOLON),MK(APOSTROPHE),MK(BRACKET_RIGHT),MK(INSERT),
	MK(LEFTSHIFT),MK(Z),MK(X),MK(C),MK(V),MK(B),MK(N),MK(M),MK(COMMA),
	MK(PERIOD),MK(SLASH),MK(RIGHTALT),MK(RIGHTSHIFT),MK(LEFTALT),MK(SPACE),
	MK(BL_DELETE),
	MK(BL_END),
	MK(BL_PAGEDOWN),
	MK(BL_CURSORUP),MK(BL_CURSORLEFT),MK(BL_CURSORRIGHT),MK(BL_CURSORDOWN)
};

ButtConfig suborkbmap[0x65]=
{
	MC(0x01),MC(0x3b),MC(0x3c),MC(0x3d),MC(0x3e),MC(0x3f),MC(0x40),MC(0x41),MC(0x42),MC(0x43),
	MC(0x44),MC(0x57),MC(0x58),MC(0x45),MC(0x29),MC(0x02),MC(0x03),MC(0x04),MC(0x05),MC(0x06),
	MC(0x07),MC(0x08),MC(0x09),MC(0x0a),MC(0x0b),MC(0x0c),MC(0x0d),MC(0x0e),MC(0xd2),MC(0xc7),
	MC(0xc9),MC(0xc5),MC(0xb5),MC(0x37),MC(0x4a),MC(0x0f),MC(0x10),MC(0x11),MC(0x12),MC(0x13),
	MC(0x14),MC(0x15),MC(0x16),MC(0x17),MC(0x18),MC(0x19),MC(0x1a),MC(0x1b),MC(0x1c),MC(0xd3),
	MC(0xca),MC(0xd1),MC(0x47),MC(0x48),MC(0x49),MC(0x4e),MC(0x3a),MC(0x1e),MC(0x1f),MC(0x20),
	MC(0x21),MC(0x22),MC(0x23),MC(0x24),MC(0x25),MC(0x26),MC(0x27),MC(0x28),MC(0x4b),MC(0x4c),
	MC(0x4d),MC(0x2a),MC(0x2c),MC(0x2d),MC(0x2e),MC(0x2f),MC(0x30),MC(0x31),MC(0x32),MC(0x33),
	MC(0x34),MC(0x35),MC(0x2b),MC(0xc8),MC(0x4f),MC(0x50),MC(0x51),MC(0x1d),MC(0x38),MC(0x39),
	MC(0xcb),MC(0xd0),MC(0xcd),MC(0x52),MC(0x53),MC(0x00),MC(0x00),MC(0x00),MC(0x00),MC(0x00),
	MC(0x00),
};


static void UpdateFKB(void)
{
Exemple #21
0
static AHDRR(bw1111insC,UC,UC){I k=    m*c/n; if(1<n)memset(z,CFF,k); else MC(z,x,k);}
Exemple #22
0
TEST(MarkovTree,EmptyChainsAreEqual)
{
    EXPECT_TRUE( isEqual( MC(), MC() ) );
}
Exemple #23
0
static B jtmvw(J jt,C*v,C*u,I n,B bv,B bu,B dv,B du){C c;
 switch((dv?8:0)+(du?4:0)+(bv?2:0)+bu){
  case MVCS(0,0,0,0): MC(v,u,n*4);                             break;
  case MVCS(0,0,0,1): DO(n, DO(4, v[3-i]=u[i];); v+=4; u+=4;); break;
int tester()
{
//description
  std::vector<std::string> neutrals;
  std::vector<std::string> ions;
  neutrals.push_back("N2");
  neutrals.push_back("CH4");
  neutrals.push_back("C2H");
//ionic system contains neutral system
  ions = neutrals;
  ions.push_back("N2+");
  Scalar MN(14.008L), MC(12.011), MH(1.008L);
  Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH, MC2H = 2.L * MC + MH;
  std::vector<Scalar> Mm;
  Mm.push_back(MN2);
  Mm.push_back(MCH4);
  Mm.push_back(MC2H);

//densities
  std::vector<Scalar> molar_frac;
  molar_frac.push_back(0.95999L);
  molar_frac.push_back(0.04000L);
  molar_frac.push_back(0.00001L);
  molar_frac.push_back(0.L);
  Scalar dens_tot(1e12L);

//hard sphere radius
  std::vector<Scalar> hard_sphere_radius;
  hard_sphere_radius.push_back(2.0675e-8L * 1e-2L); //N2  in cm -> m
  hard_sphere_radius.push_back(2.3482e-8L * 1e-2L); //CH4 in cm -> m
  hard_sphere_radius.push_back(0.L); //C2H

//zenith angle
//not necessary

//photon flux
//not necessary

////cross-section
//not necessary

//altitudes
  Scalar zmin(600.),zmax(1400.),zstep(10.);

//binary diffusion
  Scalar bCN1(1.04e-5 * 1e-4),bCN2(1.76); //cm2 -> m2
  Planet::DiffusionType CN_model(Planet::DiffusionType::Wakeham);
  Scalar bCC1(5.73e16 * 1e-4),bCC2(0.5); //cm2 -> m2
  Planet::DiffusionType CC_model(Planet::DiffusionType::Wilson);
  Scalar bNN1(0.1783 * 1e-4),bNN2(1.81); //cm2 -> m2
  Planet::DiffusionType NN_model(Planet::DiffusionType::Massman);

/************************
 * first level
 ************************/

//altitude
  Planet::Altitude<Scalar,std::vector<Scalar> > altitude(zmin,zmax,zstep);

//neutrals
  Antioch::ChemicalMixture<Scalar> neutral_species(neutrals); 

//ions
  Antioch::ChemicalMixture<Scalar> ionic_species(ions); 

//chapman
//not needed

//binary diffusion
  Planet::BinaryDiffusion<Scalar> N2N2(   Antioch::Species::N2,  Antioch::Species::N2 , bNN1, bNN2, NN_model);
  Planet::BinaryDiffusion<Scalar> N2CH4(  Antioch::Species::N2,  Antioch::Species::CH4, bCN1, bCN2, CN_model);
  Planet::BinaryDiffusion<Scalar> CH4CH4( Antioch::Species::CH4, Antioch::Species::CH4, bCC1, bCC2, CC_model);
  Planet::BinaryDiffusion<Scalar> N2C2H( Antioch::Species::N2, Antioch::Species::C2H);
  Planet::BinaryDiffusion<Scalar> CH4C2H( Antioch::Species::CH4, Antioch::Species::C2H);
  std::vector<std::vector<Planet::BinaryDiffusion<Scalar> > > bin_diff_coeff;
  bin_diff_coeff.resize(2);
  bin_diff_coeff[0].push_back(N2N2);
  bin_diff_coeff[0].push_back(N2CH4);
  bin_diff_coeff[0].push_back(N2C2H);
  bin_diff_coeff[1].push_back(N2CH4);
  bin_diff_coeff[1].push_back(CH4CH4);
  bin_diff_coeff[1].push_back(CH4C2H);


/************************
 * second level
 ************************/

//temperature
  std::vector<Scalar> T0,Tz;
  read_temperature<Scalar>(T0,Tz,"input/temperature.dat");
  std::vector<Scalar> neutral_temperature;
  linear_interpolation(T0,Tz,altitude.altitudes(),neutral_temperature);
  Planet::AtmosphericTemperature<Scalar, std::vector<Scalar> > temperature(neutral_temperature, neutral_temperature, altitude);

//photon opacity
//not needed

//reaction sets
//not needed

/************************
 * third level
 ************************/

//atmospheric mixture
  Planet::AtmosphericMixture<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > composition(neutral_species, ionic_species, altitude, temperature);
  composition.init_composition(molar_frac,dens_tot);
  composition.set_hard_sphere_radius(hard_sphere_radius);
  composition.initialize();

//kinetics evaluators
//not needed

/************************
 * fourth level
 ************************/

//photon evaluator
//not needed

//molecular diffusion
  Planet::MolecularDiffusionEvaluator<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > molecular_diffusion(bin_diff_coeff,
                                                                                                                          composition,
                                                                                                                          altitude,
                                                                                                                          temperature);
  molecular_diffusion.make_molecular_diffusion();

//eddy diffusion
//not needed

/************************
 * checks
 ************************/

  molar_frac.pop_back();//get the ion outta here
  Scalar Matm(0.L);
  for(unsigned int s = 0; s < molar_frac.size(); s++)
  {
     Matm += molar_frac[s] * composition.neutral_composition().M(s);
  }
  Matm *= 1e-3L; //to kg

  std::vector<std::vector<Scalar> > densities;
  calculate_densities(densities, dens_tot, molar_frac, zmin,zmax,zstep, temperature.neutral_temperature(), Mm);
//N2, CH4, C2H
  std::vector<std::vector<Scalar> > Dij;
  Dij.resize(2);
  Dij[0].resize(3,0.L);
  Dij[1].resize(3,0.L);

  int return_flag(0);
  for(unsigned int iz = 0; iz < altitude.altitudes().size(); iz++)
  {
      Scalar P = pressure(composition.total_density()[iz],temperature.neutral_temperature()[iz]);
      Scalar T = temperature.neutral_temperature()[iz];
      Dij[0][0] = binary_coefficient(T,P,bNN1,bNN2); //N2 N2
      Dij[1][1] = binary_coefficient(T,P,bCC1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCC2 + Scalar(1.L)) 
                                              * Planet::Constants::Universal::kb<Scalar>()
                                              / Planet::Constants::Convention::P_normal<Scalar>(),bCC2 + Scalar(1.L)); //CH4 CH4
      Dij[0][1] = binary_coefficient(T,P,bCN1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCN2),bCN2); //N2 CH4
      Dij[0][2] = binary_coefficient(Dij[0][0],Mm[0],Mm[2]); //N2 C2H
      Dij[1][2] = binary_coefficient(Dij[1][1],Mm[1],Mm[2]); //CH4 C2H
      Dij[1][0] = Dij[0][1]; //CH4 N2
      for(unsigned int s = 0; s < molar_frac.size(); s++)
      {
        Scalar tmp(0.L);
        Scalar M_diff(0.L);
        for(unsigned int medium = 0; medium < 2; medium++)
        {
           if(s == medium)continue;
           tmp += densities[medium][iz]/Dij[medium][s];
        }
        Scalar Ds = (barometry(zmin,altitude.altitudes()[iz],neutral_temperature[iz],Matm,dens_tot) - densities[s][iz]) / tmp;
        for(unsigned int j = 0; j < molar_frac.size(); j++)
        {
           if(s == j)continue;
           M_diff += composition.total_density()[iz] * composition.neutral_molar_fraction()[j][iz] * composition.neutral_composition().M(j);
        }
        M_diff /= Scalar(molar_frac.size() - 1);
        Scalar Dtilde = Ds / (Scalar(1.L) - composition.neutral_molar_fraction()[s][iz] * (Scalar(1.L) - composition.neutral_composition().M(s)/M_diff));

        return_flag = return_flag ||
                      check_test(Dtilde,molecular_diffusion.Dtilde()[s][iz],"D tilde of species at altitude");

      }
      return_flag = return_flag ||
                    check_test(Dij[0][0],molecular_diffusion.binary_coefficient(0,0,T,P),"binary molecular coefficient N2 N2 at altitude") || 
                    check_test(Dij[0][1],molecular_diffusion.binary_coefficient(0,1,T,P),"binary molecular coefficient N2 CH4 at altitude") || 
                    check_test(Dij[0][2],molecular_diffusion.binary_coefficient(0,2,T,P),"binary molecular coefficient N2 C2H at altitude") || 
                    check_test(Dij[1][1],molecular_diffusion.binary_coefficient(1,1,T,P),"binary molecular coefficient CH4 CH4 at altitude") || 
                    check_test(Dij[1][2],molecular_diffusion.binary_coefficient(1,2,T,P),"binary molecular coefficient CH4 C2H at altitude");
  }

  return return_flag;
}
/* This function prompts the players including AI players for exchanging the cards */
int prompt_for_exchange(Player *players, Deck *d, int godmode, int iteration){
  int i, bet, bet_sum, cur_bet = 0;
  char *choice;

  /* choice is represented with a string of maximal length 5 */
  choice = malloc(6*sizeof(char));
  bet_sum = 0;
  /* first deals with AI players */
  for(i = 0; i < 4; ++i){
    /* prompt for players if he/she is an alive AI player */
    if((players+i)->isAI == 1 && (players+i)->alive == 1){
      printf("%s is thinking...\n",(players+i)->name);

      if(godmode == 1){
	printf("%s's cards before exchanging:",(players+i)->name);
	player_display(players+i);	
      }

      /* use MC advisor to find out the best move */
      choice = MC((players+i)->hand,godmode,iteration);
      printf("\n%s decides to exchange card %s \n",(players+i)->name,choice);
      parse_exchange(choice, (players+i)->hand, d);

      if(godmode == 1){
	printf("%s's cards after exchanging:",(players+i)->name);
	player_display(players+i);
      }
      printf("\n");

      /* generate the bet for AI players based on their hand value plus some randome variations. */
      bet = hand_value((players+i)->hand) + rand() % 10 + i * 10;

      /* small chance of doubling */
      if(rand() % 13 == 0)
	bet *= 2;

      /* if the bet is greater than the remaining chips for the player */
      if(bet <= (players+i)->chip && bet >= cur_bet){
	cur_bet = bet;
	(players+i)->chip -= bet;
	printf("[%s is betting %d on his/her hand.]\n\n", (players+i)->name, bet);
      }
      /* Bet all the chips */
      else if(bet > (players+i)->chip && (players+i)->chip >= cur_bet){
	bet = (players+i)->chip;
	cur_bet = bet;
	printf("[%s is betting %d on his/her hand.]\n\n", (players+i)->name, bet);
      }
      else{
	printf("[%s folds.]\n\n",(players+i)->name);
	(players+i)->fold = 1;
	bet = 0;
      }

      bet_sum += bet;

    }
  }

  /* prompt for exchange for the live player */
  printf("********************************************************************************\n");
  printf("   Your current hand:\n   ");
  /*player_display(players);*/
  hand_value(players->hand);
  hand_display(players->hand);
  printf("********************************************************************************\n");
  choice = MC(players->hand,godmode,iteration);
  printf("\nMC simulator suggest exchanging card %s\n\n",choice);

  printf("%s, please enter the card you want to exchange\n(e.g. To exchange the first card, enter 1; To exchange the second and the fifth card, enter 25;\nIf you do not want to exchange any card, enter 0):",(players)->name);
  scanf("%s",choice);
  /* if the player enters a string other than "0", parse the string and exchange the cards */
  if(strcmp(choice,"0") != 0){
    parse_exchange(choice, players->hand, d);
    printf("********************************************************************************\n");
    printf("Your hand after exchanging:\n");
    /*player_display(players);*/
    hand_value(players->hand);
    hand_display(players->hand);

    printf("********************************************************************************\n");
    printf("\n");
  }
  /* no cards is exchanged if the player enters "0" */
  else{
    printf("No card exchanged for %s.\n",players->name);
  }
  /* evaluate the value */
  hand_value((players)->hand);
  printf("Current highest bet: %d.\nPlease enter the amount you want to bet. (Enter 0 to fold)\n",cur_bet);
  scanf("%d",&bet);
  while( (bet > (players)->chip || bet < cur_bet) && bet != 0 ){
    if(bet > (players)->chip)
      printf("You current chip is %d, you do not have enough chip, try again with a smaller amount.\n",players->chip);
    else
      printf("Please enter a number bigger than the current bet(%d).\n",cur_bet);
    scanf("%d",&bet);
  }
  if(bet == 0)
    players->fold = 1;
  players->chip -= bet;
  bet_sum += bet;
  cur_bet = bet;
  return bet_sum;
}
Exemple #26
0
static AHDRR(bw0000insC,UC,UC){I k=    m*c/n; if(1<n)memset(z,C0 ,k); else MC(z,x,k);}
Exemple #27
0
/* X: nxT, C: nxnxnxn.  Computes the cumulant tensor.  */
void EstCumTens(double *C, double *X, int n, int T)
{
	int n2 = n*n;
	int n3 = n*n*n;
	int n4 = n*n*n*n;
	int i, j, k, l, t;
	double Cijkl, xi, xij, xijk, *x;
	double ust = 1.0 / (float)T;

	double *R = (double *)calloc(n*n, sizeof(double));
	/* To store Cov(x).  Recomputed: no whiteness assumption here*/
	if (R == NULL) OutOfMemory();

	for (i = 0; i<n4; i++) C[i] = 0.0;
	for (i = 0; i<n2; i++) R[i] = 0.0;

	Message0(3, "Computing 2nd order cumulants...\n");
	/* accumulation */
	for (t = 0, x = X; t<T; t++, x += n)
		for (i = 0; i<n; i++)
			for (j = i; j<n; j++)
				R[i + j*n] += x[i] * x[j];
	/* normalization and symmetrization */
	for (i = 0; i<n; i++)
		for (j = i; j<n; j++) {
			R[i + j*n] = ust * R[i + j*n];
			R[j + i*n] = R[i + j*n];
		}

	Message0(3, "Computing 4th order cumulants...\n");
	/* accumulation */
	for (t = 0, x = X; t<T; t++, x += n)
		for (i = 0; i<n; i++) {
			xi = x[i];
			for (j = i; j<n; j++) {
				xij = xi *x[j];
				for (k = j; k<n; k++) {
					xijk = xij*x[k];
					for (l = k; l<n; l++)
						MC(i, j, k, l) += xijk*x[l];
				}
			}
		}
	/* normalization, mom2cum, and symmetrization */
	for (i = 0; i<n; i++)
		for (j = i; j<n; j++)
			for (k = j; k<n; k++)
				for (l = k; l<n; l++) {
					Cijkl = ust *  MC(i, j, k, l)
						- R[i + j*n] * R[k + l*n]
						- R[i + k*n] * R[j + l*n]
						- R[i + l*n] * R[j + k*n];

					MC(i, j, k, l) = Cijkl; MC(i, j, l, k) = Cijkl; MC(j, i, k, l) = Cijkl; MC(j, i, l, k) = Cijkl; /* ijxx  */
					MC(i, k, j, l) = Cijkl; MC(i, k, l, j) = Cijkl; MC(k, i, j, l) = Cijkl; MC(k, i, l, j) = Cijkl; /* ikxx  */
					MC(i, l, j, k) = Cijkl; MC(i, l, k, j) = Cijkl; MC(l, i, j, k) = Cijkl; MC(l, i, k, j) = Cijkl; /* ilxx  */
					MC(j, k, i, l) = Cijkl; MC(j, k, l, i) = Cijkl; MC(k, j, i, l) = Cijkl; MC(k, j, l, i) = Cijkl; /* jkxx  */
					MC(j, l, i, k) = Cijkl; MC(j, l, k, i) = Cijkl; MC(l, j, i, k) = Cijkl; MC(l, j, k, i) = Cijkl; /* jlxx  */
					MC(k, l, i, j) = Cijkl; MC(k, l, j, i) = Cijkl; MC(l, k, i, j) = Cijkl; MC(l, k, j, i) = Cijkl; /* klxx  */
				}
	free(R);
}
Exemple #28
0
 AHDRR(bw1111insI,UI,UI){I k=SZI*m*c/n; if(1<n)memset(z,CFF,k); else MC(z,x,k);}
Exemple #29
0
A ra(A y, I t, I n) { MONAD_PROLOG; I k=(yn>n?n:yn)*ts(t);
    RZ(y); ASSERT(t>=yt, ERDOM);
    z=ga(t,yr,n,NULL);
    MC(AV(z),AV(y),k);
    R z;
}
Exemple #30
0
 AHDRR(bw0000insI,UI,UI){I k=SZI*m*c/n; if(1<n)memset(z,C0 ,k); else MC(z,x,k);}