forked from mallano/gofem
/
ptnatbcs.go
69 lines (61 loc) · 1.86 KB
/
ptnatbcs.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
// Copyright 2015 Dorival Pedroso and Raul Durand. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fem
import (
"github.com/cpmech/gosl/fun"
"github.com/cpmech/gosl/io"
)
// PtNaturalBc holds information on point natural boundary conditions such as
// prescribed forces or fluxes) at nodes
type PtNaturalBc struct {
Key string // key such as fux, fpl, etc...
Eq int // equation
X []float64 // location
Fcn fun.Func // function
Extra string // extra information
}
// PointLoads is a set of prescribed forces
type PtNaturalBcs struct {
Eq2idx map[int]int // maps eq number to indices in Bcs
Bcs []*PtNaturalBc //active boundary conditions such as prescribed forces
}
// Reset initialises internal structures
func (o *PtNaturalBcs) Reset() {
o.Eq2idx = make(map[int]int)
o.Bcs = make([]*PtNaturalBc, 0)
}
// AddToRhs adds the boundary conditions terms to the augmented fb vector
func (o PtNaturalBcs) AddToRhs(fb []float64, t float64) {
for _, p := range o.Bcs {
fb[p.Eq] += p.Fcn.F(t, p.X)
}
}
// Set sets new point natural boundary condition data
func (o *PtNaturalBcs) Set(key string, nod *Node, fcn fun.Func, extra string) (setisok bool) {
d := nod.GetDof(key)
if d == nil { // handle LBB nodes
return
}
if idx, ok := o.Eq2idx[d.Eq]; ok {
o.Bcs[idx].Key = "f" + key
o.Bcs[idx].Eq = d.Eq
o.Bcs[idx].X = nod.Vert.C
o.Bcs[idx].Fcn = fcn
o.Bcs[idx].Extra = extra
} else {
o.Eq2idx[d.Eq] = len(o.Bcs)
o.Bcs = append(o.Bcs, &PtNaturalBc{"f" + key, d.Eq, nod.Vert.C, fcn, extra})
}
return true
}
// List returns a simple list logging bcs at time t
func (o *PtNaturalBcs) List(t float64) (l string) {
for i, bc := range o.Bcs {
if i > 0 {
l += " "
}
l += io.Sf("[%s eq=%d f(%g)=%g x=%v]", bc.Key, bc.Eq, t, bc.Fcn.F(t, bc.X), bc.X)
}
return
}