1

The whole objective behind asking this question stems from trying to multi-process the creation of Linear Constraint Equations (http://abaqus.software.polimi.it/v6.14/books/usb/default.htm?startat=pt08ch35s02aus129.html#usb-cni-pequation) in Abaqus/CAE for applying periodic boundary conditions to a meshed model. Since my model has over a million elements and I need to perform a Monte Carlo simulation of 1000 such models, I would like to parallelize the procedure for which I haven't found a solution due to the licensing and multi-threading restrictions associated with Abaqus/CAE. Some discussions on this here: Python multiprocessing from Abaqus/CAE

I am currently trying to perform the equation definitions outside of Abaqus using the node sets created as I know the syntax of Equations for the input file.

** Constraint: <name>
*Equation
<dof>
<set1>, <dof>, <coefficient1>.
<set2>, <dof>, <coefficient2>.
<set3>, <dof>, <coefficient3>.

e.g.
** Constraint: Corner_c1_Constraint-1-pair1
*Equation
3
All-1.c1_Node-1, 1, 1.
All-1.c5_Node-1, 1, -1.
RefPoint-3.SetRefPoint3, 1, -1.

Instead of directly writing these lines into the .inp file, I can also write these commands as a separate file and link it to the .inp file of the model using

*EQUATION, INPUT=file_name

I am looking for the Abaqus Python command to write a keyword such as above to the .inp file instead of specifying the Equation constraints themselves. The User's guide linked above instructs specifying this via GUI but that I haven't been able to do that in my version of Abaqus CAE 2018.

Abaqus/CAE Usage:
Interaction module: Create Constraint: Equation: click mouse button 3 while holding the cursor over the data table, and select Read from File.

So I am looking for a command from the scripting reference manual to do this instead. There are commands to parse input files (http://abaqus.software.polimi.it/v6.14/books/ker/pt01ch24.html) but not something to directly write to input file instead of performing it via scripting. I know I can hard code this into the input file but the sheer number of simulations that I would like to perform calls for every bit of automation possible. I have already tried optimising the code using appropriate algorithms and numpy arrays yet the pre-processing itself takes hours for one single model.

p.s. This is my first post on SO - so I'm not sure if this question is phrased in the appropriate format. Would appreciate any answers to the actual question or any other solutions to the intended outcome of parallelizing the pre-processing steps in Abaqus/CAE.

SnowySun
  • 33
  • 4
  • My answer below will allow you to write your keywords to the Job input files. I do something similar in my work all the time. Q: what part of your process is the bottleneck that you want to perform in parallel? Determining the nodes for the equations, or running the analysis? – Matt P Jul 24 '19 at 18:51
  • Thanks @MattP. That worked. My bottlenecks are: (1) to sort the nodes on opposite faces of a cuboid model according to their coordinates, and (2) create the constraint equations for each matching node set in order to apply periodic boundary conditions. I am currently using the native sorted() function and I guess I can speed it up further with bucket sort implementation. Haven't attempted it yet though. As for creating constraint equations, it is done serially by looping through the array of node sets and I'm trying to write the equations myself outside CAE by parallelizing the process. – SnowySun Jul 26 '19 at 05:50
  • Great! Would you mind marking/accepting the answer then? – Matt P Jul 26 '19 at 06:26
  • Done. Have you managed to find a solution for your multi-processing pursuits attempted in the other post (https://stackoverflow.com/questions/44146116/python-multiprocessing-from-abaqus-cae) ? Just curious! – SnowySun Jul 26 '19 at 08:26
  • (Thanks!) I chose to optimize the speed of the serial code at the expense of additional storage and with a very well-organized data structure. The computations were quite fast after that. I came to the conclusion that parallelization may have been possible, but not without performing the ops outside the Abaqus Python kernel. In the end, I had a pure-Python serial implementation I was happy with. – Matt P Jul 26 '19 at 17:26
  • It sounds to me like you could use a similar approach (store data rather than recompute). The main thing is to avoid repeating calcs/search or creating new objects when they aren't necessary. That gets expensive in Python, but look-ups and sorts are quick. Use a profiler like Python's cProfile to find where the actual bottlenecks are. Also, writing constraint equations to file should not be time-consuming. Try storing the data needed, and then writing them all to file at the same time? – Matt P Jul 26 '19 at 17:45

1 Answers1

1

You are looking for the KeywordBlock object. This allows you to write anything to the input file (keywords, comments, etc) as a formatted string. I believe this approach is much less error-prone than alternatives that require you to programmatically write an input file (or update an existing one) on your own.

The KeywordBlock object is created when a Part Instance is created at the Assembly level. It stores everything you do in the CAE with the corresponding keywords.

Note that any changes you make to the KeywordBlock object will be synced to the Job input file when it is written, but will not update the CAE Model database. So for example, if you use the KeywordBlock to store keywords for constraint equations, the constraint definitions will not show up in the CAE model tree. The rest of the Mdb does not know they exist.

As you know, keywords must be written to the appropriate section of an input file. For example, the *equation keyword may be defined at the Part, Part Instance, or Assembly level (see the Keywords Reference Manual). This must also be considered when you store keywords in the KeywordBlock object (it will not auto-magically put your keywords in the right spot, unfortunately!). A side effect is that it is not always safe to write to the KeywordBlock - that is, whenever it may conflict with subsequent changes made via the CAE GUI. I believe that the Abaqus docs recommend that you add your keywords as a last step.

So basically, read the KeywordBlock object, find the right place, and insert your new keyword. Here's an example snippet to get you started:

partname = "Part-1"
model = mdb.models["Model-1"]
modelkwb = model.keywordBlock
assembly = model.rootAssembly

if assembly.isOutOfDate:
    assembly.regenerate()

# Synch edits to modelkwb with those made in the model. We don't need
# access to *nodes and *elements as they would appear in the inp file,
# so set the storeNodesAndElements arg to False.
modelkwb.synchVersions(storeNodesAndElements=False)

# Search the modelkwb for the desired insertion point. In this example, 
# we are looking for a line that indicates we are beginning the Part-Level 
# block for the specific Part we are interested in. If it is found, we 
# break the loop, storing the line number, and then write our keywords
# using the insert method (which actually inserts just below the specified
# line number, fyi). 
line_num = 0
for n, line in enumerate(modelkwb.sieBlocks):
    if line.replace(" ","").lower() == "*part,name={0}".format(partname.lower()):
        line_num = n
        break
if line_num:
    kwds = "your keyword as a string here (may be multiple lines)..."
    modelkwb.insert(position=line_num, text=kwds)
else:
    e = ("Error: Part '{}' was not found".format(partname),
         "in the Model KeywordBlock.")
    raise Exception(" ".join(e))
Matt P
  • 2,287
  • 1
  • 11
  • 26