Package: ccxmeshreader
ccxmeshreaderIntroductionUsageSupported Keywords*NODE*ELEMENT*ELSET*INCLUDEApproachLimitationsUnit TestsIntroductionReads a mesh from CalcluliX input (.inp) files.Only supports a limited set of keywords defining the mesh. SeeSupported Keywordsfor details.Usagefromccxmeshreaderimportread_meshmesh=read_mesh('path/to/some.inp')Supported Keywords*NODENodes and their coordinates are parsed and added to the dictionary returned byread_meshin thenode_coordinates_by_numberkey.Thenode_coordinates_by_numberkey contains a dictionary where the key is the node number, and value is the coordinates as a three-element tuple with float values.For example, given the following*NODEdefinition:*NODE, NSET=Nall
1,  1.0, 0.0, 0.1
2,  3.0, 1.0, 2.0
3,  0.9, 5.0, 7.0mesh=read_mesh('example.inp')print(mesh['node_coordinates_by_number']){
    1: (1.0, 0.0, 0.1),
    2: (3.0, 1.0, 2.0),
    3: (0.9, 5.0, 7.0)
}Currently node sets are not supported, and the optionalNSETparameter is ignored.*ELEMENTElements and their associated nodes are parsed and added to the dictionary returned byread_meshin theelement_dict_by_typekey.Theelement_dict_by_typekey contains a dictionary where the key is the element type, and value is another dictionary where the key is the element number,
and value is a list of node numbers associated to the element.For example, given the following*ELEMENTdefinition:*ELEMENT, TYPE=C3D20R, ELSET=Eall
1,  1, 2, 3
2,  4, 5, 6mesh=read_mesh('example.inp')print(mesh['element_dict_by_type']){
    'C3D20R': {
        1: [1, 2, 3]
        2: [4, 5, 6]
    }
}Continuation of data-lines ending with a comma,is supported. For example:*ELEMENT, TYPE=C3D20R, ELSET=Eall
1,  1, 2, 3,
    4, 5, 6
2,  7, 8, 9mesh=read_mesh('example.inp')print(mesh['element_dict_by_type']){
    'C3D20R': {
        1: [1, 2, 3, 4, 5, 6]
        2: [7, 8, 9]
    }
}If theELSETparameter is provided, then the element set will be added to theelement_set_by_namedictionary returned in the mesh ofread_meshwith the corresponding element numbers.For example, from the above*ELEMENTdefinition:mesh=read_mesh('example.inp')print(mesh['element_set_by_name']){
    'Eall': {1, 2}
}*ELSETElement set definitions are parsed and added to the dictionary returned byread_meshin theelement_set_by_namekey.Theelement_set_by_namekey contains a dictionary where the key is the name of the element set, and value is a set of element numbers.For example, given the following*ELEMENTand*ELSETdefinitions:*ELEMENT, TYPE=S4, ELSET=E1
1, 1, 2, 3,
   4, 5, 6
2, 7, 8, 9

*ELSET, ELSET=E2, GENERATE
1, 4

*ELSET,ELSET=E3
E2, 5, 6mesh=read_mesh('example.inp')print(mesh['element_set_by_name']){
    'E1': {1, 2},
    'E2': {1, 2, 3, 4}
    'E3': {1, 2, 3, 4, 5, 6}
}The optionalGENERATEparameter is respected with start, end, and step.*INCLUDEFiles specified by the*INCLUDEkeyword are read, but currently limited to relative file paths, and assumed to be relative to the path passed toread_mesh.Recursive includes (i.e.*INCLUDEstatements in a previously included file) are not yet supported.ApproachThe approach this library takes is to read the.inpfile in awhileloop, line-by-line, until there are no lines left, and collect the nodes and elements that make up the mesh into a dictionary.It does not use an intermediate step of parsing the.inpfile into an abstract syntax tree -- as doing so would be costly and likely involve a parsing library.Thus,ccxmeshreadercan be considered light-weight and performant.LimitationsContinuation of keyword lines is not supported.For example, trying to read the following.inpfile:*ELEMENT, TYPE=C3D20R,
ELSET=Eallraises accxmeshreader.ParserError.Unit TestsUnit tests are included in thetests/directory, and can be ran with the following command:python -m unittest discover tests "*_test.py"