The basic idea of these classes is, that the file should look identical if written again, except for modifications. Also comments shall be preserved. Please beware in case of parsing the mesh, since the rewritten floating point numbers will deviate in due to the machine precision. To prevent this deviation, just don’t parse the mesh.
Keywordclass is used for all unknown keywords. If the mesh of a
KeyFileis not parsed, then also the mesh keywords are seen as generic keywords. To read all keywords of a
KeyFileis written again, it will look identical, since the class saves everything including the comments.
Example:from qd.cae.dyna import * # open a file (without mesh parsing) kf = KeyFile("path/to/keyfile") # get the third part keyword generic_keyword = kf["*PART"] # set a new pid (searches pid in comment line above card) generic_keyword["pid"] = 100 # save it kf.save("path/to/new_keyfile")
The specific include keyword classes provide means to deal with include files. Includes are loaded automatically, if in the
IncludePathKeywordmanages all locations, where include files could be located, while the
IncludeKeywordis resposible for managing the files.
Example:from qd.cae.dyna import * # open a file kf = KeyFile("path/to/keyfile", load_includes=True) # get first include keyword include_keyword = kf["*INCLUDE"] # get the include(s) of the keyword includes = include_keyword.get_includes() # or get all loaded includes at once includes = kf.get_includes()
All the keywords of the includes are not accessible from the main
KeyFile, but only from the include
KeyFile, which can be retrieved by
The mesh pecific Keywords:
are only created, if opening a
KeyFilewith the argument
parse_meshenabled. If the mesh is not parsed, their data is seen as a generic
Examplefrom qd.cae.dyna import * # load a file kf = KeyFile("path/to/keyfile", parse_mesh=True, load_includes=True) # get first node keyword node_keyword = kf["*NODE"] # add a node node_keyword.add_node(6728, x=1, y=2, z=3) # and save again kf.save("path/to/new_keyfile")
If parsing the mesh, all keywords except for the
PartKeywordstop parsing if they encounter a comment or empty line in the data block (e.g. between two elements or nodes)
Mesh entities, such as nodes can be created, but not deleted. Also the mesh keywords itself can not be deleted.