-
Notifications
You must be signed in to change notification settings - Fork 0
/
hstrat.go
94 lines (84 loc) · 1.92 KB
/
hstrat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package grid
import (
"fmt"
"log"
"math"
"github.com/maseology/mmio"
)
type HSTRAT struct {
Nam string
MinThick float64
Nlay int
Cells map[int]Cell
}
type Cell struct {
Top, Bottom, N, Ss, Sy, H0 float32
K []float32
}
func ReadHSTRAT(fp string, print bool) (*HSTRAT, error) {
big := func(i int) string {
return mmio.Thousands(int64(i))
}
gd, err := ReadGDEF(mmio.RemoveExtension(fp)+".gdef", true)
if err != nil {
log.Fatalf(" ReadHSTRAT gdef read error: %v", err)
}
fmt.Printf(" HSTRAT-GDEF read: %s cells (%d rows, %d columns), %s actives\n", big(gd.Ncells()), gd.Nrow, gd.Ncol, big(gd.Nact))
b := mmio.OpenBinary(fp)
if mmio.ReadString(b) != "grid" {
panic("todo")
}
nam := mmio.ReadString(b)
cs, minthick, nlay := func() (map[int]Cell, float64, int) {
cs, tn := make(map[int]Cell), float32(math.MaxFloat32)
dnlay := make(map[int]bool)
nc := gd.Ncells()
for {
cid, ok := mmio.ReadInt32check(b)
if !ok {
break // EOF
}
top := mmio.ReadFloat32(b)
nl := int(mmio.ReadInt8(b))
for ly := 0; ly < nl; ly++ {
lcid := int(cid) + ly*nc
bottom := mmio.ReadFloat32(b)
if top-bottom < tn {
tn = top - bottom
}
c := Cell{
Top: top,
Bottom: bottom,
N: mmio.ReadFloat32(b),
Ss: mmio.ReadFloat32(b),
Sy: mmio.ReadFloat32(b),
H0: mmio.ReadFloat32(b),
}
top = bottom
nk := int(mmio.ReadInt8(b))
c.K = make([]float32, nk)
for i := 0; i < nk; i++ {
c.K[i] = mmio.ReadFloat32(b) // k[d]
}
cs[lcid] = c
}
// fmt.Println(top, nl)
dnlay[nl] = true
}
// check uniform layering
nlys := make([]int, 0, len(dnlay))
for k := range dnlay {
nlys = append(nlys, k)
}
if len(nlys) == 1 {
return cs, float64(tn), nlys[0]
}
return cs, float64(tn), -1
}()
return &HSTRAT{
Nam: nam,
MinThick: minthick,
Nlay: nlay,
Cells: cs,
}, nil
}