Skip to content

Commit

Permalink
Merge pull request #163 from doluk/speedstep-timestate
Browse files Browse the repository at this point in the history
Bug fixes/Enhancement us_edit/speedsteps
  • Loading branch information
ehb54 authored Dec 13, 2024
2 parents 7403f5f + 7b8ba3f commit 9766583
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 64 deletions.
2 changes: 1 addition & 1 deletion programs/us_edit/us_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5296,7 +5296,7 @@ void US_Edit::set_data_over_lamda() {
trx_b = trx;
int min_xval = -100000000;
int max_xval = 100000000;
int dx = -1000;
int dx = 1; // preventing that dx becomes 0 and causing an infinite loop
for ( int jwx = 0; jwx < nwaveln; jwx++ )
{
edata = &allData[ trx ]; // Triple data
Expand Down
81 changes: 18 additions & 63 deletions utils/us_simparms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,74 +597,29 @@ void US_SimulationParameters::computeSpeedSteps(
computeSpeedSteps( &allrData[ 0 ].scanData, speedsteps );
return;
}

// Get indexes to low and high step scan
int ndx1 = -1;
int ndx2 = -1;
double timel = 1e+20;
double timeh = -1e+20;

for ( int ii = 0; ii < allrData.count(); ii++ )
{
int ls = allrData[ ii ].scanCount() - 1;
double time1 = allrData[ ii ].scanData[ 0 ].seconds;
double time2 = allrData[ ii ].scanData[ ls ].seconds;

if ( time1 < timel )
{ // Accumulate low scan time
timel = time1; // Lowest scan time
ndx1 = ii; // Triple to which it belongs
}

if ( time2 > timeh )
{ // Accumulate high scan time
timeh = time2; // High scan time
ndx2 = ii; // Triple to which it belongs
QVector<US_DataIO::Scan> scans;
QVector<double> times;

for ( int ii = 0; ii < allrData.count(); ii++ ) {
for ( int jj = 0; jj < allrData[ii].scanCount(); jj++ ) {
if ( !times.contains(allrData[ii].scanData[jj].seconds) ) {
scans << allrData[ii].scanData[jj];
times << allrData[ii].scanData[jj].seconds;
}
}
}
times.clear();

// Compute time steps for two triples at the extreme
QVector< SpeedProfile > speedstps2;
computeSpeedSteps( &allrData[ ndx1 ].scanData, speedsteps );
computeSpeedSteps( &allrData[ ndx2 ].scanData, speedstps2 );

// Merge them so step time ranges cover all triples' time ranges
for ( int ii = 0; ii < speedsteps.count(); ii++ )
{
SpeedProfile sp1 = speedsteps[ ii ];
SpeedProfile sp2 = speedstps2[ ii ];
double time1 = sp1.time_first;
double time2 = sp2.time_last;
double w2t1 = sp1.w2t_first;
double w2t2 = sp2.w2t_last;
double delay_secs = sp1.delay_hours * 3600.0 +
sp1.delay_minutes * 60.0;

if ( sp2.time_first < sp1.time_first )
{ // Low time in the step and its corresponding omega2t
time1 = sp2.time_first;
w2t1 = sp2.w2t_first;
}

if ( sp1.time_last > sp2.time_last )
{ // High time in the step and its corresponding omega2t
time2 = sp1.time_last;
w2t2 = sp1.w2t_last;
struct SortBySeconds {
bool operator()(const US_DataIO::Scan& a, const US_DataIO::Scan& b) const {
return a.seconds < b.seconds;
}
};
// Sort the scans by their respective attribute seconds
std::sort(scans.begin(), scans.end(), SortBySeconds());

// Reset, recompute time and omega2t values for step
double step_secs = time2 - time1 + delay_secs;
sp1.duration_hours = (int)( step_secs / 3600.0 );
sp1.duration_minutes = ( step_secs / 60.0 )
- ( (double)sp1.duration_hours * 60.0 );
sp1.w2t_first = w2t1;
sp1.w2t_last = w2t2;
sp1.time_first = qRound( time1 );
sp1.time_last = qRound( time2 );
sp1.avg_speed = ( sp1.avg_speed + sp2.avg_speed ) * 0.5;

speedsteps[ ii ] = sp1; // Save merged speed step
}
// Compute time steps for two triples at the extreme
computeSpeedSteps( &scans, speedsteps );
}

// Set parameters from hardware files, related to rotor and centerpiece
Expand Down

0 comments on commit 9766583

Please sign in to comment.