forked from cpmech/gosl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtk_isosurf01.go
More file actions
82 lines (67 loc) · 1.96 KB
/
vtk_isosurf01.go
File metadata and controls
82 lines (67 loc) · 1.96 KB
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
// Copyright 2016 The Gosl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"math"
"github.com/cpmech/gosl/vtk"
)
func calcP(x []float64) float64 {
return -(x[0] + x[1] + x[2]) / 3.0
}
func calcQ(x []float64) float64 {
return math.Sqrt(((x[0]-x[1])*(x[0]-x[1]) +
(x[1]-x[2])*(x[1]-x[2]) +
(x[2]-x[0])*(x[2]-x[0])) / 2.0)
}
func main() {
// create a new VTK Scene
scn := vtk.NewScene()
scn.Reverse = true // start viewing the negative side of the x-y-z Cartesian system
// parameters
M := 1.0 // slope of line in p-q graph
pt := 0.0 // tensile p
a0 := 0.8 // size of surface
// limits and divisions for grid generation
pqth := []float64{pt, a0, 0, M * a0, 0, 360}
ndiv := []int{21, 21, 41}
// cone symbolising the Drucker-Prager criterion
cone := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
p, q := calcP(x), calcQ(x)
f = q - M*p
return
})
cone.Limits = pqth
cone.Ndiv = ndiv
cone.OctRotate = true
cone.GridShowPts = false
cone.Color = []float64{0, 1, 1, 1}
cone.CmapNclrs = 0 // use this to use specified color
cone.AddTo(scn) // remember to add to Scene
// ellipsoid symbolising the Cam-clay yield surface
ellipsoid := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
p, q := calcP(x), calcQ(x)
f = q*q + M*M*(p-pt)*(p-a0)
return
})
ellipsoid.Limits = pqth
cone.Ndiv = ndiv
ellipsoid.OctRotate = true
ellipsoid.Color = []float64{1, 1, 0, 0.5}
ellipsoid.CmapNclrs = 0 // use this to use specified color
ellipsoid.AddTo(scn) // remember to add to Scene
// illustrate use of Arrow
arr := vtk.NewArrow() // X0 is equal to origin
arr.V = []float64{-1, -1, -1}
arr.AddTo(scn)
// illustrate use of Sphere
sph := vtk.NewSphere()
sph.Cen = []float64{-a0, -a0, -a0}
sph.R = 0.05
sph.AddTo(scn)
// start interactive mode
scn.SavePng = true
scn.Fnk = "/tmp/gosl/vtk_isosurf01"
scn.Run()
}