x1900.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 
7 namespace nmx::apps::x1900 {
8 
9 using namespace nmx::gravitation;
10 
14 enum Idx { T1, T2, T3, N, M1 };
15 
20 class X1900 : public XModel, public CResult<5, Idx>
21 {
22 public:
23  // Eingabeparameter
24  const double mu; // Haftreibungskoeffizient
25  const double mass2; // Masse m2
26  const double phi; // Winkel
27 
28 public:
35  inline X1900(double muin, double mass2in, double phiin)
36  : XModel(__func__)
37  , mu{ muin }
38  , mass2{ mass2in }
39  , phi{ phiin } {
40  Check::all(nmx_msg, { mu > 0, mass2 > 0, phi > 0 });
41  }
42 }; //X1900
43 
48 struct CModel1 : public X1900 {
49  //erbe Konstruktoren der Basisklasse
50  using X1900::X1900;
51 
52  //verwende hergeleitete Formeln
53  inline void apply() {
54  set_result(Idx::T1, mass2 * Earth::g * mu * tan(phi));
55  set_result(Idx::T2, mass2 * Earth::g * mu);
56  set_result(Idx::T3, mass2 * Earth::g * mu / cos(phi));
57  set_result(Idx::N, mass2 * Earth::g);
58  set_result(Idx::M1, mu * mass2 * tan(phi));
59  }
60 }; //CModel1
61 
66 struct CModel2 : public X1900 {
67  //erbe Konstruktoren der Basisklasse
68  using X1900::X1900;
69 
70  //löse Gleichungssystem
71  inline void apply() {
72  using LU = gsl::LU_Decomposition;
73  //LU-Zerlegung: Koeffizientenmatrix
74  LU::Matrix left{ { 0, 1, 0, -mu, 0 },
75  { 0, 0, 0, 1, 0 },
76  { 0, 1, -cos(phi), 0, 0 },
77  { 1, 0, -sin(phi), 0, 0 },
78  { 1, 0, 0, 0, -Earth::g } };
79  //LU-Zerlegung: rechte Seite des Gleichungssystems
80  LU::Vector right{ 0, mass2 * Earth::g, 0, 0, 0 };
81  //LU-Zerlegung: Berechnung der Lösung
82  LU lusolver{ left, right };
83  lusolver.solve();
84  //speichere Ergebnisse
85  set_result({ lusolver(Idx::T1),
86  lusolver(Idx::T2),
87  lusolver(Idx::T3),
88  lusolver(Idx::N),
89  lusolver(Idx::M1) });
90  }
91 }; //CModel2
92 
97 inline void run() {
98  using Data = Data<7>;
99  const double mass2 = 1.0;
100  for (auto mu : { 0.1, 0.2, 0.3, 0.4 }) {
101  //reservierter Speicher für Daten
102  Data data;
103  for (auto phi : { 10.0_deg, 30.0_deg, 40.0_deg }) {
104  //verwende hergeleitete Formeln
105  CModel1 xobj1{ mu, mass2, phi };
106  xobj1.apply();
107  //löse Gleichungssystem
108  CModel2 xobj2{ mu, mass2, phi };
109  xobj2.apply();
110  //füge Ergebnisse einer gemeinsamen Zahlentabelle hinzu
111  // clang-format off
112  data += { phi,
113  xobj2(Idx::T1), xobj2(Idx::T2), xobj2(Idx::T3),
114  xobj2(Idx::N), xobj2(Idx::M1), xobj1(Idx::M1) };
115  // clang-format on
116  }
117  //speichere Daten im CSV- und LaTeX-Format. Dateinamenskonflikte
118  //werden durch das Hinzufügen des Haftreibungskoeffizienten
119  //vermieden
120  X1900::save(data, Output::plot, mu);
121  X1900::save(data, Output::latex, mu);
122  }
123 }
124 
125 } // namespace nmx::apps::x1900
const double mass2
Definition: x1900.h:25
const double mu
Definition: x1900.h:24
X1900(double muin, double mass2in, double phiin)
X1900 Konstruktor.
Definition: x1900.h:35
The CModel struct berechnet die Daten auf Basis hergeleiteter Formeln (Rechenmodell) ...
Definition: x1900.h:48
Idx
The Idx enum Aufzählung, Zugriff auf gespeicherte Variablen.
Definition: x1900.h:14
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
The X1900 class Massen befestigt an Seilen und Haftreibung (Modellklasse)
Definition: x1900.h:20
#define nmx_msg
Definition: xerror.h:113
LU::Vector Vector
Definition: x038.h:10
void solve()
solve Berechnung des Lösungsvektors
Definition: xlu.h:116
const double phi
Definition: x1900.h:26
void run()
run Massen befestigt an Seilen und statische Reibung (Berechnung von Beispieldaten) ...
Definition: x1900.h:97
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
The LU_Decomposition class Lösung eines linearen Gleichungssystems mittels der LU-Zerlegung.
Definition: xlu.h:11
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
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 CModel2 struct löst das Gleichungssystem direkt mittels LU-Zerlegung (Rechenmodell) ...
Definition: x1900.h:66