def musearch(newmdot, newps):

    tstart = time.time()

    d.XQset(1.0, 0.99)
    f = open('musearch.txt', 'w')
    newmu1 = 1.
    newmu2 = 100.

    # right boundary, probably no solution here
    #    b.parset(newmu=newmu2, newmdot=newmdot,newps=newps,neweta=0.,newalpha=0.1)
    #    print "after bparset mu="+str(mu)
    #    d.parset(newmu=newmu2, newmdot=newmdot,newps=newps,neweta=0.,newalpha=0.1)
    #    print "after parset mu="+str(mu)
    x0, x1, converged = d.ordiv_smart(newmu2, newmdot, newps)
    if (converged):
        print "musearch converged, unexpectedly;  increase your magnetic field"
        print "mu = " + str(newmu2)
        print "xi = " + str(x0) + ", qeq = " + str(x1)
        ii = raw_input("?")

    xi = []
    muu = []
    while ((newmu2 / newmu1 - 1.) > 0.1):
        newmu = sqrt(newmu1 * newmu2)
        b.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        d.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        x0, x1, converged = d.ordiv_smart(newmu, newmdot, newps)
        if (converged):
            d.XQset(x0, x1)
            xiest = d.xiest
            qeqest = d.qeqest
            newmu1 = newmu
            f.write(str(newmu) + ' ' + str(xiest) + ' ' + str(qeqest) + '\n')
            print str(newmu) + ' ' + str(xiest) + ' ' + str(qeqest) + '\n'
            xi.append(xiest)
            muu.append(newmu)
        else:
            newmu2 = newmu
            print str(newmu) + ' ' + " not converged"
    f.close()
    tend = time.time()

    clf()
    plot(muu, xi, '.k')
    xlabel(r'$\mu$, $10^{30}$G')
    ylabel(r'$\xi$')
    savefig('musearch.eps')
    print "musearch took " + str(tend - tstart)
    return muu[-1]
def varpsi():
    newmu = 1.
    newmdot = 10.
    newps = -10.
    b.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)
    d.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)
    d.XQset(0.55, 5.)
    psi1 = 1.45
    psidiff = 0.04
    psi2 = 50.
    d.psiset(psi1)

    fout = open('psivar.dat', 'w+')
    xiar = []
    psiar = []
    qeqar = []
    converged = True
    while (converged & (psi1 < psi2)):
        thp = d.ordiv_smart(newmu, newmdot, newps)
        xi = thp[0]
        qeq = thp[1]
        converged = thp[2]
        if (converged):
            d.XQset(xi, qeq)
            xiar.append(xi)
            psiar.append(psi1)
            qeqar.append(qeq)
            print "xi = " + str(xi)
            fout.write(str(psi1) + ' ' + str(xi) + ' ' + str(qeq) + '\n')
            fout.flush()
            psi1 += psidiff
            d.psiset(psi1)
    fout.close()
    xiar = asarray(xiar, dtype=double)
    qeqar = asarray(qeqar, dtype=double)
    psiar = asarray(psiar, dtype=double)
    clf()
    subplot(2, 1, 1)
    plot(psiar, xiar, '.k')
    xscale('log')
    #    xlabel(r'$\psi$')
    ylabel(r'$\xi$')
    subplot(2, 1, 2)
    plot(psiar, qeqar, '.k')
    xscale('log')
    xlabel(r'$\psi$')
    ylabel(r'$q$')
    savefig('psivar.eps')
def xiqeqplane():
    newmu = 1.
    newmdot = 10.
    newps = -10.
    b.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)
    d.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)
    xi1 = 0.2
    xi2 = 1.2
    nxi = 11
    xi = (xi2 - xi1) * np.arange(nxi) / double(nxi - 1) + xi1
    qeq1 = 0.2
    qeq2 = 1.2
    nq = 10
    qeq = (qeq2 - qeq1) * np.arange(nq) / double(nq - 1) + qeq1
    aar = np.zeros([nxi, nq], dtype=double)
    bar = np.zeros([nxi, nq], dtype=double)
    x2 = np.zeros([nxi, nq], dtype=double)
    q2 = np.zeros([nxi, nq], dtype=double)
    fout = open('xqout.txt', 'w')
    for kx in np.arange(nxi):
        for kq in np.arange(nq):
            at, bt = d.vrapper([xi[kx], qeq[kq]])
            aar[kx, kq] = at
            bar[kx, kq] = bt
            x2[kx, kq] = xi[kx]
            q2[kx, kq] = qeq[kq]
            fout.write(
                str(xi[kx]) + ' ' + str(qeq[kq]) + ' ' + str(at) + ' ' +
                str(bt) + '\n')
            fout.flush()
    fout.close()
    xi0, qeq0, conv = d.ordiv_smart(newmu, newmdot, newps)
    clf()
    contourf(x2, q2, np.log(aar**2 + bar**2), nlevels=20)
    colorbar()
    contour(x2, q2, aar, levels=[0.], colors='w')
    contour(x2, q2, bar, levels=[0.], colors='k')
    if (conv):
        plot(xi0, qeq0, 'or')
    savefig('xiqeqmap.eps')
def varps(newmu, newmdot):
    tstart = time.time()
    d.XQset(1.0, 0.9)
    ps1 = b.peq() * 10.
    psfac = 0.95
    newps = ps1
    converged = True

    psar = []
    xar = []
    qeqar = []
    f = open('varps.txt', 'w')

    while (converged):
        rscale = newmdot
        if (newmdot < 100.):
            rscale = 100.
        b.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        d.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        x0, x1, converged = d.ordiv_smart(newmu,
                                          newmdot,
                                          newps,
                                          routscale=rscale)
        d.XQset(x0, x1)
        print "varps: P = " + str(newps) + ": " + str(x0) + ", " + str(x1)
        print "(Peq = " + str(b.peq()) + ")"
        #        print str(xiest)+", "+str(qeqest)

        if (converged):
            psar.append(newps)
            xar.append(x0)
            qeqar.append(x1)
            f.write(str(newps) + ' ' + str(x0) + ' ' + str(x1) + '\n')
            f.flush()
        newps *= psfac

    f.close()
    tend = time.time()
def everything(rmmfile):

    mu2, md2, xi, qeq = rk.rmmread(rmmfile)

    wuu = unique(mu2)
    wdd = unique(md2)
    nuu = size(wuu)
    ndd = size(wdd)

    print nuu
    print ndd

    muar = reshape(asarray(mu2, dtype=double), [nuu, ndd])
    mdar = reshape(asarray(md2, dtype=double), [nuu, ndd])
    xiar = reshape(asarray(xi, dtype=double), [nuu, ndd])
    qeqar = reshape(asarray(qeq, dtype=double), [nuu, ndd])

    fname = rmmfile + 'fignya.txt'
    fout = open(fname, 'w')

    for ku in arange(nuu):
        for kd in arange(ndd):
            b.parset(newmu=muar[ku, kd],
                     newmdot=mdar[ku, kd],
                     newps=-10.,
                     neweta=0.,
                     newalpha=0.1)
            d.parset(newmu=muar[ku, kd],
                     newmdot=mdar[ku, kd],
                     newps=-10.,
                     neweta=0.,
                     newalpha=0.1)
            mu_e = muar[ku, kd]
            mdot_e = mdar[ku, kd]
            xi_e = xiar[ku, kd]
            qeq_e = qeqar[ku, kd]
            print mdotglobal
            print mu
            oint, hint, tint, htormax, mdotin, wint = d.rastr(
                xiar[ku, kd], qeqar[ku, kd])
            fout.write(
                str(mu_e) + ' ' + str(mdot_e) + ' ' + str(xi_e) + ' ' +
                str(qeq_e) + ' ' + str(oint) + ' ' + str(hint) + ' ' +
                str(htormax) + ' ' + str(mdotin) + ' ' + str(wint) + '\n')
            fout.flush()
    fout.close()
def varmdot(newmu, newps):

    tstart = time.time()

    d.XQset(1.05, 0.965)
    newmdot1 = 1000.
    newmdot2 = 10000.
    nmdot = 25
    mdar = (newmdot2 / newmdot1)**(arange(nmdot) /
                                   double(nmdot - 1)) * newmdot1

    xx = xiest
    qq = qeqest
    f = open('varmdot.txt', 'w')
    for i in arange(nmdot):
        newmdot = mdar[i]
        b.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        d.parset(newmu=newmu,
                 newmdot=newmdot,
                 newps=newps,
                 neweta=0.,
                 newalpha=0.1)
        x0, x1, converged = d.ordiv_smart(newmu, newmdot, newps)
        d.XQset(x0, x1)
        f.write(
            str(newmu) + ' ' + str(newmdot) + ' ' + str(x0) + ' ' + str(x1) +
            '\n')
        print str(newmu) + ' ' + str(newmdot) + ' ' + str(x0) + ' ' + str(
            x1) + '\n'
        f.flush()
    f.close()
    tend = time.time()
Example #7
0
def rmesh_qeq(newmu, newmdot, newps):

    b.parset(newmu=newmu,
             newmdot=mdotglobal,
             newps=newps,
             neweta=0.,
             newalpha=0.1)
    d.parset(newmu=newmu,
             newmdot=mdotglobal,
             newps=newps,
             neweta=0.,
             newalpha=0.1)

    qeqmin = 0.85
    qeqmax = 0.95
    nr = 30

    qeq = (qeqmax - qeqmin) * arange(nr) / double(nr - 1) + qeqmin

    ocalc = np.zeros(nr, dtype=double)
    obc = np.zeros(nr, dtype=double)
    hcalc = np.zeros(nr, dtype=double)
    bmax = np.zeros(nr, dtype=double)
    hbc = np.zeros(nr, dtype=double)
    tcalc = np.zeros(nr, dtype=double)
    tbc = np.zeros(nr, dtype=double)
    so = np.zeros(nr, dtype=double)
    st = np.zeros(nr, dtype=double)
    sh = np.zeros(nr, dtype=double)
    smdot = np.zeros(nr, dtype=double)

    t = 1
    k1 = -0.1

    f = open('q' + str(t) + '.txt', 'w')

    for k in arange(nr):
        xi, tc = d.ordiv(newmu, newmdot, newps, 0.0, qeq[k])
        #      tc=ordiv_tc(newmu, newmdot, newps,0.,qeq,xi)
        print "xi= " + str(xi) + '\n'
        print "qeq= " + str(qeq[k]) + '\n'
        rin = xi * b.rafun()
        oo, hh, tt, hrmax, mdotin, ww = d.rastr(xi, qeq[k], tc)
        oin = b.oin(rin, hh, mdotin)
        hin = b.fhin(rin, tt, mdotin)
        wrfin = b.fwrfin(rin, hh, mdotin)
        ocalc[k] = oo
        hcalc[k] = hh
        tcalc[k] = ww
        obc[k] = oin
        hbc[k] = hin
        tbc[k] = wrfin
        so[k] = sign(oo - oin)
        st[k] = sign(tt - tt)
        sh[k] = sign(hin - hh)
        smdot[k] = mdotin
        f.write(
            str(qeq[k]) + ' ' + str(xi) + ' ' + str(oo) + ' ' + str(oin) +
            ' ' + str(hh) + ' ' + str(hin) + ' ' + str(ww) + ' ' + str(wrfin) +
            ' ' + str(mdotin) + '\n')

    f.close()

    plt.clf()
    plot(qeq, smdot, color='k')
    ylabel('$\dot m$')
    xlabel('$qeq$')
    savefig('mdot' + str(t) + '.eps')

    plt.clf()
    plot(qeq, ocalc, color='k')
    plot(qeq, obc, color='r')
    ylabel('$\omega$')
    xlabel('$qeq$')
    ylim(0.1, 1.5)
    savefig('oos' + str(t) + '.eps')

    plt.clf()
    plot(qeq, hcalc, color='k')
    plot(qeq, hbc, color='r')
    ylabel('$h$')
    xlabel('$qeq$')
    yscale('log')
    savefig('h' + str(t) + '.eps')

    plt.clf()
    plot(qeq, tcalc, color='k')
    plot(qeq, tbc, color='r')
    ylabel('$wrf$')
    xlabel('$qeq$')
    yscale('log')
    savefig('wrf' + str(t) + '.eps')
Example #8
0
def rmesh(newmu, newmdot, newps):

    b.parset(newmu=newmu,
             newmdot=mdotglobal,
             newp=newps,
             neweta=0.,
             newalpha=0.1)
    d.parset(newmu=newmu,
             newmdot=mdotglobal,
             newp=newps,
             neweta=0.,
             newalpha=0.1)

    qeqmin = 0.1
    qeqmax = 1.
    nr = 10
    pr = 10.
    ximin = 0.1
    ximax = 1.5
    tcmin = 0.01
    tcmax = 2.

    #    qeq=(qeqmax-qeqmin)*arange(nr)/double(nr-1)+qeqmin
    #   xi=(ximax-ximin)*arange(nr)/double(nr-1)+ximin
    #    tc=(tcmax-tcmin)*arange(nr)/double(nr-1)+tcmin

    ocalc = np.zeros([nr, nr, nr], dtype=double)
    obc = np.zeros([nr, nr, nr], dtype=double)
    hcalc = np.zeros([nr, nr, nr], dtype=double)
    bmax = np.zeros([nr, nr, nr], dtype=double)
    hbc = np.zeros([nr, nr, nr], dtype=double)
    tcalc = np.zeros([nr, nr, nr], dtype=double)
    tbc = np.zeros([nr, nr, nr], dtype=double)
    so = np.zeros([nr, nr, nr], dtype=double)
    st = np.zeros([nr, nr, nr], dtype=double)
    sh = np.zeros([nr, nr, nr], dtype=double)
    smdot = np.zeros([nr, nr, nr], dtype=double)

    t = 1
    k1 = -0.1

    f = open('q' + str(t) + '.txt', 'w')

    xi = ximin
    tc = tcmin
    qeq = qeqmin
    i = 0

    for k in arange(nr):
        xi = xi + (ximax - ximin) / pr
        tc = tcmin
        for w in arange(nr):
            tc = tc + (tcmax - tcmin) / pr
            qeq = qeqmin
            for q in arange(nr):
                qeq = qeq + (qeqmax - qeqmin) / pr
                print 'qeq= ' + str(qeq) + ' tc= ' + str(tc) + ' xi= ' + str(
                    xi) + '\n'
                rin = xi * b.rafun()
                oo, hh, tt, hrmax, mdotin, ww = d.rastr(xi, qeq, tc)
                oin = b.oin(rin, hh, mdotin)
                hin = b.fhin(rin, tt, mdotin)
                wrfin = b.fwrfin(rin, hh, mdotin)
                ocalc[k, w, q] = oo
                hcalc[k, w, q] = hh
                tcalc[k, w, q] = ww
                obc[k, w, q] = oin
                hbc[k, w, q] = hin
                tbc[k, w, q] = wrfin
                so[k, w, q] = oo - oin
                st[k, w, q] = ww - wrfin
                sh[k, w, q] = -hin + hh
                smdot[k, w, q] = mdotin
                print i
                i += 1
                f.write(
                    str(qeq) + ' ' + str(xi) + ' ' + str(tc) + ' ' + str(oo) +
                    ' ' + str(oin) + ' ' + str(hh) + ' ' + str(hin) + ' ' +
                    str(ww) + ' ' + str(wrfin) + ' ' + str(mdotin) + ' ' +
                    str(oo - oin) + ' ' + str(ww - wrfin) + ' ' +
                    str(hh - hin) + '\n')

    f.close()
def rastr1(rrin, qeq, newmu=d.mu, newmdot=mdotglobal, newps=ps):

    b.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)
    d.parset(newmu=newmu,
             newmdot=newmdot,
             newps=newps,
             neweta=0.0,
             newalpha=0.1)

    ra = b.rafun()
    rin = ra * rrin
    #    print rin
    #    kok=raw_input()
    t = 1
    rout = 100. * rin
    ddr = -3.e-5
    mdot = d.mdotglobal
    mu = d.mu
    print "rastr1: mdot= " + str(mdot) + " mu= " + str(mu) + " \n"
    #    huh=raw_input()

    if (mdot < 1.5):
        ddr *= (mdot / 1.5)
    ddr /= (1. + 0.1 * (b.peq() / ps))
    defac = 0.99

    r = rout
    omega = 1.
    drout = 1e-2
    rlast = rout
    oprev = omega
    rprev = r

    rl = []
    ol = []
    tl = []
    hl = []
    bb = []
    taussa = []
    taussb = []
    hssa = []
    hssb = []
    dt = []
    do = []
    dw = []
    dta = []
    mdot123 = []
    P1m = []
    P3m = []
    qqra = []
    qqad = []
    qqpl = []
    wwrf = []
    ttc = []

    htormax = 0.
    #    mdot=mdotglobal
    wrf = 2. * mdot / r**2 * omega * (sqrt(r) - qeq * sqrt(rin))
    tau = 4. / chi**0.8 * (pi /
                           9.)**0.2 * mdot**0.6 / alpha**0.8 / rout**0.6 * (
                               1. - qeq * (rin / rout)**0.5)**0.6
    #   tau=ftau(wrf,r,tc)
    h = hvert * sqrt(r**3 * wrf / alpha / tau)
    tc = b.ctemp(h, wrf, tau)
    #    print h/r
    hprev = h
    wprev = wrf
    tauprev = tau

    f = open('rastr_new_1.txt', 'w')

    while (r >= rin):
        dr = ddr * (r - rin * defac)
        r1 = r + dr / 2.
        #        print r/rin

        h = hvert * sqrt(r**3 * wrf / alpha / tau)
        #        print h/r

        if (isnan(tau)):
            print "tausolve resulted in NaN"
            return sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(
                -1.)
        omega1 = omega + domega(omega, r, tau, mdot, wrf, tc) * dr / 2.
        wrf1 = wrf + dwrf(tau, omega, r) * dr / 2.
        tau1 = tau + dtau(tau, tc, wrf, r, omega, mdot) * dr / 2.
        tc1 = tc + dtemp(tau, tc, wrf, r, omega, mdot) * dr / 2.

        beta1 = beta(tau1, tc1, wrf1)

        #        if((r*r)>(9.*tau1/(4.*64.*pi*tc**4.))):
        if (r < h):
            mdot1 = mdot + dmdot(r, tc, tau) * dr / 2.
        else:
            mdot1 = mdot

        if (wrf1 <= 0.):
            print "negative stress! wrf = " + str(wrf1)
            return sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(
                -1.)

        h1 = hvert * sqrt(r1**3 * wrf1 / alpha / tau1)

        if (isnan(tau1)):
            print "tausolve resulted in NaN"
            return sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(
                -1.)
        omega = omega + domega(omega1, r1, tau1, mdot1, wrf1, tc1) * dr
        wrf = wrf + dwrf(tau1, omega1, r1) * dr
        tc = tc + dtemp(tau1, tc1, wrf1, r1, omega1, mdot1) * dr

        tau = tau + dtau(tau1, tc1, wrf1, r1, omega1, mdot1) * dr

        P4 = 2. / 3.
        P3 = 1.77526e-5 * alpha * tc1 * tau1 / wrf1
        P1 = 56329.9 * h1 * h1 / tc1 * r1**(-3.)

        #       Qrad=128./9.*tc1**4./tau1

        bet = beta(tau1, tc1, wrf1)

        Stau = Scal(bet)
        Swrf = Pcal(bet)
        Stemp = Qcal(bet)

        part1 = Stau / tau1 * dtau(tau1, tc1, wrf1, r1, omega1, mdot1)
        part2 = Swrf / wrf1 * dwrf(tau1, omega1, r1)
        part3 = Stemp / tc1 * dtemp(tau1, tc1, wrf1, r1, omega1, mdot1)
        part4 = 3. / r * Swrf

        Qrad = -16. / 3. * G(n) * (n + 1.) * tc1**4. * 4. * pi / (tau1)

        Qadv = 2. / (G(n + 1.)) * mdot1 * wrf1 / (alpha * r1 * tau1) * (
            part1 + part2 + part3 + part4)

        Qplus = wrf1 * r1**(-1. / 2.) * (
            domega(omega1, r1, tau1, mdot1, wrf1, tc1) - 3. / 2. * omega1 / r1)

        r += dr

        #       if((r*r)>(9.*tau1/(4.*64.*pi*tc**4.))):
        if (r < h1):
            mdot = mdot + dmdot(r1, tc1, tau1) * dr

        if ((h / r) > htormax):
            htormax = h / r
            rmax = r
        if (r < (rlast / (1. + drout))):
            ttc.append(tc)
            qqra.append(Qrad)
            wwrf.append(wrf)
            qqpl.append(Qplus)
            qqad.append(Qadv)
            P1m.append(P1)
            P3m.append(P3)
            rl.append(r / rin)
            ol.append(omega)
            tl.append(tau)
            hl.append(h / r)
            dt.append(abs(dtemp(tau1, tc1, wrf1, r1, omega1, mdot1)) / tc1)
            do.append(abs(domega(omega1, r1, tau1, mdot1, wrf1, tc1)))
            dw.append(abs(dwrf(tau1, omega1, r1)) / wrf1)
            dta.append(abs(dtau(tau1, tc1, wrf1, r1, omega1, mdot1)) / tau1)
            bb.append(beta1)
            rlast = r
            taussa.append(ss.ftaussa(r, mdot, alpha, rin))
            taussb.append(ss.ftaussb(r, mdot, alpha, rin))
            hssa.append(ss.hssa(mdot, r, rin))
            hssb.append(ss.hssb(r, mdot, alpha, rin))
            mdot123.append(mdot)
            f.write(
                str(r / rin) + ' ' + str(omega) + ' ' + str(h / r) + ' ' +
                str(tau) + ' ' + str(tc) + ' ' + str(wrf) + ' ' +
                str(ss.ftaussa(r, mdot, alpha, rin)) + ' ' +
                str(ss.ftaussb(r, mdot, alpha, rin)) + ' ' + str(Qadv) + ' ' +
                str(Qrad) + ' ' + str(Qplus) + ' ' +
                str(ss.hssa(mdot, r, rin)) + ' ' +
                str(ss.hssb(r, mdot, alpha, rin)) + ' ' + str(mdot) + '\n')

    mdotin = mdot
    tauin = tau
    #    print "tau= "+str(tauin)+'\n'
    #    print mdotin
    #    jjoij=raw_input()
    wrfin = wrf
    #    print wrfin
    #    jjoij=raw_input()
    f.close()

    tcar = asarray(ttc, dtype=double)
    qplus = asarray(qqpl, dtype=double)
    wrfar = asarray(wwrf, dtype=double)
    qadv = asarray(qqad, dtype=double)
    qrad = asarray(qqra, dtype=double)
    p1ar = asarray(P1m, dtype=double)
    p3ar = asarray(P3m, dtype=double)
    rar = asarray(rl, dtype=double)
    oar = asarray(ol, dtype=double)
    tauar = asarray(tl, dtype=double)
    har = asarray(hl, dtype=double)
    taua = asarray(taussa, dtype=double)
    taub = asarray(taussb, dtype=double)
    hrssa = asarray(hssa, dtype=double)
    hrssb = asarray(hssb, dtype=double)
    mdar = asarray(mdot123, dtype=double)
    dtem = asarray(dt, dtype=double)
    dome = asarray(do, dtype=double)
    dwr = asarray(dw, dtype=double)
    dtaau = asarray(dta, dtype=double)
    bbeta = asarray(bb, dtype=double)

    oint = (omega - oprev) * (rin - rprev) / (r - rprev) + oprev
    hint = (h - hprev) * (rin - rprev) / (r - rprev) + hprev
    tint = (tau - tauprev) * (rin - rprev) / (r - rprev) + tauprev
    wint = (wrf - wprev) * (rin - rprev) / (r - rprev) + wprev

    pp = 1. / 4. * (n + 1.) * G(n)

    plt.clf()
    fig = figure()
    plt.subplot(3, 3, 1)
    plot(rar * rin * rrin * 206746., p1ar, color='black', label='P1')
    plot(rar * rin * rrin * 206746., p3ar, color='green', label='P3')
    plot(rar * rin * rrin * 206746.,
         p1ar * 0. + 2. / 3.,
         color='red',
         label='P2')
    plot(rar * rin * rrin * 206746., p3ar * 0. + pp, color='blue', label='P4')
    ylim(0., 7.)
    ylabel('$P1,2,3,4$')
    xlabel('$r$')
    legend()
    #    yscale('log')
    #    xscale('log')

    plt.subplot(3, 3, 2)
    plot(rar * rin * rrin * 206746.,
         qadv / qplus,
         color='red',
         label='Qadv/Qvis')
    plot(rar * rin * rrin * 206746.,
         qrad / qplus,
         color='green',
         label='Qrad/Qvis')
    #   xlim(0.01,5.e10)
    ylabel('flux ratios')
    xlabel('$r$')
    #    yscale('log')
    xscale('log')
    legend()

    plt.subplot(3, 3, 3)
    plot(rar * rin * rrin * 206746., taua, color='blue', label='rad')
    plot(rar * rin * rrin * 206746., taub, color='green', label='gas')
    plot(rar * rin * rrin * 206746., tauar, color='red', label='calc')
    ylabel(r'$\tau$')
    xlabel('$r$')
    yscale('log')
    xscale('log')
    legend()

    plt.subplot(3, 3, 4)
    plot(rar * rin * rrin * 206746., har, color='red', label='calc')
    plot(rar * rin * rrin * 206746.,
         hrssa / rar / rin,
         color='blue',
         label='rad')
    plot(rar * rin * rrin * 206746.,
         hrssb / rar / rin,
         color='green',
         label='gas')
    ylabel('$h/r$')
    xlabel('$r$')
    xscale('log')
    yscale('log')
    legend()

    plt.subplot(3, 3, 5)
    plot(rar * rin * rrin * 206746., wrfar * 2.56787e+21, color='red')
    ylabel(r'$W_{rf}$')
    xlabel('$r$')
    xscale('log')
    yscale('log')

    plt.subplot(3, 3, 6)
    plot(rar * rin * rrin * 206746., mdar / mdotglobal, color='red')
    ylabel(r'$\dot M/\dot M_{0}$')
    xlabel('$r$')
    xscale('log')
    #    yscale('log')

    plt.subplot(3, 3, 7)
    plot(rar * rin * rrin * 206746., oar, color='red')
    ylabel(r'$\Omega/\Omega_{\rm K}$')
    xlabel('$r$')
    xscale('log')
    #    yscale('log')

    plt.subplot(3, 3, 8)
    plot(rar * rin * rrin * 206746., tcar * 9.6e7, color='red')
    ylabel(r'$T_{c}$')
    xlabel('$r$')
    xscale('log')
    yscale('log')
    fig.set_size_inches(15, 15)
    savefig('all.eps')

    plt.clf()
    plot(rar, fabs(qadv / qplus), color='blue')
    ylabel('$Qadv/Qplus$')
    xlabel('$r/rin$')
    #   ylim(0.,10.)
    yscale('log')
    xscale('log')
    savefig('Qadv.eps')

    plt.clf()
    plot(rar, qrad / qplus, color='green')
    ylabel('$Qrad/Qplus$')
    xlabel('$r/rin$')
    #   yscale('log')
    xscale('log')
    savefig('Qrad.eps')

    plt.clf()
    plot(rar, qrad / qplus, color='green', label='Qrad/Qplus')
    plot(rar, qadv / qplus, color='red', label='Qadv/Qplus')
    ylabel('$Q/Qplus$')
    xlabel('$r/rin$')
    #   yscale('log')
    xscale('log')
    legend()
    savefig('Q.eps')

    plt.clf()
    plot(rar, p1ar, color='blue', label='P1')
    plot(rar, p3ar, color='green', label='P3')
    ylabel('$P$')
    xlabel('$r/rin$')
    ylim(0., 10.)
    legend()
    #   yscale('log')
    #    xscale('log')
    savefig('P.eps')

    plt.clf()
    plot(rar, p1ar, color='blue', label='P1')
    plot(rar, p3ar, color='green', label='P3')
    ylabel('$P$')
    xlabel('$r/rin$')
    yscale('log')
    xscale('log')
    legend()
    savefig('Plog.eps')

    plt.clf()
    plot(bbeta, p1ar, color='blue')
    plot(bbeta, p3ar, color='green')
    ylabel('$P$')
    xlabel('$r/rin$')
    ylim(0., 10.)

    #   yscale('log')
    #    xscale('log')
    savefig('P_beta.eps')

    plt.clf()
    plot(rar, taua, color='blue')
    plot(rar, taub, color='green')
    plot(rar, tauar, linestyle='dotted', color='red')
    plot([rin / rin], [tint], 'o')
    ylabel(r'$\tau$')
    xlabel('$r/rin$')
    yscale('log')
    xscale('log')
    savefig('tau.eps')

    plt.clf()
    plot(rar, oar, color='k')
    plot([rin / rin], [oint], 'o')
    ylabel(r'$\omega$')
    xlabel('$r/rin$')
    xscale('log')
    savefig('omega.eps')

    plt.clf()
    plot(rar, har, linestyle='dotted', color='red')
    plot(rar, hrssa / rar / rin, color='blue')
    plot(rar, hrssb / rar / rin, color='green')
    plot([rin / rin], [hint / rin], 'o')
    ylabel('$h/r$')
    xlabel('$r/rin$')
    xscale('log')
    yscale('log')
    savefig('har.eps')

    plt.clf()
    plot(rar, mdar, color='k')
    ylabel(r'$\dot{m}$')
    xlabel('$r/rin$')
    xscale('log')
    yscale('log')
    savefig('mdot.eps')

    if (isnan(omega) | (r > rin)):
        return sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.), sqrt(-1.)
    h_in = b.fhin(rin, tau, mdotin)
    #    print h_in
    #    jjoij=raw_input()
    omega_in = b.oin(rin, hint, mdotin)
    #    print omega_in
    #    jjoij=raw_input()
    wrf_in = b.fwrfin(rin, hint, mdotin)
    #    print wrf_in
    #    jjoij=raw_input()

    print "rastr1: omega = " + str(omega) + "; h = " + str(
        h) + "; htormax = " + str(htormax) + "; mdotin = " + str(
            mdot) + "; wrf = " + str(wrf) + "\n"
    print "rastr1: omega_in = " + str(omega_in) + "; h_in = " + str(
        h_in) + " ; wrf_in = " + str(wrf) + "\n"
    print "mdoyin= " + str(mdotin) + ' \n'
    huh = raw_input()
    return rar * rin, tauar