Exemplo n.º 1
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'))
Exemplo n.º 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'))
Exemplo n.º 3
0
    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'))
Exemplo n.º 4
0
        mesh=mesh,
        value=initialTemperature,
        hasOld=1
        )

    bench.stop('variables')

    bench.start()

    from fipy.tools import numerix
    mVar = phase - 0.5 - kappa1 / numerix.pi * \
        numerix.arctan(kappa2 * temperature)

    phaseY = phase.getFaceGrad().dot((0, 1))
    phaseX = phase.getFaceGrad().dot((1, 0))
    psi = theta + numerix.arctan2(phaseY, phaseX)
    Phi = numerix.tan(N * psi / 2)
    PhiSq = Phi**2
    beta = (1. - PhiSq) / (1. + PhiSq)
    betaPsi = -N * 2 * Phi / (1 + PhiSq)
    A = alpha**2 * c * (1.+ c * beta) * betaPsi
    D = alpha**2 * (1.+ c * beta)**2
    dxi = phase.getFaceGrad()._take((1, 0), axis = 1) * (-1, 1)
    anisotropySource = (A * dxi).getDivergence()
    from fipy.terms.transientTerm import TransientTerm
    from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
    from fipy.terms.implicitSourceTerm import ImplicitSourceTerm
    phaseEq = TransientTerm(tau) == ExplicitDiffusionTerm(D) + \
        ImplicitSourceTerm(mVar * ((mVar < 0) - phase)) + \
        ((mVar > 0.) * mVar * phase + anisotropySource)
Exemplo n.º 5
0
 def arctan2(self, other):
     return self._BinaryOperatorVariable(lambda a,b: numerix.arctan2(a,b), other)
Exemplo n.º 6
0
    temperature = CellVariable(name='temperature',
                               mesh=mesh,
                               value=initialTemperature,
                               hasOld=1)

    bench.stop('variables')

    bench.start()

    from fipy.tools import numerix
    mVar = phase - 0.5 - kappa1 / numerix.pi * \
        numerix.arctan(kappa2 * temperature)

    phaseY = phase.getFaceGrad().dot((0, 1))
    phaseX = phase.getFaceGrad().dot((1, 0))
    psi = theta + numerix.arctan2(phaseY, phaseX)
    Phi = numerix.tan(N * psi / 2)
    PhiSq = Phi**2
    beta = (1. - PhiSq) / (1. + PhiSq)
    betaPsi = -N * 2 * Phi / (1 + PhiSq)
    A = alpha**2 * c * (1. + c * beta) * betaPsi
    D = alpha**2 * (1. + c * beta)**2
    dxi = phase.getFaceGrad()._take((1, 0), axis=1) * (-1, 1)
    anisotropySource = (A * dxi).getDivergence()
    from fipy.terms.transientTerm import TransientTerm
    from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
    from fipy.terms.implicitSourceTerm import ImplicitSourceTerm
    phaseEq = TransientTerm(tau) == ExplicitDiffusionTerm(D) + \
        ImplicitSourceTerm(mVar * ((mVar < 0) - phase)) + \
        ((mVar > 0.) * mVar * phase + anisotropySource)
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()