Creating objects to hold loop counters

A program can spend a large proportion of its computation time executing statements inside loops. As a result, you can make your scripts more efficient if you consider how Abaqus computes the next value of a loop counter each time the loop is executed. If possible, you should create an integer or a sequence object to hold the value of a loop counter. If you use a value derived from an Abaqus object, the time taken to calculate the next value can slow your program significantly.

The following example uses the number of nodes in a part instance to determine the range of a loop counter:


    const odb_SequenceNode& nodeSequence = myInstance.nodes();
    for (int i=0; i < nodeSequence.size() ; i++){
      const odb_Node& myNode = nodeSequence[i];
      nodeLabel = myNode.label(); 
    }
 

You can make the program more efficient if you create an object to hold the value of the number of nodes.


    const odb_SequenceNode& nodeSequence = myInstance.nodes();
    int numNodes = nodeSequence.size();
    for (int i=0; i < numNodes; i++){
      const odb_Node& myNode = nodeSequence[i];
      nodeLabel = myNode.label(); 
    }
 

You can use this technique only if the maximum value of the loop counter remains fixed for the duration of the loop.