Skip to content
Snippets Groups Projects
Commit 8b6936ec authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Update readme

parent 1f792174
No related branches found
No related tags found
1 merge request!7Change clone to fetch
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
......@@ -6,70 +6,11 @@ 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.
You can find a few examples in test and examples and a documentation in docs.
Install
=======
To install PySWIFT, you can run the following command: `python3 setup.py install --with-swift SWIFT_PATH --user`.
The setup script will read all your parameters in the config file of swift, therefore you need to reinstall PySWIFT with each configuration of SWIFT.
You may need to remove the build directory to recompile PySWIFT.
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
You may need to remove the build directory to recompile PySWIFT.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment