Skip to content

Commit

Permalink
correction in terminal outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricix committed Sep 13, 2024
1 parent 4e6d700 commit c1c4e74
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#if defined (_WIN64) || defined(_WIN32)
#include <direct.h>
#include <windows.h>
#endif

#include "Output.h"
Expand Down Expand Up @@ -520,13 +521,14 @@ namespace Output{
serieFile <<"\t</Collection>\n";
serieFile <<"</VTKFile>\n";
}

void moveCursor(int row, int col) {
std::cout << "\033[" << row << ";" << col << "H";
}

void clearScreen() {
std::cout << "\033[2J\033[1;1H";

#ifdef _WIN32
system("cls");
#else
std::cout << "\033[2J\033[1;1H" << std::flush; // Clear screen for Unix systems
#endif
}

void showProgressBar(double progress, int width = 47) {
Expand All @@ -543,8 +545,6 @@ namespace Output{

void welcomeScreen() {

clearScreen();

// common format
int width = 55;

Expand All @@ -567,14 +567,17 @@ namespace Output{
}

void farewellScreen() {

int width = 55;
string hLines(width,'-');
cout<<"\n"<<left<<setw(width)<<hLines<<"\n\n";
}

void updateTerminal(vector<Body*>* bodies, double itime)
{
clearScreen();

welcomeScreen();

// get total kinetic energy
double ienergy = DynamicRelaxation::computeKineticEnergy(bodies);

Expand All @@ -583,21 +586,20 @@ namespace Output{
auto hours = std::chrono::duration_cast<std::chrono::hours>(elapsed_seconds);
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(elapsed_seconds) - hours;
double seconds = elapsed_seconds.count() - (hours.count() * 3600 + minutes.count() * 60);

// move cursor to write header
moveCursor(9, 1);
std::cout << "Time : " << std::setw(8) << std::fixed << std::setprecision(6) << itime << " s" << std::endl;
std::cout << "Energy : " << std::setw(8) << std::fixed << std::setprecision(2) << ienergy << " J" << std::endl;

std::cout << "Time : " << std::setw(8) << std::fixed << std::setprecision(4) << itime << "s" << std::endl;
std::cout << "Energy : " << std::setw(8) << std::scientific << std::setprecision(2) << ienergy << "J" << std::endl;
std::cout << "Particles : " << Particle::getTotalParticles() << std::endl;
std::cout << "Threads : " << ModelSetup::getThreads() << std::endl;
std::cout << "Time Step : " << ModelSetup::getTimeStep() << " s" << std::endl;
std::cout << "Elapsed time : "<< hours.count() << " h : " << minutes.count() << " m, " << std::fixed << std::setprecision(2) << seconds << " s"<<std::endl;
std::cout << "Time Step : " << ModelSetup::getTimeStep() << "s" << std::endl;
std::cout << "Elapsed time : "<< hours.count() << "h : " << minutes.count() << "m, " << std::fixed << std::setprecision(2) << seconds << "s"<<std::endl;

// show the progress bar
double progress = itime / ModelSetup::getTime();
moveCursor(16, 1);
showProgressBar(progress);


cout << "\n";

showProgressBar(progress);
int width = 55;
string hLines(width,'-');
cout<<"\n"<<left<<setw(width)<<hLines<<"\n";
Expand All @@ -607,8 +609,6 @@ namespace Output{
if (!csv_file.is_open()) {
std::cerr << "Error in opening the CSV file" << std::endl;
}

// write energy and time
csv_file << itime << "," << ienergy << "\n";
csv_file.close();
}
Expand Down
78 changes: 78 additions & 0 deletions tests/console-terminal/console-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"stress_scheme_update":"USL",

"shape_function":"GIMP",

"time":1,

"time_step":0.001,

"gravity":[0.0,0.0,-9.81],

"n_threads":10,

"damping":
{
"type":"local",
"value":0.0
},

"results":
{
"print":50,
"fields":["id","displacement","material","active","plastic_strain"]
},

"mesh":
{
"cells_dimension":[1,1,1],
"cells_number":[110,1,36],
"origin":[0,0,0],

"boundary_conditions":
{
"plane_X0":"fixed",
"plane_Y0":"sliding",
"plane_Z0":"fixed",
"plane_Xn":"fixed",
"plane_Yn":"sliding",
"plane_Zn":"fixed"
}
},

"material":
{
"plastic":
{
"type":"mohr-coulomb",
"id":1,
"young":70e6,
"density":2100,
"poisson":0.3,
"friction":20.0,
"cohesion":1.0e3
}
},

"body":
{
"soil":
{
"type":"polygon_2d",
"extrude_direction":"y",
"extrude_displacement":1,
"discretization_length":1,
"id":1,
"points":
[
[ 0, 0, 0 ],
[110, 0, 0 ],
[110, 0, 15],
[ 50, 0, 15],
[ 30, 0, 35],
[ 0, 0, 35]
],
"material_id":1
}
}
}

0 comments on commit c1c4e74

Please sign in to comment.