inpRW._inpMod

Module Contents

This module contains functions for modifying the data in keywords.

class inpRW._inpMod.Mod

The Mod class contains functions modify data in the parsed input file structure.

calculateCentroid(elementID)

This function gets the nodal coordinates of an element and calls centroid.averageVertices().

Parameters:

elementID (int or inpInt) – The label of an element.

Returns:

A numpy array containing the coordinates of the element centroid.

Return type:

numpy.ndarray

convertOPnewToOPmod(startStep=0, finishStep=None, bStep=None)

Converts keyword parameter OP=NEW to OP=MOD or OP=REPLACE and removes unnecessary keywords from steps.

This function will first identify a baseStep from which to compare all steps between and including startStep and finishStep. baseStep can be specified via the bStep parameter, or it will be the 0th step. The function will first identify the keyword blocks in baseStep which use the “OP” parameter (the list of potential keywords is stored in _opKeywords). This will include implied “OP” parameters.

Parameters:
  • startStep (int or str) – The beginning step for which to convert “OP” parameters. Defaults to 0.

  • finishStep (int or str) – The last step for which to convert “OP” parameters. If None, all steps after and including startStep will be converted. Defaults to None.

  • bStep (int or str) – The index or name of the step in kwg['Step'] from which the other steps will be compared. If bStep = None, the 0th step will be baseStep. Defaults to None.

Warning

This function should not be used. It needs to be reworked, as it does not properly deactivate step features that are inactive in subsequent steps.

Todo

Read Boundary Conditions in model data as the initial baseStep.

createManifest(lastBaseStep=None, stepGroupingIn=None, parameterString='')

Creates a *MANIFEST inpRW instance and places the steps in the original file into sub-input files.

This function will reorganize the steps in the input file per the user’s specification. The new *MANIFEST input file will look like the following:

*MANIFEST,BASE STATE=YES, EVOLUTION TYPE=HISTORY
model_and_basesteps.inp
stepGrouping1.inp
stepGrouping2.inp
stepGrouping3.inp

The first input file will contain the model data and any common base steps for the subsequent simulations. All subsequent input files contain independent simulation histories. See that Abaqus documentation for more information on *MANIFEST.

lastBaseStep is the last step in the input file that will be considered a base step for the analysis. It can be a 0-based integer corresponding to the step number, or it can be a case-insensitive string corresponding to a step name. If lastBaseStep is not specified, all steps in the simulation will be used in nonlinear load cases.

stepGroupingIn is a sequence of sequences, the first item is the input file name, and the second is a sequence of the steps to associate with that input file. The sequence can use step names or integers.

For example:

stepGroupingIn = [ ['LoadA.inp', ['Step-1', 'Step-2']], ['LoadB.inp', [3, 4]] ]

If stepGroupingIn is not specified, all steps after lastBaseStep will be independent nonlinear load cases. There is no limit on how steps can be ordered, reused, etc. However, it is the analyst’s responsibility to build a working step order, as this function does not check the validity of the simulation.

parameterString is a string that allows the user to specify the parameters for *MANIFEST. Specify them as you would on the Abaqus keyword line. The “BASE STATE” parameter will be set based on the lastBaseStep input. “EVOLUTION TYPE=HISTORY” is automatically included and should not be specified, as this is currently (as of Abaqus 2022 GA) the only valid option.

Example:

parameterString = 'MODEL CHANGE, RESULTS=new'
Parameters:
  • lastBaseStep (int or str) – Indicates which step should be considered the last base step for the *MANIFEST steps. Use 0-based indices.

  • stepGroupingIn (list) – A Sequence of sequences, the first item is the input file name, and the second is a sequence of the steps to associate with that input file. The sequence can use step names or integers.

  • parameterString (str) – Specifies additional parameters for the keyword line. The “BASE STATE” and “EVOLUTION TYPE” parameters will automatically be included.

Returns:

A new inpRW instance reorganized as a *MANIFEST input file.

Return type:

inpRW

deleteItemReferences(labelD, inputType='other', deleteModCouplings=False, delNodesFromElsLevel1=False, _level=0, _limit=100)

This function will delete the item references in labelD throughout the input file. If an item that is deleted also deletes a named reference, this function will also find the references to those new items and delete them.

A thorough explanation of the delNodesFromElsLevel1 option is needed.

The user has a set of nodes to delete. The user generates labelD with “labelD = findNodeRefs(nlabels)”. He then deletes the nodes and all references to the nodes (contained in labelD) with deleteItemReferences(labelD, 'node'). deleteItemReferences() will call itself to handle chained item references, and it will specify the _level parameter to track how many levels deep it is. When deleting nodes, deleteItemReferences() will by default delete the nodes and their references, which will include elements. It deletes the elements by calling deleteItemReferences(elementD, 'element', _level=1), which also handles deleting all references to the elements.

deleteItemReferences(elementD, 'element', _level=0) behaves a bit differently. When elements are deleted, any nodes that were formally parts of elements but are no longer referenced by any elements will be deleted. This does not happen with deleteItemReferences(elementD, 'element', _level=1) unless delNodesFromElsLevel1=True is also specified.

This option has some niche use cases (for example, deleting fastener constructs of the form mesh - coupling - solid elements representing weld - coupling - mesh). In most cases, leaving delNodesFromElsLevel1=False (default) is the desired choice.

Parameters:
  • labelD (csid) – Contains the mapping between the item references (the keys), and the location of the reference along with the region that should be deleted if the item is deleted (the value). labelD should be the return csid from a function in FindRefs.

  • inputType (str) – Indicates to what labelD refers. Valid options are ‘node’, ‘element’, and ‘other’. ‘node’ will handle node label and node set references, ‘element’ will handle element label and element set references, and ‘other’ handles all other cases. Defaults to ‘other’.

  • deleteModCouplings (bool) – If True, all *COUPLING, *KINEMATIC COUPLING, and *DISTRIBUTING COUPLING keywords with modified application regions (*SURFACE, *NSET, *ELSET) will be deleted. Defaults to False.

  • delNodesFromElsLevel1 (bool) – If True, nodes can be deleted when element references are deleted in _level=1. See detailed explanation above. Defaults to False.

  • _level (int) – Tracks when deleteItemReferences() calls itself to handle certain reference chains. The user should not need to specify this. Defaults to 0.

  • _limit (int) – A limit on how many iterations this function will perform when trying to identify and delete chains of references. This check is performed in a while loop, which could create an infinite loop if something unexpected happens, hence the limit. The iterations referred to is something like the following: delete a node -> delete an element -> delete an element set -> delete a surface -> delete a contact pair. This example had 5 iterations from deleting nodes to deleting a contact pair using an element based surface. The default value of 100 should be much higher than necessary. Defaults to 100.

deleteKeyword(path='', positionl=None, updateInpStructure=True, printstatus=True)

Deletes the keyword block at the indicated location and updates the data structure.

Either path or positionl is required. Set updateInpStructure to False if you need to delete many keyword blocks from a large input file, as those update operations can be slow. If updateInpStructure == True, this function will call updateInp(), but only update keyword block paths after (and including) the position of the deleted block, and it will not call _groupKeywordBlocks(), as this function will automatically delete the entry from kwg.

Note

When deleting a list of keywords, deleting one keyword will change the indices of all subsequent keywords. However, the list of inpKeyword.paths or position indices of keywords to delete will not update automatically. For this reason, the user should always sort the list of keywords to delete so that they are deleted from the end of the .inp towards the front. Deleting a keyword object at the end of the list will not affect the indices of keywords prior to it. The sorting is more easily handled when using positionl (which is a list of integers) than with path, which is a list of strings. If the input file was parsed with organize=True, the user will need to perform a multi-level sort to account for the keyword and suboption indices. Use nestedSort() for this task. Example:

oldBlockPaths = list(flatten(oldBlockPaths))
#gets a flattened list of keyword paths to delete

oldBlockPositionls = [self.parsePath(i)[1:] for i in oldBlockPaths]
#gets the positionL from each path i.e. [1,[0]] will be keyword block 1, suboption 0

oldBlockPositionls1 = nestedSort(iterable=oldBlockPositionls, reverse=True)
#sorts oldBlockPositionls in reverse order. This will account for nested suboptions.

Alternately, the user can account for the change of indices when deleting keywords. However, sorting and reversing the list of keywords to delete should be simpler in most cases.

Parameters:
  • path (str) – A string indicating the path to the inpKeyword to delete. Defaults to ‘’.

  • positionl (list) – A sequence of sequences with the indices to the inpKeyword block to delete. A path string will be generated from this via createPathFromSequence(). Defaults to None.

  • updateInpStructure (bool) – If True, will call updateInp() after deleting the keyword block. Defaults to True.

  • printstatus (bool) – If True, print which keyword block is deleted. Defaults to True.

getLabelsFromSet(blocks)

Returns a flat list of all the labels from the set defined in block.

Parameters:

blocks (list) – A list of *NSET or *ELSET keyword blocks.

Returns:

A flat list containing the labels in the sets. If more than one set is passed to this function, the output list will be sorted and contain only unique entries. If only one set is used, the output will not be sorted, and any duplicate entries will not be removed.

Return type:

list

insertKeyword(obj, path='', positionl=None, updateInpStructure=True)

Inserts a new keyword object in the inpKeywordSequence at the location specified by path or positionl.

obj is required, and either path or positionl is required. Set updateInpStructure to False if you need to insert many keyword blocks into a large input file, as those update operations can be slow. If updateInpStructure == True, this function will call updateInp(), but only update keyword block paths after (and including) the position of the inserted block. kwg will only have the new block added.

Note

Inserting multiple keywords should be done in reverse order. See the note in deleteKeyword() for a detailed explanation.

Parameters:
  • obj (inpKeyword) – The new keyword block to insert.

  • path (str) – A string indicating the path to the inpKeyword to delete. Defaults to ‘’.

  • positionl (list) – A sequence of sequences with the indices to the inpKeyword block to delete. A path string will be generated from this via createPathFromSequence(). Defaults to None.

  • updateInpStructure (bool) – If True, will call updateInp() after deleting the keyword block. Defaults to True.

mergeNodes(dupNodeDict)

Merges pairs of nodes into one node. The node labels referred to by the keys in dupNodeDict will be replaced with the node labels in values.

dupNodeDict should be a one-to-one mapping of node labels. The key will be replaced by the value. In most cases, this dictionary should be created by using findCloseNodes().

For every pair of nodes in dupNodeDict, this function will first find every element connected to the old node (the key). Each of these elements will have their references to the node label in key replaced with the node label in value. Then, the old node will have its mesh.Node.elements attribute cleared. Finally, deleteItemReferences() will be called to delete the old nodes and remove all remaining references to them. Thus, the only locations in the input file where the old node labels will be replaced with the new node labels is in *ELEMENT keyword blocks; all other references will simply be deleted.

Parameters:

dupNodeDict (dict) – A dictionary which maps the node label to be removed with the node label with which it should be replaced.

reduceStepSubKWs(removeComments=False)

Consolidates keywords in a particular step that can have the “OP” parameter.

This function can also group some sub-keywords if the parent keywords are identical. This function is limited to keyword blocks in 3 different groupings: _mergeDatalineKeywordsOP, _appendDatalineKeywordsOP, and _dofXtoYDatalineKeywordsOP.

If a keyword block to be removed has comments in its data, those comments will be included with the consolidated keyword block if removeComments=False. They will be immediately after the associated dataline if the keyword is in _appendDatalineKeywordsOP, or they will all be appended to the end of the data if the keyword is in _dofXtoYDatalineKeywordsOP.

Example:

*BOUNDARY, OP=NEW, ORIENTATION="Orientation48"
"Fixed Displacement24", 2, 2, 0.
*BOUNDARY, OP=NEW, ORIENTATION="Orientation48"
"Fixed Displacement24", 3, 3, 0.
*BOUNDARY, OP=NEW, ORIENTATION="Orientation48"
"Fixed Displacement24", 4, 4, 0.
*OUTPUT, FIELD, FREQUENCY=1
*ELEMENT OUTPUT
S
*OUTPUT, FIELD, FREQUENCY=1
*ELEMENT OUTPUT
E
*OUTPUT, FIELD, FREQUENCY=1
*ELEMENT OUTPUT
PE
*OUTPUT, FIELD, FREQUENCY=1
*ELEMENT OUTPUT
PEEQ

will become:

*BOUNDARY, OP=NEW, ORIENTATION="Orientation48"
"Fixed Displacement24", 2, 4, 0.
*OUTPUT, FIELD, FREQUENCY=1
*ELEMENT OUTPUT
S, E, PE, PEEQ
Parameters:

removeComments (bool) – If True, any comments associated with keyword blocks that are now consolidated will be deleted. Defaults to False.

Todo

Add support for keywords in _mergeDatalineKeywordsOP.

removeGenerate(generateBlocks=None)

Removes the GENERATE parameter from keyword blocks and expands the datalines.

This function will loop through the keyword blocks as specified in generateBlocks or it will search the entire inpKeywordSequence for the appropriate blocks. It will remove the “GENERATE” parameter from blocks such as *NSET, and fully expand the datalines. It will ignore *TIME POINTS, *NODAL THICKNESS, and *NODAL ENERGY RATE keywords if generateBlocks == None.

Parameters:

generateBlocks (list) – A list containing inpKeyword blocks. Defaults to None.

Todo

Test on latest version of inpRW.

replaceKeyword(obj, path='', positionl=None, updateInpStructure=True)

Deletes the keyword at the position designated by path or positionl, and then inserts the new keyword object at the same location.

obj is required, and either path or positionl is required. Set updateInpStructure to False if you need to insert many keyword blocks into a large input file, as those update operations can be slow. If updateInpStructure == True, this function will call updateInp(), but only update keyword block paths after (and including) the position of the inserted block. kwg will only have the old block deleted and the new block added.

Parameters:
  • obj (inpKeyword) – The new keyword block to insert.

  • path (str) – A string indicating the path to the inpKeyword to delete. Defaults to ‘’.

  • positionl (list) – A sequence of sequences with the indices to the inpKeyword block to delete. A path string will be generated from this via createPathFromSequence(). Defaults to None.

  • updateInpStructure (bool) – If True, will call updateInp() after deleting the keyword block. Defaults to True.

updateKTRIDD(keywordNames)

Short for “update Keywords To Remove If Data Deleted”, this function will update ktridd.

Parameters:

keywordNames (list) – A sequence of keyword names.

updatePKTRICD(mapping)

Updates pktricd with the items in mapping.

Each key in pktricd will be an inpKeyword block. The value will be parent keyword name which should be deleted if the inpKeyword contained in the key is deleted.

Parameters:

mapping (list) – A sequence of sequences of the form [[[inpKeyword, inpKeyword, …], parentKWName (str)]].

_consolidateDofXtoYDatalines(datalist, removeComments=False)

Examines datalist to determine the DOF ranges that are constrained. Returns a consolidated list.

This should be specific to the *ADAPTIVE MESH CONSTRAINT and *BOUNDARY (with certain dataline lengths) keywords. The function will group the datalines by application region and by applied load, and will consolidate the applicable DOFs. This will return new dataline(s) as applicable.

The first grouping is via the application region, which is the 0th field in the dataline. This should be a node label or node set name. This function just uses the item in the field as the key; so if one *BOUNDARY applies to node 1, and another applies to nset1, which contains only node 1, the BCs will not be consolidated together.

The items in datalist should all correspond to identical keyword lines, as it would be inappropriate to group items that are use different parameters. That must be handled before calling this function. Thus, the preferred method for calling this function is through reduceStepSubKWs(), as this will perform the necessary operations prior to calling this function.

Example:

In: datalist = [["Fixed Displacement24", 2, 2, 0.], ["Fixed Displacement24", 3, 3, 0.], ["Fixed Displacement24", 4, 4, 0.]]
In: self._consolidateDofXtoYDatalines(datalist)
Out: ["Fixed Displacement24", 2, 4, 0.]
Parameters:
  • datalist (list) – This should be a sequence of parsed datalines, not a list of strings.

  • removeComments (bool) – If True, comments included in datalist will be discarded. If False, they will be appended to the output.

Returns:

A list of the consolidated datalines.

Return type:

list

_convertSystem(node)

convertSystem(node) module: _inpMod.py

Warning

THIS FUNCTION HAS NOT BEEN TESTED WITH THE inpRW MODULE. IT NEEDS TO BE REWORKED BEFORE IT SHOULD BE USED.

Pass in node data as (X, Y, Z, cos1, cos2, cos3, ActiveSystem tuple):

Example:

(1, 10.0, 0.0, 20.0, 0.0, 0.0, 0.0, ((0.0, 0.0, 0.0, 1.0, 0.0, 0.0),))

Returns the X,Y,Z coordinates of the node in the global CSYS.

Todo

Convert to inpRW.

_isolateNodesToKeep(dup_node_dict, nodesToKeep)

Warning

THIS FUNCTION HAS NOT BEEN TESTED WITH THE inpRW MODULE. IT NEEDS TO BE REWORKED BEFORE IT SHOULD BE USED.

dup_node_dict is the duplicate nodes dictionary produced by _findCloseNodes, and nodesToKeep is a sequence of nodes. This function will remove all nodes in nodesToKeep from dup_node_dict.

_removeSystem()

Finds the active system at all points of the input file, converts all node definitions to global coordinates, then deletes the *SYSTEM keywords.

Warning

THIS FUNCTION HAS NOT BEEN TESTED WITH THE inpRW MODULE. IT NEEDS TO BE REWORKED BEFORE IT SHOULD BE USED.

_replaceStarParameter()

module: _inpMod.py

This function will delete *PARAMETER keyword lines, and substitute the appropriate values into the input file.

Warning

THIS FUNCTION HAS NOT BEEN TESTED WITH THE inpRW MODULE. IT NEEDS TO BE REWORKED BEFORE IT SHOULD BE USED.