Breakout Regula Falsi Bounds setter functions. Ref #995

This commit is contained in:
Penn, John M 047828115 2020-05-04 16:10:35 -05:00
parent e303b2ac9b
commit 9452f928d0
3 changed files with 20 additions and 13 deletions

View File

@ -54,6 +54,8 @@ typedef struct {
double regula_falsi(double my_time, REGULA_FALSI * R);
void reset_regula_falsi(double my_time, REGULA_FALSI * R);
void regula_falsi_set_upper (double my_time, double error, REGULA_FALSI * R);
void regula_falsi_set_lower (double my_time, double error, REGULA_FALSI * R);
#ifdef __cplusplus
}

View File

@ -127,14 +127,11 @@ double Contact::collision() {
if ((ii==first) && (jj==second)) {
reset_regula_falsi( now, &ballAssociations[association_index] );
} else {
//Set X_upper and t_upper to event values.
// Update the remaining REGULA_FALSI objects to the current event state.
double xdiff = balls[ii]->pos[0] - balls[jj]->pos[0];
double ydiff = balls[ii]->pos[1] - balls[jj]->pos[1];
double distance = sqrt( xdiff * xdiff + ydiff * ydiff) - (balls[ii]->radius + balls[jj]->radius);
ballAssociations[association_index].error = distance;
ballAssociations[association_index].x_upper = distance;
ballAssociations[association_index].t_upper = now;
ballAssociations[association_index].upper_set = 1;
regula_falsi_set_upper (now, distance, &ballAssociations[association_index]);
}
}
}

View File

@ -4,6 +4,20 @@
#define M_ABS(x) ((x) < 0 ? -(x) : (x))
#include "trick/regula_falsi.h"
void regula_falsi_set_upper (double time, double error, REGULA_FALSI *R) {
R->error = error;
R->x_upper = error;
R->t_upper = time;
R->upper_set = 1;
}
void regula_falsi_set_lower (double time, double error, REGULA_FALSI *R) {
R->error = error;
R->x_lower = error;
R->t_lower = time;
R->lower_set = 1;
}
double regula_falsi(
/* Return: Est. time to go to err
function zero point */
@ -26,15 +40,9 @@ double regula_falsi(
}
}
if (R->error < 0.0) {
/* Set lower bounds */
R->x_lower = R->error;
R->t_lower = time;
R->lower_set = 1;
regula_falsi_set_lower(time, R->error, R);
} else if (R->error > 0.0) {
/* Set upper bounds */
R->x_upper = R->error;
R->t_upper = time;
R->upper_set = 1;
regula_falsi_set_upper(time, R->error, R);
}
R->iterations++;