x1200.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xode.h"
4 #include "xmodel.h"
5 #include "xphysics.h"
6 #include <optional>
7 
8 namespace nmx::apps::x1200 {
9 
10 using namespace gravitation;
11 
16 class X1200 : public XModel
17 {
18 private:
19  //Brennschluss: Zeit, Geschwindigkeit, Höhe
20  double _zB, _vB, _tB;
21 
22 public:
23  //Anfangswerte
24  using IValues = std::array<double, 2>;
25 
26  //Eingabewerte
27  const double mass0; // Masse der Rakete plus Treibstoff t=0
28  const double massRocket; // Masse der Rakete ohne Treibstoff
29  const double lambda; // Brennrate
30  const double vRelative; // Relativgeschwindigkeit
31  const double z0, v0; // Anfangsbedingungen
32 
33 public:
44  inline X1200(double minit,
45  double mrocket, //
46  double l,
47  double vrocket,
48  IValues ivals)
49  : XModel(__func__)
50  , mass0{ minit }
51  , massRocket{ mrocket }
52  , lambda{ l }
53  , vRelative{ vrocket }
54  , z0{ ivals[0] }
55  , v0{ ivals[1] } {
57  { mass0 > 0,
58  massRocket > 0, //
59  lambda > 0,
60  vRelative > 0,
61  z0 >= 0,
62  v0 >= 0 });
63  _tB = (mass0 - massRocket) / lambda;
64  _vB = vRelative * log(mass0 / massRocket) - Earth::g * _tB;
65  _zB = vRelative / lambda * (mass0 - massRocket + massRocket * log(massRocket / mass0))
66  - 0.5 * Earth::g * pow(_tB, 2);
67  }
68 
74  inline bool is_propellant(double t) const { return t <= _tB; }
75 
81  inline double mass(double t) const { //
82  if (is_propellant(t)) {
83  return mass0 - lambda * t;
84  }
85  return massRocket;
86  }
87 
93  inline double acceleration(double t) const { //
94  return lambda / mass(t) * vRelative - Earth::g;
95  }
96 
102  inline double height(double t) const {
103  const double term0 = mass(t) / mass0;
104  const double term1 = term0 * log(term0) * vRelative;
105  const double term2 = 0.5 * Earth::g * pow(t, 2);
106  return vRelative * t + (mass0 / lambda) * term1 - term2;
107  }
108 
114  inline double velocity(double t) const {
115  const double term = mass0 / mass(t);
116  return vRelative * log(term) - Earth::g * t;
117  }
118 
124  inline double time() const { return _tB; }
125 
131  inline double velocity() const { return _vB; }
132 
138  inline double height() const { return _zB; }
139 }; //X1200
140 
145 class C1200 : public X1200
146 {
147 public:
149  using Data = Data<7>;
150  friend Ode;
151 
152 protected:
153  Data _data; //speichere numerisch berechnete und exakte Werte
154 
155 public:
156  using X1200::X1200; //erbe Konstruktoren der Modellklasse
157 
165  inline int odefn(double t, const double fin[], double fout[]) {
166  (void) t;
167  fout[0] = -lambda;
168  fout[1] = fin[2];
169  fout[2] = lambda / fin[0] * vRelative - Earth::g;
170  return GSL_SUCCESS;
171  }
172 
178  void exec(double t0 = 0, double tstep = 1) {
179  //Instanz zur Lösung der Differenzialgleichung
180  Ode myOde{ *this, 1e-2, 1e-6, 0 };
181  myOde.set_init_conditions(0, { mass0, z0, v0 });
182  double t = t0, dt = tstep;
183 
184  //rechne bis der Treibstoff verbraucht ist
185  while (myOde[0] > massRocket) {
186  _data += {
187  t,
188  myOde[0], //Masse
189  myOde[1], // Höhe
190  myOde[2] // Geschwindigkeit
191  };
192  t += dt;
193  myOde.solve(t);
194  }
195 
196  //exakte Werte
197  for (auto &crow : _data.data()) {
198  const double t = crow[0];
199  crow[4] = mass(t);
200  crow[5] = height(t);
201  crow[6] = velocity(t);
202  }
203  }
204 
208  inline void save_data() {
209  save(_data, Output::plot);
210  save(_data.select_total_rows(8), Output::latex);
211  }
212 }; //C1200
213 
218 inline void run() {
219  //Programmparameter
220  const double m0 = 2.85e6;
221  const double M = 0.27 * m0;
222  const double lambda = 13.84e3;
223 
224  //Umrechnung in m/s (benutzerdefinierte Literale)
225  const double vR = 2.46_km; // km/s
226  const double z0 = 0.0;
227  const double v0 = 0.0;
228 
229  //Rechenmodell
230  C1200 cobj{ m0, M, lambda, vR, { z0, v0 } };
231  cobj.exec();
232  cobj.save_data();
233 }
234 
235 } // namespace nmx::apps::x1200
The X1200 class Bewegung einer Rakete in einem konstanten Gravitationsfeld (Modellklasse) ...
Definition: x1200.h:16
double mass(double t) const
mass Masse als Funktion der Zeit
Definition: x1200.h:81
void exec(double t0=0, double tstep=1)
exec Berechnung der numerischen Lösung
Definition: x1200.h:178
X1200(double minit, double mrocket, double l, double vrocket, IValues ivals)
X1200 Konstruktor mit Liste aller Eingabeparameter.
Definition: x1200.h:44
double velocity() const
velocity Geschwindigkeit zum Zeitpunkt zu dem der gesamte Treibstoff verbraucht ist ...
Definition: x1200.h:131
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
double velocity(double t) const
velocity Geschwindigkeit als Funktion der Zeit
Definition: x1200.h:114
const double lambda
Definition: x1200.h:29
const double z0
Definition: x1200.h:31
The Odeiv2 class numerische Lösung eines Systems von N Differenzialgleichungen Schnittstelle zur gsl...
Definition: xode.h:20
The XModel class Basisklasse speichert eine ID in Form einer Zeichenkette enthält Hilfsfunktionen zur...
Definition: xmodel.h:22
#define nmx_msg
Definition: xerror.h:113
int odefn(double t, const double fin[], double fout[])
odefn Schnittstelle zur gsl
Definition: x1200.h:165
void save_data()
save_data schreibe berechnete Daten
Definition: x1200.h:208
bool is_propellant(double t) const
is_propellant Treibstoff als Funktion der Zeit
Definition: x1200.h:74
const double vRelative
Definition: x1200.h:30
double height() const
height Höhe zum Zeitpunkt zum dem der gesamte Treibstoff verbraucht ist
Definition: x1200.h:138
The C1200 class Bewegung einer Rakete in einem konstanten Gravitationsfeld (Rechenmodell) ...
Definition: x1200.h:145
double height(double t) const
height Höhe als Funktion der Zeit
Definition: x1200.h:102
std::array< double, 2 > IValues
Definition: x1200.h:24
const double mass0
Definition: x1200.h:27
double acceleration(double t) const
acceleration Beschleunigung als Funktion der Zeit
Definition: x1200.h:93
void run()
run Bewegung einer Rakete in einem konstanten Gravitationsfeld (Berechnung von Beispielwerten) ...
Definition: x1200.h:218
const double massRocket
Definition: x1200.h:28
double time() const
time Zeitpunkt zu dem der gesamte Treibstoff verbraucht ist
Definition: x1200.h:124
static const Format latex
Definition: xoutput.h:17
static constexpr double g
Definition: xphysics.h:20
static void all(const std::string &s, std::initializer_list< bool > lst)
input teste mehrere Bedingungen auf einmal
Definition: xerror.h:76
static const Format plot
Definition: xoutput.h:18