Beispiel #1
0
def create_finite_differences_configuration():
    gridConfig = GridConfiguration()
    gridConfig.add(ConstantGridValueProvider(1.0), 1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), -1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, 1)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, -1)
    gridConfig.add(ConstantGridValueProvider(-4.0), 0, 0)

    return gridConfig
def makeStandardPDEConfig():
    # this encodes the linearized PDE: -4u(i,j)+u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1) = -rho(i,j)
    # (u(i+1,j)-u(i,j))/deltaX - (u(i,j)-u(i-1,j))/deltaX +
    # (u(i,j+1)-u(i,j))/deltaY - (u(i,j)-u(i,j-1))/deltaX =
    # -rho(i,j)
    #
    # u(i+1,j)-u(i,j) - (u(i,j)-u(i-1,j)) + ... (i<->j) = -rho(i,j)
    gridConfig = GridConfiguration()
    gridConfig.add(ConstantGridValueProvider(1.0), 1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), -1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, 1)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, -1)
    gridConfig.add(ConstantGridValueProvider(-4.0), 0, 0)
    return gridConfig
Beispiel #3
0
 def make_grid_config(self, eps):
     gridConfig = GridConfiguration()
     for functionCall in self.values:
         if type(functionCall.prefactorExpr) is NumberExpression:
             gridConfig.add(
                 ConstantGridValueProvider(
                     functionCall.prefactorExpr.value),
                 int(functionCall.offset.x), int(functionCall.offset.y))
         else:
             gridConfig.add(
                 FunctionGridValueProvider(functionCall.makeFunction(eps)),
                 int(functionCall.offset.x), int(functionCall.offset.y))
     return gridConfig
def make_finite_differences_poisson_equation_in_matter(eps):
    gridConfig = GridConfiguration()
    gridConfig.add(
        FunctionGridValueProvider((lambda i, j: 0.5 *
                                   (eps(i, j) + eps(i + 1, j)))), 1, 0)
    gridConfig.add(
        FunctionGridValueProvider((lambda i, j: 0.5 *
                                   (eps(i, j) + eps(i - 1, j)))), -1, 0)
    gridConfig.add(
        FunctionGridValueProvider((lambda i, j: 0.5 *
                                   (eps(i, j) + eps(i, j + 1)))), 0, 1)
    gridConfig.add(
        FunctionGridValueProvider((lambda i, j: 0.5 *
                                   (eps(i, j) + eps(i, j - 1)))), 0, -1)
    gridConfig.add(
        FunctionGridValueProvider((lambda i, j: -0.5 * (4 * eps(i, j) + eps(
            i + 1, j) + eps(i - 1, j) + eps(i, j + 1) + eps(i, j - 1)))), 0, 0)
    return gridConfig

if __name__ == '__main__':

    np.set_printoptions(threshold=np.nan)

    delta = 1.0
    rect = Rectangle(0, 0, 3.0, 3.0)

    g = Geometry(rect, delta)

    boundaryCondition = RectangularBoundaryCondition(g)

    charges = make_central_charge(g)

    gridConfig = GridConfiguration()

    gridConfig.add(ConstantGridValueProvider(-4.0), 0,0)
    gridConfig.add(ConstantGridValueProvider(1.0), 1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), -1, 0)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, 1)
    gridConfig.add(ConstantGridValueProvider(1.0), 0, -1)

    fdm = FiniteDifferencesMethod3(g, boundaryCondition, gridConfig, charges)

    fdm.solve()
    fdm.printMatrix()

    #f = (lambda i, j:
    #     -0.5 * 2 * eps(i,j))