Exemplo n.º 1
0
def preprocess(m,N):
	n = len(m)
	L = n-1
	frames = 10
	x = np.linspace(0.0, 1.0, m[0])
	sums = np.zeros((4,m[0]),np.float)

	# get paramenters that remain the same for all runs
	f = open('mmc_testcase.inp', 'r')
	info = f.read()
	f.close

	for count in range(N):
		# uniform varying values
		v = random.uniform(0.5,3)
		#v = random.gauss(3,1.0)

		ux = ("a = " + str(v))
		
		folder = ("U_" + str(v))

		## create Warpx .pin file
		out = open('testcase.inp','w')
		for line in info:
			out.write(line.replace("a = value",ux))
		out.close

		where1 = ('L'+str(L) + '/' + folder)
		os.mkdir(where1)
		os.system("mpirun -n 1 $warpxp -i testcase.inp")
		os.system("mv *.h5 *.log " + where1)
		
		
		df = wx.WxData(where1+'/euler_mmc', frames)
		qf = dh.read('qnew')
		vf = qf[:, 1]/qf[:, 0]
		xf = np.linspace(qf.grid.lowerBounds[0],qf.grid.upperBounds[0],qf.grid.numPhysCells[0])
		df.close
		Xf = np.interp(x,xh,vl)

		
		Xc=np.zeros(m[0], np.float)
		
		sums[1,:] = sums[1,:] + np.sum(Xf-Xc)
		sums[2,:] = sums[2,:] + np.sum((Xf-Xc)*(Xf-Xc))
		sums[3,:] = sums[3,:] + np.sum(Xf)
		sums[4,:] = sums[4,:] + np.sum(Xf*Xf)
	
	return sums
Exemplo n.º 2
0
def getdata(v, LS, BFP, res, L, frames):

    os.system("cp input_mmc.inp mmc_testcase.inp")
    resx = res
    resy = res / 2
    for line in fileinput.input("mmc_testcase.inp", inplace=1):
        if "ME" in line:
            line = line.replace("ME", str(v))
        elif "      Cells = [resx, resy]" in line:
            line = line.replace(
                "      Cells = [resx, resy]",
                "      Cells = [" + str(resx) + ", " + str(resy) + "]")
        elif "LS" in line:
            line = line.replace("LS", str(LS))
        elif "bpert" in line:
            line = line.replace("bpert", str(BFP))
        sys.stdout.write(line)

    folder = ("U_" + str(v))
    where1 = ('L' + str(L) + '/' + folder)
    if not (os.path.exists(where1)):
        os.mkdir(where1)

    p = subprocess.Popen(
        "crun -nodes 16 -cores 128 $warpx -i mmc_testcase.inp", shell=True)
    sts = os.waitpid(p.pid, 0)[1]

    fluxtfh = np.zeros(frames + 1, np.float)

    for i in range(0, frames + 1):
        # open file for reading
        dtfh = wx.WxData('mmc_testcase', i)
        qtfh = dtfh.read('qnew')
        # get Y-axis spacing
        dxtfh = qtfh.grid.dx[0]
        nytfh = qtfh.grid.numPhysCells[1]
        bytfh = qtfh[:, int(np.ceil(nytfh / 2)), 14]
        fluxtfh[i] = dxtfh * np.sum(np.fabs(bytfh))
        dtfh.close()

    Ly = 12.8
    fluxtfh = fluxtfh / (2 * Ly)
    fluxtfh = 0.2 * fluxtfh / fluxtfh[0]  # rescale to match GEM conditions

    os.system('mv *.h5 *.log mmc_testcase.inp ' + where1)
    return fluxtfh
Exemplo n.º 3
0
import glob
import os
import subprocess
import wxdata as wxdata2
from pylab import *
from numpy import *
import numpy

frames = 40
Ly = 12.8
wci = 0.1
filename = 'ssrecon_wv_0'

flux  = numpy.zeros(frames+1, numpy.float)
		
for n in range(0,frames+1):
	dh = wxdata2.WxData(filename, n)
	q = dh.read('qnew')
	dx = (q.grid.upperBounds[1]-q.grid.lowerBounds[1])/q.grid.numPhysCells[1]
	ny = int(round(q.grid.numPhysCells[1]/2))
	by = q[:, ny, 14]
	
	flux[n] = dx*numpy.sum( numpy.fabs(by) )
	dh.close()
		
flux = flux/(2*Ly)
flux = 2*wci*flux/flux[0] # rescale to match GEM conditions
numpy.savetxt((filename+'.dat'),flux)
Exemplo n.º 4
0
def preprocess(m, N, L, frames, res):
    import numpy as np
    import os
    import random
    import fileinput
    import sys
    import string
    import wxdata as wx

    x = np.linspace(0.0, 1.0, res)
    sums = np.zeros((4, res), np.float)

    for count in range(int(N)):
        # uniform varying values
        v = random.uniform(1.0e-10, 1.0e-4)
        #v = random.gauss(3,1.0)
        os.system("cp input3.inp mmc_testcase.inp")
        for line in fileinput.input("mmc_testcase.inp", inplace=1):
            if "        u_i = value" in line:
                line = line.replace("        u_i = value",
                                    "        u_i = " + str(v))
            elif "      Cells = [nx]" in line:
                line = line.replace("      Cells = [nx]",
                                    "      Cells = [" + str(m[L]) + "]")
            sys.stdout.write(line)

        os.system("mpirun -n 1 $warpxp -i mmc_testcase.inp")

        df = wx.WxData('mmc_testcase', frames)
        qf = df.read('qnew')
        vf = qf[:, 1] / qf[:, 0]
        xf = np.linspace(qf.grid.lowerBounds[0], qf.grid.upperBounds[0],
                         qf.grid.numPhysCells[0])
        df.close
        Xf = np.interp(x, xf, vf)

        folder = ("U_" + str(v))
        where1 = ('L' + str(L) + '/' + folder)
        os.mkdir(where1)
        os.system("mv *.h5 *.log mmc_testcase.inp " + where1)

        if L > 0:
            os.system("cp input3.inp mmc_testcase.inp")
            for line in fileinput.input("mmc_testcase.inp", inplace=1):
                if "        u_i = value" in line:
                    line = line.replace("        u_i = value",
                                        "        u_i = " + str(v))
                elif "      Cells = [nx]" in line:
                    line = line.replace(
                        "      Cells = [nx]",
                        "      Cells = [" + str(m[L - 1]) + "]")
                sys.stdout.write(line)

            os.system("mpirun -n 1 $warpxp -i mmc_testcase.inp")

            dc = wx.WxData('mmc_testcase', frames)
            qc = dc.read('qnew')
            vc = qc[:, 1] / qc[:, 0]
            xc = np.linspace(qc.grid.lowerBounds[0], qc.grid.upperBounds[0],
                             qc.grid.numPhysCells[0])
            dc.close
            Xc = np.interp(x, xc, vc)
            where2 = ('L' + str(L - 1) + '/' + folder)
            os.mkdir(where2)
            os.system("mv *.h5 *.log mmc_testcase.inp " + where2)
        else:
            Xc = np.zeros(res, np.float)

        sums[0, :] = sums[0, :] + (Xf - Xc)
        sums[1, :] = sums[1, :] + (Xf - Xc) * (Xf - Xc)
        sums[2, :] = sums[2, :] + Xf
        sums[3, :] = sums[3, :] + Xf * Xf

    return sums
Exemplo n.º 5
0
frames = 40
Ly = 12.8
wci = 0.1

if os.path.exists('ssrecon_wv_2.pin'):
    d = ['ssrecon_wv_0', 'ssrecon_wv_1', 'ssrecon_wv_2']
elif os.path.exists('ssrecon_wv_1.pin'):
    d = ['ssrecon_wv_0', 'ssrecon_wv_1']
else:
    d = ['ssrecon_wv_0']

for m in range(0, len(d)):
    flux = numpy.zeros(frames + 1, numpy.float)

    for n in range(0, frames + 1):
        dh = wxdata2.WxData(d[m], n)
        q = dh.read('qnew')
        dx = (q.grid.upperBounds[1] -
              q.grid.lowerBounds[1]) / q.grid.numPhysCells[1]
        ny = int(round(q.grid.numPhysCells[1] / 2))
        by = q[:, ny, 14]

        flux[n] = dx * numpy.sum(numpy.fabs(by))
        dh.close()

    flux = flux / (2 * Ly)
    flux = 2 * wci * flux / flux[0]  # rescale to match GEM conditions

    numpy.savetxt((d[m] + str('.dat')), flux)
Exemplo n.º 6
0
import glob
import os
import subprocess
import wxdata as wxdata2
from pylab import *
from numpy import *
import numpy

frames = 40
Ly = 12.8
wci = 0.1

d = 'recon_pcm'
flux  = numpy.zeros(frames+1, numpy.float)
		
for n in range(0,frames+1):
	dh = wxdata2.WxData(d, n)
	q = dh.read('qnew')
	dx = (q.grid.upperBounds[1]-q.grid.lowerBounds[1])/q.grid.numPhysCells[1]
	ny = int(round(q.grid.numPhysCells[1]/2))
	by = q[:, ny, 14]
	
	flux[n] = dx*numpy.sum( numpy.fabs(by) )
	dh.close()
		
flux = flux/(2*Ly)
flux = 2*wci*flux/flux[0] # rescale to match GEM conditions
numpy.savetxt((d+str('.dat')),flux)
Exemplo n.º 7
0
import os
import subprocess
import wxdata as wxdata2
from pylab import *
import numpy as np
from numpy import *


frames = 40
location = "/home/sousae/dbg_warpx/recon_mmc/ssrecon_wv"
minpress = 10.0

for n in range(0,frames+1):
		dh = wxdata2.WxData(location, n)
		q = dh.read('qnew')
		x = np.linspace(q.grid.lowerBounds[0],q.grid.upperBounds[0],q.grid.numPhysCells[0])
		y = np.linspace(q.grid.lowerBounds[1],q.grid.upperBounds[1],q.grid.numPhysCells[1])
		X, Y = np.meshgrid(y,x)
		by = q[:, :, 4]
		
		minpress = min(minpress,by.min())
		pcolor(Y,X,by), colorbar()
		filename = str('%03d' % n) + '_recon.png'
		savefig(filename, dpi=100)
		clf()
		
		dh.close()


command = ('mencoder',
           'mf://*_recon.png',