Skip to content

Commit d145179

Browse files
committed
truncate loop length to nearest Mm
1 parent 0d3bbd6 commit d145179

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

synthesizAR/interfaces/hydrad/hydrad.py

+31-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Model interface for the HYDrodynamics and RADiation (HYDRAD) code
33
"""
44
import astropy.units as u
5+
import copy
56
import numpy as np
6-
import os
77
import pathlib
88
import pydrad.parse
99

@@ -69,30 +69,51 @@ def __init__(self,
6969
interpolate_to_norm=False):
7070
self.output_dir = pathlib.Path(output_dir)
7171
self.base_config = base_config
72-
self.hydrad_dir = hydrad_dir if hydrad_dir is None else pathlib.Path(hydrad_dir)
72+
self.hydrad_dir = hydrad_dir
7373
self.heating_model = heating_model
7474
self.use_gravity = use_gravity
7575
self.use_magnetic_field = use_magnetic_field
7676
self.use_initial_conditions = use_initial_conditions
7777
self.maximum_chromosphere_ratio = maximum_chromosphere_ratio
7878
self.interpolate_to_norm = interpolate_to_norm
7979

80-
def configure_input(self, loop):
81-
config = self.base_config.copy()
82-
config['general']['loop_length'] = loop.length
83-
config['initial_conditions']['heating_location'] = loop.length / 2.
80+
@property
81+
def hydrad_dir(self):
82+
return self._hydrad_dir
83+
84+
@hydrad_dir.setter
85+
def hydrad_dir(self, value):
86+
if value is not None:
87+
value = pathlib.Path(value)
88+
self._hydrad_dir = value
89+
90+
def _map_strand_to_config_dict(self, loop):
91+
# NOTE: This is a separate function for ease of debugging
92+
config = copy.deepcopy(self.base_config)
93+
# NOTE: Avoids a bug in HYDRAD where seg faults can arise due to inconsistencies between max cell
94+
# widths and minimum number of cells
95+
loop_length = np.round(loop.length.to('Mm'))
96+
config['general']['loop_length'] = loop_length
97+
config['initial_conditions']['heating_location'] = loop_length / 2
8498
if self.maximum_chromosphere_ratio:
8599
config['general']['footpoint_height'] = min(
86-
config['general']['footpoint_height'], self.maximum_chromosphere_ratio * loop.length / 2)
100+
config['general']['footpoint_height'], self.maximum_chromosphere_ratio * loop_length / 2)
87101
if self.use_gravity:
88102
config['general']['poly_fit_gravity'] = self.configure_gravity_fit(loop)
89103
if self.use_magnetic_field:
90104
config['general']['poly_fit_magnetic_field'] = self.configure_magnetic_field_fit(loop)
91105
config = self.heating_model.calculate_event_properties(config, loop)
92-
c = Configure(config)
93-
c.setup_simulation(os.path.join(self.output_dir, loop.name),
106+
return config
107+
108+
def configure_input(self, loop, **kwargs):
109+
# Import here to avoid circular imports
110+
from synthesizAR import log
111+
log.debug(f'Configuring HYDRAD for {loop.name}')
112+
config_dict = self._map_strand_to_config_dict(loop)
113+
c = Configure(config_dict)
114+
c.setup_simulation(self.output_dir / loop.name,
94115
base_path=self.hydrad_dir,
95-
verbose=False)
116+
**kwargs)
96117

97118
def load_results(self, loop):
98119
strand = pydrad.parse.Strand(self.output_dir / loop.name)

0 commit comments

Comments
 (0)