Exemplo n.º 1
0
def assign_node_constraints(snic, axes, face_constraints):
    """assign node constraints to prescribed node planes

    Nodes shared on multiple faces have are assigned with the following order
    of precedence: z, y, x

    Args:
      snic: sorted node IDs and coordinates from nodes.dyn
      axes: mesh axes [x, y, z]
      face_constraints: list of DOF strings ordered by
    ((xmin, max), (ymin, ...)
    (e.g., (('1,1,1,1,1,1' , '0,1,0,0,1,0'),...)

    Returns:
      bcdict - dictionary of node BC to be written to bc.dyn

    """
    from fem_mesh import extractPlane
    from numpy import ndenumerate

    bcdict = {}
    for axis in range(0, 3):
        for axlim in range(0, 2):
            if axlim == 0:
                axis_limit = axes[axis].min()
            else:
                axis_limit = axes[axis].max()
            planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit))
            for i, id in ndenumerate(planeNodeIDs):
                bcdict[id] = face_constraints[axis][axlim]

    return bcdict
Exemplo n.º 2
0
def extract_top_plane_nodes(nodefile, top_face):
    """

    Args:
        nodefile: param top_face:
        top_face:

    Returns:
        planeNodeIDs

    """
    import numpy as np
    import fem_mesh

    top_face = np.array(top_face)

    nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile)
    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)

    # extract spatially-sorted node IDs on a the top z plane
    axis = int(np.floor(np.divide(top_face.nonzero(), 2)))
    if np.mod(top_face.nonzero(), 2) == 1:
        plane = (axis, axes[axis].max())
    else:
        plane = (axis, axes[axis].min())

    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)

    return planeNodeIDs
Exemplo n.º 3
0
def assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints):
    """modify/create node BCs for quarter-symmetry edge

    Args:
      bcdict: dict of nodal BCs
      snic: sorted node IDs and coordinates
      axes: spatial axis vectors
      edge_constraints: list with vector indicating edge & constraint
    (e.g., to specify the edge shared by the xmax
    and ymin faces to allow just z translation:
    (((0,1),(1,0),(0,0)),'1,1,0,1,1,1')

    Returns:
      bcdict (updated from face assignment)

    """
    from warnings import warn
    from fem_mesh import extractPlane

    # look for edge shared with an x face
    axis = 0
    if edge_constraints[0][axis][0]:
        axis_limit = axes[axis].min()
    elif edge_constraints[0][axis][1]:
        axis_limit = axes[axis].max()
    else:
        warn('Symmetry edge not shared by an x-face specified;'
             'no edge BCs defined')
        return 1
    planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit))

    # restrict nodes to those on specified edge
    ortho_axis = 1
    if edge_constraints[0][ortho_axis][0]:
        edge_nodes = planeNodeIDs[0, :]
    elif edge_constraints[0][ortho_axis][1]:
        edge_nodes = planeNodeIDs[-1, :]
    else:
        warn('Orthogonal plane to x-face is not a y-face; no edge BCs defined')
        return 1

    # do not assign BCs to nodes associated with zmin/zmax faces
    edge_nodes = edge_nodes[1:-1]
    for i in edge_nodes:
        bcdict[i] = "%s" % edge_constraints[1]

    return bcdict
Exemplo n.º 4
0
def apply_nonreflect(face_constraints, edge_constraints,
                     nodefile="nodes.dyn", elefile="elems.dyn",
                     bcfile="bc.dyn", segfile="nonreflect_segs.dyn"):
    """driver function to generate non-reflecting boundaries

    Args:
      face_constraints (str): vector of face constraints, ordered xmin to zmax
      edge_constraints (str): vector of edge constraints, ordered xmin to zmax
      nodefile (str): default - 'nodes.dyn'
      elefile (str): default - 'elems.dyn'
      bcfile (str): default - 'bc.dyn'
      segfile (str): default - 'nonreflect_segs.dyn'

    Returns:
      0 on success

    """
    import fem_mesh

    nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile)
    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)

    segID = 1
    seg_names = [['XMIN', 'XMAX'], ['YMIN', 'YMAX'], ['ZMIN', 'ZMAX']]
    SEGBCFILE = open(segfile, 'w')
    for a in range(0, 3):
        for m in range(0, 2):
            if face_constraints[a][m] == '1,1,1,1,1,1':
                if m == 0:
                    axis_limit = axes[a][0]
                else:
                    axis_limit = axes[a][-1]
                planeNodeIDs = fem_mesh.extractPlane(snic, axes,
                                                     (a, axis_limit))
                segID = writeSeg(SEGBCFILE, seg_names[a][m], segID,
                                 planeNodeIDs)
    write_nonreflecting(SEGBCFILE, segID)
    SEGBCFILE.close()

    bcdict = assign_node_constraints(snic, axes, face_constraints)
    bcdict = assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints)
    write_bc(bcdict, bcfile)

    return 0
Exemplo n.º 5
0
def test_extractPlane(nodeIDcoords):
    """test all that all 6 planes are extracted as expected
    """
    from fem_mesh import SortNodeIDs
    from fem_mesh import extractPlane

    [snic, axes] = SortNodeIDs(nodeIDcoords)

    planeNodeIDs = extractPlane(snic, axes, [0, -1.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 1
    assert planeNodeIDs[0, 10] == 1211
    assert planeNodeIDs[10, 0] == 111
    assert planeNodeIDs[10, 10] == 1321

    planeNodeIDs = extractPlane(snic, axes, [0, 0.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 11
    assert planeNodeIDs[0, 10] == 1221
    assert planeNodeIDs[10, 0] == 121
    assert planeNodeIDs[10, 10] == 1331

    planeNodeIDs = extractPlane(snic, axes, [1, 0.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 1
    assert planeNodeIDs[0, 10] == 1211
    assert planeNodeIDs[10, 0] == 11
    assert planeNodeIDs[10, 10] == 1221

    planeNodeIDs = extractPlane(snic, axes, [1, 1.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 111
    assert planeNodeIDs[0, 10] == 1321
    assert planeNodeIDs[10, 0] == 121
    assert planeNodeIDs[10, 10] == 1331

    planeNodeIDs = extractPlane(snic, axes, [2, -1.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 1
    assert planeNodeIDs[0, 10] == 111
    assert planeNodeIDs[10, 0] == 11
    assert planeNodeIDs[10, 10] == 121

    planeNodeIDs = extractPlane(snic, axes, [2, 0.0])
    assert planeNodeIDs.shape == (11, 11)
    assert planeNodeIDs[0, 0] == 1211
    assert planeNodeIDs[0, 10] == 1321
    assert planeNodeIDs[10, 0] == 1221
    assert planeNodeIDs[10, 10] == 1331
Exemplo n.º 6
0
def constrain_sym_pml_nodes(bcdict, snic, axes, pml_elems, edge_constraints):
    """make sure that all "side" nodes for the PML elements are fully
    constrained, instead of being assigned the symmetry constraints

    THIS FUNCTION IS NOT NEEDED!!

    Args:
      bcdict: param snic:
      axes: param pml_elems:
      edge_constraints: return: bcdict
      snic:
      pml_elems:

    Returns:
      bcdict

    """
    from fem_mesh import extractPlane
    from numpy import ndenumerate

    # look for x symmetry face
    for axis in range(0, 2):
        if edge_constraints[0][axis][0]:
            axis_limit = axes[axis].min()
        elif edge_constraints[0][axis][1]:
            axis_limit = axes[axis].max()
        if axis_limit is not None:
            planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit))
            pml_node_ids_zmin = planeNodeIDs[:, 0:(pml_elems[2][0] + 1)]
            pml_node_ids_zmax = planeNodeIDs[:, -(pml_elems[2][1] + 1):]
            for i, id in ndenumerate(pml_node_ids_zmin):
                bcdict[id] = "%s" % '1,1,1,1,1,1'
            for i, id in ndenumerate(pml_node_ids_zmax):
                bcdict[id] = "%s" % '1,1,1,1,1,1'
        axis_limit = None

    return bcdict
Exemplo n.º 7
0
def main():
    import fem_mesh
    import sys

    fem_mesh.check_version()

    opts = read_cli()

    if opts.pml:
        pmlfile = create_pml_elems_file(opts.elefile)

    BCFILE = open_bcfile(opts, sys.argv[0])

    nodeIDcoords = load_nodeIDs_coords(opts.nodefile)

    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)
    axdiff = [axes[0][1]-axes[0][0],
              axes[1][1]-axes[1][0],
              axes[2][1]-axes[2][0]]

    segID = 1

    # BACK
    axis = 0
    axis_limit = axes[0].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'BACK', segID, planeNodeIDs)
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit, axis_limit+opts.num_pml_elems*axdiff[axis],
                  opts.pml_partID)

    # FRONT
    axis = 0
    axis_limit = axes[0].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if (opts.sym == 'q') or (opts.sym == 'h'):
        # no top / bottom rows (those will be defined in the
        # top/bottom defs)
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '1,0,0,0,1,1')
    else:
        if opts.nonreflect:
            segID = writeSeg(BCFILE, 'FRONT', segID, planeNodeIDs)
        elif opts.pml:
            apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                      axis_limit-opts.num_pml_elems*axdiff[axis],
                      axis_limit, opts.pml_partID)

    # LEFT (push side; non-reflecting or symmetry)
    axis = 1
    axis_limit = axes[1].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    # if quarter-symmetry, then apply BCs, in addition to a
    # modified edge; and don't deal w/ top/bottom
    if opts.sym == 'q':
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '0,1,0,1,0,1')
    # else make it a non-reflecting boundary
    else:
        if opts.nonreflect:
            segID = writeSeg(BCFILE, 'LEFT', segID, planeNodeIDs)
        elif opts.pml:
            apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                      axis_limit, axis_limit+opts.num_pml_elems*axdiff[axis],
                      opts.pml_partID)

    # RIGHT (non-reflecting)
    axis = 1
    axis_limit = axes[1].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'RIGHT', segID, planeNodeIDs)
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit-opts.num_pml_elems*axdiff[axis],
                  axis_limit, opts.pml_partID)

    # BOTTOM
    axis = 2
    axis_limit = axes[2].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'BOTTOM', segID, planeNodeIDs)
        if opts.bottom == 'full':
            writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
        elif opts.bottom == 'inplane':
            writeNodeBC(BCFILE, planeNodeIDs, '0,0,1,1,1,0')
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit, axis_limit+opts.num_pml_elems*axdiff[axis],
                  opts.pml_partID)

    # TOP (transducer face)
    axis = 2
    axis_limit = axes[2].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'TOP', segID, planeNodeIDs)
        if opts.top:
            writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit-opts.num_pml_elems*axdiff[axis],
                  axis_limit, opts.pml_partID)

    if opts.nonreflect:
        write_nonreflecting(BCFILE, segID)

    BCFILE.close()
Exemplo n.º 8
0
Arquivo: bc.py Projeto: palfonso01/fem
def main():
    import fem_mesh
    import sys

    fem_mesh.check_version()

    opts = read_cli()

    BCFILE = open_bcfile(opts, sys.argv[0])

    nodeIDcoords = load_nodeIDs_coords(opts.nodefile)

    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)

    segID = 1

    # BACK
    plane = (0, axes[0].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'BACK', segID, planeNodeIDs)

    # FRONT
    plane = (0, axes[0].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    if (opts.sym == 'q') or (opts.sym == 'h'):
        # no top / bottom rows (those will be defined in the
        # top/bottom defs)
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '1,0,0,0,1,1')
    else:
        segID = writeSeg(BCFILE, 'FRONT', segID, planeNodeIDs)

    # LEFT (push side; non-reflecting or symmetry)
    plane = (1, axes[1].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    # if quarter-symmetry, then apply BCs, in addition to a
    # modified edge; and don't deal w/ top/bottom
    if opts.sym == 'q':
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '0,1,0,1,0,1')
    # else make it a non-reflecting boundary
    else:
        segID = writeSeg(BCFILE, 'LEFT', segID, planeNodeIDs)

    # RIGHT (non-reflecting)
    plane = (1, axes[1].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'RIGHT', segID, planeNodeIDs)

    # BOTTOM
    plane = (2, axes[2].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'BOTTOM', segID, planeNodeIDs)
    if opts.bottom == 'full':
        writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
    elif opts.bottom == 'inplane':
        writeNodeBC(BCFILE, planeNodeIDs, '0,0,1,1,1,0')

    # TOP (transducer face)
    plane = (2, axes[2].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'TOP', segID, planeNodeIDs)
    if opts.top:
        writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')

    write_nonreflecting(BCFILE, segID)

    BCFILE.close()
Exemplo n.º 9
0
def main():
    import fem_mesh
    import sys

    fem_mesh.check_version()

    opts = read_cli()

    if opts.pml:
        pmlfile = create_pml_elems_file(opts.elefile)

    BCFILE = open_bcfile(opts, sys.argv[0])

    nodeIDcoords = load_nodeIDs_coords(opts.nodefile)

    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)
    axdiff = [
        axes[0][1] - axes[0][0], axes[1][1] - axes[1][0],
        axes[2][1] - axes[2][0]
    ]

    segID = 1

    # BACK
    axis = 0
    axis_limit = axes[0].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'BACK', segID, planeNodeIDs)
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit, axis_limit + opts.num_pml_elems * axdiff[axis],
                  opts.pml_partID)

    # FRONT
    axis = 0
    axis_limit = axes[0].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if (opts.sym == 'q') or (opts.sym == 'h'):
        # no top / bottom rows (those will be defined in the
        # top/bottom defs)
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '1,0,0,0,1,1')
    else:
        if opts.nonreflect:
            segID = writeSeg(BCFILE, 'FRONT', segID, planeNodeIDs)
        elif opts.pml:
            apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                      axis_limit - opts.num_pml_elems * axdiff[axis],
                      axis_limit, opts.pml_partID)

    # LEFT (push side; non-reflecting or symmetry)
    axis = 1
    axis_limit = axes[1].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    # if quarter-symmetry, then apply BCs, in addition to a
    # modified edge; and don't deal w/ top/bottom
    if opts.sym == 'q':
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '0,1,0,1,0,1')
    # else make it a non-reflecting boundary
    else:
        if opts.nonreflect:
            segID = writeSeg(BCFILE, 'LEFT', segID, planeNodeIDs)
        elif opts.pml:
            apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                      axis_limit,
                      axis_limit + opts.num_pml_elems * axdiff[axis],
                      opts.pml_partID)

    # RIGHT (non-reflecting)
    axis = 1
    axis_limit = axes[1].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'RIGHT', segID, planeNodeIDs)
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit - opts.num_pml_elems * axdiff[axis], axis_limit,
                  opts.pml_partID)

    # BOTTOM
    axis = 2
    axis_limit = axes[2].min()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'BOTTOM', segID, planeNodeIDs)
        if opts.bottom == 'full':
            writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
        elif opts.bottom == 'inplane':
            writeNodeBC(BCFILE, planeNodeIDs, '0,0,1,1,1,0')
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit, axis_limit + opts.num_pml_elems * axdiff[axis],
                  opts.pml_partID)

    # TOP (transducer face)
    axis = 2
    axis_limit = axes[2].max()
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, (axis, axis_limit))
    if opts.nonreflect:
        segID = writeSeg(BCFILE, 'TOP', segID, planeNodeIDs)
        if opts.top:
            writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
    elif opts.pml:
        apply_pml(opts.nodefile, pmlfile, BCFILE, planeNodeIDs, axis,
                  axis_limit - opts.num_pml_elems * axdiff[axis], axis_limit,
                  opts.pml_partID)

    if opts.nonreflect:
        write_nonreflecting(BCFILE, segID)

    BCFILE.close()
Exemplo n.º 10
0
Arquivo: bc.py Projeto: kmwalsh1/fem
def main():
    import fem_mesh
    import sys

    fem_mesh.check_version()

    opts = read_cli()

    BCFILE = open_bcfile(opts, sys.argv[0])

    nodeIDcoords = load_nodeIDs_coords(opts.nodefile)

    [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords)

    segID = 1

    # BACK
    plane = (0, axes[0].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'BACK', segID, planeNodeIDs)

    # FRONT
    plane = (0, axes[0].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    if (opts.sym == 'q') or (opts.sym == 'h'):
        # no top / bottom rows (those will be defined in the
        # top/bottom defs)
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '1,0,0,0,1,1')
    else:
        segID = writeSeg(BCFILE, 'FRONT', segID, planeNodeIDs)

    # LEFT (push side; non-reflecting or symmetry)
    plane = (1, axes[1].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    # if quarter-symmetry, then apply BCs, in addition to a
    # modified edge; and don't deal w/ top/bottom
    if opts.sym == 'q':
        writeNodeBC(BCFILE, planeNodeIDs[1:-1], '0,1,0,1,0,1')
    # else make it a non-reflecting boundary
    else:
        segID = writeSeg(BCFILE, 'LEFT', segID, planeNodeIDs)

    # RIGHT (non-reflecting)
    plane = (1, axes[1].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'RIGHT', segID, planeNodeIDs)

    # BOTTOM
    plane = (2, axes[2].min())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'BOTTOM', segID, planeNodeIDs)
    if opts.bottom == 'full':
        writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')
    elif opts.bottom == 'inplane':
        writeNodeBC(BCFILE, planeNodeIDs, '0,0,1,1,1,0')

    # TOP (transducer face)
    plane = (2, axes[2].max())
    planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane)
    segID = writeSeg(BCFILE, 'TOP', segID, planeNodeIDs)
    if opts.top:
        writeNodeBC(BCFILE, planeNodeIDs, '1,1,1,1,1,1')

    write_nonreflecting(BCFILE, segID)

    BCFILE.close()