Skip to content
Snippets Groups Projects
Commit 2204383a authored by lhausamm's avatar lhausamm
Browse files

Update grackle structures

parent ba5cfb0b
No related branches found
No related tags found
1 merge request!4Add cooling rate example
from pyswiftsim import wrapper
import struct
import numpy
from ctypes import *
PARSER_MAX_LINE_SIZE = 256
PARSER_MAX_NO_OF_PARAMS = 256
PARSER_MAX_NO_OF_SECTIONS = 64
######################################################################
# #
# SwiftStruct #
......@@ -71,7 +71,6 @@ class SwiftStruct(struct.Struct):
"""
return {}
def _getInfoFromName(self, name):
"""
Compute index, format and size from an attribute name.
......@@ -105,7 +104,6 @@ class SwiftStruct(struct.Struct):
return i, form, n
@property
def struct_size_format(self):
"""
......@@ -147,7 +145,6 @@ class SwiftStruct(struct.Struct):
return out_nber, out_form
def __str__(self, tab=""):
txt = tab + "%s:\n" % type(self)
for name in self.struct_name:
......@@ -198,7 +195,6 @@ class SwiftStruct(struct.Struct):
data = struct.pack(nform, *data)
return ArrayStruct(nform, data, self, name)
def __setattr__(self, name, value):
# case where the attribute is not in the structure
if name not in self.struct_name:
......@@ -255,7 +251,6 @@ class ArrayStruct(SwiftStruct):
data = self._clean(data)
return tab + str(data) + "\n"
def getArray(self):
return self.unpack(self.data)
......@@ -297,6 +292,7 @@ class ChemistryPartData(SwiftStruct):
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
######################################################################
# #
# Part #
......@@ -343,10 +339,10 @@ class Parameter(SwiftStruct):
"value"
]
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
######################################################################
# #
# Section #
......@@ -363,6 +359,7 @@ class Section(SwiftStruct):
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
######################################################################
# #
# SwiftParams #
......@@ -402,6 +399,7 @@ class SwiftParams(SwiftStruct):
"data_params": param
}
######################################################################
# #
# PhysConst #
......@@ -428,7 +426,6 @@ class PhysConst(SwiftStruct):
"const_earth_mass",
]
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
......@@ -451,6 +448,7 @@ class GrackleCodeUnits(SwiftStruct):
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
class GrackleChemistryData(SwiftStruct):
cooling_type = wrapper.configGetCooling()
_format = "iiiiiPidiidiiiiiiidddiiddiddiiddddddiiiiii"
......@@ -504,6 +502,7 @@ class GrackleChemistryData(SwiftStruct):
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
class CoolingFunctionData(SwiftStruct):
cooling_type = wrapper.configGetCooling()
if cooling_type == "const_lambda":
......@@ -515,12 +514,8 @@ class CoolingFunctionData(SwiftStruct):
"min_energy",
"cooling_tstep_mult"
]
elif cooling_type in ["grackle_double", "grackle_float"]:
if cooling_type == "grackle_double":
_format = "200cidd"
else:
_format = "200ciff"
_format += "{code_units}s{chemistry}s".format(
elif "grackle" in cooling_type:
_format = "200cidd{code_units}s{chemistry}s".format(
code_units=struct.calcsize(GrackleCodeUnits._format),
chemistry=struct.calcsize(GrackleChemistryData._format)
)
......@@ -553,6 +548,5 @@ class CoolingFunctionData(SwiftStruct):
raise ValueError(
"Cooling Type %s not implemented" % cooling_type)
def __init__(self, data, parent=None):
super().__init__(self.struct_format, data, parent)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment