diff --git a/README b/README new file mode 100644 index 0000000000000000000000000000000000000000..4cb9fdfb8e46e71cebb31aff1b97db3b923ae2ee --- /dev/null +++ b/README @@ -0,0 +1,65 @@ +Welcome to PySWIFTsim +===================== + +This code is a python wrapper around the cosmological hydrodynamical code SWIFT hosted at https://gitlab.cosma.dur.ac.uk/swift/swiftsim. + + +A few examples are given in test and the API is trying to follow the SWIFT API, therefore a developer of SWIFT should be able to quickly learn how to use it. + + +Adding a new structure +====================== + +In pyswiftsim/structure.py, a list of all SWIFT structure are described in python. +When adding a new structure, a new class should be added to this file using the following example: + +``` +class SwiftParams(SwiftStruct): + """ All object should inherit from SwiftStruct """ + _format = "{sec}s{data}sii{line_size}c".format( + sec=struct.calcsize(Section._format)*PARSER_MAX_NO_OF_SECTIONS, + data=struct.calcsize(Parameter._format)*PARSER_MAX_NO_OF_PARAMS, + line_size=PARSER_MAX_LINE_SIZE + ) + """ _format describes the type of the object contained in a C structure. + see struct python package for a list of all possible types. + For an undefined/complex object, the letter 's' is used and for string 'c'. + """ + + _name = [ + "section", + "data_params", + "sectionCount", + "paramCount", + "filename" + ] + """ _name defines the name of each variable """ + + def __init__(self, data, parent=None): + """ defines the constructor + data is a list of bytes and parent is the structure in which this one is included + """ + super().__init__(self.struct_format, data, parent) + + @property + def struct_substruct(self): + """ This method should be defined if a substructure is present in this one. + It returns a dictionary where the key is the name of the object (defined in _name) + and the value is the array size (1 if this structure is not in an array). + """ + sec = { + "class": Section, + "size": PARSER_MAX_NO_OF_SECTIONS + } + + param = { + "class": Parameter, + "size": PARSER_MAX_NO_OF_PARAMS + } + return { + "section": sec, + "data_params": param + } +``` + +If the new structure is an option (e.g. Part, Cooling, ...) you can use an if to define the _format and _name variables. \ No newline at end of file