Commit 774b635f authored by Kilian Lackhove's avatar Kilian Lackhove
Browse files

Moved Progressbar implementation into LibUtilities

parent d7b5f29d
////////////////////////////////////////////////////////////////////////////////
//
// Progressbar.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2015 Kilian Lackhove
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Print a simple progress bar
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_LIBUTILITIES_PROGRESSBAR_HPP
#define NEKTAR_LIBUTILITIES_PROGRESSBAR_HPP
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#ifdef _WIN32
#include <io.h>
#define ISTTY _isatty(_fileno(stdout))
#else
#include <unistd.h>
#define ISTTY isatty(fileno(stdout))
#endif
using namespace std;
namespace Nektar
{
namespace LibUtilities
{
/**
* @brief Prints a progressbar
*
* @param position State of the current process
* @param goal Goal of the current process
* @param message Short Description of the current process
*
* This function plots a simple progressbar to the console or log file to
* visualize the current state of an ongoing process. Make sure you minimize
* calling this routine. Ideally, this should be called only when the
* percentage is increased by an integer.
*/
inline void PrintProgressbar(const int position, const int goal, const string message)
{
if (ISTTY)
{
// carriage return
cout << "\r";
cout << message << ": ";
float progress = position / float(goal);
cout << setw(3) << int(100 * progress) << "% [";
for (int j = 0; j < int(progress * 49); j++)
{
cout << "=";
}
for (int j = int(progress * 49); j < 49; j++)
{
cout << " ";
}
cout << "]" << flush;
}
else
{
// print only every 2 percent
if (int(100 * position / goal) % 2 == 0)
{
cout << "." << flush;
}
}
}
}
}
#endif // NEKTAR_LIBUTILITIES_PROGRESSBAR_HPP
......@@ -21,6 +21,7 @@ SET(BasicUtilsHeaders
./BasicUtils/NekPtr.hpp
./BasicUtils/OperatorGenerators.hpp
./BasicUtils/ParseUtils.hpp
./BasicUtils/Progressbar.hpp
./BasicUtils/PtsField.h
./BasicUtils/PtsIO.h
./BasicUtils/Timer.h
......
......@@ -56,18 +56,8 @@
# include <boost/function.hpp>
#include <iostream>
#include <iomanip>
#include <string>
#ifdef _WIN32
#include <io.h>
#define ISTTY _isatty(_fileno(stdout))
#else
#include <unistd.h>
#define ISTTY isatty(fileno(stdout))
#endif
using std::string;
namespace Nektar
......@@ -888,9 +878,9 @@ namespace Nektar
}
else
{
ptsField->setProgressCallback(&EquationSystem::PrintProgressbar, this);
if (m_session->GetComm()->GetRank() == 0)
{
ptsField->setProgressCallback(&EquationSystem::PrintProgressbar, this);
cout << "Interpolating: ";
}
ptsField->CalcWeights(coords);
......@@ -2406,39 +2396,5 @@ namespace Nektar
{
}
void EquationSystem::PrintProgressbar(const int position, const int goal) const
{
if (m_session->GetComm()->GetRank() != 0)
{
return;
}
if (ISTTY)
{
// carriage return
cout << "\r";
cout << "Interpolating: ";
float progress = position / float(goal);
cout << setw(3) << int(100* progress) << "% [";
for (int j = 0; j < int(progress *49); j++)
{
cout << "=";
}
for (int j = int(progress *49); j < 49; j++)
{
cout << " ";
}
cout << "]" << flush;
}
else
{
// print only every 2 percent
if (int(100 * position / goal) % 2 == 0)
{
cout << "." << flush;
}
}
}
}
}
......@@ -42,6 +42,7 @@
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/FileSystem.h>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include <LibUtilities/BasicUtils/Progressbar.hpp>
#include <LibUtilities/BasicUtils/PtsField.h>
#include <LibUtilities/BasicUtils/PtsIO.h>
#include <MultiRegions/ExpList.h>
......@@ -611,7 +612,10 @@ namespace Nektar
Array<OneD, Array<OneD, NekDouble > > &qflux);
SOLVER_UTILS_EXPORT void PrintProgressbar(const int position,
const int goal) const;
const int goal) const
{
LibUtilities::PrintProgressbar(position, goal, "Interpolating");
}
};
......
......@@ -35,15 +35,6 @@
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
#include <iomanip>
#ifdef _WIN32
#include <io.h>
#define ISTTY _isatty(_fileno(stdout))
#else
#include <unistd.h>
#define ISTTY isatty(fileno(stdout))
#endif
using namespace std;
......@@ -112,10 +103,10 @@ void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
// interpolate points and transform
Array<OneD, Array<OneD, NekDouble> > intFields(nFields);
m_f->m_fieldPts->setProgressCallback(
&ProcessInterpPointDataToFld::PrintProgressbar, this);
if(m_f->m_session->GetComm()->GetRank() == 0)
if (m_f->m_session->GetComm()->GetRank() == 0)
{
m_f->m_fieldPts->setProgressCallback(
&ProcessInterpPointDataToFld::PrintProgressbar, this);
cout << "Interpolating: ";
}
m_f->m_fieldPts->Interpolate(coords, intFields, coord_id);
......@@ -161,41 +152,6 @@ void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
}
void ProcessInterpPointDataToFld::PrintProgressbar(const int position, const int goal) const
{
if (m_f->m_session->GetComm()->GetRank() != 0)
{
return;
}
if (ISTTY)
{
// carriage return
cout << "\r";
cout << "Interpolating: ";
float progress = position / float(goal);
cout << setw(3) << int(100* progress) << "% [";
for (int j = 0; j < int(progress *49); j++)
{
cout << "=";
}
for (int j = int(progress *49); j < 49; j++)
{
cout << " ";
}
cout << "]" << flush;
}
else
{
// print only every 2 percent
if (int(100 * position / goal) % 2 == 0)
{
cout << "." << flush;
}
}
}
}
}
......
......@@ -36,6 +36,8 @@
#ifndef UTILITIES_PREPROCESSING_FIELDCONVERT_PROCESSINTERPDATATOFLD
#define UTILITIES_PREPROCESSING_FIELDCONVERT_PROCESSINTERPDATATOFLD
#include <LibUtilities/BasicUtils/Progressbar.hpp>
#include "Module.h"
namespace Nektar
......@@ -61,7 +63,10 @@ public:
/// Write mesh to output file.
virtual void Process(po::variables_map &vm);
void PrintProgressbar(const int position, const int goal) const;
void PrintProgressbar(const int position, const int goal) const
{
LibUtilities::PrintProgressbar(position, goal, "Interpolating");
}
private:
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment