Ejemplo n.º 1
0
        DRY. so wen can create temporary array for the force vector and the repeating part
    """
    tmpRhs = ((1.0-theta) * (A*u[n-1] - F) - theta * F)
    rhs = M * u[n-1] + k * M * v[n-1] - k*k * theta * tmpRhs

    """
        Create the system matrix
    """
    S = M + A * k*k * theta*theta
    
    """
        Apply boundary conditions.
    """
    if n==1:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 1], grid),
                            rhs)
        
    else:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 0], grid),
                            rhs)
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(2), 0], grid),
                            rhs)
    
    """
        Solve for u
    """
    u[n] = solver.linsolve(S, rhs)
    
        DRY. so wen can create temporary array for the force vector and the repeating part
    """
    tmpRhs = ((1.0-theta) * (A*u[n-1] - F) - theta * F)
    rhs = M * u[n-1] + k * M * v[n-1] - k*k * theta * tmpRhs

    """
        Create the system matrix
    """
    S = M + A * k*k * theta*theta
    
    """
        Apply boundary conditions.
    """
    if n==1:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 1], grid),
                            rhs)
        
    else:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 0], grid),
                            rhs)
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(2), 0], grid),
                            rhs)
    
    """
        Solve for u
    """
    u[n] = solver.linsolve(S, rhs)
    
dt = times[1] - times[0]
A = solver.createStiffnessMatrix(grid, np.ones(grid.cellCount()))
M = solver.createMassMatrix(grid, np.ones(grid.cellCount()))

ut = pg.RVector(dof, 0.0)
rhs = pg.RVector(dof, 0.0)
b = pg.RVector(dof, 0.0)
theta = 0

boundUdir = solver.parseArgToBoundaries(dirichletBC, grid)

for n in range(1, len(times)):
    b = (M - A * dt) * u[n - 1] + rhs * dt
    S = M

    solver.assembleDirichletBC(S, boundUdir, rhs=b)

#    solver.assembleBoundaryConditions(grid, S,
#                                      rhs=b,
#                                      boundArgs=dirichletBC,
#                                      assembler=solver.assembleDirichletBC)

    solve = pg.LinSolver(S)
    solve.solve(b, ut)

    u[n, :] = ut

# u = solver.solvePoisson(grid, times=times, theta=0.0,
#                 u0=lambda r: np.sin(np.pi * r[0]),
#                 uBoundary=dirichletBC)
Ejemplo n.º 4
0
dt = times[1] - times[0]
A = solver.createStiffnessMatrix(grid, np.ones(grid.cellCount()))
M = solver.createMassMatrix(grid, np.ones(grid.cellCount()))

ut = pg.RVector(dof, 0.0)
rhs = pg.RVector(dof, 0.0)
b = pg.RVector(dof, 0.0)
theta = 0

boundUdir = solver.parseArgToBoundaries(dirichletBC, grid)

for n in range(1, len(times)):
    b = (M - A * dt) * u[n - 1] + rhs * dt
    S = M

    solver.assembleDirichletBC(S, boundUdir, rhs=b)

    solve = pg.LinSolver(S)
    solve.solve(b, ut)

    u[n, :] = ut

plt.plot(times, u[:, probeID], label='Explicit Euler')

theta = 1

for n in range(1, len(times)):
    b = (M + A * (dt*(theta - 1.0))) * u[n-1] + \
        rhs * (dt*(1.0 - theta)) + \
        rhs * dt * theta