forked from open-atmos/PyPartMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaero_dist.hpp
86 lines (69 loc) · 2.43 KB
/
aero_dist.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*##################################################################################################
# This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
# Copyright (C) 2022 University of Illinois Urbana-Champaign #
# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
##################################################################################################*/
#pragma once
#include "pmc_resource.hpp"
#include "aero_mode.hpp"
extern "C" void f_aero_dist_ctor(
void *ptr
) noexcept;
extern "C" void f_aero_dist_dtor(
void *ptr
) noexcept;
extern "C" void f_aero_dist_n_mode(
const void *ptr,
int *n_mode
) noexcept;
extern "C" void f_aero_dist_from_json(
void *ptr,
void *aero_data_ptr
) noexcept;
extern "C" void f_aero_dist_total_num_conc(
const void *ptr,
double *total_num_conc
) noexcept;
extern "C" void f_aero_dist_mode(
const void *ptr,
void *ptr_c,
const int *index
) noexcept;
struct AeroDist {
PMCResource ptr;
std::shared_ptr<AeroData> aero_data;
AeroDist(
std::shared_ptr<AeroData> aero_data,
const nlohmann::json &json
):
ptr(f_aero_dist_ctor, f_aero_dist_dtor),
aero_data(aero_data)
{
if (!InputJSONResource::unique_keys(json))
throw std::runtime_error("Mode names must be unique");
for (const auto &mode : json)
AeroMode::check_mode_json(mode.begin().value());
JSONResourceGuard<InputJSONResource> guard(json, "", "mode_name", 1);
f_aero_dist_from_json(ptr.f_arg_non_const(), aero_data->ptr.f_arg_non_const());
}
AeroDist() :
ptr(f_aero_dist_ctor, f_aero_dist_dtor)
{}
static auto get_n_mode(const AeroDist &self) {
int n_mode;
f_aero_dist_n_mode(self.ptr.f_arg(), &n_mode);
return n_mode;
}
static auto get_total_num_conc(const AeroDist &self) {
double total_num_conc;
f_aero_dist_total_num_conc(self.ptr.f_arg(), &total_num_conc);
return total_num_conc;
}
static AeroMode* get_mode(const AeroDist &self, const int &idx) {
if (idx < 0 || idx >= AeroDist::get_n_mode(self))
throw std::out_of_range("Index out of range");
AeroMode *ptr = new AeroMode();
f_aero_dist_mode(self.ptr.f_arg(), ptr, &idx);
return ptr;
}
};