// transform MCOORD prime primitive velocity to whichcoord whichvel velocity int metp2met2bl(int whichvel, int whichcoord, FTYPE *pr, int ii, int jj) { int k = 0; FTYPE ucon[NDIM]; struct of_geom geom; // which=WHICHVEL // which==0 means supplied the 4-velocity // which==1 means supplied the 3-velocity // which==2 means supplied the relative 4-velocity // if whichcood==PRIMECOORDS, then just pr2ucon and ucon2pr // effectively this results in changing from one primitive velocity to another within PRIMECOORDS // get prime MCOORD geometry get_geometry(ii,jj,CENT,&geom) ; // transform prime MCOORD primitive to prim MCOORD 4-vel if (pr2ucon(WHICHVEL,pr, &geom ,ucon) >= 1) FAILSTATEMENT("init.c:init()", "pr2ucon()", 1); if(whichcoord>=0){ // transform from prime MCOORD 4-vel to non-prime MCOORD 4-vel metptomet(ii,jj,ucon); // transform from non-prime MCOORD to non-prime whichcoord coordtrans(MCOORD,whichcoord,ii,jj,ucon); } // else already in prime // transform from non-prime whichcoord 4-vel to non-prime whichcoord whichvel-velocity gset(0,whichcoord,ii,jj,&geom); ucon2pr(whichvel,ucon,&geom,pr); return(0); }
Rat* getStrategies(Equilibrium eq) { int n = eq.lcpdim; Rat* strat; strat = malloc((n) * sizeof(Rat)); int i, row; gmpt num, den; ginit(num); ginit(den); for (i=1; i<=n; i++) { if((row = eq.bascobas[Z(i)]) < n) /* If Z(i) is basic */ { /* value of Z(i): scfa[Z(i)]*rhs[row] / (scfa[RHS]*det) */ gmulint(eq.scfa[Z(i)], eq.A[row][RHS(n)], num); gmulint(eq.det, eq.scfa[RHS(n)], den); greduce(num, den); strat[i-1] = ratinit(); gset(strat[i-1].num, num); gset(strat[i-1].den, den); } else if((row = eq.bascobas[W(i,n)]) < n) { strat[i-1] = ratfromi(0); /* value of W(i-n) is rhs[row] / (scfa[RHS]*det) copy(num, eq.A[row][RHS(n)]); mulint(eq.det, eq.scfa[RHS(n)], den); reduce(num, den); copy(strat[i-1].num, num); copy(strat[i-1].den, den);*/ } else { strat[i-1] = ratfromi(0); } } /* end of for (i=...) */ gclear(num); gclear(den); return strat; }
Equilibrium createEquilibrium(gmpt** A, gmpt* scfa, gmpt det, int* bascobas, int* whichvar, int n, int nrows, int ncols) { Equilibrium eq; T2ALLOC (eq.A, n, n+2, gmpt); G2INIT (eq.A, n, n+2); eq.scfa = TALLOC (n+2, gmpt); eq.bascobas = TALLOC(2*n+1, int); eq.whichvar = TALLOC(2*n+1, int); int i, j; for(i = 0; i < n; ++i) { for(j = 0; j < n+2; ++j) { gset(eq.A[i][j], A[i][j]); } } for(i = 0; i < n+2; ++i) { gset(eq.scfa[i], scfa[i]); } for(i = 0; i < 2*n+1; ++i) { eq.bascobas[i] = bascobas[i]; eq.whichvar[i] = whichvar[i]; } ginit(eq.det); gset(eq.det, det); eq.lcpdim = n; eq.nrows = nrows; eq.ncols = ncols; return eq; }
/* NOTE: This function only works if the values are all integers. This function will add a new item to the dictionary if the item is not in the dictionary. If the item is in the dictionary, it will incriment its value. */ void addOrIncriment(Dict dictionary,void* item) { int value; int index = gindexOf(dictionary->keys,item); if(index>-1) { // printf("incrimenting value\n"); value = (int)gget(dictionary->values,index); gset(dictionary->values,index,(void*)value+1); } else { daddKey(dictionary,item,(void*)1); } }
/** main functio to optimize multiple contracted S orbitals */ void GTO2Slater::optimize() { //construct one-dim grid double ri = 1e-5; double rf = 10.0; int npts = 101; string gridType("log"); if(gridPtr) { OhmmsAttributeSet radAttrib; radAttrib.add(gridType,"type"); radAttrib.add(npts,"npts"); radAttrib.add(ri,"ri"); radAttrib.add(rf,"rf"); radAttrib.put(gridPtr); } myGrid.set(ri,rf,npts); //create a numerical grid funtor typedef OneDimCubicSpline<double> RadialOrbitalType; RadialOrbitalType radorb(&myGrid); int L= 0; //Loop over all the constracted S orbitals map<string,xmlNodePtr>::iterator it(sPtr.begin()),it_end(sPtr.end()); while(it != it_end) { //create contracted gaussian GTOType gset(L,Normalized); //read the radfunc's of basisGroup gset.putBasisGroup((*it).second); //convert to a radial functor Transform2GridFunctor<GTOType,RadialOrbitalType> transform(gset, radorb); transform.generate(myGrid.rmin(),myGrid.rmax(),myGrid.size()); //optimize it with the radial functor Any2Slater gto2slater(radorb); gto2slater.optimize(); ++it; } sPtr.clear(); }
// converts whichvel/whichcoord velocity to WHICHVEL/MCOORD int bl2met2metp2v(int whichvel, int whichcoord, FTYPE *pr, int ii, int jj) { int k = 0; FTYPE ucon[NDIM]; struct of_geom geom; // whichvel==0 means supplied the 4-velocity // whichvel==1 means supplied the 3-velocity // whichvel==2 means supplied the relative 4-velocity // if whichcoord==PRIMECOORDS, then really use uses pr2ucon and ucon2pr, could probably optimize if wanted // effectively this results in changing from one primitive velocity to another within PRIMECOORDS // pr is in whichcoord coordinates // get geometry (non-prime coords) gset(0,whichcoord,ii,jj,&geom); // convert whichvel-pr in whichcoord coords to ucon in whichcoord coordinates if (pr2ucon(whichvel,pr, &geom ,ucon) >= 1) FAILSTATEMENT("init.c:init()", "pr2ucon()", 1); // convert from whichcoord to MCOORD, the coordinates of evolution if(whichcoord>=0){ coordtrans(whichcoord,MCOORD,ii,jj,ucon); // transform MCOORD ucon from MCOORD non-prime to MCOORD prime coords mettometp(ii,jj,ucon); } // otherwise already in prime // get prime geometry get_geometry(ii,jj,CENT,&geom) ; // convert from MCOORD prime 4-vel to MCOORD prime WHICHVEL-vel(i.e. primitive velocity of evolution) ucon2pr(WHICHVEL,ucon,&geom,pr); return(0); }
static void set(void) { int i, gotcha, not, sspeed = 0; speed_t ispeed0, ospeed0, ispeed1, ospeed1; const char *ap; struct termios tc; ispeed0 = ispeed1 = cfgetispeed(&ts); ospeed0 = ospeed1 = cfgetospeed(&ts); while (*args) { for (i = 0; speeds[i].s_str; i++) if (strcmp(speeds[i].s_str, *args) == 0) { ispeed1 = ospeed1 = speeds[i].s_val; sspeed |= 3; goto next; } gotcha = 0; if (**args == '-') { not = 1; ap = &args[0][1]; } else { not = 0; ap = *args; } for (i = 0; modes[i].m_name; i++) { if (modes[i].m_type == M_SEPAR || modes[i].m_flg&0100) continue; if (strcmp(modes[i].m_name, ap) == 0) { gotcha++; switch (modes[i].m_type) { case M_IFLAG: setmod(&ts.c_iflag, modes[i], not); break; case M_OFLAG: setmod(&ts.c_oflag, modes[i], not); break; case M_CFLAG: case M_PCFLAG: setmod(&ts.c_cflag, modes[i], not); break; case M_LFLAG: setmod(&ts.c_lflag, modes[i], not); break; case M_CC: if (not) inval(); setchr(ts.c_cc, modes[i]); break; case M_FUNCT: modes[i].m_func(not); break; } } } if (gotcha) goto next; if (strcmp(*args, "ispeed") == 0) { if (*++args == NULL) break; if (atol(*args) == 0) { ispeed1 = ospeed1; sspeed |= 1; goto next; } else for (i = 0; speeds[i].s_str; i++) if (strcmp(speeds[i].s_str, *args) == 0) { ispeed1 = speeds[i].s_val; sspeed |= 1; goto next; } inval(); } if (strcmp(*args, "ospeed") == 0) { if (*++args == NULL) break; for (i = 0; speeds[i].s_str; i++) if (strcmp(speeds[i].s_str, *args) == 0) { ospeed1 = speeds[i].s_val; sspeed |= 2; goto next; } inval(); } gset(); next: args++; } if (sspeed) { if (sspeed == 3 && ispeed1 != ospeed1 && ospeed1 != B0) { tc = ts; cfsetispeed(&tc, ispeed1); if (cfgetospeed(&tc) == cfgetospeed(&ts)) { tc = ts; cfsetospeed(&tc, ospeed1); if (cfgetispeed(&tc) == cfgetispeed(&ts)) { cfsetispeed(&ts, ispeed1); cfsetospeed(&ts, ospeed1); } } } else { if (ispeed0 != ispeed1) cfsetispeed(&ts, ispeed1); if (ospeed0 != ospeed1) cfsetospeed(&ts, ospeed1); } } }
int init_star(int *whichvel, int*whichcoord, int i, int j, int k, FTYPE *pr, FTYPE *pstag) { int set_zamo_velocity(int whichvel, struct of_geom *ptrgeom, FTYPE *pr); int set_phi_velocity_grb2(FTYPE *V, FTYPE *prstellar, FTYPE *pr); FTYPE X[NDIM],V[NDIM]; FTYPE dxdxp[NDIM][NDIM]; FTYPE r,th; void set_stellar_solution(int ii, int jj, int kk,FTYPE *pr, FTYPE *hcmsingle, FTYPE *ynu0single, FTYPE *ynusingle); FTYPE prstellar[NPR]; FTYPE przamobl[NPR]; FTYPE przamo[NPR]; FTYPE pratm[NPR]; struct of_geom geom; struct of_geom *ptrgeom; struct of_geom geombl; int pl,pliter; FTYPE hcmsingle,ynu0single,ynusingle; FTYPE parlist[MAXPARLIST]; int numparms; ////////////////////////////////// // // set free parameters // beta=1E6; Rbeta=1000.0*2.0*G*Mcgs/(C*C)/Lunit; // 1000R_S where Mcgs is the mass // DEBUG beta=1E30; // DEBUG // DEBUG ////////////////////////////////// // // Interpolate read-in data to computational grid set_stellar_solution(i,j,k,prstellar,&hcmsingle,&ynu0single,&ynusingle); // prstellar has 3-velocity in prstellar[U1], need to convert ///////////////////////////// // // Go ahead and set quantities that need no conversion of any kind // ///////////////////////////// if(!isfinite(hcmsingle)){ dualfprintf(fail_file,"read-in or interpolated bad hcmsingle: %d %d %d\n",i,j,k); } if(!isfinite(ynu0single)){ dualfprintf(fail_file,"read-in or interpolated bad ynu0single: %d %d %d\n",i,j,k); } if(!isfinite(ynusingle)){ dualfprintf(fail_file,"read-in or interpolated bad ynusingle: %d %d %d\n",i,j,k); } #if(DOYL!=DONOYL) pr[YL] = prstellar[YL]; if(!isfinite(pr[YL])){ dualfprintf(fail_file,"read-in or interpolated bad YL: %d %d %d\n",i,j,k); } #endif #if(DOYNU!=DONOYNU) // already accounted for WHICHEVOLVEYNU pr[YNU] = prstellar[YNU]; if(!isfinite(pr[YNU])){ dualfprintf(fail_file,"read-in or interpolated bad YNU: %d %d %d\n",i,j,k); } #endif // dualfprintf(fail_file,"YLYNU: i=%d yl=%21.15g ynu=%21.15g\n",i,pr[YL],pr[YNU]); //////////////////////////////////// // // Setup EOSextra for kazfulleos.c // parlist starts its index at 0 with EOSextra["TDYNORYEGLOBAL"] // // why not just call to compute EOSglobal things? (only because of H) // only matters for Kaz EOS and should be in correct order and type of quantity parlist[TDYNORYEGLOBAL-FIRSTEOSGLOBAL]=pr[YE]; // now using YE as primitive and YL as conserved ///pr[YL]-ynusingle; // Y_e for any WHICHEVOLVEYNU parlist[YNU0OLDGLOBAL-FIRSTEOSGLOBAL]=parlist[YNU0GLOBAL-FIRSTEOSGLOBAL]=ynu0single; // Y^0_\nu parlist[YNUOLDGLOBAL-FIRSTEOSGLOBAL]=ynusingle; // for WHICHEVOLVEYNU, no older yet, so indicate that by using same value int hi; for(hi=0;hi<NUMHDIRECTIONS;hi++){ parlist[HGLOBAL-FIRSTEOSGLOBAL+hi]=hcmsingle; // H } // first guess is neutrinos have U=P=S=0 parlist[UNUGLOBAL-FIRSTEOSGLOBAL]=0.0; parlist[PNUGLOBAL-FIRSTEOSGLOBAL]=0.0; parlist[SNUGLOBAL-FIRSTEOSGLOBAL]=0.0; parlist[IGLOBAL-FIRSTEOSGLOBAL]=i; parlist[JGLOBAL-FIRSTEOSGLOBAL]=j; parlist[KGLOBAL-FIRSTEOSGLOBAL]=k; store_EOS_parms(WHICHEOS,NUMEOSGLOBALS,GLOBALMAC(EOSextraglobal,i,j,k),parlist); ////////////////////////////////// // // Set other aspects of stellar model, such as rotational velocity // /////////////////////////////////// ptrgeom=&geom; get_geometry(i,j,k,CENT,ptrgeom); coord_ijk(i, j, k, CENT, X); bl_coord_ijk(i, j, k, CENT,V); dxdxprim_ijk(i, j, k, CENT,dxdxp); r=V[1]; th=V[2]; // if(i==1 && j==0 && k==0) dualfprintf(fail_file,"BANG1\n"); // PLOOP(pliter,pl) dualfprintf(fail_file,"i=%d j=%d k=%d prstellar[%d]=%21.15g\n",i,j,k,pl,prstellar[pl]); //////////////////////////// // assume in BL-coords // also adds up stellar 3-velocity to my additional atmosphere 3-velocity PLOOP(pliter,pl) pratm[pl]=prstellar[pl]; // default value (this copies densities and fields) set_phi_velocity_grb2(V,prstellar,pratm); // dualfprintf(fail_file,"prstellar[UU]=%21.15g pratm[UU]=%21.15g\n",prstellar[UU],pratm[UU]); // dualfprintf(fail_file,"%d %d :: star_rho=%g star_u=%g star_v1=%g star_v3=%g\n",i,j,pratm[RHO],pratm[UU],pratm[U1],pratm[U3]); //////////////////////////////////////////////////////////// // // Set primitives for different radial regions // //////////////////////////////////////////////////////////// // MBH is in length units if(fabs(r)<4.0*MBH){ // fabs(r) is because r can be less than 0 and if far from BH in negative sense, then don't want to still use this // chose 4MBH since then smoothly matches onto freely-falling frame from stellar model // if this close to BH, then set velocity in PRIMECOORDS since can't use BL coords inside horizon and dubiously set inside ergosphere // even if using VEL4 we can't use BL-coords inside horizon PLOOP(pliter,pl) przamo[pl]=0.0; set_zamo_velocity(WHICHVEL,ptrgeom, przamo); // in PRIMECOORDS/WHICHVEL pr[RHO]=pratm[RHO]; pr[UU]=pratm[UU]; for(pl=U1;pl<=U3;pl++) pr[pl]=przamo[pl]; for(pl=B1;pl<=B3;pl++) pr[pl]=pratm[pl]; // although really need vector potential+B3 or just B3 for 2D } else{ // GODMARK: at the moment the initial-value problem is setup only with 1 step iteration (essentially ignore star initially) // GODMARK: velocity can be quite bad if arbitrarily chosen and put in black hole that requires certain velocity near it. // so add in ZAMO observer in BL-coords here instead of afterwards // this gets BL-geometry in native BL spc coordinates (not PRIMECOORDS) gset(0,BLCOORDS,i,j,k,&geombl); przamobl[U1] = (geombl.gcon[GIND(0,1)])/(geombl.gcon[GIND(0,0)]) ; przamobl[U2] = (geombl.gcon[GIND(0,2)])/(geombl.gcon[GIND(0,0)]) ; przamobl[U3] = (geombl.gcon[GIND(0,3)])/(geombl.gcon[GIND(0,0)]) ; // can avoid doing below if using VEL4 // if(pratm[U1]<-0.1) pratm[U1]=-0.1; // near horizon time slows down so that 3-velocity actually goes to 0 for(pl=U1;pl<=U3;pl++) pratm[pl] += przamobl[pl]; // if(i==1 && j==0 && k==0) dualfprintf(fail_file,"BANG\n"); //PLOOP(pliter,pl) dualfprintf(fail_file,"i=%d j=%d k=%d prstellar[%d]=%21.15g pratm[%d]=%21.15g przamobl[%d]=%21.15g\n",i,j,k,pl,prstellar[pl],pl,pratm[pl],pl,przamobl[pl]); // convert BL-coordinate velocity to PRIMECOORDS // now conversion should be safe since have at least ZAMO + some small modification due to the star // GODMARK: converting to KSCOORDS since don't at the moment have TOV solution since haven't yet setup fluid! // *whichvel=VEL3; *whichvel=VEL4; // use 4-velocity so near BH velocity can be like in KS-coords and be -0.5 as in stellar model *whichcoord=BLCOORDS; if (bl2met2metp2v_gen(*whichvel,*whichcoord, WHICHVEL, KSCOORDS, pratm, i,j,k) >= 1) FAILSTATEMENT("init.readdata.c:get_data()", "bl2ks2ksp2v()", 1); /////////////////////// // // add up velocities in PRIMECOORDS // zamo is used in case near black hole so solution still good, where other term is not expected to account for black hole // zamo will be small if black hole starts off with small mass compared to self-gravity mass pr[RHO]=pratm[RHO]; pr[UU]=pratm[UU]; //for(pl=U1;pl<=U3;pl++) pr[pl]=przamo[pl]+pratm[pl]; // already accounted for ZAMO term in BL-coords above for(pl=U1;pl<=U3;pl++) pr[pl]=pratm[pl]; // These field components are overwritten by vector potential solution // If want B3, should provide A_r or A_\theta in init.c for(pl=B1;pl<=B3;pl++) pr[pl]=pratm[pl]; // although really need vector potential+B3 or just B3 for 2D // DEBUG pr[U3]=0.0;// DEBUG // DEBUG } // if(i==256 && j==0 && k==0) dualfprintf(fail_file,"BANG\n"); // PLOOP(pliter,pl) dualfprintf(fail_file,"i=%d j=%d k=%d prstellar[%d]=%21.15g przamo=%21.15g pratmpost=%21.15g\n",i,j,k,pl,prstellar[pl],przamo[pl],pratm[pl]); // dualfprintf(fail_file,"prstellar[UU]=%21.15g pratm[UU]=%21.15g pr[UU]=%21.15g\n",prstellar[UU],pratm[UU],pr[UU]); // assume same for now GODMARK (only non-field set so far anyways) PLOOP(pliter,pl){ pstag[pl]=pr[pl]; } ////////////////////////////////// // // Choose conversion of velocity // // assume already converted everything to PRIMECOORDS/WHICHVEL // use if setting in PRIMECOORDS *whichvel=WHICHVEL; *whichcoord=PRIMECOORDS; return(0); }
void Dict_set_value(Dict dict,void *key, void *value){ int index_of_key = gindexOf(dict->keys,key); gset(dict->values,index_of_key,value); }