From 0d6760469103afb687a46a4e14296ac56d6cbdb6 Mon Sep 17 00:00:00 2001 From: tobre1 Date: Mon, 21 Jul 2025 13:47:32 +0200 Subject: [PATCH] Fix domain print function in python bindings --- include/viennaps/psDomain.hpp | 18 ++++++++++++------ python/pyWrap.cpp | 10 ++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/viennaps/psDomain.hpp b/include/viennaps/psDomain.hpp index c746dac3..04e33b43 100644 --- a/include/viennaps/psDomain.hpp +++ b/include/viennaps/psDomain.hpp @@ -385,6 +385,12 @@ template class Domain { // [min, max][x, y, z] auto getBoundingBox() const { std::array, 2> boundingBox; + if (levelSets_.empty()) { + Logger::getInstance() + .addWarning("No Level-Sets in domain. Returning empty bounding box.") + .print(); + return boundingBox; + } auto mesh = viennals::Mesh::New(); viennals::ToDiskMesh(levelSets_.back(), mesh).apply(); boundingBox[0] = mesh->minimumExtent; @@ -398,8 +404,8 @@ template class Domain { } void print(std::ostream &out = std::cout, bool hrle = false) const { - out << "Process Simulation Domain:\n"; - out << "******************************\n"; + constexpr char *separator = "*****************************************\n"; + out << "Process Simulation Domain:\n" << separator; out << "Number of Level-Sets: " << levelSets_.size() << "\n"; if (materialMap_) { out << "Materials:\n"; @@ -413,13 +419,13 @@ template class Domain { } auto bb = getBoundingBox(); out << "Bounding Box: [" << bb[0][0] << ", " << bb[0][1] << ", " << bb[0][2] - << "] - [" << bb[1][0] << ", " << bb[1][1] << ", " << bb[1][2] << "]\n"; - out << "******************************\n"; + << "] - [" << bb[1][0] << ", " << bb[1][1] << ", " << bb[1][2] << "]\n" + << separator; if (hrle) { for (auto &ls : levelSets_) { ls->print(); } - out << "******************************\n"; + out << separator; } if (!metaData_.empty()) { out << "Meta Data:\n"; @@ -430,8 +436,8 @@ template class Domain { } out << "\n"; } + out << separator; } - out << "******************************" << std::endl; } // Save the level set as a VTK file. diff --git a/python/pyWrap.cpp b/python/pyWrap.cpp index d99d345e..66d0daee 100644 --- a/python/pyWrap.cpp +++ b/python/pyWrap.cpp @@ -1819,7 +1819,10 @@ PYBIND11_MODULE(VIENNAPS_MODULE_NAME, module) { "Get the boundary conditions of the domain.") .def("getMetaData", &Domain::getMetaData, "Get meta data (e.g. process data) stored in the domain") - .def("print", &Domain::print) + .def( + "print", + [](Domain &self, bool hrle) { self.print(std::cout, hrle); }, + "Print the domain information.", pybind11::arg("hrleInfo") = false) .def("saveLevelSetMesh", &Domain::saveLevelSetMesh, pybind11::arg("filename"), pybind11::arg("width") = 1, "Save the level set grids of layers in the domain.") @@ -2112,7 +2115,10 @@ PYBIND11_MODULE(VIENNAPS_MODULE_NAME, module) { "Get the bounding box of the domain.") .def("getBoundaryConditions", &Domain::getBoundaryConditions, "Get the boundary conditions of the domain.") - .def("print", &Domain::print) + .def( + "print", + [](Domain &self, bool hrle) { self.print(std::cout, hrle); }, + "Print the domain information.", pybind11::arg("hrleInfo") = false) .def("saveLevelSetMesh", &Domain::saveLevelSetMesh, pybind11::arg("filename"), pybind11::arg("width") = 1, "Save the level set grids of layers in the domain.")