x1800.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xlu.h"
4 #include "xmodel.h"
5 #include "xphysics.h"
6 #include <initializer_list>
7 #include <vector>
8 
9 namespace nmx::apps::x1800 {
10 
14 enum class Idx { T1, T2, T3 };
15 
20 class X1800 : public XModel, public CResult<3, Idx>
21 {
22 private:
23  //das Gewicht der Masse
24  double _weight = 0;
25 
26 public:
27  const double mass; // Masse der Kugel
28  const double phi; // Winkel
29 
35  inline X1800(double mass, double phi)
36  : XModel(__func__)
37  , mass{ mass }
38  , phi{ phi } {
39  Check::all(nmx_msg, { mass > 0, phi > 0, phi < 90 });
40  _weight = mass * gravitation::Earth::g;
41  }
42 
47  inline double weight() const { return _weight; }
48 
54  inline double tension(Idx idx) const { return get(idx); }
55 }; //X1800
56 
61 struct CModel1 : public X1800 {
62  //erbe Konstruktoren der Basisklasse
63  using X1800::X1800;
64 
65  //Berechnung der Seilspannungen
66  inline void apply() {
67  using LU = gsl::LU_Decomposition;
68  LU lusolver;
69  LU::Matrix m = { { 1, 0, 0 }, //
70  { 0, -cos(phi), 1 },
71  { -1, sin(phi), 0 } };
72  lusolver.set_left(m);
73  lusolver.set_right({ weight(), 0, 0 });
74  lusolver.solve();
75  //übergebe direkt ganzen Vektor
76  set_result(lusolver.solution());
77  }
78 }; //CModel1
79 
84 struct CModel2 : public X1800 {
85  //erbe Konstruktoren der Basisklasse
86  using X1800::X1800;
87 
88  //Berechnung der Seilspannungen
89  inline void apply() {
90  const auto w = weight();
91  set_result({ w, w / sin(phi), w / tan(phi) });
92  }
93 }; //CModel2
94 
98 inline void run() {
99  using Data = nmx::Data<7>;
100  for (auto m : { 2.0, 4.0, 6.0 }) {
101  Data data;
102  for (double phi = 10.0_deg; phi < 90.0_deg; phi += 10.0_deg) {
103  // initialisiere zwei Rechenmodelle
104  CModel1 xobj1(m, phi);
105  CModel2 xobj2(m, phi);
106  //Lösung über LU-Zerlegung
107  xobj1.apply();
108  //Lösung über hergeleitete Formeln
109  xobj2.apply();
110  //füge Ergebnisse einer gemeinsamen Zahlentabelle hinzu
111  data += { Math::to_degrees(phi), //
112  xobj1.tension(Idx::T1), xobj1.tension(Idx::T2), //
113  xobj1.tension(Idx::T3), xobj2.tension(Idx::T1),
114  xobj2.tension(Idx::T2), xobj2.tension(Idx::T3) };
115  }
116  //speichere Daten im CSV- und LaTeX-Format. Dateinamenskonflikte
117  //werden durch das Hinzufügen der Masse m vermieden
118  X1800::save(data, Output::plot, m);
119  X1800::save(data, Output::latex, m);
120  }
121 }
122 
123 } // namespace nmx::apps::x1800
static double to_degrees(double x)
Definition: xmath.h:17
Idx
The Idx enum Zugriff auf die Seilspannungen.
Definition: x1800.h:14
The CModel1 struct Berechnung der Seilspannungen durch direkte Lösung des Gleichungssystems.
Definition: x1800.h:61
const double phi
Definition: x1800.h:28
double weight() const
weight Zugriff auf das intern gespeicherte Gewicht
Definition: x1800.h:47
The Data class Eine Klasse für Zahlentabellen mit fester Anzahl von Spalten. Die Anzahl der Reihen wä...
Definition: xdata.h:22
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
The X1800 class Masse im Gleichgewicht befestigt an einem System mit drei Seilen. ...
Definition: x1800.h:20
void run()
run Berechnung von Beispieldaten mit zwei Rechenmodellen
Definition: x1800.h:98
double tension(Idx idx) const
tension lese Seilspannung über Index (Aufzählung)
Definition: x1800.h:54
gsl::LU_Decomposition LU
Definition: x038.h:8
LU::Matrix Matrix
Definition: x038.h:9
static void save(const T &data, Format fmt)
save Speicherung von Daten in eine Datei
Definition: xmodel.h:70
X1800(double mass, double phi)
X1800 Konstruktor.
Definition: x1800.h:35
The LU_Decomposition class Lösung eines linearen Gleichungssystems mittels der LU-Zerlegung.
Definition: xlu.h:11
const double mass
Definition: x1800.h:27
The CResult class Speicherung von Rechenergebnissen.
Definition: xmodel.h:106
static const Format latex
Definition: xoutput.h:17
static constexpr double g
Definition: xphysics.h:20
The CModel2 struct Berechnung der Seilspannungen über die theoretisch hergeleitete Formeln...
Definition: x1800.h:84
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