x200.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::x200 {
8 
9 using namespace gravitation;
10 
15 class X200 : public XModel
16 {
17 private:
18  //konstante Beschleunigungen
19  double _accel1 = 0, _accel2 = 0;
20  //Anfangsort und Geschwindigkeit für den zweiten Teil der Bewegung
21  double _v1final = 0, _x1final = 0;
22 
23 public:
24  // Eingabeparameter
25  const double mass, mu;
26  const double force, phi;
27  const double t1;
28 
35  inline X200(double inmass, double inmu, double inforce, double inphi, double t1)
36  : XModel(__func__)
37  , mass(inmass)
38  , mu{ inmu }
39  , force{ inforce }
40  , phi{ inphi }
41  , t1{ t1 } {
43  { inmass > 0, //
44  inmu > 0,
45  inforce > 0,
46  inphi > 0,
47  t1 > 0 });
48  _accel1 = (force) / (mass) * (cos(phi) + (mu) *sin(phi)) - (mu) *Earth::g;
49  _accel2 = -(mu) *Earth::g;
50  _v1final = v(t1);
51  _x1final = x(t1);
52  }
53 
59  inline double get_force(double t) const { //
60  return t <= (t1) ? force : 0;
61  }
62 
68  inline double acceleration(double t) const { //
69  return t <= t1 ? _accel1 : _accel2;
70  }
71 
77  inline double x(double t) const {
78  if (t <= t1) {
79  return 0.5 * _accel1 * pow(t, 2);
80  }
81  const double deltat = (t - t1);
82  return _x1final + _v1final * deltat + 0.5 * _accel2 * pow(deltat, 2);
83  }
84 
90  inline double v(double t) const {
91  if (t <= t1) {
92  return _accel1 * t;
93  }
94  return _v1final + _accel2 * (t - t1);
95  }
96 }; //X200
97 
101 template<bool EXACTDATA = true>
102 class C200 : public X200
103 {
104 public:
105  using Data = Data<5>;
107  friend Ode;
108 
109 private:
110  //Speicher für Bewegungsdaten
111  Data _data;
112 
120  inline int odefn(double t, const double yin[], double yout[]) {
121  yout[0] = yin[1];
122  yout[1] = acceleration(t);
123  return GSL_SUCCESS;
124  }
125 
126 public:
127  using X200::X200; //erbe Konstruktoren der Basisklasse
128 
134  inline void exec(double dt = 0.1, double tmax = 500) {
135  Ode ode{ *this, 1e-2, 1e-9, 0 };
136  ode.set_init_conditions(0, { 0, 0 });
137  double t = 0;
138  //rechne, bis die Geschwindigkeit 0 wird. Abbruch spätestens
139  //bei tmax
140  while (ode[1] >= 0 && t < tmax) {
141  if constexpr (EXACTDATA) {
142  _data += { t,
143  ode[0], // numerisch berechnete ...
144  ode[1], // ... Werte
145  x(t), // exakte Werte Ort und
146  v(t) }; // Geschwindigkeit
147  } else {
148  _data += { t, ode[0], ode[1], 0, 0 };
149  }
150 
151  t += dt;
152  ode.solve(t);
153  }
154  }
155 
159  inline void save_data() {
160  //csv-Datei
161  save(_data, Output::plot);
162  //LaTeX-Tabelle mit Auswahl an Daten inklusive erster
163  // und letzter Reihe
164  auto view = _data.select_total_rows(5);
165  save(view, Output::latex);
166  }
167 }; //C200
168 
173 inline void run() {
174  //Rechenmodell
175  C200<true> cobj{ 1.0, 0.25, 10, 30.0_deg, 10 };
176  cobj.exec();
177  cobj.save_data();
178 }
179 
180 } // namespace nmx::apps::x200
const double phi
Definition: x200.h:26
double v(double t) const
v Geschwindigkeit als Funktion der ...
Definition: x200.h:90
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
X200(double inmass, double inmu, double inforce, double inphi, double t1)
X200 Konstruktor.
Definition: x200.h:35
double acceleration(double t) const
acceleration die zeitabhängige Kraft Beschleunigung
Definition: x200.h:68
The X200 class Geradlinige Bewegung eines Objekts mit konstanter äußerer Kraft und Gleitreibung (Mode...
Definition: x200.h:15
const double t1
Definition: x200.h:27
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 get_force(double t) const
get_force die zeitabhängige Kraft
Definition: x200.h:59
Data< 5 > Data
Definition: x200.h:105
void save_data()
save_data speichere Daten in Dateien
Definition: x200.h:159
void run()
run Berechnung von Beispieldaten Geradlinige Bewegung eines Objekts mit konstanter äußerer Kraft und ...
Definition: x200.h:173
The C200 class Rechenmodell (numerisch berechnete Werte)
Definition: x200.h:102
void exec(double dt=0.1, double tmax=500)
exec numerische Lösung der Bewegungsgleichungen
Definition: x200.h:134
const double mu
Definition: x200.h:25
static const Format latex
Definition: xoutput.h:17
static constexpr double g
Definition: xphysics.h:20
double x(double t) const
v Ortsvektor als Funktion der ...
Definition: x200.h:77
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