x2000.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 
7 namespace nmx::apps::x2000 {
8 
9 using namespace gravitation;
10 
15 class X2000 : public XModel
16 {
17 private:
18  double _mOverBeta; // m/b
19  double _vTerminal; //Endgeschwindigkeit
20 
21 public:
22  //Eingabeparameter
23  //Masse,Koeffizient (Reibung)
24  const double mass, beta;
25  // Anfangsbedingungen
26  const double y0, v0;
27 
28 public:
36  X2000(double m, double b, double y0, double v0)
37  : XModel(__func__)
38  , mass{ m }
39  , beta{ b }
40  , y0{ y0 }
41  , v0{ v0 } {
42  Check::all(nmx_msg, { mass > 0, beta >= 0 });
43  _mOverBeta = (mass) / (beta);
44  _vTerminal = -_mOverBeta * gravitation::Earth::g;
45  }
46 
51  inline double terminal_velocity() const { return _vTerminal; }
52 
58  inline double v(double t) const {
59  return _vTerminal + (v0 - _vTerminal) * exp(-t / _mOverBeta);
60  }
61 
67  inline double y(double t) const {
68  const double term1 = (v0 - _vTerminal);
69  const double term2 = (1 - exp(-t / _mOverBeta));
70  return _vTerminal * t + _mOverBeta * term1 * term2;
71  }
72 
77  inline double time4ymax() const { //
78  return _mOverBeta * log((_vTerminal - v0) / _vTerminal);
79  }
80 
85  inline double ymax() const { return y(time4ymax()); }
86 }; //X2000
87 
92 class C2000 : public X2000
93 {
94 public:
96  friend Ode;
97  using Data = Data<8>;
98 
99 private:
100  // Zahlentabelle zur Speicherung der Ergebnisse
101  Data _data;
102 
103 public:
104  // benutze Konstruktoren der Basisklasse
105  using X2000::X2000;
106 
114  inline int odefn(double t, const double fin[], double fout[]) {
115  (void) t;
116  fout[0] = fin[1];
117  fout[1] = -Earth::g - (beta / (mass)) * fin[1];
118  return GSL_SUCCESS;
119  }
120 
125  inline void exec() {
126  Ode myOde{ *this, 1e-2, 1e-9, 0 };
127  myOde.set_init_conditions(0, { y0, v0 });
128  double t = 0, dt = 0.01;
129  do {
130  _data += { t, myOde[0], myOde[1] };
131  t += dt;
132  myOde.solve(t);
133  } while (myOde[0] >= 0); //stop wenn Kugel den Boden erreicht
134 
135  //Energien und exakte Werte werden hinzugefügt
136  for (auto &crow : _data.data()) {
137  const double t = crow[0];
138  const double yval = crow[1];
139  const double vval = crow[2];
140  crow[3] = Mechanics::kinetic_energy(mass, vval);
141  crow[4] = Mechanics::potential_energy(mass, yval);
142  crow[5] = crow[3] + crow[4]; //Gesamtenergie
143  crow[6] = y(t);
144  crow[7] = v(t);
145  }
146  }
147 
152  void save_data() {
153  save(_data, Output::plot, beta);
154  std::ofstream ofs = get_output_stream(Output::latex, beta);
155 
156  //ändere Formatierung der Zahlen für die LaTeX-Tabelle
157  ofs << std::fixed << std::setprecision(4);
158 
159  //speichere insgesamt 7 Reihen (5 + erste + letzte)
160  _data.select_total_rows(4).save(ofs, Output::latex);
161  }
162 }; //C2000
163 
168 inline void run() {
169  const double y0 = 0.0, v0 = 10.0; //Anfangsbedingungen
170  const double mass = 1.0;
171 
172  for (const auto beta : { 3.0, 6.0, 9.0 }) {
173  C2000 cobj{ mass, beta, y0, v0 }; //Rechenmodell
174  cobj.exec();
175  cobj.save_data();
176  }
177 }
178 
179 } // namespace nmx::apps::x2000
The X2000 class Bewegung im konstanten Gravitationsfeld mit Reibung nach Stokes (Modellklasse) ...
Definition: x2000.h:15
static double kinetic_energy(double mass, double velocity)
kinetic_energy Hilfsfunktion
Definition: xphysics.h:38
const double mass
Definition: x2000.h:24
double time4ymax() const
time4ymax
Definition: x2000.h:77
double y(double t) const
y Ort als Funktion der Zeit
Definition: x2000.h:67
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
int odefn(double t, const double fin[], double fout[])
odefn Schnittstelle zur gsl
Definition: x2000.h:114
const double y0
Definition: x2000.h:26
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
double terminal_velocity() const
terminalVelocity
Definition: x2000.h:51
double ymax() const
ymax
Definition: x2000.h:85
void save_data()
save_data speichere Daten im Diagramm- und Tabellenformat.
Definition: x2000.h:152
static double potential_energy(double mass, double height)
potential_energy Hilfsfunktion
Definition: xphysics.h:48
void run()
run Bewegung im konstanten Gravitationsfeld mit Reibung nach Stokes (Beispieldaten) ...
Definition: x2000.h:168
Data< 8 > Data
Definition: x2000.h:97
The C2000 class Bewegung im konstanten Gravitationsfeld mit Reibung nach Stokes (numerisch berechnete...
Definition: x2000.h:92
void exec()
solve_ode numerische Lösung der DGL numerische Lösung der Bewegungsgleichung
Definition: x2000.h:125
X2000(double m, double b, double y0, double v0)
X2000 Konstruktor.
Definition: x2000.h:36
double v(double t) const
v Geschwindigkeit als Funktion der Zeit
Definition: x2000.h:58
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