aboutsummaryrefslogtreecommitdiffstats
path: root/compressor
diff options
context:
space:
mode:
Diffstat (limited to 'compressor')
-rw-r--r--compressor/compressor.go116
-rw-r--r--compressor/res/borgwarner/efr/6258.toml8
-rw-r--r--compressor/res/borgwarner/k/03.toml8
-rw-r--r--compressor/res/borgwarner/k/04.toml8
-rw-r--r--compressor/res/garrett/g/25-660.toml8
5 files changed, 102 insertions, 46 deletions
diff --git a/compressor/compressor.go b/compressor/compressor.go
index fc12f26..4a30c19 100644
--- a/compressor/compressor.go
+++ b/compressor/compressor.go
@@ -1,12 +1,17 @@
package compressor
import (
+ "github.com/BurntSushi/toml"
+ "io/fs"
+ fp "path/filepath"
"time"
"github.com/sam-anthony/volute/mass"
"github.com/sam-anthony/volute/util"
)
+const root = "compressor/res/"
+
type Compressor struct {
Name string
FileName string
@@ -27,60 +32,79 @@ type Compressor struct {
MaxPressureRatio float32
}
+// [manufacturer][series][model]
var compressors = make(map[string]map[string]map[string]Compressor)
func init() {
- compressors["Garrett"] = make(map[string]map[string]Compressor)
- compressors["Garrett"]["G"] = make(map[string]Compressor)
- compressors["Garrett"]["G"]["25-660"] = garrettG25660()
- compressors["BorgWarner"] = make(map[string]map[string]Compressor)
- compressors["BorgWarner"]["K"] = make(map[string]Compressor)
- compressors["BorgWarner"]["K"]["03"] = borgwarnerK03()
- compressors["BorgWarner"]["K"]["04"] = borgwarnerK04()
- compressors["BorgWarner"]["EFR"] = make(map[string]Compressor)
- compressors["BorgWarner"]["EFR"]["6258"] = borgwarnerEFR6258()
-}
+ // Walk root, looking for .toml files describing a compressor.
+ // Parse these toml files, create a Compressor and add it to compressors.
+ err := fp.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
-func Compressors() map[string]map[string]map[string]Compressor {
- return compressors
-}
+ if fp.Ext(path) != ".toml" {
+ return nil
+ }
-func garrettG25660() Compressor {
- maxFlow, err := mass.NewFlowRate(
- mass.Mass{70, mass.Pound},
- time.Minute,
- mass.PoundsPerMinute,
- )
+ path = path[len(root):]
+
+ // manufacturer/series, model
+ manSer, mod := fp.Split(path)
+ manSer = fp.Clean(manSer) // Clean trailing slash
+ mod = mod[:len(mod)-len(".toml")] // Trim .toml extension
+ // manufacturer, series
+ man, ser := fp.Split(manSer)
+ man = fp.Clean(man) // Clean trailing slash
+
+ var exists bool
+ _, exists = compressors[man]
+ if !exists {
+ compressors[man] = make(map[string]map[string]Compressor)
+ }
+ _, exists = compressors[man][ser]
+ if !exists {
+ compressors[man][ser] = make(map[string]Compressor)
+ }
+
+ tomlFile := fp.Join(root, path)
+
+ var c Compressor
+ _, err = toml.DecodeFile(tomlFile, &c)
+ if err != nil {
+ return err
+ }
+
+ // Replace .toml with .jpg
+ imageFile := tomlFile[:len(tomlFile)-len(".toml")] + ".jpg"
+ c.FileName = imageFile
+
+ // Must parse MaxFlow seperately because the MassFlowRateUnit
+ // is stored as a string and must be converted with
+ // FlowRateUnitFromString().
+ flow := struct {
+ FlowVal float32
+ FlowUnit string
+ }{}
+ _, err = toml.DecodeFile(tomlFile, &flow)
+ if err != nil {
+ return err
+ }
+ u, err := mass.FlowRateUnitFromString(flow.FlowUnit)
+ if err != nil {
+ return err
+ }
+ c.MaxFlow = mass.FlowRate{flow.FlowVal, u}
+
+ compressors[man][ser][mod] = c
+
+ return nil
+ })
util.Check(err)
- return Compressor{
- "Garrett G25-660",
- "compressor/res/garrett/g/25-660.jpg",
- 204,
- 1885,
- 1665,
- 25,
- maxFlow,
- 4.0,
- }
}
-func borgwarnerEFR6258() Compressor {
- maxFlow, err := mass.NewFlowRate(
- mass.Mass{0.50, mass.Kilogram},
- time.Second,
- mass.KilogramsPerSecond,
- )
- util.Check(err)
- return Compressor{
- "BorgWarner EFR6258",
- "compressor/res/borgwarner/efr/6258.jpg",
- 47,
- 455,
- 773,
- 6,
- maxFlow,
- 3.8,
- }
+func Compressors() map[string]map[string]map[string]Compressor {
+ return compressors
}
func borgwarnerK04() Compressor {
diff --git a/compressor/res/borgwarner/efr/6258.toml b/compressor/res/borgwarner/efr/6258.toml
new file mode 100644
index 0000000..1a678a0
--- /dev/null
+++ b/compressor/res/borgwarner/efr/6258.toml
@@ -0,0 +1,8 @@
+name = "BorgWarner EFR6258"
+minx = 47
+miny = 455
+maxx = 773
+maxy = 6
+maxpr = 3.8
+flowval = 0.50
+flowunit = "kg/s"
diff --git a/compressor/res/borgwarner/k/03.toml b/compressor/res/borgwarner/k/03.toml
new file mode 100644
index 0000000..06f808c
--- /dev/null
+++ b/compressor/res/borgwarner/k/03.toml
@@ -0,0 +1,8 @@
+name = "BorgWarner K03"
+minx = 30
+miny = 714
+maxx = 876
+maxy = 4
+maxpr = 2.8
+flowval = 0.13
+flowunit = "kg/s"
diff --git a/compressor/res/borgwarner/k/04.toml b/compressor/res/borgwarner/k/04.toml
new file mode 100644
index 0000000..48908d2
--- /dev/null
+++ b/compressor/res/borgwarner/k/04.toml
@@ -0,0 +1,8 @@
+name = "BorgWarner K04"
+minx = 33
+miny = 712
+maxx = 1090
+maxy = 2
+maxpr = 2.8
+flowval = 0.18
+flowunit = "kg/s"
diff --git a/compressor/res/garrett/g/25-660.toml b/compressor/res/garrett/g/25-660.toml
new file mode 100644
index 0000000..6c7b948
--- /dev/null
+++ b/compressor/res/garrett/g/25-660.toml
@@ -0,0 +1,8 @@
+name = "Garrett G25-660"
+minx = 204
+miny = 1885
+maxx = 1665
+maxy = 25
+maxpr = 4.0
+flowval = 70
+flowunit = "lb/min"