Source code for upxo.meshing.writer_ABQ


import numpy as np



# -------------------------------------------------
# Heading
# -------------------------------------------------
heading = """\
*Heading
Job-1
** Job name : Job-1
** Generated by : UPXO 1.0
*Preprint, echo=NO, model=NO, history=NO, contact=NO
"""

# -------------------------------------------------
# Example data
# -------------------------------------------------
nodes = np.array([
    [1, 0.0, 0.0, 0.0],
    [2, 1.0, 0.0, 0.0],
    [3, 1.0, 1.0, 0.0],
])

elements = np.array([
    [1, 1, 2, 3],
    [2, 2, 3, 4],
])

nset = np.array([1, 2, 5, 7, 9])

# Example grain elsets dictionary (your stated structure)
elsets_dict = {
    "basic": {
        "gid_1": [1, 2, 3, 4, 5, 6],          # will use generate
        "gid_2": [7, 9, 10, 14, 15, 18],     # explicit list
    }
}

# -------------------------------------------------
# Utilities
# -------------------------------------------------


[docs] def write_elset(f, name, elem_ids, per_line=16): """ Writes an Abaqus *Elset. """ elem_ids = np.asarray(elem_ids, dtype=int) f.write(f"*Elset, elset={name}\n") for i in range(0, len(elem_ids), per_line): line = ", ".join(map(str, elem_ids[i:i+per_line])) f.write(line + "\n")
[docs] def write_grain_elsets(f, elsets_dict, prefix="Grain"): """ Writes all grain-wise elsets from dictionary. """ grain_block = elsets_dict.get("basic", {}) for gid_key, elem_ids in grain_block.items(): gid = gid_key.replace("gid_", "") elset_name = f"{prefix}{gid}_set" write_elset(f, elset_name, elem_ids)
# ------------------------------------------------- # File writer # ------------------------------------------------- with open("job1.inp", "w", encoding="utf-8") as f: # Heading f.write(heading) # -------------------- # Nodes # -------------------- f.write("*Node\n") np.savetxt(f, nodes, fmt="%d, %.6f, %.6f, %.6f") # -------------------- # Elements # -------------------- f.write("*Element, type=CPS3\n") np.savetxt(f, elements, fmt="%d, %d, %d, %d") # -------------------- # Node set # -------------------- f.write("*Nset, nset=LEFT\n") for i in range(0, len(nset), 16): f.write(", ".join(map(str, nset[i:i+16])) + "\n") # -------------------- # Grain element sets # -------------------- f.write("**\n") f.write("** Each Grain is made up of multiple elements\n") f.write("**\n") write_grain_elsets(f, elsets_dict) elementType = 'CSP4' # ======================================================================= # ======================================================================= # ======================================================================= # ======================================================================= # ======================================================================= ''' *Heading Job-1 ** Job name : Job-1 ** Generated by : ImportExport Version 6.5.167.2b16e61e0 *Preprint, echo = NO, model = NO, history = NO, contact = NO ** ** ----------------------------Geometry---------------------------- ** *Include, Input = sunil_nodes.inp *Include, Input = sunil_elems.inp *Include, Input = sunil_elset.inp *Include, Input = sunil_sects.inp ** ** ---------------------------------------------------------------- ** ''' # NODES ''' ** Generated by : ImportExport Version 6.5.167.2b16e61e0 ** ---------------------------------------------------------------- ** *Node 1, 0.000000, 0.000000, 0.000000 2, 1.000000, 0.000000, 0.000000 ''' # ELEMENTS ''' ** Generated by : ImportExport Version 6.5.167.2b16e61e0 ** ---------------------------------------------------------------- ** *Element, type=C3D8 1, 123, 2, 1, 122, 134, 13, 12, 133 2, 124, 3, 2, 123, 135, 14, 13, 134 3, 125, 4, 3, 124, 136, 15, 14, 135 ''' # ELSETS ''' ** Generated by : ImportExport Version 6.5.167.2b16e61e0 ** ---------------------------------------------------------------- ** ** The element sets *Elset, elset=cube, generate 1, 1000, 1 ** ** Each Grain is made up of multiple elements ** *Elset, elset=Grain1_set 654, 655, 656, 657, 663, 664, 665, 666, 667, 672, 673, 674, 675, 676, 744, 745, 753, 754, 755, 756, 757, 763, 764, 765, 766, 767, 771, 772, 773, 774, 775, 776, 777, 781, 782, 784, 786, 787, 791, 792, 843, 844, 845, 846, 853, 854, 855, 856, 857, 861, 863, 864, 865, 866, 867, 871, 872, 874, 875, 876, 881, 882, 884, 885, 886, 887, 891, 892, 893, 943, 944, 945, 946, 952, 953, 954, 955, 956, 961, 962, 963, 964, 965, 966, 971, 972, 973, 974, 975, 976, 981, 982, 983, 984, 985, 986, 987, 991, 992, 993, 994, 995, 996, 997 ''' # SECTIONS ''' ** Generated by : ImportExport Version 6.5.167.2b16e61e0 ** ---------------------------------------------------------------- ** ** Each section is a separate grain ** Section: Grain1 *Solid Section, elset=Grain1_set, material=Grain_Mat1 *Hourglass Stiffness 250 ** -------------------------------------- ** Section: Grain2 *Solid Section, elset=Grain2_set, material=Grain_Mat2 *Hourglass Stiffness 250 ''' # ---------------------------------------------- # *Part, name=DREAM3D # *Node # *Element, type=C3D8 # *Elset, elset=GRAIN-87 # 5603, 5604, 5623, 5624, 6003, 6004, 6023, 6024, 6025, 6026, 6027, 6028, 6047, 6048, 6403, 6404 # 6405, 6406, 6407, 6408, 6409, 6423, 6424, 6425, 6426, 6427, 6428, 6429, 6447, 6448, 6827, 6828 # 6829, 6848, 6849, 6868, 7228, 7229, 7248 # *Elset, elset=PHASE-1, generate # 1, 8000, 1 # ** Section: Section-64-GRAIN-64 # *Solid Section, elset=GRAIN-64, material=MATERIAL-GRAIN64 # , # *End Part # ---------------------------------------------- # *Assembly, name=Assembly # *Instance, name=DREAM3D-1, part=DREAM3D # *End Instance # *Nset, nset=_PickedSet4, internal, instance=DREAM3D-1, generate # 21, 9261, 21 # *End Assembly # ---------------------------------------------- # *Material, name=MATERIAL-GRAIN1 # *Depvar # 1, # *User Material, constants=6 # 26.534, 83.227, 38.07, 1., 2., 0. # ---------------------------------------------- # ** # ** STEP: Loading # ** # *Step, name=Loading, nlgeom=YES, inc=10000 # *Static # 0.01, 1., 1e-08, 1. # ---------------------------------------------- # ** # ** BOUNDARY CONDITIONS # ** ''' ** Name: xfix Type: Displacement/Rotation *Boundary Set-1, 1, 1 ** Name: yfix Type: Displacement/Rotation *Boundary Set-2, 2, 2 ** Name: zfix Type: Displacement/Rotation *Boundary Set-3, 3, 3 ''' # ---------------------------------------------- ''' ** ** STEP: Loading ** *Step, name=Loading, nlgeom=YES, inc=10000 *Static 0.01, 10., 1e-05, 1. ** ** BOUNDARY CONDITIONS ** ** Name: xpull Type: Displacement/Rotation *Boundary Set-4, 1, 1, 0.5 ** ** OUTPUT REQUESTS ** *Restart, write, frequency=0 ** ** FIELD OUTPUT: F-Output-2 ** *Output, field *Element Output, directions=YES SDV, ** ** FIELD OUTPUT: F-Output-1 ** *Output, field, variable=PRESELECT ** ** HISTORY OUTPUT: H-Output-1 ** *Output, history, variable=PRESELECT *End Step '''