Added RK4 solver
This commit is contained in:
parent
14b72ab1e0
commit
8d663f858b
@ -13,6 +13,10 @@
|
||||
<property name="windowTitle">
|
||||
<string>QtRocket</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>resources/qtrocket.png</normaloff>resources/qtrocket.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="2">
|
||||
<item>
|
||||
|
6
main.cpp
6
main.cpp
@ -12,9 +12,11 @@ int main(int argc, char *argv[])
|
||||
// TODO: Only support US English at the moment. Anyone want to help translate?
|
||||
QTranslator translator;
|
||||
const QStringList uiLanguages = QLocale::system().uiLanguages();
|
||||
for (const QString &locale : uiLanguages) {
|
||||
for (const QString &locale : uiLanguages)
|
||||
{
|
||||
const QString baseName = "qtrocket_" + QLocale(locale).name();
|
||||
if (translator.load(":/i18n/" + baseName)) {
|
||||
if (translator.load(":/i18n/" + baseName))
|
||||
{
|
||||
a.installTranslator(&translator);
|
||||
break;
|
||||
}
|
||||
|
13
qtrocket.pro
13
qtrocket.pro
@ -17,13 +17,17 @@ SOURCES += \
|
||||
qcustomplot.cpp \
|
||||
sim/AtmosphericModel.cpp \
|
||||
sim/GravityModel.cpp \
|
||||
sim/Propagator.cpp \
|
||||
sim/RK4Solver.cpp \
|
||||
sim/SphericalGeoidModel.cpp \
|
||||
sim/SphericalGravityModel.cpp \
|
||||
sim/USStandardAtmosphere.cpp \
|
||||
sim/WindModel.cpp \
|
||||
utils/BinMap.cpp \
|
||||
utils/CurlConnection.cpp \
|
||||
utils/ThrustCurveAPI.cpp
|
||||
utils/ThrustCurveAPI.cpp \
|
||||
utils/math/Quaternion.cpp \
|
||||
utils/math/Vector3.cpp
|
||||
|
||||
HEADERS += \
|
||||
QtRocket.h \
|
||||
@ -32,8 +36,11 @@ HEADERS += \
|
||||
model/Thrustcurve.h \
|
||||
qcustomplot.h \
|
||||
sim/AtmosphericModel.h \
|
||||
sim/DESolver.h \
|
||||
sim/GeoidModel.h \
|
||||
sim/GravityModel.h \
|
||||
sim/Propagator.h \
|
||||
sim/RK4Solver.h \
|
||||
sim/SphericalGeoidModel.h \
|
||||
sim/SphericalGravityModel.h \
|
||||
sim/USStandardAtmosphere.h \
|
||||
@ -41,7 +48,9 @@ HEADERS += \
|
||||
utils/BinMap.h \
|
||||
utils/CurlConnection.h \
|
||||
utils/ThrustCurveAPI.h \
|
||||
utils/math/Constants.h
|
||||
utils/math/Constants.h \
|
||||
utils/math/Quaternion.h \
|
||||
utils/math/Vector3.h
|
||||
|
||||
FORMS += \
|
||||
QtRocket.ui
|
||||
|
BIN
resources/qtrocket.png
Normal file
BIN
resources/qtrocket.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
18
sim/DESolver.h
Normal file
18
sim/DESolver.h
Normal 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
10
sim/Propagator.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "Propagator.h"
|
||||
|
||||
namespace sim {
|
||||
|
||||
Propagator::Propagator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace sim
|
18
sim/Propagator.h
Normal file
18
sim/Propagator.h
Normal 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
19
sim/RK4Solver.cpp
Normal 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
27
sim/RK4Solver.h
Normal 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
11
utils/math/Quaternion.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "Quaternion.h"
|
||||
|
||||
namespace math
|
||||
{
|
||||
|
||||
Quaternion::Quaternion()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace math
|
32
utils/math/Quaternion.h
Normal file
32
utils/math/Quaternion.h
Normal 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
66
utils/math/Vector3.cpp
Normal 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
40
utils/math/Vector3.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user