-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3plot_part.go
105 lines (83 loc) · 2.6 KB
/
d3plot_part.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
95
96
97
98
99
100
101
102
103
104
105
package dynareadout
/*
#cgo CFLAGS: -ansi
#include "dynareadout/src/d3plot.h"
*/
import "C"
import (
"errors"
"unsafe"
)
type D3plotPart struct {
handle C.d3plot_part
}
func (part D3plotPart) SolidID(index int) uint64 {
return *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(part.handle.solid_ids)) + uintptr(index)*unsafe.Sizeof(*part.handle.solid_ids)))
}
func (part D3plotPart) BeamID(index int) uint64 {
return *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(part.handle.beam_ids)) + uintptr(index)*unsafe.Sizeof(*part.handle.beam_ids)))
}
func (part D3plotPart) ShellID(index int) uint64 {
return *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(part.handle.shell_ids)) + uintptr(index)*unsafe.Sizeof(*part.handle.shell_ids)))
}
func (part D3plotPart) ThickShellID(index int) uint64 {
return *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(part.handle.thick_shell_ids)) + uintptr(index)*unsafe.Sizeof(*part.handle.thick_shell_ids)))
}
func (part D3plotPart) LenSolidIDs() int {
return int(part.handle.num_solids)
}
func (part D3plotPart) LenBeamIDs() int {
return int(part.handle.num_beams)
}
func (part D3plotPart) LenShellIDs() int {
return int(part.handle.num_shells)
}
func (part D3plotPart) LenThickShellIDs() int {
return int(part.handle.num_thick_shells)
}
func (part D3plotPart) Free() {
C.d3plot_free_part(&part.handle)
}
func (part D3plotPart) GetNodeIDs(plotFile D3plot) ([]uint64, error) {
var numPartNodeIDs C.size_t
dataC := C.d3plot_part_get_node_ids2(&plotFile.handle, &part.handle, &numPartNodeIDs, nil, 0, nil, 0, nil, 0, nil, 0, nil, 0, nil, nil, nil, nil)
if plotFile.handle.error_string != nil {
err := errors.New(C.GoString(plotFile.handle.error_string))
return nil, err
}
data := carrToSlice[C.d3_word, uint64](dataC, numPartNodeIDs)
return data, nil
}
func (part D3plotPart) GetNodeIndices(plotFile D3plot) ([]uint64, error) {
var numPartNodeIDs C.size_t
dataC := C.d3plot_part_get_node_indices2(&plotFile.handle, &part.handle, &numPartNodeIDs, nil, 0, nil, 0, nil, 0, nil, 0, nil, nil, nil, nil)
if plotFile.handle.error_string != nil {
err := errors.New(C.GoString(plotFile.handle.error_string))
return nil, err
}
data := carrToSlice[C.d3_word, uint64](dataC, numPartNodeIDs)
return data, nil
}
func (part D3plotPart) GetNumNodes(plotFile D3plot) (int, error) {
numNodes := C.d3plot_part_get_num_nodes2(
&plotFile.handle,
&part.handle,
nil,
0,
nil,
0,
nil,
0,
nil,
0,
nil,
nil,
nil,
nil,
)
if plotFile.handle.error_string != nil {
err := errors.New(C.GoString(plotFile.handle.error_string))
return 0, err
}
return int(numNodes), nil
}