mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Implementation of progress bar.
This commit is contained in:
parent
e09a78dabd
commit
6014310f01
5 changed files with 80 additions and 1 deletions
|
|
@ -413,6 +413,7 @@ add_library(libopenmc SHARED
|
|||
src/physics_mg.cpp
|
||||
src/plot.cpp
|
||||
src/position.cpp
|
||||
src/progress_bar.cpp
|
||||
src/pugixml/pugixml_c.cpp
|
||||
src/random_lcg.cpp
|
||||
src/reaction.cpp
|
||||
|
|
|
|||
22
include/openmc/progress_bar.h
Normal file
22
include/openmc/progress_bar.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef OPENMC_PROGRESSBAR_H
|
||||
#define OPENMC_PROGRESSBAR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class ProgressBar {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ProgressBar();
|
||||
|
||||
void set_value(double val);
|
||||
|
||||
private:
|
||||
std::string bar;
|
||||
char bar_old[72] = "???% | |";
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // OPENMC_PROGRESSBAR_H
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include "openmc/hdf5_interface.h"
|
||||
#include "openmc/random_lcg.h"
|
||||
#include "openmc/output.h"
|
||||
#include "openmc/progress_bar.h"
|
||||
|
||||
namespace openmc {
|
||||
|
||||
|
|
@ -951,10 +952,13 @@ void create_voxel(Plot pl)
|
|||
|
||||
int data[pl.pixels[1]][pl.pixels[2]];
|
||||
|
||||
ProgressBar pb;
|
||||
|
||||
RGBColor rgb;
|
||||
int id;
|
||||
for (int x = 0; x < pl.pixels[0]; x++) {
|
||||
// TODO: progress bar here
|
||||
pb.set_value(((double)x/(double)pl.pixels[0])*100);
|
||||
for (int y = 0; y < pl.pixels[1]; y++) {
|
||||
for (int z = 0; z < pl.pixels[2]; z++) {
|
||||
// get voxel color
|
||||
|
|
|
|||
52
src/progress_bar.cpp
Normal file
52
src/progress_bar.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
#include "openmc/progress_bar.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#define BAR_WIDTH 72
|
||||
|
||||
ProgressBar::ProgressBar() {
|
||||
// bar = "???% | |";
|
||||
|
||||
set_value(0.0);
|
||||
}
|
||||
|
||||
void
|
||||
ProgressBar::set_value(double val) {
|
||||
// set the bar percentage
|
||||
if (val >= 100.0) {
|
||||
bar.append("100");
|
||||
} else if (val <= 0.0) {
|
||||
bar.append(" 0");
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss << std::setfill(' ') << std::setw(3) << (int)val;
|
||||
bar.append(ss.str());
|
||||
}
|
||||
|
||||
bar.append("% |");
|
||||
|
||||
// remaining width of the bar
|
||||
int remain = BAR_WIDTH - bar.size() - 1;
|
||||
|
||||
// set the bar width
|
||||
if (val >= 100.0) {
|
||||
bar.append(remain, '=');
|
||||
} else {
|
||||
int width = (int)(65*val/100);
|
||||
std::cout << "Setting width: " << width;
|
||||
bar.append(width, '=');
|
||||
bar.append(1, '>');
|
||||
bar.append(remain-width-1, ' ');
|
||||
}
|
||||
|
||||
bar.append("|");
|
||||
|
||||
// write the bar
|
||||
std::cout << '\r' << bar << std::flush;
|
||||
|
||||
// reset the bar value
|
||||
bar = ""; //???% | |";
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
</plot>
|
||||
|
||||
<plot id="4" type="voxel">
|
||||
<pixels>100 100 10</pixels>
|
||||
<pixels>10000 100 10</pixels>
|
||||
<origin>0. 0. 0.</origin>
|
||||
<width>20 20 10</width>
|
||||
</plot>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue