Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an interface for GENEC #1023

Draft
wants to merge 96 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
37b7d12
Add initial interface for GENEC
rieder Jan 25, 2022
74d2cf9
updates
rieder Jan 25, 2022
47c76cd
Merge branch 'main' into add_genec
rieder Jan 25, 2022
60bab5e
updates to GENEC interface
rieder Feb 4, 2022
9ca06ba
add more methods
rieder Feb 8, 2022
200d422
Merge branch 'amusecode:main' into add_genec
rieder Feb 8, 2022
9dccb91
add firstlast functions
rieder Feb 24, 2022
3ef03db
small fix
rieder Mar 7, 2022
047effe
Add setters/getters for input parameters
rieder Mar 7, 2022
0715e51
Add setters
rieder Mar 7, 2022
12ba3c7
Add parameter setters/getters
rieder Mar 7, 2022
b4cfd70
remove methods already defined in se.py, add others
rieder Mar 7, 2022
79e755b
remove setters/getters for 'amuseinterface'
rieder Mar 7, 2022
4894605
Also support polytropic index
rieder Mar 7, 2022
6f31296
work in progress
rieder Mar 8, 2022
0122f30
add unit to vwant
rieder Mar 10, 2022
e5096c2
add test script
rieder Mar 13, 2022
e9b490c
Add script with plotting class
rieder Mar 15, 2022
dd600c1
Merge branch 'main' into add_genec
rieder Mar 15, 2022
2b72e7e
Start work on stellar structure plots
rieder Mar 16, 2022
7b0a69f
update test script
rieder Mar 16, 2022
2ecf15c
use mass profile, not radius profile
rieder Mar 16, 2022
3bd7173
changes
rieder Mar 24, 2022
60d7e13
fix error
rieder Mar 24, 2022
95d8688
one more fix
rieder Mar 24, 2022
cf93d5a
disable for now
rieder Mar 24, 2022
ccd573e
save star to a single file
rieder Mar 25, 2022
b9e61a9
Interface updates - now also store abundances in the star particle
rieder Mar 25, 2022
93c3644
store phase in plotting
rieder Mar 25, 2022
3cb494c
WIP
rieder Mar 25, 2022
152be90
Support HDF5 compression of AMUSE files
rieder Mar 25, 2022
ebb54c5
Merge branch 'feature/hdf5_compression' into add_genec
rieder Mar 25, 2022
9afb216
updates
rieder Mar 25, 2022
fbf5be7
add test for compressed AMUSE file (v 2.0 only)
rieder Mar 25, 2022
8c5be7c
Merge branch 'feature/hdf5_compression' into add_genec
rieder Mar 25, 2022
7f9e978
Add getters/setters
rieder Mar 30, 2022
8c3badb
Updates to test script (WIP)
rieder Mar 30, 2022
51009d0
interface updates
rieder Apr 11, 2022
bad2417
Merge commit '880bed106eb3a23b5bf1bebf83cb98f377122f02' into add_genec
rieder Apr 11, 2022
e6e7464
updates
rieder May 12, 2022
c43ffe1
Merge commit 'b81504ffa12fced1b94e0014df8610a1d363c10f' into add_genec
rieder May 12, 2022
4c4ef8c
Merge branch 'main' into add_genec
rieder Jun 14, 2022
24e5dc8
Merge branch 'main' into add_genec
rieder Oct 5, 2022
23a42f3
small update to Makefile
rieder Oct 31, 2022
30f57cf
interface updates
rieder Oct 31, 2022
9906e60
update test script
rieder Oct 31, 2022
9233cbe
simplify Makefile for GENEC (wip)
rieder Oct 31, 2022
45b5d42
small update (wip)
rieder Oct 31, 2022
11b7f43
fix plotting bug
rieder Nov 8, 2022
cbcb3e1
Merge remote-tracking branch 'origin/main' into add_genec
rieder Nov 22, 2022
57af834
Updates to AMUSE-Genec
rieder Nov 24, 2022
c6ff309
Interface updates
rieder Dec 6, 2022
77e25fe
Interface updates
rieder Dec 14, 2022
e5c7f76
Test script updates
rieder Dec 14, 2022
ff0e835
Merge commit '3532374b58925106811d027612a150c3ff244841' into add_genec
rieder Dec 14, 2022
e3c8215
cleanup
rieder Dec 14, 2022
f279635
updates
rieder Dec 20, 2022
a1346a9
Updates to plots (add some energies, fix some bugs)
rieder Dec 20, 2022
724403e
add remaining eps
rieder Dec 20, 2022
807ac2e
plotting updates
rieder Dec 20, 2022
5927b73
Revamping the interface
rieder Jan 10, 2023
99574c5
More updates / cleanup. Also add helper script for the interface.
rieder Jan 10, 2023
424e5c3
newer interface version
rieder Feb 2, 2023
231a0ec
rename file
rieder Feb 15, 2023
f34eaac
Merge remote-tracking branch 'origin/main' into add_genec
rieder Mar 7, 2023
afd28e4
Merge remote-tracking branch 'origin/main' into add_genec
rieder Mar 7, 2023
4d6acfe
Merge remote-tracking branch 'origin/main' into add_genec
rieder Mar 14, 2023
e37e11d
Merge commit 'aa14f8bf8a4bc865fe997e974096f76e5a2fa653' into add_genec
rieder Mar 22, 2023
4436f16
Merge branch 'main' into add_genec
rieder May 22, 2023
3365e1e
Merge branch 'amusecode:main' into add_genec
rieder May 30, 2023
167baf3
updates
rieder May 30, 2023
cf324dc
updates
rieder May 30, 2023
b1ef506
updates
rieder May 30, 2023
1cd5107
Merge commit '3365e1e24bab105ec1e670cf9b72f94f07d4fec4' into add_genec
rieder May 30, 2023
acaceaf
take vwant into account for new stars
rieder Jun 1, 2023
4538aa7
fix: store zabelx/nbelx
rieder Jun 5, 2023
87da6d1
important updates
rieder Jun 5, 2023
bb4148d
Merge commit 'acaceaf552d7782b5d31f96b7f71ed4c75ce840f' into add_genec
rieder Jun 5, 2023
af6ccc9
fix bug that would lead to Nan values if nbael was 0
rieder Jun 7, 2023
f88fb36
better recommit_particles
rieder Jun 7, 2023
1b784ff
few updates, now giving stars the right number of shells
rieder Jun 9, 2023
4bf4da1
Updates to (mostly) units used
rieder Jun 9, 2023
ff92106
Updates: add setters, rename parameters/methods
rieder Jun 12, 2023
71bb237
Updates
rieder Jun 14, 2023
1746fe9
fix for changing initial parameters of the star
rieder Jun 19, 2023
8351231
more updates!
rieder Jun 19, 2023
77881a3
fixes for state model
rieder Jun 19, 2023
8f42344
updates for clarity
rieder Jun 19, 2023
ea50c34
updates
rieder Jun 27, 2023
596ea32
small updates
rieder Sep 19, 2023
2939cea
Merge branch 'add_genec' of github.com:rieder/amuse into add_genec
rieder Sep 22, 2023
210fdad
Merge branch 'amusecode:main' into add_genec
rieder Sep 25, 2023
759541b
Merge branch 'add_genec' of github.com:rieder/amuse into add_genec
rieder Sep 25, 2023
5142a77
fix typo
rieder Sep 25, 2023
43e02a7
Merge branch 'amusecode:main' into add_genec
rieder Dec 14, 2023
eb6082e
Merge branch 'main' into add_genec
rieder Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
671 changes: 671 additions & 0 deletions examples/code_examples/genec/plot_models.py

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions examples/code_examples/genec/test_integrate_default_star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
import sys
import numpy
import time

from amuse.datamodel import Particle
from amuse.units import units
from amuse.community.genec import Genec
from amuse.io import write_set_to_file, read_set_from_file
from amuse.support.console import set_printing_strategy

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from plot_models import StellarModelPlot

from amuse.community.genec.interface import SPECIES_NAMES
import logging

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s: %(message)s',
datefmt='%Y%m%d %H:%M:%S'
)
logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)


class NeedToSave:
def __init__(self):
self.model = 0
self.current = {
'luminosity': 0 | units.LSun,
'temperature': 0 | units.K,
'central_temperature': 0 | units.K,
'central_density': 0 | units.g * units.cm**-3,
'surface_velocity': 0 | units.kms,
'mass': 0 | units.MSun,
'time_step': 0 | units.s,
}
for species in SPECIES_NAMES.keys():
self.current[species] = []
self.previous = self.current.copy()
self.derivs = {}
for key in self.current.keys():
self.derivs[key] = 1
return

def get_values(self):
return self.current

@property
def save_next(self):
return True

def update(self, star):
self.previous = self.current.copy()
for key in self.current.keys():
self.current[key] = getattr(star, key)


def read_saved_star_timeline(star_key):
star = read_set_from_file(f'star-{star_key}.amuse')[0]
age, radius = star.get_timeline_of_attribute_as_vector('radius')
print(age.in_(units.yr))
print(radius.in_(units.RSun))
return star


def write_backup(
step,
star,
abundances,
append=True,
):
# GENEC reads the following on a restore/resume:
# gms,alter,gls,teff,glsv,teffv,dzeitj,dzeit,dzeitv,xmini,ab,dm_lost,m,(q(i),p(i),t(i),r(i),s(i),x(i),y(i),&
# xc12(i),vp(i),vt(i),vr(i),vs(i),xo16(i),vx(i),vy(i),vxc12(i),vxo16(i),i=1,m),drl,drte,dk,drp,drt,drr,rlp,&
# rlt,rlc,rrp,rrt,rrc,rtp,rtt,rtc,tdiff,vsuminenv,(CorrOmega(i),i=1,npondcouche),xLtotbeg,dlelexprev,&
# zams_radius
#
# read (51) (y3(i),xc13(i),xn14(i),xn15(i),xo17(i),xo18(i),vy3(i),vxc13(i),vxn14(i),vxn15(i),vxo17(i),vxo18(i),xne20(i), &
# xne22(i),xmg24(i),xmg25(i),xmg26(i),vxne20(i),vxne22(i),vxmg24(i),vxmg25(i),vxmg26(i),omegi(i),vomegi(i),i=1,m)
#
# read(51) (xf19(i),xne21(i),xna23(i),xal26(i),xal27(i),xsi28(i),vxf19(i),vxne21(i),vxna23(i),vxal26g(i),vxal27(i), &
# vxsi28(i),xneut(i),xprot(i),xc14(i),xf18(i),xbid(i),xbid1(i),vxneut(i),vxprot(i),vxc14(i),vxf18(i),vxbid(i), &
# vxbid1(i),i=1,m)

# do ii=1,nbelx
# read(51) (abelx(ii,i),vabelx(ii,i),i=1,m)
# enddo
#
# if (isugi >= 1) then
# read(51) nsugi
# endif
#
# if (bintide) then
# read(51) period,r_core,vna,vnr
# endif

if append:
filename = f'star-{star.key}.amuse'
else:
filename = f'star-{star.key}-{step}.amuse'
write_set_to_file(
star.as_set(),
filename,
timestamp=star.age if append else None,
append_to_file=append,
compression=True,
)

# For now, abundances aren't part of the single star particle
# numpy.savez_compressed(
# f'star-abundances-{star.key}-{step}.npz',
# abundances=abundances,
# )
return

MASS_UNIT = units.MSun
LENGTH_UNIT = units.RSun
SPEED_UNIT = units.kms
TIME_UNIT = units.Myr
MASSLOSS_UNIT = units.MSun / units.yr
TEMPERATURE_UNIT = units.K
LUMINOSITY_UNIT = units.LSun
SPEEDUP_UNIT = units.Myr / units.minute
set_printing_strategy(
"custom",
preferred_units=[
MASS_UNIT, LENGTH_UNIT, TIME_UNIT, SPEED_UNIT, MASSLOSS_UNIT,
TEMPERATURE_UNIT, LUMINOSITY_UNIT, SPEEDUP_UNIT
],
precision=6,
prefix="",
separator=" ",
# separator=" [",
suffix="",
# suffix="]",
)

star_difficult = Particle(
mass=60 | units.MSun,
metallicity=0.014,
)

if len(sys.argv) > 1:
star = read_saved_star_timeline(sys.argv[1])
else:
star = Particle(
mass=7.0 | units.MSun,
metallicity=0.014,
starname="AmuseStar",
zams_velocity=0.,
)
# evo = Genec(redirection="none")
# evo = Genec()
evo = Genec(redirection="file", redirect_file="genec_worker.log")

# NOTE: this will now reset parameters...
star_in_evo = evo.particles.add_particle(star)

font = {
'size': 8,
}
plt.rc('font', **font)
# iplt.switch_backend('macosx')
plt.ion()

save_every = 10
store_every = 1
plot_time = 10 | units.s
plot_models = 1
step = 0

model_of_last_save = 0
model_of_last_plot = 0
time_start = time.time() | units.s
time_of_last_plot = 0 | units.s
age_of_last_plot = star_in_evo.age

# plotting = None
plotting = StellarModelPlot(star_in_evo)

# evo.parameters.nzmod = 100

print("age mass radius temp lum phase vequat h0 vwant xcn")
while True:
time_elapsed = (time.time() | units.s) - time_start
star = star_in_evo.copy()
# number_of_zones = star_in_evo.get_number_of_zones()
# density_profile = star_in_evo.get_density_profile()
# radius_profile = star_in_evo.get_radius_profile()
# temperature_profile = star_in_evo.get_temperature_profile()
# luminosity_profile = star_in_evo.get_luminosity_profile()
# pressure_profile = star_in_evo.get_pressure_profile()
chemical_abundance_profile = star_in_evo.get_chemical_abundance_profiles()

# print(evo.particles[0])
# print(evo.particles[0].get_number_of_species())
# print(evo.particles[0].get_names_of_species())
# print(evo.particles[0].get_mass_profile())
# exit()
print(
star.age.in_(units.Myr),
star.mass.in_(units.MSun),
star.radius.in_(units.RSun),
star.temperature.in_(units.K),
star.luminosity.in_(units.LSun),
star.surface_velocity,
)
print(f"step: {step} time: {star.age} timestep: {star.time_step}")
if (step % store_every == 0) and plotting is not None:
plotting.update(star_in_evo)
if (
(time_elapsed - time_of_last_plot) > plot_time
or step - model_of_last_plot > plot_models
):
speed = (
(star.age - age_of_last_plot).value_in(units.Myr)
/ (time_elapsed - time_of_last_plot).value_in(units.minute)
) | units.Myr / units.minute
plotting.plot_all(speed=speed, step=step)
model_of_last_plot = step
time_of_last_plot = time_elapsed
age_of_last_plot = star.age

if step % save_every == 0:
write_backup(
step,
star,
# density_profile,
# radius_profile,
# temperature_profile,
# luminosity_profile,
# pressure_profile,
chemical_abundance_profile,
)

age_previous = star_in_evo.age
star_in_evo.evolve_one_step()
# print(f"Condition: {evo.parameters.stopping_condition}")
# if evo.parameters.stopping_condition != "none":
# # star_in_evo.age == age_previous:
# if step > 1:
# print("Stopping - not evolving!")
# print(f"Condition: {evo.parameters.stopping_condition}")
# break
step += 1

runtime = (time.time() | units.s) - time_start
print(
f"Running {step} models took {runtime.value_in(units.minute)} minutes"
)
Loading
Loading