def __call__(self):
        'Return the locations of the ticks'
        b = self._base

        vmin, vmax = self.axis.get_view_interval()

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if vmax * vmin > 0:
            raise ValueError(
                "The interval must range from negative to positive values")

        ticklocs = []

        for limit, sgn in zip([vmax, -vmin], [1, -1]):
            numdec = numerix.floor(limit + self.threshold) - numerix.ceil(
                self.threshold)

            if self._subs is None:  # autosub
                if numdec > 10:
                    subs = numerix.array([1.0])
                elif numdec > 6:
                    subs = numerix.arange(2.0, b, 2.0)
                else:
                    subs = numerix.arange(2.0, b)
                subs = numerix.log(subs) / numerix.log(b)
            else:
                subs = self._subs
                if numdec == 0 and len(subs) == 1:
                    subs = numerix.array(
                        list(subs) + list(
                            numerix.log(numerix.arange(2.0, b)) /
                            numerix.log(b)))

            stride = 1
            while numdec // stride + 1 > self.numticks:
                stride += 1

            for decadeStart in numerix.arange(
                    numerix.floor(self.threshold),
                    numerix.ceil(limit + self.threshold) + stride, stride):
                ticks = subs + decadeStart - self.threshold
                ticklocs.extend(sgn * ticks.compress(ticks > 0))

        return numerix.array(ticklocs)
    def __call__(self):
        'Return the locations of the ticks'
        b=self._base

        vmin, vmax = self.axis.get_view_interval()

        if vmax<vmin:
            vmin, vmax = vmax, vmin

        if vmax * vmin > 0:
            raise ValueError("The interval must range from negative to positive values")

        ticklocs = []

        for limit, sgn in zip([vmax, -vmin], [1, -1]):
            numdec = numerix.floor(limit+self.threshold)-numerix.ceil(self.threshold)

            if self._subs is None: # autosub
                if numdec>10:
                    subs = numerix.array([1.0])
                elif numdec>6:
                    subs = numerix.arange(2.0, b, 2.0)
                else:
                    subs = numerix.arange(2.0, b)
                subs = numerix.log(subs) / numerix.log(b)
            else:
                subs = self._subs
                if numdec == 0 and len(subs) == 1:
                    subs = numerix.array(list(subs) + list(numerix.log(numerix.arange(2.0, b)) / numerix.log(b)))

            stride = 1
            while numdec // stride + 1 > self.numticks:
                stride += 1

            for decadeStart in numerix.arange(numerix.floor(self.threshold),
                                              numerix.ceil(limit + self.threshold)+stride,
                                              stride):
                ticks = subs + decadeStart - self.threshold
                ticklocs.extend( sgn * ticks.compress(ticks > 0) )

        return numerix.array(ticklocs)
Example #3
0
 def __str__(self):
     s = ""
     cellWidth = 11
     shape = self._getShape()
     for j in range(shape[1]):
         for i in range(shape[0]):
             v = self[j,i]
             if v == 0:
                 s += "---".center(cellWidth)
             else:
                 exp = numerix.log(abs(v))
                 if abs(exp) <= 4:
                     if exp < 0:
                         s += ("%9.6f" % v).ljust(cellWidth)
                     else:
                         s += ("%9.*f" % (6,v)).ljust(cellWidth)
                 else:
                     s += ("%9.2e" % v).ljust(cellWidth)
         s += "\n"
     return s[:-1]
Example #4
0
    def __str__(self):
        s = ''
        cellWidth = 11
        Irange, Jrange = self._range

        for j in Jrange:
            for i in Irange:
                v = self[j, i]
                if v == 0:
                    s += "---".center(cellWidth)
                else:
                    exp = numerix.log(abs(v))
                    if abs(exp) <= 4:
                        if exp < 0:
                            s += ("%9.6f" % v).ljust(cellWidth)
                        else:
                            s += ("%9.*f" % (6, v)).ljust(cellWidth)
                    else:
                        s += ("%9.2e" % v).ljust(cellWidth)
            s += "\n"
        return s[:-1]
Example #5
0
    def __str__(self):
        s = ''
        cellWidth = 11
        Irange, Jrange = self._range

        for j in Jrange:
            for i in Irange:
                v = self[j, i]
                if v == 0:
                    s += "---".center(cellWidth)
                else:
                    exp = numerix.log(abs(v))
                    if abs(exp) <= 4:
                        if exp < 0:
                            s += ("%9.6f" % v).ljust(cellWidth)
                        else:
                            s += ("%9.*f" % (6, v)).ljust(cellWidth)
                    else:
                        s += ("%9.2e" % v).ljust(cellWidth)
            s += "\n"
        return s[:-1]
Example #6
0
# def g(x_a):
#     if GIBBS == "FH":
#         #Flory-Huggins Expression
#         # The numerix.log is needed since x_a is a CellVariable and not a simple array of size 1.
#         # The standard math.log cannot cope with this.
#         return ( x_a * log(x_a) / N_A ) + ((1.0-x_a)*log(1-x_a)/ N_B) + x_a*(1.0-x_a)*chi_AB
#     elif GIBBS != "FH":
#         print ("Other free energy functions yet to be implemented")

# # Use automatic differentiation to evaluate the derivatives of the free energy
# print (g(0.5))
# dgdx_a = grad(g)
# d2gdx_a2 = grad(dgdx_a)
# print (dgdx_a(0.4))
if GIBBS == "FH":
    dgdx_a = ((1.0 / N_A) - (1.0 / N_B)) + (1.0 / N_A) * numerix.log(x_a) - (
        1.0 / N_B) * numerix.log(1.0 - x_a) + chi_AB * (1.0 - 2 * x_a)
    d2gdx_a2 = (1.0 / (N_A * x_a)) + (1.0 / (N_B * (1.0 - x_a))) - 2 * chi_AB
elif GIBBS != "FH":
    print("Implent more stuff you lazy f**k")

# Define the equations

# evaluating kappa
kappa = (2.0 / 3.0) * chi_AB

# eqn 1 is the 2nd order transport equation
eq1 = (TransientTerm(var=x_a)) == DiffusionTerm(coeff=x_a * (1 - x_a),
                                                var=mu_AB)

# Try constant mobility
Example #7
0
def currentTimeFunc(theta):
    tmp = -diffusion * numerix.log(1 - theta) + rateConstant * siteDensity * L * theta
    return tmp / rateConstant / diffusion/ cinf
Example #8
0
def currentTimeFunc(theta):
    tmp = -diffusion * numerix.log(
        1 - theta) + rateConstant * siteDensity * L * theta
    return tmp / rateConstant / diffusion / cinf
Example #9
0
# Defining the mesh
mesh = PeriodicGrid2D(nx=nx, ny=ny, dx=dx, dy=dy)

# Defining the variables
a = CellVariable(name=r"$a$", mesh=mesh, hasOld=1)
mu_AB = CellVariable(name=r"$\mu_{AB}", mesh=mesh, hasOld=1)

# Setting the initial composition of the system with noise
noise = UniformNoiseVariable(mesh=mesh,
                             minimum=(a_0 - noise_mag),
                             maximum=(a_0 + noise_mag))
a[:] = noise

# differentiate g(a)
dgda = ((1.0 / n_a) - (1.0 / n_b)) + (1.0 / n_a) * numerix.log(a) - (
    1.0 / n_b) * numerix.log(1.0 - a) + chi_AB * (1.0 - 2 * a)
d2gda2 = (1.0 / (n_a * a)) + (1.0 / (n_b * (1.0 - a))) - 2 * chi_AB

# Evaluate kappa
kappa = (2.0 / 3.0) * chi_AB

# Defining the equations
eq1 = (TransientTerm(var=a)) == DiffusionTerm(coeff=a * (1.0 - a), var=mu_AB)
eq2 = (ImplicitSourceTerm(
    coeff=1.0, var=mu_AB)) == dgda - DiffusionTerm(coeff=kappa, var=a)
# eq2 = (ImplicitSourceTerm(coeff=1.0, var=mu_AB)) == ImplicitSourceTerm(coeff=d2gda2, var=a) - d2gda2*a + dgda - DiffusionTerm(coeff=kappa, var=a)

# Coupling the equations
eq = eq1 & eq2
Example #10
0
print("Yay")

# # Define mesh
# mesh = Grid2D(dx=dx, dy=dx, nx=N_CELLS, ny=N_CELLS)
mesh = Grid2D(nx=10.0, ny=10.0, dx=1.0, dy=1.0)
print("mesh loaded")

# We need to define the relevant variables:
a = CellVariable(name=r"a", mesh=mesh, hasOld=1)
exp_a = CellVariable(name=r"exp_a", mesh=mesh, hasOld=1)
mu_AB = CellVariable(name=r"mu_AB", mesh=mesh, hasOld=1)

# We need to introduce the noise
noise = GaussianNoiseVariable(mesh=mesh,
                              mean=numerix.log(A_RAW),
                              variance=abs(numerix.log(NOISE_MAGNITUDE))).value

a[:] = noise

if GIBBS == "FH":
    dgda = (1 + a) * (numerix.exp(a) / N_A) - (numerix.exp(a) / N_B) * (
        1 + numerix.log(1.0 - numerix.exp(a))
    ) + chi_AB * numerix.exp(a) - 2.0 * chi_AB * numerix.exp(2.0 * a)
elif GIBBS != "FH":
    print("Implent more stuff you lazy f**k")

# Define the equations

# evaluating kappa
kappa = (1.0 / 6.0) * chi_AB
Example #11
0
psi = CellVariable(name=r"$\psi$", mesh=mesh)

noise = GaussianNoiseVariable(mesh=mesh, mean=0.5, variance=0.01).value
phi[:] = noise

D = a = epsilon = 1.
# kappa = log(phi)
N_A = 400
N_B = 400
chi_AB = 0.0075
kappa = chi_AB / 6.0
# dfdphi = a**2 * phi * (1 - phi) * (1 - 2 * phi)
# dfdphi_ = a**2 * (1 - phi) * (1 - 2 * phi)
# d2fdphi2 = a**2 * (1 - 6 * phi * (1 - phi))

dfdphi = ((1.0 / N_A) - (1.0 / N_B)) + (1.0 / N_A) * numerix.log(phi) - (
    1.0 / N_B) * numerix.log(1.0 - phi) + chi_AB * (1.0 - 2 * phi)
d2fdphi2 = (1.0 / (N_A * phi)) + (1.0 / (N_B * (1.0 - phi))) - 2 * chi_AB
eq1 = (TransientTerm(var=phi) == DiffusionTerm(coeff=D, var=psi))
eq2 = (ImplicitSourceTerm(
    coeff=1., var=psi) == ImplicitSourceTerm(coeff=d2fdphi2, var=phi) -
       d2fdphi2 * phi + dfdphi - DiffusionTerm(coeff=kappa, var=phi))

eq = eq1 & eq2

elapsed = 0.
dt = 1.0
if __name__ == "__main__":
    duration = 1000.

solver = LinearLUSolver(tolerance=1e-9, iterations=500)
Example #12
0
 def log(self):
     return self._UnaryOperatorVariable(lambda a: numerix.log(a))
 def nt(self, t, A=1, c = 0):
     return A*numerix.log(self.diode.generationRate.value*t) + c
Example #14
0
mesh = fp.Grid1D(nx=nx, dx=dx)

s0 = 0.1; s1 = 0.2
t0 = 1.; t1 = 0.01; t2 = 1.1

# IC
hini = 1.

h = fp.CellVariable(name="head", mesh=mesh, value=hini, hasOld=True)
h_implicit_source = fp.CellVariable(name="head_implicit_source", mesh=mesh, value=hini, hasOld=True)
h_convection = fp.CellVariable(name="head_convection", mesh=mesh, value=hini, hasOld=True)
theta = fp.CellVariable(name="theta", mesh=mesh, value=numerix.exp(s0 + s1*h.value), hasOld=True)

T = t0 * numerix.exp(t1 * h**t2)
S = s1 * numerix.exp(s0 + s1 * h) # and S_theta = s1 * theta
D = t0/s1 * numerix.exp(t1* ((numerix.log(theta) -s0)/s1)**t2)/ theta

# Plots
plotOpt = True
if plotOpt:
    fig, ax = plt.subplots(2,2)
    x = mesh.cellCenters.value[0]
    
    head = np.arange(0,10,0.1)
    th = np.exp(s0 + s1*head)
    trans = t0 * np.exp(t1 * head**t2)
    sto = s1 * np.exp(s0 + s1*head)
    diff_theta = t0 * np.exp(t1 * ((np.log(th)-s0)/s1)**t2) / (s1*th)
    diff_h = trans/sto
    
    if abs(diff_theta - diff_h).all() < 1e-5: print('D correctly calculated')