|
2 | 2 | Model interface for the HYDrodynamics and RADiation (HYDRAD) code
|
3 | 3 | """
|
4 | 4 | import astropy.units as u
|
| 5 | +import copy |
5 | 6 | import numpy as np
|
6 |
| -import os |
7 | 7 | import pathlib
|
8 | 8 | import pydrad.parse
|
9 | 9 |
|
@@ -69,30 +69,51 @@ def __init__(self,
|
69 | 69 | interpolate_to_norm=False):
|
70 | 70 | self.output_dir = pathlib.Path(output_dir)
|
71 | 71 | 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 |
73 | 73 | self.heating_model = heating_model
|
74 | 74 | self.use_gravity = use_gravity
|
75 | 75 | self.use_magnetic_field = use_magnetic_field
|
76 | 76 | self.use_initial_conditions = use_initial_conditions
|
77 | 77 | self.maximum_chromosphere_ratio = maximum_chromosphere_ratio
|
78 | 78 | self.interpolate_to_norm = interpolate_to_norm
|
79 | 79 |
|
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 |
84 | 98 | if self.maximum_chromosphere_ratio:
|
85 | 99 | 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) |
87 | 101 | if self.use_gravity:
|
88 | 102 | config['general']['poly_fit_gravity'] = self.configure_gravity_fit(loop)
|
89 | 103 | if self.use_magnetic_field:
|
90 | 104 | config['general']['poly_fit_magnetic_field'] = self.configure_magnetic_field_fit(loop)
|
91 | 105 | 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, |
94 | 115 | base_path=self.hydrad_dir,
|
95 |
| - verbose=False) |
| 116 | + **kwargs) |
96 | 117 |
|
97 | 118 | def load_results(self, loop):
|
98 | 119 | strand = pydrad.parse.Strand(self.output_dir / loop.name)
|
|
0 commit comments