diff --git a/trick_source/trick_utils/SAIntegrator/include/SAIntegrator.hh b/trick_source/trick_utils/SAIntegrator/include/SAIntegrator.hh index 399a49e6..34a900e7 100644 --- a/trick_source/trick_utils/SAIntegrator/include/SAIntegrator.hh +++ b/trick_source/trick_utils/SAIntegrator/include/SAIntegrator.hh @@ -83,7 +83,6 @@ namespace SA { class EulerIntegrator : public FirstOrderODEVariableStepIntegrator { public: - double *derivs; EulerIntegrator(); EulerIntegrator( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc dfunc, void* udata); EulerIntegrator( double h, unsigned int N, double* in_out_vars[], DerivsFunc derivs_func, void* udata); @@ -97,8 +96,6 @@ namespace SA { class HeunsMethod : public FirstOrderODEVariableStepIntegrator { public: - double *wstate; - double *derivs[2]; HeunsMethod(); HeunsMethod( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc dfunc, void* udata); HeunsMethod( double h, unsigned int N, double* in_out_vars[], DerivsFunc derivs_func, void* udata); @@ -112,8 +109,6 @@ namespace SA { class RK2Integrator : public FirstOrderODEVariableStepIntegrator { public: - double *wstate; - double *derivs[2]; RK2Integrator(); RK2Integrator( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc derivs_func, void* udata); RK2Integrator( double h, unsigned int N, double* in_out_vars[], DerivsFunc derivs_func, void* udata); @@ -127,9 +122,6 @@ namespace SA { class RK4Integrator : public FirstOrderODEVariableStepIntegrator { public: - double *wstate[3]; - double *derivs[4]; - RK4Integrator(); RK4Integrator( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc dfunc, void* udata); RK4Integrator( double h, unsigned int N, double* in_out_vars[], DerivsFunc derivs_func, void* udata); @@ -143,9 +135,6 @@ namespace SA { class RK3_8Integrator : public FirstOrderODEVariableStepIntegrator { public: - double *wstate[3]; - double *derivs[4]; - RK3_8Integrator(); RK3_8Integrator( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc dfunc, void* udata); RK3_8Integrator( double h, unsigned int N, double* in_out_vars[], DerivsFunc derivs_func, void* udata); @@ -180,7 +169,7 @@ namespace SA { EulerCromerIntegrator& operator=( const EulerCromerIntegrator& rhs); ~EulerCromerIntegrator(); void advanceIndyVar(double h); - void step( double dt); + void step(double dt); void step(); void load(); void unload(); diff --git a/trick_source/trick_utils/SAIntegrator/src/SAIntegrator.cpp b/trick_source/trick_utils/SAIntegrator/src/SAIntegrator.cpp index 425ee888..74339267 100644 --- a/trick_source/trick_utils/SAIntegrator/src/SAIntegrator.cpp +++ b/trick_source/trick_utils/SAIntegrator/src/SAIntegrator.cpp @@ -1,5 +1,6 @@ #include +#include #include #include // std::cout, std::cerr #include // std::copy @@ -185,6 +186,7 @@ void SA::FirstOrderODEIntegrator::step() { } advanceIndyVar(); } + static std::ostream& stream_double_array(std::ostream& os, unsigned int n, double* d_array) { if (d_array == NULL) { os << " NULL\n"; @@ -266,7 +268,7 @@ double SA::FirstOrderODEVariableStepIntegrator::undo_integrate() { void SA::FirstOrderODEVariableStepIntegrator::add_Rootfinder( double tolerance, SlopeConstraint constraint, RootErrorFunc rfunc) { root_finder = new RootFinder(tolerance, constraint); if (rfunc == NULL) { - throw std::invalid_argument("OOPS! RootErrorFunc function-pointer must be NULL."); + throw std::invalid_argument("OOPS! RootErrorFunc function-pointer is NULL."); } root_error_func = rfunc; } @@ -325,60 +327,40 @@ std::ostream& SA::operator<<(std::ostream& os, const FirstOrderODEVariableStepIn // ------------------------------------------------------------ // Default Constructor SA::EulerIntegrator::EulerIntegrator() -: FirstOrderODEVariableStepIntegrator() { - derivs = new double[state_size]; -} +: FirstOrderODEVariableStepIntegrator() {} // Constructor SA::EulerIntegrator::EulerIntegrator( double h, unsigned int N, double* in_vars[], double* out_vars[], DerivsFunc dfunc, void* udata) - : FirstOrderODEVariableStepIntegrator(h, N, in_vars, out_vars, dfunc, udata) { - derivs = new double[N]; -} + : FirstOrderODEVariableStepIntegrator(h, N, in_vars, out_vars, dfunc, udata) {} // Constructor SA::EulerIntegrator::EulerIntegrator( double h, unsigned int N, double* in_out_vars[], DerivsFunc dfunc, void* udata) : EulerIntegrator(h, N, in_out_vars, in_out_vars, dfunc, udata) {} - // Copy Constructor SA::EulerIntegrator::EulerIntegrator(const EulerIntegrator& other) - : FirstOrderODEVariableStepIntegrator(other) { - derivs = new double[state_size]; - std::copy( other.derivs, other.derivs + state_size, derivs); -} + : FirstOrderODEVariableStepIntegrator(other) {} // Assignment Operator SA::EulerIntegrator& SA::EulerIntegrator::operator=( const SA::EulerIntegrator& rhs) { if (this != &rhs) { - double* new_derivs = 0; - try { - new_derivs = new double[rhs.state_size]; - } catch (...) { - delete new_derivs; - throw; - } FirstOrderODEVariableStepIntegrator::operator=(rhs); - if (derivs != NULL) delete derivs; - derivs = new_derivs; - std::copy( rhs.derivs, rhs.derivs + state_size, derivs); } return *this; } //Destructor -SA::EulerIntegrator::~EulerIntegrator() { - if (derivs != NULL) delete derivs; -} +SA::EulerIntegrator::~EulerIntegrator() {} + void SA::EulerIntegrator::variable_step( double h) { + double derivs[state_size]; (*derivs_func)( X_in, inState, derivs, user_data); for (unsigned int i=0; i