Example #1
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()
}
Example #2
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()
}
Example #3
0
func main() {

	// create a new VTK Scene
	scn := vtk.NewScene()
	scn.HydroLine = true
	scn.FullAxes = true
	scn.AxesLen = 1.5

	// parameters
	α := 180.0 * math.Atan(1.0/math.Sqrt2) / math.Pi // <<< touches lower plane
	α = 90.0 - α                                     // <<< touches upper plane
	α = 15.0
	kα := math.Tan(α * math.Pi / 180.0)

	// cone
	cone := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
		f = cone_angle(x) - kα
		return
	})
	cone.Limits = []float64{0, -1, 0, 1, 0, 360}
	cone.Ndiv = []int{21, 21, 41}
	cone.OctRotate = true
	cone.GridShowPts = false
	cone.Color = []float64{0, 1, 0, 1}
	cone.CmapNclrs = 0 // use this to use specified color
	cone.AddTo(scn)    // remember to add to Scene

	// spheres
	sset := vtk.NewSpheresFromFile("points.dat")
	if true {
		sset.AddTo(scn)
	}

	// start interactive mode
	scn.SavePng = false
	scn.Fnk = "/tmp/vtk_cone01"
	scn.Run()
}
Example #4
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()
}
Example #5
0
func vtk_plot3(opt *goga.Optimiser, αcone, ptRad float64, onlyFront0, twice bool) {

	// results
	var X, Y, Z []float64
	if onlyFront0 {
		for _, sol := range opt.Solutions {
			if sol.Feasible() && sol.FrontId == 0 {
				X = append(X, sol.Ova[0])
				Y = append(Y, sol.Ova[1])
				Z = append(Z, sol.Ova[2])
			}
		}
	} else {
		X, Y, Z = make([]float64, opt.Nsol), make([]float64, opt.Nsol), make([]float64, opt.Nsol)
		for i, sol := range opt.Solutions {
			X[i], Y[i], Z[i] = sol.Ova[0], sol.Ova[1], sol.Ova[2]
		}
	}

	// create a new VTK Scene
	scn := vtk.NewScene()
	scn.HydroLine = false
	scn.FullAxes = false
	scn.AxesLen = 1.1
	scn.WithPlanes = false
	scn.LblX = io.Sf("f%d", 0)
	scn.LblY = io.Sf("f%d", 1)
	scn.LblZ = io.Sf("f%d", 2)
	scn.LblSz = 20
	if opt.RptName == "DTLZ1" {
		scn.AxesLen = 0.6
	}

	// optimal Pareto front
	front := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
		f = opt.Multi_fcnErr(x)
		return
	})
	front.Limits = []float64{opt.RptFmin[0], opt.RptFmax[0], opt.RptFmin[1], opt.RptFmax[1], opt.RptFmin[2], opt.RptFmax[2]}
	front.Color = []float64{0.45098039, 0.70588235, 1., 0.8}
	front.CmapNclrs = 0 // use this to use specified color
	front.Ndiv = []int{61, 61, 61}
	front.AddTo(scn)

	// cone
	if opt.RptName == "DTLZ2c" {
		cone := vtk.NewIsoSurf(func(x []float64) (f, vx, vy, vz float64) {
			f = cone_angle(x) - math.Tan(αcone)
			return
		})
		cone.Limits = []float64{0, -1, 0, 1, 0, 360}
		cone.Ndiv = []int{61, 61, 81}
		cone.OctRotate = true
		cone.GridShowPts = false
		cone.Color = []float64{0.96862745, 0.75294118, 0.40784314, 0.5}
		cone.CmapNclrs = 0 // use this to use specified color
		cone.AddTo(scn)    // remember to add to Scene
	}

	// particles
	var P vtk.Spheres
	P.X, P.Y, P.Z = X, Y, Z
	P.R = utl.DblVals(len(X), ptRad)
	P.Color = []float64{1, 0, 0, 1}
	P.AddTo(scn)

	// start interactive mode
	scn.SaveEps = false
	scn.SavePng = true
	scn.PngMag = 2
	scn.Fnk = io.Sf("/tmp/goga/vtk_%s_A", opt.RptName)
	scn.Run()
	if twice {
		scn.Fnk = io.Sf("/tmp/goga/vtk_%s_B", opt.RptName)
		scn.Run()
	}
}