x710.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xode.h"
4 #include "xmath.h"
5 #include "xmodel.h"
6 #include "xphysics.h"
7 #include "xroot.h"
8 
9 namespace nmx::apps::x710 {
10 
11 using namespace gravitation;
12 
17 class X710 : public XModel
18 {
19 protected:
20  //Komponenten der Anfangsgeschwindigkeit
21  double _v0y = 0, _v0x = 0;
22 
23 public:
24  // Eingabeparameter: Masse
25  const double mass;
26  //Anfangsbedingungen : Anfangshöhe,
27  //Geschwindigkeit, Winkel
28  const double H, v0, theta0;
29 
34  inline X710(double m, double yinit, double vinit, double angle)
35  : XModel{ __func__ }
36  , mass{ m }
37  , H{ yinit }
38  , v0{ vinit }
39  , theta0{ angle } {
40  //teste Eingabeparameter
41  Check::all(nmx_msg, { mass > 0, H > 0, v0 > 0, theta0 > 0 });
42  //berechne und speichere Anfangsbedingungen
43  _v0x = v0 * std::cos(theta0);
44  _v0y = v0 * std::sin(theta0);
45  }
46 
51  inline double xmax() const {
52  double term0 = pow(v0, 2) / Earth::g * cos(theta0);
53  double term1 = pow(sin(theta0), 2) + (2 * Earth::g * H) / pow(v0, 2);
54  return term0 * (sin(theta0) + sqrt(term1));
55  }
56 
61  inline double ymax() const { //
62  return H + 0.5 * pow(_v0y, 2) / Earth::g;
63  }
64 
69  inline double t4xmax() const {
70  const double _tmp = _v0y + sqrt(pow(_v0y, 2) + 2 * Earth::g * H);
71  return (_tmp) / Earth::g;
72  }
73 
78  inline double t4ymax() const { return _v0y / Earth::g; }
79 
84  inline double xmax_angle() const { //
85  return asin(v0 / sqrt(2 * pow(v0, 2) + 2 * Earth::g * H));
86  }
87 
93  inline double vx(double t) const {
94  (void) t;
95  return _v0x;
96  }
97 
103  inline double vy(double t) const { //
104  return v0 * sin(theta0) - Earth::g * t;
105  }
106 
112  inline double x(double t) const { return _v0x * t; }
113 
119  inline double y(double t) const { //
120  return H + vy(t) * t - 0.5 * Earth::g * pow(t, 2);
121  }
122 }; //X710
123 
127 class C710 : public X710
128 {
129 public:
131  friend Ode;
132  using Data = Data<9>;
133 
134 private:
135  //Speicher für die berechneten Daten
136  Data _data;
137 
145  inline int odefn(double t, const double fin[], double fout[]) {
146  (void) t;
147  fout[0] = fin[2];
148  fout[1] = fin[3];
149  fout[2] = 0;
150  fout[3] = -Earth::g;
151  return GSL_SUCCESS;
152  }
153 
154 public:
155  //Konstruktoren der Modellklasse werden geerbt
156  using X710::X710;
157 
161  inline void exec() {
162  //Anfangsbedingungen Ort
163  double x0 = 0.0, y0 = H;
164  //Anfangsbedingungen Geschwindigkeit
165  double vx0 = _v0x, vy0 = _v0y;
166 
167  //numerische Lösung der Bewegungsgleichungen, die Instanz des
168  // Rechenmodells wird der Lösungsroutine übergeben.
169  Ode myOde{ *this, 1e-2, 1e-9, 0 };
170  myOde.set_init_conditions(0, { x0, y0, vx0, vy0 });
171  double t = 0, dt = 0.1;
172  do {
173  _data += { t, myOde[0], myOde[1], myOde[2], myOde[3] };
174  t += dt;
175  myOde.solve(t);
176  if (myOde[1] < 2) {
177  //wenn sich das Teilchen dem Boden nähert
178  dt = 0.001;
179  }
180  } while (myOde[1] >= 0);
181 
182  //Einfügen von Energien und Geschwindigkeitsbetrag
183  for (auto &crow : _data.data()) {
184  const double _velocity = sqrt(pow(crow[3], 2) + pow(crow[4], 2));
185  crow[5] = _velocity;
186  crow[6] = Mechanics::kinetic_energy(mass, _velocity);
187  crow[7] = Mechanics::potential_energy(mass, crow[2]);
188  crow[8] = crow[6] + crow[7];
189  }
190  }
191 
195  inline void save_data() {
196  const auto id = Math::to_degrees(theta0);
197  save(_data, Output::plot, id);
198 
199  auto view = _data.select_total_rows(5);
200  std::stringstream sstr1;
201  sstr1 << id << "-v";
202  auto ofslatex1 = get_output_stream(Output::latex, sstr1.str());
203  view.save(ofslatex1, Output::latex, [](const auto &row) {
204  return std::array{ row[0], row[1], row[2], row[3], row[4], row[5] };
205  });
206 
207  std::stringstream sstr2;
208  sstr2 << id << "-e";
209  auto ofslatex2 = get_output_stream(Output::latex, sstr2.str());
210  view.save(ofslatex2, Output::latex, [](const auto &row) {
211  return std::array{ row[0], row[1], row[2], row[6], row[7], row[8] };
212  });
213  }
214 }; //C710
215 
219 inline void run() {
220  const double H = 10.0;
221  const double mass = 1.0;
222  const double v0 = 10.0;
223  for (double angle : { 10.0, 30.0, 45.0, 60.0 }) {
224  const double theta0 = Math::to_radians(angle);
225  C710 cobj{ mass, H, v0, theta0 };
226  cobj.exec();
227  cobj.save_data();
228  }
229 }
230 } // namespace nmx::apps::x710
double xmax() const
xmax
Definition: x710.h:51
static double to_degrees(double x)
Definition: xmath.h:17
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
double x(double t) const
x -Koordinate als Funktion der Zeit
Definition: x710.h:112
void run()
run Berechnung von Beispieldaten
Definition: x710.h:219
double xmax_angle() const
xmax_angle
Definition: x710.h:84
double t4xmax() const
t4xmax
Definition: x710.h:69
const double mass
Definition: x710.h:25
void save_data()
save_data speichert Daten im LaTeX- und im CSV-Format
Definition: x710.h:195
double ymax() const
ymax
Definition: x710.h:61
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
static double potential_energy(double mass, double height)
potential_energy Hilfsfunktion
Definition: xphysics.h:48
void exec()
solve_ode numerische Lösung der DGL
Definition: x710.h:161
double y(double t) const
y -Koordinate als Funktion der Zeit
Definition: x710.h:119
const double v0
Definition: x710.h:28
Data< 9 > Data
Definition: x710.h:132
double vy(double t) const
vy y-Komponente der Geschwindigkeit als Funktion der Zeit
Definition: x710.h:103
static double to_radians(double x)
Definition: xmath.h:15
double vx(double t) const
vx x-Komponente der Geschwindigkeit als Funktion der Zeit
Definition: x710.h:93
X710(double m, double yinit, double vinit, double angle)
Konstruktor.
Definition: x710.h:34
static const Format latex
Definition: xoutput.h:17
double t4ymax() const
t4ymax
Definition: x710.h:78
The C710 class Rechenmodell schiefer Wurf ohne Luftwiderstand.
Definition: x710.h:127
static constexpr double g
Definition: xphysics.h:20
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
The X710 class schiefer Wurf ohne Luftwiderstand (Modellklasse)
Definition: x710.h:17