x2010.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::x2010 {
8 
9 using namespace gravitation;
10 
15 class X2010 : public XModel
16 {
17 private:
18  //Endgeschwindigkeit
19  double vTerminal = 0;
20  //Steigzeit und Steighöhe
21  double tMax = 0, yMax = 0;
22  double gvt = 0, vt2g = 0;
23 
24 public:
25  // Eingabeparameter
26  //Masse, Reibungskoeffizient
27  const double mass, gamma;
28  //Anfangsbedingungen
29  const double y0, v0;
30 
31 public:
39  inline X2010(double m, double gm, double y0in, double v0in)
40  : XModel(__func__)
41  , mass{ m }
42  , gamma{ gm }
43  , y0{ y0in }
44  , v0{ v0in } {
45  //teste Eingabewerte
46  Check::all(nmx_msg, { m > 0, gamma > 0, y0 >= 0, v0 > 0 });
47 
48  //Endgeschwindigkeit
49  vTerminal = sqrt((mass) *Earth::g / (gamma));
50 
51  //Werte werden wiederverwendet
52  gvt = Earth::g / vTerminal;
53  vt2g = pow(vTerminal, 2) / Earth::g;
54  tMax = vTerminal / Earth::g * atan((v0) / vTerminal);
55  const double term0 = 0.5 * pow(vTerminal, 2) / Earth::g;
56  yMax = term0 * log(1 + pow((v0) / vTerminal, 2));
57  }
58 
63  inline double time4ymax() const { return tMax; }
64 
69  inline double ymax() const { return yMax; }
70 
75  inline double terminal_velocity() const { return vTerminal; }
76 
82  inline double a(double t) const {
83  return -Earth::g * (1 + (gamma) / ((mass) *Earth::g) * v(t) * abs(v(t)));
84  }
85 
91  inline double v(double t) const {
92  if (t <= tMax) {
93  return vTerminal * tan(gvt * (tMax - t));
94  }
95  return -vTerminal * tanh(gvt * (t - tMax));
96  }
97 
103  inline double y(double t) const {
104  if (t <= tMax) {
105  return vt2g * log(cos(gvt * (tMax - t)) / cos(gvt * tMax));
106  }
107  return yMax - vt2g * log(cosh(gvt * (t - tMax)));
108  }
109 }; //X2010
110 
115 class C2010 : public X2010
116 {
117 public:
119  friend Ode;
120  using Data = Data<8>;
121 
122  using X2010::X2010; //erbe Konstruktoren von der Basisklasse
123 
124 private:
125  Data _data; //Zahlentabelle zur Speicherung der Ergebnisse
126 
134  inline int odefn(double t, const double fin[], double fout[]) {
135  (void) t;
136  fout[0] = fin[1];
137  fout[1] = -Earth::g * (1 + gamma / (mass * Earth::g) * fin[1] * abs(fin[1]));
138  return GSL_SUCCESS;
139  }
140 
141 public:
145  inline void exec() {
146  Ode myOde{ *this, 1e-2, 1e-9, 0 };
147  myOde.set_init_conditions(0, { y0, v0 });
148 
149  //löse Bewegungsgleichung
150  double t = 0, dt = 0.01;
151  do {
152  _data += { t, myOde[0], myOde[1] };
153  t += dt;
154  myOde.solve(t);
155  } while (myOde[0] > 0);
156 
157  //füge Gesamtenergie und exakt berechnete Daten hinzu
158  for (auto &crow : _data.data()) {
159  const double t = crow[0];
160  crow[3] = Mechanics::kinetic_energy(mass, crow[2]);
161  crow[4] = Mechanics::potential_energy(mass, crow[1]);
162  crow[5] = crow[3] + crow[4]; //Gesamtenergie
163  crow[6] = y(t); //exakter Wert für Höhe
164  crow[7] = v(t); //exakter Wert für Geschwindigkeit
165  }
166  }
167 
171  inline void save_data() {
172  save(_data, Output::plot, gamma);
173  //ändere Formatierung der Daten für die LaTeX-Tabelle
174  std::ofstream ofs = get_output_stream(Output::latex, gamma);
175  ofs << std::fixed << std::setprecision(4);
176  _data.select_total_rows(5).save(ofs, Output::latex);
177  }
178 }; //C2010
179 
183 inline void run() {
184  const double mass = 1.0;
185  const double y0 = 0.0;
186  const double v0 = 30.0;
187 
188  for (const auto gamma : { 1.3, 1.6, 2.0 }) {
189  //Rechenmodell
190  C2010 cobj{ mass, gamma, y0, v0 };
191  cobj.exec();
192  cobj.save_data();
193  }
194 }
195 
196 } // namespace nmx::apps::x2010
static double kinetic_energy(double mass, double velocity)
kinetic_energy Hilfsfunktion
Definition: xphysics.h:38
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
The CModel class Bewegung mit Newtonscher Reibung numerische Lösung der Bewegungsgleichung (Rechenmod...
Definition: x2010.h:115
X2010(double m, double gm, double y0in, double v0in)
X2010 Konstruktor.
Definition: x2010.h:39
void exec()
solve_ode numerische Lösung der Bewegungsgleichung
Definition: x2010.h:145
double terminal_velocity() const
terminalVelocity
Definition: x2010.h:75
The X2010 class Bewegung mit Newtonscher Reibung (Modellklasse)
Definition: x2010.h:15
double ymax() const
ymax
Definition: x2010.h:69
const double mass
Definition: x2010.h:27
The Odeiv2 class numerische Lösung eines Systems von N Differenzialgleichungen Schnittstelle zur gsl...
Definition: xode.h:20
const double y0
Definition: x2010.h:29
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
static double potential_energy(double mass, double height)
potential_energy Hilfsfunktion
Definition: xphysics.h:48
double time4ymax() const
time4ymax
Definition: x2010.h:63
void save_data()
save_data speichert Daten in Dateien
Definition: x2010.h:171
const auto & data() const
data lesender Zugriff auf die interne Struktur
Definition: xdata.h:43
auto select_total_rows(size_t n, size_t start=0, bool l=true) const
get_total_rows generiere View mit eine Instanz vom Typ View bestimmter Anzahl von Spalten ...
Definition: xdata.h:338
void run()
run Berechnung von Beispieldaten
Definition: x2010.h:183
static const Format latex
Definition: xoutput.h:17
static constexpr double g
Definition: xphysics.h:20
double v(double t) const
v Geschwindigkeit
Definition: x2010.h:91
double a(double t) const
a Beschleunigung
Definition: x2010.h:82
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
double y(double t) const
y Höhe
Definition: x2010.h:103