Exemple #1
0
func main() {

	// vtk scene
	scene := vtk.NewScene()

	// setting the scene up
	scene.WithPlanes = false
	scene.HydroLine = false
	scene.AxesLen = 2

	// function
	r := 1.0 // radius
	fcn := func(x []float64) (f, vx, vy, vz float64) {
		f = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] - r*r
		return
	}

	// iso-surface object
	surface := vtk.NewIsoSurf(fcn)
	surface.AddTo(scene) // add surface to scene

	// add arrow
	arrow := vtk.NewArrow()
	arrow.V = []float64{2, 2, 2}
	arrow.AddTo(scene) // add arrow to scene

	// filename for saving figure on exit
	scene.Fnk = "/tmp/example01"
	scene.SaveOnExit = true

	// add to scene and show in interactive mode
	scene.Run()
}
Exemple #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 := calc_p(x), calc_q(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 := calc_p(x), calc_q(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.SaveOnExit = true
	scn.Fnk = "/tmp/gosl/vtk_isosurf01"
	scn.Run()
}
Exemple #3
0
func main() {

	α := 0.45
	κ := 2000.0
	SQ3 := math.Sqrt(3.0)
	M := 3.0 * SQ3 * α
	qy0 := SQ3 * κ

	sinφ := 3.0 * M / (M + 6.0)
	φrad := math.Asin(sinφ)
	φdeg := φrad * 180.0 / math.Pi
	cosφ := math.Cos(φrad)
	tanφ := math.Tan(φrad)
	c := qy0 * tanφ / M
	pt := c / tanφ
	κ_ := 6.0 * c * cosφ / (SQ3 * (3.0 - sinφ))
	io.Pforan("α   = %v\n", α)
	io.Pforan("κ   = %v  (%v)\n", κ, κ_)
	io.Pforan("φ   = %v\n", φdeg)
	io.Pforan("c   = %v\n", c)
	io.Pforan("M   = %v\n", M)
	io.Pforan("qy0 = %v\n", qy0)

	scn := vtk.NewScene()
	scn.AxesLen = c * SQ3

	pqth := []float64{-pt, pt, 0, pt * M * 1.2, 0, 360}
	ndiv := []int{21, 21, 41}

	cone1 := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
		I1, sqJ2d := calc_I1(x), calc_sqJ2d(x)
		f = sqJ2d - α*I1 - κ
		return
	})
	cone1.Limits = pqth
	cone1.Ndiv = ndiv
	cone1.OctRotate = true
	cone1.GridShowPts = false
	cone1.Color = []float64{1, 0, 0, 1.0}
	cone1.CmapNclrs = 0
	cone1.AddTo(scn)

	cone2 := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
		p, q := calc_p(x), calc_q(x)
		f = q - M*p - qy0
		return
	})
	cone2.Limits = pqth
	cone2.Ndiv = ndiv
	cone2.OctRotate = true
	cone2.GridShowPts = false
	cone2.Color = []float64{0, 0, 1, 0.5}
	cone2.ShowWire = true
	cone2.CmapNclrs = 0
	cone2.AddTo(scn)

	arr := vtk.NewArrow()
	arr.X0 = []float64{-pt / SQ3, -pt / SQ3, -pt / SQ3}
	arr.V = []float64{pt, pt, pt}
	arr.Color = []float64{0, 1, 0, 1}
	arr.CyliRad = κ / 10
	arr.ConeRad = 1.2 * κ / 10
	arr.ConePct = 0.5
	arr.AddTo(scn)

	scn.Run()
}