-
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move structs to struct.py, init default values.
- __init__ in RPacket and StorageModel resemble the same init methods in test_cmontecarlo.c - The way arguments are passed in paramterization is changed from individual params to a dict for better aesthetic sense.
- Loading branch information
karandesai-96
committed
Mar 30, 2016
1 parent
8101adb
commit 0a0c9a1
Showing
2 changed files
with
215 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import os | ||
from ctypes import * | ||
|
||
import numpy as np | ||
from tardis import __path__ as path | ||
|
||
test_path = os.path.join(path[0], 'montecarlo', 'test_montecarlo.so') | ||
tests = CDLL(test_path) | ||
|
||
cmontecarlo_filepath = os.path.join(path[0], 'montecarlo', 'montecarlo.so') | ||
cmontecarlo_methods = CDLL(cmontecarlo_filepath) | ||
|
||
|
||
class RPacket(Structure): | ||
_fields_ = [ | ||
('nu', c_double), | ||
('mu', c_double), | ||
('energy', c_double), | ||
('r', c_double), | ||
('tau_event', c_double), | ||
('nu_line', c_double), | ||
('current_shell_id', c_int64), | ||
('next_line_id', c_int64), | ||
('last_line', c_int64), | ||
('close_line', c_int64), | ||
('recently_crossed_boundary', c_int64), | ||
('current_continuum_id', c_int64), | ||
('virtual_packet_flag', c_int64), | ||
('virtual_packet', c_int64), | ||
('d_line', c_double), | ||
('d_electron', c_double), | ||
('d_boundary', c_double), | ||
('d_cont', c_double), | ||
('next_shell_id', c_int64), | ||
('status', c_int), | ||
('id', c_int64), | ||
('chi_th', c_double), | ||
('chi_cont', c_double), | ||
('chi_ff', c_double), | ||
('chi_bf', c_double) | ||
] | ||
|
||
def __init__(self, **kwargs): | ||
super(RPacket, self).__init__() | ||
self.nu = 0.4 | ||
self.mu = 0.3 | ||
self.energy = 0.9 | ||
self.r = 7.5e14 | ||
self.tau_event = 2.9e13 | ||
self.nu_line = 0.2 | ||
self.current_shell_id = 0 | ||
self.next_line_id = 1 | ||
self.last_line = 0 | ||
self.close_line = 0 | ||
self.recently_crossed_boundary = 1 | ||
self.current_continuum_id = 1 | ||
self.virtual_packet_flag = 1 | ||
self.virtual_packet = 0 | ||
self.status = 0 | ||
self.id = 0 | ||
|
||
for key, value in kwargs.iteritems(): | ||
setattr(self, key, value) | ||
|
||
|
||
class StorageModel(Structure): | ||
_fields_ = [ | ||
('packet_nus', POINTER(c_double)), | ||
('packet_mus', POINTER(c_double)), | ||
('packet_energies', POINTER(c_double)), | ||
('output_nus', POINTER(c_double)), | ||
('output_energies', POINTER(c_double)), | ||
('last_interaction_in_nu', POINTER(c_double)), | ||
('last_line_interaction_in_id', POINTER(c_int64)), | ||
('last_line_interaction_out_id', POINTER(c_int64)), | ||
('last_line_interaction_shell_id', POINTER(c_int64)), | ||
('last_line_interaction_type', POINTER(c_int64)), | ||
('no_of_packets', c_int64), | ||
('no_of_shells', c_int64), | ||
('r_inner', POINTER(c_double)), | ||
('r_outer', POINTER(c_double)), | ||
('v_inner', POINTER(c_double)), | ||
('time_explosion', c_double), | ||
('inverse_time_explosion', c_double), | ||
('electron_densities', POINTER(c_double)), | ||
('inverse_electron_densities', POINTER(c_double)), | ||
('line_list_nu', POINTER(c_double)), | ||
('continuum_list_nu', POINTER(c_double)), | ||
('line_lists_tau_sobolevs', POINTER(c_double)), | ||
('line_lists_tau_sobolevs_nd', c_int64), | ||
('line_lists_j_blues', POINTER(c_double)), | ||
('line_lists_j_blues_nd', c_int64), | ||
('no_of_lines', c_int64), | ||
('no_of_edges', c_int64), | ||
('line_interaction_id', c_int64), | ||
('transition_probabilities', POINTER(c_double)), | ||
('transition_probabilities_nd', c_int64), | ||
('line2macro_level_upper', POINTER(c_int64)), | ||
('macro_block_references', POINTER(c_int64)), | ||
('transition_type', POINTER(c_int64)), | ||
('destination_level_id', POINTER(c_int64)), | ||
('transition_line_id', POINTER(c_int64)), | ||
('js', POINTER(c_double)), | ||
('nubars', POINTER(c_double)), | ||
('spectrum_start_nu', c_double), | ||
('spectrum_delta_nu', c_double), | ||
('spectrum_end_nu', c_double), | ||
('spectrum_virt_start_nu', c_double), | ||
('spectrum_virt_end_nu', c_double), | ||
('spectrum_virt_nu', POINTER(c_double)), | ||
('sigma_thomson', c_double), | ||
('inverse_sigma_thomson', c_double), | ||
('inner_boundary_albedo', c_double), | ||
('reflective_inner_boundary', c_int64), | ||
('current_packet_id', c_int64), | ||
('chi_bf_tmp_partial', POINTER(c_double)), | ||
('t_electrons', POINTER(c_double)), | ||
('l_pop', POINTER(c_double)), | ||
('l_pop_r', POINTER(c_double)), | ||
('cont_status', c_int), | ||
('virt_packet_nus', POINTER(c_double)), | ||
('virt_packet_energies', POINTER(c_double)), | ||
('virt_packet_last_interaction_in_nu', POINTER(c_double)), | ||
('virt_packet_last_interaction_type', POINTER(c_int64)), | ||
('virt_packet_last_line_interaction_in_id', POINTER(c_int64)), | ||
('virt_packet_last_line_interaction_out_id', POINTER(c_int64)), | ||
('virt_packet_count', c_int64), | ||
('virt_array_size', c_int64) | ||
] | ||
|
||
def __init__(self, **kwargs): | ||
super(StorageModel, self).__init__() | ||
|
||
self.last_line_interaction_in_id = np.ctypeslib.as_ctypes(np.array([0] * 2)) | ||
self.last_line_interaction_shell_id = np.ctypeslib.as_ctypes(np.array([0] * 2)) | ||
self.last_line_interaction_type = np.ctypeslib.as_ctypes(np.array([2])) | ||
|
||
self.no_of_shells = 2 | ||
|
||
self.r_inner = np.ctypeslib.as_ctypes(np.array([6.912e14, 8.64e14])) | ||
self.r_outer = np.ctypeslib.as_ctypes(np.array([8.64e14, 1.0368e15])) | ||
|
||
self.time_explosion = 5.2e7 | ||
self.inverse_time_explosion = 1 / 5.2e7 | ||
|
||
# self.electron_densities = np.ctypeslib.as_ctypes(np.array([1.0e9] * 2)) | ||
# self.inverse_electron_densities = np.ctypeslib.as_ctypes(np.array([1.0e-9] * 2)) | ||
|
||
self.line_list_nu = np.ctypeslib.as_ctypes(np.array([1.26318289e+16, 1.26318289e+16, | ||
1.23357675e+16, 1.23357675e+16, | ||
1.16961598e+16])) | ||
|
||
self.continuum_list_nu = np.ctypeslib.as_ctypes(np.array([1.e13] * 20000)) | ||
|
||
self.line_lists_tau_sobolevs = np.ctypeslib.as_ctypes(np.array([1.e-5] * 1000)) | ||
# self.line_lists_j_blues = np.ctypeslib.as_ctypes(np.array([1.e-10] * 2)) | ||
self.line_lists_j_blues_nd = 0 | ||
|
||
self.no_of_lines = 2 | ||
self.no_of_edges = 100 | ||
|
||
self.line_interaction_id = 0 | ||
# self.line2macro_level_upper = np.ctypeslib.as_ctypes(np.array([0] * 2)) | ||
|
||
# self.js = np.ctypeslib.as_ctypes(np.array([0.0] * 2)) | ||
# self.nubars = np.ctypeslib.as_ctypes(np.array([0.0] * 2)) | ||
|
||
self.spectrum_start_nu = 1.e14 | ||
self.spectrum_delta_nu = 293796608840.0 | ||
self.spectrum_end_nu = 6.e15 | ||
|
||
self.spectrum_virt_start_nu = 1e14 | ||
self.spectrum_virt_end_nu = 6e15 | ||
self.spectrum_virt_nu = np.ctypeslib.as_ctypes(np.array([0.0] * 20000)) | ||
|
||
self.sigma_thomson = 6.652486e-25 | ||
self.inverse_sigma_thomson = 1 / self.sigma_thomson | ||
|
||
self.inner_boundary_albedo = 0.0 | ||
self.reflective_inner_boundary = 0 | ||
|
||
self.chi_bf_tmp_partial = np.ctypeslib.as_ctypes(np.array([160.0] * 20000)) | ||
# self.t_electrons = np.ctypeslib.as_ctypes(np.array([0.0] * 2)) | ||
|
||
self.l_pop = np.ctypeslib.as_ctypes(np.array([2.0] * 20000)) | ||
self.l_pop_r = np.ctypeslib.as_ctypes(np.array([3.0] * 20000)) | ||
|
||
for key, value in kwargs.iteritems(): | ||
setattr(self, key, value) | ||
|
Oops, something went wrong.