Exemple #1
0
def write_material(material):
    """

    :param material:
    :type material: ada.Material
    :return: Code Aster COMM Input string
    """
    from ada.core.utils import NewLine

    # Bi-linear hardening ECRO_LINE=_F(D_SIGM_EPSI=2.0e06, SY=2.35e06,)

    model = material.model
    nl = NewLine(3, suffix="	")
    nl_mat = "nl_mat=(	\n	"

    if model.plasticity_model is not None:
        eps = [e for e in model.eps_p]
        eps[0] = 1e-5  # Epsilon index=0 cannot be zero
        nl_mat += "".join(
            [f"{e:.4E},{s:.4E}," + next(nl)
             for e, s in zip(eps, model.sig_p)]) + ")"
    else:
        nl_mat += ",)"
        logging.error(f"No plasticity is defined for material {material.name}")

    hardening_model_str = """Traction=DEFI_FONCTION(
    NOM_PARA='EPSI', NOM_RESU='SIGM', VALE=nl_mat, INTERPOL='LIN', PROL_DROITE='LINEAIRE', PROL_GAUCHE='CONSTANT'
)"""
    return f"""{nl_mat}
Exemple #2
0
def material_str(material: Material) -> str:
    from ada.core.utils import NewLine

    # Bi-linear hardening ECRO_LINE=_F(D_SIGM_EPSI=2.0e06, SY=2.35e06,)

    model = material.model
    nl = NewLine(3, suffix="	")

    if model.plasticity_model is not None and model.plasticity_model.eps_p is not None:
        nl_mat = "nl_mat=(	\n	"
        eps = [e for e in model.plasticity_model.eps_p]
        eps[0] = 1e-5  # Epsilon index=0 cannot be zero
        nl_mat += "".join([
            f"{e:.4E},{s:.4E}," + next(nl)
            for e, s in zip(eps, model.plasticity_model.sig_p)
        ]) + ")"
        nl_mat += """
Traction=DEFI_FONCTION(
    NOM_PARA='EPSI', NOM_RESU='SIGM', VALE=nl_mat, INTERPOL='LIN', PROL_DROITE='LINEAIRE', PROL_GAUCHE='CONSTANT'
)"""
        mat_nl_in = ", TRACTION=_F(SIGM=Traction,)"
    else:
        logging.debug(f"No plasticity is defined for material {material.name}")
        nl_mat = ""
        mat_nl_in = ""

    return f"""{nl_mat}
def hist_output_str(hist_output: HistOutput) -> str:
    hist_map = dict(
        connector="*Element Output, elset=",
        node="*Node Output, nset=",
        energy="*Energy Output",
        contact="*Contact Output",
    )

    if hist_output.type not in hist_map.keys():
        raise Exception('Unknown output type "{}"'.format(hist_output.type))

    set_type_str = hist_map[hist_output.type]
    newline = NewLine(10)
    var_str = "".join([
        " {},".format(val) + next(newline) for val in hist_output.variables
    ])[:-1]

    if hist_output.type == HistOutput.TYPES.CONTACT:
        iname1 = get_instance_name(hist_output.fem_set[1], True)
        iname2 = get_instance_name(hist_output.fem_set[0], True)
        fem_set_str = f", master={iname1}, slave={iname2}"
    else:
        fem_set_str = "" if hist_output.fem_set is None else get_instance_name(
            hist_output.fem_set, True)
    return f"""*Output, history, {hist_output.int_type}={hist_output.int_value}
Exemple #4
0
def write_elem(el: "Elem") -> str:
    nl = NewLine(10, suffix=7 * " ")
    if len(el.nodes) > 6:
        di = " {}"
    else:
        di = "{:>13}"
    el_str = f"{el.id:>7}, " + " ".join(
        [f"{di.format(no.id)}," + next(nl) for no in el.nodes])[:-1]
    return el_str
Exemple #5
0
def write_elem(el: "Elem", alevel: bool) -> str:
    nl = NewLine(10, suffix=7 * " ")
    if len(el.nodes) > 6:
        di = " {}"
    else:
        di = "{:>13}"
    el_str = (f"{el.id:>7}, " + " ".join([
        f"{di.format(get_instance_name(no, alevel))}," + next(nl)
        for no in el.nodes
    ])[:-1])
    return el_str
Exemple #6
0
def nonstru_str(nonstru):
    from ada.core.utils import NewLine

    nonstru_str = """' Non Structural Elements\n NonStru Group"""
    nl = NewLine(10)

    def write_nonstru(g):
        return f" {g}" + next(nl)

    if len(nonstru) > 0:
        return nonstru_str + "".join(list(map(write_nonstru, nonstru)))
    else:
        return nonstru_str
Exemple #7
0
def gen_set_str(fem_set):
    if len(fem_set.members) == 0:
        if "generate" in fem_set.metadata.keys():
            if fem_set.metadata["generate"] is False:
                raise ValueError(
                    f'set "{fem_set.name}" is empty. Please check your input')
        else:
            raise ValueError("No Members are found")

    generate = fem_set.metadata.get("generate", False)
    internal = fem_set.metadata.get("internal", False)
    newline = NewLine(15)

    el_str = "*Elset, elset" if fem_set.type == "elset" else "*Nset, nset"

    el_instances = dict()

    for p, mem in groupby(fem_set.members, key=attrgetter("parent")):
        el_instances[p.name] = list(mem)

    # for mem in self.members:
    #     if mem.parent.name not in el_instances.keys():
    #         el_instances[mem.parent.name] = []
    #     if mem not in el_instances[mem.parent.name]:
    #         el_instances[mem.parent.name].append(mem)

    set_str = ""
    for elinst, members in el_instances.items():
        el_root = f"{el_str}={fem_set.name}"
        if internal is True and type(fem_set._fem_writer) in (
                AbaqusWriter,
                AbaStep,
        ):
            el_root += "" if "," in el_str[-2] else ", "
            el_root += "internal"

        if generate:
            assert len(fem_set.metadata["gen_mem"]) == 3
            el_root += "" if "," in el_root[-2] else ", "
            set_str += (el_root + "generate\n {},  {},   {}"
                        "".format(*[no
                                    for no in fem_set.metadata["gen_mem"]]) +
                        "\n")
        else:
            set_str += el_root + "\n " + " ".join(
                [f"{no.id}," + next(newline)
                 for no in members]).rstrip()[:-1] + "\n"
    return set_str.rstrip()
Exemple #8
0
    def create_groupdef_str(elset: FemSet):
        if "include" not in elset.metadata.keys():
            return None
        if "unique_id" in elset.metadata.keys():
            gid = elset.metadata["unique_id"]
        else:
            gid = next(gr_ids)

        if "nonstru" in elset.metadata.keys():
            nonstrus.append(gid)

        nline = NewLine(10)
        mem_str = " ".join([f"{x.id}{next(nline)}" for x in elset.members])
        if elset.type == "elset":
            return f" Name  Group         {gid}  {elset.name}\n GroupDef            {gid}  Elem\n {mem_str}\n\n"
        else:
            return f" Name  Group         {gid}  {elset.name}\n GroupNod  {gid}  {mem_str}\n\n"