def define_ode(self, current_time):

        x, y = self.mesh.faceCenters

        # Internal source specificatio - currently no functional
        internal_source_value = self.parameter.internal_source_value
        internal_source_region = self.parameter.internal_source_region

        internal_source_mask = (
            (x > internal_source_region.xmin) &
            (x < internal_source_region.xmax) &
            (y > internal_source_region.ymin) &
            (y < internal_source_region.ymax)
        )

        # Get convection data
        convection = self.define_convection_variable(current_time)

        eq = TransientTerm() == - ConvectionTerm(coeff=convection) \
            + DiffusionTerm(coeff=self.parameter.Diffusivity)\
            - ImplicitSourceTerm(coeff=self.parameter.Decay)\
            # + ImplicitSourceTerm(coeff=internal_source_value*internal_source_mask)  # Internal source not working

        return eq
コード例 #2
0
'''Equations to solve for each varible must be defined:
  -TransientTerm = dvar/dt
  -ConvectionTerm = dvar/dx
  -DiffusionTerm = d^2var/dx^2
  -Source terms can be described as they would appear mathematically
Notes:  coeff = terms that are multiplied by the Term.. must be rank-1 FaceVariable for ConvectionTerm
        "var" must be defined for each Term if they are not all the variable being solved for,
        otherwise will see "fipy.terms.ExplicitVariableError: Terms with explicit Variables cannot mix with Terms with implicit Variables." '''

#In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

Pion.equation = TransientTerm(
    coeff=1,
    var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad, var=Pion) +
                         Pion * potential.faceGrad.divergence) + DiffusionTerm(
                             coeff=Dp, var=Pion) - k_rec * Pion * Nion

#In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

Nion.equation = TransientTerm(
    coeff=1, var=Nion
) == -mu_n * (ConvectionTerm(coeff=potential.faceGrad, var=Nion) +
              Nion * potential.faceGrad.divergence) + DiffusionTerm(
                  coeff=Dn, var=Nion) - k_rec * Pion * Nion

#In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density = Pion + Nion
# Poisson's Equation
コード例 #3
0
# plt.plot(x, y01(x))
# plt.plot(x, y03(x))
# plt.show()

mesh = Grid1D(dx=dx, nx=nx)  # Establish mesh in how many dimensions necessary
Pion = CellVariable(mesh=mesh, name='Positive ion Charge Density', value=y01(x))
Nion = CellVariable(mesh=mesh, name='Negative ion Charge Density', value=y02(x))
# Hole = CellVariable(mesh=mesh, name='Hole Density',value=y03(x))
# Electron = CellVariable(mesh=mesh, name='Electron Density',value=y04(x))
potential = CellVariable(mesh=mesh, name='Potential')

#### Equations set-up ####
# In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Pion_equation = TransientTerm(coeff=1., var=Pion) == mu_p_1 * ConvectionTerm(coeff=potential.faceGrad, var=Pion) + Dp_1 * DiffusionTerm(coeff=1., var=Pion) - k_rec * Pion * Nion
# In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Nion_equation = TransientTerm(coeff=1., var=Nion) == -mu_n_1 * ConvectionTerm(coeff=potential.faceGrad, var=Nion) + Dn_1 * DiffusionTerm(coeff=1., var=Nion) - k_rec * Pion * Nion
# Electron_equation = TransientTerm(coeff=1., var=Electron) == -mu_n_2 * ConvectionTerm(coeff=potential.faceGrad, var=Electron) + Dn_2 * DiffusionTerm(coeff=1., var=Electron) - k_rec * Electron * Hole
# Hole_equation = TransientTerm(coeff=1., var=Hole) == mu_p_2 * ConvectionTerm(coeff=potential.faceGrad, var=Hole) + Dp_2 * DiffusionTerm(coeff=1., var=Hole) - k_rec * Electron * Hole
# In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density= Pion-Nion
# Poisson's Equation
potential_equation = DiffusionTerm(coeff=1., var=potential) == -(q / epsilon) * (Pion - Nion)
# potential_equation = DiffusionTerm(coeff=1., var=potential) == -(q / epsilon) * (Pion - Nion + Hole - Electron)
### Boundary conditions ###
# Fipy is defaulted to be no-flux, so we only need to constrain potential

potential.constrain(0., where=mesh.exteriorFaces)
コード例 #4
0
y02 = np.zeros(nx)
y02[0:500] = 0.5e21

mesh = Grid1D(dx=dx, nx=nx)  # Establish mesh in how many dimensions necessary

Pion = CellVariable(mesh=mesh, name='Positive ion Charge Density', value=y01)
Nion = CellVariable(mesh=mesh, name='Negative ion Charge Density', value=y02)
potential = CellVariable(mesh=mesh, name='Potential')

#### Equations set-up ####

# In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Pion_equation = TransientTerm(coeff=1., var=Pion) == mu_p * ConvectionTerm(
    coeff=potential.faceGrad, var=Pion) + Dp * DiffusionTerm(
        coeff=1., var=Pion) - k_rec * Pion * Nion

# In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Nion_equation = TransientTerm(coeff=1., var=Nion) == -mu_n * ConvectionTerm(
    coeff=potential.faceGrad, var=Nion) + Dn * DiffusionTerm(
        coeff=1., var=Nion) - k_rec * Pion * Nion

# In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density= Pion-Nion
# Poisson's Equation
potential_equation = DiffusionTerm(
    coeff=1., var=potential) == -(q / epsilon) * (Pion - Nion)

### Boundary conditions ###
コード例 #5
0
mesh = Grid1D(dx=dx, nx=nx)  # Establish mesh in how many dimensions necessary
Pion = CellVariable(mesh=mesh,
                    name='Positive ion Charge Density',
                    value=y01(x))
Nion = CellVariable(mesh=mesh,
                    name='Negative ion Charge Density',
                    value=y02(x))
Hole = CellVariable(mesh=mesh, name='Hole Density', value=y03(x))
Electron = CellVariable(mesh=mesh, name='Electron Density', value=y04(x))
potential = CellVariable(mesh=mesh, name='Potential')

#### Equations set-up ####
# In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Pion_equation = TransientTerm(coeff=1., var=Pion) == mu_p_1 * ConvectionTerm(
    coeff=potential.faceGrad, var=Pion) + Dp_1 * DiffusionTerm(
        coeff=1., var=Pion) - k_rec * Pion * Nion
# In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation
Nion_equation = TransientTerm(coeff=1., var=Nion) == -mu_n_1 * ConvectionTerm(
    coeff=potential.faceGrad, var=Nion) + Dn_1 * DiffusionTerm(
        coeff=1., var=Nion) - k_rec * Pion * Nion
Electron_equation = TransientTerm(
    coeff=1., var=Electron) == -mu_n_2 * ConvectionTerm(
        coeff=potential.faceGrad, var=Electron) + Dn_2 * DiffusionTerm(
            coeff=1., var=Electron) - k_rec * Electron * Hole
Hole_equation = TransientTerm(coeff=1., var=Hole) == mu_p_2 * ConvectionTerm(
    coeff=potential.faceGrad, var=Hole) + Dp_2 * DiffusionTerm(
        coeff=1., var=Hole) - k_rec * Electron * Hole
# In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density= Pion-Nion
コード例 #6
0
ファイル: simulation.py プロジェクト: zhaoshiii/spin-fpe
#m = odeint(model, m0, t)
#vol = volt(m,t)
xx = mesh.faceCenters[0]
yy = mesh.faceCenters[1]
zz = mesh.faceCenters[2]
ll = len(xx)
print("size of ll = " + str(ll))
lista = []

for i in range(0, 5):
    for j in range(0, ll):
        point = np.array([xx[j], yy[j], zz[j]])
        gradient = model(point, i * 1e-9)
        print(Diffusion)
        eq = (TransientTerm() == DiffusionTerm(coeff=Diffusion) -
              ConvectionTerm(coeff=gradient))
        eq.solve(Phi, dt=1e-9, solver=DefaultSolver(precon=None))
        print("size of Phi = " + str(len(Phi)))
        lista.append(Phi[j])
    Phi = lista.copy()
    lista.clear()
    if __name__ == "__main__":  #Parameters to be changed are in the seciton below.
        viewer.plot(
            filename="trial.vtk"
        )  #It will only save the final vtk file. You can change the name
        if not i % 10 or i == 0:
            dest_name = '/home/zhaoshi/Zhao_test/img_' + str(
                i
            ) + '.vtk'  #Path and name of the intermediate file. The Green Part should be changed to your path & name
            copyfile('/home/zhaoshi/trial.vtk',
                     dest_name)  #Specify the path of your trial.vtk file
コード例 #7
0
# EQUATION SETUP BASIC DESCRIPTION
'''Equations to solve for each variable must be defined:
  -TransientTerm = dvar/dt
  -ConvectionTerm = dvar/dx
  -DiffusionTerm = d^2var/dx^2
  -Source terms can be described as they would appear mathematically
Notes:  coeff = terms that are multiplied by the Term.. must be rank-1 FaceVariable for ConvectionTerm
        "var" must be defined for each Term if they are not all the variable being solved for,
        otherwise will see "fipy.terms.ExplicitVariableError: Terms with explicit Variables cannot mix with Terms with implicit Variables." '''

# In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

# Pion.equation = TransientTerm(coeff=1, var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad,var=Pion) + Pion * potential.faceGrad.divergence) + DiffusionTerm(coeff=Dp,var=Pion) - k_rec*Pion*Nion
Pion.equation = TransientTerm(coeff=1, var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad, var=Pion) + Pion * potential.faceGrad.divergence)

# In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

# Nion.equation = TransientTerm(coeff=1, var=Nion) == -mu_n * (ConvectionTerm(coeff=potential.faceGrad,var=Nion) + Nion * potential.faceGrad.divergence) + DiffusionTerm(coeff=Dn,var=Nion) - k_rec*Pion*Nion


# In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density = Pion + Nion
# Poisson's Equation

# potential.equation = DiffusionTerm(coeff=1, var=potential) == (-q/epsilon)*(Pion + Nion)
potential.equation = DiffusionTerm(coeff=1, var=potential) == (-q/epsilon)*Pion