コード例 #1
0
def generateEkinFile(fileName='e_kin.test'):
    from magic import MagicGraph, Movie

    gr = MagicGraph(ivar=1)

    file = open(fileName, 'w')
    st = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f' % (
        gr.entropy[10, 13, 3], gr.Br[33, 0, 2], gr.Btheta[3, 11, 11],
        gr.Bphi[34, 12, 25], gr.vr[11, 15, 2], gr.vtheta[33, 33, 3],
        gr.vphi[32, 33, 7], gr.Br_ic[5, 101, 2], gr.Btheta_ic[40, 39, 12])

    #Write output for graphic files
    file.write(st + '\n')

    av = Movie(file='AV_mov.start', iplot=False)
    ahf = Movie(file='AHF_mov.start', iplot=False)
    brcmb = Movie(file='Br_CMB_mov.start', iplot=False)
    vtr = Movie(file='Vt_R=C1_mov.start', iplot=False)
    vreq = Movie(file='Vr_EQU_mov.start', iplot=False)
    teq = Movie(file='T_EQU_mov.start', iplot=False)
    vortz = Movie(file='VorZ_EQU_mov.start', iplot=False)
    hel = Movie(file='HE_R=C2_mov.start', iplot=False)
    Bteq = Movie(file='Bt_EQU_mov.start', iplot=False)
    st = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f' % (
        av.data[0, 1, 121, 12], ahf.data[0, 0, 99, 33],
        brcmb.data[0, 1, 47, 128], vtr.data[0, 0, 33, 87],
        vreq.data[0, 0, 28, 31], teq.data[0, 1, 29, 29],
        vortz.data[0, 1, 1, 1], hel.data[0, 0, 3, 4], Bteq.data_ic[0, -1, 10,
                                                                   5])

    # Write output for movie files
    file.write(st)
    file.close()
コード例 #2
0
        """
        In this case, the output is extrapolated on a cartesian grid
        and then written in a vti file.

        :param filename: the file name of the output (without extension)
        :type filename: str
        :param nx: number of grid points in the x direction
        :type nx: int
        :param ny: number of grid points in the x direction
        :type ny: int
        :param nz: number of grid points in the x direction
        :type nz: int
        """
        scals_cart, gridMax, spacing = sph2cart_scal(self.scals, \
                                                     self.radius, nx, ny, nz,
                                                     self.minc)
        if self.nvecs == 0:
            vti_scal(filename, scals_cart, self.scalNames, self.minc, \
                     gridMax, spacing)
        else:
            vecx, vecy, vecz = sph2cart_vec(self.vecr, self.vect, self.vecp, \
                                        self.radius, nx, ny, nz, self.minc)
            vti(filename, vecx, vecy, vecz, scals_cart, self.scalNames,
                self.vecNames, self.minc, gridMax, spacing)


if __name__ == '__main__':
    ivar = 1
    g = MagicGraph(ivar=ivar)
    Graph2Vtk(g, scals=['tfluct', 'emag'], vecs=['b'], potExtra=True)
コード例 #3
0
ファイル: cyl.py プロジェクト: magic-sph/magic
    def __init__(self, ivar=1, datadir='.', ns=None):
        """
        :param ivar: the number of the Graphic file
        :type ivar: int
        :param datadir: working directory
        :type datadir: str
        :param ns: number of grid points in the radial direction
        :type ns: int
        """
        MagicSetup.__init__(self, datadir)

        self.datadir = datadir

        filename = '{}G_{}.{}'.format('cyl', ivar, self.tag)
        if not os.path.exists(filename):
            print("sph2cyl...")
            gr = MagicGraph(ivar=ivar, datadir=self.datadir)
            if ns is None:
                self.ns = gr.nr
                self.nz = 2*self.ns
            else:
                self.ns = ns
                self.nz = 2*ns
            self.nphi = gr.nphi
            self.npI = gr.npI
            self.minc = gr.minc
            self.ro = gr.radius[0]
            self.ri = gr.radius[-1]
            self.S, self.Z, self.vs, self.vphi, self.vz = sph2cyl(gr,
                                    self.ns, self.nz)
            file = open(filename, 'wb')
            pickle.dump([self.ns, self.nz, self.nphi, self.npI, self.minc], file)
            pickle.dump([self.ro, self.ri], file)
            pickle.dump([self.S, self.Z, self.vs, self.vphi, self.vz],
                        file)
            file.close()
        else:
            print("read cyl file")
            file = open(filename, 'r')
            self.ns, self.nz, self.nphi, self.npI, self.minc = pickle.load(file)
            self.ro, self.ri = pickle.load(file)
            self.S, self.Z, self.vs, self.vphi, self.vz = \
                         pickle.load(file)
            file.close()
        self.radius = np.linspace(0., self.ro, self.ns)
        temp0, rho0, beta0 = anelprof(np.linspace(self.ro, self.ri, self.ns),
                                     self.strat, self.polind)
        rho = np.zeros((self.nphi/2, self.ns), dtype=self.vr.dtype)
        beta = np.zeros_like(rho)
        for i in range(self.nphi/2):
            rho[i, :] = rho0
            beta[i, :] = beta0
        Z, S, [rho, beta] = sph2cyl_plane([rho,beta],
                                 np.linspace(self.ro, self.ri, self.ns),
                                 self.ns, self.nz)
        self.rho = np.zeros_like(self.vs)
        self.beta = np.zeros_like(self.vs)
        for i in range(self.npI):
            self.rho[i, ...] = rho
            self.beta[i, ...] = beta
        self.z = np.linspace(-self.ro, self.ro, self.nz)
コード例 #4
0
            for i in range(self.n_r_ic_max):
                rdep = np.ones(sh.ell.shape, dtype=np.float64)
                if i == 0:  # ICB radius
                    om = sh.spat_spec(jr[:, :, -1])
                    rr = self.radius[-1]
                    rdep[:] = 1.
                else:
                    om = sh.spat_spec(jr_ic[:, :, i - 1])
                    rr = self.radius_ic[i - 1]
                    rdep[1:] = (self.radius_ic[i - 1] / ri)**(sh.ell[1:] + 1)
                self.btor_ic[i, 1:] = om[1:] / (sh.ell[1:] *
                                                (sh.ell[1:] + 1)) * rr**2
                # Not stable
                #if self.radius_ic[i] >= 0.1:
                #    mask = ( self.lm2l <= 5 ) * ( self.lm2m <= 5)
                #    self.btor_ic[i, mask] /= rdep[mask]

        self.write(filename)


if __name__ == '__main__':
    from magic import MagicGraph
    chk = MagicCheckpoint(l_read=False)
    #chk.fd2cheb(33)
    #chk.write('checkpoint_cheb.tmp')
    gr = MagicGraph()
    chk.graph2rst(gr)
    #chk.cheb2fd(96)
    #chk.write('checkpoint_alpha.tmp')
コード例 #5
0
ファイル: getData.py プロジェクト: leloulight/magic
#!/usr/bin/env python
from magic import MagicGraph, Movie

gr = MagicGraph(ivar=1)

out = 'e_kin.test'
file = open(out, 'w')
st = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f' % (
    gr.entropy[10, 13, 3], gr.Br[33, 0, 2], gr.Btheta[3, 11, 11],
    gr.Bphi[34, 12, 25], gr.vr[11, 15, 2], gr.vtheta[33, 33,
                                                     3], gr.vphi[32, 33, 7])

# Write output for graphic files
file.write(st + '\n')

av = Movie(file='AV_mov.start', iplot=False)
ahf = Movie(file='AHF_mov.start', iplot=False)
brcmb = Movie(file='Br_CMB_mov.start', iplot=False)
vtr = Movie(file='Vt_R=C1_mov.start', iplot=False)
vreq = Movie(file='Vr_EQU_mov.start', iplot=False)
teq = Movie(file='T_EQU_mov.start', iplot=False)
vortz = Movie(file='VorZ_EQU_mov.start', iplot=False)
hel = Movie(file='HE_R=C2_mov.start', iplot=False)
st = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f' % (
    av.data[1, 121, 12], ahf.data[0, 99, 33], brcmb.data[1, 47, 128],
    vtr.data[0, 33, 87], vreq.data[0, 28, 31], teq.data[1, 29, 29],
    vortz.data[1, 1, 1], hel.data[0, 3, 4])

# Write output for movie files
file.write(st)
コード例 #6
0
from magic import MagicGraph
from magic.libmagic import symmetrize
import pylab as P
import numpy as N
from potential import *


def proj(theta, phi):
    x = 2. * N.sqrt(2.) * N.sin(theta) * N.sin(
        phi / 2.) / N.sqrt(1. + N.sin(theta) * N.cos(phi / 2.))
    y = N.sqrt(2.) * N.cos(theta) / N.sqrt(1. + N.sin(theta) * N.cos(phi / 2.))
    return x, y


g = MagicGraph()
rcmb = g.radius[0]
rsurf = rcmb
radratio = rcmb / rsurf
brCMB = g.Br[..., 0]
btCMB = g.Btheta[..., 0]
bpCMB = g.Bphi[..., 0]

phi = N.linspace(-N.pi, N.pi, g.nphi)
theta = g.colatitude
ttheta, pphi = N.meshgrid(theta, phi)

x, y = proj(ttheta, pphi)
anlc = N.fft.fft(brCMB, axis=0) / (4. * N.pi * g.npI)
brm, btm, bpm = extrapolate(anlc, radratio, g.minc)

brsurf = N.fft.ifft(brm, axis=0) * g.npI