Skip to content

Commit de1fc14

Browse files
committed
log fixed
1 parent 04dbe93 commit de1fc14

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

cmake/PolyfemPythonDownloadExternal.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ endfunction()
2727
function(polyfem_python_download_polyfem)
2828
polyfem_python_download_project(polyfem
2929
GIT_REPOSITORY https://github.com/polyfem/polyfem.git
30-
GIT_TAG e9fb95f456b2c76f6b37f4ad0f958025efd751a0
30+
GIT_TAG 1f40d1fd2d45871d47197fe92edc65280864bd31
3131
)
3232
endfunction()
3333

setup.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,11 @@ def build_extension(self, ext):
4242

4343
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
4444
'-DPYTHON_EXECUTABLE=' + sys.executable,
45-
'-DENABLE_PARDISO=OFF',
46-
'-DLIBIGL_WITH_OPENGL=OFF',
47-
'-DLIBIGL_WITH_OPENGL_GLFW=OFF',
48-
'-DLIBIGL_WITH_OPENGL_GLFW_IMGUI=OFF',
49-
'-DLIBIGL_WITH_PNG=OFF',
50-
'-DLIBIGL_WITH_PNG=OFF',
51-
'-DLIBIGL_WITH_VIEWER=OFF',
52-
'-DGEOGRAM_WITH_GRAPHICS=OFF',
45+
'-DPOLYFEM_WITH_PARDISO=OFF',
46+
'-DPOLYFEM_NO_UI=ON',
5347
'-DPOLYFEM_WITH_APPS=OFF',
5448
'-DPOLYFEM_WITH_MISC=OFF']
5549

56-
if platform.system() == 'Darwin':
57-
cmake_args.append('-DINPUT_THIRD_PARTY_DIR=3rdparty.nosync')
58-
5950

6051
cfg = 'Debug' if self.debug else 'Release'
6152
build_args = ['--config', cfg]

src/binding.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <pybind11/eigen.h>
1616
#include <pybind11/functional.h>
1717
#include <pybind11/stl.h>
18+
#include <pybind11/iostream.h>
1819

1920
namespace py = pybind11;
2021

@@ -48,7 +49,7 @@ namespace {
4849
GEO::CmdLine::import_arg_group("pre");
4950
GEO::CmdLine::import_arg_group("algo");
5051

51-
state.init_logger("", 2, false);
52+
state.init_logger(std::cout, 2);
5253

5354
initialized = true;
5455
}
@@ -57,6 +58,8 @@ namespace {
5758
}
5859

5960
PYBIND11_MODULE(polyfempy, m) {
61+
add_ostream_redirect(m);
62+
6063
const auto &sa = py::class_<ScalarAssemblers>(m, "ScalarFormulations");
6164
for(auto &a : polyfem::AssemblerUtils::instance().scalar_assemblers())
6265
sa.attr(a.c_str()) = a;
@@ -71,6 +74,7 @@ PYBIND11_MODULE(polyfempy, m) {
7174

7275
.def("settings", [](polyfem::State &self, const py::object &json) {
7376
init_globals(self);
77+
py::scoped_ostream_redirect output;
7478
const std::string json_string = py::str(json);
7579
self.init(json::parse(json_string));
7680
},
@@ -79,6 +83,7 @@ PYBIND11_MODULE(polyfempy, m) {
7983

8084
.def("set_log_level", [](polyfem::State &s, int log_level) {
8185
init_globals(s);
86+
py::scoped_ostream_redirect output;
8287
log_level = std::max(0, std::min(6, log_level));
8388
spdlog::set_level(static_cast<spdlog::level::level_enum>(log_level));
8489
},
@@ -87,19 +92,22 @@ PYBIND11_MODULE(polyfempy, m) {
8792

8893
.def("load_mesh_from_settings", [](polyfem::State &s) {
8994
init_globals(s);
95+
py::scoped_ostream_redirect output;
9096
s.load_mesh();
9197
},
9298
"Loads a mesh from the 'mesh' field of the json and 'bc_tag' if any bc tags")
9399

94100
.def("load_mesh_from_path", [](polyfem::State &s, const std::string &path) {
95101
init_globals(s);
102+
py::scoped_ostream_redirect output;
96103
s.args["mesh"] = path;
97104
s.load_mesh();
98105
},
99106
"Loads a mesh from the path and 'bc_tag' from the json if any bc tags",
100107
py::arg("path"))
101108
.def("load_mesh_from_path_and_tags", [](polyfem::State &s, const std::string &path, const std::string &bc_tag) {
102109
init_globals(s);
110+
py::scoped_ostream_redirect output;
103111
s.args["mesh"] = path;
104112
s.args["bc_tag"] = bc_tag;
105113
s.load_mesh();
@@ -108,6 +116,7 @@ PYBIND11_MODULE(polyfempy, m) {
108116
py::arg("path"), py::arg("bc_tag_path"))
109117
.def("set_mesh", [](polyfem::State &s, const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) {
110118
init_globals(s);
119+
py::scoped_ostream_redirect output;
111120

112121
if(V.cols() == 2)
113122
s.mesh = std::make_unique<polyfem::Mesh2D>();
@@ -123,18 +132,21 @@ PYBIND11_MODULE(polyfempy, m) {
123132

124133
.def("set_boundary_side_set_from_bary", [](polyfem::State &s, const std::function<int(const polyfem::RowVectorNd&)> &boundary_marker) {
125134
init_globals(s);
135+
py::scoped_ostream_redirect output;
126136
s.mesh->compute_boundary_ids(boundary_marker);
127137
},
128138
"Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face)",
129139
py::arg("boundary_marker"))
130140
.def("set_boundary_side_set_from_bary_and_boundary", [](polyfem::State &s, const std::function<int(const polyfem::RowVectorNd&, bool)> &boundary_marker) {
131141
init_globals(s);
142+
py::scoped_ostream_redirect output;
132143
s.mesh->compute_boundary_ids(boundary_marker);
133144
},
134145
"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",
135146
py::arg("boundary_marker"))
136147
.def("set_boundary_side_set_from_v_ids", [](polyfem::State &s, const std::function<int(const std::vector<int>&, bool)> &boundary_marker) {
137148
init_globals(s);
149+
py::scoped_ostream_redirect output;
138150
s.mesh->compute_boundary_ids(boundary_marker);
139151
},
140152
"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",
@@ -143,23 +155,33 @@ PYBIND11_MODULE(polyfempy, m) {
143155

144156
.def("set_rhs_from_path", [](polyfem::State &s, std::string &path) {
145157
init_globals(s);
158+
py::scoped_ostream_redirect output;
146159
s.args["rhs_path"] = path;
147160
},
148161
"Loads the rhs from a file",
149162
py::arg("path"))
150163
.def("set_rhs", [](polyfem::State &s, const Eigen::MatrixXd &rhs) {
151164
init_globals(s);
165+
py::scoped_ostream_redirect output;
152166
s.rhs_in = rhs;
153167
},
154168
"Sets the rhs",
155169
py::arg("matrix"))
156170

157171

158172

159-
.def("solve",[](polyfem::State &s) {
173+
.def("compute_mesh_stats",[](polyfem::State &s) {
160174
init_globals(s);
175+
py::scoped_ostream_redirect output;
161176

162177
s.compute_mesh_stats();
178+
},
179+
"compute statistics")
180+
181+
182+
.def("solve",[](polyfem::State &s) {
183+
init_globals(s);
184+
py::scoped_ostream_redirect output;
163185

164186
s.build_basis();
165187

@@ -173,25 +195,31 @@ PYBIND11_MODULE(polyfempy, m) {
173195
},
174196
"solve the pde")
175197

176-
.def("compute_errors",
177-
&polyfem::State::compute_errors,
178-
"compute the error")
198+
.def("compute_errors",[](polyfem::State &s) {
199+
init_globals(s);
200+
py::scoped_ostream_redirect output;
201+
202+
s.compute_errors();
203+
},
204+
"compute the error")
179205

180206
.def("get_log", [](polyfem::State &s) {
207+
py::scoped_ostream_redirect output;
181208
std::stringstream ss;
182209
s.save_json(ss);
183210
return ss.str();
184211
},
185212
"gets the log as json")
186213

187-
.def("export_data", &polyfem::State::export_data, "exports all data specified in the settings")
188-
.def("export_vtu", &polyfem::State::save_vtu, "exports the solution as vtu", py::arg("path"))
189-
.def("export_wire", &polyfem::State::save_wire, "exports wireframe of the mesh", py::arg("path"), py::arg("isolines") = false)
214+
.def("export_data", [](polyfem::State &s) { py::scoped_ostream_redirect output; s.export_data(); }, "exports all data specified in the settings")
215+
.def("export_vtu", [](polyfem::State &s, std::string &path) { py::scoped_ostream_redirect output; s.save_vtu(path); }, "exports the solution as vtu", py::arg("path"))
216+
.def("export_wire", [](polyfem::State &s, std::string &path, bool isolines) { py::scoped_ostream_redirect output; s.save_wire(path, isolines); }, "exports wireframe of the mesh", py::arg("path"), py::arg("isolines") = false)
190217

191218

192219
.def("get_solution", [](const polyfem::State &s) { return s.sol;}, "returns the solution")
193220
.def("get_pressure", [](const polyfem::State &s) { return s.pressure;}, "returns the pressure")
194221
.def("get_sampled_solution", [](polyfem::State &s, bool boundary_only) {
222+
py::scoped_ostream_redirect output;
195223
Eigen::MatrixXd points;
196224
Eigen::MatrixXi tets;
197225
Eigen::MatrixXd discr;
@@ -213,6 +241,7 @@ PYBIND11_MODULE(polyfempy, m) {
213241
py::arg("boundary_only") = bool(false))
214242

215243
.def("get_stresses", [](polyfem::State &s, bool boundary_only) {
244+
py::scoped_ostream_redirect output;
216245
Eigen::MatrixXd points;
217246
Eigen::MatrixXi tets;
218247
Eigen::MatrixXd discr;
@@ -232,6 +261,7 @@ PYBIND11_MODULE(polyfempy, m) {
232261
py::arg("boundary_only") = bool(false))
233262

234263
.def("get_sampled_mises", [](polyfem::State &s, bool boundary_only) {
264+
py::scoped_ostream_redirect output;
235265
Eigen::MatrixXd points;
236266
Eigen::MatrixXi tets;
237267
Eigen::MatrixXd discr;
@@ -251,6 +281,7 @@ PYBIND11_MODULE(polyfempy, m) {
251281
py::arg("boundary_only") = bool(false))
252282

253283
.def("get_sampled_mises_avg", [](polyfem::State &s, bool boundary_only) {
284+
py::scoped_ostream_redirect output;
254285
Eigen::MatrixXd points;
255286
Eigen::MatrixXi tets;
256287
Eigen::MatrixXd discr;
@@ -274,6 +305,7 @@ PYBIND11_MODULE(polyfempy, m) {
274305

275306
////////////////////////////////////////////////////////////////////////////////////////////
276307
.def("get_sampled_points_frames", [](polyfem::State &s) {
308+
py::scoped_ostream_redirect output;
277309
assert(!s.solution_frames.empty());
278310

279311
std::vector<Eigen::MatrixXd> pts;
@@ -288,6 +320,7 @@ PYBIND11_MODULE(polyfempy, m) {
288320
"returns the points frames for a time dependent problem on a densly sampled mesh, use 'vismesh_rel_area' to control density")
289321

290322
.def("get_sampled_connectivity_frames", [](polyfem::State &s) {
323+
py::scoped_ostream_redirect output;
291324
assert(!s.solution_frames.empty());
292325

293326
std::vector<Eigen::MatrixXi> tets;
@@ -302,6 +335,7 @@ PYBIND11_MODULE(polyfempy, m) {
302335

303336

304337
.def("get_sampled_solution_frames", [](polyfem::State &s) {
338+
py::scoped_ostream_redirect output;
305339
assert(!s.solution_frames.empty());
306340

307341
std::vector<Eigen::MatrixXd> fun;
@@ -316,6 +350,7 @@ PYBIND11_MODULE(polyfempy, m) {
316350
"returns the solution frames for a time dependent problem on a densly sampled mesh, use 'vismesh_rel_area' to control density")
317351

318352
.def("get_sampled_mises_frames", [](polyfem::State &s) {
353+
py::scoped_ostream_redirect output;
319354
assert(!s.solution_frames.empty());
320355

321356
std::vector<Eigen::MatrixXd> mises;
@@ -328,6 +363,7 @@ PYBIND11_MODULE(polyfempy, m) {
328363
"returns the von mises stresses frames on a densly sampled mesh, use 'vismesh_rel_area' to control density")
329364

330365
.def("get_sampled_mises_avg_frames", [](polyfem::State &s) {
366+
py::scoped_ostream_redirect output;
331367
assert(!s.solution_frames.empty());
332368

333369
std::vector<Eigen::MatrixXd> mises;
@@ -341,6 +377,7 @@ PYBIND11_MODULE(polyfempy, m) {
341377

342378

343379
.def("get_boundary_sidesets", [](polyfem::State &s) {
380+
py::scoped_ostream_redirect output;
344381
Eigen::MatrixXd points;
345382
Eigen::MatrixXi faces;
346383
Eigen::MatrixXd sidesets;

0 commit comments

Comments
 (0)