inpRW._inpFind¶
Module Contents¶
This module contains functions for finding information in keywords.
- class inpRW._inpFind.Find¶
The
Findclass contains functions related to finding information from theinpRWdata structure.- findItemReferences(blockName, refNames)¶
This function will call the appropriate function from
FindRefsbased on the value of blockName. refNames will serve as the input to the final function.This function is mainly meant to be used in
deleteItemReferences(), where chains of data items and their references need to be deleted. When this happens, a function needs to be called which will search for references to the new keyword block.- Parameters:
blockName (str) – A string which should be the
nameattribute of a keyword block. This function will callrsl(blockName).title()to format blockName prior to calling the appropriate function inFindRefs, so the user just needs to specify the full name of the Abaqus keyword in any formatting, without the *.refNames (list) – A sequence of reference items for which to search. These could be strings (i.e. names of sets, surfaces, etc.) or integers (i.e. node labels).
- Returns:
csid
- findKeyword(keywordName='', parameters=None, excludeParameters=None, data='', mode='all', printOutput=True, parentBlock='')¶
Finds keyword blocks in
keywordsusing multiple criteria.This function uses a system of filters to find keyword blocks. It will first create a list of potential blocks by getting blocks that match keywordName. It will then try to match using parameters, and finally data. If one of keywordName, parameters, or data are not specified, they will not be used to filter the search. For example, if we call
inp.findKeyword(keywordName='BOUNDARY'), this will return all *BOUNDARY keyword blocks. If we callinp.findKeyword(keywordName='BOUNDARY', parameters='AMPLITUDE=amp1')this will return the *BOUNDARY keyword blocks that include ‘AMPLITUDE=amp1’ as a parameter.All inputs to this function are case-insensitive.
keywordName can be a string or a list of strings indicating for which keywords to search. Potential blocks will be taken from matching entries in
kwginstead of looping through every block inkeywordsto find matches.parameters can be a string, a list, or a dictionary of parameters for which to look. The parameters may or may not include values. Specifying parameters as a string will be the simplest option for the user. This function will convert parameters to a parameter
csidif it is not already one.excludeParameters can be a string, a list, or a dictionary of parameters. A keyword block must not include a parameter in excludeParameters for
findKeyword()to match the keyword block. The parameters may or may not include values. Specifying excludeParameters as a string will be the simplest option for the user. This function will convert excludeParameters to a parametercsidif it is not already one.data should be a string for which the entirety of the data for the keyword block will be searched, or it can be a list containing parsed data objects. If data is a list, the matching will be very strict, so it is best to retrieve the list items from the keyword block’s data field directly. Specifying data as a list is primarily intended for cases where you have identified a keyword block of interest, but need to perform an operation that moves the keyword block (such as deleting or inserting keywords) and precisely find the same keyword block in its new location.
mode should specifically be ‘all’ (default), ‘any’, or ‘keyandone’. If mode == ‘all’, only keyword blocks that match every input to this function will be returned. If mode == ‘any’, every keyword block that matches one of the inputs will be returned. If mode == ‘keyandone’, every keyword block that matches keywordName and at least one other input will be returned. mode == ‘all’ will likely be the most useful.
printOutput is a boolean: True (default) or False. If True, the function will print whether it found any keyword blocks matching the input parameters. True is useful if using this function interactively, False is useful if calling this function in batch and you don’t want a lot of printed output.
parentBlock should be a keyword object that will contain suboptions. This function will search for keywords that match the input parameters, but the potential matches are limited to the suboptions of parentBlock. This is very useful for finding a *BOUNDARY in a specific *STEP, for example.
Note
modes ‘any’, and ‘keyandone’ have not been extensively tested with the parentBlock and list of keywordName options, so they might not behave properly.
Warning
Do not use this function if you need to search for many specific keywords in a large keyword group. For example, you should not use this function to search for 100,000 *COUPLING blocks with different surface names. Each time this function is called, it will loop through the list of available keywords searching for the appropriate item. If you have a specific search you need to perform multiple times, you should instead create a
csidusing the item of interest as the key and the block as the value. Example:coupD = csid([ [[block.parameter['surface']], [block]] for block in self.kwg['coupling'] ])Todo
The search for data functionality should be augmented to search for data in specific lines or locations in a line to give fewer false positives.
- Parameters:
keywordName (str or list) – The name(s) of the keyword(s) for which to search. Defaults to ‘’.
parameters (list or str or dict) – The parameters and possibly values for which to search. Users are recommended to use a string, as this will be simplest.
excludeParameters (list or str or dict) – The parameters and possibly values which should not be in keywords (i.e. the block will only match if the other parameters are matched and excludeParameters is not matched). Users are recommended to use a string, as this will be simplest.
data (str or list) – A string or list for which to search in any potential block’s data.
mode (str) – Indicates the matching mode. Can be one of ‘all’, ‘any’, or ‘keyandone’. Defaults to ‘all’
printOutput (bool) – Indicates if this function should print out a summary (i.e. how many keyword blocks matched the given criteria). Defaults to True.
parentBlock (inpKeyword) – If parentBlock is specified, the search will be restricted to
suboptionsof parentBlock.
- Returns:
A list of all matching
inpKeywordblocks.- Return type:
- findKeywordsIgnoreParam(kwNameGroup)¶
Searches
kwgfor the keywords in kwNameGroup, and returns the keyword groups it finds.- Parameters:
kwNameGroup (list) – A sequence of strings designating the keyword names of interest.
- Returns:
This returns a list of
keyword groupsas specified by “kwNameGroup”.- Return type:
- findStepLocations()¶
Creates objects
stepsandstep_paths.If a step does not set the “name”
parameter, the key for the step will be its index inkwg['STEP'].This function is called by
updateInp().
- findValidParentKW(child)¶
Prints the keyword names that can be parent blocks for child.
This function searches through all subkeywords for every parent keyword in
_subBlockKWs._subBlockKWsgives you the valid child keywords for a given parent keyword; this function finds the valid parent keywords for a given child keyword.- Parameters:
child (str) – The keyword name for which the valid keyword block
- getParentBlock(item, parentKWName='', _level=1)¶
Retrieves the parent block for item.
This function will find the parent keyword block for item. If parentKWName is specified, the function will keep searching up the
pathof item until it finds parentKWName.- Parameters:
item (inpKeyword, str, list, or tuple) – If item is a string, it must be of the form in
path. Example:'self.keywords[0].suboptions[1]'. If item is a list or tuple, it must be of the form of the seq parameter described increatePathFromSequence().parentKWName (str) – Must correspond to a valid Abaqus keyword. Case- and space-insensitive.
_level (int) – Indicates how many times to split
item.path. Should only be specified by this function.
- Returns:
If a parent block is found that matches the input parameters, an
inpKeywordis returned. Otherwise, this function returns None.- Return type:
inpKeyword or None
- _findActiveSystem()¶
module: _inpFind.py
Finds which *SYSTEM is active at all points in the .inp
Warning
THIS FUNCTION HAS NOT BEEN TESTED WITH THE inpRW MODULE. IT NEEDS TO BE REWORKED BEFORE IT SHOULD BE USED.
- findCloseNodes(nodeGroup1=None, nodeGroup2=None, searchDist=1e-06, _sliceStart=1)¶
This function searches for nodes that are within searchDist of each other. It will generate a cKDTree from
scipy.spatial, and the function will return a dictionary using the pairs of nodes which fall withing searchDist as the key-value pairs.nodeGroup1 must be a
TotalMeshorMeshinstance. In most cases the user should usend, which will contain all nodes in the input file.The nodes in nodeGroup1 will be used to generate a
cKDTree, which will be stored to_tree. If_treealready exists and nodeGroup1 contains the same number of entities as_tree, the existing tree will be used. ThecKDTreeallows for quick nearest-neighbor lookups.nodeGroup2 can be specified as a
MeshorTotalMeshinstance. These nodes are the source nodes for which this function will search for close nodes from nodeGroup1. If nodeGroup2 is not specified, it will be identical to nodeGroup1. nodeGroup2 can be a subset of *nodeGroup1; this function will automatically filter out nodes which are only close to themselves. A node from nodeGroup1 will be considered close to a node from nodeGroup2 if it falls within searchDist of the nodeGroup2 node. The search is performed usingquery_ball_point(), with nodeGroup2 being passed to the “x” parameter and searchDist being passed to the “r” parameter.Not specifying nodeGroup2 will thus look for close nodes over the entire mesh. If the user has an idea of where to find close nodes (i.e. a particular node set), then nodeGroup2 should be specified to reduce the number of locations this function needs to check.
searchDist should be a small float. This defaults to 1e-6.
_sliceStart = 1 will remove the 0th data column (i.e. remove the node labels). It should not be changed in most cases as this functions is written specifically to operate on information stored in
MeshorTotalMeshinstances.The output dictionary will be key-value pairs of node labels. There will strictly be one value for each key. If nodeGroup2 is specified, the values of this dictionary will be node labels from nodeGroup2, and the keys will be node labels from nodeGroup1 which are close to each node from nodeGroup2. For example, let’s say we have three nodes (1, 2, and 3) which are within searchDist of each other (and many other nodes in the mesh), and we want to search for the nodes which are close to node 3. The output of this function would look like the following:
{1: 3, 2: 3}
If nodeGroup2 is not specified, the lower node label will always be the value.
- Parameters:
nodeGroup1 (Mesh or TotalMesh) – nodeGroup1 defines the search domain. In most cases, it should include every node in the input file. Defaults to
nd, which will include every node.nodeGroup2 (Mesh or TotalMesh) – nodeGroup2 defines the nodes for which close nodes should be found If nodeGroup2 is specified, the each value in the output dictionary will be a node label from nodeGroup2. Defaults to
nd.searchDist (float) – The distance which defines close nodes. Defaults to 1e-6.
_sliceStart (int) – Used to specify the “column” in a list where the nodal coordinates begin. Since the datalines for a node begin with the node label before the coordinates, _sliceStart defaults to 1. Since this function needs to operate on
MeshorTotalMeshobjects, this argument should be left at the default of 1.
- Returns:
- This dictionary will always contain a 1:1 mapping of nodelabels which fall within searchDist
of each other. If nodeGroup2 is specified, a nodelabel from nodeGroup2 will always be the value, otherwise the lower nodelabel will be the value.
- Return type:
- _findData(labelD, kwNames=None, parameters=None, excludeParameters=None, mode='all', data_pos='', linesToCheck='', custom='', dataOffset=None, dataStep=None, lineOffset=None, lineStep=None, dataGroup='line', kwBlocks=None)¶
This function will search for references to the keys in labelD in the locations specified by the rest of the parameters to this function. It is meant to be called from one of the functions in
FindRefs.If kwBlocks is specified,
_findData()will check the locations indicated by any combination of data_pos, linesToCheck, custom, dataOffset, dataStep, lineOffset, and lineStep for items which are in labelD. If any location matches an item in labelD, the item in labelD will be updated with the path to the location, along with the region of the keyword block the item affects (specified by dataGroup). If kwBlocks is not specified, kwNames must be specified, andfindKeyword()will be called with arguments kwNames, parameters, excludeParameters, and mode. The function will then run as before, but using the resulting keyword blocks fromfindKeyword()instead of those specified by kwBlocks.When using kwNames, this function will find the
inpKeywordblocks to search using this command:`list(flatten([j for j in self.findKeyword(keywordName=kwNames, parameters=parameters, excludeParameters=excludeParameters, mode=mode, printOutput=False) if j]))`If this is not sufficient to generate a list of keywords to search, the list should be generated prior to calling_findData()and input using the kwBlocks parameter.- Parameters:
labelD (csid) – A csid of the form
`csid([[name, []] for name in names])`. The items in names can beintegersorstrings, but the function might not work properly if labelD contains both types.kwNames (list) – A sequence containing the keyword names in which to search. Will be passed to
findKeyword(). Defaults to None. Must be specified if kwBlocks is omitted.parameters – See
findKeyword(). Defaults to None.excludeParameters – See
findKeyword(). Defaults to None.mode (str) – See
findKeyword(). Defaults to ‘all’.data_pos (int or str) – Indicates which positions in the dataline to search for a match. Can be an
int, or astr. If astr, can be ‘EVEN’, ‘ODD’, or a string indicating a slicing notation. Defaults to ‘’, which will be converted to ‘[:]’ and check every data position. Works in conjunction with linesToChecklinesToCheck (int or str) – Indicates which datalines to search for a match. Can be an
int, or astr. If astr, can be ‘EVEN’, ‘ODD’, or a string indicating a slicing notation. Defaults to ‘’, which will be converted to ‘[:]’ and check every dataline. Works in conjunction with data_pos.custom (function) – A custom function to determine which locations should be examined for data matching. This is an alternative to data_pos and linesToCheck, and should only be used in the few cases where those options are not sufficient. This function will have access to all the local variables of
_findData(), and needs to be written like it’s a part of_findData(). See function externalFieldCustomSub insidefindElementRefs()for an example.dataOffset (int) – Used to override the value the function will calculate. They are used in this manner with slicing [Offset : : Step]. They should not be used in most cases, as the appropriate values will be calculated from data_pos and linesToCheck, but they are still options for the rare cases the default calculation is incorrect. Defaults to None.
dataStep (int) – Used to override the value the function will calculate. They are used in this manner with slicing [Offset : : Step]. They should not be used in most cases, as the appropriate values will be calculated from data_pos and linesToCheck, but they are still options for the rare cases the default calculation is incorrect. Defaults to None.
lineOffset (int) – Used to override the value the function will calculate. They are used in this manner with slicing [Offset : : Step]. They should not be used in most cases, as the appropriate values will be calculated from data_pos and linesToCheck, but they are still options for the rare cases the default calculation is incorrect. Defaults to None.
lineStep (int) – Used to override the value the function will calculate. They are used in this manner with slicing [Offset : : Step]. They should not be used in most cases, as the appropriate values will be calculated from data_pos and linesToCheck, but they are still options for the rare cases the default calculation is incorrect. Defaults to None.
dataGroup (str) – Must be one of ‘line’, ‘multiline’, ‘alldata’, or ‘subline’. Indicates the region of the keyword associated with the reference (i.e. if the reference is deleted, how much of the keyword block must be deleted to still have a valid keyword). ‘line’ corresponds to the entire data line. ‘multiline’ corresponds to multiple keyword lines as indicated by linesToCheck. ‘alldata’ corresponds to the entirety of
data. ‘subline’ corresponds to a region of the dataline as indicated by data_pos. Defaults to ‘line’.kwBlocks (list) – Each item in kwBlocks must be an
inpKeyword. Defaults to None. One of kwBlocks or kwNames must be specified.
- _findIncludeFileNames()¶
Finds all child input file names in
keywords.This function will search for *INCLUDE, *MANIFEST, and any keywords in
_dataKWsthat have the “input”parameter. It will populateincludeFileNameswith all file names it finds andincludeBlockPathswith thepathsto the blocks that read from child input files.This function is called by
updateInp().
- _findParam(labelD, parameterName, kwNames=None, excludeParameters=None, mode='all', kwBlocks=None)¶
This function will look for keyword blocks that reference items in labelD.
It will search kwBlocks, or it will search the blocks returned by
`findKeyword(keywordName=kwNames, parameters=parameterName, excludeParameters=excludeParameters, mode=mode, printOutput=False `- Parameters:
labelD (csid) – A csid of the form
`csid([[name, []] for name in names])`. The items in names can beintegersorstrings, but the function might not work properly if labelD contains both types.parameterName (str) – A string indicating the parameter name for which to search. This should not include a value. parameterName will be passed to parameters of
findKeyword()if kwBlocks is not specified. If matching keyword blocks are found, the function will check if the value of`block.parameter[parameterName]`is in labelD. If so, labelD[parameterName] will have [{path to parameter}, {path to block}] appended.kwNames (list) – A sequence containing the keyword names in which to search. Will be passed to
findKeyword(). Defaults to None. Must be specified if kwBlocks is omitted.excludeParameters – See
findKeyword(). Defaults to None.mode (str) – See
findKeyword(). Defaults to ‘all’.kwBlocks (list) – Each item in kwBlocks must be an
inpKeyword. Defaults to None. Must be specified if kwNames is omitted.
- _getLastBlockPath(_block='')¶
Sets
_lbpto the path of the last block in the input file.- Parameters:
_block (inpKeyword) – Only meant to be used when this function calls itself to handle blocks with
suboptions.
This function is called by
updateInp().