Esempio n. 1
0
 def setUp(self):
     test_shape = ((-1, -.5, 0, .5, 1), (-2, 0, 2, 4))
     self.tgrid = np.ones((5, 4))
     self.tgrid[3, 2] = 12
     self.tgrid[1, 1] = 5
     self.gspec = grid.CartesianGridSpec(test_shape)
     self.grid = grid.GridScalar(self.gspec, self.tgrid)
 def setUp(self):
     test_shape = ((-1, -.5, 0, .5, 1), (-2, 0, 2, 4))
     self.tgrid = np.ones((5, 4))
     self.gspec = grid.CartesianGridSpec(test_shape)
     self.grid = grid.GridScalar(self.gspec, self.tgrid)
     self.logg = logger.Logger()
     self.vis = vis.VisGif2d(r"tests/test_outs/")
     #instantiate many items in the log_list
     for i in range(50):
         self.logg.log(i, self.grid + i)
Esempio n. 3
0
 def setUp(self):
     test_shape = ((-1, -.5, 0, .5, 1), (-2, 0, 2, 4))
     self.tgrid = np.ones((5, 4))
     self.tgrid[3, 2] = 12
     self.tgrid[1, 1] = 5
     self.gspec = grid.CartesianGridSpec(test_shape)
     self.grid = grid.GridScalar(self.gspec, self.tgrid)
     self.logg = logger.Logger()
     #instantiate two items in the log_list
     self.logg.log(0., self.grid)
     self.logg.log(3., self.grid)
    def setUp(self):
        self.dimen1 = 0
        self.dimen2 = 1
        self.side1 = 'r'
        self.side2 = 'l'
        self.vals = np.array([1., 2., 3., 4.])
        self.bc_list = [
            sbcs.Dirichlet(self.dimen1, self.side1, self.vals),
            sbcs.Dirichlet(self.dimen2, self.side2, self.vals)
        ]
        self.bch = dh.DirichletHand(self.bc_list)

        self.coords = ((0, 1, 2, 3), (3, 4, 5, 6))
        self.initial_vals = np.zeros((4, 4))
        self.time = 0
        self.gspec = grid.CartesianGridSpec(self.coords)
        self.gscl = grid.GridScalar(self.gspec, self.initial_vals)
Esempio n. 5
0
def main():
    nx = 100
    ny = 100
    dx = 2 / (nx - 1)
    dy = 2 / (ny - 1)

    x = np.linspace(0, 2, nx)
    y = np.linspace(0, 2, ny)
    coords = (tuple(x), tuple(y))

    # Sloppily assign initial conditions
    u = np.zeros((ny, nx))
    # set hat function I.C. : u(.5<=x<=1 && .5<=y<=1 ) is 2
    u[int(.5 / dy):int(1 / dy + 1), int(.5 / dx):int(1 / dx + 1)] = 2

    # Make the interior laplacian operator
    # A first order, center difference, 2nd derivative
    d2_int = operator_1d.Operator1D([-1, 0, 1], 2)
    # The OperatorND object for a 2D laplacian
    laplac_int = operator_nd.OperatorND((d2_int, d2_int))

    # Make the exterior laplacian operators
    d2_left = operator_1d.Operator1D([0, 1, 2], 2)
    d2_right = operator_1d.Operator1D([-2, -1, 0], 2)
    x_edge_ops = fixed_edge_ops.FixedEdgeOps((d2_left, ), (d2_right, ))
    y_edge_ops = fixed_edge_ops.FixedEdgeOps((d2_left, ), (d2_right, ))

    # Full laplacian operator
    laplacian = op_nd_scheme.OperatorNDScheme(laplac_int,
                                              (y_edge_ops, x_edge_ops))

    gridspec = grid.CartesianGridSpec(coords)

    test_grid = grid.GridScalar(gridspec, u)

    lapl_op = gridoperator.GridOperator(gridspec, laplacian)

    out_grid = lapl_op(test_grid)
Esempio n. 6
0
    def setUp(self):
        self.opcd = operator_1d.Operator1D([-1, 0, 1], 2)
        self.opbd = operator_1d.Operator1D([-2, -1, 0], 2)
        self.opfd = operator_1d.Operator1D([0, 1, 2], 2)
        self.laplace_int = operator_nd.OperatorND((self.opcd, self.opcd))
        self.edge = fixed_edge_ops.FixedEdgeOps((self.opfd, ), (self.opbd, ))

        self.laplace_scheme = op_nd_scheme.OperatorNDScheme(
            self.laplace_int, (self.edge, self.edge))

        self.spec = grid.CartesianGridSpec(((0, 1, 2), (0, 1, 2)))

        self.grid_op = gridoperator.GridOperator(self.spec,
                                                 self.laplace_scheme)

        # Define correct output
        x_out_cor = operatormatrix.OperatorMatrix(9)
        int_points = [1, 4, 7]
        weights = [1, -2, 1]
        for pt in int_points:
            x_out_cor[pt, pt - 1:pt + 2] = weights

        left_points = [0, 3, 6]
        for pt in left_points:
            x_out_cor[pt, pt:pt + 3] = weights

        right_points = [2, 5, 8]
        for pt in right_points:
            x_out_cor[pt, pt - 2:pt + 1] = weights

        y_out_cor = operatormatrix.OperatorMatrix(9)
        yweights = [1, 0, 0, -2, 0, 0, 1]
        for j in range(3):
            for i in range(3):
                y_out_cor[3 * i + j, j:j + 7] = yweights

        self.laplace_cor = x_out_cor + y_out_cor
Esempio n. 7
0
    def test_applyOp(self):
        testspec = grid.CartesianGridSpec(((0, 1, 2), (0, 1, 2)))
        test_int = np.zeros((3, 3))
        test_int[1, 1] = 1
        testgrid = grid.GridScalar(testspec, test_int)

        x_out_cor = operatormatrix.OperatorMatrix(9)
        int_points = [1, 4, 7]
        weights = [1, -2, 1]
        for pt in int_points:
            x_out_cor[pt, pt - 1:pt + 2] = weights

        left_points = [0, 3, 6]
        for pt in left_points:
            x_out_cor[pt, pt:pt + 3] = weights

        right_points = [2, 5, 8]
        for pt in right_points:
            x_out_cor[pt, pt - 2:pt + 1] = weights

        y_out_cor = operatormatrix.OperatorMatrix(9)
        yweights = [1, 0, 0, -2, 0, 0, 1]
        for j in range(3):
            for i in range(3):
                y_out_cor[3 * i + j, j:j + 7] = yweights

        laplace = y_out_cor + x_out_cor

        results = testgrid.applyOp(laplace)

        result_cor = np.zeros((3, 3))
        result_cor[1, :] = [-2, -4, -2]
        result_cor[0, 1] = -2
        result_cor[2, 1] = -2

        np.testing.assert_array_equal(result_cor, results.grid)
Esempio n. 8
0
import numpy as np
from src import grid
from src import gridoperator
from src import static_bcs
from src import dirichlet_hand
from src import logger
from src import forward_euler
from src import conduct_heat_eqn
from src import spatial_driver
from src import driver
from src import vis_gif_2d
from src import plot_end
import initializer

gspec = grid.CartesianGridSpec(initializer.coords)
grid_u = grid.GridScalar(gspec,initializer.u)  # initial grid of temperature values

laplace_op = gridoperator.GridOperator(gspec, initializer.laplace_scheme)
ops_dict = {'laplacian': laplace_op}

#set each of the boundaries (using all dirichlet zero for now)
BCs = []
# BCs.append(static_bcs.Dirichlet(0,'l',np.array([1])))
# BCs.append(static_bcs.Dirichlet(0,'r',np.array([0])))
BCs.append(static_bcs.Dirichlet(0,'l',np.zeros(grid_u.shape[0])))
BCs.append(static_bcs.Dirichlet(0,'r',np.zeros(grid_u.shape[0])))
BCs.append(static_bcs.Dirichlet(1,'l',np.zeros(grid_u.shape[0])))
BCs.append(static_bcs.Dirichlet(1,'r',np.zeros(grid_u.shape[0])))

bound_handlr = dirichlet_hand.DirichletHand(BCs)