x010.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xerror.h"
4 #include "xtools.h"
5 #include <array>
6 #include <cmath>
7 #include <iostream>
8 
9 namespace nmx::apps::x010 {
14 class Spring
15 {
16 private:
17  double _k; //Federkonstante
18  double _elongation = 0; //Auslenkung
19  //Kraft, elastische potenzielle Energie
20  double _force = 0, _ePotential = 0;
21 
22 public:
27  Spring(double k)
28  : _k{ k } {
29  if (_k <= 0) {
30  throw std::domain_error(__func__);
31  }
32  }
33 
38  void set_elongation(double x) {
39  _elongation = x; //neue Auslenkung
40  _force = -_k * x; //aktualisiere Kraft
41  //aktualisiere potenzielle Energie
42  _ePotential = 0.5 * _k * pow(_elongation, 2);
43  }
44 
49  double k() const { return _k; }
50 
55  double elongation() const { return _elongation; }
56 
61  double force() const { return _force; }
62 
68  double e_potential() const { return _ePotential; }
69 
74  auto values() const { //
75  return std::array{ _elongation, _force, _ePotential };
76  }
77 
84  inline static Spring add_paralell(const Spring &s1, const Spring &s2) {
85  double k = s1.k() + s2.k();
86  return Spring{ k }; //Kopierkonstruktor automatisch generiert
87  }
88 
95  inline static Spring add_series(const Spring &s1, const Spring s2) {
96  double tmp = 1. / s1.k() + 1. / s2.k();
97  //Kopierkonstruktor automatisch generiert
98  return Spring{ 1 / tmp };
99  }
100 }; //Spring
101 
105 inline void ex1() {
106  const Spring s1{ 200 }, s2{ 100 }, s3{ 100 };
107  Spring s = Spring::add_paralell(s1, s2);
108  s = Spring::add_series(s3, s);
109  //Auslenkung
110  const double x = 0.10;
111  std::cout << "k1=" << s1.k() << " N/m,";
112  std::cout << "k2=" << s2.k() << " N/m,";
113  std::cout << "k3=" << s3.k() << " N/m" << std::endl;
114  std::cout << "k=" << s.k() << " N/m" << std::endl;
115  //Feder wird gedehnt
116  s.set_elongation(x);
117  std::cout << "x=" << x << " m," //
118  << "F=" << s.force() << " N," //
119  << "U=" << s.e_potential() << " J" << std::endl;
120 }
121 } // namespace nmx::apps::x010
double e_potential() const
e_potential lese...
Definition: x010.h:68
void set_elongation(double x)
set_elongation setze Wert für die Auslenkung
Definition: x010.h:38
void ex1()
ex1 Berechnung von äquivalenten Federn
Definition: x010.h:105
auto values() const
values
Definition: x010.h:74
static Spring add_series(const Spring &s1, const Spring s2)
add_series Reihen-Schaltung von zwei Federn
Definition: x010.h:95
double k() const
k lese ...
Definition: x010.h:49
double force() const
force lese ...
Definition: x010.h:61
The Spring class Klasse Eigenschaften einer idealen Feder.
Definition: x010.h:14
Spring(double k)
Spring Konstruktor.
Definition: x010.h:27
static Spring add_paralell(const Spring &s1, const Spring &s2)
add_paralell Parallel-Schaltung von zwei Federn
Definition: x010.h:84
double elongation() const
elongation lese...
Definition: x010.h:55