@@ -62,34 +62,46 @@ PYBIND11_MODULE(polyfempy, m) {
62
62
for (auto &a : polyfem::AssemblerUtils::instance ().tensor_assemblers ())
63
63
ta.attr (a.c_str ()) = a;
64
64
65
- py::class_<polyfem::State>(m, " Solver" )
65
+ const auto &solver = py::class_<polyfem::State>(m, " Solver" )
66
+
66
67
.def (py::init<>())
67
- .def (" settings" , [](polyfem::State &s, const std::string &json) {
68
+
69
+ .def (" settings" , [](polyfem::State &self, const std::string &json) {
68
70
init_globals ();
69
- s.init (json::parse (json));
70
- }, " load PDE and problem parameters from the settings" )
71
+ self.init (json::parse (json));
72
+ },
73
+ " load PDE and problem parameters from the settings" ,
74
+ py::arg (" json" ))
71
75
72
76
.def (" set_log_level" , [](polyfem::State &s, int log_level) {
73
77
init_globals ();
74
78
log_level = std::max (0 , std::min (6 , log_level));
75
79
spdlog::set_level (static_cast <spdlog::level::level_enum>(log_level));
76
- }, " sets polyfem log level, valid value between 0 (all logs) and 6 (no logs)" )
80
+ },
81
+ " sets polyfem log level, valid value between 0 (all logs) and 6 (no logs)" ,
82
+ py::arg (" log_level" ))
77
83
78
84
.def (" load_mesh" , [](polyfem::State &s) {
79
85
init_globals ();
80
86
s.load_mesh ();
81
- }, " Loads a mesh from the 'mesh' field of the json and 'bc_tag' if any bc tags" )
87
+ },
88
+ " Loads a mesh from the 'mesh' field of the json and 'bc_tag' if any bc tags" )
89
+
82
90
.def (" load_mesh" , [](polyfem::State &s, const std::string &path) {
83
91
init_globals ();
84
92
s.args [" mesh" ] = path;
85
93
s.load_mesh ();
86
- }, " Loads a mesh from the path and 'bc_tag' from the json if any bc tags" )
94
+ },
95
+ " Loads a mesh from the path and 'bc_tag' from the json if any bc tags" ,
96
+ py::arg (" path" ))
87
97
.def (" load_mesh" , [](polyfem::State &s, const std::string &path, const std::string &bc_tag) {
88
98
init_globals ();
89
99
s.args [" mesh" ] = path;
90
100
s.args [" bc_tag" ] = bc_tag;
91
101
s.load_mesh ();
92
- }, " Loads a mesh and bc_tags from path" )
102
+ },
103
+ " Loads a mesh and bc_tags from path" ,
104
+ py::arg (" path" ), py::arg (" bc_tag_path" ))
93
105
.def (" set_mesh" , [](polyfem::State &s, const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) {
94
106
init_globals ();
95
107
@@ -99,35 +111,47 @@ PYBIND11_MODULE(polyfempy, m) {
99
111
else
100
112
polyfem::to_geogram_mesh_3d (V, F, M);
101
113
s.load_mesh (M, [](const polyfem::RowVectorNd&){ return -1 ; }, true );
102
- }, " Loads a mesh from vertices and connectivity" )
114
+ },
115
+ " Loads a mesh from vertices and connectivity" ,
116
+ py::arg (" vertices" ), py::arg (" connectivity" ))
103
117
104
118
105
119
.def (" set_boundary_side_set_from_bary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&)> &boundary_marker) {
106
120
init_globals ();
107
121
s.mesh ->compute_boundary_ids (boundary_marker);
108
- }, " Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face)" )
122
+ },
123
+ " Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face)" ,
124
+ py::arg (" boundary_marker" ))
109
125
.def (" set_boundary_side_set_from_bary_and_boundary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&, bool )> &boundary_marker) {
110
126
init_globals ();
111
127
s.mesh ->compute_boundary_ids (boundary_marker);
112
- }, " Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face) and a flag that says if the element is boundary" )
128
+ },
129
+ " Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face) and a flag that says if the element is boundary" ,
130
+ py::arg (" boundary_marker" ))
113
131
.def (" set_boundary_side_set_from_v_ids" , [](polyfem::State &s, const std::function<int (const std::vector<int >&, bool )> &boundary_marker) {
114
132
init_globals ();
115
133
s.mesh ->compute_boundary_ids (boundary_marker);
116
- }, " Sets the side set for the boundary conditions, the functions takes the sorted list of vertex id and a flag that says if the element is boundary" )
134
+ },
135
+ " Sets the side set for the boundary conditions, the functions takes the sorted list of vertex id and a flag that says if the element is boundary" ,
136
+ py::arg (" boundary_marker" ))
117
137
118
138
119
139
.def (" set_rhs" , [](polyfem::State &s, std::string &path) {
120
140
init_globals ();
121
141
s.args [" rhs_path" ] = path;
122
- }, " Loads the rhs from a file" )
142
+ },
143
+ " Loads the rhs from a file" ,
144
+ py::arg (" path" ))
123
145
.def (" set_rhs" , [](polyfem::State &s, const Eigen::MatrixXd &rhs) {
124
146
init_globals ();
125
147
s.rhs_in = rhs;
126
- }, " Sets the rhs" )
148
+ },
149
+ " Sets the rhs" ,
150
+ py::arg (" matrix" ))
127
151
128
152
129
153
130
- .def (" solve" , [](polyfem::State &s) {
154
+ .def (" solve" ,[](polyfem::State &s) {
131
155
init_globals ();
132
156
133
157
s.compute_mesh_stats ();
@@ -139,18 +163,23 @@ PYBIND11_MODULE(polyfempy, m) {
139
163
s.assemble_stiffness_mat ();
140
164
141
165
s.solve_problem ();
142
- }, " solve the pde" )
166
+ },
167
+ " solve the pde" )
143
168
144
- .def (" compute_errors" , &polyfem::State::compute_errors, " compute the error" )
169
+ .def (" compute_errors" ,
170
+ &polyfem::State::compute_errors,
171
+ " compute the error" )
145
172
146
173
.def (" get_log" , [](polyfem::State &s) {
147
174
std::stringstream ss;
148
175
s.save_json (ss);
149
176
return ss.str ();
150
- }, " gets the log as json" )
177
+ },
178
+ " gets the log as json" )
179
+
151
180
.def (" export_data" , &polyfem::State::export_data, " exports all data specified in the settings" )
152
- .def (" export_vtu" , &polyfem::State::save_vtu, " exports the solution as vtu" )
153
- .def (" export_wire" , &polyfem::State::save_wire, " exports wireframe of the mesh" )
181
+ .def (" export_vtu" , &polyfem::State::save_vtu, " exports the solution as vtu" , py::arg ( " path " ) )
182
+ .def (" export_wire" , &polyfem::State::save_wire, " exports wireframe of the mesh" , py::arg ( " path " ), py::arg ( " isolines " ) = false )
154
183
155
184
156
185
.def (" get_solution" , [](const polyfem::State &s) { return s.sol ;}, " returns the solution" )
@@ -166,7 +195,10 @@ PYBIND11_MODULE(polyfempy, m) {
166
195
167
196
s.interpolate_function (points.rows (), s.sol , fun, boundary_only);
168
197
return py::make_tuple (points, tets, fun);
169
- }, " returns the solution on a densly sampled mesh, use 'vismesh_rel_area' to control density" , py::arg (" boundary_only" ) = bool (false ))
198
+ },
199
+ " returns the solution on a densly sampled mesh, use 'vismesh_rel_area' to control density" ,
200
+ py::arg (" boundary_only" ) = bool (false ))
201
+
170
202
.def (" get_stresses" , [](polyfem::State &s, bool boundary_only) {
171
203
Eigen::MatrixXd points;
172
204
Eigen::MatrixXi tets;
@@ -177,7 +209,10 @@ PYBIND11_MODULE(polyfempy, m) {
177
209
s.compute_tensor_value (points.rows (), s.sol , fun, boundary_only);
178
210
179
211
return fun;
180
- }, " returns the stress tensor on a densly sampled mesh, use 'vismesh_rel_area' to control density" , py::arg (" boundary_only" ) = bool (false ))
212
+ },
213
+ " returns the stress tensor on a densly sampled mesh, use 'vismesh_rel_area' to control density" ,
214
+ py::arg (" boundary_only" ) = bool (false ))
215
+
181
216
.def (" get_sampled_mises" , [](polyfem::State &s, bool boundary_only) {
182
217
Eigen::MatrixXd points;
183
218
Eigen::MatrixXi tets;
@@ -188,7 +223,10 @@ PYBIND11_MODULE(polyfempy, m) {
188
223
s.compute_scalar_value (points.rows (), s.sol , fun, boundary_only);
189
224
190
225
return fun;
191
- }, " returns the von mises stresses on a densly sampled mesh, use 'vismesh_rel_area' to control density" , py::arg (" boundary_only" ) = bool (false ))
226
+ },
227
+ " returns the von mises stresses on a densly sampled mesh, use 'vismesh_rel_area' to control density" ,
228
+ py::arg (" boundary_only" ) = bool (false ))
229
+
192
230
.def (" get_sampled_mises_avg" , [](polyfem::State &s, bool boundary_only) {
193
231
Eigen::MatrixXd points;
194
232
Eigen::MatrixXi tets;
@@ -199,6 +237,10 @@ PYBIND11_MODULE(polyfempy, m) {
199
237
s.average_grad_based_function (points.rows (), s.sol , fun, tfun, boundary_only);
200
238
201
239
return py::make_tuple (fun, tfun);
202
- }, " returns the von mises stresses and stress tensor averaged around a vertex on a densly sampled mesh, use 'vismesh_rel_area' to control density" , py::arg (" boundary_only" ) = bool (false ));
240
+ },
241
+ " returns the von mises stresses and stress tensor averaged around a vertex on a densly sampled mesh, use 'vismesh_rel_area' to control density" ,
242
+ py::arg (" boundary_only" ) = bool (false ));
243
+
244
+ solver.doc () = " Polyfem solver" ;
203
245
204
246
}
0 commit comments