@@ -62,34 +62,46 @@ PYBIND11_MODULE(polyfempy, m) {
6262 for (auto &a : polyfem::AssemblerUtils::instance ().tensor_assemblers ())
6363 ta.attr (a.c_str ()) = a;
6464
65- py::class_<polyfem::State>(m, " Solver" )
65+ const auto &solver = py::class_<polyfem::State>(m, " Solver" )
66+
6667 .def (py::init<>())
67- .def (" settings" , [](polyfem::State &s, const std::string &json) {
68+
69+ .def (" settings" , [](polyfem::State &self, const std::string &json) {
6870 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" ))
7175
7276 .def (" set_log_level" , [](polyfem::State &s, int log_level) {
7377 init_globals ();
7478 log_level = std::max (0 , std::min (6 , log_level));
7579 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" ))
7783
7884 .def (" load_mesh" , [](polyfem::State &s) {
7985 init_globals ();
8086 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+
8290 .def (" load_mesh" , [](polyfem::State &s, const std::string &path) {
8391 init_globals ();
8492 s.args [" mesh" ] = path;
8593 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" ))
8797 .def (" load_mesh" , [](polyfem::State &s, const std::string &path, const std::string &bc_tag) {
8898 init_globals ();
8999 s.args [" mesh" ] = path;
90100 s.args [" bc_tag" ] = bc_tag;
91101 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" ))
93105 .def (" set_mesh" , [](polyfem::State &s, const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) {
94106 init_globals ();
95107
@@ -99,35 +111,47 @@ PYBIND11_MODULE(polyfempy, m) {
99111 else
100112 polyfem::to_geogram_mesh_3d (V, F, M);
101113 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" ))
103117
104118
105119 .def (" set_boundary_side_set_from_bary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&)> &boundary_marker) {
106120 init_globals ();
107121 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" ))
109125 .def (" set_boundary_side_set_from_bary_and_boundary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&, bool )> &boundary_marker) {
110126 init_globals ();
111127 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" ))
113131 .def (" set_boundary_side_set_from_v_ids" , [](polyfem::State &s, const std::function<int (const std::vector<int >&, bool )> &boundary_marker) {
114132 init_globals ();
115133 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" ))
117137
118138
119139 .def (" set_rhs" , [](polyfem::State &s, std::string &path) {
120140 init_globals ();
121141 s.args [" rhs_path" ] = path;
122- }, " Loads the rhs from a file" )
142+ },
143+ " Loads the rhs from a file" ,
144+ py::arg (" path" ))
123145 .def (" set_rhs" , [](polyfem::State &s, const Eigen::MatrixXd &rhs) {
124146 init_globals ();
125147 s.rhs_in = rhs;
126- }, " Sets the rhs" )
148+ },
149+ " Sets the rhs" ,
150+ py::arg (" matrix" ))
127151
128152
129153
130- .def (" solve" , [](polyfem::State &s) {
154+ .def (" solve" ,[](polyfem::State &s) {
131155 init_globals ();
132156
133157 s.compute_mesh_stats ();
@@ -139,18 +163,23 @@ PYBIND11_MODULE(polyfempy, m) {
139163 s.assemble_stiffness_mat ();
140164
141165 s.solve_problem ();
142- }, " solve the pde" )
166+ },
167+ " solve the pde" )
143168
144- .def (" compute_errors" , &polyfem::State::compute_errors, " compute the error" )
169+ .def (" compute_errors" ,
170+ &polyfem::State::compute_errors,
171+ " compute the error" )
145172
146173 .def (" get_log" , [](polyfem::State &s) {
147174 std::stringstream ss;
148175 s.save_json (ss);
149176 return ss.str ();
150- }, " gets the log as json" )
177+ },
178+ " gets the log as json" )
179+
151180 .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 )
154183
155184
156185 .def (" get_solution" , [](const polyfem::State &s) { return s.sol ;}, " returns the solution" )
@@ -166,7 +195,10 @@ PYBIND11_MODULE(polyfempy, m) {
166195
167196 s.interpolate_function (points.rows (), s.sol , fun, boundary_only);
168197 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+
170202 .def (" get_stresses" , [](polyfem::State &s, bool boundary_only) {
171203 Eigen::MatrixXd points;
172204 Eigen::MatrixXi tets;
@@ -177,7 +209,10 @@ PYBIND11_MODULE(polyfempy, m) {
177209 s.compute_tensor_value (points.rows (), s.sol , fun, boundary_only);
178210
179211 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+
181216 .def (" get_sampled_mises" , [](polyfem::State &s, bool boundary_only) {
182217 Eigen::MatrixXd points;
183218 Eigen::MatrixXi tets;
@@ -188,7 +223,10 @@ PYBIND11_MODULE(polyfempy, m) {
188223 s.compute_scalar_value (points.rows (), s.sol , fun, boundary_only);
189224
190225 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+
192230 .def (" get_sampled_mises_avg" , [](polyfem::State &s, bool boundary_only) {
193231 Eigen::MatrixXd points;
194232 Eigen::MatrixXi tets;
@@ -199,6 +237,10 @@ PYBIND11_MODULE(polyfempy, m) {
199237 s.average_grad_based_function (points.rows (), s.sol , fun, tfun, boundary_only);
200238
201239 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" ;
203245
204246}
0 commit comments