Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pyAMRZeusModel.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
15
20#include <pybind11/functional.h>
21#include <memory>
22
23namespace shammodels::zeus {
24 template<class Tvec, class TgridVec>
25 void add_instance(py::module &m, std::string name_config, std::string name_model) {
26
27 using Tscal = shambase::VecComponent<Tvec>;
28 using Tgridscal = shambase::VecComponent<TgridVec>;
29
30 using T = Model<Tvec, TgridVec>;
31 using TConfig = typename T::Solver::Config;
32 using TAnalysisSodTube = shammodels::zeus::modules::AnalysisSodTube<Tvec, TgridVec>;
33
34 shamlog_debug_ln("[Py]", "registering class :", name_config, typeid(T).name());
35 shamlog_debug_ln("[Py]", "registering class :", name_model, typeid(T).name());
36
37 py::class_<TConfig>(m, name_config.c_str())
38 .def(
39 "set_scale_factor",
40 [](TConfig &self, Tscal scale_factor) {
41 self.grid_coord_to_pos_fact = scale_factor;
42 })
43 .def(
44 "set_eos_gamma",
45 [](TConfig &self, Tscal eos_gamma) {
46 self.set_eos_gamma(eos_gamma);
47 })
48 .def(
49 "set_Csafe",
50 [](TConfig &self, Tscal Csafe) {
51 self.Csafe = Csafe;
52 })
53 .def(
54 "set_consistent_transport",
55 [](TConfig &self, bool enable) {
56 self.use_consistent_transport = enable;
57 })
58 .def(
59 "set_van_leer",
60 [](TConfig &self, bool enable) {
61 self.use_van_leer = enable;
62 })
63 .def(
64 "set_scheduler_config",
65 [](TConfig &self, u64 split_crit, u64 merge_crit) {
66 self.scheduler_conf.split_load_value = split_crit;
67 self.scheduler_conf.merge_load_value = merge_crit;
68 },
69 py::kw_only(),
70 py::arg("split_load_value"),
71 py::arg("merge_load_value"));
72
73 std::string sod_tube_analysis_name = name_model + "_AnalysisSodTube";
74 py::class_<TAnalysisSodTube>(m, sod_tube_analysis_name.c_str())
75 .def("compute_L2_dist", [](TAnalysisSodTube &self) -> std::tuple<Tscal, Tvec, Tscal> {
76 auto ret = self.compute_L2_dist();
77 return {ret.rho, ret.v, ret.P};
78 });
79 py::class_<T>(m, name_model.c_str())
80 .def("init", &T::init)
81 .def("init_scheduler", &T::init_scheduler)
82 .def("make_base_grid", &T::make_base_grid)
83 .def("dump_vtk", &T::dump_vtk)
84 .def("evolve_once", &T::evolve_once)
85 .def("set_field_value_lambda_f64", &T::template set_field_value_lambda<f64>)
86 .def("set_field_value_lambda_f64_3", &T::template set_field_value_lambda<f64_3>)
87 .def(
88 "gen_default_config",
89 [](T &self) -> TConfig {
90 return TConfig();
91 })
92 .def(
93 "set_solver_config",
94 [](T &self, TConfig cfg) {
95 if (self.ctx.is_scheduler_initialized()) {
97 "Cannot change solver config after scheduler is initialized");
98 }
99 cfg.check_config();
100 self.solver.solver_config = cfg;
101 })
102 .def(
103 "get_cell_coords",
104 [](T &self, std::pair<TgridVec, TgridVec> block_coord, u32 cell_local_id) {
105 return self.get_cell_coords(block_coord, cell_local_id);
106 })
107 .def(
108 "make_analysis_sodtube",
109 [](T &self,
110 shamphys::SodTube sod,
111 Tvec direction,
112 Tscal time_val,
113 Tscal x_ref,
114 Tscal x_min,
115 Tscal x_max) {
116 return std::make_unique<TAnalysisSodTube>(
117 self.ctx,
118 self.solver.solver_config,
119 self.solver.storage,
120 sod,
121 direction,
122 time_val,
123 x_ref,
124 x_min,
125 x_max);
126 });
127 }
128} // namespace shammodels::zeus
129
131 auto &m = root_module;
132
133 py::module mzeus = m.def_submodule("model_zeus", "Shamrock Zeus solver");
134
135 std::string base_name = "ZeusModel";
136 using namespace shammodels::zeus;
137
138 add_instance<f64_3, i64_3>(
139 mzeus, base_name + "_f64_3_i64_3_SolverConfig", base_name + "_f64_3_i64_3_Model");
140
141 using VariantAMRZeusBind = std::variant<std::unique_ptr<Model<f64_3, i64_3>>>;
142
143 m.def(
144 "get_Model_Zeus",
145 [](ShamrockCtx &ctx, std::string vector_type, std::string grid_repr) -> VariantAMRZeusBind {
146 VariantAMRZeusBind ret;
147
148 if (vector_type == "f64_3" && grid_repr == "i64_3") {
149 ret = std::make_unique<Model<f64_3, i64_3>>(ctx);
150 } else {
152 "unknown combination of representation and grid_repr");
153 }
154
155 return ret;
156 },
157 py::kw_only(),
158 py::arg("context"),
159 py::arg("vector_type"),
160 py::arg("grid_repr"));
161}
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Zeus scheme zeus2d_main fargo3d_1 implementation in Shamrock (WIP).
Definition Model.hpp:38
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace for the zeus model
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.