x9000.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::x9000 {
9 
14 class X9000 : public XModel
15 {
16 public:
17  // Eingabeparameter
18  const double mass, b;
19  const double mu; // sqrt(b/m)
20  const double x0, v0;
21 
22 public:
30  X9000(double m, double b, double x0, double v0)
31  : XModel(__func__)
32  , mass{ m }
33  , b{ b }
34  , mu{ sqrt((b) / (mass)) }
35  , x0{ x0 }
36  , v0{ v0 } {
37  Check::all(nmx_msg, { b > 0, mass > 0 });
38  }
39 
45  inline double a(double x) const { return pow(mu, 2) * x; }
46 
52  inline double force(double x) const { return b * x; }
53 
59  inline double v(double t) const { //
60  return v0 * cosh(mu * t) + mu * (x0) *sinh(mu * t);
61  }
62 
68  inline double x(double t) const { //
69  return (x0) *cosh(mu * t) + (v0) / mu * sinh(mu * t);
70  }
71 }; //X9000
72 
77 class C9000 : public X9000
78 {
79 public:
80  using Data = Data<7>;
82  friend Ode;
83 
84 private:
85  // Datenobjekt
86  Data _data;
87 
95  inline int odefn(double t, const double fin[], double fout[]) {
96  (void) t;
97  fout[0] = fin[1];
98  fout[1] = a(fin[0]);
99  return GSL_SUCCESS;
100  }
101 
102 public:
103  //benutze Konstruktoren der Basisklasse
104  using X9000::X9000;
105 
110  void exec(double tmax) {
111  Ode ode{ *this, 1e-2, 1e-6, 0 };
112  ode.set_init_conditions(0, { x0, v0 });
113  double t = 0, dt = 0.1;
114  // berechne Daten für die tmax s
115  while (t <= tmax) {
116  //speichere nur numerisch berechnete Werte
117  _data += { t,
118  ode[0],
119  ode[1],
120  a(ode[0]), //
122  x(t),
123  v(t) };
124  t += dt;
125  ode.solve(t);
126  }
127  }
128 
133  inline void save_data() {
134  //eine Auswahl der Daten wird zur Darstellung
135  //als LaTeX-Tabelle gespeichert
136  auto view = _data.select_total_rows(5);
137  save(view, Output::latex);
138  //alle berechneten Daten werden im CSV-Format gespeichert
139  save(_data, Output::plot);
140  }
141 }; //C9000
142 
147 inline void run() {
148  //Rechenmodell
149  C9000 cobj(1, 2, 10, 10);
150  //berechne Lösungen von t=0 s bis t = 2 s
151  cobj.exec(2);
152  cobj.save_data();
153 }
154 
155 } // namespace nmx::apps::x9000
const double v0
Definition: x9000.h:20
static double kinetic_energy(double mass, double velocity)
kinetic_energy Hilfsfunktion
Definition: xphysics.h:38
const double mass
Definition: x9000.h:18
double v(double t) const
v Geschwindigkeit als Funktion von t
Definition: x9000.h:59
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
Definition: xode.h:133
The X9000 class Teilchen bewegt sich unter dem Einfluss einer ortsabhängigen Kraft (Modellklasse) ...
Definition: x9000.h:14
double a(double x) const
acceleration Beschleunigung als Funktion von x
Definition: x9000.h:45
double x(double t) const
x Ort als Funktion von t
Definition: x9000.h:68
const double b
Definition: x9000.h:18
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 force(double x) const
force Kraft als Funktion von x
Definition: x9000.h:52
void run()
run Teilchen bewegt sich unter dem Einfluss einer ortsabhängigen Kraft (Berechnung von Beispieldaten)...
Definition: x9000.h:147
void exec(double tmax)
solve numerische Lösung der Bewegungsgleichung
Definition: x9000.h:110
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
static void save(const T &data, Format fmt)
save Speicherung von Daten in eine Datei
Definition: xmodel.h:70
X9000(double m, double b, double x0, double v0)
X9000 Konstruktor.
Definition: x9000.h:30
const double x0
Definition: x9000.h:20
The CModel class Teilchen bewegt sich unter dem Einfluss einer ortsabhängigen Kraft (Rechenmodell) ...
Definition: x9000.h:77
const double mu
Definition: x9000.h:19
static const Format latex
Definition: xoutput.h:17
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
void save_data()
save_data Daten werden im CSV- und LaTeX-Format gespeichert.
Definition: x9000.h:133