x910.h
Go to the documentation of this file.
1 #pragma once
2 #include "xode.h"
3 #include "xmath.h"
4 #include "xmodel.h"
5 #include "xphysics.h"
6 
7 namespace nmx::apps::x910 {
8 
9 using namespace gravitation;
10 
15 class X910 : public XModel
16 {
17 public:
18  // Eingabeparameter
19  const double m1, m2;
20  const double k;
21  const double y0, v0;
22  const double omega0;
23  const double period;
24 
25 public:
34  inline X910(double m1, double m2, double k, double y0, double v0)
35  : XModel(__func__)
36  , m1{ m1 }
37  , m2{ m2 }
38  , k{ k }
39  , y0{ y0 }
40  , v0{ v0 }
41  , omega0{ sqrt(k / (m1 + m2)) }
42  , period{ 2 * Math::PI / omega0 } {}
43 
49  inline double acceleration(double x) const { //
50  return -pow(omega0, 2) * x;
51  }
52 
58  inline double normal_force2(double t) const {
59  return m2 * Earth::g * (1 + y0 * pow(omega0, 2) / Earth::g * cos(omega0 * t));
60  }
61 }; //X910
62 
67 class C910 : public X910
68 {
69 public:
71  friend Ode;
72  using Data = Data<6>;
73 
74  //benutze Konstruktoren der Basisklasse
75  using X910::X910;
76 
77 private:
78  double _normalForce2;
79  //Zahlentabelle zum Speichern der Ergebnisse
80  Data _data;
81 
90  int odefn(double t, const double yin[], double yout[]) {
91  (void) t;
92  yout[0] = yin[1];
93  yout[1] = acceleration(yin[0]);
94  return GSL_SUCCESS;
95  }
96 
97 public:
102  void exec() {
103  //Objekt zur numerischen Lösung der Differenzialgleichung
104  Ode ode{ *this, 1e-2, 1e-9, 0 };
105  ode.set_init_conditions(0, { y0, v0 });
106  double t = 0, dt = 0.001;
107 
108  //rechne solange die Geschwindigkeit negativ ist.
109  while (ode[1] <= 0) {
110  _normalForce2 = m2 * (-acceleration(ode[0]) + Earth::g);
111 
112  //Abbruchkriterium
113  if (_normalForce2 < 0) {
114  break; // m2 hat sich gelöst
115  }
116 
117  //schreibe Daten in Zahlentabelle
118  _data += {
119  t,
120  t / period,
121  ode[0],
122  ode[1],
123  _normalForce2, // numerisch
124  normal_force2(t) //exakt
125  };
126 
127  t += dt;
128  ode.solve(t);
129  }
130  }
131 
136  inline void save_data() const { //
137  //erzeuge id (für jede maximale Auslenkung wird eine sepparate
138  //Datei erzeugt)
139  std::stringstream sid;
140  sid << std::setprecision(2) << abs(y0);
141  const auto id = sid.str();
142 
143  save(_data, Output::plot, id);
144  save(_data.select_total_rows(5), Output::latex, id);
145  }
146 }; //C910
147 
152 inline void run() {
153  //Bewegungsparameter
154  const double m1 = 1.5, m2 = .5, k = 200.0;
155 
156  //Anfangsbedingungen
157  const double y0max = Earth::g / (k / (m1 + m2)), v0 = 0.0;
158 
159  //Berechnung der Daten
160  for (const auto y0 : { 1.5 * y0max, y0max }) {
161  //Rechenmodell
162  C910 cobj{ m1, m2, k, y0, v0 };
163  cobj.exec();
164  cobj.save_data();
165  }
166 }
167 
168 } // namespace nmx::apps::x910
void save_data() const
save_data Speicherung der Daten in Dateien im CSV- und LaTeX-Format
Definition: x910.h:136
const double period
Definition: x910.h:23
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
void run()
run Schwingung in vertikaler Richtung eines Systems aus zwei Massen (Berechnung von Beispieldaten) ...
Definition: x910.h:152
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
void exec()
exec Lösung der Bewegungsgleichung und Berechnung der Normalkraft auf m2
Definition: x910.h:102
const double k
Definition: x910.h:20
double normal_force2(double t) const
normal_force2 Normalkraft
Definition: x910.h:58
The C910 class Schwingung in vertikaler Richtung eines Systems aus zwei Massen (Rechenmodell) ...
Definition: x910.h:67
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
The X910 class Schwingung in vertikaler Richtung eines Systems aus zwei Massen (Modellklasse) ...
Definition: x910.h:15
const double m2
Definition: x910.h:19
static constexpr double PI
Definition: xmath.h:11
static const Format latex
Definition: xoutput.h:17
const double y0
Definition: x910.h:21
static constexpr double g
Definition: xphysics.h:20
X910(double m1, double m2, double k, double y0, double v0)
X910 Konstruktor.
Definition: x910.h:34
const double omega0
Definition: x910.h:22
double acceleration(double x) const
acceleration Beschleunigung
Definition: x910.h:49
static const Format plot
Definition: xoutput.h:18