def generate_local_block_operator(context, my_proc, graph, layers, alpha):
    """Generate the local system matrix.
    """
    def copy_to_structure(brow, bcol, block, structure):
        """Small helper routine to copy a 2x2 block at the right position into a structure
        """
        structure.setBlock(2 * brow, 2 * bcol, block.block(0, 0))
        structure.setBlock(2 * brow, 2 * bcol + 1, block.block(0, 1))
        structure.setBlock(2 * brow + 1, 2 * bcol, block.block(1, 0))
        structure.setBlock(2 * brow + 1, 2 * bcol + 1, block.block(1, 1))

    nproc = Epetra.PyComm().NumProc()

    process_map = procmap(blockmap(graph), nproc)
    scheduler = partition(process_map)

    # Initialize structure of local system matrix

    nb = process_map.shape[0]  # Block-dimension of global matrix
    structure = lib.createBlockedOperatorStructure(context)
    for i in range(nb):
        plc = layers[i]['spaces']['l']
        pwc = layers[i]['spaces']['c']
        null_op_00 = lib.createNullOperator(context, plc, pwc, plc)
        null_op_11 = lib.createNullOperator(context, pwc, plc, pwc)
        structure.setBlock(2 * i, 2 * i, null_op_00)
        structure.setBlock(2 * i + 1, 2 * i + 1, null_op_11)

    # Iterate through elements from scheduler and fill up local system matrix

    if not scheduler.has_key(my_proc + 1):
        A = lib.createBlockedBoundaryOperator(context, structure)
        return A

    for elem in scheduler[my_proc + 1]:
        if elem[0] == elem[1]:
            # Diagonal Block
            block = diagonal_block(context, layers, elem[0], alpha)
            copy_to_structure(elem[0], elem[1], block, structure)
        else:
            if layers[elem[0]]['sons'].count(elem[1]):
                # elem[1] is a son of elem[0]
                block1, block2 = off_diagonal_block_father_son(
                    context, layers, elem[0], elem[1])
            else:
                # elements must be on the same level
                block1, block2 = off_diagonal_block_same_layer(
                    context, layers, elem[0], elem[1])
            copy_to_structure(elem[0], elem[1], block1, structure)
            copy_to_structure(elem[1], elem[0], block2, structure)
    A = lib.createBlockedBoundaryOperator(context, structure)
    return A
def generate_local_block_operator(context,my_proc,graph,layers,alpha):
    """Generate the local system matrix.
    """

    def copy_to_structure(brow,bcol,block,structure):
        """Small helper routine to copy a 2x2 block at the right position into a structure
        """
        structure.setBlock(2*brow,2*bcol,block.block(0,0))
        structure.setBlock(2*brow,2*bcol+1,block.block(0,1))
        structure.setBlock(2*brow+1,2*bcol,block.block(1,0))
        structure.setBlock(2*brow+1,2*bcol+1,block.block(1,1))

    nproc = Epetra.PyComm().NumProc()

    process_map = procmap(blockmap(graph),nproc)
    scheduler = partition(process_map)

    # Initialize structure of local system matrix

    nb = process_map.shape[0] # Block-dimension of global matrix
    structure = lib.createBlockedOperatorStructure(context)
    for i in range(nb):
        plc = layers[i]['spaces']['l']
        pwc = layers[i]['spaces']['c']
        null_op_00 = lib.createNullOperator(context,plc,pwc,plc)
        null_op_11 = lib.createNullOperator(context,pwc,plc,pwc)
        structure.setBlock(2*i,2*i,null_op_00)
        structure.setBlock(2*i+1,2*i+1,null_op_11)

    # Iterate through elements from scheduler and fill up local system matrix

    if not scheduler.has_key(my_proc+1):
        A = lib.createBlockedBoundaryOperator(context,structure)
        return A
        
    for elem in scheduler[my_proc+1]:
        if elem[0]==elem[1]:
            # Diagonal Block
            block = diagonal_block(context,layers,elem[0],alpha)
            copy_to_structure(elem[0],elem[1],block,structure)
        else:
            if layers[elem[0]]['sons'].count(elem[1]):
                # elem[1] is a son of elem[0]
                block1,block2 = off_diagonal_block_father_son(context,layers,elem[0],elem[1])
            else:
                # elements must be on the same level
                block1,block2 = off_diagonal_block_same_layer(context,layers,elem[0],elem[1])
            copy_to_structure(elem[0],elem[1],block1,structure)
            copy_to_structure(elem[1],elem[0],block2,structure)
    A = lib.createBlockedBoundaryOperator(context,structure)
    return A
def generate_local_block_operator(context,my_proc,process_map,layers,impedance):
    """Generate the local system matrix.
    """

    nproc = Epetra.PyComm().NumProc()
    total_time = 0

    scheduler = process_map.scheduler

    # Initialize structure of local system matrix

    nb = process_map.block_matrix_layout.shape[0] # Block-dimension of global matrix
    structure = lib.createBlockedOperatorStructure(context)
    for i in range(nb):
        plc = layers[i]['spaces']['l']
        pwc = layers[i]['spaces']['c']
        null_op_00 = lib.createNullOperator(context,plc,pwc,plc)
        null_op_11 = lib.createNullOperator(context,pwc,plc,pwc)
        structure.setBlock(2*i,2*i,null_op_00)
        structure.setBlock(2*i+1,2*i+1,null_op_11)

    # Iterate through elements from scheduler and fill up local system matrix

    if not scheduler.has_key(my_proc+1):
        A = lib.createBlockedBoundaryOperator(context,structure)
        return (A,total_time)
        
    for elem in scheduler[my_proc+1]:
        if elem[0]==elem[1]:
            # Diagonal Block
            print "Generating block element [%(e0)i,%(e1)i] on process %(my_proc)i... " % {'e0':elem[0],
                                                                                        'e1':elem[1],
                                                                                        'my_proc':my_proc}

            tstart=time()
            block = diagonal_block(context,layers,elem[0],impedance)
            block.weakForm()
            copy_to_structure(elem[0],elem[1],block,structure)
            tend=time()
            print "Block element [%(e0)i,%(e1)i] on process %(my_proc)i generated in %(tval)f seconds" % {'e0':elem[0],
                                                                                                          'e1':elem[1],
                                                                                                          'my_proc':my_proc,
                                                                                                          'tval':tend-tstart}
            total_time +=tend-tstart
        else:
            print "Generating block elements [%(e0)i,%(e1)i] and [%(e1)i,%(e0)i] on process %(my_proc)i... " % {'e0':elem[0],
                                                                                                           'e1':elem[1],
                                                                                                           'my_proc':my_proc}
            tstart=time()
            if layers[elem[0]]['sons'].count(elem[1]):
                # elem[1] is a son of elem[0]
                block1,block2 = off_diagonal_block_father_son(context,layers,elem[0],elem[1])
            else:
                # elements must be on the same level
                block1,block2 = off_diagonal_block_same_layer(context,layers,elem[0],elem[1])
            block1.weakForm()
            block2.weakForm()
            copy_to_structure(elem[0],elem[1],block1,structure)
            copy_to_structure(elem[1],elem[0],block2,structure)
            tend = time()
            print "Block elements [%(e0)i,%(e1)i] and [%(e1)i,%(e0)i] on process %(my_proc)i generated in %(tval)f seconds " % {'e0':elem[0],
                                                                                                                                'e1':elem[1],
                                                                                                                                'my_proc':my_proc,
                                                                                                                                'tval':tend-tstart
                                                                                                                                }
            total_time +=tend-tstart

    A = lib.createBlockedBoundaryOperator(context,structure)
    return (A,total_time)
def generate_local_block_operator(context, my_proc, process_map, layers,
                                  impedance):
    """Generate the local system matrix.
    """

    nproc = Epetra.PyComm().NumProc()
    total_time = 0

    scheduler = process_map.scheduler

    # Initialize structure of local system matrix

    nb = process_map.block_matrix_layout.shape[
        0]  # Block-dimension of global matrix
    structure = lib.createBlockedOperatorStructure(context)
    for i in range(nb):
        plc = layers[i]['spaces']['l']
        pwc = layers[i]['spaces']['c']
        null_op_00 = lib.createNullOperator(context, plc, pwc, plc)
        null_op_11 = lib.createNullOperator(context, pwc, plc, pwc)
        structure.setBlock(2 * i, 2 * i, null_op_00)
        structure.setBlock(2 * i + 1, 2 * i + 1, null_op_11)

    # Iterate through elements from scheduler and fill up local system matrix

    if not scheduler.has_key(my_proc + 1):
        A = lib.createBlockedBoundaryOperator(context, structure)
        return (A, total_time)

    for elem in scheduler[my_proc + 1]:
        if elem[0] == elem[1]:
            # Diagonal Block
            print "Generating block element [%(e0)i,%(e1)i] on process %(my_proc)i... " % {
                'e0': elem[0],
                'e1': elem[1],
                'my_proc': my_proc
            }

            tstart = time()
            block = diagonal_block(context, layers, elem[0], impedance)
            block.weakForm()
            copy_to_structure(elem[0], elem[1], block, structure)
            tend = time()
            print "Block element [%(e0)i,%(e1)i] on process %(my_proc)i generated in %(tval)f seconds" % {
                'e0': elem[0],
                'e1': elem[1],
                'my_proc': my_proc,
                'tval': tend - tstart
            }
            total_time += tend - tstart
        else:
            print "Generating block elements [%(e0)i,%(e1)i] and [%(e1)i,%(e0)i] on process %(my_proc)i... " % {
                'e0': elem[0],
                'e1': elem[1],
                'my_proc': my_proc
            }
            tstart = time()
            if layers[elem[0]]['sons'].count(elem[1]):
                # elem[1] is a son of elem[0]
                block1, block2 = off_diagonal_block_father_son(
                    context, layers, elem[0], elem[1])
            else:
                # elements must be on the same level
                block1, block2 = off_diagonal_block_same_layer(
                    context, layers, elem[0], elem[1])
            block1.weakForm()
            block2.weakForm()
            copy_to_structure(elem[0], elem[1], block1, structure)
            copy_to_structure(elem[1], elem[0], block2, structure)
            tend = time()
            print "Block elements [%(e0)i,%(e1)i] and [%(e1)i,%(e0)i] on process %(my_proc)i generated in %(tval)f seconds " % {
                'e0': elem[0],
                'e1': elem[1],
                'my_proc': my_proc,
                'tval': tend - tstart
            }
            total_time += tend - tstart

    A = lib.createBlockedBoundaryOperator(context, structure)
    return (A, total_time)
Ejemplo n.º 5
0
lhs_k13 = -(1.0 / kappa1) * slp12
lhs_k21 = dlp21 + scale * slp21
lhs_k22 = 0.5 * id22 - dlp22_w1
lhs_k23 = -(1.0 / kappa1) * slp22_w1
lhs_k32 = 0.5 * id22 + dlp22_w2
lhs_k33 = (1.0 / kappa2) * slp22_w2
lhs_k34 = -1.0 * dlp23
lhs_k35 = -(1.0 / kappa2) * slp23
lhs_k42 = dlp32
lhs_k43 = (1.0 / kappa2) * slp32
lhs_k44 = 0.5 * id33 - dlp33_w2
lhs_k45 = -(1.0 / kappa2) * slp33_w2
lhs_k54 = 0.5 * id33 + dlp33_w3
lhs_k55 = (1.0 / kappa3) * slp33_w3

structure = blib.createBlockedOperatorStructure(context)
structure.setBlock(0, 0, lhs_k11)
structure.setBlock(0, 1, lhs_k12)
structure.setBlock(0, 2, lhs_k13)
structure.setBlock(1, 0, lhs_k21)
structure.setBlock(1, 1, lhs_k22)
structure.setBlock(1, 2, lhs_k23)
structure.setBlock(2, 1, lhs_k32)
structure.setBlock(2, 2, lhs_k33)
structure.setBlock(2, 3, lhs_k34)
structure.setBlock(2, 4, lhs_k35)
structure.setBlock(3, 1, lhs_k42)
structure.setBlock(3, 2, lhs_k43)
structure.setBlock(3, 3, lhs_k44)
structure.setBlock(3, 4, lhs_k45)
structure.setBlock(4, 3, lhs_k54)
Ejemplo n.º 6
0
lhs_k13 = -(1.0/kappa1)*slp12
lhs_k21 = dlp21 + scale*slp21
lhs_k22 = 0.5*id22 - dlp22_w1
lhs_k23 = -(1.0/kappa1)*slp22_w1
lhs_k32 = 0.5*id22 + dlp22_w2
lhs_k33 = (1.0/kappa2) * slp22_w2
lhs_k34 = -1.0*dlp23
lhs_k35 = -(1.0/kappa2)*slp23
lhs_k42 = dlp32
lhs_k43 = (1.0/kappa2)*slp32
lhs_k44 = 0.5*id33 - dlp33_w2
lhs_k45 = -(1.0/kappa2)*slp33_w2
lhs_k54 = 0.5*id33 + dlp33_w3
lhs_k55 = (1.0/kappa3)*slp33_w3

structure = blib.createBlockedOperatorStructure(context)
structure.setBlock(0, 0, lhs_k11);
structure.setBlock(0, 1, lhs_k12);
structure.setBlock(0, 2, lhs_k13);
structure.setBlock(1, 0, lhs_k21);
structure.setBlock(1, 1, lhs_k22);
structure.setBlock(1, 2, lhs_k23);
structure.setBlock(2, 1, lhs_k32);
structure.setBlock(2, 2, lhs_k33);
structure.setBlock(2, 3, lhs_k34);
structure.setBlock(2, 4, lhs_k35);
structure.setBlock(3, 1, lhs_k42);
structure.setBlock(3, 2, lhs_k43);
structure.setBlock(3, 3, lhs_k44);
structure.setBlock(3, 4, lhs_k45);
structure.setBlock(4, 3, lhs_k54);