-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.go
130 lines (109 loc) · 3.24 KB
/
node.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package structure
import (
"fmt"
"github.com/angelsolaorbaiceta/inkfem/contracts"
"github.com/angelsolaorbaiceta/inkgeom/g2d"
)
const unsetDOFNumber = -1
// Node is a point in the structure where one or more resistant elements meet.
type Node struct {
id contracts.StrID
Position *g2d.Point
ExternalConstraint *Constraint
globalDof [3]int
}
// MakeNode creates a new node with the given id, position and external constraint.
func MakeNode(
id contracts.StrID,
position *g2d.Point,
externalConstraint *Constraint,
) *Node {
return &Node{
id,
position,
externalConstraint,
[3]int{unsetDOFNumber, unsetDOFNumber, unsetDOFNumber},
}
}
// MakeNodeAtPosition creates a new node with the given id, position coordinates and external constraint.
func MakeNodeAtPosition(
id contracts.StrID,
x, y float64,
externalConstraint *Constraint,
) *Node {
return &Node{
id,
g2d.MakePoint(x, y),
externalConstraint,
[3]int{unsetDOFNumber, unsetDOFNumber, unsetDOFNumber},
}
}
// MakeFreeNodeAtPosition creates a new node without external constraint, with the given id and
// position by coordinates.
func MakeFreeNodeAtPosition(id contracts.StrID, x, y float64) *Node {
return &Node{
id,
g2d.MakePoint(x, y),
&NilConstraint,
[3]int{unsetDOFNumber, unsetDOFNumber, unsetDOFNumber},
}
}
func (n Node) Copy() *Node {
return MakeNode(n.id, n.Position, n.ExternalConstraint)
}
// IsExternallyConstrained returns true if this node is externally constrained.
func (n Node) IsExternallyConstrained() bool {
return n.ExternalConstraint != &NilConstraint
}
// DegreesOfFreedomNum returns the degrees of freedom numbers assigned to the node.
func (n Node) DegreesOfFreedomNum() [3]int {
return n.globalDof
}
func (n Node) DxDegreeOfFreedomNum() int {
return n.globalDof[0]
}
func (n Node) DyDegreeOfFreedomNum() int {
return n.globalDof[1]
}
func (n Node) RzDegreeOfFreedomNum() int {
return n.globalDof[2]
}
// HasDegreesOfFreedomNum returns true if the node has already been assigned degress of freedom.
func (n Node) HasDegreesOfFreedomNum() bool {
return n.globalDof[0] != unsetDOFNumber &&
n.globalDof[1] != unsetDOFNumber &&
n.globalDof[2] != unsetDOFNumber
}
// SetDegreesOfFreedomNum assigns numbers to the degress of freedom of the node.
func (n *Node) SetDegreesOfFreedomNum(dx, dy, rz int) *Node {
n.globalDof[0] = dx
n.globalDof[1] = dy
n.globalDof[2] = rz
return n
}
// Equals tests whether this node and other are equal.
func (n *Node) Equals(other *Node) bool {
return n.Position.Equals(other.Position) &&
n.ExternalConstraint.Equals(other.ExternalConstraint) &&
n.globalDof[0] == other.globalDof[0] &&
n.globalDof[1] == other.globalDof[1] &&
n.globalDof[2] == other.globalDof[2]
}
// GetID returns the node's id.
func (n Node) GetID() contracts.StrID {
return n.id
}
// String representation of the node.
// This method is used for serialization, thus if the format is changed, the definition,
// preprocessed and solution file formats are affected.
func (n Node) String() string {
str := fmt.Sprintf(
"%s -> %f %f %s",
n.id, n.Position.X(), n.Position.Y(),
n.ExternalConstraint.String(),
)
if n.HasDegreesOfFreedomNum() {
str += fmt.Sprintf(" | %v", n.DegreesOfFreedomNum())
}
return str
}