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]])
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'))
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'))
stats = [] Phieq = fp.DiffusionTerm(var=Phi) == fp.ImplicitSourceTerm(coeff=-k / epsilon, var=c) 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()
d2fchemd2c * c + dfchemdc - fp.DiffusionTerm(coeff=kappa, var=c) + fp.ImplicitSourceTerm(coeff=k, var=Phi)) stats = [] Phieq = fp.DiffusionTerm(var=Phi) == fp.ImplicitSourceTerm(coeff=-k / epsilon, var=c) eq = ceq & psieq & Phieq x, y = mesh.cellCenters X, Y = mesh.faceCenters Phi.faceGrad.constrain(0., where=mesh.facesTop | mesh.facesBottom) Phi.constrain(0., where=mesh.facesLeft) Phi.constrain(sin(Y / 7.), where=mesh.facesRight) 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()
#print(numerix.shape(m_cell_modified_sph_pol)) 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)
def one_fourier (n): mode = (-2.0/(n*pi))*numerix.sin(n*pi*x)*numerix.exp(-t*(pi**2)*(n**2)) return mode
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)
def sin(self): return self._UnaryOperatorVariable(lambda a: numerix.sin(a))
vacuum = ~(ntype | ptype) # Assigning material properties to each Cell cdse_cdte = (CdSe() * ntype + CdTe() * ptype + Vacuum() * vacuum) nFaces = mesh.facesLeft pFaces = mesh.facesRight illuminatedFaces =mesh.facesLeft nContact = OhmicContact(faces=nFaces) pContact = OhmicContact(faces=pFaces) ##graded doping x_dummy = x.value*(x.value>=n_thickness) y_dummy = (1e22*(x_dummy-n_thickness)/(p_thickness-n_thickness) + 1e17 )*(x.value>=n_thickness) #linear y_dummy =1e21*abs(numerix.sin((x_dummy-n_thickness)*2e6))# abs(sin(x)) diode = Device(mesh=mesh, temperature=300, # K material=cdse_cdte, dopants=(Donor(concentration=1e23 * ntype, # m**-3" ionizationEnergy=-1.), # eV Acceptor(concentration=y_dummy * ptype, # m**-3 ionizationEnergy=-1.)), # eV traps=(ShockleyReadHallTrap(recombinationLevel=0, # eV electronMinimumLifetime=3e-11, # s holeMinimumLifetime=3e-11),), # s contacts=(pContact, nContact)) diode.contacts[1].bias.value = 0. # V
import re import os # Setting up a mesh nx = 50 dx = 0.02 L = nx * dx mesh = Grid1D(nx=nx, dx=dx) # Defining the cell variable c = CellVariable(mesh=mesh, name=r"$c$") # Initialise c with a funky profile x = mesh.cellCenters[0] c.value = 0.0 c.setValue((0.3 * numerix.sin(2.0 * x * numerix.pi)) + 0.5) # Setting up the no-flux boundary conditions c.faceGrad.constrain(0.0, where=mesh.facesLeft) c.faceGrad.constrain(0.0, where=mesh.facesRight) # Provide value for diffusion and reaction coefficient D = 1.0 k = -2.0 # Specifying our alpha value. We will only use backwards Euler going forward alpha = 1 # Defining the equation with the reaction term. eq = TransientTerm() == DiffusionTerm(coeff=D) + ImplicitSourceTerm(coeff=k)
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() solid_area = (np.array(phase.globalValue)>0).sum()*dx*dy # initial size of solid nucleus if parallelComm.procID==0: