本文整理汇总了Golang中github.com/cpmech/gosl/io.Pfpink函数的典型用法代码示例。如果您正苦于以下问题:Golang Pfpink函数的具体用法?Golang Pfpink怎么用?Golang Pfpink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pfpink函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: msg
// msg prints information on residuals
func (o *NlSolver) msg(typ string, it int, Ldx, fx_max float64, first, last bool) {
if first {
io.Pfpink("\n%4s%23s%23s\n", "it", "Ldx", "fx_max")
io.Pfpink("%4s%23s%23s\n", "", io.Sf("(%7.1e)", o.fnewt), io.Sf("(%7.1e)", o.ftol))
return
}
io.Pfyel("%4d%23.15e%23.15e\n", it, Ldx, fx_max)
if last {
io.Pfgrey(". . . converged with %s. nit=%d, nFeval=%d, nJeval=%d\n", typ, it, o.NFeval, o.NJeval)
}
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:12,代码来源:nlsolver.go
示例2: Test_GOflt01
func Test_GOflt01(tst *testing.T) {
//verbose()
chk.PrintTitle("GOflt01. float64")
Init(1234)
xmin := 10.0
xmax := 20.0
vals := make([]float64, NSAMPLES)
// using Float64
t0 := time.Now()
for i := 0; i < NSAMPLES; i++ {
vals[i] = Float64(xmin, xmax)
}
io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))
hist := Histogram{Stations: []float64{10, 12.5, 15, 17.5, 20}}
hist.Count(vals, true)
io.Pfpink(TextHist(hist.GenLabels("%4g"), hist.Counts, 60))
// using Float64s
t0 = time.Now()
Float64s(vals, xmin, xmax)
io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))
hist.Count(vals, true)
io.Pfblue2(TextHist(hist.GenLabels("%4g"), hist.Counts, 60))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:30,代码来源:t_random_test.go
示例3: Test_fileio01
func Test_fileio01(tst *testing.T) {
//verbose()
chk.PrintTitle("fileio01")
// start
analysis := NewFEM("data/bh16.sim", "", true, false, false, false, chk.Verbose, 0)
// domain A
domsA := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false)
if len(domsA) == 0 {
tst.Errorf("NewDomains failed\n")
return
}
domA := domsA[0]
err := domA.SetStage(0)
if err != nil {
tst.Errorf("SetStage failed\n%v", err)
return
}
for i, _ := range domA.Sol.Y {
domA.Sol.Y[i] = float64(i)
}
io.Pforan("domA.Sol.Y = %v\n", domA.Sol.Y)
// write file
tidx := 123
err = domA.SaveSol(tidx, true)
if err != nil {
tst.Errorf("SaveSol failed:\n%v", err)
return
}
// domain B
domsB := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false)
if len(domsB) == 0 {
tst.Errorf("NewDomains failed\n")
return
}
domB := domsB[0]
err = domB.SetStage(0)
if err != nil {
tst.Errorf("SetStage failed\n%v", err)
return
}
io.Pfpink("domB.Sol.Y (before) = %v\n", domB.Sol.Y)
// read file
err = domB.ReadSol(analysis.Sim.DirOut, analysis.Sim.Key, analysis.Sim.EncType, tidx)
if err != nil {
tst.Errorf("ReadSol failed:\n%v", err)
return
}
io.Pfgreen("domB.Sol.Y (after) = %v\n", domB.Sol.Y)
// check
chk.Vector(tst, "Y", 1e-17, domA.Sol.Y, domB.Sol.Y)
chk.Vector(tst, "dy/dt", 1e-17, domA.Sol.Dydt, domB.Sol.Dydt)
chk.Vector(tst, "d²y/dt²", 1e-17, domA.Sol.D2ydt2, domB.Sol.D2ydt2)
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:60,代码来源:t_fileio_test.go
示例4: Test_ind02
func Test_ind02(tst *testing.T) {
//verbose()
chk.PrintTitle("ind02. copy into")
rnd.Init(0)
nbases := 1
A := get_individual(0, nbases)
B := get_individual(1, nbases)
fmts := map[string][]string{
"int": {"%2d", "%4d", "%5d"}, // ints
"flt": {"%6g", "%6g", "%5g"}, // floats
"str": {"%4s", "%2s", "%2s"}, // strings
"key": {"%3x", "%3x", "%3x"}, // keys
"byt": {"%4s", "%4s", "%4s"}, // bytes
"fun": {"%3s", "%3s", "%3s"}, // funcs
}
io.Pfpink("A = %v\n", A.Output(fmts, false))
io.Pfcyan("B = %v\n", B.Output(fmts, false))
var ops OpsData
ops.SetDefault()
ops.Pc = 1.0
ops.Cuts = []int{1, 2}
ops.Xrange = [][]float64{{0, 1}, {-20, 20}, {-300, 300}}
a := A.GetCopy()
b := A.GetCopy()
IndCrossover(a, b, A, B, 0, &ops)
io.Pforan("a = %v\n", a.Output(fmts, false))
io.Pfblue2("b = %v\n", b.Output(fmts, false))
chk.Ints(tst, "a.Ints ", a.Ints, []int{1, -20, 300})
chk.Ints(tst, "b.Ints ", b.Ints, []int{-1, 20, -300})
chk.Strings(tst, "a.Strings", a.Strings, []string{"abc", "Y", "c"})
chk.Strings(tst, "b.Strings", b.Strings, []string{"X", "b", "Z"})
// TODO: add other tests here
io.Pf("\n")
x := get_individual(0, nbases)
x.Ovas = []float64{0, 0}
x.Oors = []float64{0, 0, 0}
io.Pfblue2("x = %v\n", x.Output(fmts, false))
B.CopyInto(x)
chk.Scalar(tst, "ova0", 1e-17, x.Ovas[0], 200)
chk.Scalar(tst, "ova1", 1e-17, x.Ovas[1], 100)
chk.Scalar(tst, "oor0", 1e-17, x.Oors[0], 15)
chk.Scalar(tst, "oor1", 1e-17, x.Oors[1], 25)
chk.Scalar(tst, "oor2", 1e-17, x.Oors[2], 35)
io.Pforan("x = %v\n", x.Output(fmts, false))
chk.String(tst, x.Output(fmts, false), B.Output(fmts, false))
}
开发者ID:postfix,项目名称:goga-1,代码行数:57,代码来源:t_individual_test.go
示例5: Test_fileio01
func Test_fileio01(tst *testing.T) {
chk.PrintTitle("fileio01")
// start
if !Start("data/bh16.sim", true, chk.Verbose) {
tst.Errorf("test failed\n")
}
defer End()
// domain A
distr := false
domA := NewDomain(Global.Sim.Regions[0], distr)
if domA == nil {
tst.Errorf("test failed\n")
}
if !domA.SetStage(0, Global.Sim.Stages[0], distr) {
tst.Errorf("test failed\n")
}
for i, _ := range domA.Sol.Y {
domA.Sol.Y[i] = float64(i)
}
io.Pforan("domA.Sol.Y = %v\n", domA.Sol.Y)
// write file
tidx := 123
if !domA.SaveSol(tidx) {
tst.Errorf("test failed")
return
}
dir, fnk := Global.Dirout, Global.Fnkey
io.Pfblue2("file %v written\n", out_nod_path(dir, fnk, tidx, Global.Rank))
// domain B
domB := NewDomain(Global.Sim.Regions[0], distr)
if domB == nil {
tst.Errorf("test failed\n")
}
if !domB.SetStage(0, Global.Sim.Stages[0], distr) {
tst.Errorf("test failed")
}
io.Pfpink("domB.Sol.Y (before) = %v\n", domB.Sol.Y)
// read file
if !domB.ReadSol(dir, fnk, tidx) {
tst.Errorf("test failed")
return
}
io.Pfgreen("domB.Sol.Y (after) = %v\n", domB.Sol.Y)
// check
chk.Vector(tst, "Y", 1e-17, domA.Sol.Y, domB.Sol.Y)
chk.Vector(tst, "dy/dt", 1e-17, domA.Sol.Dydt, domB.Sol.Dydt)
chk.Vector(tst, "d²y/dt²", 1e-17, domA.Sol.D2ydt2, domB.Sol.D2ydt2)
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:55,代码来源:t_fileio_test.go
示例6: Test_sort05
func Test_sort05(tst *testing.T) {
//verbose()
chk.PrintTitle("sort05")
a := map[string]int{"a": 1, "z": 2, "c": 3, "y": 4, "d": 5, "b": 6, "x": 7}
b := map[string]float64{"a": 1, "z": 2, "c": 3, "y": 4, "d": 5, "b": 6, "x": 7}
c := map[string]bool{"a": false, "z": true, "c": false, "y": true, "d": true, "b": false, "x": true}
ka := StrIntMapSort(a)
kb := StrDblMapSort(b)
kc := StrBoolMapSort(c)
io.Pforan("sorted_keys(a) = %v\n", ka)
io.Pforan("sorted_keys(b) = %v\n", kb)
io.Pforan("sorted_keys(c) = %v\n", kc)
chk.Strings(tst, "ka", ka, []string{"a", "b", "c", "d", "x", "y", "z"})
chk.Strings(tst, "kb", kb, []string{"a", "b", "c", "d", "x", "y", "z"})
chk.Strings(tst, "kc", kc, []string{"a", "b", "c", "d", "x", "y", "z"})
ka, va := StrIntMapSortSplit(a)
io.Pfpink("sorted_keys(a) = %v\n", ka)
io.Pfpink("sorted_vals(a) = %v\n", va)
chk.Strings(tst, "ka", ka, []string{"a", "b", "c", "d", "x", "y", "z"})
chk.Ints(tst, "va", va, []int{1, 6, 3, 5, 7, 4, 2})
kb, vb := StrDblMapSortSplit(b)
io.Pfcyan("sorted_keys(b) = %v\n", kb)
io.Pfcyan("sorted_vals(b) = %v\n", vb)
chk.Strings(tst, "kb", kb, []string{"a", "b", "c", "d", "x", "y", "z"})
chk.Vector(tst, "vb", 1e-16, vb, []float64{1, 6, 3, 5, 7, 4, 2})
kc, vc := StrBoolMapSortSplit(c)
io.Pfcyan("sorted_keys(c) = %v\n", kc)
io.Pfcyan("sorted_vals(c) = %v\n", vc)
chk.Strings(tst, "kc", kc, []string{"a", "b", "c", "d", "x", "y", "z"})
chk.Bools(tst, "vc", vc, []bool{false, false, false, true, true, true, true})
}
开发者ID:PatrickSchm,项目名称:gosl,代码行数:36,代码来源:t_sorting_test.go
示例7: KrefineN
// KrefineN return a new Nurbs with each span divided into ndiv parts = [2, 3, ...]
func (o *Nurbs) KrefineN(ndiv int, hughesEtAlPaper bool) *Nurbs {
X := make([][]float64, o.gnd)
if hughesEtAlPaper {
elems := o.Elements()
switch o.gnd {
case 2:
for _, e := range elems {
umin, umax := o.b[0].T[e[0]], o.b[0].T[e[1]]
vmin, vmax := o.b[1].T[e[2]], o.b[1].T[e[3]]
xa := o.Point([]float64{umin, vmin})
xb := o.Point([]float64{umax, vmin})
xc := []float64{(xa[0] + xb[0]) / 2.0, (xa[1] + xb[1]) / 2.0}
io.Pf("xa = %v\n", xa)
io.Pf("xb = %v\n", xb)
io.Pf("xc = %v\n", xc)
xa = o.Point([]float64{umin, vmax})
xb = o.Point([]float64{umax, vmax})
xc = []float64{(xa[0] + xb[0]) / 2.0, (xa[1] + xb[1]) / 2.0}
io.Pfpink("xa, xb, xc = %v, %v, %v\n", xa, xb, xc)
chk.Panic("KrefineN with hughesEtAlPaper==true is not implemented in 2D yet")
}
case 3:
chk.Panic("KrefineN with hughesEtAlPaper==true is not implemented in 3D yet")
}
io.Pfgrey("KrefineN with hughesEtAlPaper==true => not implemented yet\n")
return nil
} else {
for d := 0; d < o.gnd; d++ {
nspans := o.b[d].m - 2*o.p[d] - 1
nnewk := nspans * (ndiv - 1)
X[d] = make([]float64, nnewk)
k := 0
for i := 0; i < nspans; i++ {
umin, umax := o.b[d].T[o.p[d]+i], o.b[d].T[o.p[d]+i+1]
du := (umax - umin) / float64(ndiv)
for j := 1; j < ndiv; j++ {
X[d][k] = umin + du*float64(j)
k += 1
}
}
}
}
return o.Krefine(X)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:48,代码来源:nurbs.go
示例8: Test_nurbs01
func Test_nurbs01(tst *testing.T) {
//verbose()
chk.PrintTitle("nurbs01")
nurbs := get_nurbs_A()
faces := nurbs.ExtractSurfaces()
spans := nurbs.Elements()
ibasis0 := nurbs.IndBasis(spans[0])
ibasis1 := nurbs.IndBasis(spans[1])
io.Pforan("spans = %v\n", spans)
chk.Ints(tst, "span0", spans[0], []int{2, 3, 1, 2})
chk.Ints(tst, "span1", spans[1], []int{3, 4, 1, 2})
chk.Ints(tst, "ibasis0", ibasis0, []int{0, 1, 2, 4, 5, 6})
chk.Ints(tst, "ibasis1", ibasis1, []int{1, 2, 3, 5, 6, 7})
shape0 := GetShapeNurbs(nurbs, faces, spans[0])
shape1 := GetShapeNurbs(nurbs, faces, spans[1])
dux := 0.5
duy := 1.0
drx := 2.0
dry := 2.0
r := []float64{0.75, 0.75, 0}
shape0.NurbsFunc(shape0.S, shape0.DSdR, r, true, -1)
io.Pforan("0: u = %v\n", shape0.U)
chk.Scalar(tst, "0: ux", 1e-17, shape0.U[0], (1.0+r[0])*dux/drx)
chk.Scalar(tst, "0: uy", 1e-17, shape0.U[1], (1.0+r[1])*duy/dry)
chk.Ints(tst, "0: ibasis", shape0.Ibasis, []int{0, 1, 2, 4, 5, 6})
io.Pforan("S(u(r)) = %v\n", shape0.S)
shape1.NurbsFunc(shape1.S, shape1.DSdR, r, true, -1)
io.Pfpink("\n1: u = %v\n", shape1.U)
chk.Scalar(tst, "1: ux", 1e-17, shape1.U[0], 0.5+(1.0+r[0])*dux/drx)
chk.Scalar(tst, "1: uy", 1e-17, shape1.U[1], (1.0+r[1])*duy/dry)
chk.Ints(tst, "1: ibasis", shape1.Ibasis, []int{1, 2, 3, 5, 6, 7})
if chk.Verbose {
gm.PlotNurbs("/tmp/gofem", "tst_nurbs01", nurbs, 21, false, nil)
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:44,代码来源:t_nurbs_test.go
示例9: Test_pareto01
func Test_pareto01(tst *testing.T) {
//verbose()
chk.PrintTitle("pareto01. compare vectors: Pareto-optimal")
u := []float64{1, 2, 3, 4, 5, 6}
v := []float64{1, 2, 3, 4, 5, 6}
io.Pforan("u = %v\n", u)
io.Pfblue2("v = %v\n", v)
u_dominates, v_dominates := DblsParetoMin(u, v)
io.Pfpink("u_dominates = %v\n", u_dominates)
io.Pfpink("v_dominates = %v\n", v_dominates)
if u_dominates {
tst.Errorf("test failed\n")
return
}
if v_dominates {
tst.Errorf("test failed\n")
return
}
v = []float64{1, 1.8, 3, 4, 5, 6}
io.Pforan("\nu = %v\n", u)
io.Pfblue2("v = %v\n", v)
u_dominates, v_dominates = DblsParetoMin(u, v)
io.Pfpink("u_dominates = %v\n", u_dominates)
io.Pfpink("v_dominates = %v\n", v_dominates)
if u_dominates {
tst.Errorf("test failed\n")
return
}
if !v_dominates {
tst.Errorf("test failed\n")
return
}
v = []float64{1, 2.1, 3, 4, 5, 6}
io.Pforan("\nu = %v\n", u)
io.Pfblue2("v = %v\n", v)
u_dominates, v_dominates = DblsParetoMin(u, v)
io.Pfpink("u_dominates = %v\n", u_dominates)
io.Pfpink("v_dominates = %v\n", v_dominates)
if !u_dominates {
tst.Errorf("test failed\n")
return
}
if v_dominates {
tst.Errorf("test failed\n")
return
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:51,代码来源:t_pareto_test.go
示例10: RunInvCheck
func RunInvCheck(tst *testing.T, key string, M, CorrectInvM [][]float64, checkI bool, Tol, TolI float64) {
m, n := len(M), len(M[0])
Mi := MatAlloc(n, m)
t0 := time.Now()
err := MatInvG(Mi, M, 1e-13)
if err != nil {
chk.Panic("%v", err.Error())
}
io.Pfpink("Lapack: time elapsed = %v\n", time.Now().Sub(t0))
MMi := MatAlloc(m, m)
MMiM := MatAlloc(m, n)
MatMul(MMi, 1, M, Mi) // MMi = M * Mi
MatMul(MMiM, 1, MMi, M) // MMiM = M * Mi * M == M
chk.Matrix(tst, io.Sf("%s => Mi - CorrectInvM ", key), Tol, Mi, CorrectInvM)
chk.Matrix(tst, io.Sf("%s => M*Mi*M = M ", key), Tol, MMiM, M)
if checkI {
I := MatAlloc(m, m)
MatSetDiag(I, 1)
chk.Matrix(tst, io.Sf("%s => M*Mi = I ", key), TolI, MMi, I)
}
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:21,代码来源:t_matinv_test.go
示例11: KrefineN
// KrefineN return a new Nurbs with each span divided into ndiv parts = [2, 3, ...]
func (o *Nurbs) KrefineN(ndiv int, useCspace bool) *Nurbs {
X := make([][]float64, o.gnd)
if useCspace {
elems := o.Elements()
for _, e := range elems {
switch o.gnd {
case 2:
umin, umax := o.b[0].T[e[0]], o.b[0].T[e[1]]
vmin, vmax := o.b[1].T[e[2]], o.b[1].T[e[3]]
xa := o.Point([]float64{umin, vmin})
xb := o.Point([]float64{umax, vmin})
xc := []float64{(xa[0] + xb[0]) / 2.0, (xa[1] + xb[1]) / 2.0}
io.Pforan("xa, xb, xc = %v, %v, %v\n", xa, xb, xc)
xa = o.Point([]float64{umin, vmax})
xb = o.Point([]float64{umax, vmax})
xc = []float64{(xa[0] + xb[0]) / 2.0, (xa[1] + xb[1]) / 2.0}
io.Pfpink("xa, xb, xc = %v, %v, %v\n", xa, xb, xc)
}
}
chk.Panic("nurbs.go: KrefineN with useCspace==true => not implemented yet")
} else {
for d := 0; d < o.gnd; d++ {
nspans := o.b[d].m - 2*o.p[d] - 1
nnewk := nspans * (ndiv - 1)
X[d] = make([]float64, nnewk)
k := 0
for i := 0; i < nspans; i++ {
umin, umax := o.b[d].T[o.p[d]+i], o.b[d].T[o.p[d]+i+1]
du := (umax - umin) / float64(ndiv)
for j := 1; j < ndiv; j++ {
X[d][k] = umin + du*float64(j)
k += 1
}
}
}
}
return o.Krefine(X)
}
开发者ID:PatrickSchm,项目名称:gosl,代码行数:39,代码来源:nurbs.go
示例12: Test_map03
func Test_map03(tst *testing.T) {
//verbose()
chk.PrintTitle("map03")
m := map[string][]int{
"a": []int{100, 101},
"b": []int{1000},
"c": []int{200, 300, 400},
}
io.Pforan("m (before) = %v\n", m)
StrIntsMapAppend(&m, "a", 102)
io.Pfpink("m (after) = %v\n", m)
chk.Ints(tst, "m[\"a\"]", m["a"], []int{100, 101, 102})
chk.Ints(tst, "m[\"b\"]", m["b"], []int{1000})
chk.Ints(tst, "m[\"c\"]", m["c"], []int{200, 300, 400})
StrIntsMapAppend(&m, "d", 666)
io.Pfcyan("m (after) = %v\n", m)
chk.Ints(tst, "m[\"a\"]", m["a"], []int{100, 101, 102})
chk.Ints(tst, "m[\"b\"]", m["b"], []int{1000})
chk.Ints(tst, "m[\"c\"]", m["c"], []int{200, 300, 400})
chk.Ints(tst, "m[\"d\"]", m["d"], []int{666})
chk.Ints(tst, "m[\"e\"]", m["e"], nil)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:24,代码来源:t_maps_test.go
示例13: Test_frechet_03
func Test_frechet_03(tst *testing.T) {
//verbose()
chk.PrintTitle("dist_frechet_03")
μ := 10.0
σ := 5.0
δ := σ / μ
d := 1.0 + δ*δ
io.Pforan("μ=%v σ=%v δ=%v d=%v\n", μ, σ, δ, d)
if chk.Verbose {
plt.AxHline(d, "color='k'")
FrechetPlotCoef("/tmp/gosl", "fig_frechet_coef.eps", 3.0, 5.0)
}
k := 0.2441618
α := 1.0 / k
l := μ - math.Gamma(1.0-k)
io.Pfpink("l=%v α=%v\n", l, α)
l = 8.782275
α = 4.095645
var dist DistFrechet
dist.Init(&VarData{L: l, A: α})
io.Pforan("dist = %+#v\n", dist)
io.Pforan("mean = %v\n", dist.Mean())
io.Pforan("var = %v\n", dist.Variance())
io.Pforan("σ = %v\n", math.Sqrt(dist.Variance()))
if chk.Verbose {
plot_frechet(l, 1, α, 8, 16)
plt.SaveD("/tmp/gosl", "rnd_dist_frechet_03.eps")
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:36,代码来源:t_dist_frechet_test.go
示例14: Test_map01
func Test_map01(tst *testing.T) {
//verbose()
chk.PrintTitle("map01")
m := map[int][]int{
1: []int{100, 101},
2: []int{1000},
3: []int{200, 300, 400},
}
io.Pforan("m (before) = %v\n", m)
IntIntsMapAppend(&m, 1, 102)
io.Pfpink("m (after) = %v\n", m)
chk.Ints(tst, "m[1]", m[1], []int{100, 101, 102})
chk.Ints(tst, "m[2]", m[2], []int{1000})
chk.Ints(tst, "m[3]", m[3], []int{200, 300, 400})
IntIntsMapAppend(&m, 4, 666)
io.Pfcyan("m (after) = %v\n", m)
chk.Ints(tst, "m[1]", m[1], []int{100, 101, 102})
chk.Ints(tst, "m[2]", m[2], []int{1000})
chk.Ints(tst, "m[3]", m[3], []int{200, 300, 400})
chk.Ints(tst, "m[4]", m[4], []int{666})
chk.Ints(tst, "m[5]", m[5], nil)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:24,代码来源:t_maps_test.go
示例15: Test_ends01
func Test_ends01(tst *testing.T) {
//verbose()
chk.PrintTitle("ends01")
size := 8
cuts := []int{5, 7}
ends := GenerateCxEnds(size, 0, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pfyel("ends = %v\n", ends)
chk.IntAssert(len(ends), 3)
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 2
cuts = []int{}
ends = GenerateCxEnds(size, 0, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pforan("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{1, 2})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 3
ncuts := 3
ends = GenerateCxEnds(size, ncuts, nil)
io.Pfpink("size=%v ncuts=%v\n", size, ncuts)
io.Pforan("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{1, 2, 3})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 3
ncuts = 2
ends = GenerateCxEnds(size, ncuts, nil)
io.Pfpink("size=%v ncuts=%v\n", size, ncuts)
io.Pforan("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{1, 2, 3})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 8
cuts = []int{7}
ends = GenerateCxEnds(size, 0, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pforan("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{7, 8})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 8
cuts = []int{2, 5}
ends = GenerateCxEnds(size, 0, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pforan("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{2, 5, 8})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 20
cuts = []int{1, 5, 15, 17}
ends = GenerateCxEnds(size, 0, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pfyel("ends = %v\n", ends)
chk.Ints(tst, "ends", ends, []int{1, 5, 15, 17, 20})
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
size = 20
ncuts = 5
ends = GenerateCxEnds(size, ncuts, cuts)
io.Pfpink("size=%v cuts=%v\n", size, cuts)
io.Pfyel("ends = %v\n", ends)
chk.IntAssert(ends[len(ends)-1], size)
checkRepeated(ends)
io.Pf("\n")
}
开发者ID:postfix,项目名称:goga-1,代码行数:84,代码来源:t_operators_test.go
示例16: Test_isofun01
func Test_isofun01(tst *testing.T) {
//verbose()
chk.PrintTitle("isofun01. rounded cone")
// SMP director parameters
// Note:
// 1) eps and ϵ have an effect on how close to DP/MC SMP will be
// 2) as eps increases, SMP is closer to DP/MC
// 3) as ϵ increases, SMP is closer to DP/MC
// 4) eps also changes the shape of FC surface
a, b, eps, ϵ := -1.0, 0.5, 1e-3, 1e-3
shift := 1.0
// radius
r := 2.0
// failure crit parameters and number of stress components
φ, ncp := 30.0, 6
// q/p coefficient
μ := SmpCalcμ(φ, a, b, eps, ϵ)
io.Pforan("μ = %v\n", μ)
// isotropic functions
var o IsoFun
o.Init(a, b, eps, ϵ, shift, ncp, rounded_cone_ffcn, rounded_cone_gfcn, rounded_cone_hfcn)
// plot
if false {
//if true {
σcCte := 10.0
M := Phi2M(φ, "oct")
rmin, rmax := 0.0, 1.28*M*σcCte
nr, nα := 31, 81
//nr, nα := 31, 1001
npolarc := true
simplec := true
only0 := true
grads := false
showpts := false
ferr := 10.0
PlotOct("fig_isofun01.png", σcCte, rmin, rmax, nr, nα, φ, o.Fa, o.Ga,
npolarc, simplec, only0, grads, showpts, true, true, ferr, r, μ)
}
// 3D view
if false {
//if true {
grads := true
gftol := 5e-2
o.View(10, nil, grads, gftol, func(e *vtk.IsoSurf) {
e.Nlevels = 7
}, r, μ)
}
// constants
ver := chk.Verbose
tol := 1e-6
tol2 := 1e-6
tolq := tol2
// check gradients
for idxA := 0; idxA < len(test_nd); idxA++ {
//for idxA := 0; idxA < 1; idxA++ {
//for idxA := 2; idxA < 3; idxA++ {
//for idxA := 10; idxA < 11; idxA++ {
//for idxA := 11; idxA < 12; idxA++ {
//for idxA := 12; idxA < 13; idxA++ {
// tensor
AA := test_AA[idxA]
A := M_Alloc2(3)
Ten2Man(A, AA)
io.PfYel("\n\ntst # %d ###################################################################################\n", idxA)
io.Pfblue2("A = %v\n", A)
// function evaluation and shifted eigenvalues
fval, err := o.Fa(A, r, μ)
if err != nil {
chk.Panic("cannot compute F(A):\n%v", err)
}
io.Pfpink("shift = %v\n", shift)
io.Pforan("p, q = %v, %v\n", o.p, o.q)
io.Pforan("f(A) = %v\n", fval)
// change tolerances
tol3 := tol2
tol2_tmp := tol2
switch idxA {
case 7:
tolq = 1e-5
case 10:
tolq = 2508 // TODO
tol3 = 0.772 // TODO: check why test # 10 fails with d2f/dAdA
case 11:
tol2 = 0.0442 // TODO: check this
tol3 = 440 //TODO: check this
case 12:
tol2 = 1e-3
//.........这里部分代码省略.........
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:101,代码来源:t_isofun_test.go
示例17: Test_up01a
//.........这里部分代码省略.........
chk.StrAssert(nod.Dofs[2].Key, "pl")
} else {
chk.IntAssert(len(nod.Dofs), 2)
chk.StrAssert(nod.Dofs[0].Key, "ux")
chk.StrAssert(nod.Dofs[1].Key, "uy")
}
}
// check equations
nids, eqs := get_nids_eqs(dom)
chk.Ints(tst, "eqs", eqs, utl.IntRange(10*3+17*2))
chk.Ints(tst, "nids", nids, []int{
0, 1, 3, 2, 10, 16, 11, 15, 23,
5, 4, 18, 12, 17, 24,
7, 6, 20, 13, 19, 25,
9, 8, 22, 14, 21, 26,
})
// check pmap
Pmaps := [][]int{
{2, 5, 8, 11},
{11, 8, 24, 27},
{27, 24, 38, 41},
{41, 38, 52, 55},
}
Umaps := [][]int{
{0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21},
{9, 10, 6, 7, 22, 23, 25, 26, 16, 17, 28, 29, 30, 31, 32, 33, 34, 35},
{25, 26, 22, 23, 36, 37, 39, 40, 30, 31, 42, 43, 44, 45, 46, 47, 48, 49},
{39, 40, 36, 37, 50, 51, 53, 54, 44, 45, 56, 57, 58, 59, 60, 61, 62, 63},
}
for i, ele := range dom.Elems {
e := ele.(*ElemUP)
io.Pfpink("%2d : Pmap = %v\n", e.Id(), e.P.Pmap)
io.Pfpink("%2d : Umap = %v\n", e.Id(), e.U.Umap)
chk.Ints(tst, "Pmap", e.P.Pmap, Pmaps[i])
chk.Ints(tst, "Umap", e.U.Umap, Umaps[i])
}
// constraints
chk.IntAssert(len(dom.EssenBcs.Bcs), 9*2+2+3)
var ct_ux_eqs []int // equations with ux prescribed [sorted]
var ct_uy_eqs []int // equations with uy prescribed [sorted]
var ct_pl_eqs []int // equations with pl prescribed [sorted]
for _, c := range dom.EssenBcs.Bcs {
chk.IntAssert(len(c.Eqs), 1)
eq := c.Eqs[0]
io.Pfgrey("key=%v eq=%v\n", c.Key, eq)
switch c.Key {
case "ux":
ct_ux_eqs = append(ct_ux_eqs, eq)
case "uy":
ct_uy_eqs = append(ct_uy_eqs, eq)
case "pl":
ct_pl_eqs = append(ct_pl_eqs, eq)
default:
tst.Errorf("key %s is incorrect", c.Key)
}
}
sort.Ints(ct_ux_eqs)
sort.Ints(ct_uy_eqs)
sort.Ints(ct_pl_eqs)
chk.Ints(tst, "equations with ux prescribed", ct_ux_eqs, []int{0, 3, 6, 9, 14, 18, 22, 25, 28, 32, 36, 39, 42, 46, 50, 53, 56, 60})
chk.Ints(tst, "equations with uy prescribed", ct_uy_eqs, []int{1, 4, 13})
chk.Ints(tst, "equations with pl prescribed", ct_pl_eqs, []int{2, 5})
开发者ID:PatrickSchm,项目名称:gofem,代码行数:66,代码来源:t_up_test.go
示例18: Test_mylab06
func Test_mylab06(tst *testing.T) {
//verbose()
chk.PrintTitle("mylab06. scaling")
// |dx|>0: increasing
io.Pfblue2("\n|dx|>0: increasing\n")
reverse := false
useinds := true
x := []float64{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
s := make([]float64, len(x))
Scaling(s, x, -2.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, LinSpace(-2, -1, len(x)))
// |dx|>0: reverse
io.Pfblue2("\n|dx|>0: reverse\n")
reverse = true
Scaling(s, x, -3.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, LinSpace(-2, -3, len(x)))
// |dx|>0: increasing
io.Pfblue2("\n|dx|>0: increasing (shuffled)\n")
reverse = false
x = []float64{11, 10, 12, 19, 15, 20, 17, 16, 18, 13, 14}
Scaling(s, x, 0.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, []float64{0.1, 0.0, 0.2, 0.9, 0.5, 1.0, 0.7, 0.6, 0.8, 0.3, 0.4})
// |dx|=0: increasing (using indices)
io.Pfblue2("\n|dx|=0: increasing (using indices)\n")
reverse = false
x = []float64{123, 123, 123, 123, 123}
s = make([]float64, len(x))
Scaling(s, x, 10.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, []float64{10, 10.25, 10.5, 10.75, 11})
// |dx|=0: reverse (using indices)
io.Pfblue2("\n|dx|=0: reverse (using indices)\n")
reverse = true
Scaling(s, x, 10.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, []float64{11, 10.75, 10.5, 10.25, 10})
// |dx|=0: increasing (not using indices)
io.Pfblue2("\n|dx|=0: increasing (not using indices)\n")
reverse = false
useinds = false
Scaling(s, x, 88.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, DblVals(len(x), 88))
// |dx|=0: reverse (not using indices)
io.Pfblue2("\n|dx|=0: reverse (not using indices)\n")
reverse = true
Scaling(s, x, 88.0, 1e-16, reverse, useinds)
io.Pfpink("x = %v\n", x)
io.Pforan("s = %v\n", s)
chk.Vector(tst, "s", 1e-15, s, DblVals(len(x), 88))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:68,代码来源:t_mylab_test.go
示例19: Test_smpinvs02
func Test_smpinvs02(tst *testing.T) {
//verbose()
chk.PrintTitle("smpinvs02")
// coefficients for smp invariants
smp_a := -1.0
smp_b := 0.5
smp_β := 1e-1 // derivative values become too high with
smp_ϵ := 1e-1 // small β and ϵ @ zero
// constants for checking derivatives
dver := chk.Verbose
dtol := 1e-9
dtol2 := 1e-8
// run tests
nd := test_nd
for idxA := 0; idxA < len(test_nd); idxA++ {
//for idxA := 0; idxA < 1; idxA++ {
//for idxA := 10; idxA < 11; idxA++ {
// tensor and eigenvalues
A := test_AA[idxA]
a := M_Alloc2(nd[idxA])
Ten2Man(a, A)
L := make([]float64, 3)
M_EigenValsNum(L, a)
// SMP director
N := make([]float64, 3)
n := make([]float64, 3)
m := SmpDirector(N, L, smp_a, smp_b, smp_β, smp_ϵ)
SmpUnitDirector(n, m, N)
// output
io.PfYel("\n\ntst # %d ###################################################################################\n", idxA)
io.Pforan("L = %v\n", L)
io.Pforan("N = %v\n", N)
io.Pforan("m = %v\n", m)
io.Pfpink("n = %v\n", n)
chk.Vector(tst, "L", 1e-12, L, test_λ[idxA])
chk.Scalar(tst, "norm(n)==1", 1e-15, la.VecNorm(n), 1)
chk.Scalar(tst, "m=norm(N)", 1e-14, m, la.VecNorm(N))
// dN/dL
var tmp float64
N_tmp := make([]float64, 3)
dNdL := make([]float64, 3)
SmpDirectorDeriv1(dNdL, L, smp_a, smp_b, smp_β, smp_ϵ)
io.Pfpink("\ndNdL = %v\n", dNdL)
for i := 0; i < 3; i++ {
dnum, _ := num.DerivCentral(func(x float64, args ...interface{}) (res float64) {
tmp, L[i] = L[i], x
SmpDirector(N_tmp, L, smp_a, smp_b, smp_β, smp_ϵ)
L[i] = tmp
return N_tmp[i]
}, L[i], 1e-6)
chk.AnaNum(tst, io.Sf("dN/dL[%d][%d]", i, i), dtol, dNdL[i], dnum, dver)
}
// dm/dL
n_tmp := make([]float64, 3)
dmdL := make([]float64, 3)
SmpNormDirectorDeriv1(dmdL, m, N, dNdL)
io.Pfpink("\ndmdL = %v\n", dmdL)
for j := 0; j < 3; j++ {
dnum, _ := num.DerivCentral(func(x float64, args ...interface{}) (res float64) {
tmp, L[j] = L[j], x
m_tmp := SmpDirector(N_tmp, L, smp_a, smp_b, smp_β, smp_ϵ)
L[j] = tmp
return m_tmp
}, L[j], 1e-6)
chk.AnaNum(tst, io.Sf("dm/dL[%d]", j), dtol, dmdL[j], dnum, dver)
}
// dn/dL
dndL := la.MatAlloc(3, 3)
SmpUnitDirectorDeriv1(dndL, m, N, dNdL, dmdL)
io.Pfpink("\ndndL = %v\n", dndL)
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
dnum, _ := num.DerivCentral(func(x float64, args ...interface{}) (res float64) {
tmp, L[j] = L[j], x
m_tmp := SmpDirector(N_tmp, L, smp_a, smp_b, smp_β, smp_ϵ)
SmpUnitDirector(n_tmp, m_tmp, N_tmp)
L[j] = tmp
return n_tmp[i]
}, L[j], 1e-6)
chk.AnaNum(tst, io.Sf("dn/dL[%d][%d]", i, j), dtol, dndL[i][j], dnum, dver)
}
}
// change tolerance
dtol2_tmp := dtol2
if idxA == 10 || idxA == 11 {
dtol2 = 1e-6
}
// d²m/dLdL
//.........这里部分代码省略.........
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:101,代码来源:t_smpinvs_test.go
示例20: Test_list02
func Test_list02(tst *testing.T) {
//verbose()
chk.PrintTitle("list02. DblSlist.Append")
var L DblSlist
L.Append(true, 0.0)
io.Pforan("L.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "0: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "0: vals", 1e-17, L.Vals, []float64{0.0})
chk.Ints(tst, "0: ptrs", L.Ptrs, []int{0, 1})
L.Append(true, 1.0)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "1: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "1: vals", 1e-17, L.Vals, []float64{0.0, 1.0})
chk.Ints(tst, "1: ptrs", L.Ptrs, []int{0, 1, 2})
L.Append(false, 1.1)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "2: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "2: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1})
chk.Ints(tst, "2: ptrs", L.Ptrs, []int{0, 1, 3})
L.Append(false, 1.2)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "3: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "3: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2})
chk.Ints(tst, "3: ptrs", L.Ptrs, []int{0, 1, 4})
L.Append(false, 1.3)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "4: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "4: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3})
chk.Ints(tst, "4: ptrs", L.Ptrs, []int{0, 1, 5})
L.Append(true, 2.0)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "5: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "5: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3, 2.0})
chk.Ints(tst, "5: ptrs", L.Ptrs, []int{0, 1, 5, 6})
L.Append(false, 2.1)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "6: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "6: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3, 2.0, 2.1})
chk.Ints(tst, "6: ptrs", L.Ptrs, []int{0, 1, 5, 7})
L.Append(true, 3.0)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "7: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "7: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3, 2.0, 2.1, 3.0})
chk.Ints(tst, "7: ptrs", L.Ptrs, []int{0, 1, 5, 7, 8})
L.Append(false, 3.1)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "8: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "8: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3, 2.0, 2.1, 3.0, 3.1})
chk.Ints(tst, "8: ptrs", L.Ptrs, []int{0, 1, 5, 7, 9})
L.Append(false, 3.2)
io.Pforan("\nL.Vals = %v\n", L.Vals)
io.Pfpink("L.Ptrs = %v\n", L.Ptrs)
chk.Ints(tst, "9: lens", []int{L.Ptrs[len(L.Ptrs)-1]}, []int{len(L.Vals)})
chk.Vector(tst, "9: vals", 1e-17, L.Vals, []float64{0.0, 1.0, 1.1, 1.2, 1.3, 2.0, 2.1, 3.0, 3.1, 3.2})
chk.Ints(tst, "9: ptrs", L.Ptrs, []int{0, 1, 5, 7, 10})
io.Pf("\n")
L.Print("%10g")
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:80,代码来源:t_list_test.go
注:本文中的github.com/cpmech/gosl/io.Pfpink函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论