From 6f9549451dd229d443ce32eba59e18dc828c0926 Mon Sep 17 00:00:00 2001 From: Tomas Bylund Date: Sat, 14 May 2016 18:05:51 +0200 Subject: [PATCH 1/8] Added simple counting estimator Added a counting estimator to cmontecarlo closely following the example of increment_j_blue_estimator. Updated the various structures and headerfiles to accomodate this and exposing the result the same way as j_blue is exposed. --- tardis/montecarlo/base.py | 5 ++++- tardis/montecarlo/montecarlo.pyx | 4 ++++ tardis/montecarlo/src/cmontecarlo.c | 12 ++++++++++++ tardis/montecarlo/src/cmontecarlo.h | 4 ++++ tardis/montecarlo/src/storage.h | 1 + tardis/montecarlo/struct.py | 1 + tardis/simulation/base.py | 1 + 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tardis/montecarlo/base.py b/tardis/montecarlo/base.py index 5a9733ef8ad..b8df7602b13 100644 --- a/tardis/montecarlo/base.py +++ b/tardis/montecarlo/base.py @@ -46,6 +46,7 @@ def _initialize_estimator_arrays(self, no_of_shells, tau_sobolev_shape): self.j_estimator = np.zeros(no_of_shells, dtype=np.float64) self.nu_bar_estimator = np.zeros(no_of_shells, dtype=np.float64) self.j_blue_estimator = np.zeros(tau_sobolev_shape) + self.interact_estimator = np.zeros(tau_sobolev_shape) def _initialize_geometry_arrays(self, structure): @@ -134,6 +135,8 @@ def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1): # but python expects (no_of_lines, no_of_shells) self.j_blue_estimator = self.j_blue_estimator.flatten().reshape( self.j_blue_estimator.shape, order='F') + self.interact_estimator = self.interact_estimator.flatten().reshape( + self.interact_estimator.shape, order='F') def legacy_return(self): return (self.output_nu, self.output_energy, @@ -248,4 +251,4 @@ def calculate_f_lambda(self, wavelength): def save_spectra(self, fname): self.spectrum.to_ascii(fname) - self.spectrum_virtual.to_ascii('virtual_' + fname) \ No newline at end of file + self.spectrum_virtual.to_ascii('virtual_' + fname) diff --git a/tardis/montecarlo/montecarlo.pyx b/tardis/montecarlo/montecarlo.pyx index c90d3f68796..21e0b828ecc 100644 --- a/tardis/montecarlo/montecarlo.pyx +++ b/tardis/montecarlo/montecarlo.pyx @@ -50,6 +50,7 @@ cdef extern from "src/cmontecarlo.h": double *continuum_list_nu int_type_t line_lists_tau_sobolevs_nd double *line_lists_j_blues + double *line_lists_interact int_type_t line_lists_j_blues_nd int_type_t no_of_lines int_type_t no_of_edges @@ -156,6 +157,9 @@ cdef initialize_storage_model(model, runner, storage_model_t *storage): storage.line_lists_j_blues = PyArray_DATA( runner.j_blue_estimator) + storage.line_lists_interact = PyArray_DATA( + runner.interact_estimator) + storage.line_interaction_id = runner.get_line_interaction_id( model.tardis_config.plasma.line_interaction_type) diff --git a/tardis/montecarlo/src/cmontecarlo.c b/tardis/montecarlo/src/cmontecarlo.c index ddb701c3dc5..937e8029201 100644 --- a/tardis/montecarlo/src/cmontecarlo.c +++ b/tardis/montecarlo/src/cmontecarlo.c @@ -373,6 +373,17 @@ increment_j_blue_estimator (const rpacket_t * packet, storage_model_t * storage, } } +void +increment_iteract_estimator (const rpacket_t * packet, storage_model_t * storage, + double d_line, int64_t line_idx) +{ + if (storage->line_lists_interact != NULL) + { + storage->line_lists_interact[line_idx] += 1; + } +} + + int64_t montecarlo_one_packet (storage_model_t * storage, rpacket_t * packet, int64_t virtual_mode, rk_state *mt_state) @@ -613,6 +624,7 @@ montecarlo_line_scatter (rpacket_t * packet, storage_model_t * storage, if (rpacket_get_virtual_packet (packet) == 0) { increment_j_blue_estimator (packet, storage, distance, line2d_idx); + increment_iteract_estimator (packet, storage, distance, line2d_idx); } double tau_line = storage->line_lists_tau_sobolevs[line2d_idx]; diff --git a/tardis/montecarlo/src/cmontecarlo.h b/tardis/montecarlo/src/cmontecarlo.h index 014c4558a0c..8a955730ce8 100644 --- a/tardis/montecarlo/src/cmontecarlo.h +++ b/tardis/montecarlo/src/cmontecarlo.h @@ -67,6 +67,10 @@ void increment_j_blue_estimator (const rpacket_t * packet, storage_model_t * storage, double d_line, int64_t j_blue_idx); +void increment_interact_estimator (const rpacket_t * packet, + storage_model_t * storage, + double d_line, int64_t j_blue_idx); + int64_t montecarlo_one_packet (storage_model_t * storage, rpacket_t * packet, int64_t virtual_mode, rk_state *mt_state); diff --git a/tardis/montecarlo/src/storage.h b/tardis/montecarlo/src/storage.h index 2abea5b1f2b..387d10be0e0 100644 --- a/tardis/montecarlo/src/storage.h +++ b/tardis/montecarlo/src/storage.h @@ -31,6 +31,7 @@ typedef struct StorageModel double *line_lists_tau_sobolevs; int64_t line_lists_tau_sobolevs_nd; double *line_lists_j_blues; + double *line_lists_interact; int64_t line_lists_j_blues_nd; int64_t no_of_lines; int64_t no_of_edges; diff --git a/tardis/montecarlo/struct.py b/tardis/montecarlo/struct.py index a68bbfde450..3d9ddf36c6a 100644 --- a/tardis/montecarlo/struct.py +++ b/tardis/montecarlo/struct.py @@ -61,6 +61,7 @@ class StorageModel(Structure): ('line_lists_tau_sobolevs_nd', c_int64), ('line_lists_j_blues', POINTER(c_double)), ('line_lists_j_blues_nd', c_int64), + ('line_lists_interact', POINTER(c_double)), ('no_of_lines', c_int64), ('no_of_edges', c_int64), ('line_interaction_id', c_int64), diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py index 2c349363e77..73077199dad 100644 --- a/tardis/simulation/base.py +++ b/tardis/simulation/base.py @@ -247,6 +247,7 @@ def legacy_run_simulation(self, model): model.ws = next_w model.t_inner = next_t_inner model.j_blue_estimators = self.runner.j_blue_estimator + model.interact_estimators = self.runner.interact_estimator model.calculate_j_blues(init_detailed_j_blues=False) model.update_plasmas(initialize_nlte=False) From 6ff58aade646b35f9f4d0f3d309b25c23a28e7eb Mon Sep 17 00:00:00 2001 From: Tomas Bylund Date: Fri, 17 Jun 2016 15:51:05 +0200 Subject: [PATCH 2/8] Added core of Edotlu estimator to cmontecarlo and the supporting scaffolding --- tardis/montecarlo/base.py | 6 +++--- tardis/montecarlo/montecarlo.pyx | 6 +++--- tardis/montecarlo/src/cmontecarlo.c | 12 +++++++----- tardis/montecarlo/src/cmontecarlo.h | 8 ++++++-- tardis/montecarlo/src/storage.h | 2 +- tardis/montecarlo/struct.py | 2 +- tardis/simulation/base.py | 2 +- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tardis/montecarlo/base.py b/tardis/montecarlo/base.py index b8df7602b13..0cee8acd63a 100644 --- a/tardis/montecarlo/base.py +++ b/tardis/montecarlo/base.py @@ -46,7 +46,7 @@ def _initialize_estimator_arrays(self, no_of_shells, tau_sobolev_shape): self.j_estimator = np.zeros(no_of_shells, dtype=np.float64) self.nu_bar_estimator = np.zeros(no_of_shells, dtype=np.float64) self.j_blue_estimator = np.zeros(tau_sobolev_shape) - self.interact_estimator = np.zeros(tau_sobolev_shape) + self.Edotlu_estimator = np.zeros(tau_sobolev_shape) def _initialize_geometry_arrays(self, structure): @@ -135,8 +135,8 @@ def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1): # but python expects (no_of_lines, no_of_shells) self.j_blue_estimator = self.j_blue_estimator.flatten().reshape( self.j_blue_estimator.shape, order='F') - self.interact_estimator = self.interact_estimator.flatten().reshape( - self.interact_estimator.shape, order='F') + self.Edotlu_estimator = self.Edotlu_estimator.flatten().reshape( + self.Edotlu_estimator.shape, order='F') def legacy_return(self): return (self.output_nu, self.output_energy, diff --git a/tardis/montecarlo/montecarlo.pyx b/tardis/montecarlo/montecarlo.pyx index 21e0b828ecc..2b5d35c756c 100644 --- a/tardis/montecarlo/montecarlo.pyx +++ b/tardis/montecarlo/montecarlo.pyx @@ -50,7 +50,7 @@ cdef extern from "src/cmontecarlo.h": double *continuum_list_nu int_type_t line_lists_tau_sobolevs_nd double *line_lists_j_blues - double *line_lists_interact + double *line_lists_Edotlu int_type_t line_lists_j_blues_nd int_type_t no_of_lines int_type_t no_of_edges @@ -157,8 +157,8 @@ cdef initialize_storage_model(model, runner, storage_model_t *storage): storage.line_lists_j_blues = PyArray_DATA( runner.j_blue_estimator) - storage.line_lists_interact = PyArray_DATA( - runner.interact_estimator) + storage.line_lists_Edotlu = PyArray_DATA( + runner.Edotlu_estimator) storage.line_interaction_id = runner.get_line_interaction_id( model.tardis_config.plasma.line_interaction_type) diff --git a/tardis/montecarlo/src/cmontecarlo.c b/tardis/montecarlo/src/cmontecarlo.c index 937e8029201..8db9c7ef47a 100644 --- a/tardis/montecarlo/src/cmontecarlo.c +++ b/tardis/montecarlo/src/cmontecarlo.c @@ -374,12 +374,14 @@ increment_j_blue_estimator (const rpacket_t * packet, storage_model_t * storage, } void -increment_iteract_estimator (const rpacket_t * packet, storage_model_t * storage, - double d_line, int64_t line_idx) +increment_Edotlu_estimator (const rpacket_t * packet, storage_model_t * storage, int64_t line_idx) { - if (storage->line_lists_interact != NULL) + if (storage->line_lists_Edotlu != NULL) { - storage->line_lists_interact[line_idx] += 1; +#ifdef WITHOPENMP +#pragma omp atomic +#endif + storage->line_lists_Edotlu[line_idx] += rpacket_get_energy (packet); } } @@ -624,7 +626,7 @@ montecarlo_line_scatter (rpacket_t * packet, storage_model_t * storage, if (rpacket_get_virtual_packet (packet) == 0) { increment_j_blue_estimator (packet, storage, distance, line2d_idx); - increment_iteract_estimator (packet, storage, distance, line2d_idx); + increment_Edotlu_estimator (packet, storage, line2d_idx); } double tau_line = storage->line_lists_tau_sobolevs[line2d_idx]; diff --git a/tardis/montecarlo/src/cmontecarlo.h b/tardis/montecarlo/src/cmontecarlo.h index 8a955730ce8..73665eab0b3 100644 --- a/tardis/montecarlo/src/cmontecarlo.h +++ b/tardis/montecarlo/src/cmontecarlo.h @@ -13,6 +13,10 @@ #define LOG_VPACKETS 0 #endif +#define RESONANCE 0 +#define DOWNBRANCH 1 +#define MACROATOM 2 + typedef void (*montecarlo_event_handler_t) (rpacket_t *packet, storage_model_t *storage, double distance, rk_state *mt_state); @@ -67,9 +71,9 @@ void increment_j_blue_estimator (const rpacket_t * packet, storage_model_t * storage, double d_line, int64_t j_blue_idx); -void increment_interact_estimator (const rpacket_t * packet, +void increment_Edotlu_estimator (const rpacket_t * packet, storage_model_t * storage, - double d_line, int64_t j_blue_idx); + int64_t j_blue_idx); int64_t montecarlo_one_packet (storage_model_t * storage, rpacket_t * packet, int64_t virtual_mode, rk_state *mt_state); diff --git a/tardis/montecarlo/src/storage.h b/tardis/montecarlo/src/storage.h index 387d10be0e0..0fdb5602665 100644 --- a/tardis/montecarlo/src/storage.h +++ b/tardis/montecarlo/src/storage.h @@ -31,7 +31,7 @@ typedef struct StorageModel double *line_lists_tau_sobolevs; int64_t line_lists_tau_sobolevs_nd; double *line_lists_j_blues; - double *line_lists_interact; + double *line_lists_Edotlu; int64_t line_lists_j_blues_nd; int64_t no_of_lines; int64_t no_of_edges; diff --git a/tardis/montecarlo/struct.py b/tardis/montecarlo/struct.py index 3d9ddf36c6a..14c964afbb7 100644 --- a/tardis/montecarlo/struct.py +++ b/tardis/montecarlo/struct.py @@ -61,7 +61,7 @@ class StorageModel(Structure): ('line_lists_tau_sobolevs_nd', c_int64), ('line_lists_j_blues', POINTER(c_double)), ('line_lists_j_blues_nd', c_int64), - ('line_lists_interact', POINTER(c_double)), + ('line_lists_Edotlu', POINTER(c_double)), ('no_of_lines', c_int64), ('no_of_edges', c_int64), ('line_interaction_id', c_int64), diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py index 73077199dad..f4e61f17f8f 100644 --- a/tardis/simulation/base.py +++ b/tardis/simulation/base.py @@ -247,7 +247,7 @@ def legacy_run_simulation(self, model): model.ws = next_w model.t_inner = next_t_inner model.j_blue_estimators = self.runner.j_blue_estimator - model.interact_estimators = self.runner.interact_estimator + model.Edotlu_estimators = self.runner.Edotlu_estimator model.calculate_j_blues(init_detailed_j_blues=False) model.update_plasmas(initialize_nlte=False) From 467c23a665f8fbbdeacbf613d396eba508278c29 Mon Sep 17 00:00:00 2001 From: Tomas Bylund Date: Tue, 21 Jun 2016 18:03:24 +0200 Subject: [PATCH 3/8] Defined normalization --- tardis/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tardis/model.py b/tardis/model.py index 0b970aba516..b075050ab38 100644 --- a/tardis/model.py +++ b/tardis/model.py @@ -180,6 +180,9 @@ def t_inner(self, value): (4 * np.pi * self.time_of_simulation * self.tardis_config.structure.volumes)) + self.E_dot_lu_norm_factor = (1 / + (self.time_of_simulation * self.tardis_config.structure.volumes)) + @staticmethod def calculate_geometric_w(r, r_inner): From 733b694dc1f0df30cf4c4283795d343a484abee0 Mon Sep 17 00:00:00 2001 From: Tobychev Date: Thu, 23 Jun 2016 03:50:28 +0200 Subject: [PATCH 4/8] Added postprocessing of Edotlu estimator --- tardis/model.py | 10 ++++++++-- tardis/simulation/base.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tardis/model.py b/tardis/model.py index b075050ab38..8c3763f1991 100644 --- a/tardis/model.py +++ b/tardis/model.py @@ -180,8 +180,6 @@ def t_inner(self, value): (4 * np.pi * self.time_of_simulation * self.tardis_config.structure.volumes)) - self.E_dot_lu_norm_factor = (1 / - (self.time_of_simulation * self.tardis_config.structure.volumes)) @staticmethod @@ -244,3 +242,11 @@ def update_plasmas(self, initialize_nlte=False): 'macroatom'): self.transition_probabilities = ( self.plasma_array.transition_probabilities) + + def postprocess(self): + self.Edotlu_norm_factor = (1 / + (self.time_of_simulation * self.tardis_config.structure.volumes)) + exptau = 1 - np.exp(- + self.runner.line_lists_tau_sobolevs.reshape(-1, + self.tardis_config.structure["velocity"]["num"]) ) + self.Edotlu = self.Edotlu_norm_factor*exptau*self.Edotlu_estimators diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py index f4e61f17f8f..f339092b383 100644 --- a/tardis/simulation/base.py +++ b/tardis/simulation/base.py @@ -247,7 +247,6 @@ def legacy_run_simulation(self, model): model.ws = next_w model.t_inner = next_t_inner model.j_blue_estimators = self.runner.j_blue_estimator - model.Edotlu_estimators = self.runner.Edotlu_estimator model.calculate_j_blues(init_detailed_j_blues=False) model.update_plasmas(initialize_nlte=False) @@ -292,6 +291,9 @@ def legacy_run_simulation(self, model): self.runner.legacy_update_spectrum(no_of_virtual_packets) self.legacy_set_final_model_properties(model) + model.Edotlu_estimators = self.runner.Edotlu_estimator + model.postprocess() + #the following instructions, passing down information to the model are #required for the gui model.no_of_packets = no_of_packets From e0c5a1dcf1ce0d8ac1cf2fb68c0cc47cec1abba9 Mon Sep 17 00:00:00 2001 From: Tobychev Date: Thu, 23 Jun 2016 14:53:41 +0200 Subject: [PATCH 5/8] Moved the postprocessing of the estimator to and added argument to indicate a last run of the monte carlo iteration, updating things as required --- tardis/model.py | 9 +-------- tardis/montecarlo/base.py | 4 ++-- tardis/montecarlo/montecarlo.pyx | 13 ++++++++++++- tardis/simulation/base.py | 8 +++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tardis/model.py b/tardis/model.py index 8c3763f1991..a74b929a57c 100644 --- a/tardis/model.py +++ b/tardis/model.py @@ -119,6 +119,7 @@ def __init__(self, tardis_config): v_outer=tardis_config.structure.v_outer) self.calculate_j_blues(init_detailed_j_blues=True) + self.Edotlu = np.zeros(np.shape(self.j_blues.shape)) self.update_plasmas(initialize_nlte=True) @property @@ -242,11 +243,3 @@ def update_plasmas(self, initialize_nlte=False): 'macroatom'): self.transition_probabilities = ( self.plasma_array.transition_probabilities) - - def postprocess(self): - self.Edotlu_norm_factor = (1 / - (self.time_of_simulation * self.tardis_config.structure.volumes)) - exptau = 1 - np.exp(- - self.runner.line_lists_tau_sobolevs.reshape(-1, - self.tardis_config.structure["velocity"]["num"]) ) - self.Edotlu = self.Edotlu_norm_factor*exptau*self.Edotlu_estimators diff --git a/tardis/montecarlo/base.py b/tardis/montecarlo/base.py index 0cee8acd63a..4274094dde0 100644 --- a/tardis/montecarlo/base.py +++ b/tardis/montecarlo/base.py @@ -106,7 +106,7 @@ def legacy_update_spectrum(self, no_of_virtual_packets): self.spectrum_virtual.update_luminosity( self.montecarlo_virtual_luminosity) - def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1): + def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1,last_run=False): """ Running the TARDIS simulation @@ -129,7 +129,7 @@ def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1): montecarlo.montecarlo_radial1d( model, self, virtual_packet_flag=no_of_virtual_packets, - nthreads=nthreads) + nthreads=nthreads,last_run=last_run) # Workaround so that j_blue_estimator is in the right ordering # They are written as an array of dimension (no_of_shells, no_of_lines) # but python expects (no_of_lines, no_of_shells) diff --git a/tardis/montecarlo/montecarlo.pyx b/tardis/montecarlo/montecarlo.pyx index 2b5d35c756c..f5efaa956c9 100644 --- a/tardis/montecarlo/montecarlo.pyx +++ b/tardis/montecarlo/montecarlo.pyx @@ -222,7 +222,7 @@ cdef initialize_storage_model(model, runner, storage_model_t *storage): storage.t_electrons = t_electrons.data def montecarlo_radial1d(model, runner, int_type_t virtual_packet_flag=0, - int nthreads=4): + int nthreads=4,last_run=False): """ Parameters ---------- @@ -292,3 +292,14 @@ def montecarlo_radial1d(model, runner, int_type_t virtual_packet_flag=0, runner.virt_packet_last_interaction_type = np.zeros(0) runner.virt_packet_last_line_interaction_in_id = np.zeros(0) runner.virt_packet_last_line_interaction_out_id = np.zeros(0) + + if last_run: + postprocess(model,runner) + +def postprocess(model, runner): + Edotlu_norm_factor = (1 / + (model.time_of_simulation * model.tardis_config.structure.volumes)) + exptau = 1 - np.exp(- + runner.line_lists_tau_sobolevs.reshape(-1, + model.tardis_config.structure["velocity"]["num"]) ) + model.Edotlu = Edotlu_norm_factor*exptau*runner.Edotlu_estimator diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py index f339092b383..5bc51352c04 100644 --- a/tardis/simulation/base.py +++ b/tardis/simulation/base.py @@ -31,7 +31,7 @@ def __init__(self, tardis_config): self.t_inner_update = itertools.cycle(t_inner_lock_cycle) def run_single_montecarlo(self, model, no_of_packets, - no_of_virtual_packets=0): + no_of_virtual_packets=0,last_run=False): """ Will do a single TARDIS iteration with the given model Parameters @@ -49,7 +49,7 @@ def run_single_montecarlo(self, model, no_of_packets, """ self.runner.run(model, no_of_packets, no_of_virtual_packets=no_of_virtual_packets, - nthreads=self.tardis_config.montecarlo.nthreads) + nthreads=self.tardis_config.montecarlo.nthreads,last_run=last_run) (montecarlo_nu, montecarlo_energies, self.j_estimators, @@ -286,13 +286,11 @@ def legacy_run_simulation(self, model): no_of_virtual_packets = ( self.tardis_config.montecarlo.no_of_virtual_packets) - self.run_single_montecarlo(model, no_of_packets, no_of_virtual_packets) + self.run_single_montecarlo(model, no_of_packets, no_of_virtual_packets, last_run=True) self.runner.legacy_update_spectrum(no_of_virtual_packets) self.legacy_set_final_model_properties(model) - model.Edotlu_estimators = self.runner.Edotlu_estimator - model.postprocess() #the following instructions, passing down information to the model are #required for the gui From 598abc059c6033ed4c02d20e0cf57f654db1de44 Mon Sep 17 00:00:00 2001 From: Tobychev Date: Mon, 27 Jun 2016 12:20:07 +0200 Subject: [PATCH 6/8] Started adding unit tests --- tardis/montecarlo/tests/test_cmontecarlo.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tardis/montecarlo/tests/test_cmontecarlo.py b/tardis/montecarlo/tests/test_cmontecarlo.py index ed1eacf59bd..5b440c589ef 100644 --- a/tardis/montecarlo/tests/test_cmontecarlo.py +++ b/tardis/montecarlo/tests/test_cmontecarlo.py @@ -119,6 +119,9 @@ def model(): line_lists_j_blues=(c_double * 2)(*([1.e-10] * 2)), line_lists_j_blues_nd=0, + line_lists_Edotlu=(c_double * 3)(1e-10,1e-10,1.0), # Init to an explicit array + line_lists_Edotlu_nd=0, + no_of_lines=2, no_of_edges=100, @@ -426,7 +429,23 @@ def test_montecarlo_line_scatter(packet_params, expected_params, packet, model, assert_almost_equal(packet.tau_event, expected_params['tau_event']) assert_almost_equal(packet.next_line_id, expected_params['next_line_id']) +""" +Simple Tests: +---------------- +These test check very simple pices of code still work. +""" + +@pytest.mark.parametrize( + ['packet_params', 'line_idx', 'expected'], + [({'energy':0.0}, 0, 0), + ({'energy':1.0}, 1, 1), + ({'energy':0.5}, 2, 1.5)] +) +def test_increment_Edotlu_estimator(packet_params, line_idx, expected, packet, model): + packet.energy = packet_params['energy'] + cmontecarlo_methods.increment_Edotlu_estimator(byref(packet), byref(model), c_int64(line_idx)) + assert_almost_equal(model.line_lists_Edotlu[line_idx], expected) """ Difficult Tests: From c863f78da45f302a1432a0517b2f575d44270f85 Mon Sep 17 00:00:00 2001 From: Tobychev Date: Mon, 27 Jun 2016 12:21:50 +0200 Subject: [PATCH 7/8] Removed suggested cleanup --- tardis/montecarlo/src/cmontecarlo.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tardis/montecarlo/src/cmontecarlo.h b/tardis/montecarlo/src/cmontecarlo.h index 73665eab0b3..608b7bd5f0c 100644 --- a/tardis/montecarlo/src/cmontecarlo.h +++ b/tardis/montecarlo/src/cmontecarlo.h @@ -13,10 +13,6 @@ #define LOG_VPACKETS 0 #endif -#define RESONANCE 0 -#define DOWNBRANCH 1 -#define MACROATOM 2 - typedef void (*montecarlo_event_handler_t) (rpacket_t *packet, storage_model_t *storage, double distance, rk_state *mt_state); From 3457c7b9b3c5c671e1971ac0d5141548fe50a35b Mon Sep 17 00:00:00 2001 From: Tobychev Date: Tue, 28 Jun 2016 11:27:12 +0200 Subject: [PATCH 8/8] Fixed problem with unit tests --- tardis/montecarlo/src/storage.h | 2 +- tardis/montecarlo/tests/test_cmontecarlo.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tardis/montecarlo/src/storage.h b/tardis/montecarlo/src/storage.h index 0fdb5602665..9ba7406ff86 100644 --- a/tardis/montecarlo/src/storage.h +++ b/tardis/montecarlo/src/storage.h @@ -31,8 +31,8 @@ typedef struct StorageModel double *line_lists_tau_sobolevs; int64_t line_lists_tau_sobolevs_nd; double *line_lists_j_blues; - double *line_lists_Edotlu; int64_t line_lists_j_blues_nd; + double *line_lists_Edotlu; int64_t no_of_lines; int64_t no_of_edges; int64_t line_interaction_id; diff --git a/tardis/montecarlo/tests/test_cmontecarlo.py b/tardis/montecarlo/tests/test_cmontecarlo.py index 5b440c589ef..807d021bc49 100644 --- a/tardis/montecarlo/tests/test_cmontecarlo.py +++ b/tardis/montecarlo/tests/test_cmontecarlo.py @@ -119,8 +119,7 @@ def model(): line_lists_j_blues=(c_double * 2)(*([1.e-10] * 2)), line_lists_j_blues_nd=0, - line_lists_Edotlu=(c_double * 3)(1e-10,1e-10,1.0), # Init to an explicit array - line_lists_Edotlu_nd=0, + line_lists_Edotlu=(c_double * 3)(*[0.0,0.0,1.0]), # Init to an explicit array no_of_lines=2, no_of_edges=100, @@ -443,6 +442,7 @@ def test_montecarlo_line_scatter(packet_params, expected_params, packet, model, ) def test_increment_Edotlu_estimator(packet_params, line_idx, expected, packet, model): packet.energy = packet_params['energy'] + cmontecarlo_methods.increment_Edotlu_estimator(byref(packet), byref(model), c_int64(line_idx)) assert_almost_equal(model.line_lists_Edotlu[line_idx], expected)