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)
    
    """
        Solve the second equation for v 
    """
    
    rhs = M * v[n-1] - A * u[n] * k * theta - k * tmpRhs

    """
        Be aware of python's #No copy at all!#. 
        So we need to take a copy of the mass element matrix ourself to keep in
        safe environment.
    """
    S = pg.RSparseMatrix(M)
    #S = M
Пример #2
0
        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)
    
    """
        Solve the second equation for v 
    """
    
    rhs = M * v[n-1] - A * u[n] * k * theta - k * tmpRhs

    """
        Be aware of python's #No copy at all!#. 
        So we need to take a copy of the mass element matrix ourself to keep in
        safe environment.
    """
    S = pg.matrix.SparseMatrix(M)
    #S = M
dirichletBC = [[1, 0.0],  # top
               [2, 0.0]]  # bottom

A = solver.createStiffnessMatrix(grid, np.ones(grid.cellCount()))
M = solver.createMassMatrix(grid, np.ones(grid.cellCount()))

for n in range(1, len(t)):
    """
        Direct time and space discretization of the second derivatives
        # diff in space is 2nd order central
    """
    # FD explicit
#    uE[n] = uE[n-1] + c * (Lg * -uE[n-1])

    # FD implicit
    uI[n] = solver.linsolve(I + Lg * c, uI[n-1])

    # FE implicit
    S = M + A * tempLF * dt
    rhs = M * uFEM[n-1]
    solver.assembleBoundaryConditions(grid, S,
                                      rhs=rhs,
                                      boundArgs=dirichletBC,
                                      assembler=solver.assembleDirichletBC)
    uFEM[n] = solver.linsolve(S, rhs)

#ax1.plot(x, uE[timeProbeID], label='FD explicit')
#ax2.plot(t, uE[:,spaceProbeID], label='FD explicit')

ax1.plot(x, uI[timeProbeID], '.-', label='FD implicit')
ax2.plot(t, uI[:, spaceProbeID], '.-', label='FD implicit')