Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 13 additions & 10 deletions src/tdhf/methods/tdhf/td_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tdhf.methods.shared.data import DataHandler
from tdhf.methods.shared.progress import generate_progress_bar_object, fmt_compact2
from tdhf.methods.shared.results import SimulationResults
from tdhf.modules.propagators import RungeKutta, MagnusSCF
from tdhf.modules.propagators import RungeKutta, AdaptiveTimestepRungeKutta, MagnusSCF

import sys
from tdhf.config.globals import PROJECT_ROOT, AU_TO_FS
Expand Down Expand Up @@ -333,15 +333,12 @@ def td_hf_simulation(ic : InputConfig, absorption_dipole_store_axes: List[str] =
}
match ic.propagation_type:
case "rk":
propagator = RungeKutta(dm_differential_eq_from_EOM, ic.dt, func_kwargs=func_kwargs)
propagator = RungeKutta(dm_differential_eq_from_EOM, ic.dt, t_end, func_kwargs=func_kwargs)
case "adaptive_rk":
"""
propagator = AdaptiveTimestepRungeKutta(dm_differential_eq_from_EOM, \
ic.dt, ic.propagation_safety_factor, ic.min_dt, ic.max_dt, \
ic.propagation_tolerance, ic.propagation_accept, \
ic.propagation_tolerance, t_end, ic.propagation_accept, \
ic.propagation_exponent)
"""
pass
case "magnus":
propagator = MagnusSCF(
hcore=hcore,
Expand All @@ -354,9 +351,9 @@ def td_hf_simulation(ic : InputConfig, absorption_dipole_store_axes: List[str] =
update_fock_func=update_fock
)

propagator.set_initial_condition(dm0, 0)
propagator.set_initial_condition(0, dm0)
# Only RK-based propagators need set_method
if hasattr(propagator, 'set_method'):
if hasattr(propagator, "set_method"):
propagator.set_method(ic.propagation_method)

# for t_idx, t in enumerate(time, description="[cyan]Propagating[/]")): # TODO fix dt issue
Expand All @@ -368,7 +365,10 @@ def td_hf_simulation(ic : InputConfig, absorption_dipole_store_axes: List[str] =
# allocat fock matrix space
runtime_globals.set_variable("fock_matrix", np.zeros_like(hcore, dtype="complex"))

for t_idx, t in enumerate(time):
t = t_start
t_idx = 0
while t < t_end:
t_idx += 1

# UPDATE PROGRESS BAR
if t_idx % update_every == 0:
Expand All @@ -383,7 +383,7 @@ def td_hf_simulation(ic : InputConfig, absorption_dipole_store_axes: List[str] =
dm, t, fock = propagator.advance()
runtime_globals.get_variable("fock_matrix")[:] = fock # update global fock matrix
else:
dm, t = propagator.advance()
dm, t, finished = propagator.advance()
fock = update_fock(
hcore=hcore,
eri_mo=eri_mo,
Expand All @@ -396,6 +396,9 @@ def td_hf_simulation(ic : InputConfig, absorption_dipole_store_axes: List[str] =
)
runtime_globals.get_variable("fock_matrix")[:] = fock # update global fock matrix

if finished:
break

#### SAVE CUBEFILES ####
if ic.save and t_idx % ic.frames_interval == 0:
dm_ao = mo_to_ao_dm(mean_field, dm)
Expand Down
12 changes: 8 additions & 4 deletions src/tdhf/modules/butcher_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

MATH_EPS = 1e-14
class ButcherTableau:
"""
Represents a Butcher tableau storing the coefficients
for runge kutta propagation
"""
def __init__(self, method):
self.method = method

# Access package data file using importlib.resources
butcher_tableaus_yaml = files('tdhf.modules').joinpath('butcher_tableaus.yaml')
with butcher_tableaus_yaml.open('r') as f:
yaml_loader = get_fraction_loader()
butcher_tableaus_yaml = files("tdhf.modules").joinpath("butcher_tableaus.yaml")
with butcher_tableaus_yaml.open("r") as f:
yaml_loader = get_fraction_loader() # necessary to read fractional coefficients
data = yaml.load(f, Loader=yaml_loader)

self.a = data[method]["a"]
self.b = data[method]["b"]
self.c = data[method]["c"]
self.stage = len(self.b)

# for adaptive timestep methods
# For adaptive timestep methods
if "b_hat" in data[method]:
self.b_hat = data[method]["b_hat"]

Expand Down
Loading