Skip to content

Commit 52c688d

Browse files
committed
SAR: very simple progress feedback
Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
1 parent f216b7e commit 52c688d

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

python/openEMS/sar_calculation.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cdef extern from "openEMS/sar_calculation.h":
2424
_SAR_Calculation() nogil except +
2525

2626
void SetDebugLevel(int level)
27+
void EnableProgress(bool enable)
2728
void SetAveragingMass(float mass)
2829
bool SetAveragingMethod(string method, bool silent)
2930
bool CalcFromHDF5(string h5_fn, string out_name, bool export_cube_stats) nogil

python/openEMS/sar_calculation.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ cdef class SAR_Calculation:
3737
def SetDebugLevel(self, level):
3838
self.thisptr.SetDebugLevel(level)
3939

40+
def EnableProgress(self, enable):
41+
self.thisptr.EnableProgress(enable)
42+
4043
def SetAveragingMass(self, mass):
4144
### Set the averaging mass in g
4245
# convert from g to kg

tools/sar_calc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int main(int argc, char *argv[])
3838
bool debug = false;
3939
bool export_cube_stats = false;
4040
bool legacyHDF5 = false;
41+
bool progress = false;
4142

4243
desc.add_options()
4344
("help,h" , "print usage message")
@@ -46,6 +47,7 @@ int main(int argc, char *argv[])
4647
("method", value(&method)->default_value("SIMPLE"), "set SAR method: IEEE_C95_3, IEEE_62704, SIMPLE")
4748
("mass,m" , value(&m_avg), "averaging mass in g")
4849
("verbose,v", bool_switch(&debug), "verbose")
50+
("progress,p", bool_switch(&progress), "show progress")
4951
("export_cube_stats,e", bool_switch(&export_cube_stats), "Export Cube Statistics")
5052
("legacyHDF5Dumps", bool_switch(&legacyHDF5), "Dumping using the legacy HDF5 file format as required for Octave/Matlab import");
5153

@@ -60,6 +62,7 @@ int main(int argc, char *argv[])
6062

6163
SAR_Calculation sar_calc;
6264
sar_calc.SetDebugLevel(int(debug));
65+
sar_calc.EnableProgress(progress);
6366
sar_calc.SetAveragingMass(m_avg/1000);
6467
//sar_calc.SetAveragingMethod(SAR_Calculation::IEEE_62704);
6568
if (!sar_calc.SetAveragingMethod(method, !debug))

tools/sar_calculation.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ bool SAR_Calculation::CalcAveragedSAR(ArrayLib::ArrayIJK<float> & SAR)
800800
float* cube_vol = m_cube_volume.data();
801801
float* cell_density = m_cell_density->data();
802802
loc = 0;
803+
unsigned int prog_N = SAR.size()/100;
804+
if (m_progress)
805+
std::cout << "Step-1: ";
803806
for (pos[0]=0; pos[0]<m_numLines[0]; ++pos[0])
804807
{
805808
for (pos[1]=0; pos[1]<m_numLines[1]; ++pos[1])
@@ -811,6 +814,11 @@ bool SAR_Calculation::CalcAveragedSAR(ArrayLib::ArrayIJK<float> & SAR)
811814
SAR(pos[0], pos[1], pos[2]) = 0;
812815
++m_AirVoxel;
813816
++loc;
817+
if (m_progress && (loc%prog_N == 0))
818+
{
819+
std::cout << ".";
820+
std::cout.flush();
821+
}
814822
continue;
815823
}
816824

@@ -840,9 +848,17 @@ bool SAR_Calculation::CalcAveragedSAR(ArrayLib::ArrayIJK<float> & SAR)
840848
else
841849
cerr << "other EC" << EC << endl;
842850
++loc;
851+
if (m_progress && (loc%prog_N == 0))
852+
{
853+
std::cout << ".";
854+
std::cout.flush();
855+
}
843856
}
844857
}
845858
}
859+
if (m_progress)
860+
std::cout << " Done" << std::endl;
861+
846862
if (cnt_NoConvergence>0)
847863
{
848864
cerr << "SAR_Calculation::CalcAveragedSAR: Warning, for some voxel a valid averaging cube could not be found (no convergence)... " << endl;
@@ -859,6 +875,9 @@ bool SAR_Calculation::CalcAveragedSAR(ArrayLib::ArrayIJK<float> & SAR)
859875
m_Used=0;
860876
m_Unused=0;
861877
loc = 0;
878+
if (m_progress)
879+
std::cout << "Step-2: ";
880+
862881
for (pos[0]=0;pos[0]<m_numLines[0];++pos[0])
863882
{
864883
for (pos[1]=0;pos[1]<m_numLines[1];++pos[1])
@@ -921,9 +940,16 @@ bool SAR_Calculation::CalcAveragedSAR(ArrayLib::ArrayIJK<float> & SAR)
921940
}
922941
}
923942
++loc;
943+
if (m_progress && (loc%prog_N == 0))
944+
{
945+
std::cout << ".";
946+
std::cout.flush();
947+
}
924948
}
925949
}
926950
}
951+
if (m_progress)
952+
std::cout << " Done" << std::endl;
927953

928954
if (m_Valid+m_Used+m_Unused+m_AirVoxel!=m_numLines[0]*m_numLines[1]*m_numLines[2])
929955
{

tools/sar_calculation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class SAR_EXPORT SAR_Calculation
4545
//! Set the debug level
4646
void SetDebugLevel(int level) {m_DebugLevel=level;}
4747

48+
//! Enable progress output
49+
void EnableProgress(bool enable=true) {m_progress=enable;}
50+
4851
//! Set the used averaging method
4952
bool SetAveragingMethod(SARAveragingMethod method, bool silent=false);
5053

@@ -107,6 +110,8 @@ class SAR_EXPORT SAR_Calculation
107110

108111
int m_DebugLevel;
109112

113+
bool m_progress = false;
114+
110115
/*********** SAR calculation parameter and settings ***********/
111116
float m_massTolerance;
112117
unsigned int m_maxMassIterations;

0 commit comments

Comments
 (0)