def sphericalDatapoint(theta, phi):
    # Expect theta and rho to be in radians
    #   theta is the angle from the +z-axis to the coordinate vector
    #   rho is the angle from the +x-axis to projection of the coordinate
    #     vector onto the xy-plane
    sin_theta = numerix.sin(theta)
    print(sin_theta)
    cos_theta = numerix.cos(theta)
    sin_phi = numerix.sin(phi)
    #print(len(sin_phi))
    cos_phi = numerix.cos(phi)
    return sin_theta * getCellVariableDatapoint.remote(
        [[sin_theta * cos_phi], [sin_theta * sin_phi], [cos_theta]])
Exemple #2
0
    def _plot(self):

        var = self.vars[0]
        mesh = var.mesh

        U, V = var.numericValue

        U = numerix.take(U, self.indices)
        V = numerix.take(V, self.indices)

        ang = numerix.arctan2(V, U)
        mag = numerix.sqrt(U**2 + V**2)

        datamin, datamax = self._autoscale(vars=(mag, ),
                                           datamin=self._getLimit('datamin'),
                                           datamax=self._getLimit('datamax'))

        mag = numerix.where(mag > datamax, datamax, mag)
        mag = numerix.ma.masked_array(mag, mag < datamin)

        if self.log:
            mag = numerix.log10(mag)
            mag = numerix.ma.masked_array(mag, numerix.isnan(mag))

        U = mag * numerix.cos(ang)
        V = mag * numerix.sin(ang)

        self._quiver.set_UVC(U, V)

        self.axes.set_xlim(xmin=self._getLimit('xmin'),
                           xmax=self._getLimit('xmax'))
        self.axes.set_ylim(ymin=self._getLimit('ymin'),
                           ymax=self._getLimit('ymax'))
    def _plot(self):

        var = self.vars[0]
        mesh = var.mesh

        U, V = var.numericValue

        U = numerix.take(U, self.indices)
        V = numerix.take(V, self.indices)
        
        ang = numerix.arctan2(V, U)
        mag = numerix.sqrt(U**2 + V**2)
        
        datamin, datamax = self._autoscale(vars=(mag,),
                                           datamin=self._getLimit('datamin'),
                                           datamax=self._getLimit('datamax'))
        
        mag = numerix.where(mag > datamax, datamax, mag)
        mag = numerix.ma.masked_array(mag, mag < datamin)
        
        if self.log:
            mag = numerix.log10(mag)
            mag = numerix.ma.masked_array(mag, numerix.isnan(mag))
            
        U = mag * numerix.cos(ang)
        V = mag * numerix.sin(ang)

        self._quiver.set_UVC(U, V)
        
        self.axes.set_xlim(xmin=self._getLimit('xmin'),
                           xmax=self._getLimit('xmax'))
        self.axes.set_ylim(ymin=self._getLimit('ymin'),
                           ymax=self._getLimit('ymax'))
Exemple #4
0
    def getElectrolyteMask(self):
        x, y = self.getCellCenters()
        
        Y = (y - (self.heightBelowTrench + self.trenchDepth / 2))

        ## taper
        taper = numerix.tan(self.angle) * Y

        ## bow
        if abs(self.bowWidth) > 1e-12 and (-self.trenchDepth / 2 < Y < self.trenchDepth / 2):
            param1 = self.trenchDepth**2 / 8 / self.bowWidth
            param2 = self.bowWidth / 2
            bow = -numerix.sqrt((param1 + param2)**2 - Y**2) + param1 - param2
        else:
            bow = 0

        ## over hang
        Y = y - (self.heightBelowTrench + self.trenchDepth - self.overBumpRadius)

        overBump = 0

        if self.overBumpRadius > 1e-12:            
            overBump += numerix.where(Y > -self.overBumpRadius,
                                      self.overBumpWidth / 2 * (1 + numerix.cos(Y * numerix.pi / self.overBumpRadius)),
                                      0)

        tmp = self.overBumpRadius**2 - Y**2
        tmp = (tmp > 0) * tmp
        overBump += numerix.where((Y > -self.overBumpRadius) & (Y > 0),
                                  numerix.where(Y > self.overBumpRadius,
                                                -self.overBumpRadius,
                                                -(self.overBumpRadius - numerix.sqrt(tmp))),
                                  0)

        return numerix.where(y > self.trenchDepth + self.heightBelowTrench,
                             1,
                             numerix.where(y < self.heightBelowTrench,
                                           0,
                                           numerix.where(x > self.trenchWidth / 2 + taper - bow - overBump,
                                                         0,
                                                         1)))
    def _plot(self):
        from scipy.interpolate import griddata

        var = self.vars[0]
        mesh = var.mesh

        xmin, ymin = mesh.extents['min']
        xmax, ymax = mesh.extents['max']

        N = 100
        X = numerix.linspace(xmin, xmax, N)
        Y = numerix.linspace(ymin, ymax, N)

        grid_x, grid_y = numerix.mgrid[xmin:xmax:N * 1j, ymin:ymax:N * 1j]

        if isinstance(var, FaceVariable):
            C = mesh.faceCenters
        elif isinstance(var, CellVariable):
            C = mesh.cellCenters

        U = griddata(C.value.T, var.value[0], (grid_x, grid_y), method='cubic')
        V = griddata(C.value.T, var.value[1], (grid_x, grid_y), method='cubic')

        lw = self.linewidth
        if isinstance(lw, (FaceVariable, CellVariable)):
            lw = griddata(C.value.T,
                          lw.value, (grid_x, grid_y),
                          method='cubic')

        color = self.color
        if isinstance(color, (FaceVariable, CellVariable)):
            color = griddata(C.value.T,
                             color.value, (grid_x, grid_y),
                             method='cubic',
                             fill_value=color.min())

        U = U.T
        V = V.T

        ang = numerix.arctan2(V, U)
        mag = numerix.sqrt(U**2 + V**2)

        datamin, datamax = self._autoscale(vars=(mag, ),
                                           datamin=self._getLimit('datamin'),
                                           datamax=self._getLimit('datamax'))

        mag = numerix.where(mag > datamax, numerix.nan, mag)
        mag = numerix.where(mag < datamin, numerix.nan, mag)

        if self.log:
            mag = numerix.log10(mag)

        U = mag * numerix.cos(ang)
        V = mag * numerix.sin(ang)

        #         if self._stream is not None:
        #             # the following doesn't work, nor does it help to `add_collection` first
        #             # self._stream.arrows.remove()
        #             self._stream.lines.remove()

        self.axes.cla()
        self._stream = self.axes.streamplot(X,
                                            Y,
                                            U,
                                            V,
                                            linewidth=lw,
                                            color=color,
                                            **self.kwargs)

        self.axes.set_xlim(xmin=self._getLimit('xmin'),
                           xmax=self._getLimit('xmax'))
        self.axes.set_ylim(ymin=self._getLimit('ymin'),
                           ymax=self._getLimit('ymax'))
Exemple #6
0
eq = ceq & psieq & Phieq

x, y = mesh.cellCenters
X, Y = mesh.faceCenters

Phi.faceGrad.constrain(0.,
                       where=mesh.physicalFaces["top"]
                       | mesh.physicalFaces["bottom"])
Phi.constrain(0., where=mesh.physicalFaces["left"])
Phi.constrain(sin(Y / 7.), where=mesh.physicalFaces["right"])

c0 = 0.5
c1 = 0.04
c.setValue(c0 + c1 *
           (cos(0.2 * x) * cos(0.11 * y) +
            (cos(0.13 * x) * cos(0.087 * y))**2 + cos(0.025 * x - 0.15 * y) *
            (cos(0.07 * x - 0.02 * y))))
Phi.setValue(0.)

synchTimes = [0, 5, 10, 20, 50, 100, 200, 400, 1000]
synchTimes.reverse()

t = synchTimes.pop()


def saveData(t, dt, dt_synch):
    if dt_synch == dt:
        fp.tools.dump.write(
            (c, Phi), filename=data["t={}.tar.gz".format(t)].make().abspath)
Exemple #7
0
from fipy.tools import numerix

L = 2.
X0 = -1.
nx = 800
cfl = 0.1
K = 4.
rho = 1.

dx = L / nx
m = Grid1D(nx=nx, dx=dx) + X0
x, = m.cellCenters

q = CellVariable(mesh=m, rank=1, elementshape=(2, ))

q[0, :] = numerix.exp(-50 * (x - 0.3)**2) * numerix.cos(20 * (x - 0.3))
q[0, x > 0.3] = 0.

Ax = FaceVariable(mesh=m,
                  rank=3,
                  value=[((0, K), (1 / rho, 0))],
                  elementshape=(1, 2, 2))

eqn = TransientTerm() + CentralDifferenceConvectionTerm(Ax) == 0

if __name__ == '__main__':
    from fipy import MatplotlibViewer as Viewer
    vi = Viewer((q[0], q[1]))
    vi.plot()

for step in range(500):
def delta_func(x, epsilon, coeff):
    return ((x < epsilon) & (x > -epsilon)) * \
        (coeff * (1 + numerix.cos(numerix.pi * x / epsilon)) / (2 * epsilon))
    m_cell_sph = numerix.append(
        m_cell_sph, (m_cell_modified_sph_pol),
        axis=1)  #Appending the m values in spherical polar coordinate

    theta_sz = np.shape(theta_sorted)
    size = theta_sz[0]
    total_size = total_size + size  # calculate total number of cells being covered during calculation

    phi_value = phi_value + delta  # phi is increased by delta at end of each loop

print('Total number of cells covered = ' + str(total_size))
#type(m_cell_sph)

######## Converted the spherical polar coordinates back to cartesian coordinate #####################
m_x = (m_cell_sph[0, :] * numerix.sin(m_cell_sph[2, :]) *
       numerix.cos(m_cell_sph[1, :]))
m_y = (m_cell_sph[0, :] * numerix.sin(m_cell_sph[2, :]) *
       numerix.sin(m_cell_sph[1, :]))
m_z = m_cell_sph[0, :] * numerix.cos(m_cell_sph[2, :])

m_cellcenters_cart_modified = numerix.array([[m_x], [m_y], [m_z]])
#numerix.shape(m_cellcenters_cart_modified)

m_cellcenters_cart_modified = numerix.reshape(m_cellcenters_cart_modified,
                                              (3, total_size))

#mcell_new=m_cellcenters_cart_modified*CellVariable([1.0])

mcell_new = CellVariable(mesh=mesh, value=m_cellcenters_cart_modified)

#type(mcell_new)
Exemple #10
0
magVolume = 1.0e-9 * (40e-9 * 40e-9) * (numerix.pi / 4.0)  # in m^3
#magVolume=(numerix.pi/4)*length*width*thickness
delta = 43.0
Eb = delta * kBoltzmann * Temperature
Ku2 = Eb / magVolume
#Ku2 = 2.245e5                   # in J/m^3
#print('Ku2 = '+str(Ku2))

D = alphaDamping * gamFac * kBoltzmann * Temperature / (
    (1 + alphaDamping**2) * Msat * magVolume)  # unit 1/s

# ### Calculation of uniaxial anisotropy field

th = numerix.pi / 6.0
ph = 0.0 * numerix.pi
ux = numerix.sin(th) * numerix.cos(ph)
uy = numerix.sin(th) * numerix.sin(ph)
uz = numerix.cos(th)
uAxis = numerix.array([[ux, uy, uz]])

#uAxis=numerix.array([[0.0,0.0,1.0]])

HuniaxBase = H_UniaxialAnisotropy(mAllCell, uAxis, Ku2, Msat)
print('Max_Huni=' + str(max(HuniaxBase[2, :])))
print('Min_Huni=' + str(min(HuniaxBase[2, :])))

######## Create matrix form of applied magnetic field ####################################
th = numerix.pi / 6.0
ph = 0.0 * numerix.pi
ux = numerix.sin(th) * numerix.cos(ph)
uy = numerix.sin(th) * numerix.sin(ph)
Exemple #11
0
 def cos(self):
     return self._UnaryOperatorVariable(lambda a: numerix.cos(a))
Exemple #12
0
from fipy.tools import numerix

L = 2.
X0 = -1.
nx = 800
cfl = 0.1
K = 4.
rho = 1.

dx = L / nx
m = Grid1D(nx=nx, dx=dx) + X0
x, = m.cellCenters

q = CellVariable(mesh=m, rank=1, elementshape=(2,))

q[0,:] = numerix.exp(-50 * (x - 0.3)**2) * numerix.cos(20 * (x - 0.3))
q[0, x > 0.3] = 0.

Ax = FaceVariable(mesh=m, rank=3, value=[((0, K), (1 / rho, 0))], elementshape=(1, 2, 2))

eqn = TransientTerm() + CentralDifferenceConvectionTerm(Ax) == 0

if  __name__ == '__main__':
    from fipy import MatplotlibViewer as Viewer
    vi = Viewer((q[0], q[1]))
    vi.plot()

for step in range(500):
    eqn.solve(q, dt=cfl * dx)
    if step % 10 ==  0 and  __name__ == '__main__':
        vi.plot()
Exemple #13
0
    v1.setName('KM')
    v2.setName('PN')
    v3.setName('TM')

    KMViewer = fipy.viewers.make((v1, v2, v3), title = 'Gradient Stimulus: Profile')

    KMViewer.plot()

    for i in range(100):
        for var, eqn in eqs:
            var.updateOld()
        for var, eqn in eqs:
            eqn.solve(var, dt = 1.)

    from fipy.tools import numerix
    RVar[:] = params['S'] + (1 + params['S']) * params['G'] * numerix.cos((2 * numerix.pi * mesh.getCellCenters()[:,0]) / L)

    for i in range(100):
        for var, eqn in eqs:
            var.updateOld()
        for var, eqn in eqs:
            eqn.solve(var, dt = 0.1)
        KMViewer.plot()

    KMViewer.plot()

    raw_input("finished")

    

def make_tau(phase_):
    theta_cell = numerix.arctan2(phase_.grad[1], phase_.grad[0])
    a_cell = 1 + epsilon_m * numerix.cos(mm * theta_cell + theta_0)
    return tau_0 * a_cell**2
initialize()


def make_tau(phase_):
    theta_cell = numerix.arctan2(phase_.grad[1], phase_.grad[0])
    a_cell = 1 + epsilon_m * numerix.cos(mm * theta_cell + theta_0)
    return tau_0 * a_cell**2

tau = make_tau(phase)
tau_old = make_tau(phase.old)

source = (phase - lamda * uu * (1 - phase**2)) * (1 - phase**2)


theta = numerix.arctan2(phase.faceGrad[1], phase.faceGrad[0])
W = W_0 * (1 + epsilon_m * numerix.cos(mm * theta - theta_0))

W_theta = - W_0 * mm * epsilon_m * numerix.sin(mm * theta - theta_0)

# Build up the diffusivity matrix
I0 = Variable(value=((1,0), (0,1)))
I1 = Variable(value=((0,-1), (1,0)))
Dphase = W**2 * I0 + W * W_theta * I1


heat_eqn = TransientTerm() == DiffusionTerm(DD) + (phase - phase.old) / dt / 2.

phase_eqn = TransientTerm(tau) == DiffusionTerm(Dphase) + source

initialize()