Ejemplo n.º 1
0
def IC_condition(Nx, Np, u, v, u_hat, v_hat, ICchoice, omega, omega_hat, X, Y):
    #todo this initial condition function does not work for any amount of processes
    # I need to discretize the initial condition amongst the processes after setting IC.
    if ICchoice == 'randomVel':
        u = random.rand(Np, Ny)
        v = random.rand(Np, Ny)
        #  u = u / npmax(u)
        # v = v / npmax(v)
        u_hat = fftn_mpi(u, u_hat)
        v_hat = fftn_mpi(v, v_hat)
        omega_hat = 1j * (Kx * v_hat - Ky * u_hat)
    if ICchoice == 'TaylorGreen':
        u = sin(3 * X) * cos(3 * Y)
        v = -cos(3 * X) * sin(3 * Y)
        #  u = u / npmax(u)
        # v = v / npmax(v)
        u_hat = fftn_mpi(u, u_hat)
        v_hat = fftn_mpi(v, v_hat)
        omega_hat = 1j * (Kx * v_hat - Ky * u_hat)
    if ICchoice == 'Vel1':
        if rank == 0:
            # u =
            ## v =
            # u = u/npmax(u)
            # v = v/npmax(v)
            # u_hat = fftn_mpi(u, u_hat)
            # v_hat = fftn_mpi(v, v_hat)
            u_hat[2, 2] = 5 + 10j
            v_hat[2, 2] = 5 + 10j
            u_hat[5, 2] = 5 + 10j
            v_hat[5, 2] = 5 + 10j
            u_hat[2, 3] = 5 + 10j
            v_hat[2, 3] = 5 + 10j
        u = ifftn_mpi(u_hat, u)
        v = ifftn_mpi(v_hat, v)
        u = u / npmax(u)
        v = v / npmax(v)
        u_hat = fftn_mpi(u, u_hat)
        v_hat = fftn_mpi(v, v_hat)
        omega_hat = 1j * (Kx * v_hat - Ky * u_hat)
    if ICchoice == 'omegahat1':
        if rank == 0:
            random.seed(1969)
            omega_hat[0, 4] = random.uniform() + 1j * random.uniform()
            omega_hat[1, 1] = random.uniform() + 1j * random.uniform()
            omega_hat[3, 0] = random.uniform() + 1j * random.uniform()
            omega_hat[2, 3] = random.uniform() + 1j * random.uniform()
            omega_hat[5, 3] = random.uniform() + 1j * random.uniform()

        omega = abs(ifftn_mpi(omega_hat, omega))
        omega = omega / npmax(omega)
        omega_hat = fftn_mpi(omega, omega_hat)
    if ICchoice == 'omega1':
        omega = sin(X) * cos(Y)
        omega_hat = fftn_mpi(omega, omega_hat)
    if ICchoice == 'omegahatrandom':
        omega_hat = random.rand(N, Np) * 1j + random.rand(N, Np)
        binary = random.choice([0, 1], size=(N, Np), p=[7. / 10, 3. / 10])
        omega_hat = omega_hat * binary
    if ICchoice == 'omega3':
        H = exp(-((2*X - pi + pi / 5) ** 2 + (4*Y - pi + pi / 5) ** 2) / 0.3) - exp(
            -((2*X - pi - pi / 5) ** 2 + (3*Y - pi + pi / 5) ** 2) / 0.2) + exp(
            -((3*X - pi - pi / 5) ** 2 + (2*Y - pi - pi / 5) ** 2) / 0.4)+exp(-((2*X - pi + pi / 5)**2 + (Y - pi + pi / 5) ** 2) / 0.3) - exp(
            -((X - pi - pi / 5)**2 + (Y - pi + pi / 5) ** 2) /0.2) + exp(-((X - pi - pi / 5)**2 + (3*Y - pi - pi / 5)**2)/0.4)+\
            exp(-((X - pi + pi / 5)**2 + (Y - pi + pi / 5) ** 2) / 0.3) + exp(
            -((X - pi - pi / 5)**2 + (3*Y - pi + pi / 5) ** 2) /0.3) - exp(-((X - pi - pi / 5)**2 + (Y - pi - pi / 5)**2)/0.4)
        epsilon = 0.4
        Noise = random.rand(Np, Ny)
        omega = H + Noise * epsilon
        omega_hat = (fftn_mpi(omega, omega_hat))
        omega = real(ifftn_mpi(omega_hat, omega))
    if ICchoice == 'omega4':
        H = exp(-((2*X - pi + pi / 5) ** 2 + (4*Y - pi + pi / 5) ** 2) / 0.3) - exp(
            -((2*X - pi - pi / 5) ** 2 + (3*Y - pi + pi / 5) ** 2) / 0.2) + exp(
            -((X + pi - pi / 5) ** 2 + (2*Y - pi - pi / 5) ** 2) / 0.4)+exp(-((2*X - pi + pi / 5)**2 + (Y - pi + pi / 5) ** 2) / 0.3) - exp(
            -((X - pi - pi / 5)**2 + (Y - pi + pi / 5) ** 2) /0.2) + exp(-((X - pi - pi / 5)**2 + (3*Y - pi - pi / 5)**2)/0.4)+\
            exp(-((X - pi + pi / 5)**2 + (Y - pi + pi / 5) ** 2) / 0.3) + exp(
            -((X - pi - pi / 5)**2 + (3*Y - pi + pi / 5) ** 2) /0.3) + exp(-((X + pi - pi / 5)**2 + (Y + pi - pi / 5)**2)/0.4)-\
            exp(-((X - pi + pi / 5) ** 2 + (Y - pi + pi / 5) ** 2) / 0.3) + exp(
            -((2*X - pi - pi / 5) ** 2 + (3*Y - pi + pi / 5) ** 2) / 0.2) + exp(
            -((X - pi - pi / 5) ** 2 + (Y - pi - pi / 5) ** 2) / 0.4)
        epsilon = 0.7
        Noise = random.rand(Np, Ny)
        omega = H + Noise * epsilon
        omega_hat = (fftn_mpi(omega, omega_hat))
        omega = real(ifftn_mpi(omega_hat, omega))
    if ICchoice == 'omega2':

        H = exp(-((X - pi + pi / 5)**2 + (Y - pi + pi / 5)**2) / 0.3) - exp(-(
            (X - pi - pi / 5)**2 +
            (Y - pi + pi / 5)**2) / 0.2) + exp(-((X - pi - pi / 5)**2 +
                                                 (Y - pi - pi / 5)**2) / 0.4)
        #epsilon = 0.1;
        #Noise = random.rand(Np, Ny)
        omega = H
        omega_hat = (fftn_mpi(omega, omega_hat))
        omega = real(ifftn_mpi(omega_hat, omega))
    return omega_hat
Ejemplo n.º 2
0
    imgx = 20
    imgy = 0
    def pltshow(plt, dpi=300):
        global imgx, imgy
        temppath = tempimage()
        plt.savefig(temppath, dpi=dpi)
        dx,dy = imagesize(temppath)
        w = min(W,dx)
        image(temppath,imgx,imgy,width=w)
        imgy = imgy + dy + 20
        os.remove(temppath)
        size(W, HEIGHT+dy+40)
else:
    def pltshow(mplpyplot):
        mplpyplot.show()
# nodebox section end


x = [val*radians for val in np.arange(0, 15, 0.01)]

fig = plt.figure()
fig.subplots_adjust(hspace=0.3)

ax = fig.add_subplot(211)
line1, = ax.plot(x, cos(x), xunits=radians)

ax = fig.add_subplot(212)
line2, = ax.plot(x, cos(x), xunits=degrees)

pltshow(plt)
Ejemplo n.º 3
0
"""
Plot with radians from the basic_units mockup example package
This example shows how the unit class can determine the tick locating,
formatting and axis labeling.
"""
import numpy as np
from basic_units import radians, degrees, cos
from pylab import figure, show
from matplotlib.cbook import iterable
import math

x = np.arange(0, 15, 0.01) * radians

fig = figure()

ax = fig.add_subplot(211)
ax.plot(x, cos(x), xunits=radians)

ax = fig.add_subplot(212)
ax.plot(x, cos(x), xunits=degrees)

show()
Ejemplo n.º 4
0
"""
Plot with radians from the basic_units mockup example package
This example shows how the unit class can determine the tick locating,
formatting and axis labeling.
"""
import numpy as np
from basic_units import radians, degrees, cos
from matplotlib.pyplot import figure, show

x = [val * radians for val in np.arange(0, 15, 0.01)]

fig = figure()
fig.subplots_adjust(hspace=0.3)

ax = fig.add_subplot(211)
line1, = ax.plot(x, cos(x), xunits=radians)

ax = fig.add_subplot(212)
line2, = ax.plot(x, cos(x), xunits=degrees)

show()
Ejemplo n.º 5
0
import numpy as np
from basic_units import radians, degrees, cos
from pylab import figure, show

x = np.arange(0, 15, 0.01) * radians

fig = figure()
fig.subplots_adjust(hspace=0.3)
ax = fig.add_subplot(211)
ax.plot(x, cos(x), xunits=radians)

ax = fig.add_subplot(212)
ax.plot(x, cos(x), xunits=degrees)

show()

plt.style.use(astropy_mpl_style)
from matplotlib import rc
rc('font', **{'family': 'serif', 'serif': ['Palatino']})
rc('text', usetex=True)
rc('text.latex',
   preamble=r'''\usepackage{amsmath}
          \usepackage{physics}
          \usepackage{siunitx}
          ''')

from basic_units import cos, sin, radians

theta_r = np.linspace(0, 2 * np.pi, num=1000)
theta = np.array([x * radians for x in theta_r])

a = (1 - cos(theta)) / 2
t = (theta_r - sin(theta)) / 2

plt.plot(theta, a, label='Scale factor $a$')
plt.plot(theta, t, label='Time $t$')
plt.xlabel('Angle parameter $\\theta$')
plt.ylabel(
    'Normalized scale factor $a / \\widetilde{a}_0$ or time $t / \\widetilde{t}_0$'
)
plt.legend()
plt.savefig('positive_curvature_a.pdf', format='pdf')
# plt.show()
plt.close()

plt.plot(t, a)
plt.xlabel("Time $t / \\widetilde{t}_0$")
Ejemplo n.º 7
0
"""
============
Radian ticks
============

Plot with radians from the basic_units mockup example package.


This example shows how the unit class can determine the tick locating,
formatting and axis labeling.

.. only:: builder_html

   This example requires :download:`basic_units.py <basic_units.py>`
"""

import matplotlib.pyplot as plt
import numpy as np

from basic_units import radians, degrees, cos

x = [val*radians for val in np.arange(0, 15, 0.01)]

fig, axs = plt.subplots(2)

axs[0].plot(x, cos(x), xunits=radians)
axs[1].plot(x, cos(x), xunits=degrees)

fig.tight_layout()
plt.show()