static int serial_open (struct tty_struct* tty, struct file* filp) { int line; NkPort* port; NkDevVlink* vlink; line = NKLINE(tty); port = line + serial_port; printk("serial_open tty addr = %p, filp = %p, port =%p\n", tty, filp, port); if (line >= MAX_PORT) { return -ENODEV; } port->count++; if (port->count > 1) { return 0; } port->id = os_ctx->id; tty->driver_data = port; port->stoptx = 0; port->stoprx = 0; port->wakeup = 0; port->sz = 0; port->poss = 0; port->tty = tty; port->vlink = 0; port->xid = 0; port->timer.data = 0; spin_lock_init(&port->lock); /* * console specific initialization. */ if (line == 1) { /* history initialization */ return hist_open(port); } else { /* use vcons driver if possible */ vlink = vcons_lookup(tty); if (vlink) { return vcons_open(port, vlink); } else { return cons_open(port); } } }
static hist_t *lj_domc(model_t *m, const double *beta) { double emin, emax; int istep, iT, jT, acc; double *mctot, *mcacc, *mcamp; double retot = DBL_MIN, reacc = 0; lj_t **lj, *ljtmp; hist_t *hs; /* round emin and emax to multiples of m->de */ emin = (int) (m->nn * m->emin / m->de) * m->de; emax = (int) (m->nn * m->emax / m->de) * m->de; hs = hist_open(m->nT, emin, emax, m->de); /* randomize the initial state */ mtscramble( time(NULL) ); xnew(lj, m->nT); for ( iT = 0; iT < m->nT; iT++ ) { lj[iT] = lj_open(m->nn, m->rho, m->rcdef); lj[iT]->dof = m->nn * D; lj_energy( lj[iT] ); } xnew(mctot, m->nT); xnew(mcacc, m->nT); xnew(mcamp, m->nT); for ( iT = 0; iT < m->nT; iT++ ) { mctot[iT] = DBL_MIN; mcacc[iT] = 0; mcamp[iT] = m->mcamp; } /* do simulations */ for ( istep = 1; istep <= m->nequil + m->nsteps; istep++ ) { for ( iT = 0; iT < m->nT; iT++ ) { acc = lj_metro(lj[iT], mcamp[iT], beta[iT]); mcacc[iT] += acc; mctot[iT] += 1; } if ( m->re ) { /* replica exchange: randomly swap configurations of * two neighboring temperatures */ double dbdE, r; iT = (int) (rand01() * (m->nT - 1)); jT = iT + 1; dbdE = (beta[iT] - beta[jT]) * (lj[iT]->epot - lj[jT]->epot); acc = 0; if ( dbdE >= 0 ) { acc = 1; } else { r = rand01(); if ( r < exp(dbdE) ) { acc = 1; } } if ( acc ) { /* swap the models */ ljtmp = lj[iT], lj[iT] = lj[jT], lj[jT] = ljtmp; } if ( istep > m->nequil ) { reacc += acc; retot += 1; } } if ( istep <= m->nequil ) { /* adjust the MC move amplitude */ if ( istep % m->nstadj == 0 ) { for ( iT = 0; iT < m->nT; iT++ ) { fprintf(stderr, "T %g, mcamp %g, mcacc %g%%\n", 1/beta[iT], mcamp[iT], 100*mcacc[iT]/mctot[iT]); mcamp[iT] *= sqrt( mcacc[iT] / mctot[iT] / 0.5 ); } } continue; } for ( iT = 0; iT < m->nT; iT++ ) { hist_add1(hs, iT, lj[iT]->epot, 1.0, HIST_VERBOSE); } } hist_save(hs, m->fnhis, HIST_ADDAHALF | HIST_NOZEROES | HIST_VERBOSE); fprintf(stderr, "simulation ended, doing WHAM\n"); for ( iT = 0; iT < m->nT; iT++ ) { lj_close( lj[iT] ); } free(mctot); free(mcacc); free(mcamp); return hs; }
int main(void) { lj_t *lj; int t, vtot = 0, vacc = 0, isrun; real u, k, p, rhoav, bc = 0.f; static av_t avU, avK, avp, avbc, avrho; hist_t *hsvol; lj = lj_open(N, 3, rho, rc); if (usesw) { lj_initsw(lj, rs); printf("rc %g, rs %g, box %g\n", rc, rs, lj->l*.5f); } if (initload && 0 != lj_readpos(lj, lj->x, lj->v, fnpos, LJ_LOADBOX)) { fprintf(stderr, "error loading previous coordinates from %s\n", fnpos); } hsvol = hist_open(1, 0, 5.*lj->n/lj->rho, 2.f); for (t = 1; t <= nequil + nsteps; t++) { lj_vv(lj, mddt); lj_shiftcom(lj, lj->v); lj_vrescalex(lj, tp, thermdt); isrun = (t > nequil); if ( t % 5 == 0 ) { /* different barostats */ if ( barostat == 1 ) { vacc += lj_mctp(lj, 0.05, tp, pressure, 0, 1e300, 0, 0); } else if ( barostat == 2 ) { vacc += lj_mcp(lj, 0.05, tp, pressure, 0, 1e300, 0, 0); } else if ( barostat == 3 ) { lj_langtp0(lj, 1e-5, tp, pressure, 0); } else if ( barostat == 4 ) { lj_langp0(lj, 1e-5, tp, pressure, 0); } vtot++; if (isrun) { av_add(&avrho, lj->n / lj->vol); hist_add1ez(hsvol, lj->vol, HIST_VERBOSE); } } if (isrun) { av_add(&avU, lj->epot); av_add(&avK, lj->ekin); av_add(&avp, lj_calcp(lj, tp)); /* or lj_calcpk(lj) */ if (usesw) { bc = lj_bconfsw3d(lj, NULL); av_add(&avbc, bc); } } } u = av_getave(&avU)/N; k = av_getave(&avK)/N; p = av_getave(&avp); bc = av_getave(&avbc); rhoav = av_getave(&avrho); printf("T %g, U/N %6.3f, K/N %6.3f, p %6.3f, bc %6.3f, rho %6.3f, vacc %g%%\n", tp, u, k, p, bc, rhoav, 100. * vacc / vtot); u = ljeos3d_getx(rhoav, tp, &p, NULL, NULL, LJEOS_PVEhBHKN); printf("ref., u %6.3f, p %6.3f\n", u, p); hist_save(hsvol, "volmd.his", HIST_NOZEROES); hist_close(hsvol); lj_writepos(lj, lj->x, lj->v, fnpos); lj_close(lj); return 0; }
static hist_t *lj_domd(model_t *m, const double *beta) { double emin, emax; int istep, iT; lj_t **lj, *ljtmp; hist_t *hs; /* round emin and emax to multiples of m->de */ emin = (int) (m->nn * m->emin / m->de) * m->de; emax = (int) (m->nn * m->emax / m->de) * m->de; hs = hist_open(m->nT, emin, emax, m->de); /* randomize the initial state */ mtscramble( time(NULL) ); xnew(lj, m->nT); for ( iT = 0; iT < m->nT; iT++ ) { lj[iT] = lj_open(m->nn, m->rho, m->rcdef); } /* do simulations */ for ( istep = 1; istep <= m->nequil + m->nsteps; istep++ ) { for ( iT = 0; iT < m->nT; iT++ ) { lj_vv(lj[iT], m->mddt); lj[iT]->ekin = lj_vrescale(lj[iT], 1/beta[iT], m->thdt); } if ( m->re ) { /* replica exchange: randomly swap configurations of * two neighboring temperatures */ int jT, acc; double dbdE, r; iT = (int) (rand01() * (m->nT - 1)); jT = iT + 1; dbdE = (beta[iT] - beta[jT]) * (lj[iT]->epot - lj[jT]->epot); acc = 0; if ( dbdE >= 0 ) { acc = 1; } else { r = rand01(); if ( r < exp(dbdE) ) { acc = 1; } } if ( acc ) { double scl = sqrt( beta[iT]/beta[jT] ); /* sqrt(Tj/Ti) */ int i; /* scale the velocities */ for ( i = 0; i < m->nn; i++ ) { vsmul(lj[iT]->v[i], scl); vsmul(lj[jT]->v[i], 1/scl); } /* swap the models */ ljtmp = lj[iT], lj[iT] = lj[jT], lj[jT] = ljtmp; } } if ( istep <= m->nequil ) continue; for ( iT = 0; iT < m->nT; iT++ ) { hist_add1(hs, iT, lj[iT]->epot, 1.0, HIST_VERBOSE); } } hist_save(hs, m->fnhis, HIST_ADDAHALF | HIST_NOZEROES | HIST_VERBOSE); fprintf(stderr, "simulation ended, doing WHAM\n"); for ( iT = 0; iT < m->nT; iT++ ) { lj_close( lj[iT] ); } return hs; }
int main(void) { int t, acc = 0, vacc = 0, vtot = 0, isrun = 0; lj_t *lj; ljrdf_t *ljrdf; real u, p, rho1; hist_t *hsvol; lj = lj_open(n, d, rho, rcdef); /* since this is MC, the dof should be n*d * maybe we can that it were the same dof as MD? */ lj->dof = n * d; if (usesq) { lj_initsq(lj, ra, rb); lj->vir = 0; } ljrdf = ljrdf_open(lj, 0.01, 0); hsvol = hist_open(1, 0, 5.*lj->n/rho, 1.f); for (t = 1; t <= nsteps; t++) { acc += lj_metro3d(lj, amp, 1.0f/tp); isrun = (t > nsteps / 2); if (nstvmove && t % nstvmove == 0) { vtot += 1; vacc += lj_mcp(lj, 0.01, tp, pressure, 0, 1e300, 0, 0); if (isrun) { av_add(&avrho, lj->n / lj->vol); hist_add1ez(hsvol, lj->vol, HIST_VERBOSE); } } if (t % 10000 == 0) { /* refresh energy regularly, just in case */ real epo = lj->epot; lj_energy(lj); if (fabs(lj->epot - epo) > 1e-2) { fprintf(stderr, "energy mismatch %g vs %g\n", epo, lj->epot); } } if (t % 10000 == 0) printf("t %d\n", t); if (isrun) { av_add(&avU, lj->epot); av_add(&avp, lj_calcp(lj, tp)); if (t % nstrdf == 0) ljrdf_add(ljrdf, 0); } } u = av_getave(&avU)/lj->n; p = av_getave(&avp); rho1 = av_getave(&avrho); printf("erg %g, p %g, rho %g, acc %.2f%%, vacc %.2f%%, rdfnfr %d, dof/d %g\n", u, p, rho1, 100.*acc/nsteps, 100.*vacc/(1e-6 + vtot), ljrdf->nfr, 1.*lj->dof/lj->d); hist_save(hsvol, "volmc.his", HIST_NOZEROES); hist_close(hsvol); ljrdf_save(ljrdf, "rdfmc.dat", HIST_ADDAHALF | HIST_KEEPHIST | HIST_NOZEROES); ljrdf_close(ljrdf); lj_close(lj); return 0; }