x9100.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 <iomanip>
7 
8 namespace nmx::apps::x9100 {
13 class X9100 : public XModel
14 {
15 private:
16  double _f0, _f0overomega;
17 
18 public:
19  //Eingabeparameter
20  const double mass;
21  const double Force0, omega;
22  //Anfangsbedingungen
23  const double x0, v0;
24 
25 public:
34  inline X9100(double m, double F0, double omg, double x0, double v0)
35  : XModel{ __func__ }
36  , mass{ m }
37  , Force0{ F0 }
38  , omega{ omg }
39  , x0{ x0 }
40  , v0{ v0 } {
41  Check::all(nmx_msg, { mass > 0, Force0 > 0, omega > 0 });
42  _f0 = Force0 / (mass);
43  _f0overomega = _f0 / (omega);
44  }
45 
51  inline double x(double t) const {
52  return x0 + (v0 + _f0overomega) * t - _f0 / pow(omega, 2) * sin(omega * t);
53  }
54 
61  inline double v(double t) const { //
62  return (v0 + _f0overomega) - _f0overomega * cos(omega * t);
63  }
64 
71  inline double a(double t) const { return _f0 * sin(omega * t); }
72 }; //X9100
73 
79 class C9100 : public X9100
80 {
81 public:
82  using Data = nmx::Data<7>;
84  friend Ode;
85 
86 private:
87  //Zahlentabelle für die Bewegungsdaten
88  Data _data;
89 
90 public:
91  using X9100::X9100;
92 
100  inline int odefn(double t, const double fin[], double fout[]) {
101  fout[0] = fin[1];
102  fout[1] = a(t);
103  return GSL_SUCCESS;
104  }
105 
110  void exec(double tmax) {
111  Ode ode{ *this, 1e-2, 1e-9, 0 };
112  ode.set_init_conditions(0, { x0, v0 });
113  double t = 0, dt = 0.1;
114  while (t < tmax) {
115  _data += { t,
116  ode[0],
117  ode[1],
118  a(t), //
120  x(t),
121  v(t) };
122  t += dt;
123  ode.solve(t);
124  }
125  }
126 
130  inline void save_data() {
131  save(_data, Output::plot);
132  save(_data.select_rows(4), Output::latex);
133  }
134 }; //C9100
135 
140 inline void run() {
141  //Bewegungsparameter
142  const double mass = 2.0, F0 = 10.0, omega = 2;
143  //Anfangsbedingungen
144  const double x0 = 0.0, v0 = 10.0;
145  //Rechenmodell
146  C9100 cobj{ mass, F0, omega, x0, v0 };
147  cobj.exec(4);
148  cobj.save_data();
149 }
150 
151 } // namespace nmx::apps::x9100
const double Force0
Definition: x9100.h:21
static double kinetic_energy(double mass, double velocity)
kinetic_energy Hilfsfunktion
Definition: xphysics.h:38
void save_data()
save_data speichere Daten in Dateien
Definition: x9100.h:130
auto select_rows(size_t step, size_t startidx=0, bool last=false) const
view Teile der Tabelle als View
Definition: xdata.h:319
int odefn(double t, const double fin[], double fout[])
odefn Schnittstelle zur gsl
Definition: x9100.h:100
void exec(double tmax)
solve_ode numerische Lösung der Bewegungsgleichung
Definition: x9100.h:110
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
void run()
run Teilchen bewegt sich unter dem Einfluss einer zeitabhängigen Kraft (Berechnung von Beispieldaten)...
Definition: x9100.h:140
The X9100 class Teilchen bewegt sich unter dem Einfluss einer zeitabhängigen Kraft (Modellklasse) ...
Definition: x9100.h:13
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 v(double t) const
v Geschwindigkeit als Funktion der Zeit (analytische Formel)
Definition: x9100.h:61
const double v0
Definition: x9100.h:23
const double mass
Definition: x9100.h:20
static void save(const T &data, Format fmt)
save Speicherung von Daten in eine Datei
Definition: xmodel.h:70
const double omega
Definition: x9100.h:21
double a(double t) const
a Beschleunigung als Funktion der Zeit (analytische Formel)
Definition: x9100.h:71
double x(double t) const
x Ortsfunktion (analytische Formel)
Definition: x9100.h:51
The CModel class Teilchen bewegt sich unter dem Einfluss einer zeitabhängigen Kraft, numerische Lösung der Bewegungsgleichungen. (Rechenmodell)
Definition: x9100.h:79
static const Format latex
Definition: xoutput.h:17
const double x0
Definition: x9100.h:23
X9100(double m, double F0, double omg, double x0, double v0)
X9100 Konstruktor.
Definition: x9100.h:34
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