コード例 #1
0
    def add_constraint(self, constraint: Constraint) -> Constraint:
        constraint.parent = self
        if constraint.m_set.parent is None:
            self.add_set(constraint.m_set)

        if constraint.s_set.parent is None:
            self.add_set(constraint.s_set)

        self.constraints[constraint.name] = constraint
        return constraint
コード例 #2
0
ファイル: read_constraints.py プロジェクト: Krande/adapy
def grab_constraint(master, data, fem: FEM) -> Constraint:
    m = str_to_int(master)
    m_set = FemSet(f"co{m}_m", [fem.nodes.from_id(m)], "nset")
    slaves = []
    for d in data:
        s = str_to_int(d["slave"])
        slaves.append(fem.nodes.from_id(s))
    s_set = FemSet(f"co{m}_s", slaves, "nset")
    fem.add_set(m_set)
    fem.add_set(s_set)
    return Constraint(f"co{m}", Constraint.TYPES.COUPLING, m_set, s_set, parent=fem)
コード例 #3
0
 def grab_constraint(master, data):
     m = str_to_int(master)
     m_set = FemSet(f"co{m}_m", [fem.nodes.from_id(m)], "nset")
     slaves = []
     for d in data:
         s = str_to_int(d["slave"])
         slaves.append(fem.nodes.from_id(s))
     s_set = FemSet(f"co{m}_m", slaves, "nset")
     fem.add_set(m_set)
     fem.add_set(s_set)
     return Constraint(f"co{m}", "coupling", m_set, s_set, parent=fem)
コード例 #4
0
 def get_mpc(mpc_values):
     m_set, s_set = zip(*mpc_values)
     mpc_name = mpc_type + "_mpc"
     mset = FemSet("mpc_" + mpc_type + "_m", m_set, "nset")
     sset = FemSet("mpc_" + mpc_type + "_s", s_set, "nset")
     return Constraint(mpc_name,
                       "mpc",
                       mset,
                       sset,
                       mpc_type=mpc_type,
                       parent=fem)
コード例 #5
0
ファイル: reader.py プロジェクト: Krande/adapy
 def get_mpc(mpc_values):
     m_set, s_set = zip(*mpc_values)
     mpc_name = mpc_type + "_mpc"
     mset = FemSet("mpc_" + mpc_type + "_m", m_set, FemSet.TYPES.NSET)
     sset = FemSet("mpc_" + mpc_type + "_s", s_set, FemSet.TYPES.NSET)
     return Constraint(mpc_name,
                       Constraint.TYPES.MPC,
                       mset,
                       sset,
                       mpc_type=mpc_type,
                       parent=fem)
コード例 #6
0
    def convert_hinge(elem: Elem, hinge: Hinge):
        if hinge.constraint_ref is not None:
            return
        n = hinge.fem_node
        csys = hinge.csys
        d = hinge.retained_dofs

        n2 = Node(n.p, next(new_node_id), parent=elem.parent)
        elem.parent.nodes.add(n2, allow_coincident=True)
        i = elem.nodes.index(n)
        elem.nodes[i] = n2

        if elem.eccentricity is not None:
            if elem.eccentricity.end1 is not None:
                if n == elem.eccentricity.end1.node:
                    elem.eccentricity.end1.node = n2

            if elem.eccentricity.end2 is not None:
                if n == elem.eccentricity.end2.node:
                    elem.eccentricity.end2.node = n2

        if n2.id not in constrain_ids:
            constrain_ids.append(n2.id)
        else:
            logging.error(f"Hinged node {n2} cannot be added twice to different couplings")
            return None

        m_set = FemSet(f"el{elem.id}_hinge{i + 1}_m", [n], "nset")
        s_set = FemSet(f"el{elem.id}_hinge{i + 1}_s", [n2], "nset")

        elem.parent.add_set(m_set)
        elem.parent.add_set(s_set)
        c = Constraint(
            f"el{elem.id}_hinge{i + 1}_co",
            Constraint.TYPES.COUPLING,
            m_set,
            s_set,
            d,
            csys=csys,
        )
        elem.parent.add_constraint(c)
        hinge.constraint_ref = c
        logging.info(f"added constraint {c}")
コード例 #7
0
 def build_mpc_for_end(elem, n_old, ecc, i):
     if n_old.id in edited_nodes.keys():
         build_constraint(n_old, elem, ecc, i)
     else:
         mat = np.eye(3)
         new_p = np.dot(mat, ecc) + n_old.p
         n_new = Node(new_p, parent=elem.parent)
         elem.parent.nodes.add(n_new, allow_coincident=True)
         m_set = FemSet(f"el{elem.id}_mpc{i + 1}_m", [n_new], "nset")
         s_set = FemSet(f"el{elem.id}_mpc{i + 1}_s", [n_old], "nset")
         c = Constraint(
             f"el{elem.id}_mpc{i + 1}_co",
             Constraint.TYPES.MPC,
             m_set,
             s_set,
             mpc_type="Beam",
             parent=elem.parent,
         )
         elem.parent.add_constraint(c)
         elem.nodes[i] = n_new
         edited_nodes[n_old.id] = n_new
コード例 #8
0
    def build_constraint(n_old, elem, ecc, i):
        n_new = edited_nodes[n_old.id]
        mat = np.eye(3)
        new_p = np.dot(mat, ecc) + n_old.p
        n_new_ = Node(new_p, parent=elem.parent)
        if vector_length(n_new_.p - n_new.p) > tol:
            elem.parent.nodes.add(n_new_, allow_coincident=True)
            m_set = FemSet(f"el{elem.id}_mpc{i + 1}_m", [n_new_], "nset")
            s_set = FemSet(f"el{elem.id}_mpc{i + 1}_s", [n_old], "nset")
            c = Constraint(
                f"el{elem.id}_mpc{i + 1}_co",
                Constraint.TYPES.MPC,
                m_set,
                s_set,
                mpc_type="Beam",
                parent=elem.parent,
            )
            elem.parent.add_constraint(c)
            elem.nodes[i] = n_new_
            edited_nodes[n_old.id] = n_new_

        else:
            elem.nodes[i] = n_new
            edited_nodes[n_old.id] = n_new
コード例 #9
0
def get_constraints_from_inp(bulk_str, fem):
    """

    ** Constraint: Container_RigidBody
    *Rigid Body, ref node=container_rp, elset=container

    *MPC
     BEAM,    2007,     161
     BEAM,    2008,     162

    :param bulk_str:
    :param fem:
    :type fem: ada.fem.FEM
    """

    # Rigid Bodies

    constraints = []
    rbnames = Counter(1, "rgb")
    conames = Counter(1, "co")

    for m in AbaCards.tie.regex.finditer(bulk_str):
        d = m.groupdict()
        name = d["name"]
        msurf = grab_set_from_assembly(d["surf1"], fem, "surface")
        ssurf = grab_set_from_assembly(d["surf2"], fem, "surface")
        constraints.append(
            Constraint(name,
                       "tie",
                       msurf,
                       ssurf,
                       metadata=dict(adjust=d["adjust"])))

    for m in AbaCards.rigid_bodies.regex.finditer(bulk_str):
        d = m.groupdict()
        name = next(rbnames)
        ref_node = grab_set_from_assembly(d["ref_node"], fem, "nset")
        elset = grab_set_from_assembly(d["elset"], fem, "elset")
        constraints.append(
            Constraint(name, "rigid body", ref_node, elset, parent=fem))

    couplings = []
    for m in AbaCards.coupling.regex.finditer(bulk_str):
        d = m.groupdict()
        name = d["constraint_name"]
        rn = d["ref_node"].strip()
        sf = d["surface"].strip()
        if rn.isnumeric():
            ref_set = FemSet(next(conames), [int(rn)], "nset", parent=fem)
            fem.sets.add(ref_set)
        else:
            ref_set = fem.nsets[rn]

        surf = fem.surfaces[sf]

        res = np.fromstring(list_cleanup(d["bulk"]), sep=",", dtype=int)
        size = res.size
        cols = 2
        rows = int(size / cols)
        dofs = res.reshape(rows, cols)

        csys_name = d.get("orientation", None)
        if csys_name is not None:
            if csys_name not in fem.lcsys.keys():
                raise ValueError(
                    f'Csys "{csys_name}" was not found on part {fem}')
            csys = fem.lcsys[csys_name]
        else:
            csys = None

        couplings.append(
            Constraint(name,
                       "coupling",
                       ref_set,
                       surf,
                       csys=csys,
                       dofs=dofs,
                       parent=fem))

    # Shell to Solid Couplings
    sh2solids = []
    for m in AbaCards.sh2so_re.regex.finditer(bulk_str):
        d = m.groupdict()
        name = d["constraint_name"]
        surf1 = grab_set_from_assembly(d["surf1"], fem, "surface")
        surf2 = grab_set_from_assembly(d["surf2"], fem, "surface")
        sh2solids.append(Constraint(name, "shell2solid", surf1, surf2))

    # MPC's
    mpc_dict = dict()
    mpc_re = re.compile(r"\*mpc\n(?P<bulk>.*?)^\*", _re_in)
    mpc_content = re.compile(
        r"\s*(?P<mpc_type>.*?),\s*(?P<master>.*?),\s*(?P<slave>.*?)$", _re_in)
    for match in mpc_re.finditer(bulk_str):
        d1 = match.groupdict()
        for subm in mpc_content.finditer(d1["bulk"]):
            d = subm.groupdict()
            mpc_type = d["mpc_type"]
            m = d["master"]
            s = d["slave"]
            if mpc_type not in mpc_dict.keys():
                mpc_dict[mpc_type] = []
            try:
                n1_ = str_to_int(m)
            except BaseException as e:
                logging.debug(e)
                n1_ = grab_set_from_assembly(m, fem, "nset")

            try:
                n2_ = str_to_int(s)
            except BaseException as e:
                logging.debug(e)
                n2_ = grab_set_from_assembly(s, fem, "nset")

            mpc_dict[mpc_type].append((n1_, n2_))

    def get_mpc(mpc_values):
        m_set, s_set = zip(*mpc_values)
        mpc_name = mpc_type + "_mpc"
        mset = FemSet("mpc_" + mpc_type + "_m", m_set, "nset")
        sset = FemSet("mpc_" + mpc_type + "_s", s_set, "nset")
        return Constraint(mpc_name,
                          "mpc",
                          mset,
                          sset,
                          mpc_type=mpc_type,
                          parent=fem)

    mpcs = [get_mpc(mpc_values_in) for mpc_values_in in mpc_dict.values()]

    return list(chain.from_iterable([constraints, couplings, sh2solids, mpcs]))