//Creating matrix for calculations with Armadillo mat mainMatrix(int dimensions, double step_length, double(*potential)(double,int,double), double omega_r) { double diagonal_fixed = 2./(step_length*step_length); double off_diagonal = -1./(step_length*step_length); mat A(dimensions, dimensions, fill::zeros); A(0,0) = diagonal_fixed+potential(step_length, 1, omega_r); A(0,1) = off_diagonal; A(dimensions-1,dimensions-1) = diagonal_fixed + potential(step_length,dimensions,omega_r); A(dimensions-1, dimensions-2) = off_diagonal; for(int i = 1; i < dimensions-1; i++){ A(i,i) = diagonal_fixed + potential(step_length,i+1,omega_r); A(i,i+1) = off_diagonal; A(i,i-1) = off_diagonal; } return A; }
void MainWindow::on_saveButton_clicked() { int size = nc*3/4; char potentialFilename[]="out/potential-%1.txt"; char concFilename[]="out/ni_ne-%1.txt"; //Save potential QVector<double> r(size), potential(size); for (int i=0; i<size; ++i) { r[i] = r_array[i]; potential[i] = phi[i]; } saveToFile(r,potential,QString(potentialFilename).arg((t/dt))); //Save concentration of the electrons and ions QVector<double> /*r(size),*/ ne(size),ni(size); for (int i=0; i<size; ++i) { r[i] = r_array[i]; ne[i] = srho[0][i]; ni[i] = srho[1][i]; } saveToFile2(r,ne,ni, QString(concFilename).arg((t/dt))); }
double theory_t::hamiltonian(conf_t &conf,double t) { double K=conf.kinetic_energy(); double V=potential(conf.X,t); return K+V; }
//------------------------------------------------------------------------------ CoulombInteractionNucleus::CoulombInteractionNucleus(Config *cfg, const Grid &grid): Potential(cfg, grid) { double b = 1; double Z = 2; try{ b = cfg->lookup("oneBodyPotential.coulombInteractionNucleus.b"); Z = cfg->lookup("oneBodyPotential.coulombInteractionNucleus.Z"); } catch (const SettingNotFoundException &nfex) { cerr << "CoulombInteractionNucleus::CoulombInteractionNucleus(Config *cfg)" << "::Error reading from config object." << endl; } potential = vec(nGrid); // Setting the potential for(int j=0; j<nGrid; j++){ vec r = grid.at(j); double r2 = 0; for(int i=0; i<dim; i++){ r2 += r(i)*r(i); } potential(j) = - Z/sqrt(r2 + b*b); } }
double a3_pot(double r) { double V_0 = -60.0 * pow(10,6), r_0 = 3.0 * pow(10,-15), a_0 = 0.4 * pow(10,-15); return potential(r, r_0, a_0, V_0); }
double find_minimum(double *x, double *y, int i) { double dx = 0.001; double xmax = 1.0; double xcur = 0.0; double pcur = 0.0; double xopt = 0.0; double popt = 0.0; while (dx > 1e-9) { while (xcur < xmax) { pcur = potential(x, y, i, xcur); // printf("%f, %f, %f\n", xcur, y[i], pcur); if (pcur < popt) { xopt = xcur; popt = pcur; } xcur += dx; } xcur = xopt-dx; xmax = xopt+dx; dx /= 10.0; } if (xopt > 1.0) { xopt -= 1.0; } else if (xopt < 0.0) { xopt += 1.0; } return xopt; }
/*Function of the 1th (radial) momentum component differential equation for the geodesics. ${p1}^{dot} = f1(x^{\alpha},p^{\alpha})$.*/ mydbl geodesic_equation_r(gsl_spline *spline1, gsl_interp_accel *acc1, gsl_spline *spline2, gsl_interp_accel *acc2, mydbl p0, mydbl pr, mydbl x0, mydbl r) { double t = (double)(1.0*x0/C); mydbl a = (mydbl) 1.0*interpolator(spline1, t, acc1); mydbl adot = (mydbl) 1.0*interpolator(spline2, t, acc2); mydbl f = - (der_potential(r)*p0*p0)/(a*a*C*C*(1.0 - 2.0*potential(r)/(C*C))) - (2.0*adot*p0*pr)/(C*a) + (der_potential(r)/(C*C))*(pr*pr)/(1.0 - 2.0*potential(r)/(C*C)); return f; }
int main(int, char **) { FILE *o = fopen("paper/figs/constrained-water.dat", "w"); Functional f = OfEffectivePotential(SaftFluidSlow(water_prop.lengthscale, water_prop.epsilonAB, water_prop.kappaAB, water_prop.epsilon_dispersion, water_prop.lambda_dispersion, water_prop.length_scaling, 0)); double mu_satp = find_chemical_potential(f, water_prop.kT, water_prop.liquid_density); Lattice lat(Cartesian(width,0,0), Cartesian(0,width,0), Cartesian(0,0,zmax)); GridDescription gd(lat, 0.1); Grid potential(gd); Grid constraint(gd); constraint.Set(notinwall); f = constrain(constraint, OfEffectivePotential(SaftFluidSlow(water_prop.lengthscale, water_prop.epsilonAB, water_prop.kappaAB, water_prop.epsilon_dispersion, water_prop.lambda_dispersion, water_prop.length_scaling, mu_satp))); Minimizer min = Precision(0, PreconditionedConjugateGradient(f, gd, water_prop.kT, &potential, QuadraticLineMinimizer)); potential = water_prop.liquid_density*constraint + water_prop.vapor_density*VectorXd::Ones(gd.NxNyNz); //potential = water_prop.liquid_density*VectorXd::Ones(gd.NxNyNz); potential = -water_prop.kT*potential.cwise().log(); const int numiters = 50; for (int i=0;i<numiters && min.improve_energy(true);i++) { fflush(stdout); Grid density(gd, EffectivePotentialToDensity()(water_prop.kT, gd, potential)); density.epsNative1d("paper/figs/1d-constrained-plot.eps", Cartesian(0,0,0), Cartesian(0,0,zmax), water_prop.liquid_density, 1, "Y axis: , x axis: "); } min.print_info(); double energy = min.energy()/width/width; printf("Energy is %.15g\n", energy); double N = 0; { Grid density(gd, EffectivePotentialToDensity()(water_prop.kT, gd, potential)); for (int i=0;i<gd.NxNyNz;i++) N += density[i]*gd.dvolume; } N = N/width/width; printf("N is %.15g\n", N); Grid density(gd, EffectivePotentialToDensity()(water_prop.kT, gd, potential)); density.epsNative1d("paper/figs/1d-constrained-plot.eps", Cartesian(0,0,0), Cartesian(0,0,zmax), water_prop.liquid_density, 1, "Y axis: , x axis: "); //potential.epsNative1d("hard-wall-potential.eps", Cartesian(0,0,0), Cartesian(0,0,zmax), 1, 1); fclose(o); }
bool finalState(HyperRectangle* rect) { double points[16][4] = { {rect->dims[0].min, rect->dims[1].min, rect->dims[2].min, rect->dims[3].min}, {rect->dims[0].min, rect->dims[1].min, rect->dims[2].min, rect->dims[3].max}, {rect->dims[0].min, rect->dims[1].min, rect->dims[2].max, rect->dims[3].min}, {rect->dims[0].min, rect->dims[1].min, rect->dims[2].max, rect->dims[3].max}, {rect->dims[0].min, rect->dims[1].max, rect->dims[2].min, rect->dims[3].min}, {rect->dims[0].min, rect->dims[1].max, rect->dims[2].min, rect->dims[3].max}, {rect->dims[0].min, rect->dims[1].max, rect->dims[2].max, rect->dims[3].min}, {rect->dims[0].min, rect->dims[1].max, rect->dims[2].max, rect->dims[3].max}, {rect->dims[0].max, rect->dims[1].min, rect->dims[2].min, rect->dims[3].min}, {rect->dims[0].max, rect->dims[1].min, rect->dims[2].min, rect->dims[3].max}, {rect->dims[0].max, rect->dims[1].min, rect->dims[2].max, rect->dims[3].min}, {rect->dims[0].max, rect->dims[1].min, rect->dims[2].max, rect->dims[3].max}, {rect->dims[0].max, rect->dims[1].max, rect->dims[2].min, rect->dims[3].min}, {rect->dims[0].max, rect->dims[1].max, rect->dims[2].min, rect->dims[3].max}, {rect->dims[0].max, rect->dims[1].max, rect->dims[2].max, rect->dims[3].min}, {rect->dims[0].max, rect->dims[1].max, rect->dims[2].max, rect->dims[3].max}, }; double maxPotential = potential(points[0][0], points[0][1], points[0][2], points[0][3]); for (int i = 1; i < 16; ++i) { double p = potential(points[i][0], points[i][1], points[i][2], points[i][3]); if (p > maxPotential) maxPotential = p; } hyperrectangle_to_file(f_final, rect,2); printf("---> potential of final state = %f\n", maxPotential); return maxPotential < 1; }
double run_walls(double reduced_density, const char *name, Functional fhs, double teff) { double kT = teff; if (kT == 0) kT = 1; Functional f = OfEffectivePotential(fhs); const double zmax = width + 2*spacing; Lattice lat(Cartesian(dw,0,0), Cartesian(0,dw,0), Cartesian(0,0,zmax)); GridDescription gd(lat, dx); Grid constraint(gd); constraint.Set(notinwall); f = constrain(constraint, f); Grid potential(gd); potential = pow(2,-5.0/2.0)*(reduced_density*constraint + 1e-4*reduced_density*VectorXd::Ones(gd.NxNyNz)); potential = -kT*potential.cwise().log(); const double approx_energy = fhs(kT, reduced_density*pow(2,-5.0/2.0))*dw*dw*width; const double precision = fabs(approx_energy*1e-11); printf("\tMinimizing to %g absolute precision from %g from %g...\n", precision, approx_energy, kT); fflush(stdout); Minimizer min = Precision(precision, PreconditionedConjugateGradient(f, gd, kT, &potential, QuadraticLineMinimizer)); took("Setting up the variables"); if (strcmp(name, "hard") != 0 && false) { printf("For now, SoftFluid doesn't work properly, so we're skipping the\n"); printf("minimization at temperature %g.\n", teff); } else { for (int i=0;min.improve_energy(false) && i<100;i++) { } } took("Doing the minimization"); min.print_info(); Grid density(gd, EffectivePotentialToDensity()(kT, gd, potential)); //printf("# per area is %g at filling fraction %g\n", density.sum()*gd.dvolume/dw/dw, eta); char *plotname = (char *)malloc(1024); sprintf(plotname, "papers/fuzzy-fmt/figs/walls%s-%06.4f-%04.2f.dat", name, teff, reduced_density); z_plot(plotname, Grid(gd, density*pow(2,5.0/2.0))); free(plotname); took("Plotting stuff"); printf("density %g gives ff %g for reduced density = %g and T = %g\n", density(0,0,gd.Nz/2), density(0,0,gd.Nz/2)*4*M_PI/3, reduced_density, teff); return density(0, 0, gd.Nz/2)*4*M_PI/3; // return bulk filling fraction }
double solve_even(double h, double x_right, double E){ fp = fopen( "output.txt", "w" ); /* boundary condition */ x = x_left; psi[0] = 1; psi[1] = 1 + pow(h, 2)/2*potential(x_left, E) + pow(h, 4)/24*(2 + pow(potential(x_left, E), 2)); printf( "%f %f\n%f %f\n ", x_left, psi[0], x_left + h, psi[1] ); fprintf(fp, "%e %e\n%e %e\n ", x_left, psi[0], x_left + h, psi[1]); /* recursion */ while (x <= x_right) { x += h; psi[2] = ((2 + 5 * pow(h, 2) * potential(x, E)/6.0)*psi[1] - (1.0 - pow(h, 2) * potential(x - h, E)/12.0)*psi[0])/(1 - pow(h, 2) * potential(x + h, E)/12.0); printf("%f %f\n ", x + h, psi[2]); fprintf(fp, "%e %e\n ", x+h, psi[2]); psi[0] = psi[1]; psi[1] = psi[2]; } fclose( fp ); return 0; }
int mem_pool_alloc(struct mem_pool * pool, size_t size) { size_t sz = size >= ND_MIN_SZ ? size : ND_MIN_SZ; sz = IS_POW2(sz) ? sz : NEXT_POW2(sz); printf("aligning requested size %d to %d...\n", size, sz); unsigned order = pool->order + 4 - LOG2(sz); printf("requested order is %d\n", order); unsigned i = 0, rval = 0; if (!potential(pool, i, order)) { return -1; } for (;;) { printf("checking node %d ...\n", i); struct node * n = &pool->nl[i]; if (n->status == FREE && HEIGHT(i) == order) { n->status = FULL; mark_parent(pool, i); while (i < pool->valid_nr) { rval = i; i = LEFT(i); } return rval - LEFT_LEAF(pool->order); //good } else if (potential(pool, LEFT(i), order)) { i = LEFT(i); } else if (potential(pool, RIGHT(i), order)) { i = RIGHT(i); } else { break; } } return -1; }
//Function utilizing the function tqli() in lib.cpp to calculate eigenvalues and eigenvectors void tqliEigensolver(double *off_diagonal, double *diagonal, double **output_matrix, int n, double step_length, double omega_r,double(*potential)(double,int,double)) { double constant_diagonal = 2./(step_length*step_length); double constant_off_diagonal = -1./(step_length*step_length); for(int i = 0; i < n; i++){ diagonal[i] = constant_diagonal+potential(step_length,i+1,omega_r); off_diagonal[i] = constant_off_diagonal; output_matrix[i][i] = 1; for(int j = i + 1; j < n; j++){ output_matrix[i][j] = 0; } } tqli(diagonal, off_diagonal, n, output_matrix); }
int PlasmaBunch::interaction(int m, int sum){ register int i, j,k; static Vector_3 r; int ret=Plasma::interaction(m,sum); // now interacting with bunch particles int type=0; // ion-ion double dEcoul,dEpotent,dQuant; double df; for(i=0;i<(m<0 ? n : m+1);i++){ if(i>=ni)type|=0x1;// setting electron-? interaction type else type&=0x2;// setting ion-? interaction type if(is_ion)type&=0x1; // setting ?-ion interaction type else type|=0x2;// setting ?-electron interaction type for(j=0;j<nb;j++){ for(k=0;k<3;k++){ // determining the closest //distance and correspondent direction r[k]=xx[i][k]-xb[j][k]; if(r[k]>L/2)r[k]-=L; if(r[k]<-L/2)r[k]+=L; } double R=r.norm(); if(R<1e-20)printf("Got small distance to bunch (%d,b%d) !\n",i,j); r/=R; dEcoul=qb/R; df=potential(type,R,dEpotent,dQuant); for(k=0;k<3;k++){ // to avoid vector copying f[i][k]+=df*r[k]; //f[j][k]-=df*r[k]; } Ecoul+=dEcoul; Quant+=dQuant; Epotent+=dEpotent; } } return ret; }
int main(int argc,char **argv) { int i,n=100; double x0 = 0.75; for (i=0 ; i<n ; i++) { double x = i/((double)(n-1)); printf("%f %f %f\n", x, potential(x,x0), potential_derivative(x,x0)); } return EXIT_SUCCESS; }
bool shouldStop(double state[NUM_DIMS], double simTime, void* p) { bool rv = false; double pot = potential(state[0], state[1], state[2], state[3]); double maxTime = 2.0; if (pot < 1) { rv = true; double* stopTime = (double*)p; *stopTime = simTime; } if (simTime >= maxTime) { rv = true; double* stopTime = (double*)p; *stopTime = -1; } return rv; }
void run_with_eta(double eta, const char *name, Functional fhs) { // Generates a data file for the pair distribution function, for filling fraction eta // and distance of first sphere from wall of z0. Data saved in a table such that the // columns are x values and rows are z1 values. printf("Now starting run_with_eta with eta = %g name = %s\n", eta, name); Functional f = OfEffectivePotential(fhs + IdealGas()); double mu = find_chemical_potential(f, 1, eta/(4*M_PI/3)); f = OfEffectivePotential(fhs + IdealGas() + ChemicalPotential(mu)); Lattice lat(Cartesian(width,0,0), Cartesian(0,width,0), Cartesian(0,0,width)); GridDescription gd(lat, dx); Grid potential(gd); Grid constraint(gd); constraint.Set(notinsphere); f = constrain(constraint, f); potential = (eta*constraint + 1e-4*eta*VectorXd::Ones(gd.NxNyNz))/(4*M_PI/3); potential = -potential.cwise().log(); const double approx_energy = (fhs + IdealGas() + ChemicalPotential(mu))(1, eta/(4*M_PI/3))*uipow(width,3); const double precision = fabs(approx_energy*1e-10); //printf("Minimizing to %g absolute precision...\n", precision); { // Put mimizer in block so as to free it when we finish minimizing to save memory. Minimizer min = Precision(precision, PreconditionedConjugateGradient(f, gd, 1, &potential, QuadraticLineMinimizer)); for (int i=0;min.improve_energy(true) && i<100;i++) { double peak = peak_memory()/1024.0/1024; double current = current_memory()/1024.0/1024; printf("Peak memory use is %g M (current is %g M)\n", peak, current); fflush(stdout); } took("Doing the minimization"); } Grid density(gd, EffectivePotentialToDensity()(1, gd, potential)); Grid gsigma(gd, gSigmaA(1.0)(1, gd, density)); Grid nA(gd, ShellConvolve(2)(1, density)/(4*M_PI*4)); Grid n3(gd, StepConvolve(1)(1, density)); Grid nbar_sokolowski(gd, StepConvolve(1.6)(1, density)); nbar_sokolowski /= (4.0/3.0*M_PI*ipow(1.6, 3)); // Create the walls directory if it doesn't exist. if (mkdir("papers/pair-correlation/figs/walls", 0777) != 0 && errno != EEXIST) { // We failed to create the directory, and it doesn't exist. printf("Failed to create papers/pair-correlation/figs/walls: %s", strerror(errno)); exit(1); // fail immediately with error code } // here you choose the values of z0 to use // dx is the resolution at which we compute the density. char *plotname = new char[4096]; for (double z0 = 2.1; z0 < 4.5; z0 += 2.1) { // For each z0, we now pick one of our methods for computing the // pair distribution function: for (int version = 0; version < numplots; version++) { sprintf(plotname, "papers/pair-correlation/figs/triplet%s-%s-%04.2f-%1.2f.dat", name, fun[version], eta, z0); FILE *out = fopen(plotname,"w"); FILE *xfile = fopen("papers/pair-correlation/figs/triplet-x.dat","w"); FILE *zfile = fopen("papers/pair-correlation/figs/triplet-z.dat","w"); // the +1 for z0 and z1 are to shift the plot over, so that a sphere touching the wall // is at z = 0, to match with the monte carlo data const Cartesian r0(0,0,z0); for (double x = 0; x < 4; x += dx) { for (double z1 = -4; z1 <= 9; z1 += dx) { const Cartesian r1(x,0,z1); double g2 = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out, "%g\t", g3); fprintf(xfile, "%g\t", x); fprintf(zfile, "%g\t", z1); } fprintf(out, "\n"); fprintf(xfile, "\n"); fprintf(zfile, "\n"); } fclose(out); fclose(xfile); fclose(zfile); } } delete[] plotname; took("Dumping the triplet dist plots"); const double ds = 0.01; // step size to use in path plots, FIXME increase for publication! const double delta = .1; //this is the value of radius of the //particle as it moves around the contact //sphere on its path char *plotname_path = new char[4096]; for (int version = 0; version < numplots; version++) { sprintf(plotname_path, "papers/pair-correlation/figs/triplet%s-path-%s-%04.2f.dat", name, fun[version], eta); FILE *out_path = fopen(plotname_path, "w"); if (!out_path) { fprintf(stderr, "Unable to create file %s!\n", plotname_path); return; } sprintf(plotname_path, "papers/pair-correlation/figs/triplet-back-contact-%s-%04.2f.dat", fun[version], eta); FILE *out_back = fopen(plotname_path, "w"); if (!out_back) { fprintf(stderr, "Unable to create file %s!\n", plotname_path); return; } fprintf(out_path, "# unused\tg3\tz\tx\n"); fprintf(out_back, "# unused\tg3\tz\tx\n"); const Cartesian r0(0,0, 2.0+delta); const double max_theta = M_PI*2.0/3; for (double z = 7; z >= 2*(2.0 + delta); z-=ds) { const Cartesian r1(0,0,z); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double z = -7; z <= -(2.0 + delta); z+=ds) { const Cartesian r1(0,0,z); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } const double dtheta = ds/2; for (double theta = 0; theta <= max_theta; theta += dtheta){ const Cartesian r1((2.0+delta)*sin(theta), 0, (2.0+delta)*(1+cos(theta))); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double theta = 0; theta <= max_theta; theta += dtheta){ const Cartesian r1((2.0+delta)*sin(theta), 0,-(2.0+delta)*cos(theta)); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double x = (2.0+delta)*sqrt(3)/2; x<=6; x+=ds){ const Cartesian r1(x, 0, 1.0+delta/2); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } fclose(out_path); fclose(out_back); } for (int version = 0; version < numplots; version++) { sprintf(plotname_path, "papers/pair-correlation/figs/triplet-path-inbetween-%s-%04.2f.dat", fun[version], eta); FILE *out_path = fopen(plotname_path, "w"); if (!out_path) { fprintf(stderr, "Unable to create file %s!\n", plotname_path); return; } sprintf(plotname_path, "papers/pair-correlation/figs/triplet-back-inbetween-%s-%04.2f.dat", fun[version], eta); FILE *out_back = fopen(plotname_path, "w"); if (!out_back) { fprintf(stderr, "Unable to create file %s!\n", plotname_path); return; } fprintf(out_path, "# unused\tg3\tz\tx\n"); fprintf(out_back, "# unused\tg3\tz\tx\n"); const Cartesian r0(0,0, 4.0+2*delta); const double max_theta = M_PI; for (double z = 11; z >= 3*(2.0 + delta); z-=ds) { const Cartesian r1(0,0,z); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double z = -10; z <= -(2.0 + delta); z+=ds) { const Cartesian r1(0,0,z); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } const double dtheta = ds/2; for (double theta = 0; theta <= max_theta; theta += dtheta){ const Cartesian r1((2.0+delta)*sin(theta), 0, (2.0+delta)*(2+cos(theta))); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double theta = 0; theta <= max_theta; theta += dtheta){ const Cartesian r1((2.0+delta)*sin(theta), 0, -(2.0+delta)*cos(theta)); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } for (double x = 0; x>=-6; x-=ds){ const Cartesian r1(x, 0, 2.0+delta); double g2_path = pairdists[version](gsigma, density, nA, n3, nbar_sokolowski, r0, r1); double n_bulk = (3.0/4.0/M_PI)*eta; double g3 = g2_path*density(r0)*density(r1)/n_bulk/n_bulk; fprintf(out_path,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); fprintf(out_back,"0\t%g\t%g\t%g\n", g3, r1[2], r1[0]); } fclose(out_path); fclose(out_back); } delete[] plotname_path; }
pair<Cost,Flow> mincost(Index s, Index t, Flow f = InfCapacity, bool bellmanFord = false) { int n = g.size(); vector<Cost> dist(n); vector<Index> prev(n); vector<Index> prevEdge(n); pair<Cost,Flow> total = make_pair(0, 0); vector<Cost> potential(n); while(f > 0) { fill(dist.begin(), dist.end(), InfCost); if(bellmanFord || total.second == 0) { dist[s] = 0; for(int k=0; k<n; k++) { bool update = false; for(int i=0; i<n; i++) if(dist[i] != InfCost) for(Index ei = 0; ei < (Index)g[i].size(); ei ++) { const Edge &e = g[i][ei]; if(e.capacity <= 0) continue; Index j = e.to; Cost d = dist[i] + e.cost; if(dist[j] > d ) { dist[j] = d; prev[j] = i; prevEdge[j] = ei; update = true; } } if(!update) break; } } else { vector<bool> vis(n); priority_queue<pair<Cost,Index> > q; q.push(make_pair(-0, s)); dist[s] = 0; while(!q.empty()) { Index i = q.top().second; q.pop(); if(vis[i]) continue; vis[i] = true; for(Index ei = 0; ei < (Index)g[i].size(); ei ++) { const Edge &e = g[i][ei]; if(e.capacity <= 0) continue; Index j = e.to; Cost d = dist[i] + e.cost + potential[i] - potential[j]; if(d < dist[i]) d = dist[i]; if(dist[j] > d) { dist[j] = d; prev[j] = i; prevEdge[j] = ei; q.push(make_pair(-d, j)); } } } } if(dist[t] == InfCost) break; if(!bellmanFord) for(Index i = 0; i < n; i ++) potential[i] += dist[i]; Flow d = f; Cost distt = 0; for(Index v = t; v != s; ) { Index u = prev[v]; const Edge &e = g[u][prevEdge[v]]; d = min(d, e.capacity); distt += e.cost; v = u; } f -= d; total.first += d * distt; total.second += d; for(Index v = t; v != s; v = prev[v]) { Edge &e = g[prev[v]][prevEdge[v]]; e.capacity -= d; g[e.to][e.rev].capacity += d; } } return total; }
double surface_tension(Minimizer min, Functional f0, LiquidProperties prop, bool verbose, const char *plotname) { int numptspersize = 100; int size = 64; const int gas_size = 10; Lattice lat(Cartesian(1,0,0), Cartesian(0,1,0), Cartesian(0,0,size*prop.lengthscale)); GridDescription gd(lat, 1, 1, numptspersize*size); Grid potential(gd); // Set the density to range from vapor to liquid const double Veff_liquid = -prop.kT*log(prop.liquid_density); const double Veff_gas = -prop.kT*log(prop.vapor_density); for (int i=0; i<gd.NxNyNz*gas_size/size; i++) potential[i] = Veff_gas; for (int i=gd.NxNyNz*gas_size/size; i<gd.NxNyNz; i++) potential[i] = Veff_liquid; // Enable the following line for debugging... //f0.run_finite_difference_test("f0", prop.kT, potential); min.minimize(f0, gd, &potential); while (min.improve_energy(verbose)) if (verbose) { printf("Working on liberated interface...\n"); fflush(stdout); } const double Einterface = f0.integral(prop.kT, potential); double Ninterface = 0; Grid interface_density(gd, EffectivePotentialToDensity()(prop.kT, gd, potential)); for (int i=0;i<gd.NxNyNz;i++) Ninterface += interface_density[i]*gd.dvolume; if (verbose) printf("Got interface energy of %g.\n", Einterface); for (int i=0; i<gd.NxNyNz; i++) potential[i] = Veff_gas; min.minimize(f0, gd, &potential); while (min.improve_energy(verbose)) if (verbose) { printf("Working on gas...\n"); fflush(stdout); } const double Egas = f0.integral(prop.kT, potential); double Ngas = 0; { Grid density(gd, EffectivePotentialToDensity()(prop.kT, gd, potential)); for (int i=0;i<gd.NxNyNz;i++) Ngas += density[i]*gd.dvolume; } for (int i=0; i<gd.NxNyNz; i++) potential[i] = Veff_liquid; if (verbose) { printf("\n\n\nWorking on liquid...\n"); fflush(stdout); } min.minimize(f0, gd, &potential); while (min.improve_energy(verbose)) if (verbose) { printf("Working on liquid...\n"); fflush(stdout); } const double Eliquid = f0.integral(prop.kT, potential); double Nliquid = 0; { Grid density(gd, EffectivePotentialToDensity()(prop.kT, gd, potential)); for (int i=0;i<gd.NxNyNz;i++) Nliquid += density[i]*gd.dvolume; } const double X = Ninterface/Nliquid; // Fraction of volume effectively filled with liquid. const double surface_tension = (Einterface - Eliquid*X - Egas*(1-X))/2; if (verbose) { printf("\n\n"); printf("interface energy is %.15g\n", Einterface); printf("gas energy is %.15g\n", Egas); printf("liquid energy is %.15g\n", Eliquid); printf("Ninterface/liquid/gas = %g/%g/%g\n", Ninterface, Nliquid, Ngas); printf("X is %g\n", X); printf("surface tension is %.10g\n", surface_tension); } if (plotname) interface_density.Dump1D(plotname, Cartesian(0,0,0), Cartesian(0,0,size*prop.lengthscale)); return surface_tension; }
int Plasma::interaction(int m, int sum){ register int i, j,k; static Vector_3 r; //static Vector_3 df; int type=0; // ion-ion for(i=(m<0 ? 0 : m);i<n;i++){ for(k=0;k<3;k++){ f[i][k]=0; // reducing to elementary cell if(x[i][k]>0)xx[i][k]=amod1(x[i][k]+L/2,L)-L/2; else xx[i][k]=amod1(x[i][k]-L/2,L)+L/2; } if(m>=0)break; } Quant=Ecoul=0; double dEcoul,dEpotent,dQuant; double df; if(!is_matr || m<0)Epotent=0; for(i=0;i<(m<0 ? n : m+1);i++){ if(i>=ni)type|=0x1;// setting electron-? interaction type type&=0x1; // setting ?-ion interaction type for(j=((m<0 || i==m) ? i+1: m); j<n;j++){ if(j>=ni)type|=0x2;// setting ?-electron interaction type //r=xx[i]-xx[j]; for(k=0;k<3;k++){ // determining the closest //distance and correspondent direction r[k]=xx[i][k]-xx[j][k]; if(r[k]>L/2)r[k]-=L; if(r[k]<-L/2)r[k]+=L; } double R=r.norm(); if(R<1e-20){ printf("Got small distance (%d,%d) !\n",i,j); } r/=R; dEcoul=-1/R; if(type==ELCELC || type ==IONION){ dEcoul=-dEcoul; if(write_distr){ if(non_symm && type==IONION)DRRpp.point(R,1.); else DRRee.point(R,1.); } } else if(write_distr)DRRep.point(R,1.); df=potential(type,R,dEpotent,dQuant); ///df=PotentialKELBG(type,R,dEpotent,dQuant); //f[i]+=df; //f[j]-=df; for(k=0;k<3;k++){ // to avoid vector copying f[i][k]+=df*r[k]; f[j][k]-=df*r[k]; } Ecoul+=dEcoul; Quant+=dQuant; if(is_matr && m>=0)Epotent+=dEpotent-(*umatr)(i,j); else Epotent+=dEpotent; if(is_matr){ if(m>=0){ int l=(i< m ? i : j); (*umatr)(l,l)=(*umatr)(i,j); //(l,l) used for storing temporary //fucktmp[l]=(*umatr)(i,j); //printf("%d <- (%d, %d)[%f]\n",l,i,j,fucktmp[l]); } (*umatr)(i,j)=dEpotent; } if(m>=0 && i!=m)break; } } if(is_matr && m>=0 && sum){ Epotent=0; for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ Epotent+=(*umatr)(i,j); } } } return 0; }
/*To set the initial value of pr, it must hold $g_{\mu\nu}p^{\mu}p^{\nu} = 0$. This factor multiplies p0 to guarantee that p1 fulfill the null geodesic condition.*/ mydbl condition_factor(mydbl r, double a) { return (mydbl)(1.0/a)*sqrtl((1.0+2.0*potential(r)/(C*C))/(1.0 - 2.0*potential(r)/(C*C))); }
void schroedinger(int n,double x,double y[2],double yp[2]) { /* Calculate first order derivatives for R-K4 algorithm*/ yp[0] = y[1]; yp[1] = 5.1363071e13 * 0.5110e6 * (potential(x) - E) * y[0]; }
int main(int argc, char *argv[]) { if (argc > 1) { if (sscanf(argv[1], "%lg", &diameter) != 1) { printf("Got bad argument: %s\n", argv[1]); return 1; } diameter *= nm; using_default_diameter = false; printf("Diameter is %g bohr\n", diameter); } const double ptransition =(3.0*M_PI-4.0)*(diameter/2.0)/2.0; const double dmax = ptransition + 0.6*nm; double zmax = 2*diameter+dmax+2*nm; double ymax = 2*diameter+dmax+2*nm; char *datname = new char[1024]; snprintf(datname, 1024, "papers/water-saft/figs/four-rods-in-water-%04.1fnm.dat", diameter/nm); FILE *o = fopen(datname, "w"); delete[] datname; Functional f = OfEffectivePotential(WaterSaft(new_water_prop.lengthscale, new_water_prop.epsilonAB, new_water_prop.kappaAB, new_water_prop.epsilon_dispersion, new_water_prop.lambda_dispersion, new_water_prop.length_scaling, 0)); double n_1atm = pressure_to_density(f, new_water_prop.kT, atmospheric_pressure, 0.001, 0.01); double mu_satp = find_chemical_potential(f, new_water_prop.kT, n_1atm); f = OfEffectivePotential(WaterSaft(new_water_prop.lengthscale, new_water_prop.epsilonAB, new_water_prop.kappaAB, new_water_prop.epsilon_dispersion, new_water_prop.lambda_dispersion, new_water_prop.length_scaling, mu_satp)); const double EperVolume = f(new_water_prop.kT, -new_water_prop.kT*log(n_1atm)); const double EperCell = EperVolume*(zmax*ymax - 4*0.25*M_PI*diameter*diameter)*width; //Functional X = Xassociation(new_water_prop.lengthscale, new_water_prop.epsilonAB, // new_water_prop.kappaAB, new_water_prop.epsilon_dispersion, // new_water_prop.lambda_dispersion, // new_water_prop.length_scaling); Functional S = OfEffectivePotential(EntropySaftFluid2(new_water_prop.lengthscale, new_water_prop.epsilonAB, new_water_prop.kappaAB, new_water_prop.epsilon_dispersion, new_water_prop.lambda_dispersion, new_water_prop.length_scaling)); //dmax, dstep already in bohrs (so it doesn't need to be converted from nm) double dstep = 0.25*nm; for (distance=0.0*nm; distance<=dmax; distance += dstep) { if ((distance >= ptransition - 0.5*nm) && (distance <= ptransition + 0.05*nm)) { if (distance >= ptransition - 0.25*nm) { dstep = 0.03*nm; } else { dstep = 0.08*nm; } } else { dstep = 0.25*nm; } Lattice lat(Cartesian(width,0,0), Cartesian(0,ymax,0), Cartesian(0,0,zmax)); GridDescription gd(lat, 0.2); printf("Grid is %d x %d x %d\n", gd.Nx, gd.Ny, gd.Nz); Grid potential(gd); Grid constraint(gd); constraint.Set(notinwall); f = OfEffectivePotential(WaterSaft(new_water_prop.lengthscale, new_water_prop.epsilonAB, new_water_prop.kappaAB, new_water_prop.epsilon_dispersion, new_water_prop.lambda_dispersion, new_water_prop.length_scaling, mu_satp)); f = constrain(constraint, f); printf("Diameter is %g bohr (%g nm)\n", diameter, diameter/nm); printf("Distance between rods = %g bohr (%g nm)\n", distance, distance/nm); potential = new_water_prop.liquid_density*constraint + 400*new_water_prop.vapor_density*VectorXd::Ones(gd.NxNyNz); //potential = new_water_prop.liquid_density*VectorXd::Ones(gd.NxNyNz); potential = -new_water_prop.kT*potential.cwise().log(); const double surface_tension = 5e-5; // crude guess from memory... const double surfprecision = 1e-5*(4*M_PI*diameter)*width*surface_tension; // five digits accuracy const double bulkprecision = 1e-12*fabs(EperCell); // but there's a limit on our precision for small rods const double precision = bulkprecision + surfprecision; printf("Precision limit from surface tension is to %g based on %g and %g\n", precision, surfprecision, bulkprecision); Minimizer min = Precision(precision, PreconditionedConjugateGradient(f, gd, new_water_prop.kT, &potential, QuadraticLineMinimizer)); const int numiters = 200; for (int i=0;i<numiters && min.improve_energy(false);i++) { fflush(stdout); // { // double peak = peak_memory()/1024.0/1024; // double current = current_memory()/1024.0/1024; // printf("Peak memory use is %g M (current is %g M)\n", peak, current); // } } Grid potential2(gd); Grid constraint2(gd); constraint2.Set(notinmiddle); potential2 = new_water_prop.liquid_density*(constraint2.cwise()*constraint) + 400*new_water_prop.vapor_density*VectorXd::Ones(gd.NxNyNz); potential2 = -new_water_prop.kT*potential2.cwise().log(); Minimizer min2 = Precision(1e-12, PreconditionedConjugateGradient(f, gd, new_water_prop.kT, &potential2, QuadraticLineMinimizer)); for (int i=0;i<numiters && min2.improve_energy(false);i++) { fflush(stdout); // { // double peak = peak_memory()/1024.0/1024; // double current = current_memory()/1024.0/1024; // printf("Peak memory use is %g M (current is %g M)\n", peak, current); // } } char *plotnameslice = new char[1024]; snprintf(plotnameslice, 1024, "papers/water-saft/figs/four-rods-%04.1f-%04.2f.dat", diameter/nm, distance/nm); printf("The bulk energy per cell should be %g\n", EperCell); double energy; if (min.energy() < min2.energy()) { energy = (min.energy() - EperCell)/width; Grid density(gd, EffectivePotentialToDensity()(new_water_prop.kT, gd, potential)); printf("Using liquid in middle initially.\n"); plot_grids_yz_directions(plotnameslice, density); { double peak = peak_memory()/1024.0/1024; double current = current_memory()/1024.0/1024; printf("Peak memory use is %g M (current is %g M)\n", peak, current); } } else { energy = (min2.energy() - EperCell)/width; Grid density(gd, EffectivePotentialToDensity()(new_water_prop.kT, gd, potential2)); printf("Using vapor in middle initially.\n"); plot_grids_yz_directions(plotnameslice, density); { double peak = peak_memory()/1024.0/1024; double current = current_memory()/1024.0/1024; printf("Peak memory use is %g M (current is %g M)\n", peak, current); } } printf("Liquid energy is %.15g. Vapor energy is %.15g\n", min.energy(), min2.energy()); fprintf(o, "%g\t%.15g\n", distance/nm, energy); //Grid entropy(gd, S(new_water_prop.kT, potential)); //Grid Xassoc(gd, X(new_water_prop.kT, density)); //plot_grids_y_direction(plotnameslice, density, energy_density, entropy, Xassoc); //Grid energy_density(gd, f(new_water_prop.kT, gd, potential)); delete[] plotnameslice; } fclose(o); { double peak = peak_memory()/1024.0/1024; double current = current_memory()/1024.0/1024; printf("Peak memory use is %g M (current is %g M)\n", peak, current); } }
int main(int argc, char **argv) { printf("Mapping & Scaffolding module.\n"); if(argc == 1) { usage(); return 0; } int c = 0; int inpseq, outseq; //char optarg[256]; int mode = -1; //char temp[100]; while((c = getopt(argc, argv, "s:g:p:L:t:i:u:c:P:K:MSBDO")) != EOF) { switch(c) { case 'M': mode = MAPPING; break; case 'S': mode = SCAFF; break; case 'B': mode = BUNDLE; break; case 'D': mode = PREPARE; break; case 'O': mode = POTENT; break; case 's': inpseq = 1; shortrdsfile = (char *)ckalloc(256 * sizeof(char)); strcpy(shortrdsfile, optarg); break; case 'g': outseq = 1; graphfile = (char *)ckalloc(256 * sizeof(char)); strcpy(graphfile, optarg); break; case 'p': thrd_num = atoi(optarg); break; case 'L': ctg_short = atoi(optarg); break; case 'P': OverlapPercent = atof (optarg); break; case 't': close_threshold = atof (optarg); break; case 'i': ins_size_var = atoi (optarg); break; case 'u': bund_threshold = atoi (optarg); break; case 'c': ctg_file = (char *)ckalloc(256 * sizeof(char)); strcpy(ctg_file, optarg); break; case 'K': overlaplen = atoi(optarg); break; case 'h': usage(); break; case '?': usage(); exit(1); default: usage(); exit(1); } } if(mode == -1) { usage(); exit(1); } else if(mode == MAPPING) { printf("[%s]Mapping mode selected .\n", __FUNCTION__); if(outseq == 0 || inpseq == 0) { usage(); exit(1); } call_align(); } else if(mode == SCAFF) { printf("[%s]Scaffolding mode selected .\n", __FUNCTION__); if(outseq == 0) { usage(); exit(1); } call_scaffold(); } else if(mode == BUNDLE) { printf("[%s]Bundling mode selected .\n", __FUNCTION__); if(outseq == 0) { usage(); exit(1); } call_bundle(); } else if(mode == PREPARE) { printf("[%s]Data prepare mode selected .\n", __FUNCTION__); if(outseq == 0 || ctg_file == NULL) { usage(); exit(1); } data_prepare(); } else if(mode == POTENT) { printf("[%s]Potential analysis mode selected .\n", __FUNCTION__) ; if(outseq == NULL) { usage(); exit(1); } potential(); } return 0; }
/* Lagrangiana euclidea */ static double HOeLagrangian(double x1, double x2) { return M/2*(x2 - x1)*(x2 - x1) + (potential(x1) + potential(x2))/2; }
int main( int argc, const char *argv[] ) { int i, j; PLFLT xx, yy, argx, argy, distort; static PLINT mark = 1500, space = 1500; PLFLT **z, **w; PLFLT xg1[XPTS], yg1[YPTS]; PLcGrid cgrid1; PLcGrid2 cgrid2; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); // Set up function arrays plAlloc2dGrid( &z, XPTS, YPTS ); plAlloc2dGrid( &w, XPTS, YPTS ); for ( i = 0; i < XPTS; i++ ) { xx = (double) ( i - ( XPTS / 2 ) ) / (double) ( XPTS / 2 ); for ( j = 0; j < YPTS; j++ ) { yy = (double) ( j - ( YPTS / 2 ) ) / (double) ( YPTS / 2 ) - 1.0; z[i][j] = xx * xx - yy * yy; w[i][j] = 2 * xx * yy; } } // Set up grids cgrid1.xg = xg1; cgrid1.yg = yg1; cgrid1.nx = XPTS; cgrid1.ny = YPTS; plAlloc2dGrid( &cgrid2.xg, XPTS, YPTS ); plAlloc2dGrid( &cgrid2.yg, XPTS, YPTS ); cgrid2.nx = XPTS; cgrid2.ny = YPTS; for ( i = 0; i < XPTS; i++ ) { for ( j = 0; j < YPTS; j++ ) { mypltr( (PLFLT) i, (PLFLT) j, &xx, &yy, NULL ); argx = xx * M_PI / 2; argy = yy * M_PI / 2; distort = 0.4; cgrid1.xg[i] = xx + distort * cos( argx ); cgrid1.yg[j] = yy - distort * cos( argy ); cgrid2.xg[i][j] = xx + distort * cos( argx ) * cos( argy ); cgrid2.yg[i][j] = yy - distort * cos( argx ) * cos( argy ); } } // Plot using identity transform // // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); // plcol0(2); // plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL); // plstyl(1, &mark, &space); // plcol0(3); // plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL); // plstyl(0, &mark, &space); // plcol0(1); // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); // pl_setcontlabelformat( 4, 3 ); pl_setcontlabelparam( 0.006, 0.3, 0.1, 1 ); plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 ); plcol0( 2 ); plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL ); plstyl( 1, &mark, &space ); plcol0( 3 ); plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL ); plstyl( 0, &mark, &space ); plcol0( 1 ); pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" ); pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 ); // Plot using 1d coordinate transform plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 ); plcol0( 2 ); plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr1, (void *) &cgrid1 ); plstyl( 1, &mark, &space ); plcol0( 3 ); plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr1, (void *) &cgrid1 ); plstyl( 0, &mark, &space ); plcol0( 1 ); pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" ); // // pl_setcontlabelparam(0.006, 0.3, 0.1, 1); // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); // plcol0(2); // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, // pltr1, (void *) &cgrid1); // // plstyl(1, &mark, &space); // plcol0(3); // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, // pltr1, (void *) &cgrid1); // plstyl(0, &mark, &space); // plcol0(1); // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); // pl_setcontlabelparam(0.006, 0.3, 0.1, 0); // // Plot using 2d coordinate transform plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 ); plcol0( 2 ); plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr2, (void *) &cgrid2 ); plstyl( 1, &mark, &space ); plcol0( 3 ); plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr2, (void *) &cgrid2 ); plstyl( 0, &mark, &space ); plcol0( 1 ); pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" ); // // pl_setcontlabelparam(0.006, 0.3, 0.1, 1); // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); // plcol0(2); // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, // pltr2, (void *) &cgrid2); // // plstyl(1, &mark, &space); // plcol0(3); // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, // pltr2, (void *) &cgrid2); // plstyl(0, &mark, &space); // plcol0(1); // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); // pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 ); polar(); // // pl_setcontlabelparam(0.006, 0.3, 0.1, 1); // polar(); // pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 ); potential(); // // pl_setcontlabelparam(0.006, 0.3, 0.1, 1); // potential(); // // Clean up plFree2dGrid( z, XPTS, YPTS ); plFree2dGrid( w, XPTS, YPTS ); plFree2dGrid( cgrid2.xg, XPTS, YPTS ); plFree2dGrid( cgrid2.yg, XPTS, YPTS ); plend(); exit( 0 ); }
/*$cp^{0}$ multiplied by this factor allows to obtain the energy for a local inertial observer in this spacetime.*/ mydbl energy_factor(mydbl r) { mydbl g = sqrtl(1.0 + 2.0*potential(r)/(C*C)); return g; }
/*Violation of null geodesics condition $g_{\mu\nu}p^{\mu}p^{\nu} = 0$.*/ mydbl violation(mydbl r, mydbl p0, mydbl pr, double a) { mydbl f = -(1.0+2.0*potential(r)/(C*C))*p0*p0 + (mydbl)(1.0*a*a)*(1.0-2.0*potential(r)/(C*C))*pr*pr; return f; }
void interactionForce( latticeMesh* mesh, scalar Ff[3], scalar* rho, scalar* T, uint id ) { uint i, k; /* // EOS Perturbation. Temporal */ /* scalar r = 1; */ /* if (mesh->mesh.points[id][1] == 0) { */ /* srand(id); */ /* r = (scalar)rand() / RAND_MAX; */ /* r = 0.9 + (1.1-0.9)*r; */ /* } */ scalar F[3] = {0.0, 0.0, 0.0}; // Initialize force term for( i = 0 ; i < 3 ; i++) { Ff[i] = 0 ; } // Do not use unexisting neighbour if( mesh->mesh.isOnBnd[id] == 0 ) { for( k = 1 ; k < mesh->lattice.Q ; k++ ) { int neighId = mesh->mesh.nb[id][ mesh->lattice.reverse[k] ]; scalar alpha = mesh->lattice.weights[k] * potential(mesh, rho[neighId], T[neighId]); for( i = 0 ; i < 3 ; i++ ) { F[i] += alpha * (scalar)mesh->lattice.vel[k][i] ; } } // Extra constant scalar beta = -mesh->EOS.G * potential(mesh, rho[id], T[id]); for( i = 0 ; i < 3 ; i++) { Ff[i] = F[i] * beta; } } }
/* Variazione di azione euclidea conseguente alla modifica di un elemento del * vettore x */ static double deltaS(double *x, int dim, double x_new, int i) { return M*((x[i] - x_new)*(x[(i+1)%dim] + x[(i-1+dim)%dim]) +\ (x_new*x_new - x[i]*x[i])) + potential(x_new) - potential(x[i]); }