48 values[int(basicDimension)] = 1;
53 values[i] = other.values[i];
62 values[i] = other.values[i];
68 return values[int(dim)];
72 return values[int(dim)];
77 values[i] += other.values[i];
84 values[i] -= other.values[i];
104 dims.values[i] = -values[i];
128 return values == other.values;
132 return values != other.values;
136 return { 0, 0, 0, 0 };
202 coeffs[i] = other.coeffs[i];
207 : coeffs{ length, mass, time, angle } {}
219 return coeffs[int(dim)];
223 return coeffs[int(dim)];
227 return { 1._f, 1._f, 1._f, 1._f };
231 return { 0.01_f, 0.001_f, 1._f, 1._f };
248 : dimensions(dimensions) {
251 this->data = conversion *
value;
256 return data / system.
getFactor(dimensions);
278 neg.dimensions = dimensions;
290 dimensions += other.dimensions;
296 dimensions -= other.dimensions;
302 return data == other.data;
306 return !(*
this == other);
311 return data < other.data;
316 return data <= other.data;
320 return !(*
this <= other);
324 return !(*
this < other);
340 friend std::ostream&
operator<<(std::ostream& stream,
const Unit& u);
344 result.data =
std::pow(u.data, power);
345 result.dimensions = u.dimensions * power;
444 return 1.e-3_kg *
Float(value);
450 return 0.01_m *
Float(value);
453 return 1.e-3_m *
Float(value);
456 return 1.e3_m *
Float(value);
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
#define SPH_ASSERT(x,...)
Definitions of physical constaints (in SI units).
Wrapper of type containing either a value or an error message.
Key-value associative container implemented as a sorted array.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Additional math routines (with more includes).
constexpr INLINE Float pow(const Float v)
Power for floats.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
@ MASS
Particle masses, always a scalar quantity.
Expected< Unit > parseUnit(const std::string &text)
Unit operator/(const Unit &u1, const Unit &u2)
Unit operator*(const Unit &u, const Float f)
constexpr Size DIMENSION_CNT
Unit operator+(const Unit &u1, const Unit &u2)
Unit operator-(const Unit &u1, const Unit &u2)
Wrapper of type that either contains a value of given type, or an error message.
void fill(const T &value)
Assigns a value to all constructed elements of the array.
static UnitDimensions power()
UnitDimensions(const UnitDimensions &other)
static UnitDimensions force()
static UnitDimensions velocity()
static UnitDimensions time()
static UnitDimensions numberDensity()
friend UnitDimensions operator-(const UnitDimensions &dim1, const UnitDimensions &dim2)
static UnitDimensions energyDensity()
static UnitDimensions mass()
static UnitDimensions density()
static UnitDimensions energy()
static UnitDimensions dimensionless()
UnitDimensions(const BasicDimension &basicDimension)
bool operator!=(const UnitDimensions &other) const
bool operator==(const UnitDimensions &other) const
friend UnitDimensions operator*(const int mult, const UnitDimensions &dim)
UnitDimensions(const int length, const int mass, const int time, const int angle)
UnitDimensions & operator+=(const UnitDimensions &other)
static UnitDimensions volume()
static UnitDimensions length()
friend UnitDimensions operator*(const UnitDimensions &dim, const int mult)
UnitDimensions & operator*=(const int mult)
UnitDimensions & operator=(const UnitDimensions &other)
int & operator[](const BasicDimension dim)
int operator[](const BasicDimension dim) const
static UnitDimensions area()
friend UnitDimensions operator+(const UnitDimensions &dim1, const UnitDimensions &dim2)
static UnitDimensions acceleration()
UnitDimensions operator-() const
UnitDimensions & operator-=(const UnitDimensions &other)
Float operator[](const BasicDimension dim) const
Float getFactor(const UnitDimensions &dimensions) const
Returns the conversion factor with a respect to the reference unit system.
UnitSystem(const UnitSystem &other)
UnitSystem(const Float length, const Float mass, const Float time, const Float angle)
Float & operator[](const BasicDimension dim)
static Unit dimensionless(const Float value)
bool operator==(const Unit &other) const
bool operator!=(const Unit &other) const
static Unit second(const Float value)
bool operator>(const Unit &other) const
Unit & operator*=(const Float f)
friend Unit pow(const Unit &u, const int power)
bool operator<=(const Unit &other) const
friend std::ostream & operator<<(std::ostream &stream, const Unit &u)
Utility functions.
static Unit kilogram(const Float value)
Unit & operator*=(const Unit &other)
Float value(const UnitSystem &system) const
Returns the value in given unit system.
Unit & operator+=(const Unit &other)
Arithmetics.
friend bool almostEqual(const Unit &u1, const Unit &u2, const Float eps)
Unit & operator-=(const Unit &other)
Unit(const Float &value, const UnitDimensions &dimensions, const UnitSystem &system)
Creates a unit, given its value, dimensions and a unit system in which the value is expressed.
bool operator<(const Unit &other) const
UnitDimensions dimension() const
bool operator>=(const Unit &other) const
static Unit radian(const Float value)
Unit & operator/=(const Unit &other)
static Unit meter(const Float value)