diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/Python/FlushStdoutGuard.h b/ProcessLib/BoundaryConditionAndSourceTerm/Python/FlushStdoutGuard.h new file mode 100644 index 0000000000000000000000000000000000000000..89dba0f13f5b1ee5f3441e0c594c8762ffecddcb --- /dev/null +++ b/ProcessLib/BoundaryConditionAndSourceTerm/Python/FlushStdoutGuard.h @@ -0,0 +1,48 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#pragma once + +namespace +{ +//! Optionally flushes the standard output upon creation and destruction. +//! Can be used to improve the debug output readability when printing debug +//! messages both from OGS and from Python. +class FlushStdoutGuard final +{ +public: + //! Optionally flushes C++ stdout before running Python code. + explicit FlushStdoutGuard(bool const flush) : _flush(flush) + { + if (!flush) + { + return; + } + + std::cout << std::flush; + } + + //! Optionally flushes Python's stdout after running Python code. + ~FlushStdoutGuard() + { + if (!_flush) + { + return; + } + + using namespace pybind11::literals; + pybind11::print("end"_a = "", "flush"_a = true); + } + +private: + //! To flush or not to flush. + const bool _flush; +}; +} // anonymous namespace diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonBoundaryCondition.cpp index 15d6f05f0dfeb95d17c9eb2b0e85fa081f8dee17..eb45191687823674033bc9ab945ac966fe0f56af 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonBoundaryCondition.cpp @@ -15,47 +15,11 @@ #include <iostream> #include "BaseLib/ConfigTree.h" +#include "FlushStdoutGuard.h" #include "MeshLib/MeshSearch/NodeSearch.h" #include "ProcessLib/BoundaryConditionAndSourceTerm/Utils/CreateLocalAssemblers.h" #include "PythonBoundaryConditionLocalAssembler.h" -namespace -{ -//! Optionally flushes the standard output upon creation and destruction. -//! Can be used to improve the debug output readability when printing debug -//! messages both from OGS and from Python. -class FlushStdoutGuard -{ -public: - //! Optionally flushes C++ stdout before running Python code. - explicit FlushStdoutGuard(bool const flush) : _flush(flush) - { - if (!flush) - { - return; - } - - std::cout << std::flush; - } - - //! Optionally flushes Python's stdout after running Python code. - ~FlushStdoutGuard() - { - if (!_flush) - { - return; - } - - using namespace pybind11::literals; - pybind11::print("end"_a = "", "flush"_a = true); - } - -private: - //! To flush or not to flush. - const bool _flush; -}; -} // anonymous namespace - namespace ProcessLib { PythonBoundaryCondition::PythonBoundaryCondition( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonSourceTerm.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonSourceTerm.cpp index 91c145ebafb0555e17cffffb52f38c6e0b2038de..0df3287aa5719a1a8595e16736e0f14c1a93284a 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonSourceTerm.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/Python/PythonSourceTerm.cpp @@ -14,48 +14,12 @@ #include <iostream> +#include "FlushStdoutGuard.h" #include "MeshLib/MeshSearch/NodeSearch.h" #include "NumLib/DOF/LocalToGlobalIndexMap.h" #include "ProcessLib/BoundaryConditionAndSourceTerm/Utils/CreateLocalAssemblers.h" #include "PythonSourceTermLocalAssembler.h" -namespace -{ -//! Optionally flushes the standard output upon creation and destruction. -//! Can be used to improve the debug output readability when printing debug -//! messages both from OGS and from Python. -class FlushStdoutGuard final -{ -public: - //! Optionally flushes C++ stdout before running Python code. - explicit FlushStdoutGuard(bool const flush) : _flush(flush) - { - if (!flush) - { - return; - } - - std::cout << std::flush; - } - - //! Optionally flushes Python's stdout after running Python code. - ~FlushStdoutGuard() - { - if (!_flush) - { - return; - } - - using namespace pybind11::literals; - pybind11::print("end"_a = "", "flush"_a = true); - } - -private: - //! To flush or not to flush. - const bool _flush; -}; -} // anonymous namespace - namespace ProcessLib { namespace SourceTerms