Skip to content

Instantly share code, notes, and snippets.

@lzkelley
Last active March 27, 2019 21:29
Show Gist options
  • Save lzkelley/66fe50b8dcabd0c67e42026c7ddaadc7 to your computer and use it in GitHub Desktop.
Save lzkelley/66fe50b8dcabd0c67e42026c7ddaadc7 to your computer and use it in GitHub Desktop.
Highly schematic pseudo-code showing thoughts on how to structure the evolution class and subclasses. This *very much* does not accurately reflect the existing structure of the code, but is just meant to convey the basic idea.
EVOLVE_ACCRETION_FLAG = True
def main():
mbhb, sets = run_init()
# ... do some check and logging and whatever ...
if EVOLVE_ACCRETION_FLAG:
evol = Evolution_Accretion()
else:
evol = Evolution()
# Run the exact same methods regardless of which class we're using
evol.evolve()
analysis.analyze(evol)
plotting.plot_stuff(evol)
# ...Save data...
return
class Evolution:
def __init__(self):
# sets up all of the internal parameters of the class
# ...
return
def evolve(self):
# Sets up lots of variables
# Runs lots of functions
# Evolves the binaries
self.evolve_a()
self.evolve_b()
# ...
return
def evolve_a(self):
# Does component 'a' of the evolution calculation
# ...
return
def evolve_b(self):
# Does component 'b' of the evolution calculation
# ...
return
class Evolution_Accretion(Evolution):
# This defines `Evolution_Accretion` as a subclass of `Evolution`, which means that by default
# it 'inherits' all of the functions and behaviors from `Evolution`, unless (or until) they are 'overridden'
def __init__(self):
# Call the 'parent' initialization method (i.e. this runs everything in `Evolution.__init__`)
super().__init__(self)
# Now add additional initialization behaviors (possibly changing what was already done in the super().__init__
# ...
# Run additional intialization methods
# ...
return
def evolve_a(self):
# Run the parent `evolve_a` method
super().evolve_a()
# Add additional behavior
# ...
return
def evolve_b(self):
# do *not* run the parent behavior (i.e. no call to `super().evolve_b()`), do completely different things
mdot_pf = self.accretion_partition_function()
# Evolve the masses
self.masses[STEP+1, :] = self.masses[STEP, :] + mdot_pf * DELTA_TIME
return
def accretion_partition_function(self):
# totally new function that's not in the parent class
# do stuff ...
# ...
# calculate mdot ...
return mdot
if __name___ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment