Added RK4 solver

This commit is contained in:
Travis Hunter 2023-03-15 19:30:56 -06:00
parent 14b72ab1e0
commit 8d663f858b
13 changed files with 260 additions and 4 deletions

View File

@ -13,6 +13,10 @@
<property name="windowTitle"> <property name="windowTitle">
<string>QtRocket</string> <string>QtRocket</string>
</property> </property>
<property name="windowIcon">
<iconset>
<normaloff>resources/qtrocket.png</normaloff>resources/qtrocket.png</iconset>
</property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="2"> <layout class="QVBoxLayout" name="verticalLayout" stretch="2">
<item> <item>

View File

@ -12,9 +12,11 @@ int main(int argc, char *argv[])
// TODO: Only support US English at the moment. Anyone want to help translate? // TODO: Only support US English at the moment. Anyone want to help translate?
QTranslator translator; QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages(); const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) { for (const QString &locale : uiLanguages)
{
const QString baseName = "qtrocket_" + QLocale(locale).name(); const QString baseName = "qtrocket_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) { if (translator.load(":/i18n/" + baseName))
{
a.installTranslator(&translator); a.installTranslator(&translator);
break; break;
} }

View File

@ -17,13 +17,17 @@ SOURCES += \
qcustomplot.cpp \ qcustomplot.cpp \
sim/AtmosphericModel.cpp \ sim/AtmosphericModel.cpp \
sim/GravityModel.cpp \ sim/GravityModel.cpp \
sim/Propagator.cpp \
sim/RK4Solver.cpp \
sim/SphericalGeoidModel.cpp \ sim/SphericalGeoidModel.cpp \
sim/SphericalGravityModel.cpp \ sim/SphericalGravityModel.cpp \
sim/USStandardAtmosphere.cpp \ sim/USStandardAtmosphere.cpp \
sim/WindModel.cpp \ sim/WindModel.cpp \
utils/BinMap.cpp \ utils/BinMap.cpp \
utils/CurlConnection.cpp \ utils/CurlConnection.cpp \
utils/ThrustCurveAPI.cpp utils/ThrustCurveAPI.cpp \
utils/math/Quaternion.cpp \
utils/math/Vector3.cpp
HEADERS += \ HEADERS += \
QtRocket.h \ QtRocket.h \
@ -32,8 +36,11 @@ HEADERS += \
model/Thrustcurve.h \ model/Thrustcurve.h \
qcustomplot.h \ qcustomplot.h \
sim/AtmosphericModel.h \ sim/AtmosphericModel.h \
sim/DESolver.h \
sim/GeoidModel.h \ sim/GeoidModel.h \
sim/GravityModel.h \ sim/GravityModel.h \
sim/Propagator.h \
sim/RK4Solver.h \
sim/SphericalGeoidModel.h \ sim/SphericalGeoidModel.h \
sim/SphericalGravityModel.h \ sim/SphericalGravityModel.h \
sim/USStandardAtmosphere.h \ sim/USStandardAtmosphere.h \
@ -41,7 +48,9 @@ HEADERS += \
utils/BinMap.h \ utils/BinMap.h \
utils/CurlConnection.h \ utils/CurlConnection.h \
utils/ThrustCurveAPI.h \ utils/ThrustCurveAPI.h \
utils/math/Constants.h utils/math/Constants.h \
utils/math/Quaternion.h \
utils/math/Vector3.h
FORMS += \ FORMS += \
QtRocket.ui QtRocket.ui

BIN
resources/qtrocket.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

18
sim/DESolver.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef SIM_DESOLVER_H
#define SIM_DESOLVER_H
namespace sim
{
class DESolver
{
public:
DESolver() {}
virtual ~DESolver() {}
virtual double step(double curVal, double t, double dt) = 0;
};
} // namespace sim
#endif // SIM_DESOLVER_H

10
sim/Propagator.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "Propagator.h"
namespace sim {
Propagator::Propagator()
{
}
} // namespace sim

18
sim/Propagator.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef SIM_PROPAGATOR_H
#define SIM_PROPAGATOR_H
namespace sim
{
class Propagator
{
public:
Propagator();
private:
};
} // namespace sim
#endif // SIM_PROPAGATOR_H

19
sim/RK4Solver.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "RK4Solver.h"
namespace sim {
double RK4Solver::step(double curVal, double t, double dt)
{
double retVal(0.0);
k1 = de(t, curVal);
k2 = de(t + dt / 2.0, curVal + (dt * k1 / 2.0));
k3 = de(t + dt / 2.0, curVal + (dt * k2 / 2.0));
k4 = de(t + dt, curVal + dt * k3);
retVal = curVal + (1.0 / 6.0)*dt*(k1 + 2.0*k2 + 2.0*k3 + k4);
return retVal;
}
} // namespace sim

27
sim/RK4Solver.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef SIM_RK4SOLVER_H
#define SIM_RK4SOLVER_H
#include "DESolver.h"
#include <functional>
namespace sim {
class RK4Solver : public DESolver
{
public:
RK4Solver(const std::function<double(double, double)>& d) : de(d) {}
virtual ~RK4Solver() {}
virtual double step(double curVal, double t, double dt) override;
private:
std::function<double(double, double)> de;
double k1, k2, k3, k4;
};
} // namespace sim
#endif // SIM_RK4SOLVER_H

11
utils/math/Quaternion.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "Quaternion.h"
namespace math
{
Quaternion::Quaternion()
{
}
} // namespace math

32
utils/math/Quaternion.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef MATH_QUATERNION_H
#define MATH_QUATERNION_H
#include "Vector3.h"
namespace math
{
class Quaternion
{
public:
Quaternion();
Quaternion(double r, const Vector3& i);
Quaternion(double r, double i1, double i2, double i3);
~Quaternion();
Quaternion operator-();
Quaternion operator-(const Quaternion& rhs);
Quaternion operator+(const Quaternion& rhs);
Quaternion operator*(double s);
Quaternion operator*(const Quaternion& rhs);
private:
double real;
Vector3 imag;
};
} // namespace math
#endif // MATH_QUATERNION_H

66
utils/math/Vector3.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "Vector3.h"
namespace math
{
Vector3::Vector3()
: x1(0.0),
x2(0.0),
x3(0.0)
{
}
Vector3::Vector3(const double& inX1,
const double& inX2,
const double& inX3)
: x1(inX1),
x2(inX2),
x3(inX3)
{
}
Vector3::Vector3(const Vector3& o)
: x1(o.x1),
x2(o.x2),
x3(o.x3)
{
}
Vector3::~Vector3()
{}
Vector3 Vector3::operator=(const Vector3& rhs)
{
return Vector3(rhs.x1, rhs.x2, rhs.x3);
}
Vector3 Vector3::operator-()
{
return Vector3(-x1, -x2, -x3);
}
Vector3 Vector3::operator-(const Vector3& rhs)
{
return Vector3(x1 - rhs.x1,
x2 - rhs.x2,
x3 - rhs.x3);
}
Vector3 Vector3::operator+(const Vector3& rhs)
{
return Vector3(x1 + rhs.x1,
x2 + rhs.x2,
x3 + rhs.x3);
}
Vector3 Vector3::operator*(const double& s)
{
return Vector3(x1 * s,
x2 * s,
x3 * s);
}
} // namespace math

40
utils/math/Vector3.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef MATH_VECTOR3_H
#define MATH_VECTOR3_H
namespace math
{
class Vector3
{
public:
Vector3();
Vector3(const double& inX1,
const double& inX2,
const double& inX3);
Vector3(const Vector3& o);
~Vector3();
Vector3 operator=(const Vector3& rhs);
Vector3 operator-();
Vector3 operator-(const Vector3& rhs);
Vector3 operator+(const Vector3& rhs);
Vector3 operator*(const double& s);
double getX1() { return x1; }
double getX2() { return x2; }
double getX3() { return x3; }
private:
double x1;
double x2;
double x3;
};
} // namespace math
#endif // MATH_VECTOR3_H