@@ -24,7 +24,7 @@ class TensorAssemblers { };
2424
2525
2626namespace {
27- void init_globals ()
27+ void init_globals (polyfem::State &state )
2828 {
2929 static bool initialized = false ;
3030
@@ -48,6 +48,8 @@ namespace {
4848 GEO::CmdLine::import_arg_group (" pre" );
4949 GEO::CmdLine::import_arg_group (" algo" );
5050
51+ state.init_logger (" " , 2 , false );
52+
5153 initialized = true ;
5254 }
5355 }
@@ -68,43 +70,43 @@ PYBIND11_MODULE(polyfempy, m) {
6870 .def (py::init<>())
6971
7072 .def (" settings" , [](polyfem::State &self, const std::string &json) {
71- init_globals ();
73+ init_globals (self );
7274 self.init (json::parse (json));
7375 },
7476 " load PDE and problem parameters from the settings" ,
7577 py::arg (" json" ))
7678
7779 .def (" set_log_level" , [](polyfem::State &s, int log_level) {
78- init_globals ();
80+ init_globals (s );
7981 log_level = std::max (0 , std::min (6 , log_level));
8082 spdlog::set_level (static_cast <spdlog::level::level_enum>(log_level));
8183 },
8284 " sets polyfem log level, valid value between 0 (all logs) and 6 (no logs)" ,
8385 py::arg (" log_level" ))
8486
8587 .def (" load_mesh_from_settings" , [](polyfem::State &s) {
86- init_globals ();
88+ init_globals (s );
8789 s.load_mesh ();
8890 },
8991 " Loads a mesh from the 'mesh' field of the json and 'bc_tag' if any bc tags" )
9092
9193 .def (" load_mesh_from_path" , [](polyfem::State &s, const std::string &path) {
92- init_globals ();
94+ init_globals (s );
9395 s.args [" mesh" ] = path;
9496 s.load_mesh ();
9597 },
9698 " Loads a mesh from the path and 'bc_tag' from the json if any bc tags" ,
9799 py::arg (" path" ))
98100 .def (" load_mesh_from_path_and_tags" , [](polyfem::State &s, const std::string &path, const std::string &bc_tag) {
99- init_globals ();
101+ init_globals (s );
100102 s.args [" mesh" ] = path;
101103 s.args [" bc_tag" ] = bc_tag;
102104 s.load_mesh ();
103105 },
104106 " Loads a mesh and bc_tags from path" ,
105107 py::arg (" path" ), py::arg (" bc_tag_path" ))
106108 .def (" set_mesh" , [](polyfem::State &s, const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) {
107- init_globals ();
109+ init_globals (s );
108110
109111 if (V.cols () == 2 )
110112 s.mesh = std::make_unique<polyfem::Mesh2D>();
@@ -119,33 +121,33 @@ PYBIND11_MODULE(polyfempy, m) {
119121
120122
121123 .def (" set_boundary_side_set_from_bary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&)> &boundary_marker) {
122- init_globals ();
124+ init_globals (s );
123125 s.mesh ->compute_boundary_ids (boundary_marker);
124126 },
125127 " Sets the side set for the boundary conditions, the functions takes the barycenter of the boundary (edge or face)" ,
126128 py::arg (" boundary_marker" ))
127129 .def (" set_boundary_side_set_from_bary_and_boundary" , [](polyfem::State &s, const std::function<int (const polyfem::RowVectorNd&, bool )> &boundary_marker) {
128- init_globals ();
130+ init_globals (s );
129131 s.mesh ->compute_boundary_ids (boundary_marker);
130132 },
131133 " 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" ,
132134 py::arg (" boundary_marker" ))
133135 .def (" set_boundary_side_set_from_v_ids" , [](polyfem::State &s, const std::function<int (const std::vector<int >&, bool )> &boundary_marker) {
134- init_globals ();
136+ init_globals (s );
135137 s.mesh ->compute_boundary_ids (boundary_marker);
136138 },
137139 " 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" ,
138140 py::arg (" boundary_marker" ))
139141
140142
141143 .def (" set_rhs_from_path" , [](polyfem::State &s, std::string &path) {
142- init_globals ();
144+ init_globals (s );
143145 s.args [" rhs_path" ] = path;
144146 },
145147 " Loads the rhs from a file" ,
146148 py::arg (" path" ))
147149 .def (" set_rhs" , [](polyfem::State &s, const Eigen::MatrixXd &rhs) {
148- init_globals ();
150+ init_globals (s );
149151 s.rhs_in = rhs;
150152 },
151153 " Sets the rhs" ,
@@ -154,7 +156,7 @@ PYBIND11_MODULE(polyfempy, m) {
154156
155157
156158 .def (" solve" ,[](polyfem::State &s) {
157- init_globals ();
159+ init_globals (s );
158160
159161 s.compute_mesh_stats ();
160162
0 commit comments