MySources/beam.hpp

81 lines
2.5 KiB
C++
Raw Normal View History

2020-11-27 11:47:21 +01:00
#ifndef BEAM_HPP
#define BEAM_HPP
#include <assert.h>
#include <cmath>
#include <iostream>
#include <string>
2020-11-27 11:47:21 +01:00
struct RectangularBeamDimensions {
inline static std::string name{"Rectangular"};
double b;
double h;
2021-12-19 19:15:36 +01:00
double A{0}; // cross sectional area
struct MomentsOfInertia
{
double I2{0}; // second moment of inertia
double I3{0}; // third moment of inertia
double J{0}; // torsional constant (polar moment of inertia)
} inertia;
RectangularBeamDimensions(const double &width, const double &height) : b(width), h(height)
{
assert(width > 0 && height > 0);
updateProperties();
2020-11-27 11:47:21 +01:00
}
2021-12-19 19:15:36 +01:00
RectangularBeamDimensions() : b(0.002), h(0.002) { updateProperties(); }
std::string toString() const {
return std::string("b=") + std::to_string(b) + std::string(" h=") +
std::to_string(h);
}
2021-12-19 19:15:36 +01:00
void updateProperties()
{
A = b * h;
inertia.I2 = b * std::pow(h, 3) / 12;
inertia.I3 = h * std::pow(b, 3) / 12;
inertia.J = inertia.I2 + inertia.I3;
}
static void computeMomentsOfInertia(const RectangularBeamDimensions &dimensions,
MomentsOfInertia &inertia);
2020-11-27 11:47:21 +01:00
};
2020-12-09 16:59:18 +01:00
struct CylindricalBeamDimensions {
inline static std::string name{"Cylindrical"};
double od; // Cylinder outside diameter
double
2020-11-27 11:47:21 +01:00
id; // Cylinder inside diameter
// https://www.engineeringtoolbox.com/area-moment-inertia-d_1328.html
CylindricalBeamDimensions(const double &outsideDiameter,
const double &insideDiameter)
2020-11-27 11:47:21 +01:00
: od(outsideDiameter), id(insideDiameter) {
assert(outsideDiameter > 0 && insideDiameter > 0 &&
outsideDiameter > insideDiameter);
}
2020-12-09 16:59:18 +01:00
CylindricalBeamDimensions() : od(0.03), id(0.026) {}
2020-11-27 11:47:21 +01:00
};
2021-04-08 20:03:23 +02:00
struct ElementMaterial
{
double poissonsRatio;
double youngsModulus;
2021-12-19 19:15:36 +01:00
double G;
2021-04-08 20:03:23 +02:00
ElementMaterial(const double &poissonsRatio, const double &youngsModulus)
: poissonsRatio(poissonsRatio), youngsModulus(youngsModulus)
{
assert(poissonsRatio <= 0.5 && poissonsRatio >= -1);
2021-12-19 19:15:36 +01:00
updateProperties();
2021-04-08 20:03:23 +02:00
}
2021-12-19 19:15:36 +01:00
ElementMaterial() : poissonsRatio(0.3), youngsModulus(200 * 1e9) { updateProperties(); }
2021-04-08 20:03:23 +02:00
std::string toString() const
{
return std::string("Material:") + std::string("\nPoisson's ratio=")
+ std::to_string(poissonsRatio) + std::string("\nYoung's Modulus(GPa)=")
+ std::to_string(youngsModulus / 1e9);
}
2021-12-19 19:15:36 +01:00
void updateProperties() { G = youngsModulus / (2 * (1 + poissonsRatio)); }
2020-11-27 11:47:21 +01:00
};
#endif // BEAM_HPP