def make_charges(trainingsSetGeometry):
    rect = Rectangle(0.0, 0.0, trainingsSetGeometry.gridWidth,
                     trainingsSetGeometry.gridHeight)
    delta = 1.0
    g = Geometry(rect, delta)
    countCharges = 11
    chargeValue = -10.0
    yCoord = 20.0
    xCoordLeft = rect.midX() - (trainingsSetGeometry.gridWidth -
                                trainingsSetGeometry.innerGridWidth) / 2.0
    xCoordRight = rect.midX() + (trainingsSetGeometry.gridWidth -
                                 trainingsSetGeometry.innerGridWidth) / 2.0
    return make_charges_in_line(g, countCharges, chargeValue, xCoordLeft,
                                yCoord, xCoordRight, yCoord)
def makeGeometry(gridWidth, gridHeight):
    delta = 1.0
    gridWidth = gridWidth
    gridHeight = gridHeight
    rect = Rectangle(0, 0, gridWidth, gridHeight)
    g = Geometry(rect, delta)
    return g
def generate_dataset(count, trainingsSetGeometry, charges, label):

    #np.set_printoptions(threshold=np.nan)

    index = 0

    # setup for finite differences
    rect = Rectangle(0.0, 0.0, trainingsSetGeometry.gridWidth,
                     trainingsSetGeometry.gridHeight)
    delta = 1.0
    g = Geometry(rect, delta)

    start = time.time()

    dataset = calculate_random_parameters(count,
                                          trainingsSetGeometry,
                                          chargesList=charges.chargesList,
                                          label=label)

    for dataElement in dataset:
        dataElement.calc_permittivity_matrix(64, 64, 32, 32)

    duration = time.time() - start
    print('Total duration for generating {0} dataset elements:{1}'.format(
        count, duration))

    return dataset
Esempio n. 4
0
 def __init__(self, gridWidth, gridHeight):
     self.gridWidth = gridWidth
     self.gridHeight = gridHeight
     self.delta = 1.0
     self.rect = Rectangle(0, 0, gridWidth, gridHeight)
     self.geometry = Geometry(self.rect, self.delta)
     self.boundaryCondition = RectangularBoundaryCondition(self.geometry)
     self.auxiliaryFunctions = {}
Esempio n. 5
0
def calcSolutions(inputDataSet):

    delta = 1.0
    rect = Rectangle(0, 0, inputDataSet.geometry.gridWidth,
                     inputDataSet.geometry.gridHeight)
    g = Geometry(rect, delta)
    boundaryCondition = RectangularBoundaryCondition(g)
    charges = load_chargedistribution(g, inputDataSet)

    index = 1

    resultsSet = ResultsSet(label=inputDataSet.label)

    start = time.time()

    for dataElement in inputDataset:
        eps = generate_permittivity_function(
            dataElement.get_permittivity_matrix())
        gridConfig = make_finite_differences_poisson_equation_in_matter(eps)

        #fdm3 = FiniteDifferencesMethod3(g, boundaryCondition, gridConfig, charges)
        #fdm3.solve()
        #fdm3.calcMetrices()

        fdm = FiniteDifferencesMethod4(g, boundaryCondition, gridConfig,
                                       charges)
        fdm.solve()
        #fdm.calcMetrices()

        #compareVectors(fdm3.bias, fdm.bias)
        #compareMatrices(fdm3.matrix, fdm.matrix.todense())

        #resultsSet.add(fdm.results)
        resultsSet.add(fdm.values)

        #s = json.dumps(fdm.results.tolist())
        #print(s)

        #s = generate_text_presentation(index, dataElement, fdm.values, fdm.error)
        index = index + 1

    duration = time.time() - start
    print('Total duration for solving {0} PDEs lasted :{1}'.format(
        inputDataset.count(), duration))

    return resultsSet
                                        norm=norm,
                                        cmap=self.cmap)
        self.error_axes.set_title('Errors', fontsize=9)
        self.colorbar = fig.colorbar(im, ax=self.error_axes)


if __name__ == '__main__':

    np.set_printoptions(threshold=np.nan)

    count = 60
    index = 0

    # setup for finite differences
    delta = 1.0
    rect = Rectangle(0, 0, 64.0, 64.0)
    g = Geometry(rect, delta)
    boundaryCondition = RectangularBoundaryCondition(g)
    charges = make_charges_in_line(g, 11, -10.0, 16.0, 20.0, 48.0, 20.0)
    #charges = make_charges_in_line(g, 32, -10.0, 16.0, 20.0, 48.0, 20.0)

    # setup for plot
    fig = plt.figure()

    permittivity_data = load_test_set(count)
    permittivity_title = 'eps = {0}'.format(
        permittivity_data[0]['permittivities'][index])
    permittivity_axes = fig.add_subplot(1, 3, 1)
    surface_axes = fig.add_subplot(1, 3, 2, projection='3d')
    error_axes = fig.add_subplot(1, 3, 3)
    if i==0 and j==0:
        return -200.0
    if i == 2 and j==2:
        return 10.0
    if i==1 and j==2:
        return -20.0
    else:
        return 1.0


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)
Esempio n. 8
0
    for m in d:
        if len(m) <= maxdepth:
            all_models.append((m, make_model(m, length * 2, length * 2, 2)))
            i += 1
            #print('count:', len(all_models))

    print('count:', i, len(all_models))
    return all_models


if __name__ == '__main__':

    delta = 1.0
    gridWidth = 32.0
    gridHeight = 32.0
    rect = Rectangle(0, 0, gridWidth, gridHeight)
    g = Geometry(rect, delta)

    chargeCount = 2
    count = 600

    x_areaWithoutCharge = 4.0
    y_areaWithoutCharge = 4.0
    x_positions = np.linspace(x_areaWithoutCharge,
                              gridWidth - x_areaWithoutCharge,
                              gridWidth - 2 * x_areaWithoutCharge)
    y_positions = np.linspace(y_areaWithoutCharge,
                              gridHeight - y_areaWithoutCharge,
                              gridHeight - 2 * y_areaWithoutCharge)
    x = np.random.choice(x_positions, size=count * chargeCount) / gridWidth
    y = np.random.choice(y_positions, size=count * chargeCount) / gridHeight
Esempio n. 9
0
import time
import matplotlib.pyplot as plt

from sources.experiments.charges_generators import make_comb
from sources.experiments.fdm_helper import plotSurface, solve_finite_differences
from sources.pdesolver.finite_differences_method.boundaryconditions import RectangularBoundaryCondition
from sources.pdesolver.finite_differences_method.geometry import Geometry
from sources.pdesolver.finite_differences_method.rectangle import Rectangle

if __name__ == '__main__':

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

    g = Geometry(rect, delta)
    print(g.numX, g.numY)

    boundaryCondition = RectangularBoundaryCondition(g)

    charges = make_comb(g, delta)

    start = time.clock()
    duration = time.clock() - start

    fdm = solve_finite_differences(g, boundaryCondition, charges)

    print(duration)

    showGraph = 1

    if showGraph: