Skip to content

Commit 1d4772d

Browse files
committed
add n_spec for gas_data and gas_state
1 parent 1509097 commit 1d4772d

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/gas_state.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" void f_gas_state_mix_rats(const void *ptr, const double *data, const
2525
struct GasState {
2626
PMCResource ptr;
2727

28-
GasState(const GasData &gas_data,
28+
/* GasState(const GasData &gas_data,
2929
const nlohmann::json &json) :
3030
ptr(f_gas_state_ctor, f_gas_state_dtor)
3131
{
@@ -38,6 +38,13 @@ struct GasState {
3838
3939
gimmick_ptr().reset(); // TODO #117: guard
4040
}
41+
*/
42+
43+
GasState(const GasData &gas_data) :
44+
ptr(f_gas_state_ctor, f_gas_state_dtor)
45+
{
46+
f_gas_state_set_size(this->ptr.f_arg(), &gas_data.ptr);
47+
}
4148

4249
static void set_item(const GasState &self, const int &idx, const double &val) {
4350
if (idx < 0 || idx >= (int)__len__(self))
@@ -80,18 +87,17 @@ struct GasState {
8087
}
8188

8289
static void set_size(GasState &self, const GasData &GasData) {
83-
f_gas_state_set_size(&self.ptr, &GasData.ptr);
90+
f_gas_state_set_size(&self.ptr, &GasData.ptr);
8491
}
8592

8693
static std::valarray<double> mix_rats(const GasState &self) {
87-
int len;
88-
f_gas_state_len(&self.ptr, &len);
89-
std::valarray<double> data(len);
90-
91-
for (int idx = 0; idx < len; idx++) {
92-
f_gas_state_get_item(&self.ptr, &idx, &data[idx]);
93-
}
94-
//f_gas_state_mix_rats(&self.ptr, &data, &len);
95-
return data;
94+
int len;
95+
f_gas_state_len(&self.ptr, &len);
96+
std::valarray<double> data(len);
97+
98+
for (int idx = 0; idx < len; idx++) {
99+
f_gas_state_get_item(&self.ptr, &idx, &data[idx]);
100+
}
101+
return data;
96102
}
97103
};

src/pypartmc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
170170
)
171171
.def(py::init<const py::tuple&>())
172172
.def("__len__", GasData::__len__)
173+
.def_property_readonly("n_spec", GasData::__len__)
173174
.def("__str__", GasData::__str__,
174175
"returns a string with JSON representation of the object")
175176
.def("spec_by_name", GasData::spec_by_name,
@@ -256,13 +257,14 @@ PYBIND11_MODULE(_PyPartMC, m) {
256257
it. This will be the case for new \c gas_state_t structures.
257258
)pbdoc"
258259
)
259-
.def(py::init<const nlohmann::json&>(),
260-
"instantiates and initializes from a JSON object", py::arg(0) = py::dict())
260+
.def(py::init<const GasData&>(),
261+
"instantiates and initializes based on GasData")
261262
.def("__setitem__", GasState::set_item)
262263
//.def("__setitem__", GasState::set_items)
263264
.def("__getitem__", GasState::get_item)
264265
//.def("__getitem__", GasState::get_items)
265266
.def("__len__", GasState::__len__)
267+
.def_property_readonly("n_spec", GasState::__len__)
266268
.def("__str__", GasState::__str__,
267269
"returns a string with JSON representation of the object")
268270
.def("set_size", GasState::set_size,

0 commit comments

Comments
 (0)