LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
unit.hpp
浏览该文件的文档.
1
#pragma once
2
3
#include <map>
4
#include <string>
5
#include <unordered_map>
6
7
#include "
lmcas_export.hpp
"
8
#include "
rational.hpp
"
9
#include "
result.hpp
"
10
11
namespace
LMCAS
{
12
13
/** A canonical product of base dimensions raised to exact rational powers. */
14
class
LMCAS_API
DimensionSignature {
15
public
:
16
using
Exponents = std::map<std::string, Rational>;
17
18
DimensionSignature() =
default
;
19
explicit
DimensionSignature(Exponents exponents);
20
21
static
DimensionSignature base(std::string name);
22
23
bool
is_dimensionless() const noexcept {
return
exponents_.empty(); }
24
const
Exponents& exponents() const noexcept {
return
exponents_; }
25
26
DimensionSignature multiplied_by(
const
DimensionSignature& other)
const
;
27
DimensionSignature divided_by(
const
DimensionSignature& other)
const
;
28
DimensionSignature raised_to(
const
Rational& exponent)
const
;
29
std::string to_string()
const
;
30
31
bool
operator==(
const
DimensionSignature& other)
const
noexcept
{
32
return
exponents_ == other.exponents_;
33
}
34
bool
operator!=(
const
DimensionSignature& other)
const
noexcept
{
35
return
!(*
this
== other);
36
}
37
38
private
:
39
Exponents exponents_;
40
};
41
42
struct
UnitDefinition
{
43
DimensionSignature
dimension
;
44
Rational
scale_to_base
= Rational(1);
45
};
46
47
/** Owns unit declarations for one computation context. */
48
class
LMCAS_API
UnitSystem {
49
public
:
50
UnitSystem();
51
52
Result<void>
declare_base_unit(
const
std::string&
name
);
53
Result<void>
declare_derived_unit(
const
std::string&
name
,
54
UnitDefinition
definition
);
55
Result<UnitDefinition>
resolve(
const
std::string&
name
)
const
;
56
Result<Rational>
conversion_factor(
const
std::string& source,
57
const
std::string&
target
)
const
;
58
59
private
:
60
std::unordered_map<std::string, UnitDefinition> units_;
61
};
62
63
}
// namespace LMCAS
LMCAS::Result
定义
result.hpp:39
lmcas_export.hpp
LMCAS_API
#define LMCAS_API
定义
lmcas_export.hpp:13
LMCAS
定义
assumption.hpp:11
LMCAS::UnitDefinition::dimension
DimensionSignature dimension
定义
unit.hpp:43
LMCAS::definition
std::string UnitDefinition definition
定义
expr.hpp:167
LMCAS::target
const ExprPtr & target
定义
expr.hpp:317
LMCAS::name
__attribute__((visibility("default"))) Result< EqvProfile > eqv_profile_from_name(const std const std::string & name
定义
equivalence_options.hpp:41
LMCAS::UnitDefinition::scale_to_base
Rational scale_to_base
定义
unit.hpp:44
LMCAS::UnitDefinition
定义
unit.hpp:42
rational.hpp
精确有理数 Rational,基于 BigInt 分子/分母表示,自动约分。
result.hpp
include
unit.hpp
生成于
, 为 LMCAS使用
1.18.0