Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #548 #547

Merged
merged 2 commits into from
Apr 22, 2016
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
64 changes: 0 additions & 64 deletions tardis/montecarlo/enum.py

This file was deleted.

23 changes: 20 additions & 3 deletions tardis/montecarlo/struct.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from ctypes import Structure, POINTER, c_int, c_int64, c_double, c_ulong
from enum import RPacketStatus, ContinuumProcessesStatus

c_tardis_error_t = c_int
c_rpacket_status_t = c_int
c_cont_status_t = c_int

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you missed c_error_t here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't used in structs right now, though declaration would be helpful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Done. ( c_tardis_error_t )


class RPacket(Structure):
Expand All @@ -22,7 +25,7 @@ class RPacket(Structure):
('d_boundary', c_double),
('d_cont', c_double),
('next_shell_id', c_int64),
('status', RPacketStatus),
('status', c_rpacket_status_t),
('id', c_int64),
('chi_th', c_double),
('chi_cont', c_double),
Expand Down Expand Up @@ -85,7 +88,7 @@ class StorageModel(Structure):
('t_electrons', POINTER(c_double)),
('l_pop', POINTER(c_double)),
('l_pop_r', POINTER(c_double)),
('cont_status', ContinuumProcessesStatus),
('cont_status', c_cont_status_t),
('virt_packet_nus', POINTER(c_double)),
('virt_packet_energies', POINTER(c_double)),
('virt_packet_last_interaction_in_nu', POINTER(c_double)),
Expand All @@ -104,3 +107,17 @@ class RKState(Structure):
('has_gauss', c_int),
('gauss', c_double)
]

# Variables corresponding to `tardis_error_t` enum.
TARDIS_ERROR_OK = 0
TARDIS_ERROR_BOUNDS_ERROR = 1
TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE = 2

# Variables corresponding to `rpacket_status_t` enum.
TARDIS_PACKET_STATUS_IN_PROCESS = 0
TARDIS_PACKET_STATUS_EMITTED = 1
TARDIS_PACKET_STATUS_REABSORBED = 2

# Variables corresponding to `ContinuumProcessesStatus` enum.
CONTINUUM_OFF = 0
CONTINUUM_ON = 1
25 changes: 17 additions & 8 deletions tardis/montecarlo/tests/test_cmontecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@
from numpy.testing import assert_almost_equal

from tardis import __path__ as path
from tardis.montecarlo.struct import RPacket, StorageModel, RKState
from tardis.montecarlo.enum import TardisError, RPacketStatus, ContinuumProcessesStatus
from tardis.montecarlo.struct import (
RPacket, StorageModel, RKState,
TARDIS_ERROR_OK,
TARDIS_ERROR_BOUNDS_ERROR,
TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE,
TARDIS_PACKET_STATUS_IN_PROCESS,
TARDIS_PACKET_STATUS_EMITTED,
TARDIS_PACKET_STATUS_REABSORBED,
CONTINUUM_OFF,
CONTINUUM_ON
)

# Wrap the shared object containing tests for C methods, written in C.
# TODO: Shift all tests here in Python and completely remove this test design.
Expand Down Expand Up @@ -79,7 +88,7 @@ def packet():
current_continuum_id=1,
virtual_packet_flag=1,
virtual_packet=0,
status=RPacketStatus.IN_PROCESS,
status=TARDIS_PACKET_STATUS_IN_PROCESS,
id=0
)

Expand Down Expand Up @@ -141,7 +150,7 @@ def model():

l_pop=(c_double * 20000)(*([2.0] * 20000)),
l_pop_r=(c_double * 20000)(*([3.0] * 20000)),
cont_status=ContinuumProcessesStatus.OFF
cont_status=CONTINUUM_OFF
)


Expand Down Expand Up @@ -203,16 +212,16 @@ def test_compute_distance2boundary(packet_params, expected_params, packet, model
@pytest.mark.parametrize(
['packet_params', 'expected_params'],
[({'nu_line': 0.1, 'next_line_id': 0, 'last_line': 1},
{'tardis_error': TardisError.OK, 'd_line': 1e+99}),
{'tardis_error': TARDIS_ERROR_OK, 'd_line': 1e+99}),

({'nu_line': 0.2, 'next_line_id': 1, 'last_line': 0},
{'tardis_error': TardisError.OK, 'd_line': 7.792353908000001e+17}),
{'tardis_error': TARDIS_ERROR_OK, 'd_line': 7.792353908000001e+17}),

({'nu_line': 0.5, 'next_line_id': 1, 'last_line': 0},
{'tardis_error': TardisError.COMOV_NU_LESS_THAN_NU_LINE, 'd_line': 0.0}),
{'tardis_error': TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE, 'd_line': 0.0}),

({'nu_line': 0.6, 'next_line_id': 0, 'last_line': 0},
{'tardis_error': TardisError.COMOV_NU_LESS_THAN_NU_LINE, 'd_line': 0.0})]
{'tardis_error': TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE, 'd_line': 0.0})]
)
def test_compute_distance2line(packet_params, expected_params, packet, model):
packet.nu_line = packet_params['nu_line']
Expand Down