PyPartMC 2.1.2__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. PyPartMC/_PyPartMC.pyd +0 -0
  2. PyPartMC/__generate_si.py +37 -0
  3. PyPartMC/__init__.py +78 -0
  4. PyPartMC/cmake/PyPartMCConfig.cmake +65 -0
  5. PyPartMC/include/PyPartMC/aero_binned.hpp +117 -0
  6. PyPartMC/include/PyPartMC/aero_data.hpp +283 -0
  7. PyPartMC/include/PyPartMC/aero_dist.hpp +85 -0
  8. PyPartMC/include/PyPartMC/aero_mode.hpp +359 -0
  9. PyPartMC/include/PyPartMC/aero_particle.hpp +275 -0
  10. PyPartMC/include/PyPartMC/aero_state.hpp +664 -0
  11. PyPartMC/include/PyPartMC/bin_grid.hpp +143 -0
  12. PyPartMC/include/PyPartMC/camp_core.hpp +31 -0
  13. PyPartMC/include/PyPartMC/condense.hpp +35 -0
  14. PyPartMC/include/PyPartMC/env_state.hpp +161 -0
  15. PyPartMC/include/PyPartMC/gas_data.hpp +105 -0
  16. PyPartMC/include/PyPartMC/gas_state.hpp +129 -0
  17. PyPartMC/include/PyPartMC/getters.hpp +55 -0
  18. PyPartMC/include/PyPartMC/input_guard.hpp +155 -0
  19. PyPartMC/include/PyPartMC/json_resource.hpp +363 -0
  20. PyPartMC/include/PyPartMC/output.hpp +96 -0
  21. PyPartMC/include/PyPartMC/photolysis.hpp +29 -0
  22. PyPartMC/include/PyPartMC/pmc_resource.hpp +42 -0
  23. PyPartMC/include/PyPartMC/rand.hpp +12 -0
  24. PyPartMC/include/PyPartMC/run_exact.hpp +34 -0
  25. PyPartMC/include/PyPartMC/run_exact_opt.hpp +46 -0
  26. PyPartMC/include/PyPartMC/run_part.hpp +110 -0
  27. PyPartMC/include/PyPartMC/run_part_opt.hpp +72 -0
  28. PyPartMC/include/PyPartMC/run_sect.hpp +34 -0
  29. PyPartMC/include/PyPartMC/run_sect_opt.hpp +54 -0
  30. PyPartMC/include/PyPartMC/scenario.hpp +220 -0
  31. PyPartMC/include/PyPartMC/si.hpp +118 -0
  32. PyPartMC/include/PyPartMC/util.hpp +22 -0
  33. PyPartMC/include/PyPartMC.hpp +28 -0
  34. PyPartMC/include/aero_data_parameters.hpp +27 -0
  35. PyPartMC/include/bpstd/detail/string_view.inl +925 -0
  36. PyPartMC/include/bpstd/string_view.hpp +498 -0
  37. PyPartMC/include/gas_data_parameters.hpp +14 -0
  38. PyPartMC/include/nanobind_json/nanobind_json.h +226 -0
  39. PyPartMC/include/nlohmann/adl_serializer.hpp +55 -0
  40. PyPartMC/include/nlohmann/byte_container_with_subtype.hpp +103 -0
  41. PyPartMC/include/nlohmann/detail/abi_macros.hpp +100 -0
  42. PyPartMC/include/nlohmann/detail/conversions/from_json.hpp +497 -0
  43. PyPartMC/include/nlohmann/detail/conversions/to_chars.hpp +1118 -0
  44. PyPartMC/include/nlohmann/detail/conversions/to_json.hpp +446 -0
  45. PyPartMC/include/nlohmann/detail/exceptions.hpp +257 -0
  46. PyPartMC/include/nlohmann/detail/hash.hpp +129 -0
  47. PyPartMC/include/nlohmann/detail/input/binary_reader.hpp +3009 -0
  48. PyPartMC/include/nlohmann/detail/input/input_adapters.hpp +492 -0
  49. PyPartMC/include/nlohmann/detail/input/json_sax.hpp +727 -0
  50. PyPartMC/include/nlohmann/detail/input/lexer.hpp +1633 -0
  51. PyPartMC/include/nlohmann/detail/input/parser.hpp +519 -0
  52. PyPartMC/include/nlohmann/detail/input/position_t.hpp +37 -0
  53. PyPartMC/include/nlohmann/detail/iterators/internal_iterator.hpp +35 -0
  54. PyPartMC/include/nlohmann/detail/iterators/iter_impl.hpp +751 -0
  55. PyPartMC/include/nlohmann/detail/iterators/iteration_proxy.hpp +242 -0
  56. PyPartMC/include/nlohmann/detail/iterators/iterator_traits.hpp +61 -0
  57. PyPartMC/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +130 -0
  58. PyPartMC/include/nlohmann/detail/iterators/primitive_iterator.hpp +132 -0
  59. PyPartMC/include/nlohmann/detail/json_custom_base_class.hpp +39 -0
  60. PyPartMC/include/nlohmann/detail/json_pointer.hpp +988 -0
  61. PyPartMC/include/nlohmann/detail/json_ref.hpp +78 -0
  62. PyPartMC/include/nlohmann/detail/macro_scope.hpp +482 -0
  63. PyPartMC/include/nlohmann/detail/macro_unscope.hpp +45 -0
  64. PyPartMC/include/nlohmann/detail/meta/call_std/begin.hpp +17 -0
  65. PyPartMC/include/nlohmann/detail/meta/call_std/end.hpp +17 -0
  66. PyPartMC/include/nlohmann/detail/meta/cpp_future.hpp +171 -0
  67. PyPartMC/include/nlohmann/detail/meta/detected.hpp +70 -0
  68. PyPartMC/include/nlohmann/detail/meta/identity_tag.hpp +21 -0
  69. PyPartMC/include/nlohmann/detail/meta/is_sax.hpp +159 -0
  70. PyPartMC/include/nlohmann/detail/meta/std_fs.hpp +29 -0
  71. PyPartMC/include/nlohmann/detail/meta/type_traits.hpp +795 -0
  72. PyPartMC/include/nlohmann/detail/meta/void_t.hpp +24 -0
  73. PyPartMC/include/nlohmann/detail/output/binary_writer.hpp +1838 -0
  74. PyPartMC/include/nlohmann/detail/output/output_adapters.hpp +147 -0
  75. PyPartMC/include/nlohmann/detail/output/serializer.hpp +988 -0
  76. PyPartMC/include/nlohmann/detail/string_concat.hpp +146 -0
  77. PyPartMC/include/nlohmann/detail/string_escape.hpp +72 -0
  78. PyPartMC/include/nlohmann/detail/value_t.hpp +118 -0
  79. PyPartMC/include/nlohmann/json.hpp +5258 -0
  80. PyPartMC/include/nlohmann/json_fwd.hpp +75 -0
  81. PyPartMC/include/nlohmann/ordered_map.hpp +359 -0
  82. PyPartMC/include/nlohmann/thirdparty/hedley/hedley.hpp +2045 -0
  83. PyPartMC/include/nlohmann/thirdparty/hedley/hedley_undef.hpp +158 -0
  84. PyPartMC/include/output_parameters.hpp +25 -0
  85. PyPartMC/include/tcb/span.hpp +617 -0
  86. PyPartMC/include/tl/optional.hpp +2062 -0
  87. PyPartMC/lib/libpartmclib.a +0 -0
  88. pypartmc-2.1.2.dist-info/METADATA +494 -0
  89. pypartmc-2.1.2.dist-info/RECORD +91 -0
  90. pypartmc-2.1.2.dist-info/WHEEL +5 -0
  91. pypartmc-2.1.2.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,143 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022-2025 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+
9
+ #include "pmc_resource.hpp"
10
+ #include "getters.hpp"
11
+ #include <valarray>
12
+ #include <vector>
13
+ #include "nanobind/stl/string.h"
14
+
15
+ extern "C" void f_bin_grid_ctor(void *ptr) noexcept;
16
+
17
+ extern "C" void f_bin_grid_dtor(void *ptr) noexcept;
18
+
19
+ extern "C" void f_bin_grid_init(
20
+ const void *ptr,
21
+ const int *n_bin,
22
+ const int *type,
23
+ const double *min,
24
+ const double *max
25
+ ) noexcept;
26
+
27
+ extern "C" void f_bin_grid_size(
28
+ const void *ptr,
29
+ int *val
30
+ ) noexcept;
31
+
32
+ extern "C" void f_bin_grid_edges(
33
+ const void *ptr,
34
+ void *arr_data,
35
+ const int *arr_size
36
+ ) noexcept;
37
+
38
+ extern "C" void f_bin_grid_centers(
39
+ const void *ptr,
40
+ void *arr_data,
41
+ const int *arr_size
42
+ ) noexcept;
43
+
44
+ extern "C" void f_bin_grid_widths(
45
+ const void *ptr,
46
+ void *arr_data,
47
+ const int *arr_size
48
+ ) noexcept;
49
+
50
+ extern "C" void f_bin_grid_histogram_1d(
51
+ const void *x_bin_grid_ptr_c,
52
+ const void *x_data,
53
+ const void *weight_data,
54
+ const int *arr_size,
55
+ void *output_data,
56
+ const int *grid_size
57
+ ) noexcept;
58
+
59
+ extern "C" void f_bin_grid_histogram_2d(
60
+ const void *x_bin_grid_ptr_c,
61
+ const void *x_data,
62
+ const void *y_bin_grid_ptr_c,
63
+ const void *y_data,
64
+ const void *weight_data,
65
+ const int *arr_size,
66
+ void *output_data,
67
+ const int *x_grid_size,
68
+ const int *y_grid_size
69
+ ) noexcept;
70
+
71
+ namespace nb = nanobind;
72
+
73
+ struct BinGrid {
74
+ PMCResource ptr;
75
+
76
+ BinGrid(const int &n_bin, const nb::str &grid_type, const double &min, const double &max) :
77
+ ptr(f_bin_grid_ctor, f_bin_grid_dtor)
78
+ {
79
+ const std::string grid_type_str {grid_type.c_str()};
80
+
81
+ int type = 0;
82
+ if (grid_type_str == "log") type = 1;
83
+ if (grid_type_str == "linear") type = 2;
84
+ if (type == 0)
85
+ throw std::invalid_argument( "Invalid grid spacing." );
86
+
87
+ f_bin_grid_init(ptr.f_arg(), &n_bin, &type, &min, &max);
88
+ }
89
+
90
+ BinGrid():
91
+ ptr(f_bin_grid_ctor, f_bin_grid_dtor)
92
+ {
93
+ }
94
+
95
+ static std::size_t __len__(const BinGrid &self) {
96
+ int len;
97
+ f_bin_grid_size(
98
+ self.ptr.f_arg(),
99
+ &len
100
+ );
101
+ return len;
102
+ }
103
+
104
+ static auto edges(const BinGrid &self)
105
+ {
106
+ int len;
107
+ f_bin_grid_size(
108
+ self.ptr.f_arg(),
109
+ &len
110
+ );
111
+ auto fn = f_bin_grid_edges;
112
+ return pypartmc::get_array_values_set_len(self, fn, len + 1);
113
+ }
114
+
115
+ static auto centers(const BinGrid &self)
116
+ {
117
+ auto len_fn = f_bin_grid_size;
118
+ auto fn = f_bin_grid_centers;
119
+ return pypartmc::get_array_values(self, fn, len_fn);
120
+ }
121
+
122
+ static auto widths(const BinGrid &self)
123
+ {
124
+ auto len_fn = f_bin_grid_size;
125
+ auto fn = f_bin_grid_widths;
126
+ return pypartmc::get_array_values(self, fn, len_fn);
127
+ }
128
+
129
+ };
130
+
131
+ std::valarray<double> histogram_1d(
132
+ const BinGrid &bin_grid,
133
+ std::valarray<double> values,
134
+ std::valarray<double> weights
135
+ );
136
+
137
+ std::vector<std::vector<double>> histogram_2d(
138
+ const BinGrid &x_bin_grid,
139
+ std::valarray<double> x_values,
140
+ const BinGrid &y_bin_grid,
141
+ std::valarray<double> y_values,
142
+ std::valarray<double> weights
143
+ );
@@ -0,0 +1,31 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+
9
+ #include "json_resource.hpp"
10
+ #include "pmc_resource.hpp"
11
+
12
+ extern "C" void f_camp_core_ctor(void *ptr) noexcept;
13
+ extern "C" void f_camp_core_dtor(void *ptr) noexcept;
14
+ extern "C" void f_camp_core_initialize(void *ptr, const char *prefix,
15
+ const int *prefix_size) noexcept;
16
+
17
+ struct CampCore {
18
+ PMCResource ptr;
19
+
20
+ CampCore() :
21
+ ptr(f_camp_core_ctor, f_camp_core_dtor)
22
+ {
23
+ }
24
+
25
+ CampCore(const std::string &config_name) :
26
+ ptr(f_camp_core_ctor, f_camp_core_dtor)
27
+ {
28
+ const int config_name_size = config_name.size();
29
+ f_camp_core_initialize(ptr.f_arg_non_const(), config_name.c_str(), &config_name_size);
30
+ }
31
+ };
@@ -0,0 +1,35 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+ #include "aero_data.hpp"
9
+ #include "aero_state.hpp"
10
+ #include "env_state.hpp"
11
+ #include "aero_particle.hpp"
12
+
13
+ extern "C" void f_condense_equilib_particle(
14
+ const void*,
15
+ const void*,
16
+ const void*
17
+ ) noexcept;
18
+
19
+ extern "C" void f_condense_equilib_particles(
20
+ const void*,
21
+ const void*,
22
+ const void*
23
+ ) noexcept;
24
+
25
+ void condense_equilib_particle(
26
+ const EnvState &env_state,
27
+ const AeroData &aero_data,
28
+ const AeroParticle &aero_particle
29
+ );
30
+
31
+ void condense_equilib_particles(
32
+ const EnvState &env_state,
33
+ const AeroData &aero_data,
34
+ const AeroState &aero_state
35
+ );
@@ -0,0 +1,161 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+
9
+ #include "json_resource.hpp"
10
+ #include "pmc_resource.hpp"
11
+ #include "getters.hpp"
12
+
13
+ extern "C" void f_env_state_ctor(void *ptr) noexcept;
14
+ extern "C" void f_env_state_dtor(void *ptr) noexcept;
15
+ extern "C" void f_env_state_from_json(const void *ptr) noexcept;
16
+ extern "C" void f_env_state_set_temperature(const void *ptr, const double *temperature) noexcept;
17
+ extern "C" void f_env_state_get_temperature(const void *ptr, double *temperature) noexcept;
18
+ extern "C" void f_env_state_set_additive_kernel_coefficient(const void *ptr, const double *additive_kernel_coefficient) noexcept;
19
+ extern "C" void f_env_state_get_additive_kernel_coefficient(const void *ptr, double *additive_kernel_coefficient) noexcept;
20
+ extern "C" void f_env_state_get_rel_humid(const void *ptr, double *rel_humid) noexcept;
21
+ extern "C" void f_env_state_set_height(const void *ptr, const double *height) noexcept;
22
+ extern "C" void f_env_state_get_height(const void *ptr, double *height) noexcept;
23
+ extern "C" void f_env_state_set_pressure(const void *ptr, const double *pressure) noexcept;
24
+ extern "C" void f_env_state_get_pressure(const void *ptr, double *pressure) noexcept;
25
+ extern "C" void f_env_state_get_elapsed_time(const void *ptr, double *elapsed_time) noexcept;
26
+ extern "C" void f_env_state_get_start_time(const void *ptr, double *start_time) noexcept;
27
+ extern "C" void f_env_state_air_dens(const void *ptr, double *air_density) noexcept;
28
+ extern "C" void f_env_state_air_molar_dens(const void *ptr, double *air_molar_density) noexcept;
29
+ extern "C" void f_env_state_set_latitude(const void *ptr, const double *latitude) noexcept;
30
+ extern "C" void f_env_state_get_latitude(const void *ptr, double *latitude) noexcept;
31
+ extern "C" void f_env_state_set_longitude(const void *ptr, const double *longitude) noexcept;
32
+ extern "C" void f_env_state_get_longitude(const void *ptr, double *longitude) noexcept;
33
+ extern "C" void f_env_state_set_altitude(const void *ptr, const double *altitude) noexcept;
34
+ extern "C" void f_env_state_get_altitude(const void *ptr, double *altitude) noexcept;
35
+ extern "C" void f_env_state_ppb_to_conc(const void *ptr, const double *ppb, double *conc) noexcept;
36
+ extern "C" void f_env_state_conc_to_ppb(const void *ptr, const double *conc, double *ppb) noexcept;
37
+ extern "C" void f_env_state_sat_vapor_pressure(const void *ptr, double *sat_vapor_pressure) noexcept;
38
+
39
+ struct EnvState {
40
+ PMCResource ptr;
41
+
42
+ EnvState(const nlohmann::ordered_json &json) :
43
+ ptr(f_env_state_ctor, f_env_state_dtor)
44
+ {
45
+ JSONResourceGuard<InputJSONResource> guard(json);
46
+ f_env_state_from_json(this->ptr.f_arg());
47
+ guard.check_parameters();
48
+ }
49
+
50
+ EnvState() :
51
+ ptr(f_env_state_ctor, f_env_state_dtor)
52
+ {}
53
+
54
+ static double temp(const EnvState &self) {
55
+ return pypartmc::get_value(self, f_env_state_get_temperature);
56
+ }
57
+
58
+ static void set_temperature(EnvState &self, double temperature) {
59
+ pypartmc::set_value(self, f_env_state_set_temperature, temperature);
60
+ }
61
+
62
+ static auto rh(const EnvState &self) {
63
+ return pypartmc::get_value(self, f_env_state_get_rel_humid);
64
+ }
65
+
66
+ static void set_height(EnvState &self, const double height) {
67
+ pypartmc::set_value(self, f_env_state_set_height, height);
68
+ }
69
+
70
+ static double get_height(const EnvState &self) {
71
+ return pypartmc::get_value(self, f_env_state_get_height);
72
+ }
73
+
74
+ static void set_additive_kernel_coefficient(
75
+ EnvState &self,
76
+ const double additive_kernel_coefficient)
77
+ {
78
+ pypartmc::set_value(
79
+ self,
80
+ f_env_state_set_additive_kernel_coefficient,
81
+ additive_kernel_coefficient);
82
+ }
83
+ static double get_additive_kernel_coefficient(const EnvState &self) {
84
+ return pypartmc::get_value(self, f_env_state_get_additive_kernel_coefficient);
85
+ }
86
+
87
+ static void set_pressure(EnvState &self, const double pressure) {
88
+ pypartmc::set_value(self, f_env_state_set_pressure, pressure);
89
+ }
90
+
91
+ static double get_pressure(const EnvState &self) {
92
+ return pypartmc::get_value(self, f_env_state_get_pressure);
93
+ }
94
+
95
+ static auto get_elapsed_time(const EnvState &self) {
96
+ return pypartmc::get_value(self, f_env_state_get_elapsed_time);
97
+ }
98
+
99
+ static auto get_start_time(const EnvState &self) {
100
+ return pypartmc::get_value(self, f_env_state_get_start_time);
101
+ }
102
+
103
+ static auto air_density(const EnvState &self) {
104
+ return pypartmc::get_value(self, f_env_state_air_dens);
105
+ }
106
+
107
+ static auto air_molar_density(const EnvState &self) {
108
+ return pypartmc::get_value(self, f_env_state_air_molar_dens);
109
+ }
110
+
111
+ static auto get_latitude(const EnvState &self) {
112
+ return pypartmc::get_value(self, f_env_state_get_latitude);
113
+ }
114
+
115
+ static void set_latitude(EnvState &self, const double latitude) {
116
+ pypartmc::set_value(self, f_env_state_set_latitude, latitude);
117
+ }
118
+
119
+ static auto get_longitude(const EnvState &self) {
120
+ return pypartmc::get_value(self, f_env_state_get_longitude);
121
+ }
122
+
123
+ static void set_longitude(EnvState &self, const double longitude) {
124
+ pypartmc::set_value(self, f_env_state_set_longitude, longitude);
125
+ }
126
+
127
+ static auto get_altitude(const EnvState &self) {
128
+ return pypartmc::get_value(self, f_env_state_get_altitude);
129
+ }
130
+
131
+ static void set_altitude(EnvState &self, const double altitude) {
132
+ pypartmc::set_value(self, f_env_state_set_altitude, altitude);
133
+ }
134
+
135
+ static auto ppb_to_conc(const EnvState &self, const double ppb) {
136
+ double conc;
137
+
138
+ f_env_state_ppb_to_conc(
139
+ self.ptr.f_arg(),
140
+ &ppb,
141
+ &conc
142
+ );
143
+ return conc;
144
+ }
145
+
146
+ static auto conc_to_ppb(const EnvState &self, const double conc) {
147
+ double ppb;
148
+
149
+ f_env_state_conc_to_ppb(
150
+ self.ptr.f_arg(),
151
+ &conc,
152
+ &ppb
153
+ );
154
+ return ppb;
155
+ }
156
+
157
+ static auto sat_vapor_pressure(const EnvState &self) {
158
+ return pypartmc::get_value(self, f_env_state_sat_vapor_pressure);
159
+ }
160
+
161
+ };
@@ -0,0 +1,105 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+
9
+ #include "json_resource.hpp"
10
+ #include "pmc_resource.hpp"
11
+ #include "gas_data_parameters.hpp"
12
+ #include "camp_core.hpp"
13
+ #include "nanobind/nanobind.h"
14
+ #include "nanobind_json/nanobind_json.h"
15
+
16
+ extern "C" void f_gas_data_ctor(void *ptr) noexcept;
17
+ extern "C" void f_gas_data_dtor(void *ptr) noexcept;
18
+ extern "C" void f_gas_data_len(const void *ptr, int *len) noexcept;
19
+ extern "C" void f_gas_data_from_json(const void *ptr) noexcept;
20
+ extern "C" void f_gas_data_from_camp(const void *ptr, const void *camp_core_ptr) noexcept;
21
+ extern "C" void f_gas_data_to_json(const void *ptr) noexcept;
22
+ extern "C" void f_gas_data_spec_by_name(const void *ptr, int *value, const char *name_data,
23
+ const int *name_size) noexcept;
24
+ extern "C" void f_gas_data_spec_name_by_index(const void *ptr, const int *i_spec,
25
+ char *name_data) noexcept;
26
+
27
+ struct GasData {
28
+ PMCResource ptr;
29
+ const nlohmann::ordered_json json;
30
+
31
+ GasData(const CampCore &CampCore) :
32
+ ptr(f_gas_data_ctor, f_gas_data_dtor)
33
+ {
34
+ f_gas_data_from_camp(this->ptr.f_arg(), CampCore.ptr.f_arg());
35
+ }
36
+
37
+ GasData(const nanobind::tuple &tpl) :
38
+ ptr(f_gas_data_ctor, f_gas_data_dtor),
39
+ json(tpl)
40
+ {
41
+ auto json_array = nlohmann::ordered_json::array();
42
+ for (const auto item : tpl)
43
+ json_array.push_back(nlohmann::ordered_json::object({{
44
+ nanobind::cast<std::string>(item),
45
+ nlohmann::ordered_json::array()
46
+ }}));
47
+
48
+ JSONResourceGuard<InputJSONResource> guard(json_array);
49
+ f_gas_data_from_json(this->ptr.f_arg());
50
+ guard.check_parameters();
51
+ }
52
+
53
+ GasData() :
54
+ ptr(f_gas_data_ctor, f_gas_data_dtor)
55
+ {}
56
+
57
+ static auto __str__(const GasData &self) {
58
+ return self.json.dump();
59
+ }
60
+
61
+ static std::size_t __len__(const GasData &self) {
62
+ int len;
63
+ f_gas_data_len(
64
+ self.ptr.f_arg(),
65
+ &len
66
+ );
67
+ return len;
68
+ }
69
+
70
+ static auto spec_by_name(const GasData &self, const std::string &name) {
71
+ int value;
72
+ const int name_size = name.size();
73
+ f_gas_data_spec_by_name(
74
+ self.ptr.f_arg(),
75
+ &value,
76
+ name.c_str(),
77
+ &name_size
78
+ );
79
+ if (value == 0)
80
+ throw std::runtime_error("Element not found.");
81
+ return value - 1;
82
+ }
83
+
84
+ static auto names(const GasData &self) {
85
+
86
+ int len;
87
+ f_gas_data_len(
88
+ self.ptr.f_arg(),
89
+ &len
90
+ );
91
+
92
+ char name[GAS_NAME_LEN];
93
+ nanobind::list names;
94
+ for (int idx = 0; idx < len; idx++) {
95
+ f_gas_data_spec_name_by_index(
96
+ self.ptr.f_arg(),
97
+ &idx,
98
+ name
99
+ );
100
+ names.append(nanobind::str(name));
101
+ }
102
+ return nanobind::tuple(names);
103
+ }
104
+ };
105
+
@@ -0,0 +1,129 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+ #include <string>
9
+ #include "nlohmann/json.hpp"
10
+ #include "json_resource.hpp"
11
+ #include "pmc_resource.hpp"
12
+ #include "gas_data.hpp"
13
+
14
+ extern "C" void f_gas_state_ctor(void *ptr) noexcept;
15
+ extern "C" void f_gas_state_dtor(void *ptr) noexcept;
16
+ extern "C" void f_gas_state_set_item(const void *ptr, const int *idx, const double *val) noexcept;
17
+ extern "C" void f_gas_state_get_item(const void *ptr, const int *idx, double *val) noexcept;
18
+ extern "C" void f_gas_state_len(const void *ptr, int *len) noexcept;
19
+ extern "C" void f_gas_state_to_json(const void *ptr) noexcept;
20
+ extern "C" void f_gas_state_from_json(const void *ptr, const void *gasdata_ptr) noexcept;
21
+ extern "C" void f_gas_state_set_size(const void *ptr, const void *gasdata_ptr) noexcept;
22
+ extern "C" void f_gas_state_mix_rats(const void *ptr, const double *data, const int *len);
23
+
24
+ struct GasState {
25
+ PMCResource ptr;
26
+ std::shared_ptr<GasData> gas_data;
27
+
28
+ GasState(std::shared_ptr<GasData> gas_data):
29
+ ptr(f_gas_state_ctor, f_gas_state_dtor),
30
+ gas_data(gas_data)
31
+ {
32
+ f_gas_state_set_size(
33
+ this->ptr.f_arg(),
34
+ gas_data->ptr.f_arg()
35
+ );
36
+ }
37
+
38
+ static void set_item(const GasState &self, const int &idx, const double &val) {
39
+ if (idx < 0 || idx >= (int)__len__(self))
40
+ throw std::out_of_range("TODO #118");
41
+ f_gas_state_set_item(
42
+ self.ptr.f_arg(),
43
+ &idx,
44
+ &val
45
+ );
46
+ }
47
+
48
+ static auto get_item(const GasState &self, const int &idx) {
49
+ if (idx < 0 || idx >= (int)__len__(self))
50
+ throw std::out_of_range("TODO #118");
51
+ double value;
52
+ f_gas_state_get_item(
53
+ self.ptr.f_arg(),
54
+ &idx,
55
+ &value
56
+ );
57
+ return value;
58
+ }
59
+
60
+ static auto __str__(const GasState &self) {
61
+ JSONResourceGuard<OutputJSONResource> guard;
62
+
63
+ f_gas_state_to_json(self.ptr.f_arg());
64
+ auto str = json_resource_ptr()->str();
65
+
66
+ return str;
67
+ }
68
+
69
+ static std::size_t __len__(const GasState &self) {
70
+ int len;
71
+ f_gas_state_len(self.ptr.f_arg(), &len);
72
+ return len;
73
+ }
74
+
75
+ static auto mix_rat(
76
+ const GasState &self,
77
+ const std::string &name
78
+ ) {
79
+ int value;
80
+ const int name_size = name.size();
81
+
82
+ f_gas_data_spec_by_name(
83
+ self.gas_data->ptr.f_arg(),
84
+ &value,
85
+ name.c_str(),
86
+ &name_size
87
+ );
88
+ if (value == 0)
89
+ throw std::runtime_error("Element not found.");
90
+ return get_item(self, value - 1);
91
+ }
92
+
93
+ static void set_size(GasState &self) {
94
+ f_gas_state_set_size(
95
+ self.ptr.f_arg(),
96
+ self.gas_data->ptr.f_arg()
97
+ );
98
+ }
99
+
100
+ static auto mix_rats(const GasState &self) {
101
+ int len;
102
+ f_gas_state_len(
103
+ self.ptr.f_arg(),
104
+ &len
105
+ );
106
+ std::valarray<double> data(len);
107
+
108
+ for (int idx = 0; idx < len; idx++) {
109
+ f_gas_state_get_item(
110
+ self.ptr.f_arg(),
111
+ &idx,
112
+ &data[idx]
113
+ );
114
+ }
115
+ return data;
116
+ }
117
+
118
+ static void set_mix_rats(const GasState &self, const nlohmann::ordered_json &json) {
119
+ if (json.size() == 0)
120
+ throw std::runtime_error("Non-empty sequence of mixing ratios expected");
121
+
122
+ JSONResourceGuard<InputJSONResource> guard(json);
123
+ f_gas_state_from_json(
124
+ self.ptr.f_arg(),
125
+ self.gas_data->ptr.f_arg()
126
+ );
127
+ guard.check_parameters();
128
+ }
129
+ };
@@ -0,0 +1,55 @@
1
+ /*##################################################################################################
2
+ # This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3
+ # Copyright (C) 2022 University of Illinois Urbana-Champaign #
4
+ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5
+ ##################################################################################################*/
6
+
7
+ #pragma once
8
+
9
+ #include <utility>
10
+ #include <valarray>
11
+
12
+ namespace pypartmc {
13
+
14
+ // Retrieves a single value from a Fortran routine.
15
+ template <typename T = double, typename SelfType, typename Func>
16
+ inline T get_value(const SelfType &self, Func func) {
17
+ T value{};
18
+ func(self.ptr.f_arg(), &value);
19
+ return value;
20
+ }
21
+
22
+ // Sets a single value through a Fortran routine via input parameter.
23
+ template <typename T = double, typename SelfType, typename Func>
24
+ inline void set_value(SelfType &self, Func func, T value) {
25
+ func(self.ptr.f_arg_non_const(), &value);
26
+ }
27
+
28
+ // Retrieves a computed value from a Fortran routine with additional arguments.
29
+ template <typename T = double, typename SelfType, typename Func, typename... Args>
30
+ inline T get_derived_value(const SelfType &self, Func func, Args&&... args) {
31
+ T value{};
32
+ func(self.ptr.f_arg(), std::forward<Args>(args)..., &value);
33
+ return value;
34
+ }
35
+
36
+ // Retrieves an array from a Fortran routine, querying length dynamically via len_fn.
37
+ template<typename T = double, typename SelfType, typename Func, typename LenF, typename... ExtraArgs>
38
+ inline auto get_array_values(const SelfType &self, Func f, LenF len_fn,
39
+ ExtraArgs&&... extra) {
40
+ int len;
41
+ len_fn(self.ptr.f_arg(), &len);
42
+ std::valarray<T> arr(len);
43
+ f(self.ptr.f_arg(), std::forward<ExtraArgs>(extra)..., begin(arr), &len);
44
+ return arr;
45
+ }
46
+
47
+ // Retrieves an array from a Fortran routine with a predetermined length.
48
+ template<typename T = double, typename SelfType, typename Func, typename... ExtraArgs>
49
+ inline auto get_array_values_set_len(const SelfType &self, Func f, int len,
50
+ ExtraArgs&&... extra) {
51
+ std::valarray<T> arr(len);
52
+ f(self.ptr.f_arg(), std::forward<ExtraArgs>(extra)..., begin(arr), &len);
53
+ return arr;
54
+ }
55
+ }